@bomjan133/react-crud-ui 1.2.5 → 1.2.7
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/README.md +4630 -369
- package/bin/cli.js +387 -387
- package/dist/components/book-viewer/EpubViewer.d.ts +8 -0
- package/dist/components/book-viewer/PdfViewer.d.ts +9 -0
- package/dist/components/book-viewer/constants.d.ts +23 -0
- package/dist/components/book-viewer/hooks.d.ts +6 -0
- package/dist/components/book-viewer/index.d.ts +16 -0
- package/dist/components/book-viewer/ui.d.ts +16 -0
- package/dist/components/book-viewer/utils.d.ts +12 -0
- package/dist/components/crud/CrudDetail.d.ts +86 -0
- package/dist/components/crud/CrudForm.d.ts +33 -0
- package/dist/components/crud/CrudList.d.ts +105 -0
- package/dist/components/crud/DataTable.d.ts +64 -0
- package/dist/components/crud/EmptyState.d.ts +54 -0
- package/dist/components/crud/Loading.d.ts +32 -0
- package/dist/components/crud/Modal.d.ts +75 -0
- package/dist/components/crud/Pagination.d.ts +18 -0
- package/dist/components/crud/ServerErrorPage.d.ts +7 -0
- package/dist/components/layouts/AuthLayout.d.ts +32 -0
- package/dist/components/layouts/BreadcrumbContext.d.ts +4 -0
- package/dist/components/layouts/DashboardLayout.d.ts +41 -0
- package/dist/components/layouts/DetailView.d.ts +58 -0
- package/dist/components/layouts/Header.d.ts +13 -0
- package/dist/components/layouts/HeaderSlotContext.d.ts +4 -0
- package/dist/components/layouts/LoginPage.d.ts +50 -0
- package/dist/components/layouts/Sidebar.d.ts +38 -0
- package/dist/components/layouts/SidebarContext.d.ts +18 -0
- package/dist/components/layouts/index.d.ts +8 -0
- package/dist/components/toast/ToastContainer.d.ts +4 -0
- package/dist/components/toast/useUI.d.ts +33 -0
- package/dist/components/ui/CopyableField.d.ts +12 -0
- package/dist/components/ui/DownloadableButton.d.ts +15 -0
- package/dist/components/ui/alert-dialog.d.ts +26 -0
- package/dist/components/ui/alert.d.ts +8 -0
- package/dist/components/ui/avatar.d.ts +4 -0
- package/dist/components/ui/badge.d.ts +8 -0
- package/dist/components/ui/button.d.ts +6 -0
- package/dist/components/ui/calendar.d.ts +16 -0
- package/dist/components/ui/card.d.ts +7 -0
- package/dist/components/ui/checkbox.d.ts +2 -0
- package/dist/components/ui/collapsible.d.ts +3 -0
- package/dist/components/ui/date-picker.d.ts +2 -0
- package/dist/components/ui/date-range-picker.d.ts +2 -0
- package/dist/components/ui/dialog.d.ts +25 -0
- package/dist/components/ui/dropdown-menu.d.ts +23 -0
- package/dist/components/ui/form-fields.d.ts +19 -0
- package/dist/components/ui/input-group.d.ts +28 -0
- package/dist/components/ui/input.d.ts +2 -0
- package/dist/components/ui/label.d.ts +2 -0
- package/dist/components/ui/popover.d.ts +5 -0
- package/dist/components/ui/q-tabs.d.ts +18 -0
- package/dist/components/ui/rich-text-editor.d.ts +2 -0
- package/dist/components/ui/scroll-area.d.ts +3 -0
- package/dist/components/ui/search-select.d.ts +6 -0
- package/dist/components/ui/select.d.ts +12 -0
- package/dist/components/ui/separator.d.ts +2 -0
- package/dist/components/ui/skeleton.d.ts +4 -0
- package/dist/components/ui/switch.d.ts +2 -0
- package/dist/components/ui/table.d.ts +9 -0
- package/dist/components/ui/tabs.d.ts +6 -0
- package/dist/components/ui/textarea.d.ts +2 -0
- package/dist/components/ui/tiptap-editor.d.ts +2 -0
- package/dist/components/ui/tooltip.d.ts +6 -0
- package/dist/index.d.ts +42 -0
- package/dist/lib/utils.d.ts +61 -0
- package/dist/store/createCrudStore.d.ts +11 -0
- package/dist/store/useUIStore.d.ts +5 -0
- package/docs/1_GETTING_STARTED.md +333 -333
- package/docs/2_UI_COMPONENTS.md +586 -586
- package/docs/3_CRUD_COMPONENTS.md +974 -974
- package/docs/4_FORM_COMPONENTS.md +778 -778
- package/docs/5_LAYOUT_COMPONENTS.md +402 -402
- package/docs/6_STORE_FACTORY.md +456 -456
- package/docs/7_BOOK_VIEWER.md +365 -365
- package/docs/8_TOAST_NOTIFICATIONS.md +130 -130
- package/docs/9_UTILITIES.md +204 -204
- package/docs/README.md +83 -83
- package/package.json +1 -1
|
@@ -1,778 +1,778 @@
|
|
|
1
|
-
# Form Components Guide
|
|
2
|
-
|
|
3
|
-
Complete reference for form field components in @
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
1. [FormField](#formfield)
|
|
7
|
-
2. [QInput](#qinput)
|
|
8
|
-
3. [QTextarea](#qtextarea)
|
|
9
|
-
4. [QSelect](#qselect)
|
|
10
|
-
5. [QSearchSelect](#qsearchselect)
|
|
11
|
-
6. [QSwitch](#qswitch)
|
|
12
|
-
7. [QCheckbox](#qcheckbox)
|
|
13
|
-
8. [QForm](#qform)
|
|
14
|
-
9. [QDatePicker](#qdatepicker)
|
|
15
|
-
10. [QDateRangePicker](#qdaterangepicker)
|
|
16
|
-
11. [QRichTextEditor](#qrichtexteditor)
|
|
17
|
-
12. [Form Validation](#form-validation)
|
|
18
|
-
|
|
19
|
-
All `Q*` components (except `QInput`) are thin wrappers around [`FormField`](#formfield) plus a Radix/native primitive — they share the `label`/`description`/`error`/`required` props documented once below.
|
|
20
|
-
|
|
21
|
-
Every `Q*` component also accepts a `helpText` prop as an alias for `description` — pass whichever name reads better at the call site. If both are passed, `description` wins.
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## FormField
|
|
26
|
-
|
|
27
|
-
The base wrapper every `Q*` component (other than `QInput`, which lays itself out manually) renders through. Use it directly if you're wrapping a custom input that isn't covered by the `Q*` components.
|
|
28
|
-
|
|
29
|
-
### Props
|
|
30
|
-
|
|
31
|
-
| Prop | Type | Default | Description |
|
|
32
|
-
|------|------|---------|-------------|
|
|
33
|
-
| `label` | `string` | - | Label text |
|
|
34
|
-
| `description` | `string` | - | Helper text shown below the field (hidden while `error` is set) |
|
|
35
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
36
|
-
| `error` | `string` | - | Error message; when set, also adds destructive-color styling to the first child input |
|
|
37
|
-
| `required` | `boolean` | `false` | Shows a red `*` next to the label |
|
|
38
|
-
| `children` | `node` | - | The input element(s) to wrap. The **first** child automatically receives `id`, `aria-invalid`, and error border styling |
|
|
39
|
-
| `className` | `string` | - | Classes on the outer wrapper `div` |
|
|
40
|
-
| `labelClassName` | `string` | - | Classes on the `Label` |
|
|
41
|
-
| `descriptionClassName` | `string` | - | Classes on the description text |
|
|
42
|
-
| `errorClassName` | `string` | - | Classes on the error text |
|
|
43
|
-
|
|
44
|
-
### Usage
|
|
45
|
-
|
|
46
|
-
```jsx
|
|
47
|
-
import { FormField } from '@
|
|
48
|
-
|
|
49
|
-
<FormField label="Custom Field" description="Some helper text" error={errors.custom} required>
|
|
50
|
-
<MyCustomInput value={value} onChange={setValue} />
|
|
51
|
-
</FormField>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## QInput
|
|
57
|
-
|
|
58
|
-
Text/number input with label and error handling. Unlike the other `Q*` components, `QInput` does **not** use `FormField` — it has its own layout, and in `type="number"` mode it renders a full increment/decrement spinner instead of a plain `<input>`.
|
|
59
|
-
|
|
60
|
-
### Props
|
|
61
|
-
|
|
62
|
-
| Prop | Type | Default | Description |
|
|
63
|
-
|------|------|---------|-------------|
|
|
64
|
-
| `label` | `string` | - | Label text |
|
|
65
|
-
| `description` | `string` | - | Helper text shown below the input (hidden while `error` is set) |
|
|
66
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
67
|
-
| `error` | `string` | - | Error message shown below the input |
|
|
68
|
-
| `required` | `boolean` | `false` | Adds a red `*` next to the label |
|
|
69
|
-
| `type` | `string` | - | Input type (`text`, `email`, `password`, `number`, etc.) — `'number'` switches to spinner mode |
|
|
70
|
-
| `value` | `string \| number` | - | Input value |
|
|
71
|
-
| `onChange` | `function` | - | Change handler. By default called with just the new value: `(value) => void`. Set `emitValue={false}` to instead receive the raw event: `(e) => void` |
|
|
72
|
-
| `emitValue` | `boolean` | `true` | Whether `onChange` receives the value directly vs. the raw event |
|
|
73
|
-
| `disabled` | `boolean` | `false` | Disable the input |
|
|
74
|
-
| `className` | `string` | - | Classes on the outer wrapper |
|
|
75
|
-
| `inputClassName` | `string` | - | Classes on the `<input>` itself |
|
|
76
|
-
| `containerClassName` | `string` | - | Classes on the input's relative-position container (number mode) |
|
|
77
|
-
| `buttonClassName` | `string` | - | Classes on the +/- spinner buttons (number mode only) |
|
|
78
|
-
| `labelClassName` / `descriptionClassName` / `errorClassName` | `string` | - | Classes for those respective parts |
|
|
79
|
-
| `icon` | `ReactNode` | - | Icon rendered inside the input (non-`number` mode only). When set, the input is wrapped in an `InputGroup` so the icon sits flush against the border |
|
|
80
|
-
| `iconPosition` | `'prefix' \| 'postfix'` | `'prefix'` | Where `icon` is placed — `'prefix'` renders it before the text, `'postfix'` renders it after |
|
|
81
|
-
| `...props` | - | - | Anything else (`name`, `placeholder`, `readOnly`, `onBlur`, etc.) passes through to the underlying `<input>` |
|
|
82
|
-
|
|
83
|
-
> **Not implemented:** `icon`/`iconPosition` have no effect in `type="number"` mode, since that mode renders its own increment/decrement spinner layout instead.
|
|
84
|
-
|
|
85
|
-
### Number mode props
|
|
86
|
-
|
|
87
|
-
Only apply when `type="number"`:
|
|
88
|
-
|
|
89
|
-
| Prop | Type | Default | Description |
|
|
90
|
-
|------|------|---------|-------------|
|
|
91
|
-
| `min` | `number` | `-Infinity` | Minimum value; also disables the decrement button at the floor |
|
|
92
|
-
| `max` | `number` | `Infinity` | Maximum value; also disables the increment button at the ceiling |
|
|
93
|
-
| `step` | `number` | `1` | Amount added/subtracted per spinner click |
|
|
94
|
-
| `allowNegative` | `boolean` | `false` | Allow negative values/typing a leading `-` |
|
|
95
|
-
| `width` | `string` | `'w-36'` | Tailwind width class applied to the numeric `<input>` between the spinner buttons |
|
|
96
|
-
|
|
97
|
-
`onChange` in number mode always emits a `number` (not a string), including on blur, where partial/empty input is normalized to `0` (or `min`, if `min > 0`).
|
|
98
|
-
|
|
99
|
-
### Usage
|
|
100
|
-
|
|
101
|
-
```jsx
|
|
102
|
-
import { QInput } from '@
|
|
103
|
-
|
|
104
|
-
// Basic text input
|
|
105
|
-
<QInput
|
|
106
|
-
name="name"
|
|
107
|
-
label="Full Name"
|
|
108
|
-
value={form.name}
|
|
109
|
-
onChange={(val) => setField('name', val)}
|
|
110
|
-
placeholder="Enter your name"
|
|
111
|
-
required
|
|
112
|
-
/>
|
|
113
|
-
|
|
114
|
-
// With error
|
|
115
|
-
<QInput
|
|
116
|
-
name="email"
|
|
117
|
-
label="Email"
|
|
118
|
-
type="email"
|
|
119
|
-
value={form.email}
|
|
120
|
-
onChange={(val) => setField('email', val)}
|
|
121
|
-
error={errors.email}
|
|
122
|
-
placeholder="Enter email address"
|
|
123
|
-
/>
|
|
124
|
-
|
|
125
|
-
// Number input with spinner, bounds, and step
|
|
126
|
-
<QInput
|
|
127
|
-
name="quantity"
|
|
128
|
-
label="Quantity"
|
|
129
|
-
type="number"
|
|
130
|
-
value={form.quantity}
|
|
131
|
-
onChange={(val) => setField('quantity', val)}
|
|
132
|
-
min={1}
|
|
133
|
-
max={100}
|
|
134
|
-
step={1}
|
|
135
|
-
/>
|
|
136
|
-
|
|
137
|
-
// Number input allowing negative values
|
|
138
|
-
<QInput
|
|
139
|
-
name="adjustment"
|
|
140
|
-
label="Stock Adjustment"
|
|
141
|
-
type="number"
|
|
142
|
-
value={form.adjustment}
|
|
143
|
-
onChange={(val) => setField('adjustment', val)}
|
|
144
|
-
allowNegative
|
|
145
|
-
/>
|
|
146
|
-
|
|
147
|
-
// Receive the raw event instead of the value
|
|
148
|
-
<QInput
|
|
149
|
-
name="search"
|
|
150
|
-
label="Search"
|
|
151
|
-
value={form.search}
|
|
152
|
-
onChange={(e) => handleRawEvent(e)}
|
|
153
|
-
emitValue={false}
|
|
154
|
-
/>
|
|
155
|
-
|
|
156
|
-
// With a prefix icon
|
|
157
|
-
<QInput
|
|
158
|
-
name="search"
|
|
159
|
-
label="Search"
|
|
160
|
-
value={form.search}
|
|
161
|
-
onChange={(val) => setField('search', val)}
|
|
162
|
-
icon={<SearchIcon />}
|
|
163
|
-
iconPosition="prefix"
|
|
164
|
-
placeholder="Search..."
|
|
165
|
-
/>
|
|
166
|
-
|
|
167
|
-
// With a postfix icon
|
|
168
|
-
<QInput
|
|
169
|
-
name="email"
|
|
170
|
-
label="Email"
|
|
171
|
-
type="email"
|
|
172
|
-
value={form.email}
|
|
173
|
-
onChange={(val) => setField('email', val)}
|
|
174
|
-
icon={<MailIcon />}
|
|
175
|
-
iconPosition="postfix"
|
|
176
|
-
/>
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
---
|
|
180
|
-
|
|
181
|
-
## QTextarea
|
|
182
|
-
|
|
183
|
-
Multi-line text input, wrapped in [`FormField`](#formfield).
|
|
184
|
-
|
|
185
|
-
### Props
|
|
186
|
-
|
|
187
|
-
| Prop | Type | Default | Description |
|
|
188
|
-
|------|------|---------|-------------|
|
|
189
|
-
| `label` | `string` | - | Label text |
|
|
190
|
-
| `description` | `string` | - | Helper text |
|
|
191
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
192
|
-
| `error` | `string` | - | Error message |
|
|
193
|
-
| `required` | `boolean` | `false` | Mark as required |
|
|
194
|
-
| `value` | `string` | - | Input value |
|
|
195
|
-
| `onChange` | `function` | - | Change handler — `(value) => void` by default, `(e) => void` if `emitValue={false}` |
|
|
196
|
-
| `emitValue` | `boolean` | `true` | Whether `onChange` receives the value directly vs. the raw event |
|
|
197
|
-
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
198
|
-
| `textareaClassName` | `string` | - | Classes on the `<textarea>` itself |
|
|
199
|
-
| `...props` | - | - | Anything else (`rows`, `placeholder`, `disabled`, `maxLength`, etc.) passes through to the underlying `<textarea>` as native HTML attributes |
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
### Usage
|
|
203
|
-
|
|
204
|
-
```jsx
|
|
205
|
-
import { QTextarea } from '@
|
|
206
|
-
|
|
207
|
-
// Basic textarea
|
|
208
|
-
<QTextarea
|
|
209
|
-
name="description"
|
|
210
|
-
label="Description"
|
|
211
|
-
value={form.description}
|
|
212
|
-
onChange={(val) => setField('description', val)}
|
|
213
|
-
placeholder="Enter description"
|
|
214
|
-
rows={4}
|
|
215
|
-
/>
|
|
216
|
-
|
|
217
|
-
// With a manual character count
|
|
218
|
-
<QTextarea
|
|
219
|
-
name="bio"
|
|
220
|
-
label="Bio"
|
|
221
|
-
value={form.bio}
|
|
222
|
-
onChange={(val) => setField('bio', val)}
|
|
223
|
-
maxLength={500}
|
|
224
|
-
placeholder="Tell us about yourself..."
|
|
225
|
-
description={`${form.bio?.length ?? 0}/500`}
|
|
226
|
-
/>
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
---
|
|
230
|
-
|
|
231
|
-
## QSelect
|
|
232
|
-
|
|
233
|
-
Dropdown select (built on the Radix `Select` primitive) for choosing a single value from a static list, wrapped in [`FormField`](#formfield).
|
|
234
|
-
|
|
235
|
-
### Props
|
|
236
|
-
|
|
237
|
-
| Prop | Type | Default | Description |
|
|
238
|
-
|------|------|---------|-------------|
|
|
239
|
-
| `label` | `string` | - | Label text |
|
|
240
|
-
| `description` | `string` | - | Helper text |
|
|
241
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
242
|
-
| `error` | `string` | - | Error message |
|
|
243
|
-
| `required` | `boolean` | `false` | Mark as required |
|
|
244
|
-
| `options` | `array` | `[]` | Array of options (objects or primitives) |
|
|
245
|
-
| `value` | `any` | - | Selected value (compared as a string internally) |
|
|
246
|
-
| `onChange` | `function` | - | Value change handler — `(value: string) => void` |
|
|
247
|
-
| `optionLabel` | `string \| function` | - | Key name, or `(option) => label`, for display text. Falls back to `option.label ?? option.name ?? String(option)` |
|
|
248
|
-
| `optionValue` | `string \| function` | - | Key name, or `(option) => value`, for the option's value. Falls back to `option.value ?? option.id ?? option` |
|
|
249
|
-
| `getOptionLabel` | `function` | - | Alternative to `optionLabel` — takes precedence if both are given |
|
|
250
|
-
| `getOptionValue` | `function` | - | Alternative to `optionValue` — takes precedence if both are given |
|
|
251
|
-
| `placeholder` | `string` | `'Select...'` | Placeholder text |
|
|
252
|
-
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
253
|
-
| `selectTriggerClassName` | `string` | - | Classes on the trigger button |
|
|
254
|
-
| `selectContentClassName` | `string` | - | Classes on the dropdown content panel |
|
|
255
|
-
| `selectItemClassName` | `string` | - | Classes on each option item |
|
|
256
|
-
| `...props` | - | - | Anything else (`disabled`, etc.) passes through to the underlying Radix `Select` |
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
### Usage
|
|
260
|
-
|
|
261
|
-
```jsx
|
|
262
|
-
import { QSelect } from '@
|
|
263
|
-
|
|
264
|
-
// With simple options
|
|
265
|
-
const statusOptions = [
|
|
266
|
-
{ value: 'active', label: 'Active' },
|
|
267
|
-
{ value: 'inactive', label: 'Inactive' },
|
|
268
|
-
{ value: 'pending', label: 'Pending' },
|
|
269
|
-
];
|
|
270
|
-
|
|
271
|
-
<QSelect
|
|
272
|
-
name="status"
|
|
273
|
-
label="Status"
|
|
274
|
-
value={form.status}
|
|
275
|
-
onChange={(val) => setField('status', val)}
|
|
276
|
-
options={statusOptions}
|
|
277
|
-
placeholder="Select status"
|
|
278
|
-
/>
|
|
279
|
-
|
|
280
|
-
// With object options and a custom key
|
|
281
|
-
const categories = [
|
|
282
|
-
{ id: 1, name: 'Electronics' },
|
|
283
|
-
{ id: 2, name: 'Clothing' },
|
|
284
|
-
{ id: 3, name: 'Books' },
|
|
285
|
-
];
|
|
286
|
-
|
|
287
|
-
<QSelect
|
|
288
|
-
name="category_id"
|
|
289
|
-
label="Category"
|
|
290
|
-
value={form.category_id}
|
|
291
|
-
onChange={(val) => setField('category_id', val)}
|
|
292
|
-
options={categories}
|
|
293
|
-
optionLabel="name"
|
|
294
|
-
optionValue="id"
|
|
295
|
-
placeholder="Select category"
|
|
296
|
-
/>
|
|
297
|
-
|
|
298
|
-
// With function-based getters
|
|
299
|
-
<QSelect
|
|
300
|
-
name="user_id"
|
|
301
|
-
label="Assigned To"
|
|
302
|
-
value={form.user_id}
|
|
303
|
-
onChange={(val) => setField('user_id', val)}
|
|
304
|
-
options={users}
|
|
305
|
-
getOptionLabel={(u) => `${u.firstName} ${u.lastName}`}
|
|
306
|
-
getOptionValue={(u) => u.id}
|
|
307
|
-
error={errors.user_id}
|
|
308
|
-
required
|
|
309
|
-
/>
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
---
|
|
313
|
-
|
|
314
|
-
## QSearchSelect
|
|
315
|
-
|
|
316
|
-
Searchable select with client-side filtering, async search, multi-select, and infinite-scroll pagination — built on the custom `SearchSelect` primitive, wrapped in [`FormField`](#formfield).
|
|
317
|
-
|
|
318
|
-
### Props
|
|
319
|
-
|
|
320
|
-
| Prop | Type | Default | Description |
|
|
321
|
-
|------|------|---------|-------------|
|
|
322
|
-
| `label` | `string` | - | Label text |
|
|
323
|
-
| `description` | `string` | - | Helper text |
|
|
324
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
325
|
-
| `error` | `string` | - | Error message |
|
|
326
|
-
| `required` | `boolean` | `false` | Mark as required |
|
|
327
|
-
| `value` | `any` | - | Selected value — a single value normally, an array when `multiple` |
|
|
328
|
-
| `onChange` | `function` | - | Change handler. Single mode: `(value) => void`. Multi mode: `(values: array) => void` |
|
|
329
|
-
| `options` | `array` | `[]` | Array of options (objects or primitives) |
|
|
330
|
-
| `optionLabel` / `optionValue` | `string \| function` | - | Same resolution rules as [`QSelect`](#qselect) |
|
|
331
|
-
| `getOptionLabel` / `getOptionValue` | `function` | - | Same as `QSelect` — take precedence over `optionLabel`/`optionValue` |
|
|
332
|
-
| `onSearch` | `function` | - | Debounced (300ms) search handler — `(query: string) => void`. Use this to trigger an async fetch and update `options` |
|
|
333
|
-
| `multiple` | `boolean` | `false` | Allow multiple selections; `onChange`/`value` become arrays |
|
|
334
|
-
| `onLoadMore` | `function` | - | `() => Promise` — called when the dropdown list is scrolled near the bottom, for infinite-scroll pagination |
|
|
335
|
-
| `hasMore` | `boolean` | `false` | Whether more pages are available (controls whether `onLoadMore` can fire again) |
|
|
336
|
-
| `loadingMore` | `boolean` | `false` | Shows a loading row at the bottom of the list while a `onLoadMore` page is in flight |
|
|
337
|
-
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
338
|
-
| `searchSelectClassName` | `string` | - | Classes on the `SearchSelect` root |
|
|
339
|
-
| `searchSelectTriggerClassName` | `string` | - | Classes on the trigger button |
|
|
340
|
-
| `...props` | - | - | Anything else (`loading`, `disabled`, `renderOption`, `renderValue`, `filterOption`, `noOptionsMessage`, `loadingMessage`, etc.) passes through to the underlying `SearchSelect` |
|
|
341
|
-
|
|
342
|
-
> **Selection survives search filtering:** `QSearchSelect` internally caches every full option object it has ever seen (by value), so a previously-selected item keeps displaying its label even if it later scrolls out of the current (filtered or paginated) `options` list.
|
|
343
|
-
|
|
344
|
-
### Usage
|
|
345
|
-
|
|
346
|
-
```jsx
|
|
347
|
-
import { QSearchSelect } from '@
|
|
348
|
-
import { searchUsers } from '@/api';
|
|
349
|
-
|
|
350
|
-
// Async search select
|
|
351
|
-
const [users, setUsers] = useState([]);
|
|
352
|
-
const [loading, setLoading] = useState(false);
|
|
353
|
-
|
|
354
|
-
const handleUserSearch = async (query) => {
|
|
355
|
-
setLoading(true);
|
|
356
|
-
try {
|
|
357
|
-
setUsers(await searchUsers(query));
|
|
358
|
-
} finally {
|
|
359
|
-
setLoading(false);
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
<QSearchSelect
|
|
364
|
-
name="user_id"
|
|
365
|
-
label="Assign User"
|
|
366
|
-
value={form.user_id}
|
|
367
|
-
onChange={(val) => setField('user_id', val)}
|
|
368
|
-
options={users}
|
|
369
|
-
optionLabel="name"
|
|
370
|
-
optionValue="id"
|
|
371
|
-
onSearch={handleUserSearch}
|
|
372
|
-
loading={loading}
|
|
373
|
-
placeholder="Search users..."
|
|
374
|
-
/>
|
|
375
|
-
|
|
376
|
-
// Multiple selection
|
|
377
|
-
<QSearchSelect
|
|
378
|
-
name="tags"
|
|
379
|
-
label="Tags"
|
|
380
|
-
value={form.tags}
|
|
381
|
-
onChange={(val) => setField('tags', val)}
|
|
382
|
-
options={tags}
|
|
383
|
-
optionLabel="name"
|
|
384
|
-
optionValue="id"
|
|
385
|
-
multiple
|
|
386
|
-
placeholder="Select tags..."
|
|
387
|
-
/>
|
|
388
|
-
|
|
389
|
-
// Infinite scroll pagination
|
|
390
|
-
const [items, setItems] = useState([]);
|
|
391
|
-
const [page, setPage] = useState(1);
|
|
392
|
-
const [hasMore, setHasMore] = useState(true);
|
|
393
|
-
const [loadingMore, setLoadingMore] = useState(false);
|
|
394
|
-
|
|
395
|
-
const loadMore = async () => {
|
|
396
|
-
const next = page + 1;
|
|
397
|
-
const results = await fetchItems({ page: next });
|
|
398
|
-
setItems((prev) => [...prev, ...results.data]);
|
|
399
|
-
setHasMore(results.hasMore);
|
|
400
|
-
setPage(next);
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
<QSearchSelect
|
|
404
|
-
name="item_id"
|
|
405
|
-
label="Item"
|
|
406
|
-
value={form.item_id}
|
|
407
|
-
onChange={(val) => setField('item_id', val)}
|
|
408
|
-
options={items}
|
|
409
|
-
onLoadMore={loadMore}
|
|
410
|
-
hasMore={hasMore}
|
|
411
|
-
loadingMore={loadingMore}
|
|
412
|
-
/>
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
---
|
|
416
|
-
|
|
417
|
-
## QSwitch
|
|
418
|
-
|
|
419
|
-
Toggle switch for boolean values, built on the Radix `Switch` primitive.
|
|
420
|
-
|
|
421
|
-
### Props
|
|
422
|
-
|
|
423
|
-
| Prop | Type | Default | Description |
|
|
424
|
-
|------|------|---------|-------------|
|
|
425
|
-
| `label` | `string` | - | Label text |
|
|
426
|
-
| `description` | `string` | - | Helper text below the label |
|
|
427
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
428
|
-
| `error` | `string` | - | Error message |
|
|
429
|
-
| `checked` | `boolean` | `false` | Switch state |
|
|
430
|
-
| `onChange` | `function` | - | State change handler — `(checked: boolean) => void` |
|
|
431
|
-
| `onCheckedChange` | `function` | - | Alternative handler name (Radix convention); both fire if both are passed |
|
|
432
|
-
| `className` | `string` | - | Classes on the outer flex container |
|
|
433
|
-
| `switchClassName` | `string` | - | Classes on the switch root |
|
|
434
|
-
| `switchThumbClassName` | `string` | - | Classes on the switch thumb |
|
|
435
|
-
| `...props` | - | - | Anything else (`disabled`, etc.) passes through to the underlying `Switch` |
|
|
436
|
-
|
|
437
|
-
### Usage
|
|
438
|
-
|
|
439
|
-
```jsx
|
|
440
|
-
import { QSwitch } from '@
|
|
441
|
-
|
|
442
|
-
<QSwitch
|
|
443
|
-
label="Active"
|
|
444
|
-
checked={form.is_active}
|
|
445
|
-
onChange={(val) => setField('is_active', val)}
|
|
446
|
-
/>
|
|
447
|
-
|
|
448
|
-
<QSwitch
|
|
449
|
-
label="Email Notifications"
|
|
450
|
-
description="Receive email notifications for new orders"
|
|
451
|
-
checked={form.email_notifications}
|
|
452
|
-
onChange={(val) => setField('email_notifications', val)}
|
|
453
|
-
disabled={!form.email_verified}
|
|
454
|
-
/>
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
---
|
|
458
|
-
|
|
459
|
-
## QCheckbox
|
|
460
|
-
|
|
461
|
-
Checkbox with label, built on the Radix `Checkbox` primitive.
|
|
462
|
-
|
|
463
|
-
### Props
|
|
464
|
-
|
|
465
|
-
| Prop | Type | Default | Description |
|
|
466
|
-
|------|------|---------|-------------|
|
|
467
|
-
| `label` | `string` | - | Label text |
|
|
468
|
-
| `description` | `string` | - | Helper text below the label |
|
|
469
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
470
|
-
| `error` | `string` | - | Error message |
|
|
471
|
-
| `checked` | `boolean` | `false` | Checkbox state |
|
|
472
|
-
| `onCheckedChange` | `function` | - | State change handler — `(checked: boolean) => void` |
|
|
473
|
-
| `className` | `string` | - | Classes on the outer flex container |
|
|
474
|
-
| `checkboxClassName` | `string` | - | Classes on the checkbox itself |
|
|
475
|
-
| `...props` | - | - | Anything else (`disabled`, etc.) passes through to the underlying `Checkbox` |
|
|
476
|
-
|
|
477
|
-
> **Use `onCheckedChange`, not `onChange`:** `QCheckbox` only wires up `onCheckedChange` (matching the underlying Radix `Checkbox` API) — passing `onChange` instead is silently ignored. There is also no built-in `indeterminate` prop.
|
|
478
|
-
|
|
479
|
-
### Usage
|
|
480
|
-
|
|
481
|
-
```jsx
|
|
482
|
-
import { QCheckbox } from '@
|
|
483
|
-
|
|
484
|
-
<QCheckbox
|
|
485
|
-
label="I agree to the terms and conditions"
|
|
486
|
-
checked={form.agree}
|
|
487
|
-
onCheckedChange={(val) => setField('agree', val)}
|
|
488
|
-
/>
|
|
489
|
-
|
|
490
|
-
// Checkbox group
|
|
491
|
-
const permissions = ['read', 'write', 'delete', 'admin'];
|
|
492
|
-
|
|
493
|
-
<div className="space-y-2">
|
|
494
|
-
<label className="text-sm font-medium">Permissions</label>
|
|
495
|
-
{permissions.map((perm) => (
|
|
496
|
-
<QCheckbox
|
|
497
|
-
key={perm}
|
|
498
|
-
label={perm.charAt(0).toUpperCase() + perm.slice(1)}
|
|
499
|
-
checked={form.permissions?.includes(perm)}
|
|
500
|
-
onCheckedChange={(checked) => {
|
|
501
|
-
const newPerms = checked
|
|
502
|
-
? [...(form.permissions || []), perm]
|
|
503
|
-
: form.permissions?.filter((p) => p !== perm);
|
|
504
|
-
setField('permissions', newPerms);
|
|
505
|
-
}}
|
|
506
|
-
/>
|
|
507
|
-
))}
|
|
508
|
-
</div>
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
---
|
|
512
|
-
|
|
513
|
-
## QForm
|
|
514
|
-
|
|
515
|
-
Thin `<form>` wrapper that calls `preventDefault()` for you before invoking `onSubmit`.
|
|
516
|
-
|
|
517
|
-
### Props
|
|
518
|
-
|
|
519
|
-
| Prop | Type | Default | Description |
|
|
520
|
-
|------|------|---------|-------------|
|
|
521
|
-
| `onSubmit` | `function` | - | Called with the (already `preventDefault`-ed) submit event: `(e) => void` |
|
|
522
|
-
| `className` | `string` | - | Classes on the `<form>` (defaults include `space-y-4`) |
|
|
523
|
-
| `children` | `node` | - | Form fields |
|
|
524
|
-
| `...props` | - | - | Anything else passes through to the native `<form>` element |
|
|
525
|
-
|
|
526
|
-
### Usage
|
|
527
|
-
|
|
528
|
-
```jsx
|
|
529
|
-
import { QForm, QInput } from '@
|
|
530
|
-
|
|
531
|
-
<QForm onSubmit={() => handleSave(form)}>
|
|
532
|
-
<QInput name="name" label="Name" value={form.name} onChange={(v) => setField('name', v)} />
|
|
533
|
-
<button type="submit">Save</button>
|
|
534
|
-
</QForm>
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
---
|
|
538
|
-
|
|
539
|
-
## QDatePicker
|
|
540
|
-
|
|
541
|
-
Single date picker combining a typeable `yyyy-MM-dd` text field with a calendar popover, wrapped in [`FormField`](#formfield).
|
|
542
|
-
|
|
543
|
-
### Props
|
|
544
|
-
|
|
545
|
-
| Prop | Type | Default | Description |
|
|
546
|
-
|------|------|---------|-------------|
|
|
547
|
-
| `label` | `string` | - | Label text |
|
|
548
|
-
| `description` | `string` | - | Helper text |
|
|
549
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
550
|
-
| `error` | `string` | - | Error message |
|
|
551
|
-
| `required` | `boolean` | `false` | Mark as required |
|
|
552
|
-
| `value` | `Date \| string` | - | Selected date. Accepts a `Date`, a `yyyy-MM-dd` string, or an ISO string |
|
|
553
|
-
| `onChange` | `function` | - | Change handler — `(value: string | undefined) => void`. See output format below |
|
|
554
|
-
| `placeholder` | `string` | `'Pick a date'` | Placeholder shown when empty |
|
|
555
|
-
| `clearable` | `boolean` | `true` | Show a clear (`×`) button once a date is selected |
|
|
556
|
-
| `sendUTC` | `boolean` | `false` | Changes the `onChange` output format — see below |
|
|
557
|
-
| `minDate` / `maxDate` | `Date \| string` | - | Disables calendar days outside this range and rejects typed dates outside it (shows an inline error under the field) |
|
|
558
|
-
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
559
|
-
| `...props` | - | - | Anything else passes through to the underlying trigger button |
|
|
560
|
-
|
|
561
|
-
### Output format
|
|
562
|
-
|
|
563
|
-
`onChange` is always called with a **string**, never a `Date` object:
|
|
564
|
-
- `sendUTC={false}` (default): `'yyyy-MM-dd'`, e.g. `'2026-07-12'`
|
|
565
|
-
- `sendUTC={true}`: a full UTC ISO string, e.g. `'2026-07-12T00:00:00.000Z'`
|
|
566
|
-
|
|
567
|
-
There is no `format` prop — the input/output format is fixed as above; only the *displayed* calendar month/labels use `date-fns` formatting internally.
|
|
568
|
-
|
|
569
|
-
### Usage
|
|
570
|
-
|
|
571
|
-
```jsx
|
|
572
|
-
import { QDatePicker } from '@
|
|
573
|
-
|
|
574
|
-
<QDatePicker
|
|
575
|
-
name="date"
|
|
576
|
-
label="Event Date"
|
|
577
|
-
value={form.date}
|
|
578
|
-
onChange={(val) => setField('date', val)}
|
|
579
|
-
/>
|
|
580
|
-
|
|
581
|
-
// With min/max bounds
|
|
582
|
-
<QDatePicker
|
|
583
|
-
name="start_date"
|
|
584
|
-
label="Start Date"
|
|
585
|
-
value={form.start_date}
|
|
586
|
-
onChange={(val) => setField('start_date', val)}
|
|
587
|
-
minDate={new Date()}
|
|
588
|
-
maxDate={new Date(2027, 11, 31)}
|
|
589
|
-
/>
|
|
590
|
-
|
|
591
|
-
// Send full UTC timestamps instead of yyyy-MM-dd
|
|
592
|
-
<QDatePicker
|
|
593
|
-
name="published_at"
|
|
594
|
-
label="Publish Date"
|
|
595
|
-
value={form.published_at}
|
|
596
|
-
onChange={(val) => setField('published_at', val)}
|
|
597
|
-
sendUTC
|
|
598
|
-
/>
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
---
|
|
602
|
-
|
|
603
|
-
## QDateRangePicker
|
|
604
|
-
|
|
605
|
-
Date range picker with quick presets (last 7 days, this month, etc.) and a click-twice range selection in the calendar, wrapped in [`FormField`](#formfield).
|
|
606
|
-
|
|
607
|
-
### Props
|
|
608
|
-
|
|
609
|
-
| Prop | Type | Default | Description |
|
|
610
|
-
|------|------|---------|-------------|
|
|
611
|
-
| `label` | `string` | - | Label text |
|
|
612
|
-
| `description` | `string` | - | Helper text |
|
|
613
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
614
|
-
| `error` | `string` | - | Error message |
|
|
615
|
-
| `required` | `boolean` | `false` | Mark as required |
|
|
616
|
-
| `value` | `{ from, to }` | - | Selected range |
|
|
617
|
-
| `onChange` | `function` | - | Change handler — `({ from, to }) => void`. See output format below |
|
|
618
|
-
| `placeholder` | `string` | `'Pick a date range'` | Placeholder shown when empty |
|
|
619
|
-
| `clearable` | `boolean` | `true` | Show a clear button once a range is selected |
|
|
620
|
-
| `sendUTC` | `boolean` | `false` | Changes the `onChange` output format — see below |
|
|
621
|
-
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
622
|
-
| `datePickerTriggerClassName` | `string` | - | Classes on the trigger button |
|
|
623
|
-
| `...props` | - | - | Anything else passes through to the underlying trigger button |
|
|
624
|
-
|
|
625
|
-
### Output format
|
|
626
|
-
|
|
627
|
-
The selection only commits when the user clicks **Apply** in the popover (picking two calendar days stages the range first). `onChange` then receives:
|
|
628
|
-
- `sendUTC={false}` (default): `{ from: 'yyyy-MM-dd', to: 'yyyy-MM-dd' }`
|
|
629
|
-
- `sendUTC={true}`: `{ from: ISOString, to: ISOString }`
|
|
630
|
-
|
|
631
|
-
> There is no `minDate`/`maxDate` support on `QDateRangePicker` (unlike `QDatePicker`) — all days are selectable.
|
|
632
|
-
|
|
633
|
-
### Usage
|
|
634
|
-
|
|
635
|
-
```jsx
|
|
636
|
-
import { QDateRangePicker } from '@
|
|
637
|
-
|
|
638
|
-
<QDateRangePicker
|
|
639
|
-
name="date_range"
|
|
640
|
-
label="Date Range"
|
|
641
|
-
value={form.date_range}
|
|
642
|
-
onChange={(val) => setField('date_range', val)}
|
|
643
|
-
/>
|
|
644
|
-
```
|
|
645
|
-
|
|
646
|
-
---
|
|
647
|
-
|
|
648
|
-
## QRichTextEditor
|
|
649
|
-
|
|
650
|
-
Rich text editor (built on [`suneditor-react`](https://github.com/mkhstar/suneditor-react)) with a full formatting toolbar, wrapped in [`FormField`](#formfield).
|
|
651
|
-
|
|
652
|
-
### Props
|
|
653
|
-
|
|
654
|
-
| Prop | Type | Default | Description |
|
|
655
|
-
|------|------|---------|-------------|
|
|
656
|
-
| `label` | `string` | - | Label text |
|
|
657
|
-
| `description` | `string` | - | Helper text |
|
|
658
|
-
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
659
|
-
| `error` | `string` | - | Error message |
|
|
660
|
-
| `required` | `boolean` | `false` | Mark as required |
|
|
661
|
-
| `value` | `string` | `''` | HTML content |
|
|
662
|
-
| `onChange` | `function` | - | Content change handler — `(html: string) => void` |
|
|
663
|
-
| `placeholder` | `string` | `'Start writing...'` | Placeholder text |
|
|
664
|
-
| `height` | `string` | `'200px'` | Editor height |
|
|
665
|
-
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
666
|
-
| `editorClassName` | `string` | - | Classes on the editor container |
|
|
667
|
-
| `editorToolbarClassName` | `string` | - | Classes on the toolbar |
|
|
668
|
-
| `...props` | - | - | Anything else passes through to `SunEditorReact` |
|
|
669
|
-
|
|
670
|
-
### Usage
|
|
671
|
-
|
|
672
|
-
```jsx
|
|
673
|
-
import { QRichTextEditor } from '@
|
|
674
|
-
|
|
675
|
-
<QRichTextEditor
|
|
676
|
-
name="content"
|
|
677
|
-
label="Content"
|
|
678
|
-
value={form.content}
|
|
679
|
-
onChange={(val) => setField('content', val)}
|
|
680
|
-
placeholder="Start writing your content..."
|
|
681
|
-
height="300px"
|
|
682
|
-
/>
|
|
683
|
-
```
|
|
684
|
-
|
|
685
|
-
### Toolbar Features
|
|
686
|
-
|
|
687
|
-
The editor includes a comprehensive toolbar with the following features:
|
|
688
|
-
|
|
689
|
-
- **Text Formatting**: Bold, italic, underline, strike, subscript, superscript
|
|
690
|
-
- **Font**: Font family, size, color, background color
|
|
691
|
-
- **Paragraph**: Headings, blockquotes, alignment, line height
|
|
692
|
-
- **Lists**: Ordered and unordered lists
|
|
693
|
-
- **Links**: Insert and edit links
|
|
694
|
-
- **Media**: Images, videos, audio files
|
|
695
|
-
- **Tables**: Create and edit tables
|
|
696
|
-
- **Code**: Code view, full screen mode
|
|
697
|
-
- **Templates**: Predefined templates
|
|
698
|
-
- **Undo/Redo**: History management
|
|
699
|
-
|
|
700
|
-
---
|
|
701
|
-
|
|
702
|
-
## Form Validation
|
|
703
|
-
|
|
704
|
-
### Client-Side Validation
|
|
705
|
-
|
|
706
|
-
Use the `onBeforeSubmit` prop to validate before submission:
|
|
707
|
-
|
|
708
|
-
```jsx
|
|
709
|
-
<CrudForm
|
|
710
|
-
onBeforeSubmit={(data) => {
|
|
711
|
-
const errors = {};
|
|
712
|
-
|
|
713
|
-
if (!data.name?.trim()) {
|
|
714
|
-
errors.name = 'Name is required';
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
if (!data.email?.trim()) {
|
|
718
|
-
errors.email = 'Email is required';
|
|
719
|
-
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) {
|
|
720
|
-
errors.email = 'Invalid email format';
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
if (Object.keys(errors).length > 0) {
|
|
724
|
-
// Set errors in store
|
|
725
|
-
setFormErrors(errors);
|
|
726
|
-
return false; // Prevent submission
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
return data; // Return transformed data
|
|
730
|
-
}}
|
|
731
|
-
>
|
|
732
|
-
{/* Form fields */}
|
|
733
|
-
</CrudForm>
|
|
734
|
-
```
|
|
735
|
-
|
|
736
|
-
### Server-Side Validation
|
|
737
|
-
|
|
738
|
-
Handle API validation errors:
|
|
739
|
-
|
|
740
|
-
```jsx
|
|
741
|
-
// In your store
|
|
742
|
-
create: async (data) => {
|
|
743
|
-
try {
|
|
744
|
-
const response = await api.post('/items', data);
|
|
745
|
-
return response.data;
|
|
746
|
-
} catch (error) {
|
|
747
|
-
if (error.response?.status === 422) {
|
|
748
|
-
// Validation errors
|
|
749
|
-
const errors = error.response.data.errors;
|
|
750
|
-
set({ form: { ...get().form, errors } });
|
|
751
|
-
}
|
|
752
|
-
throw error;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
```
|
|
756
|
-
|
|
757
|
-
### Form State Management
|
|
758
|
-
|
|
759
|
-
The store provides form state management:
|
|
760
|
-
|
|
761
|
-
```jsx
|
|
762
|
-
const store = useStore();
|
|
763
|
-
|
|
764
|
-
// Access form state
|
|
765
|
-
const { values, errors, loading } = store.form;
|
|
766
|
-
|
|
767
|
-
// Set field value
|
|
768
|
-
store.setFormField('name', 'New Value');
|
|
769
|
-
|
|
770
|
-
// Set multiple fields
|
|
771
|
-
store.setFormFields({ name: 'John', email: 'john@example.com' });
|
|
772
|
-
|
|
773
|
-
// Set errors
|
|
774
|
-
store.setFormErrors({ name: 'Required' });
|
|
775
|
-
|
|
776
|
-
// Reset form
|
|
777
|
-
store.resetForm();
|
|
778
|
-
```
|
|
1
|
+
# Form Components Guide
|
|
2
|
+
|
|
3
|
+
Complete reference for form field components in @bomjan133/react-crud-ui.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
1. [FormField](#formfield)
|
|
7
|
+
2. [QInput](#qinput)
|
|
8
|
+
3. [QTextarea](#qtextarea)
|
|
9
|
+
4. [QSelect](#qselect)
|
|
10
|
+
5. [QSearchSelect](#qsearchselect)
|
|
11
|
+
6. [QSwitch](#qswitch)
|
|
12
|
+
7. [QCheckbox](#qcheckbox)
|
|
13
|
+
8. [QForm](#qform)
|
|
14
|
+
9. [QDatePicker](#qdatepicker)
|
|
15
|
+
10. [QDateRangePicker](#qdaterangepicker)
|
|
16
|
+
11. [QRichTextEditor](#qrichtexteditor)
|
|
17
|
+
12. [Form Validation](#form-validation)
|
|
18
|
+
|
|
19
|
+
All `Q*` components (except `QInput`) are thin wrappers around [`FormField`](#formfield) plus a Radix/native primitive — they share the `label`/`description`/`error`/`required` props documented once below.
|
|
20
|
+
|
|
21
|
+
Every `Q*` component also accepts a `helpText` prop as an alias for `description` — pass whichever name reads better at the call site. If both are passed, `description` wins.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## FormField
|
|
26
|
+
|
|
27
|
+
The base wrapper every `Q*` component (other than `QInput`, which lays itself out manually) renders through. Use it directly if you're wrapping a custom input that isn't covered by the `Q*` components.
|
|
28
|
+
|
|
29
|
+
### Props
|
|
30
|
+
|
|
31
|
+
| Prop | Type | Default | Description |
|
|
32
|
+
|------|------|---------|-------------|
|
|
33
|
+
| `label` | `string` | - | Label text |
|
|
34
|
+
| `description` | `string` | - | Helper text shown below the field (hidden while `error` is set) |
|
|
35
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
36
|
+
| `error` | `string` | - | Error message; when set, also adds destructive-color styling to the first child input |
|
|
37
|
+
| `required` | `boolean` | `false` | Shows a red `*` next to the label |
|
|
38
|
+
| `children` | `node` | - | The input element(s) to wrap. The **first** child automatically receives `id`, `aria-invalid`, and error border styling |
|
|
39
|
+
| `className` | `string` | - | Classes on the outer wrapper `div` |
|
|
40
|
+
| `labelClassName` | `string` | - | Classes on the `Label` |
|
|
41
|
+
| `descriptionClassName` | `string` | - | Classes on the description text |
|
|
42
|
+
| `errorClassName` | `string` | - | Classes on the error text |
|
|
43
|
+
|
|
44
|
+
### Usage
|
|
45
|
+
|
|
46
|
+
```jsx
|
|
47
|
+
import { FormField } from '@bomjan133/react-crud-ui';
|
|
48
|
+
|
|
49
|
+
<FormField label="Custom Field" description="Some helper text" error={errors.custom} required>
|
|
50
|
+
<MyCustomInput value={value} onChange={setValue} />
|
|
51
|
+
</FormField>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## QInput
|
|
57
|
+
|
|
58
|
+
Text/number input with label and error handling. Unlike the other `Q*` components, `QInput` does **not** use `FormField` — it has its own layout, and in `type="number"` mode it renders a full increment/decrement spinner instead of a plain `<input>`.
|
|
59
|
+
|
|
60
|
+
### Props
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
|------|------|---------|-------------|
|
|
64
|
+
| `label` | `string` | - | Label text |
|
|
65
|
+
| `description` | `string` | - | Helper text shown below the input (hidden while `error` is set) |
|
|
66
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
67
|
+
| `error` | `string` | - | Error message shown below the input |
|
|
68
|
+
| `required` | `boolean` | `false` | Adds a red `*` next to the label |
|
|
69
|
+
| `type` | `string` | - | Input type (`text`, `email`, `password`, `number`, etc.) — `'number'` switches to spinner mode |
|
|
70
|
+
| `value` | `string \| number` | - | Input value |
|
|
71
|
+
| `onChange` | `function` | - | Change handler. By default called with just the new value: `(value) => void`. Set `emitValue={false}` to instead receive the raw event: `(e) => void` |
|
|
72
|
+
| `emitValue` | `boolean` | `true` | Whether `onChange` receives the value directly vs. the raw event |
|
|
73
|
+
| `disabled` | `boolean` | `false` | Disable the input |
|
|
74
|
+
| `className` | `string` | - | Classes on the outer wrapper |
|
|
75
|
+
| `inputClassName` | `string` | - | Classes on the `<input>` itself |
|
|
76
|
+
| `containerClassName` | `string` | - | Classes on the input's relative-position container (number mode) |
|
|
77
|
+
| `buttonClassName` | `string` | - | Classes on the +/- spinner buttons (number mode only) |
|
|
78
|
+
| `labelClassName` / `descriptionClassName` / `errorClassName` | `string` | - | Classes for those respective parts |
|
|
79
|
+
| `icon` | `ReactNode` | - | Icon rendered inside the input (non-`number` mode only). When set, the input is wrapped in an `InputGroup` so the icon sits flush against the border |
|
|
80
|
+
| `iconPosition` | `'prefix' \| 'postfix'` | `'prefix'` | Where `icon` is placed — `'prefix'` renders it before the text, `'postfix'` renders it after |
|
|
81
|
+
| `...props` | - | - | Anything else (`name`, `placeholder`, `readOnly`, `onBlur`, etc.) passes through to the underlying `<input>` |
|
|
82
|
+
|
|
83
|
+
> **Not implemented:** `icon`/`iconPosition` have no effect in `type="number"` mode, since that mode renders its own increment/decrement spinner layout instead.
|
|
84
|
+
|
|
85
|
+
### Number mode props
|
|
86
|
+
|
|
87
|
+
Only apply when `type="number"`:
|
|
88
|
+
|
|
89
|
+
| Prop | Type | Default | Description |
|
|
90
|
+
|------|------|---------|-------------|
|
|
91
|
+
| `min` | `number` | `-Infinity` | Minimum value; also disables the decrement button at the floor |
|
|
92
|
+
| `max` | `number` | `Infinity` | Maximum value; also disables the increment button at the ceiling |
|
|
93
|
+
| `step` | `number` | `1` | Amount added/subtracted per spinner click |
|
|
94
|
+
| `allowNegative` | `boolean` | `false` | Allow negative values/typing a leading `-` |
|
|
95
|
+
| `width` | `string` | `'w-36'` | Tailwind width class applied to the numeric `<input>` between the spinner buttons |
|
|
96
|
+
|
|
97
|
+
`onChange` in number mode always emits a `number` (not a string), including on blur, where partial/empty input is normalized to `0` (or `min`, if `min > 0`).
|
|
98
|
+
|
|
99
|
+
### Usage
|
|
100
|
+
|
|
101
|
+
```jsx
|
|
102
|
+
import { QInput } from '@bomjan133/react-crud-ui';
|
|
103
|
+
|
|
104
|
+
// Basic text input
|
|
105
|
+
<QInput
|
|
106
|
+
name="name"
|
|
107
|
+
label="Full Name"
|
|
108
|
+
value={form.name}
|
|
109
|
+
onChange={(val) => setField('name', val)}
|
|
110
|
+
placeholder="Enter your name"
|
|
111
|
+
required
|
|
112
|
+
/>
|
|
113
|
+
|
|
114
|
+
// With error
|
|
115
|
+
<QInput
|
|
116
|
+
name="email"
|
|
117
|
+
label="Email"
|
|
118
|
+
type="email"
|
|
119
|
+
value={form.email}
|
|
120
|
+
onChange={(val) => setField('email', val)}
|
|
121
|
+
error={errors.email}
|
|
122
|
+
placeholder="Enter email address"
|
|
123
|
+
/>
|
|
124
|
+
|
|
125
|
+
// Number input with spinner, bounds, and step
|
|
126
|
+
<QInput
|
|
127
|
+
name="quantity"
|
|
128
|
+
label="Quantity"
|
|
129
|
+
type="number"
|
|
130
|
+
value={form.quantity}
|
|
131
|
+
onChange={(val) => setField('quantity', val)}
|
|
132
|
+
min={1}
|
|
133
|
+
max={100}
|
|
134
|
+
step={1}
|
|
135
|
+
/>
|
|
136
|
+
|
|
137
|
+
// Number input allowing negative values
|
|
138
|
+
<QInput
|
|
139
|
+
name="adjustment"
|
|
140
|
+
label="Stock Adjustment"
|
|
141
|
+
type="number"
|
|
142
|
+
value={form.adjustment}
|
|
143
|
+
onChange={(val) => setField('adjustment', val)}
|
|
144
|
+
allowNegative
|
|
145
|
+
/>
|
|
146
|
+
|
|
147
|
+
// Receive the raw event instead of the value
|
|
148
|
+
<QInput
|
|
149
|
+
name="search"
|
|
150
|
+
label="Search"
|
|
151
|
+
value={form.search}
|
|
152
|
+
onChange={(e) => handleRawEvent(e)}
|
|
153
|
+
emitValue={false}
|
|
154
|
+
/>
|
|
155
|
+
|
|
156
|
+
// With a prefix icon
|
|
157
|
+
<QInput
|
|
158
|
+
name="search"
|
|
159
|
+
label="Search"
|
|
160
|
+
value={form.search}
|
|
161
|
+
onChange={(val) => setField('search', val)}
|
|
162
|
+
icon={<SearchIcon />}
|
|
163
|
+
iconPosition="prefix"
|
|
164
|
+
placeholder="Search..."
|
|
165
|
+
/>
|
|
166
|
+
|
|
167
|
+
// With a postfix icon
|
|
168
|
+
<QInput
|
|
169
|
+
name="email"
|
|
170
|
+
label="Email"
|
|
171
|
+
type="email"
|
|
172
|
+
value={form.email}
|
|
173
|
+
onChange={(val) => setField('email', val)}
|
|
174
|
+
icon={<MailIcon />}
|
|
175
|
+
iconPosition="postfix"
|
|
176
|
+
/>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## QTextarea
|
|
182
|
+
|
|
183
|
+
Multi-line text input, wrapped in [`FormField`](#formfield).
|
|
184
|
+
|
|
185
|
+
### Props
|
|
186
|
+
|
|
187
|
+
| Prop | Type | Default | Description |
|
|
188
|
+
|------|------|---------|-------------|
|
|
189
|
+
| `label` | `string` | - | Label text |
|
|
190
|
+
| `description` | `string` | - | Helper text |
|
|
191
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
192
|
+
| `error` | `string` | - | Error message |
|
|
193
|
+
| `required` | `boolean` | `false` | Mark as required |
|
|
194
|
+
| `value` | `string` | - | Input value |
|
|
195
|
+
| `onChange` | `function` | - | Change handler — `(value) => void` by default, `(e) => void` if `emitValue={false}` |
|
|
196
|
+
| `emitValue` | `boolean` | `true` | Whether `onChange` receives the value directly vs. the raw event |
|
|
197
|
+
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
198
|
+
| `textareaClassName` | `string` | - | Classes on the `<textarea>` itself |
|
|
199
|
+
| `...props` | - | - | Anything else (`rows`, `placeholder`, `disabled`, `maxLength`, etc.) passes through to the underlying `<textarea>` as native HTML attributes |
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
### Usage
|
|
203
|
+
|
|
204
|
+
```jsx
|
|
205
|
+
import { QTextarea } from '@bomjan133/react-crud-ui';
|
|
206
|
+
|
|
207
|
+
// Basic textarea
|
|
208
|
+
<QTextarea
|
|
209
|
+
name="description"
|
|
210
|
+
label="Description"
|
|
211
|
+
value={form.description}
|
|
212
|
+
onChange={(val) => setField('description', val)}
|
|
213
|
+
placeholder="Enter description"
|
|
214
|
+
rows={4}
|
|
215
|
+
/>
|
|
216
|
+
|
|
217
|
+
// With a manual character count
|
|
218
|
+
<QTextarea
|
|
219
|
+
name="bio"
|
|
220
|
+
label="Bio"
|
|
221
|
+
value={form.bio}
|
|
222
|
+
onChange={(val) => setField('bio', val)}
|
|
223
|
+
maxLength={500}
|
|
224
|
+
placeholder="Tell us about yourself..."
|
|
225
|
+
description={`${form.bio?.length ?? 0}/500`}
|
|
226
|
+
/>
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## QSelect
|
|
232
|
+
|
|
233
|
+
Dropdown select (built on the Radix `Select` primitive) for choosing a single value from a static list, wrapped in [`FormField`](#formfield).
|
|
234
|
+
|
|
235
|
+
### Props
|
|
236
|
+
|
|
237
|
+
| Prop | Type | Default | Description |
|
|
238
|
+
|------|------|---------|-------------|
|
|
239
|
+
| `label` | `string` | - | Label text |
|
|
240
|
+
| `description` | `string` | - | Helper text |
|
|
241
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
242
|
+
| `error` | `string` | - | Error message |
|
|
243
|
+
| `required` | `boolean` | `false` | Mark as required |
|
|
244
|
+
| `options` | `array` | `[]` | Array of options (objects or primitives) |
|
|
245
|
+
| `value` | `any` | - | Selected value (compared as a string internally) |
|
|
246
|
+
| `onChange` | `function` | - | Value change handler — `(value: string) => void` |
|
|
247
|
+
| `optionLabel` | `string \| function` | - | Key name, or `(option) => label`, for display text. Falls back to `option.label ?? option.name ?? String(option)` |
|
|
248
|
+
| `optionValue` | `string \| function` | - | Key name, or `(option) => value`, for the option's value. Falls back to `option.value ?? option.id ?? option` |
|
|
249
|
+
| `getOptionLabel` | `function` | - | Alternative to `optionLabel` — takes precedence if both are given |
|
|
250
|
+
| `getOptionValue` | `function` | - | Alternative to `optionValue` — takes precedence if both are given |
|
|
251
|
+
| `placeholder` | `string` | `'Select...'` | Placeholder text |
|
|
252
|
+
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
253
|
+
| `selectTriggerClassName` | `string` | - | Classes on the trigger button |
|
|
254
|
+
| `selectContentClassName` | `string` | - | Classes on the dropdown content panel |
|
|
255
|
+
| `selectItemClassName` | `string` | - | Classes on each option item |
|
|
256
|
+
| `...props` | - | - | Anything else (`disabled`, etc.) passes through to the underlying Radix `Select` |
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
### Usage
|
|
260
|
+
|
|
261
|
+
```jsx
|
|
262
|
+
import { QSelect } from '@bomjan133/react-crud-ui';
|
|
263
|
+
|
|
264
|
+
// With simple options
|
|
265
|
+
const statusOptions = [
|
|
266
|
+
{ value: 'active', label: 'Active' },
|
|
267
|
+
{ value: 'inactive', label: 'Inactive' },
|
|
268
|
+
{ value: 'pending', label: 'Pending' },
|
|
269
|
+
];
|
|
270
|
+
|
|
271
|
+
<QSelect
|
|
272
|
+
name="status"
|
|
273
|
+
label="Status"
|
|
274
|
+
value={form.status}
|
|
275
|
+
onChange={(val) => setField('status', val)}
|
|
276
|
+
options={statusOptions}
|
|
277
|
+
placeholder="Select status"
|
|
278
|
+
/>
|
|
279
|
+
|
|
280
|
+
// With object options and a custom key
|
|
281
|
+
const categories = [
|
|
282
|
+
{ id: 1, name: 'Electronics' },
|
|
283
|
+
{ id: 2, name: 'Clothing' },
|
|
284
|
+
{ id: 3, name: 'Books' },
|
|
285
|
+
];
|
|
286
|
+
|
|
287
|
+
<QSelect
|
|
288
|
+
name="category_id"
|
|
289
|
+
label="Category"
|
|
290
|
+
value={form.category_id}
|
|
291
|
+
onChange={(val) => setField('category_id', val)}
|
|
292
|
+
options={categories}
|
|
293
|
+
optionLabel="name"
|
|
294
|
+
optionValue="id"
|
|
295
|
+
placeholder="Select category"
|
|
296
|
+
/>
|
|
297
|
+
|
|
298
|
+
// With function-based getters
|
|
299
|
+
<QSelect
|
|
300
|
+
name="user_id"
|
|
301
|
+
label="Assigned To"
|
|
302
|
+
value={form.user_id}
|
|
303
|
+
onChange={(val) => setField('user_id', val)}
|
|
304
|
+
options={users}
|
|
305
|
+
getOptionLabel={(u) => `${u.firstName} ${u.lastName}`}
|
|
306
|
+
getOptionValue={(u) => u.id}
|
|
307
|
+
error={errors.user_id}
|
|
308
|
+
required
|
|
309
|
+
/>
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## QSearchSelect
|
|
315
|
+
|
|
316
|
+
Searchable select with client-side filtering, async search, multi-select, and infinite-scroll pagination — built on the custom `SearchSelect` primitive, wrapped in [`FormField`](#formfield).
|
|
317
|
+
|
|
318
|
+
### Props
|
|
319
|
+
|
|
320
|
+
| Prop | Type | Default | Description |
|
|
321
|
+
|------|------|---------|-------------|
|
|
322
|
+
| `label` | `string` | - | Label text |
|
|
323
|
+
| `description` | `string` | - | Helper text |
|
|
324
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
325
|
+
| `error` | `string` | - | Error message |
|
|
326
|
+
| `required` | `boolean` | `false` | Mark as required |
|
|
327
|
+
| `value` | `any` | - | Selected value — a single value normally, an array when `multiple` |
|
|
328
|
+
| `onChange` | `function` | - | Change handler. Single mode: `(value) => void`. Multi mode: `(values: array) => void` |
|
|
329
|
+
| `options` | `array` | `[]` | Array of options (objects or primitives) |
|
|
330
|
+
| `optionLabel` / `optionValue` | `string \| function` | - | Same resolution rules as [`QSelect`](#qselect) |
|
|
331
|
+
| `getOptionLabel` / `getOptionValue` | `function` | - | Same as `QSelect` — take precedence over `optionLabel`/`optionValue` |
|
|
332
|
+
| `onSearch` | `function` | - | Debounced (300ms) search handler — `(query: string) => void`. Use this to trigger an async fetch and update `options` |
|
|
333
|
+
| `multiple` | `boolean` | `false` | Allow multiple selections; `onChange`/`value` become arrays |
|
|
334
|
+
| `onLoadMore` | `function` | - | `() => Promise` — called when the dropdown list is scrolled near the bottom, for infinite-scroll pagination |
|
|
335
|
+
| `hasMore` | `boolean` | `false` | Whether more pages are available (controls whether `onLoadMore` can fire again) |
|
|
336
|
+
| `loadingMore` | `boolean` | `false` | Shows a loading row at the bottom of the list while a `onLoadMore` page is in flight |
|
|
337
|
+
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
338
|
+
| `searchSelectClassName` | `string` | - | Classes on the `SearchSelect` root |
|
|
339
|
+
| `searchSelectTriggerClassName` | `string` | - | Classes on the trigger button |
|
|
340
|
+
| `...props` | - | - | Anything else (`loading`, `disabled`, `renderOption`, `renderValue`, `filterOption`, `noOptionsMessage`, `loadingMessage`, etc.) passes through to the underlying `SearchSelect` |
|
|
341
|
+
|
|
342
|
+
> **Selection survives search filtering:** `QSearchSelect` internally caches every full option object it has ever seen (by value), so a previously-selected item keeps displaying its label even if it later scrolls out of the current (filtered or paginated) `options` list.
|
|
343
|
+
|
|
344
|
+
### Usage
|
|
345
|
+
|
|
346
|
+
```jsx
|
|
347
|
+
import { QSearchSelect } from '@bomjan133/react-crud-ui';
|
|
348
|
+
import { searchUsers } from '@/api';
|
|
349
|
+
|
|
350
|
+
// Async search select
|
|
351
|
+
const [users, setUsers] = useState([]);
|
|
352
|
+
const [loading, setLoading] = useState(false);
|
|
353
|
+
|
|
354
|
+
const handleUserSearch = async (query) => {
|
|
355
|
+
setLoading(true);
|
|
356
|
+
try {
|
|
357
|
+
setUsers(await searchUsers(query));
|
|
358
|
+
} finally {
|
|
359
|
+
setLoading(false);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
<QSearchSelect
|
|
364
|
+
name="user_id"
|
|
365
|
+
label="Assign User"
|
|
366
|
+
value={form.user_id}
|
|
367
|
+
onChange={(val) => setField('user_id', val)}
|
|
368
|
+
options={users}
|
|
369
|
+
optionLabel="name"
|
|
370
|
+
optionValue="id"
|
|
371
|
+
onSearch={handleUserSearch}
|
|
372
|
+
loading={loading}
|
|
373
|
+
placeholder="Search users..."
|
|
374
|
+
/>
|
|
375
|
+
|
|
376
|
+
// Multiple selection
|
|
377
|
+
<QSearchSelect
|
|
378
|
+
name="tags"
|
|
379
|
+
label="Tags"
|
|
380
|
+
value={form.tags}
|
|
381
|
+
onChange={(val) => setField('tags', val)}
|
|
382
|
+
options={tags}
|
|
383
|
+
optionLabel="name"
|
|
384
|
+
optionValue="id"
|
|
385
|
+
multiple
|
|
386
|
+
placeholder="Select tags..."
|
|
387
|
+
/>
|
|
388
|
+
|
|
389
|
+
// Infinite scroll pagination
|
|
390
|
+
const [items, setItems] = useState([]);
|
|
391
|
+
const [page, setPage] = useState(1);
|
|
392
|
+
const [hasMore, setHasMore] = useState(true);
|
|
393
|
+
const [loadingMore, setLoadingMore] = useState(false);
|
|
394
|
+
|
|
395
|
+
const loadMore = async () => {
|
|
396
|
+
const next = page + 1;
|
|
397
|
+
const results = await fetchItems({ page: next });
|
|
398
|
+
setItems((prev) => [...prev, ...results.data]);
|
|
399
|
+
setHasMore(results.hasMore);
|
|
400
|
+
setPage(next);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
<QSearchSelect
|
|
404
|
+
name="item_id"
|
|
405
|
+
label="Item"
|
|
406
|
+
value={form.item_id}
|
|
407
|
+
onChange={(val) => setField('item_id', val)}
|
|
408
|
+
options={items}
|
|
409
|
+
onLoadMore={loadMore}
|
|
410
|
+
hasMore={hasMore}
|
|
411
|
+
loadingMore={loadingMore}
|
|
412
|
+
/>
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## QSwitch
|
|
418
|
+
|
|
419
|
+
Toggle switch for boolean values, built on the Radix `Switch` primitive.
|
|
420
|
+
|
|
421
|
+
### Props
|
|
422
|
+
|
|
423
|
+
| Prop | Type | Default | Description |
|
|
424
|
+
|------|------|---------|-------------|
|
|
425
|
+
| `label` | `string` | - | Label text |
|
|
426
|
+
| `description` | `string` | - | Helper text below the label |
|
|
427
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
428
|
+
| `error` | `string` | - | Error message |
|
|
429
|
+
| `checked` | `boolean` | `false` | Switch state |
|
|
430
|
+
| `onChange` | `function` | - | State change handler — `(checked: boolean) => void` |
|
|
431
|
+
| `onCheckedChange` | `function` | - | Alternative handler name (Radix convention); both fire if both are passed |
|
|
432
|
+
| `className` | `string` | - | Classes on the outer flex container |
|
|
433
|
+
| `switchClassName` | `string` | - | Classes on the switch root |
|
|
434
|
+
| `switchThumbClassName` | `string` | - | Classes on the switch thumb |
|
|
435
|
+
| `...props` | - | - | Anything else (`disabled`, etc.) passes through to the underlying `Switch` |
|
|
436
|
+
|
|
437
|
+
### Usage
|
|
438
|
+
|
|
439
|
+
```jsx
|
|
440
|
+
import { QSwitch } from '@bomjan133/react-crud-ui';
|
|
441
|
+
|
|
442
|
+
<QSwitch
|
|
443
|
+
label="Active"
|
|
444
|
+
checked={form.is_active}
|
|
445
|
+
onChange={(val) => setField('is_active', val)}
|
|
446
|
+
/>
|
|
447
|
+
|
|
448
|
+
<QSwitch
|
|
449
|
+
label="Email Notifications"
|
|
450
|
+
description="Receive email notifications for new orders"
|
|
451
|
+
checked={form.email_notifications}
|
|
452
|
+
onChange={(val) => setField('email_notifications', val)}
|
|
453
|
+
disabled={!form.email_verified}
|
|
454
|
+
/>
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
---
|
|
458
|
+
|
|
459
|
+
## QCheckbox
|
|
460
|
+
|
|
461
|
+
Checkbox with label, built on the Radix `Checkbox` primitive.
|
|
462
|
+
|
|
463
|
+
### Props
|
|
464
|
+
|
|
465
|
+
| Prop | Type | Default | Description |
|
|
466
|
+
|------|------|---------|-------------|
|
|
467
|
+
| `label` | `string` | - | Label text |
|
|
468
|
+
| `description` | `string` | - | Helper text below the label |
|
|
469
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
470
|
+
| `error` | `string` | - | Error message |
|
|
471
|
+
| `checked` | `boolean` | `false` | Checkbox state |
|
|
472
|
+
| `onCheckedChange` | `function` | - | State change handler — `(checked: boolean) => void` |
|
|
473
|
+
| `className` | `string` | - | Classes on the outer flex container |
|
|
474
|
+
| `checkboxClassName` | `string` | - | Classes on the checkbox itself |
|
|
475
|
+
| `...props` | - | - | Anything else (`disabled`, etc.) passes through to the underlying `Checkbox` |
|
|
476
|
+
|
|
477
|
+
> **Use `onCheckedChange`, not `onChange`:** `QCheckbox` only wires up `onCheckedChange` (matching the underlying Radix `Checkbox` API) — passing `onChange` instead is silently ignored. There is also no built-in `indeterminate` prop.
|
|
478
|
+
|
|
479
|
+
### Usage
|
|
480
|
+
|
|
481
|
+
```jsx
|
|
482
|
+
import { QCheckbox } from '@bomjan133/react-crud-ui';
|
|
483
|
+
|
|
484
|
+
<QCheckbox
|
|
485
|
+
label="I agree to the terms and conditions"
|
|
486
|
+
checked={form.agree}
|
|
487
|
+
onCheckedChange={(val) => setField('agree', val)}
|
|
488
|
+
/>
|
|
489
|
+
|
|
490
|
+
// Checkbox group
|
|
491
|
+
const permissions = ['read', 'write', 'delete', 'admin'];
|
|
492
|
+
|
|
493
|
+
<div className="space-y-2">
|
|
494
|
+
<label className="text-sm font-medium">Permissions</label>
|
|
495
|
+
{permissions.map((perm) => (
|
|
496
|
+
<QCheckbox
|
|
497
|
+
key={perm}
|
|
498
|
+
label={perm.charAt(0).toUpperCase() + perm.slice(1)}
|
|
499
|
+
checked={form.permissions?.includes(perm)}
|
|
500
|
+
onCheckedChange={(checked) => {
|
|
501
|
+
const newPerms = checked
|
|
502
|
+
? [...(form.permissions || []), perm]
|
|
503
|
+
: form.permissions?.filter((p) => p !== perm);
|
|
504
|
+
setField('permissions', newPerms);
|
|
505
|
+
}}
|
|
506
|
+
/>
|
|
507
|
+
))}
|
|
508
|
+
</div>
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
---
|
|
512
|
+
|
|
513
|
+
## QForm
|
|
514
|
+
|
|
515
|
+
Thin `<form>` wrapper that calls `preventDefault()` for you before invoking `onSubmit`.
|
|
516
|
+
|
|
517
|
+
### Props
|
|
518
|
+
|
|
519
|
+
| Prop | Type | Default | Description |
|
|
520
|
+
|------|------|---------|-------------|
|
|
521
|
+
| `onSubmit` | `function` | - | Called with the (already `preventDefault`-ed) submit event: `(e) => void` |
|
|
522
|
+
| `className` | `string` | - | Classes on the `<form>` (defaults include `space-y-4`) |
|
|
523
|
+
| `children` | `node` | - | Form fields |
|
|
524
|
+
| `...props` | - | - | Anything else passes through to the native `<form>` element |
|
|
525
|
+
|
|
526
|
+
### Usage
|
|
527
|
+
|
|
528
|
+
```jsx
|
|
529
|
+
import { QForm, QInput } from '@bomjan133/react-crud-ui';
|
|
530
|
+
|
|
531
|
+
<QForm onSubmit={() => handleSave(form)}>
|
|
532
|
+
<QInput name="name" label="Name" value={form.name} onChange={(v) => setField('name', v)} />
|
|
533
|
+
<button type="submit">Save</button>
|
|
534
|
+
</QForm>
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
---
|
|
538
|
+
|
|
539
|
+
## QDatePicker
|
|
540
|
+
|
|
541
|
+
Single date picker combining a typeable `yyyy-MM-dd` text field with a calendar popover, wrapped in [`FormField`](#formfield).
|
|
542
|
+
|
|
543
|
+
### Props
|
|
544
|
+
|
|
545
|
+
| Prop | Type | Default | Description |
|
|
546
|
+
|------|------|---------|-------------|
|
|
547
|
+
| `label` | `string` | - | Label text |
|
|
548
|
+
| `description` | `string` | - | Helper text |
|
|
549
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
550
|
+
| `error` | `string` | - | Error message |
|
|
551
|
+
| `required` | `boolean` | `false` | Mark as required |
|
|
552
|
+
| `value` | `Date \| string` | - | Selected date. Accepts a `Date`, a `yyyy-MM-dd` string, or an ISO string |
|
|
553
|
+
| `onChange` | `function` | - | Change handler — `(value: string | undefined) => void`. See output format below |
|
|
554
|
+
| `placeholder` | `string` | `'Pick a date'` | Placeholder shown when empty |
|
|
555
|
+
| `clearable` | `boolean` | `true` | Show a clear (`×`) button once a date is selected |
|
|
556
|
+
| `sendUTC` | `boolean` | `false` | Changes the `onChange` output format — see below |
|
|
557
|
+
| `minDate` / `maxDate` | `Date \| string` | - | Disables calendar days outside this range and rejects typed dates outside it (shows an inline error under the field) |
|
|
558
|
+
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
559
|
+
| `...props` | - | - | Anything else passes through to the underlying trigger button |
|
|
560
|
+
|
|
561
|
+
### Output format
|
|
562
|
+
|
|
563
|
+
`onChange` is always called with a **string**, never a `Date` object:
|
|
564
|
+
- `sendUTC={false}` (default): `'yyyy-MM-dd'`, e.g. `'2026-07-12'`
|
|
565
|
+
- `sendUTC={true}`: a full UTC ISO string, e.g. `'2026-07-12T00:00:00.000Z'`
|
|
566
|
+
|
|
567
|
+
There is no `format` prop — the input/output format is fixed as above; only the *displayed* calendar month/labels use `date-fns` formatting internally.
|
|
568
|
+
|
|
569
|
+
### Usage
|
|
570
|
+
|
|
571
|
+
```jsx
|
|
572
|
+
import { QDatePicker } from '@bomjan133/react-crud-ui';
|
|
573
|
+
|
|
574
|
+
<QDatePicker
|
|
575
|
+
name="date"
|
|
576
|
+
label="Event Date"
|
|
577
|
+
value={form.date}
|
|
578
|
+
onChange={(val) => setField('date', val)}
|
|
579
|
+
/>
|
|
580
|
+
|
|
581
|
+
// With min/max bounds
|
|
582
|
+
<QDatePicker
|
|
583
|
+
name="start_date"
|
|
584
|
+
label="Start Date"
|
|
585
|
+
value={form.start_date}
|
|
586
|
+
onChange={(val) => setField('start_date', val)}
|
|
587
|
+
minDate={new Date()}
|
|
588
|
+
maxDate={new Date(2027, 11, 31)}
|
|
589
|
+
/>
|
|
590
|
+
|
|
591
|
+
// Send full UTC timestamps instead of yyyy-MM-dd
|
|
592
|
+
<QDatePicker
|
|
593
|
+
name="published_at"
|
|
594
|
+
label="Publish Date"
|
|
595
|
+
value={form.published_at}
|
|
596
|
+
onChange={(val) => setField('published_at', val)}
|
|
597
|
+
sendUTC
|
|
598
|
+
/>
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
---
|
|
602
|
+
|
|
603
|
+
## QDateRangePicker
|
|
604
|
+
|
|
605
|
+
Date range picker with quick presets (last 7 days, this month, etc.) and a click-twice range selection in the calendar, wrapped in [`FormField`](#formfield).
|
|
606
|
+
|
|
607
|
+
### Props
|
|
608
|
+
|
|
609
|
+
| Prop | Type | Default | Description |
|
|
610
|
+
|------|------|---------|-------------|
|
|
611
|
+
| `label` | `string` | - | Label text |
|
|
612
|
+
| `description` | `string` | - | Helper text |
|
|
613
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
614
|
+
| `error` | `string` | - | Error message |
|
|
615
|
+
| `required` | `boolean` | `false` | Mark as required |
|
|
616
|
+
| `value` | `{ from, to }` | - | Selected range |
|
|
617
|
+
| `onChange` | `function` | - | Change handler — `({ from, to }) => void`. See output format below |
|
|
618
|
+
| `placeholder` | `string` | `'Pick a date range'` | Placeholder shown when empty |
|
|
619
|
+
| `clearable` | `boolean` | `true` | Show a clear button once a range is selected |
|
|
620
|
+
| `sendUTC` | `boolean` | `false` | Changes the `onChange` output format — see below |
|
|
621
|
+
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
622
|
+
| `datePickerTriggerClassName` | `string` | - | Classes on the trigger button |
|
|
623
|
+
| `...props` | - | - | Anything else passes through to the underlying trigger button |
|
|
624
|
+
|
|
625
|
+
### Output format
|
|
626
|
+
|
|
627
|
+
The selection only commits when the user clicks **Apply** in the popover (picking two calendar days stages the range first). `onChange` then receives:
|
|
628
|
+
- `sendUTC={false}` (default): `{ from: 'yyyy-MM-dd', to: 'yyyy-MM-dd' }`
|
|
629
|
+
- `sendUTC={true}`: `{ from: ISOString, to: ISOString }`
|
|
630
|
+
|
|
631
|
+
> There is no `minDate`/`maxDate` support on `QDateRangePicker` (unlike `QDatePicker`) — all days are selectable.
|
|
632
|
+
|
|
633
|
+
### Usage
|
|
634
|
+
|
|
635
|
+
```jsx
|
|
636
|
+
import { QDateRangePicker } from '@bomjan133/react-crud-ui';
|
|
637
|
+
|
|
638
|
+
<QDateRangePicker
|
|
639
|
+
name="date_range"
|
|
640
|
+
label="Date Range"
|
|
641
|
+
value={form.date_range}
|
|
642
|
+
onChange={(val) => setField('date_range', val)}
|
|
643
|
+
/>
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
---
|
|
647
|
+
|
|
648
|
+
## QRichTextEditor
|
|
649
|
+
|
|
650
|
+
Rich text editor (built on [`suneditor-react`](https://github.com/mkhstar/suneditor-react)) with a full formatting toolbar, wrapped in [`FormField`](#formfield).
|
|
651
|
+
|
|
652
|
+
### Props
|
|
653
|
+
|
|
654
|
+
| Prop | Type | Default | Description |
|
|
655
|
+
|------|------|---------|-------------|
|
|
656
|
+
| `label` | `string` | - | Label text |
|
|
657
|
+
| `description` | `string` | - | Helper text |
|
|
658
|
+
| `helpText` | `string` | - | Alias for `description` — used if `description` isn't passed |
|
|
659
|
+
| `error` | `string` | - | Error message |
|
|
660
|
+
| `required` | `boolean` | `false` | Mark as required |
|
|
661
|
+
| `value` | `string` | `''` | HTML content |
|
|
662
|
+
| `onChange` | `function` | - | Content change handler — `(html: string) => void` |
|
|
663
|
+
| `placeholder` | `string` | `'Start writing...'` | Placeholder text |
|
|
664
|
+
| `height` | `string` | `'200px'` | Editor height |
|
|
665
|
+
| `className` | `string` | - | Classes on the `FormField` wrapper |
|
|
666
|
+
| `editorClassName` | `string` | - | Classes on the editor container |
|
|
667
|
+
| `editorToolbarClassName` | `string` | - | Classes on the toolbar |
|
|
668
|
+
| `...props` | - | - | Anything else passes through to `SunEditorReact` |
|
|
669
|
+
|
|
670
|
+
### Usage
|
|
671
|
+
|
|
672
|
+
```jsx
|
|
673
|
+
import { QRichTextEditor } from '@bomjan133/react-crud-ui';
|
|
674
|
+
|
|
675
|
+
<QRichTextEditor
|
|
676
|
+
name="content"
|
|
677
|
+
label="Content"
|
|
678
|
+
value={form.content}
|
|
679
|
+
onChange={(val) => setField('content', val)}
|
|
680
|
+
placeholder="Start writing your content..."
|
|
681
|
+
height="300px"
|
|
682
|
+
/>
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
### Toolbar Features
|
|
686
|
+
|
|
687
|
+
The editor includes a comprehensive toolbar with the following features:
|
|
688
|
+
|
|
689
|
+
- **Text Formatting**: Bold, italic, underline, strike, subscript, superscript
|
|
690
|
+
- **Font**: Font family, size, color, background color
|
|
691
|
+
- **Paragraph**: Headings, blockquotes, alignment, line height
|
|
692
|
+
- **Lists**: Ordered and unordered lists
|
|
693
|
+
- **Links**: Insert and edit links
|
|
694
|
+
- **Media**: Images, videos, audio files
|
|
695
|
+
- **Tables**: Create and edit tables
|
|
696
|
+
- **Code**: Code view, full screen mode
|
|
697
|
+
- **Templates**: Predefined templates
|
|
698
|
+
- **Undo/Redo**: History management
|
|
699
|
+
|
|
700
|
+
---
|
|
701
|
+
|
|
702
|
+
## Form Validation
|
|
703
|
+
|
|
704
|
+
### Client-Side Validation
|
|
705
|
+
|
|
706
|
+
Use the `onBeforeSubmit` prop to validate before submission:
|
|
707
|
+
|
|
708
|
+
```jsx
|
|
709
|
+
<CrudForm
|
|
710
|
+
onBeforeSubmit={(data) => {
|
|
711
|
+
const errors = {};
|
|
712
|
+
|
|
713
|
+
if (!data.name?.trim()) {
|
|
714
|
+
errors.name = 'Name is required';
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (!data.email?.trim()) {
|
|
718
|
+
errors.email = 'Email is required';
|
|
719
|
+
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email)) {
|
|
720
|
+
errors.email = 'Invalid email format';
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (Object.keys(errors).length > 0) {
|
|
724
|
+
// Set errors in store
|
|
725
|
+
setFormErrors(errors);
|
|
726
|
+
return false; // Prevent submission
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
return data; // Return transformed data
|
|
730
|
+
}}
|
|
731
|
+
>
|
|
732
|
+
{/* Form fields */}
|
|
733
|
+
</CrudForm>
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
### Server-Side Validation
|
|
737
|
+
|
|
738
|
+
Handle API validation errors:
|
|
739
|
+
|
|
740
|
+
```jsx
|
|
741
|
+
// In your store
|
|
742
|
+
create: async (data) => {
|
|
743
|
+
try {
|
|
744
|
+
const response = await api.post('/items', data);
|
|
745
|
+
return response.data;
|
|
746
|
+
} catch (error) {
|
|
747
|
+
if (error.response?.status === 422) {
|
|
748
|
+
// Validation errors
|
|
749
|
+
const errors = error.response.data.errors;
|
|
750
|
+
set({ form: { ...get().form, errors } });
|
|
751
|
+
}
|
|
752
|
+
throw error;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
### Form State Management
|
|
758
|
+
|
|
759
|
+
The store provides form state management:
|
|
760
|
+
|
|
761
|
+
```jsx
|
|
762
|
+
const store = useStore();
|
|
763
|
+
|
|
764
|
+
// Access form state
|
|
765
|
+
const { values, errors, loading } = store.form;
|
|
766
|
+
|
|
767
|
+
// Set field value
|
|
768
|
+
store.setFormField('name', 'New Value');
|
|
769
|
+
|
|
770
|
+
// Set multiple fields
|
|
771
|
+
store.setFormFields({ name: 'John', email: 'john@example.com' });
|
|
772
|
+
|
|
773
|
+
// Set errors
|
|
774
|
+
store.setFormErrors({ name: 'Required' });
|
|
775
|
+
|
|
776
|
+
// Reset form
|
|
777
|
+
store.resetForm();
|
|
778
|
+
```
|