@@ -16,6 +16,9 @@ import {
1616 S_CORNER_TOP_RIGHT ,
1717} from './common.js' ;
1818
19+ /**
20+ * Alignment for content or titles within the box.
21+ */
1922export type BoxAlignment = 'left' | 'center' | 'right' ;
2023
2124type BoxSymbols = [ topLeft : string , topRight : string , bottomLeft : string , bottomRight : string ] ;
@@ -28,13 +31,49 @@ const roundedSymbols: BoxSymbols = [
2831] ;
2932const squareSymbols : BoxSymbols = [ S_BAR_START , S_BAR_START_RIGHT , S_BAR_END , S_BAR_END_RIGHT ] ;
3033
34+ /**
35+ * Options for the {@link box} prompt.
36+ */
3137export interface BoxOptions extends CommonOptions {
38+ /**
39+ * Alignment of the content (`'left'`, `'center'`, or `'right'`).
40+ * @default 'left'
41+ */
3242 contentAlign ?: BoxAlignment ;
43+
44+ /**
45+ * Alignment of the title (`'left'`, `'center'`, or `'right'`).
46+ * @default 'left'
47+ */
3348 titleAlign ?: BoxAlignment ;
49+
50+ /**
51+ * The width of the box, either `'auto'` to fit the content or a number for a fixed width.
52+ * @default 'auto'
53+ */
3454 width ?: number | 'auto' ;
55+
56+ /**
57+ * Padding around the title.
58+ * @default 1
59+ */
3560 titlePadding ?: number ;
61+
62+ /**
63+ * Padding around the content.
64+ * @default 2
65+ */
3666 contentPadding ?: number ;
67+
68+ /**
69+ * Use rounded corners when `true`, square corners when `false`.
70+ * @default true
71+ */
3772 rounded ?: boolean ;
73+
74+ /**
75+ * Custom function to style the border characters.
76+ */
3877 formatBorder ?: ( text : string ) => string ;
3978}
4079
@@ -59,6 +98,28 @@ function getPaddingForLine(
5998
6099const defaultFormatBorder = ( text : string ) => text ;
61100
101+ /**
102+ * Renders a customizable box around text content. It's similar to {@link note} but offers
103+ * more styling options.
104+ *
105+ * @see https://bomb.sh/docs/clack/packages/prompts/#box
106+ *
107+ * @param message - The content to display inside the box.
108+ * @param title - The title to display in the top border of the box.
109+ * @param opts - Optional configuration for the box styling and behavior.
110+ *
111+ * @example
112+ * ```ts
113+ * import { box } from '@clack/prompts';
114+ *
115+ * box('This is the content of the box', 'Box Title', {
116+ * contentAlign: 'center',
117+ * titleAlign: 'center',
118+ * width: 'auto',
119+ * rounded: true,
120+ * });
121+ * ```
122+ */
62123export const box = ( message = '' , title = '' , opts ?: BoxOptions ) => {
63124 const output : Writable = opts ?. output ?? process . stdout ;
64125 const columns = getColumns ( output ) ;
0 commit comments