···11+---
22+"@clack/prompts": patch
33+---
44+55+docs: add jsdoc for `box`, `group`, and `group-multi-select`
+61
packages/prompts/src/box.ts
···1616 S_CORNER_TOP_RIGHT,
1717} from './common.js';
18181919+/**
2020+ * Alignment for content or titles within the box.
2121+ */
1922export type BoxAlignment = 'left' | 'center' | 'right';
20232124type BoxSymbols = [topLeft: string, topRight: string, bottomLeft: string, bottomRight: string];
···2831];
2932const squareSymbols: BoxSymbols = [S_BAR_START, S_BAR_START_RIGHT, S_BAR_END, S_BAR_END_RIGHT];
30333434+/**
3535+ * Options for the {@link box} prompt.
3636+ */
3137export interface BoxOptions extends CommonOptions {
3838+ /**
3939+ * Alignment of the content (`'left'`, `'center'`, or `'right'`).
4040+ * @default 'left'
4141+ */
3242 contentAlign?: BoxAlignment;
4343+4444+ /**
4545+ * Alignment of the title (`'left'`, `'center'`, or `'right'`).
4646+ * @default 'left'
4747+ */
3348 titleAlign?: BoxAlignment;
4949+5050+ /**
5151+ * The width of the box, either `'auto'` to fit the content or a number for a fixed width.
5252+ * @default 'auto'
5353+ */
3454 width?: number | 'auto';
5555+5656+ /**
5757+ * Padding around the title.
5858+ * @default 1
5959+ */
3560 titlePadding?: number;
6161+6262+ /**
6363+ * Padding around the content.
6464+ * @default 2
6565+ */
3666 contentPadding?: number;
6767+6868+ /**
6969+ * Use rounded corners when `true`, square corners when `false`.
7070+ * @default true
7171+ */
3772 rounded?: boolean;
7373+7474+ /**
7575+ * Custom function to style the border characters.
7676+ */
3877 formatBorder?: (text: string) => string;
3978}
4079···59986099const defaultFormatBorder = (text: string) => text;
61100101101+/**
102102+ * Renders a customizable box around text content. It's similar to {@link note} but offers
103103+ * more styling options.
104104+ *
105105+ * @see https://bomb.sh/docs/clack/packages/prompts/#box
106106+ *
107107+ * @param message - The content to display inside the box.
108108+ * @param title - The title to display in the top border of the box.
109109+ * @param opts - Optional configuration for the box styling and behavior.
110110+ *
111111+ * @example
112112+ * ```ts
113113+ * import { box } from '@clack/prompts';
114114+ *
115115+ * box('This is the content of the box', 'Box Title', {
116116+ * contentAlign: 'center',
117117+ * titleAlign: 'center',
118118+ * width: 'auto',
119119+ * rounded: true,
120120+ * });
121121+ * ```
122122+ */
62123export const box = (message = '', title = '', opts?: BoxOptions) => {
63124 const output: Writable = opts?.output ?? process.stdout;
64125 const columns = getColumns(output);
+65
packages/prompts/src/group-multi-select.ts
···1212import { limitOptions } from './limit-options.js';
1313import type { Option } from './select.js';
14141515+/**
1616+ * Options for the {@link groupMultiselect} prompt.
1717+ */
1518export interface GroupMultiSelectOptions<Value> extends CommonOptions {
1919+ /**
2020+ * The message or question shown to the user above the input.
2121+ */
1622 message: string;
2323+2424+ /**
2525+ * Grouped options to display. Each key is a group label, and each value is an array of options.
2626+ */
1727 options: Record<string, Option<Value>[]>;
2828+2929+ /**
3030+ * The initially selected option(s).
3131+ */
1832 initialValues?: Value[];
3333+3434+ /**
3535+ * The maximum number of items/options to display at once.
3636+ */
1937 maxItems?: number;
3838+3939+ /**
4040+ * When `true` at least one option must be selected.
4141+ * @default true
4242+ */
2043 required?: boolean;
4444+4545+ /**
4646+ * The value the cursor should be positioned at initially.
4747+ */
2148 cursorAt?: Value;
4949+5050+ /**
5151+ * Whether entire groups can be selected at once.
5252+ * @default true
5353+ */
2254 selectableGroups?: boolean;
5555+5656+ /**
5757+ * Number of blank lines between groups.
5858+ * @default 0
5959+ */
2360 groupSpacing?: number;
2461}
6262+6363+/**
6464+ * The `groupMultiselect` prompt extends the {@link multiselect} prompt to allow
6565+ * arranging distinct Multi-Selects, whilst keeping all of them interactive.
6666+ *
6767+ * @see https://bomb.sh/docs/clack/packages/prompts/#group-multiselect
6868+ *
6969+ * @example
7070+ * ```ts
7171+ * import { groupMultiselect } from '@clack/prompts';
7272+ *
7373+ * const result = await groupMultiselect({
7474+ * message: 'Define your project',
7575+ * options: {
7676+ * 'Testing': [
7777+ * { value: 'Jest', hint: 'JavaScript testing framework' },
7878+ * { value: 'Playwright', hint: 'End-to-end testing' },
7979+ * ],
8080+ * 'Language': [
8181+ * { value: 'js', label: 'JavaScript', hint: 'Dynamic typing' },
8282+ * { value: 'ts', label: 'TypeScript', hint: 'Static typing' },
8383+ * ],
8484+ * },
8585+ * });
8686+ * ```
8787+ *
8888+ * @param opts The options for the group multiselect prompt
8989+ */
2590export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) => {
2691 const { selectableGroups = true, groupSpacing = 0 } = opts;
2792 const opt = (
+35-4
packages/prompts/src/group.ts
···44 [P in keyof T]: T[P];
55} & {};
6677+/**
88+ * The return type of a {@link PromptGroup}.
99+ * Resolves all prompt results, excluding the cancel symbol.
1010+ */
711export type PromptGroupAwaitedReturn<T> = {
812 [P in keyof T]: Exclude<Awaited<T[P]>, symbol>;
913};
10141515+/**
1616+ * Options for the {@link group} utility.
1717+ */
1118export interface PromptGroupOptions<T> {
1219 /**
1313- * Control how the group can be canceled
1414- * if one of the prompts is canceled.
2020+ * Called when any one of the prompts is canceled.
1521 */
1622 onCancel?: (opts: { results: Prettify<Partial<PromptGroupAwaitedReturn<T>>> }) => void;
1723}
18242525+/**
2626+ * A group of prompts to be displayed sequentially, with each prompt receiving
2727+ * the results of all previous prompts in the group.
2828+ */
1929export type PromptGroup<T> = {
2030 [P in keyof T]: (opts: {
2131 results: Prettify<Partial<PromptGroupAwaitedReturn<Omit<T, P>>>>;
···2333};
24342535/**
2626- * Define a group of prompts to be displayed
2727- * and return a results of objects within the group
3636+ * The `group` utility provides a consistent way to combine a series of prompts,
3737+ * combining each answer into one object. Each prompt receives the results of
3838+ * all previously completed prompts, and are displayed sequentially.
3939+ *
4040+ * @see https://bomb.sh/docs/clack/packages/prompts/#group
4141+ *
4242+ * @example
4343+ * ```ts
4444+ * import { group, text, password } from '@clack/prompts';
4545+ *
4646+ * const account = await group({
4747+ * email: () => text({
4848+ * message: 'What is your email address?',
4949+ * }),
5050+ * username: ({ results }) => text({
5151+ * message: 'What is your username?',
5252+ * placeholder: results.email?.replace(/@.+$/, '').toLowerCase() ?? '',
5353+ * }),
5454+ * password: () => password({
5555+ * message: 'Define your password',
5656+ * }),
5757+ * });
5858+ * ```
2859 */
2960export const group = async <T>(
3061 prompts: PromptGroup<T>,