···11+---
22+"@clack/prompts": patch
33+---
44+55+docs: add jsdoc for `autocomplete`, `confirm`, and `path` prompts
+24-3
packages/prompts/README.md
···81818282### Confirm
83838484-The confirm component accepts a yes or no answer. The result is a boolean value of `true` or `false`.
8484+The `confirm` prompt accepts a yes or no choice, returning a boolean value corresponding to the user's selection.
85858686```js
8787import { confirm } from '@clack/prompts';
···125125126126### Autocomplete
127127128128-The autocomplete component lets a user filter a list by typing, then choose one option from the matching results. By default, matching uses each option's `label`, `hint`, and `value`. The result is the selected option's `value`.
128128+The `autocomplete` prompt combines text input with a searchable list of options. It's perfect for when you have a large list of options and want to help users find what they're looking for quickly.
129129130130```js
131131import { autocomplete } from '@clack/prompts';
···139139 { value: 'sveltekit', label: 'SvelteKit' },
140140 { value: 'remix', label: 'Remix' },
141141 ],
142142+});
143143+```
144144+145145+### Autocomplete Multi-Select
146146+147147+The `autocompleteMultiselect` prompt combines the search functionality of [autocomplete](#autocomplete) with the ability to select multiple options.
148148+149149+```js
150150+import { autocomplete } from '@clack/prompts';
151151+152152+const framework = await autocomplete({
153153+ message: 'Search for a framework',
154154+ options: [
155155+ { value: 'next', label: 'Next.js', hint: 'React framework' },
156156+ { value: 'astro', label: 'Astro', hint: 'Content-focused' },
157157+ { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' },
158158+ { value: 'remix', label: 'Remix', hint: 'Full stack framework' },
159159+ { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' },
160160+ ],
161161+ placeholder: 'Type to search...',
162162+ maxItems: 5,
142163});
143164```
144165···226247227248### Path
228249229229-The path component offers filesystem path suggestions and returns the selected path as a string. When `directory: true` is set, only directories can be selected.
250250+The `path` prompt extends [`autocomplete`](#autocomplete) to provide file and directory suggestions.
230251231252```js
232253import { path } from '@clack/prompts';
+76-13
packages/prompts/src/autocomplete.ts
···4141 return results;
4242}
43434444+/**
4545+ * Options for the {@link autocomplete} prompt.
4646+ */
4447interface AutocompleteSharedOptions<Value> extends CommonOptions {
4548 /**
4646- * The message to display to the user.
4949+ * The message or question shown to the user above the input.
4750 */
4851 message: string;
5252+4953 /**
5050- * Available options for the autocomplete prompt.
5454+ * The options to present, or a function that returns the options to present
5555+ * allowing for custom search/filtering.
5656+ *
5757+ * @see https://bomb.sh/docs/clack/packages/prompts/#dynamic-options-getter
5158 */
5259 options: Option<Value>[] | ((this: AutocompletePrompt<Option<Value>>) => Option<Value>[]);
6060+5361 /**
5454- * Maximum number of items to display at once.
6262+ * The maximum number of items/options to display in the autocomplete list at once.
5563 */
5664 maxItems?: number;
6565+5766 /**
5858- * Placeholder text to display when no input is provided.
6767+ * Placeholder text displayed when the search field is empty. When set, pressing
6868+ * tab copies the placeholder into the input.
5969 */
6070 placeholder?: string;
7171+6172 /**
6262- * Validates the value
7373+ * A function that validates user input. Return a `string` or `Error` to show as a
7474+ * validation error, or `undefined` to accept the result.
6375 */
6476 validate?: (value: Value | Value[] | undefined) => string | Error | undefined;
7777+6578 /**
6666- * Custom filter function to match options against search input.
6767- * If not provided, a default filter that matches label, hint, and value is used.
7979+ * Custom filter function to match options against the search input.
6880 */
6981 filter?: (search: string, option: Option<Value>) => boolean;
7082}
71837284export interface AutocompleteOptions<Value> extends AutocompleteSharedOptions<Value> {
7385 /**
7474- * The initial selected value.
8686+ * The initially selected option from the list.
7587 */
7688 initialValue?: Value;
8989+7790 /**
7878- * The initial user input
9191+ * The starting value shown in the users input box.
7992 */
8093 initialUserInput?: string;
8194}
82959696+/**
9797+ * The `autocomplete` prompt combines a text input with a searchable list of options.
9898+ * It's perfect for when you have a large list of options and want to help users
9999+ * find what they're looking for quickly.
100100+ *
101101+ * @see https://bomb.sh/docs/clack/packages/prompts/#autocomplete
102102+ *
103103+ * @example
104104+ * ```ts
105105+ * import { autocomplete } from '@clack/prompts';
106106+ *
107107+ * const framework = await autocomplete({
108108+ * message: 'Search for a framework',
109109+ * options: [
110110+ * { value: 'next', label: 'Next.js', hint: 'React framework' },
111111+ * { value: 'astro', label: 'Astro', hint: 'Content-focused' },
112112+ * { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' },
113113+ * { value: 'remix', label: 'Remix', hint: 'Full stack framework' },
114114+ * { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' },
115115+ * ],
116116+ * placeholder: 'Type to search...',
117117+ * maxItems: 5,
118118+ * });
119119+ * ```
120120+ */
83121export const autocomplete = <Value>(opts: AutocompleteOptions<Value>) => {
84122 const prompt = new AutocompletePrompt({
85123 options: opts.options,
···223261 return prompt.prompt() as Promise<Value | symbol>;
224262};
225263226226-// Type definition for the autocompleteMultiselect component
264264+/**
265265+ * Options for the {@link autocompleteMultiselect} prompt
266266+ */
227267export interface AutocompleteMultiSelectOptions<Value> extends AutocompleteSharedOptions<Value> {
228268 /**
229229- * The initial selected values
269269+ * The initially selected option(s) from the list.
230270 */
231271 initialValues?: Value[];
272272+232273 /**
233233- * If true, at least one option must be selected
274274+ * When `true` at least one option must be selected.
275275+ * @default false
234276 */
235277 required?: boolean;
236278}
237279238280/**
239239- * Integrated autocomplete multiselect - combines type-ahead filtering with multiselect in one UI
281281+ * The `autocompleteMultiselect` prompt combines the search functionality of autocomplete
282282+ * with the ability to select multiple options.
283283+ *
284284+ * @see https://bomb.sh/docs/clack/packages/prompts/#autocomplete-multiselect
285285+ *
286286+ * @example
287287+ * ```ts
288288+ * import { autocompleteMultiselect } from '@clack/prompts';
289289+ *
290290+ * const frameworks = await autocompleteMultiselect({
291291+ * message: 'Select frameworks',
292292+ * options: [
293293+ * { value: 'next', label: 'Next.js', hint: 'React framework' },
294294+ * { value: 'astro', label: 'Astro', hint: 'Content-focused' },
295295+ * { value: 'svelte', label: 'SvelteKit', hint: 'Compile-time framework' },
296296+ * { value: 'remix', label: 'Remix', hint: 'Full stack framework' },
297297+ * { value: 'nuxt', label: 'Nuxt', hint: 'Vue framework' },
298298+ * ],
299299+ * placeholder: 'Type to search...',
300300+ * maxItems: 5,
301301+ * });
302302+ * ```
240303 */
241304export const autocompleteMultiselect = <Value>(opts: AutocompleteMultiSelectOptions<Value>) => {
242305 const formatOption = (
+42
packages/prompts/src/confirm.ts
···99 symbol,
1010} from './common.js';
11111212+/**
1313+ * Options for the {@link confirm} prompt.
1414+ */
1215export interface ConfirmOptions extends CommonOptions {
1616+ /**
1717+ * The message or question shown to the user above the input.
1818+ */
1319 message: string;
2020+2121+ /**
2222+ * The label to use for the active (true) option.
2323+ * @default 'Yes'
2424+ */
1425 active?: string;
2626+2727+ /**
2828+ * The label to use for the inactive (false) option.
2929+ * @default 'No'
3030+ */
1531 inactive?: string;
3232+3333+ /**
3434+ * The initial selected value (true or false).
3535+ * @default true
3636+ */
1637 initialValue?: boolean;
3838+3939+ /**
4040+ * Whether to render the options vertically instead of horizontally.
4141+ * @default false
4242+ */
1743 vertical?: boolean;
1844}
4545+4646+/**
4747+ * The `confirm` prompt accepts a yes or no choice, returning a boolean value
4848+ * corresponding to the user's selection.
4949+ *
5050+ * @see https://bomb.sh/docs/clack/packages/prompts/#confirmation
5151+ *
5252+ * @example
5353+ * ```ts
5454+ * import { confirm } from '@clack/prompts';
5555+ *
5656+ * const shouldProceed = await confirm({
5757+ * message: 'Do you want to continue?',
5858+ * });
5959+ * ```
6060+ */
1961export const confirm = (opts: ConfirmOptions) => {
2062 const active = opts.active ?? 'Yes';
2163 const inactive = opts.inactive ?? 'No';
+45-1
packages/prompts/src/path.ts
···33import { autocomplete } from './autocomplete.js';
44import type { CommonOptions } from './common.js';
5566+/**
77+ * Options for the {@link path} prompt.
88+ */
69export interface PathOptions extends CommonOptions {
1010+ /**
1111+ * The message or question shown to the user above the input.
1212+ */
1313+ message: string;
1414+1515+ /**
1616+ * The starting directory for path suggestions (defaults to current working directory).
1717+ */
718 root?: string;
1919+2020+ /**
2121+ * When `true` only **directories** appear in suggestions while you navigate.
2222+ */
823 directory?: boolean;
2424+2525+ /**
2626+ * The starting path shown when the prompt first renders, which users can edit
2727+ * before submitting. If not provided it will fall back to the given `root`,
2828+ * or the current working directory.
2929+ *
3030+ * In `directory` mode, if the initial value points to a directory that exists,
3131+ * pressing enter will submit the input instead of jumping to the first child.
3232+ */
933 initialValue?: string;
1010- message: string;
3434+3535+ /**
3636+ * A function that validates the given path. Return a `string` or `Error` to show as a
3737+ * validation error, or `undefined` to accept the result.
3838+ */
1139 validate?: (value: string | undefined) => string | Error | undefined;
1240}
13414242+/**
4343+ * The `path` prompt extends `autocomplete` to provide file and directory suggestions.
4444+ *
4545+ * @see https://bomb.sh/docs/clack/packages/prompts/#path-selection
4646+ *
4747+ * @example
4848+ * ```ts
4949+ * import { path } from '@clack/prompts';
5050+ *
5151+ * const result = await path({
5252+ * message: 'Select a file:',
5353+ * root: process.cwd(),
5454+ * directory: false,
5555+ * });
5656+ * ```
5757+ */
1458export const path = (opts: PathOptions) => {
1559 const validate = opts.validate;
1660