-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: renderChoices
option
#1350
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1350 +/- ##
=======================================
Coverage 94.48% 94.49%
=======================================
Files 51 51
Lines 4423 4429 +6
Branches 771 772 +1
=======================================
+ Hits 4179 4185 +6
Misses 239 239
Partials 5 5 ☔ View full report in Codecov by Sentry. |
@SBoudrias I have exported the |
@matthyk I was wondering if you saw that PR to add full theming capacity over at #1323 Thinking about the changes introduced here, I'm reflecting the better approach might be with a theme. The theming PR is functional and close to ready; I was just hoping to wrap up #1334 before merging it since it'd conflict pretty bad with that PR. I'd love to hear your thoughts on this! |
@SBoudrias Themes are a great feature! This would make it easy to add a type CheckboxTheme = {
checkedIcon: string;
uncheckedIcon: string;
cursorIcon: string;
disabled: (text: string) => string;
};
type Config<Value> = PromptConfig<{
pageSize?: number;
instructions?: string | boolean;
choices: ReadonlyArray<Choice<Value> | Separator>;
loop?: boolean;
required?: boolean;
theme?: Partial<
Theme<CheckboxTheme> & {
style: Partial<Theme<CheckboxTheme>['style']>;
}
>;
renderChoices?: (this: Config<Value>['theme'], selected: Choice<Value>[], items: Item<Value>[]) => string
}>; const config: Config<number> = {
choices: [],
message: "undefined",
renderChoices: function renderChoices(selected: Choice<number>[], items: Item<number>[]): string {
// `this` is typed as Partial<Theme<CheckboxTheme>
return this?.disabled?("text") // The current typing of `theme` causes us to have to do this ugly double check
}
} |
@matthyk I like this idea very much! Would you want to open PRs against the theme branch? (I'm guessing ~2 PRs for the type change, and one for adding renderChoice) I'll work on wrapping up the password prompt change in ~a week. |
Slightly thinking back on theme + |
It possibly offers better usability for the developers. |
superseded by #1360 |
Closes #1349.
Adds the option
renderChoices
to the checkbox prompt. Currently, only the output of the selected choices can be modified by this option. Maybe we should consider to let this function also modify theprefix
andmessage
value?