[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

feat: support isAllowEmpty for multi-select

Jinma Yamashita (Feb 15, 2023, 11:34 PM +0900) de1314e0 d366a1f6

+11 -1
+6
.changeset/heavy-fishes-change.md
··· 1 + --- 2 + "@clack/prompts": patch 3 + "@clack/core": patch 4 + --- 5 + 6 + Support `isAllowEmpty` option for multi-select
+2 -1
packages/core/src/prompts/multi-select.ts
··· 4 4 interface MultiSelectOptions<T extends { value: any }> extends PromptOptions<MultiSelectPrompt<T>> { 5 5 options: T[]; 6 6 initialValue?: T['value']; 7 + isAllowEmpty?: boolean 7 8 } 8 9 export default class MultiSelectPrompt<T extends { value: any }> extends Prompt { 9 10 options: T[]; ··· 26 27 constructor(opts: MultiSelectOptions<T>) { 27 28 if (!opts.validate) { 28 29 opts.validate = () => { 29 - if (this.selectedValues.length === 0) return `Please select at least one option\n${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(color.bgWhite(color.inverse(' enter ')))} to submit`))}` 30 + if (!opts.isAllowEmpty && this.selectedValues.length === 0) return `Please select at least one option\n${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(color.bgWhite(color.inverse(' enter ')))} to submit`))}` 30 31 } 31 32 } 32 33 super(opts, false);
+1
packages/prompts/README.md
··· 104 104 { value: "prettier", label: "Prettier" }, 105 105 { value: "gh-action", label: "GitHub Action" }, 106 106 ], 107 + isAllowEmpty: true, 107 108 }); 108 109 ``` 109 110
+2
packages/prompts/src/index.ts
··· 114 114 message: string; 115 115 options: Options; 116 116 initialValue?: Options[number]["value"]; 117 + isAllowEmpty?: boolean; 117 118 } 118 119 export const select = <Options extends Option<Value>[], Value extends Readonly<string>>( 119 120 opts: SelectOptions<Options, Value> ··· 186 187 return new MultiSelectPrompt({ 187 188 options: opts.options, 188 189 initialValue: opts.initialValue, 190 + isAllowEmpty: opts.isAllowEmpty, 189 191 render() { 190 192 let title = `${color.gray(bar)}\n${symbol(this.state)} ${opts.message}\n`; 191 193