Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom instructions in the checkbox type #1139

Merged
merged 1 commit into from Jul 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions packages/checkbox/src/index.ts
Expand Up @@ -23,13 +23,14 @@ export type Choice<Value> = {
type State<Value> = {
prefix?: string;
pageSize?: number;
instructions?: string | boolean;
message: string;
choices: ReadonlyArray<Choice<Value>>;
};

export default createPrompt(
<Value>(state: State<Value>, done: (value: Array<Value>) => void): string => {
const { prefix, pageSize = 7 } = state;
const { prefix, pageSize = 7, instructions } = state;
const paginator = useRef(new Paginator()).current;

const [status, setStatus] = useState('pending');
Expand Down Expand Up @@ -103,13 +104,17 @@ export default createPrompt(
}

let helpTip = '';
if (showHelpTip !== false) {
const keys = [
`${chalk.cyan.bold('<space>')} to select`,
`${chalk.cyan.bold('<a>')} to toggle all`,
`${chalk.cyan.bold('<i>')} to invert selection`,
];
helpTip = ` (Press ${keys.join(', ')})`;
if (showHelpTip && (instructions === undefined || instructions)) {
if (typeof instructions === 'string') {
helpTip = instructions;
} else {
const keys = [
`${chalk.cyan.bold('<space>')} to select`,
`${chalk.cyan.bold('<a>')} to toggle all`,
`${chalk.cyan.bold('<i>')} to invert selection`,
];
helpTip = ` (Press ${keys.join(', ')})`;
}
}

const allChoices = choices
Expand Down