| 305 | */ |
| 306 | export const autocompleteMultiselect = <Value>(opts: AutocompleteMultiSelectOptions<Value>) => { |
| 307 | const formatOption = ( |
| 308 | option: Option<Value>, |
| 309 | active: boolean, |
| 310 | selectedValues: Value[], |
| 311 | focusedValue: Value | undefined |
| 312 | ) => { |
| 313 | const isSelected = selectedValues.includes(option.value); |
| 314 | const label = option.label ?? String(option.value ?? ''); |
| 315 | const hint = |
| 316 | option.hint && focusedValue !== undefined && option.value === focusedValue |
| 317 | ? styleText('dim', ` (${option.hint})`) |
| 318 | : ''; |
| 319 | const checkbox = isSelected |
| 320 | ? styleText('green', S_CHECKBOX_SELECTED) |
| 321 | : styleText('dim', S_CHECKBOX_INACTIVE); |
| 322 | |
| 323 | if (option.disabled) { |
| 324 | return `${styleText('gray', S_CHECKBOX_INACTIVE)} ${styleText(['strikethrough', 'gray'], label)}`; |
| 325 | } |
| 326 | if (active) { |
| 327 | return `${checkbox} ${label}${hint}`; |
| 328 | } |
| 329 | return `${checkbox} ${styleText('dim', label)}`; |
| 330 | }; |
| 331 | |
| 332 | // Create text prompt which we'll use as foundation |
| 333 | const prompt = new AutocompletePrompt<Option<Value>>({ |