From 3d12cf26524062d4ecdb5326e5858ba02e845e1e Mon Sep 17 00:00:00 2001 From: zonemeen Date: Wed, 13 Jul 2022 14:55:34 +0800 Subject: [PATCH] feat: custom instructions in the checkbox type --- packages/checkbox/src/index.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/checkbox/src/index.ts b/packages/checkbox/src/index.ts index 67de61ade..61ec9a79c 100644 --- a/packages/checkbox/src/index.ts +++ b/packages/checkbox/src/index.ts @@ -23,13 +23,14 @@ export type Choice = { type State = { prefix?: string; pageSize?: number; + instructions?: string | boolean; message: string; choices: ReadonlyArray>; }; export default createPrompt( (state: State, done: (value: Array) => void): string => { - const { prefix, pageSize = 7 } = state; + const { prefix, pageSize = 7, instructions } = state; const paginator = useRef(new Paginator()).current; const [status, setStatus] = useState('pending'); @@ -103,13 +104,17 @@ export default createPrompt( } let helpTip = ''; - if (showHelpTip !== false) { - const keys = [ - `${chalk.cyan.bold('')} to select`, - `${chalk.cyan.bold('')} to toggle all`, - `${chalk.cyan.bold('')} to invert selection`, - ]; - helpTip = ` (Press ${keys.join(', ')})`; + if (showHelpTip && (instructions === undefined || instructions)) { + if (typeof instructions === 'string') { + helpTip = instructions; + } else { + const keys = [ + `${chalk.cyan.bold('')} to select`, + `${chalk.cyan.bold('')} to toggle all`, + `${chalk.cyan.bold('')} to invert selection`, + ]; + helpTip = ` (Press ${keys.join(', ')})`; + } } const allChoices = choices