[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

chore: update readme

Christian Preston (Feb 17, 2023, 8:46 AM EST) 007f1254 c0f34693

+38
+5
.changeset/witty-icons-try.md
··· 1 + --- 2 + '@clack/prompts': patch 3 + --- 4 + 5 + adding group to README.md
+33
packages/prompts/README.md
··· 120 120 // Do installation 121 121 s.stop('Installed via npm'); 122 122 ``` 123 + 124 + ## Utilities 125 + 126 + ### Grouping 127 + 128 + Grouping prompts together is a great way to keep your code organized. This accepts a JSON object with a name that can be used to reference the group later. The second argument is an optional but has a `onCancel` callback that will be called if the user cancels one of the prompts in the group. 129 + 130 + ```js 131 + import * as p from '@clack/prompts' 132 + 133 + const group = await p.group({ 134 + name: () => p.text({ message: "What is your name?" }), 135 + age: () => p.text({ message: "What is your age?" }), 136 + color: ({ results }) => p.multiselect({ 137 + message: `What is your favorite color ${results.name}?`, 138 + options: [ 139 + { value: 'red', label: 'Red' }, 140 + { value: 'green', label: 'Green' }, 141 + { value: 'blue', label: 'Blue' }, 142 + ], 143 + }) 144 + }, 145 + { 146 + // On Cancel callback that wraps the group 147 + // So if the user cancels one of the prompts in the group this function will be called 148 + onCancel: ({ results }) => { 149 + p.cancel('Operation cancelled.') 150 + process.exit(0) 151 + } 152 + }) 153 + 154 + console.log(group.name, group.age, group.color) 155 + ```