From 007f1254c6126d4ed34133534e972d2c3cdfc67d Mon Sep 17 00:00:00 2001 From: Christian Preston Date: Fri, 17 Feb 2023 08:46:12 -0500 Subject: [PATCH 1/2] chore: update readme --- .changeset/witty-icons-try.md | 5 +++++ packages/prompts/README.md | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 .changeset/witty-icons-try.md diff --git a/.changeset/witty-icons-try.md b/.changeset/witty-icons-try.md new file mode 100644 index 00000000..2a6c8ba0 --- /dev/null +++ b/.changeset/witty-icons-try.md @@ -0,0 +1,5 @@ +--- +'@clack/prompts': patch +--- + +adding group to README.md diff --git a/packages/prompts/README.md b/packages/prompts/README.md index 403abb77..b6a5bb8c 100644 --- a/packages/prompts/README.md +++ b/packages/prompts/README.md @@ -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. + +```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) +``` From 68c486721ad92cddb0d6dc260577b75d81a3840f Mon Sep 17 00:00:00 2001 From: Christian Preston Date: Fri, 17 Feb 2023 08:51:08 -0500 Subject: [PATCH 2/2] chore: don't need to changeset since it's docs --- .changeset/witty-icons-try.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .changeset/witty-icons-try.md diff --git a/.changeset/witty-icons-try.md b/.changeset/witty-icons-try.md deleted file mode 100644 index 2a6c8ba0..00000000 --- a/.changeset/witty-icons-try.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@clack/prompts': patch ---- - -adding group to README.md