Skip to content

Conversation

@natemoo-re
Copy link
Member

clack-changesets.mp4

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2023

🦋 Changeset detected

Latest commit: 8a4a12f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/prompts Minor
@clack/core Minor

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

Comment on lines +464 to +489
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);
Copy link
Member Author

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...

Copy link
Collaborator

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.?

Copy link
Member Author

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!

Comment on lines +613 to +657
const prompt = prompts[name as keyof T];
const result = await prompt({ results })?.catch((e) => {
Copy link
Member Author

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

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

@ulken ulken left a 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?

Comment on lines +464 to +489
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);
Copy link
Collaborator

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.?

Comment on lines +613 to +657
const prompt = prompts[name as keyof T];
const result = await prompt({ results })?.catch((e) => {
Copy link
Collaborator

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.

Comment on lines +613 to +657
const prompt = prompts[name as keyof T];
const result = await prompt({ results })?.catch((e) => {
Copy link
Collaborator

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.

natemoo-re and others added 4 commits February 24, 2023 18:45
Co-authored-by: Oskar Löfgren <516549+ulken@users.noreply.github.com>
Co-authored-by: Oskar Löfgren <516549+ulken@users.noreply.github.com>
@natemoo-re natemoo-re merged commit e4dec12 into main Feb 25, 2023
@natemoo-re natemoo-re deleted the feat/changeset branch February 25, 2023 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants