Skip to content

Commit d8e8257

Browse files
committed
docs: update date, limit-options, and messages sections
1 parent 4f80005 commit d8e8257

1 file changed

Lines changed: 44 additions & 16 deletions

File tree

src/content/docs/clack/packages/prompts.mdx

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -476,26 +476,30 @@ Options:
476476

477477
### Date input
478478

479-
`date` returns a `Date` on success or a cancel symbol. Use `format` to pick segment order: `YMD`, `MDY`, or `DMY`. Pass `locale` (BCP 47 string) to derive order and separators from `Intl`, or rely on the format alone.
479+
The `date` prompt provides an interactive date picker, allowing users to navigate between year, month, and day segments and increment/decrement values using keyboard controls.
480480

481481
```ts twoslash
482-
import { date, isCancel } from '@clack/prompts';
482+
import { date } from '@clack/prompts';
483483

484-
const picked = await date({
485-
message: 'Pick a date',
486-
format: 'YMD',
487-
minDate: new Date('2026-01-01'),
488-
maxDate: new Date('2026-12-31'),
484+
const birthday = await date({
485+
message: 'Pick your birthday',
486+
minDate: new Date('1900-01-01'),
487+
initialValue: new Date(),
488+
maxDate: new Date(),
489489
});
490-
491-
if (isCancel(picked)) {
492-
process.exit(0);
493-
}
494-
495-
// picked is a Date
496490
```
497491

498-
Options include `defaultValue`, `initialValue`, `minDate`, `maxDate`, `validate`, and the usual `signal`, `input`, `output`, and `withGuide` settings.
492+
Options:
493+
494+
- `message`: The message or question shown to the user above the input.
495+
- `format`: The date format to use (default: based on `locale`).
496+
- `locale`: The [BCP 47 language tag](https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag) to use for formatting.
497+
- `defaultValue`: The default value returned when the user doesn't select a date.
498+
- `initialValue`: The starting date shown when the prompt first renders. Users can edit this value before submitting.
499+
- `minDate`: The minimum allowed date for validation.
500+
- `maxDate`: The maximum allowed date for validation.
501+
- `validate`: A function or a [Standard Schema](https://github.com/standard-schema/standard-schema) that validates user input. If a custom function is given, you should return a `string` or `Error` to show as a validation error, or `undefined` to accept the result..
502+
- All [Common Options](#common-options)
499503

500504
### Confirmation
501505

@@ -701,6 +705,10 @@ intro('Welcome to clack');
701705

702706
<pre class="cli-preview"><font color="#555753">┌</font> Welcome to clack</pre>
703707

708+
Options:
709+
710+
- All [Common Options](#common-options)
711+
704712
### Outro
705713

706714
The `outro` function defines the end of an interaction.
@@ -716,20 +724,30 @@ outro('All operations are finished');
716724
<font color="#555753">└</font> All operations are finished
717725
&nbsp;</pre>
718726

727+
Options:
728+
729+
- All [Common Options](#common-options)
730+
719731
### Cancel
720732

721733
The `cancel` function defines an interruption of an interaction and therefore its end.
722734
It accepts an optional string parameter which is displayed as a cancellation message.
723735

724736
```ts twoslash
725737
import { cancel } from '@clack/prompts';
738+
import { process } from 'node:process';
726739

727740
cancel('Installation canceled');
741+
process.exit(1);
728742
```
729743

730744
<pre class="cli-preview"><font color="#555753">└</font> <font color="#CC0000">Installation canceled</font>
731745
&nbsp;</pre>
732746

747+
Options:
748+
749+
- All [Common Options](#common-options)
750+
733751
### Spinner
734752

735753
The `spinner` function provides a loading indicator for long-running operations.
@@ -1167,7 +1185,7 @@ await stream.step([
11671185

11681186
### limitOptions
11691187

1170-
`limitOptions` trims a long option list to what fits the terminal, returning the lines to render and keeping the active index visible—intended for **custom** prompts that mirror Clack’s sliding window (see `@clack/prompts` source). Pass `options`, `cursor`, a `style` callback, optional `maxItems`, `columnPadding`, `rowPadding`, and `output` if not using `stdout`.
1188+
Trims an option list to what fits the terminal, while keeping the active option (cursor) visible using a Clack style sliding window. Returns the lines to render.
11711189

11721190
```ts twoslash
11731191
import { limitOptions } from '@clack/prompts';
@@ -1177,8 +1195,18 @@ const options = ['apple', 'banana', 'cherry', 'date'];
11771195
const lines = limitOptions({
11781196
options,
11791197
cursor: 2,
1198+
maxItems: 8,
11801199
style: (opt, active) =>
11811200
active ? styleText('cyan', opt) : styleText('dim', opt),
1182-
maxItems: 8,
11831201
});
11841202
```
1203+
1204+
Options:
1205+
1206+
- `options`: The list of options to display.
1207+
- `cursor`: The index of the currently active/selected option.
1208+
- `style`: A function that styles the given option string. The `active` parameter indicates whether the option is currently selected.
1209+
- `maxItems`: Maximum number of options to display at once (default: `Infinity`).
1210+
- `columnPadding`: Number of columns to reserve for padding (default: `0`).
1211+
- `rowPadding`: Number of rows to reserve for padding (default: `0`).
1212+
- All [Common Options](#common-options)

0 commit comments

Comments
 (0)