Skip to content

Commit aab46a2

Browse files
ghostdevvdreyfus92
andauthored
docs: add jsdoc for text, password, and multiline prompts (#523)
Co-authored-by: paul valladares <85648028+dreyfus92@users.noreply.github.com>
1 parent 54be8d7 commit aab46a2

5 files changed

Lines changed: 112 additions & 2 deletions

File tree

.changeset/five-chicken-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/prompts": patch
3+
---
4+
5+
docs: add jsdoc for `text`, `password`, and `multiline` prompts

packages/prompts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const meaning = await text({
6565

6666
### Password
6767

68-
The password component behaves like `text`, but masks the input as the user types.
68+
The password prompt behaves like the [`text`](#text) prompt, but masks the input as the user types.
6969

7070
```js
7171
import { password } from '@clack/prompts';
@@ -201,7 +201,7 @@ const basket = await groupMultiselect({
201201

202202
### Multi-Line Text
203203

204-
The multi-line text component accepts multiple lines of text input. By default, pressing `Enter` twice submits the input.
204+
The multi-line prompt accepts multiple lines of text input. By default, pressing `Enter` twice submits the input.
205205

206206
```js
207207
import { multiline } from '@clack/prompts';

packages/prompts/src/multi-line.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,36 @@ import { MultiLinePrompt, settings, wrapTextWithPrefix } from '@clack/core';
33
import { S_BAR, S_BAR_END, symbol } from './common.js';
44
import type { TextOptions } from './text.js';
55

6+
/**
7+
* Options for the {@link multiline} prompt
8+
*/
69
export interface MultiLineOptions extends TextOptions {
10+
/**
11+
* When enabled it shows a `[ submit ]` button that can be focused with tab.
12+
* By default, pressing `Enter` twice submits the input
13+
*
14+
* @default false
15+
*/
716
showSubmit?: boolean;
817
}
918

19+
/**
20+
* The multi-line prompt accepts multiple lines of text input.
21+
* By default, pressing `Enter` twice submits the input.
22+
*
23+
* @see https://bomb.sh/docs/clack/packages/prompts/#multi-line-text
24+
*
25+
* @example
26+
* ```ts
27+
* import { multiline } from '@clack/prompts';
28+
*
29+
* const bio = await multiline({
30+
* message: 'Enter your bio',
31+
* placeholder: 'Tell us about yourself...',
32+
* showSubmit: true,
33+
* });
34+
* ```
35+
*/
1036
export const multiline = (opts: MultiLineOptions) => {
1137
return new MultiLinePrompt({
1238
validate: opts.validate,

packages/prompts/src/password.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,48 @@ import { styleText } from 'node:util';
22
import { PasswordPrompt, settings } from '@clack/core';
33
import { type CommonOptions, S_BAR, S_BAR_END, S_PASSWORD_MASK, symbol } from './common.js';
44

5+
/**
6+
* Options for the {@link password} prompt
7+
*/
58
export interface PasswordOptions extends CommonOptions {
9+
/**
10+
* The prompt message or question shown to the user above the input.
11+
*/
612
message: string;
13+
14+
/**
15+
* Character to use for masking input.
16+
* @default ▪/•
17+
*/
718
mask?: string;
19+
20+
/**
21+
* A function that validates user input. Return a `string` or `Error` to show as a
22+
* validation error, or `undefined` to accept the result.
23+
*/
824
validate?: (value: string | undefined) => string | Error | undefined;
25+
26+
/**
27+
* When enabled it causes the input to be cleared if/when validation fails.
28+
* @default false
29+
*/
930
clearOnError?: boolean;
1031
}
32+
33+
/**
34+
* The password prompt behaves like the {@link text} prompt, but the input is masked.
35+
*
36+
* @see https://bomb.sh/docs/clack/packages/prompts/#password-input
37+
*
38+
* @example
39+
* ```ts
40+
* import { password } from '@clack/prompts';
41+
*
42+
* const result = await password({
43+
* message: 'Enter your password',
44+
* });
45+
* ```
46+
*/
1147
export const password = (opts: PasswordOptions) => {
1248
return new PasswordPrompt({
1349
validate: opts.validate,

packages/prompts/src/text.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,57 @@ import { styleText } from 'node:util';
22
import { settings, TextPrompt } from '@clack/core';
33
import { type CommonOptions, S_BAR, S_BAR_END, symbol } from './common.js';
44

5+
/**
6+
* Options for the {@link text} prompt
7+
*/
58
export interface TextOptions extends CommonOptions {
9+
/**
10+
* The prompt message or question shown to the user above the input.
11+
*/
612
message: string;
13+
14+
/**
15+
* A visual hint shown when the field has no content.
16+
*/
717
placeholder?: string;
18+
19+
/**
20+
* A fallback value returned when the user provides nothing (empty input).
21+
*/
822
defaultValue?: string;
23+
24+
/**
25+
* The starting value shown when the prompt first renders.
26+
* Users can edit this value before submitting.
27+
*/
928
initialValue?: string;
29+
30+
/**
31+
* A function that validates user input. Return a `string` or `Error` to show as a
32+
* validation error, or `undefined` to accept the result.
33+
*/
1034
validate?: (value: string | undefined) => string | Error | undefined;
1135
}
1236

37+
/**
38+
* The text prompt accepts a single line of text.
39+
*
40+
* @see https://bomb.sh/docs/clack/packages/prompts/#text-input
41+
*
42+
* @example
43+
* ```ts
44+
* import { text } from '@clack/prompts';
45+
*
46+
* const name = await text({
47+
* message: 'What is your name?',
48+
* placeholder: 'John Doe',
49+
* validate: (value) => {
50+
* if (!value || value.length < 2) return 'Name must be at least 2 characters';
51+
* return undefined;
52+
* },
53+
* });
54+
* ```
55+
*/
1356
export const text = (opts: TextOptions) => {
1457
return new TextPrompt({
1558
validate: opts.validate,

0 commit comments

Comments
 (0)