-
Notifications
You must be signed in to change notification settings - Fork 154
Add changeset-like prompts, changeset demo #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 8a4a12f The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| const selected = this.value.includes(option.value) || (option.group === true && this.isGroupSelected(option.value)); | ||
| const active = i === this.cursor; | ||
| const groupActive = !active && typeof option.group === 'string' && this.options[this.cursor].value === option.group; | ||
| if (groupActive) { | ||
| return opt(option, selected ? 'group-active-selected' : 'group-active', options); | ||
| } | ||
| if (active && selected) { | ||
| return opt(option, 'active-selected', options); | ||
| } | ||
| if (selected) { | ||
| return opt(option, 'selected', options); | ||
| } | ||
| return opt(option, active ? 'active' : 'inactive', options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like logic that should be moved into @clack/core somehow...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean if a group/option is selected/active etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't know what the API should look like, but the fact that we have to track state in the rendering logic feels leaky. That's the whole point of @clack/core!
| const prompt = prompts[name as keyof T]; | ||
| const result = await prompt({ results })?.catch((e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows p.group({ something: () => void }) to be skipped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you mean to conditionally skip a prompt, one would not return anything from the factory function? Neat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As addressed in the open PR which didn't land so well, I still don't see a value in catching and rethrowing the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this allows you to conditionally skip by returning undefined.
Agreed on the weird catch => throw, will have to think about that some more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super slick demo!
Do you plan on adding grouping variants of any other prompts?
| const selected = this.value.includes(option.value) || (option.group === true && this.isGroupSelected(option.value)); | ||
| const active = i === this.cursor; | ||
| const groupActive = !active && typeof option.group === 'string' && this.options[this.cursor].value === option.group; | ||
| if (groupActive) { | ||
| return opt(option, selected ? 'group-active-selected' : 'group-active', options); | ||
| } | ||
| if (active && selected) { | ||
| return opt(option, 'active-selected', options); | ||
| } | ||
| if (selected) { | ||
| return opt(option, 'selected', options); | ||
| } | ||
| return opt(option, active ? 'active' : 'inactive', options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean if a group/option is selected/active etc.?
| const prompt = prompts[name as keyof T]; | ||
| const result = await prompt({ results })?.catch((e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you mean to conditionally skip a prompt, one would not return anything from the factory function? Neat.
| const prompt = prompts[name as keyof T]; | ||
| const result = await prompt({ results })?.catch((e) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As addressed in the open PR which didn't land so well, I still don't see a value in catching and rethrowing the error.
Co-authored-by: Oskar Löfgren <516549+ulken@users.noreply.github.com>
Co-authored-by: Oskar Löfgren <516549+ulken@users.noreply.github.com>
faa42ef to
11552e2
Compare
clack-changesets.mp4