* Example demonstrating the integrated autocomplete multiselect component * Which combines filtering and selection in a single interface
()
| 7 | */ |
| 8 | |
| 9 | async function main() { |
| 10 | console.clear(); |
| 11 | |
| 12 | p.intro(`${color.bgCyan(color.black(' Integrated Autocomplete Multiselect Example '))}`); |
| 13 | |
| 14 | p.note( |
| 15 | ` |
| 16 | ${color.cyan('Filter and select multiple items in a single interface:')} |
| 17 | - ${color.yellow('Type')} to filter the list in real-time |
| 18 | - Use ${color.yellow('up/down arrows')} to navigate with improved stability |
| 19 | - Press ${color.yellow('Space')} to select/deselect the highlighted item ${color.green('(multiple selections allowed)')} |
| 20 | - Use ${color.yellow('Backspace')} to modify your filter text when searching for different options |
| 21 | - Press ${color.yellow('Enter')} when done selecting all items |
| 22 | - Press ${color.yellow('Ctrl+C')} to cancel |
| 23 | `, |
| 24 | 'Instructions' |
| 25 | ); |
| 26 | |
| 27 | // Frameworks in alphabetical order |
| 28 | const frameworks = [ |
| 29 | { value: 'angular', label: 'Angular', hint: 'Frontend/UI' }, |
| 30 | { value: 'django', label: 'Django', hint: 'Python Backend' }, |
| 31 | { value: 'dotnet', label: '.NET Core', hint: 'C# Backend' }, |
| 32 | { value: 'electron', label: 'Electron', hint: 'Desktop' }, |
| 33 | { value: 'express', label: 'Express', hint: 'Node.js Backend' }, |
| 34 | { value: 'flask', label: 'Flask', hint: 'Python Backend' }, |
| 35 | { value: 'flutter', label: 'Flutter', hint: 'Mobile' }, |
| 36 | { value: 'laravel', label: 'Laravel', hint: 'PHP Backend' }, |
| 37 | { value: 'nestjs', label: 'NestJS', hint: 'Node.js Backend' }, |
| 38 | { value: 'nextjs', label: 'Next.js', hint: 'React Framework' }, |
| 39 | { value: 'nuxt', label: 'Nuxt.js', hint: 'Vue Framework' }, |
| 40 | { value: 'rails', label: 'Ruby on Rails', hint: 'Ruby Backend' }, |
| 41 | { value: 'react', label: 'React', hint: 'Frontend/UI' }, |
| 42 | { value: 'reactnative', label: 'React Native', hint: 'Mobile' }, |
| 43 | { value: 'spring', label: 'Spring Boot', hint: 'Java Backend' }, |
| 44 | { value: 'svelte', label: 'Svelte', hint: 'Frontend/UI' }, |
| 45 | { value: 'tauri', label: 'Tauri', hint: 'Desktop' }, |
| 46 | { value: 'vue', label: 'Vue.js', hint: 'Frontend/UI' }, |
| 47 | ]; |
| 48 | |
| 49 | // Use the new integrated autocompleteMultiselect component |
| 50 | const result = await p.autocompleteMultiselect<string>({ |
| 51 | message: 'Select frameworks (type to filter)', |
| 52 | options: frameworks, |
| 53 | placeholder: 'Type to filter...', |
| 54 | maxItems: 8, |
| 55 | }); |
| 56 | |
| 57 | if (p.isCancel(result)) { |
| 58 | p.cancel('Operation cancelled.'); |
| 59 | process.exit(0); |
| 60 | } |
| 61 | |
| 62 | // Type guard: if not a cancel symbol, result must be a string array |
| 63 | function isStringArray(value: unknown): value is string[] { |
| 64 | return Array.isArray(value) && value.every((item) => typeof item === 'string'); |
| 65 | } |
| 66 |
no test coverage detected