feat: `transformChoice` options for checkbox
matthyk opened this issue · 5 comments
After the selection within the checkbox prompt is made, the selected values are printed to stdout
. This can look very messy if the name of the choice is very long. The reason for this is this line:
Inquirer.js/packages/checkbox/src/index.mts
Line 173 in a3ab276
An option like transformChoice
could solve the problem. The line could then be updated to like this for example:
.map( transformChoice || (choice => choice.name || choice.value));
If I get the OK, I would also work on it right away.
The older checkbox prompt had a short
option to shorten long choices: https://github.com/SBoudrias/Inquirer.js/blob/master/packages/inquirer/lib/prompts/checkbox.js
I don't know we need to keep the same API, but it's an option. Also, if we want to shorten the display, maybe we're better with a rendering function receiving the whole option list (so you could custom format like "a, b and 3 others", etc)
@SBoudrias Are you open for a PR?
Yes, happy to review and merge a PR.
I would recommend us aligning on the right approach to the problem though - want to make sure you don't waste your time if we end up feeling a different API would cover more cases!
I would go with your second option, to provide a rendering function. I think it is the most flexible option. We could provide the rendering function with the list of all options AND the list of all selected options. Something like:
type RenderFn = (choices: ReadonlyArray<Choice<Value> | Separator>, selectedChoices: ReadonlyArray<Choice<Value>>) => string
But I'm open to everything.
Yeah, that works. I like it - it's probably the most flexible option.
Just a nit that I'd flip the function params for all choices and selected choices.