From d70d52f25a708df729556a69ea95986979c99b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E8=B0=A6?= Date: Thu, 14 Jul 2022 04:27:05 +0800 Subject: [PATCH] feat: custom instructions in the checkbox type (#1139) --- 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