Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/prompts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,36 @@ s.start('Installing via npm');
// Do installation
s.stop('Installed via npm');
```

## Utilities

### Grouping

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accepts a JSON object with a name that can be used to reference the group later.

I don't understand this part. Care to explain?

To me, there's only one group of named prompts.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was meaning to say the first argument accepts an object and for each key correlates to a prompt function that then can be referenced within the return.

Might need to change the wording but if you have any suggestions to simplify I'll make those changes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, then we're on the same page regarding intended meaning. I don't think that's what it says right now, though.

It states the name can be used to reference the group, not the prompt.

I'll see what I can come up with.

On a related note, I think explanations of API parameters would be better suited for more structural API docs, but that's a whole other beast.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#68


```js
import * as p from '@clack/prompts'

const group = await p.group({
name: () => p.text({ message: "What is your name?" }),
age: () => p.text({ message: "What is your age?" }),
color: ({ results }) => p.multiselect({
message: `What is your favorite color ${results.name}?`,
options: [
{ value: 'red', label: 'Red' },
{ value: 'green', label: 'Green' },
{ value: 'blue', label: 'Blue' },
],
})
},
{
// On Cancel callback that wraps the group
// So if the user cancels one of the prompts in the group this function will be called
onCancel: ({ results }) => {
p.cancel('Operation cancelled.')
process.exit(0)
}
})

console.log(group.name, group.age, group.color)
```