inquirer-grouped-checkbox 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2025 Craig Patik
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,265 @@
1
+ # inquirer-grouped-checkbox
2
+
3
+ A searchable, grouped checkbox prompt for [Inquirer.js](https://github.com/SBoudrias/Inquirer.js) with per-group and global selection controls.
4
+
5
+ ![Demo gif](https://github.com/user-attachments/assets/d4f7fd13-aa3d-4bcd-ab8d-fca7bd54bbef)
6
+
7
+ ![npm version](https://img.shields.io/npm/v/inquirer-grouped-checkbox)
8
+ ![license](https://img.shields.io/npm/l/inquirer-grouped-checkbox)
9
+
10
+ ## Features
11
+
12
+ - **Grouped display** - Organize choices under labeled headers with optional icons
13
+ - **Per-group controls** - Select all/none within a single group (Shift+A/Shift+I)
14
+ - **Global controls** - Select all/none across all groups (a/i or Ctrl+A/Ctrl+I when searchable)
15
+ - **Real-time search** - Filter choices across all groups simultaneously
16
+ - **Keyboard navigation** - Navigate between items and jump between groups with Tab
17
+ - **Selection stats** - See how many items are selected in each group
18
+ - **Theming support** - Customize icons and colors
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pnpm add inquirer-grouped-checkbox
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```typescript
29
+ import groupedCheckbox from 'inquirer-grouped-checkbox'
30
+
31
+ const selected = await groupedCheckbox({
32
+ message: 'Select items to process',
33
+ groups: [
34
+ {
35
+ key: 'fruits',
36
+ label: 'Fruits',
37
+ icon: '🍎',
38
+ choices: [
39
+ { value: 'apple', name: 'Apple' },
40
+ { value: 'banana', name: 'Banana' },
41
+ { value: 'orange', name: 'Orange' },
42
+ ],
43
+ },
44
+ {
45
+ key: 'vegetables',
46
+ label: 'Vegetables',
47
+ icon: '🥬',
48
+ choices: [
49
+ { value: 'carrot', name: 'Carrot' },
50
+ { value: 'broccoli', name: 'Broccoli' },
51
+ { value: 'spinach', name: 'Spinach' },
52
+ ],
53
+ },
54
+ ],
55
+ searchable: true,
56
+ pageSize: 15,
57
+ })
58
+
59
+ console.log(selected)
60
+ // Output: { fruits: ['apple', 'banana'], vegetables: ['carrot'] }
61
+ ```
62
+
63
+ ## API
64
+
65
+ ### `groupedCheckbox(config)`
66
+
67
+ Returns a `Promise` that resolves to an object with group keys mapping to arrays of selected values.
68
+
69
+ #### Config Options
70
+
71
+ | Option | Type | Default | Description |
72
+ | ------------ | ---------- | ---------- | ---------------------------------- |
73
+ | `message` | `string` | _required_ | The question to display |
74
+ | `groups` | `Group[]` | _required_ | Array of groups containing choices |
75
+ | `searchable` | `boolean` | `false` | Enable real-time filtering |
76
+ | `pageSize` | `number` | `15` | Number of items to display at once |
77
+ | `required` | `boolean` | `false` | Require at least one selection |
78
+ | `validate` | `function` | - | Custom validation function |
79
+ | `theme` | `object` | - | Theme customization |
80
+
81
+ #### Group Object
82
+
83
+ | Property | Type | Description |
84
+ | --------- | ---------- | ------------------------------------------------------- |
85
+ | `key` | `string` | Unique identifier for the group (used in result object) |
86
+ | `label` | `string` | Display name for the group header |
87
+ | `icon` | `string` | Optional icon to show before the label |
88
+ | `choices` | `Choice[]` | Array of choices in this group |
89
+
90
+ #### Choice Object
91
+
92
+ | Property | Type | Description |
93
+ | ------------- | ------------------- | ------------------------------------------------------ |
94
+ | `value` | `any` | The value returned when selected |
95
+ | `name` | `string` | Display text (defaults to `value` if not provided) |
96
+ | `description` | `string` | Additional description shown when item is focused |
97
+ | `short` | `string` | Short display text for the answer (defaults to `name`) |
98
+ | `checked` | `boolean` | Whether the item is pre-selected |
99
+ | `disabled` | `boolean \| string` | Disable selection (string shows reason) |
100
+
101
+ ## Keyboard Shortcuts
102
+
103
+ | Key | Action |
104
+ | ----------- | -------------------------------- |
105
+ | `↑` / `↓` | Move cursor up/down |
106
+ | `Space` | Toggle current item |
107
+ | `Enter` | Submit selection |
108
+ | `Tab` | Jump to next group |
109
+ | `Shift+Tab` | Jump to previous group |
110
+ | `a` | Toggle all (when not searchable) |
111
+ | `i` | Invert all (when not searchable) |
112
+ | `Ctrl+A` | Toggle all (when searchable) |
113
+ | `Ctrl+I` | Invert all (when searchable) |
114
+ | `Shift+A` | Toggle all in current group |
115
+ | `Shift+I` | Invert all in current group |
116
+ | `Escape` | Clear search query |
117
+ | `Backspace` | Delete last search character |
118
+
119
+ When `searchable: true`, typing alphanumeric characters filters the choices in real-time.
120
+
121
+ ## Examples
122
+
123
+ ### With Validation
124
+
125
+ ```typescript
126
+ const selected = await groupedCheckbox({
127
+ message: 'Select at least 2 items',
128
+ groups: [
129
+ /* ... */
130
+ ],
131
+ validate: (selections) => {
132
+ const total = Object.values(selections).flat().length
133
+ if (total < 2) {
134
+ return 'Please select at least 2 items'
135
+ }
136
+ return true
137
+ },
138
+ })
139
+ ```
140
+
141
+ ### With Pre-selected Items
142
+
143
+ ```typescript
144
+ const selected = await groupedCheckbox({
145
+ message: 'Select items',
146
+ groups: [
147
+ {
148
+ key: 'defaults',
149
+ label: 'Recommended',
150
+ choices: [
151
+ { value: 'option1', name: 'Option 1', checked: true },
152
+ { value: 'option2', name: 'Option 2', checked: true },
153
+ { value: 'option3', name: 'Option 3' },
154
+ ],
155
+ },
156
+ ],
157
+ })
158
+ ```
159
+
160
+ ### With Disabled Items
161
+
162
+ ```typescript
163
+ const selected = await groupedCheckbox({
164
+ message: 'Select available items',
165
+ groups: [
166
+ {
167
+ key: 'items',
168
+ label: 'Items',
169
+ choices: [
170
+ { value: 'available', name: 'Available Item' },
171
+ { value: 'unavailable', name: 'Unavailable', disabled: 'Out of stock' },
172
+ ],
173
+ },
174
+ ],
175
+ })
176
+ ```
177
+
178
+ ### With Descriptions
179
+
180
+ ```typescript
181
+ const selected = await groupedCheckbox({
182
+ message: 'Select a plan',
183
+ groups: [
184
+ {
185
+ key: 'plans',
186
+ label: 'Plans',
187
+ choices: [
188
+ {
189
+ value: 'basic',
190
+ name: 'Basic Plan',
191
+ description: '$9/month - 10GB storage, email support',
192
+ },
193
+ {
194
+ value: 'pro',
195
+ name: 'Pro Plan',
196
+ description: '$29/month - 100GB storage, priority support',
197
+ },
198
+ ],
199
+ },
200
+ ],
201
+ })
202
+ ```
203
+
204
+ ## Theming
205
+
206
+ You can customize the appearance by passing a theme object:
207
+
208
+ ```typescript
209
+ const selected = await groupedCheckbox({
210
+ message: 'Select items',
211
+ groups: [
212
+ /* ... */
213
+ ],
214
+ theme: {
215
+ checkbox: {
216
+ icon: {
217
+ checked: '[x]',
218
+ unchecked: '[ ]',
219
+ cursor: '>',
220
+ },
221
+ style: {
222
+ highlight: (text) => `\x1b[36m${text}\x1b[0m`, // cyan
223
+ groupHeader: (text, icon) => `\x1b[1m${icon ? `${icon} ` : ''}${text}\x1b[0m`,
224
+ },
225
+ helpMode: 'always', // 'always' | 'never' | 'auto'
226
+ },
227
+ },
228
+ })
229
+ ```
230
+
231
+ ## TypeScript
232
+
233
+ Full TypeScript support is included. You can type your values:
234
+
235
+ ```typescript
236
+ import groupedCheckbox, { type GroupedSelections } from 'inquirer-grouped-checkbox'
237
+
238
+ type FruitOrVegetable = 'apple' | 'banana' | 'carrot' | 'broccoli'
239
+
240
+ const selected: GroupedSelections<FruitOrVegetable> = await groupedCheckbox({
241
+ message: 'Select items',
242
+ groups: [
243
+ {
244
+ key: 'fruits',
245
+ label: 'Fruits',
246
+ choices: [
247
+ { value: 'apple' as const, name: 'Apple' },
248
+ { value: 'banana' as const, name: 'Banana' },
249
+ ],
250
+ },
251
+ {
252
+ key: 'vegetables',
253
+ label: 'Vegetables',
254
+ choices: [
255
+ { value: 'carrot' as const, name: 'Carrot' },
256
+ { value: 'broccoli' as const, name: 'Broccoli' },
257
+ ],
258
+ },
259
+ ],
260
+ })
261
+ ```
262
+
263
+ ## License
264
+
265
+ See `LICENSE` file