( options: SelectOptions<A> & MultiSelectOptions )
| 1382 | * @since 4.0.0 |
| 1383 | */ |
| 1384 | export const MultiSelect = <const A>( |
| 1385 | options: SelectOptions<A> & MultiSelectOptions |
| 1386 | ): Prompt<Array<A>> => { |
| 1387 | const opts: SelectOptionsReq<A> & MultiSelectOptionsReq = { |
| 1388 | maxPerPage: 10, |
| 1389 | ...options |
| 1390 | } |
| 1391 | // Seed initial selection from choices marked as selected: true |
| 1392 | const initialSelected = new Set<number>() |
| 1393 | for (let i = 0; i < opts.choices.length; i++) { |
| 1394 | const choice = opts.choices[i] as SelectChoice<A> |
| 1395 | if (choice.selected === true && !choice.disabled) { |
| 1396 | initialSelected.add(i) |
| 1397 | } |
| 1398 | } |
| 1399 | const initialState: MultiSelectState = { index: 0, selectedIndices: initialSelected, error: Option.none() } |
| 1400 | return Custom(initialState, { |
| 1401 | render: handleMultiSelectRender(opts), |
| 1402 | process: handleMultiSelectProcess(opts), |
| 1403 | clear: handleMultiSelectClear(opts) |
| 1404 | }) |
| 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * Creates a `Prompt` which immediately succeeds with the specified value. |
nothing calls this directly
no test coverage detected