Feat: @inquirer/prompts checkbox support for different name when selected
When using checkbox I would like to show more information in the name when a user selects an option. This information is quite expensive to retrieve, so I would only want to do it on selection. The feature should also support Promises to update the name of the Choice. Or this can be solved using events, which also could be exposed.
usage proposal:
const choices = await checkbox(
message: "Select modules",
choices: choice
.map(({ name, value, key }) => ({
name
value,
onChecked: async () => ({ name: `${name} - ${await getData(key)}` })
}))
I'm also willing to provide a PR, but would like to know how the API should look like for it.
Hi, thanks for reaching out!
This should be implemented within the theme options of the checkbox prompt.
For performance & simplicity reason, I'd prefer all-in-all not to expose an async interface. That'll also just be a UX headache to manage.
Hi 👋 I’d like to work on this issue as my first contribution. Just to confirm, the idea is to support a different label when a checkbox is selected (e.g. checkedName) and handle this within the theme options, correct?
Hey @Sakthieswaran-tech, that's roughly right. Not sure on the exact API, I think I'd implement it somewhat similarly to the message theme option; with 2 parameters (choice, status: checked | unchecked | disabled) and consolidate the theming functions (like we should review if we still need disabledChoice after that change)
Thanks a lot for the clarification I understand now — the idea is to add a theming hook for checkboxes similar to the message theme option, with a function like theme.checkbox(choice, status) where status can be checked | unchecked | disabled. I’ll first go through how the message theme option is implemented in the codebase, then draft an API plan for checkbox before starting the implementation. I’ll share the proposal here for confirmation before opening a PR.