You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 🧱 Comes with `text`, `confirm`, `select`, and `spinner` components
15
15
16
+
## Basics
16
17
18
+
### Setup
19
+
20
+
The `intro` and `outro` functions will print a message to begin or end a prompt session, respectively.
21
+
22
+
```js
23
+
import { intro, outro } from"@clack/prompts";
24
+
25
+
intro(`create-my-app`);
26
+
// Do stuff
27
+
outro(`You're all set!`);
28
+
```
29
+
30
+
### Cancellation
31
+
32
+
The `isCancel` function is a guard that detects when a user cancels a question with `CTRL + C`. You should handle this situation for each prompt, optionally providing a nice cancellation message with the `cancel` utility.
33
+
34
+
```js
35
+
import { isCancel, cancel, text } from"@clack/prompts";
36
+
37
+
constvalue=awaittext(/* TODO */);
38
+
39
+
if (isCancel(value)) {
40
+
cancel("Operation cancelled.");
41
+
process.exit(0);
42
+
}
43
+
```
44
+
45
+
## Components
46
+
47
+
### Text
48
+
49
+
The text component accepts a single line of text.
50
+
51
+
```js
52
+
import { text } from"@clack/prompts";
53
+
54
+
constmeaning=awaittext({
55
+
message:"What is the meaning of life?",
56
+
placeholder:"Not sure",
57
+
validate(value) {
58
+
if (value.length===0) return`Value is required!`;
59
+
},
60
+
});
61
+
```
62
+
63
+
### Confirm
64
+
65
+
The confirm component accepts a yes or no answer. The result is a boolean value of `true` or `false`.
66
+
67
+
```js
68
+
import { confirm } from"@clack/prompts";
69
+
70
+
constshouldContinue=awaitconfirm({
71
+
message:"Do you want to continue?",
72
+
});
73
+
```
74
+
75
+
### Select
76
+
77
+
The select component allows a user to choose one value from a list of options. The result is the `value` prop of a given option.
0 commit comments