Skip to content

Commit 1a7738a

Browse files
committed
docs(@clack/prompts): add builder
1 parent 6009a96 commit 1a7738a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/prompts/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,32 @@ const group = await p.group(
156156

157157
console.log(group.name, group.age, group.color);
158158
```
159+
160+
### Building
161+
162+
Just like `group`, but on `builder` way, so you can choose which one fits better.
163+
164+
```js
165+
import * as p from '@clack/prompts';
166+
167+
const results = await p
168+
.builder()
169+
.add('name', () => p.text({ message: 'What is your name?' }))
170+
.add('age', () => p.text({ message: 'What is your age?' }))
171+
.add('color', ({ results }) =>
172+
p.multiselect({
173+
message: `What is your favorite color ${results.name}?`,
174+
options: [
175+
{ value: 'red', label: 'Red' },
176+
{ value: 'green', label: 'Green' },
177+
{ value: 'blue', label: 'Blue' }
178+
]
179+
})
180+
)
181+
.onCancel(() => {
182+
p.cancel('Builder canceled');
183+
process.exit(0);
184+
})
185+
.run();
186+
console.log(results.name, results.age, results.color);
187+
```

0 commit comments

Comments
 (0)