Skip to content

Commit

Permalink
feat: custom instructions in the checkbox type (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
zonemeen committed Jul 13, 2022
1 parent cd3dc72 commit d70d52f
Showing 1 changed file with 13 additions and 8 deletions.
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

0 comments on commit d70d52f

Please sign in to comment.