@rjsf/daisyui 6.0.0-beta.21 → 6.0.0-beta.23
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/dist/chakra-ui.esm.js +169 -355
- package/dist/chakra-ui.esm.js.map +4 -4
- package/dist/chakra-ui.umd.js +60 -237
- package/dist/index.cjs +186 -370
- package/dist/index.cjs.map +4 -4
- package/lib/templates/ArrayFieldItemButtonsTemplate/ArrayFieldItemButtonsTemplate.d.ts +2 -2
- package/lib/templates/ArrayFieldItemButtonsTemplate/ArrayFieldItemButtonsTemplate.js +2 -7
- package/lib/templates/ArrayFieldItemButtonsTemplate/ArrayFieldItemButtonsTemplate.js.map +1 -1
- package/lib/templates/ArrayFieldItemTemplate/ArrayFieldItemTemplate.d.ts +3 -3
- package/lib/templates/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js +1 -1
- package/lib/templates/ArrayFieldItemTemplate/ArrayFieldItemTemplate.js.map +1 -1
- package/lib/templates/ArrayFieldTemplate/ArrayFieldTemplate.js +1 -2
- package/lib/templates/ArrayFieldTemplate/ArrayFieldTemplate.js.map +1 -1
- package/lib/templates/BaseInputTemplate/BaseInputTemplate.js +8 -2
- package/lib/templates/BaseInputTemplate/BaseInputTemplate.js.map +1 -1
- package/lib/templates/FieldTemplate/FieldTemplate.js +3 -3
- package/lib/templates/FieldTemplate/FieldTemplate.js.map +1 -1
- package/lib/templates/ObjectFieldTemplate/ObjectFieldTemplate.js +2 -2
- package/lib/templates/ObjectFieldTemplate/ObjectFieldTemplate.js.map +1 -1
- package/lib/templates/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js +2 -9
- package/lib/templates/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/widgets/AltDateWidget/AltDateWidget.d.ts +1 -1
- package/lib/widgets/AltDateWidget/AltDateWidget.js +5 -121
- package/lib/widgets/AltDateWidget/AltDateWidget.js.map +1 -1
- package/lib/widgets/CheckboxWidget/CheckboxWidget.js +2 -2
- package/lib/widgets/CheckboxWidget/CheckboxWidget.js.map +1 -1
- package/lib/widgets/CheckboxesWidget/CheckboxesWidget.d.ts +1 -1
- package/lib/widgets/CheckboxesWidget/CheckboxesWidget.js +2 -2
- package/lib/widgets/CheckboxesWidget/CheckboxesWidget.js.map +1 -1
- package/lib/widgets/RadioWidget/RadioWidget.d.ts +1 -1
- package/lib/widgets/RadioWidget/RadioWidget.js +2 -2
- package/lib/widgets/RadioWidget/RadioWidget.js.map +1 -1
- package/lib/widgets/TextareaWidget/TextareaWidget.js +2 -2
- package/lib/widgets/TextareaWidget/TextareaWidget.js.map +1 -1
- package/lib/widgets/Widgets.d.ts +1 -2
- package/lib/widgets/Widgets.js +1 -3
- package/lib/widgets/Widgets.js.map +1 -1
- package/package.json +7 -7
- package/src/templates/ArrayFieldItemButtonsTemplate/ArrayFieldItemButtonsTemplate.tsx +10 -15
- package/src/templates/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +3 -3
- package/src/templates/ArrayFieldTemplate/ArrayFieldTemplate.tsx +1 -8
- package/src/templates/BaseInputTemplate/BaseInputTemplate.tsx +11 -3
- package/src/templates/FieldTemplate/FieldTemplate.tsx +9 -7
- package/src/templates/ObjectFieldTemplate/ObjectFieldTemplate.tsx +2 -2
- package/src/templates/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.tsx +5 -16
- package/src/widgets/AltDateWidget/AltDateWidget.tsx +18 -253
- package/src/widgets/CheckboxWidget/CheckboxWidget.tsx +2 -0
- package/src/widgets/CheckboxesWidget/CheckboxesWidget.tsx +2 -1
- package/src/widgets/RadioWidget/RadioWidget.tsx +2 -1
- package/src/widgets/TextareaWidget/TextareaWidget.tsx +2 -1
- package/src/widgets/Widgets.tsx +0 -3
- package/lib/widgets/FileWidget/FileWidget.d.ts +0 -12
- package/lib/widgets/FileWidget/FileWidget.js +0 -57
- package/lib/widgets/FileWidget/FileWidget.js.map +0 -1
- package/lib/widgets/FileWidget/index.d.ts +0 -2
- package/lib/widgets/FileWidget/index.js +0 -3
- package/lib/widgets/FileWidget/index.js.map +0 -1
- package/src/widgets/FileWidget/FileWidget.tsx +0 -86
- package/src/widgets/FileWidget/index.ts +0 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
1
|
import {
|
|
3
2
|
WrapIfAdditionalTemplateProps,
|
|
4
3
|
StrictRJSFSchema,
|
|
@@ -29,8 +28,9 @@ export default function WrapIfAdditionalTemplate<
|
|
|
29
28
|
required,
|
|
30
29
|
schema,
|
|
31
30
|
uiSchema,
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
onKeyRename,
|
|
32
|
+
onKeyRenameBlur,
|
|
33
|
+
onRemoveProperty,
|
|
34
34
|
registry,
|
|
35
35
|
...rest
|
|
36
36
|
} = props;
|
|
@@ -41,17 +41,6 @@ export default function WrapIfAdditionalTemplate<
|
|
|
41
41
|
const { RemoveButton } = templates.ButtonTemplates;
|
|
42
42
|
const keyLabel = translateString(TranslatableString.KeyLabel, [label]);
|
|
43
43
|
|
|
44
|
-
const handleBlur = useCallback(
|
|
45
|
-
(event: React.FocusEvent<HTMLInputElement>) => {
|
|
46
|
-
onKeyChange(event.target.value);
|
|
47
|
-
},
|
|
48
|
-
[onKeyChange],
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const handleRemove = useCallback(() => {
|
|
52
|
-
onDropPropertyClick(label)();
|
|
53
|
-
}, [onDropPropertyClick, label]);
|
|
54
|
-
|
|
55
44
|
if (!additional) {
|
|
56
45
|
return <div className={classNames}>{children}</div>;
|
|
57
46
|
}
|
|
@@ -67,7 +56,7 @@ export default function WrapIfAdditionalTemplate<
|
|
|
67
56
|
type='text'
|
|
68
57
|
className='input input-bordered'
|
|
69
58
|
id={`${id}-key`}
|
|
70
|
-
onBlur={
|
|
59
|
+
onBlur={onKeyRenameBlur}
|
|
71
60
|
defaultValue={label}
|
|
72
61
|
disabled={disabled || readonly}
|
|
73
62
|
/>
|
|
@@ -78,7 +67,7 @@ export default function WrapIfAdditionalTemplate<
|
|
|
78
67
|
id={buttonId(id, 'remove')}
|
|
79
68
|
className='rjsf-object-property-remove'
|
|
80
69
|
disabled={disabled || readonly}
|
|
81
|
-
onClick={
|
|
70
|
+
onClick={onRemoveProperty}
|
|
82
71
|
uiSchema={uiSchema}
|
|
83
72
|
registry={registry}
|
|
84
73
|
/>
|
|
@@ -1,187 +1,13 @@
|
|
|
1
|
-
import { MouseEvent, useCallback, useEffect, useReducer, useState } from 'react';
|
|
2
1
|
import {
|
|
3
|
-
|
|
2
|
+
DateElement,
|
|
4
3
|
FormContextType,
|
|
5
4
|
RJSFSchema,
|
|
6
5
|
StrictRJSFSchema,
|
|
7
|
-
WidgetProps,
|
|
8
6
|
TranslatableString,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
dateRangeOptions,
|
|
12
|
-
DateObject as RJSFDateObject,
|
|
13
|
-
Registry,
|
|
7
|
+
useAltDateWidgetProps,
|
|
8
|
+
WidgetProps,
|
|
14
9
|
} from '@rjsf/utils';
|
|
15
10
|
|
|
16
|
-
/** Interface for date object with optional string fields for each date/time component */
|
|
17
|
-
interface DateObject {
|
|
18
|
-
year?: string;
|
|
19
|
-
month?: string;
|
|
20
|
-
day?: string;
|
|
21
|
-
hour?: string;
|
|
22
|
-
minute?: string;
|
|
23
|
-
second?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Determines if the date object has all required fields to form a valid date
|
|
27
|
-
*
|
|
28
|
-
* @param state - The date object to check
|
|
29
|
-
* @param time - Whether to check time fields as well
|
|
30
|
-
* @returns True if all required fields are present
|
|
31
|
-
*/
|
|
32
|
-
function readyForChange(state: DateObject, time = false) {
|
|
33
|
-
return state.year && state.month && state.day && (!time || (state.hour && state.minute && state.second));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Supported date element display formats */
|
|
37
|
-
type DateElementFormat = 'YMD' | 'MDY' | 'DMY';
|
|
38
|
-
|
|
39
|
-
/** Gets configuration for date elements based on format and ranges
|
|
40
|
-
*
|
|
41
|
-
* @param state - The current date object state
|
|
42
|
-
* @param time - Whether to include time elements
|
|
43
|
-
* @param yearsRange - Optional range of years to display
|
|
44
|
-
* @param format - Format for ordering date elements (year, month, day)
|
|
45
|
-
* @returns Array of element properties for rendering
|
|
46
|
-
*/
|
|
47
|
-
function getDateElementProps(
|
|
48
|
-
state: DateObject,
|
|
49
|
-
time: boolean,
|
|
50
|
-
yearsRange?: [number, number],
|
|
51
|
-
format: DateElementFormat = 'YMD',
|
|
52
|
-
) {
|
|
53
|
-
const rangeOptions = yearsRange ?? [1900, new Date().getFullYear() + 2];
|
|
54
|
-
// Define the order based on the format
|
|
55
|
-
const formats: Record<DateElementFormat, Array<keyof DateObject>> = {
|
|
56
|
-
YMD: ['year', 'month', 'day'],
|
|
57
|
-
MDY: ['month', 'day', 'year'],
|
|
58
|
-
DMY: ['day', 'month', 'year'],
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Get the elements in the specified order
|
|
62
|
-
const dateElements = formats[format].map((key) => ({
|
|
63
|
-
type: key,
|
|
64
|
-
value: state[key],
|
|
65
|
-
range:
|
|
66
|
-
key === 'year'
|
|
67
|
-
? (rangeOptions as [number, number])
|
|
68
|
-
: key === 'month'
|
|
69
|
-
? ([1, 12] as [number, number])
|
|
70
|
-
: key === 'day'
|
|
71
|
-
? ([1, 31] as [number, number])
|
|
72
|
-
: ([0, 59] as [number, number]),
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
// Add time elements if needed
|
|
76
|
-
if (time) {
|
|
77
|
-
dateElements.push(
|
|
78
|
-
{ type: 'hour', value: state.hour, range: [0, 23] as [number, number] },
|
|
79
|
-
{ type: 'minute', value: state.minute, range: [0, 59] as [number, number] },
|
|
80
|
-
{ type: 'second', value: state.second, range: [0, 59] as [number, number] },
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return dateElements;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Props for the DateElement component */
|
|
88
|
-
interface DateElementProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
|
|
89
|
-
/** Type of date element (year, month, day, etc.) */
|
|
90
|
-
type: string;
|
|
91
|
-
/** Min/max range for the element values */
|
|
92
|
-
range: [number, number];
|
|
93
|
-
/** Current value */
|
|
94
|
-
value?: string;
|
|
95
|
-
/** Function to call when value is selected */
|
|
96
|
-
select: (property: keyof DateObject, value: any) => void;
|
|
97
|
-
/** Base ID for the form element */
|
|
98
|
-
rootId: string;
|
|
99
|
-
/** Name attribute for the form element */
|
|
100
|
-
name: string;
|
|
101
|
-
/** Whether the input is disabled */
|
|
102
|
-
disabled?: boolean;
|
|
103
|
-
/** Whether the input is readonly */
|
|
104
|
-
readonly?: boolean;
|
|
105
|
-
/** Whether the input should autofocus */
|
|
106
|
-
autofocus?: boolean;
|
|
107
|
-
/** Registry containing widgets and templates */
|
|
108
|
-
registry: Registry<T, S, F>;
|
|
109
|
-
/** Function called when input loses focus */
|
|
110
|
-
onBlur: (id: string, value: string) => void;
|
|
111
|
-
/** Function called when input gains focus */
|
|
112
|
-
onFocus: (id: string, value: string) => void;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** Component for rendering individual date/time elements (year, month, day, etc.)
|
|
116
|
-
*
|
|
117
|
-
* Renders a select input for each date component with appropriate options.
|
|
118
|
-
*
|
|
119
|
-
* @param props - The props for the component
|
|
120
|
-
*/
|
|
121
|
-
function DateElement<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
122
|
-
type,
|
|
123
|
-
range,
|
|
124
|
-
value,
|
|
125
|
-
select,
|
|
126
|
-
rootId,
|
|
127
|
-
name,
|
|
128
|
-
disabled,
|
|
129
|
-
readonly,
|
|
130
|
-
autofocus,
|
|
131
|
-
registry,
|
|
132
|
-
onBlur,
|
|
133
|
-
onFocus,
|
|
134
|
-
}: DateElementProps<T, S, F>) {
|
|
135
|
-
const id = `${rootId}_${type}`;
|
|
136
|
-
const { SelectWidget } = registry.widgets as Registry<T, S, F>['widgets'];
|
|
137
|
-
|
|
138
|
-
// Memoize the onChange handler
|
|
139
|
-
const handleChange = useCallback(
|
|
140
|
-
(value: any) => {
|
|
141
|
-
select(type as keyof DateObject, value);
|
|
142
|
-
},
|
|
143
|
-
[select, type],
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<SelectWidget
|
|
148
|
-
schema={{ type: 'integer' } as S}
|
|
149
|
-
id={id}
|
|
150
|
-
name={name}
|
|
151
|
-
className='select select-bordered select-sm w-full'
|
|
152
|
-
options={{ enumOptions: dateRangeOptions<S>(range[0], range[1]) }}
|
|
153
|
-
placeholder={type}
|
|
154
|
-
value={value}
|
|
155
|
-
disabled={disabled}
|
|
156
|
-
readonly={readonly}
|
|
157
|
-
autofocus={autofocus}
|
|
158
|
-
onChange={handleChange}
|
|
159
|
-
onBlur={onBlur}
|
|
160
|
-
onFocus={onFocus}
|
|
161
|
-
registry={registry}
|
|
162
|
-
label=''
|
|
163
|
-
aria-describedby={ariaDescribedByIds(rootId)}
|
|
164
|
-
required={false}
|
|
165
|
-
/>
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/** Converts our DateObject to the expected format for toDateString
|
|
170
|
-
*
|
|
171
|
-
* @param dateObj - The internal DateObject
|
|
172
|
-
* @returns A properly formatted object for the utils toDateString function
|
|
173
|
-
*/
|
|
174
|
-
function convertToRJSFDateObject(dateObj: DateObject): RJSFDateObject {
|
|
175
|
-
return {
|
|
176
|
-
year: dateObj.year ? parseInt(dateObj.year) : 0,
|
|
177
|
-
month: dateObj.month ? parseInt(dateObj.month) : 0,
|
|
178
|
-
day: dateObj.day ? parseInt(dateObj.day) : 0,
|
|
179
|
-
hour: dateObj.hour ? parseInt(dateObj.hour) : 0,
|
|
180
|
-
minute: dateObj.minute ? parseInt(dateObj.minute) : 0,
|
|
181
|
-
second: dateObj.second ? parseInt(dateObj.second) : 0,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
11
|
/** The `AltDateWidget` component provides an alternative date/time input
|
|
186
12
|
* with individual fields for year, month, day, and optionally time components.
|
|
187
13
|
*
|
|
@@ -199,87 +25,25 @@ export default function AltDateWidget<
|
|
|
199
25
|
T = any,
|
|
200
26
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
201
27
|
F extends FormContextType = any,
|
|
202
|
-
>({
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
value,
|
|
215
|
-
}: WidgetProps<T, S, F>) {
|
|
28
|
+
>(props: WidgetProps<T, S, F>) {
|
|
29
|
+
const {
|
|
30
|
+
disabled = false,
|
|
31
|
+
readonly = false,
|
|
32
|
+
autofocus = false,
|
|
33
|
+
options = {},
|
|
34
|
+
id,
|
|
35
|
+
name,
|
|
36
|
+
registry,
|
|
37
|
+
onBlur,
|
|
38
|
+
onFocus,
|
|
39
|
+
} = props;
|
|
216
40
|
const { translateString } = registry;
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
// Use a type-safe version of parseDateString result
|
|
220
|
-
const initialState = parseDateString(value, time) as unknown as DateObject;
|
|
221
|
-
|
|
222
|
-
// Create a reducer for date objects
|
|
223
|
-
const dateReducer = (state: DateObject, action: Partial<DateObject>): DateObject => {
|
|
224
|
-
return { ...state, ...action };
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const [state, setState] = useReducer(dateReducer, initialState);
|
|
228
|
-
|
|
229
|
-
// Handle changes in props or state
|
|
230
|
-
useEffect(() => {
|
|
231
|
-
const rjsfDateObj = convertToRJSFDateObject(state);
|
|
232
|
-
const stateValue = toDateString(rjsfDateObj, time);
|
|
233
|
-
if (readyForChange(state, time) && stateValue !== value) {
|
|
234
|
-
// Valid date changed via the selects
|
|
235
|
-
onChange(stateValue);
|
|
236
|
-
} else if (lastValue !== value) {
|
|
237
|
-
// New value from props
|
|
238
|
-
setLastValue(value);
|
|
239
|
-
setState(parseDateString(value, time) as unknown as DateObject);
|
|
240
|
-
}
|
|
241
|
-
}, [time, value, onChange, state, lastValue]);
|
|
242
|
-
|
|
243
|
-
// Handle individual field changes
|
|
244
|
-
const handleChange = useCallback((property: keyof DateObject, value: string) => {
|
|
245
|
-
setState({ [property]: value });
|
|
246
|
-
}, []);
|
|
247
|
-
|
|
248
|
-
// Set current date
|
|
249
|
-
const handleSetNow = useCallback(
|
|
250
|
-
(event: MouseEvent<HTMLButtonElement>) => {
|
|
251
|
-
event.preventDefault();
|
|
252
|
-
if (disabled || readonly) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
const nextState = parseDateString(new Date().toJSON(), time) as unknown as DateObject;
|
|
256
|
-
const rjsfDateObj = convertToRJSFDateObject(nextState);
|
|
257
|
-
onChange(toDateString(rjsfDateObj, time));
|
|
258
|
-
},
|
|
259
|
-
[disabled, readonly, time, onChange],
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
// Clear the date
|
|
263
|
-
const handleClear = useCallback(
|
|
264
|
-
(event: MouseEvent<HTMLButtonElement>) => {
|
|
265
|
-
event.preventDefault();
|
|
266
|
-
if (disabled || readonly) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
onChange(undefined);
|
|
270
|
-
},
|
|
271
|
-
[disabled, readonly, onChange],
|
|
272
|
-
);
|
|
41
|
+
const { elements, handleChange, handleClear, handleSetNow } = useAltDateWidgetProps(props);
|
|
273
42
|
|
|
274
43
|
return (
|
|
275
44
|
<div className='space-y-3'>
|
|
276
45
|
<div className='grid grid-cols-3 gap-2'>
|
|
277
|
-
{
|
|
278
|
-
state,
|
|
279
|
-
time,
|
|
280
|
-
options.yearsRange as [number, number] | undefined,
|
|
281
|
-
options.format as DateElementFormat | undefined,
|
|
282
|
-
).map((elemProps, i) => (
|
|
46
|
+
{elements.map((elemProps, i) => (
|
|
283
47
|
<div key={i} className='form-control'>
|
|
284
48
|
<label className='label'>
|
|
285
49
|
<span className='label-text capitalize'>{elemProps.type}</span>
|
|
@@ -287,6 +51,7 @@ export default function AltDateWidget<
|
|
|
287
51
|
<DateElement
|
|
288
52
|
rootId={id}
|
|
289
53
|
name={name}
|
|
54
|
+
className='select select-bordered select-sm'
|
|
290
55
|
select={handleChange}
|
|
291
56
|
type={elemProps.type}
|
|
292
57
|
range={elemProps.range}
|
|
@@ -19,6 +19,7 @@ export default function CheckboxWidget<
|
|
|
19
19
|
>(props: WidgetProps<T, S, F>) {
|
|
20
20
|
const {
|
|
21
21
|
id,
|
|
22
|
+
htmlName,
|
|
22
23
|
value,
|
|
23
24
|
required,
|
|
24
25
|
disabled,
|
|
@@ -71,6 +72,7 @@ export default function CheckboxWidget<
|
|
|
71
72
|
<input
|
|
72
73
|
type='checkbox'
|
|
73
74
|
id={id}
|
|
75
|
+
name={htmlName || id}
|
|
74
76
|
checked={value}
|
|
75
77
|
required={required}
|
|
76
78
|
disabled={disabled || readonly}
|
|
@@ -17,6 +17,7 @@ import { WidgetProps, StrictRJSFSchema, RJSFSchema, FormContextType } from '@rjs
|
|
|
17
17
|
*/
|
|
18
18
|
export default function CheckboxesWidget<T, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
19
19
|
id,
|
|
20
|
+
htmlName,
|
|
20
21
|
disabled,
|
|
21
22
|
options,
|
|
22
23
|
value,
|
|
@@ -106,7 +107,7 @@ export default function CheckboxesWidget<T, S extends StrictRJSFSchema = RJSFSch
|
|
|
106
107
|
type='checkbox'
|
|
107
108
|
id={`${id}-${option.value}`}
|
|
108
109
|
className='checkbox'
|
|
109
|
-
name={id}
|
|
110
|
+
name={htmlName || id}
|
|
110
111
|
checked={isChecked(option)}
|
|
111
112
|
required={required}
|
|
112
113
|
disabled={disabled || readonly}
|
|
@@ -15,6 +15,7 @@ import { WidgetProps, StrictRJSFSchema, FormContextType, RJSFSchema } from '@rjs
|
|
|
15
15
|
*/
|
|
16
16
|
export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
|
|
17
17
|
id,
|
|
18
|
+
htmlName,
|
|
18
19
|
options,
|
|
19
20
|
value,
|
|
20
21
|
required,
|
|
@@ -95,7 +96,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
|
|
|
95
96
|
type='radio'
|
|
96
97
|
id={`${id}-${option.value}`}
|
|
97
98
|
className='radio'
|
|
98
|
-
name={id}
|
|
99
|
+
name={htmlName || id}
|
|
99
100
|
value={getValue(option)}
|
|
100
101
|
checked={isChecked(option)}
|
|
101
102
|
required={required}
|
|
@@ -16,7 +16,7 @@ export default function TextareaWidget<
|
|
|
16
16
|
S extends StrictRJSFSchema = RJSFSchema,
|
|
17
17
|
F extends FormContextType = any,
|
|
18
18
|
>(props: WidgetProps<T, S, F>) {
|
|
19
|
-
const { id, value, required, disabled, readonly, onChange, onFocus, onBlur, options } = props;
|
|
19
|
+
const { id, htmlName, value, required, disabled, readonly, onChange, onFocus, onBlur, options } = props;
|
|
20
20
|
|
|
21
21
|
/** Handle focus events
|
|
22
22
|
*
|
|
@@ -62,6 +62,7 @@ export default function TextareaWidget<
|
|
|
62
62
|
<div className='form-control'>
|
|
63
63
|
<textarea
|
|
64
64
|
id={id}
|
|
65
|
+
name={htmlName || id}
|
|
65
66
|
value={value || ''}
|
|
66
67
|
required={required}
|
|
67
68
|
disabled={disabled || readonly}
|
package/src/widgets/Widgets.tsx
CHANGED
|
@@ -6,7 +6,6 @@ import CheckboxWidget from './CheckboxWidget/CheckboxWidget';
|
|
|
6
6
|
import CheckboxesWidget from './CheckboxesWidget/CheckboxesWidget';
|
|
7
7
|
import DateTimeWidget from './DateTimeWidget/DateTimeWidget';
|
|
8
8
|
import DateWidget from './DateWidget/DateWidget';
|
|
9
|
-
import FileWidget from './FileWidget/FileWidget';
|
|
10
9
|
import RadioWidget from './RadioWidget/RadioWidget';
|
|
11
10
|
import RangeWidget from './RangeWidget/RangeWidget';
|
|
12
11
|
import RatingWidget from './RatingWidget/RatingWidget';
|
|
@@ -22,7 +21,6 @@ export {
|
|
|
22
21
|
CheckboxWidget,
|
|
23
22
|
DateTimeWidget,
|
|
24
23
|
DateWidget,
|
|
25
|
-
FileWidget,
|
|
26
24
|
RadioWidget,
|
|
27
25
|
RangeWidget,
|
|
28
26
|
RatingWidget,
|
|
@@ -44,7 +42,6 @@ export function generateWidgets<
|
|
|
44
42
|
CheckboxWidget,
|
|
45
43
|
DateTimeWidget,
|
|
46
44
|
DateWidget,
|
|
47
|
-
FileWidget,
|
|
48
45
|
RadioWidget,
|
|
49
46
|
RangeWidget,
|
|
50
47
|
RatingWidget,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjsf/utils';
|
|
2
|
-
/** The `FileWidget` component provides a file input with DaisyUI styling
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - Handles both single and multiple file uploads
|
|
6
|
-
* - Supports file type filtering via accept attribute
|
|
7
|
-
* - Properly manages disabled and readonly states
|
|
8
|
-
* - Handles focus and blur events
|
|
9
|
-
*
|
|
10
|
-
* @param props - The `WidgetProps` for this component
|
|
11
|
-
*/
|
|
12
|
-
export default function FileWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(props: WidgetProps<T, S, F>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback } from 'react';
|
|
3
|
-
/** The `FileWidget` component provides a file input with DaisyUI styling
|
|
4
|
-
*
|
|
5
|
-
* Features:
|
|
6
|
-
* - Handles both single and multiple file uploads
|
|
7
|
-
* - Supports file type filtering via accept attribute
|
|
8
|
-
* - Properly manages disabled and readonly states
|
|
9
|
-
* - Handles focus and blur events
|
|
10
|
-
*
|
|
11
|
-
* @param props - The `WidgetProps` for this component
|
|
12
|
-
*/
|
|
13
|
-
export default function FileWidget(props) {
|
|
14
|
-
const { id, required, disabled, readonly, schema, onChange, onFocus, onBlur, options = {} } = props;
|
|
15
|
-
// Ensure isMulti is explicitly a boolean.
|
|
16
|
-
const isMulti = schema.type === 'array' || Boolean(options.multiple);
|
|
17
|
-
// Accept attribute for restricting file types (e.g., "image/*"), if defined in options.
|
|
18
|
-
const accept = typeof options.accept === 'string' ? options.accept : undefined;
|
|
19
|
-
/** Handle file selection changes
|
|
20
|
-
*
|
|
21
|
-
* @param event - The change event from the file input
|
|
22
|
-
*/
|
|
23
|
-
const handleChange = useCallback((event) => {
|
|
24
|
-
if (!event.target.files) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
// Convert FileList to array for multiple upload handling.
|
|
28
|
-
const fileList = Array.from(event.target.files);
|
|
29
|
-
if (isMulti) {
|
|
30
|
-
onChange(fileList);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
// For single file, send the first file (or null if none chosen)
|
|
34
|
-
onChange(fileList[0] || null);
|
|
35
|
-
}
|
|
36
|
-
}, [onChange, isMulti]);
|
|
37
|
-
/** Handle focus events
|
|
38
|
-
*
|
|
39
|
-
* @param event - The focus event
|
|
40
|
-
*/
|
|
41
|
-
const handleFocus = useCallback((event) => {
|
|
42
|
-
if (onFocus) {
|
|
43
|
-
onFocus(id, event.target.files ? Array.from(event.target.files) : null);
|
|
44
|
-
}
|
|
45
|
-
}, [onFocus, id]);
|
|
46
|
-
/** Handle blur events
|
|
47
|
-
*
|
|
48
|
-
* @param event - The blur event
|
|
49
|
-
*/
|
|
50
|
-
const handleBlur = useCallback((event) => {
|
|
51
|
-
if (onBlur) {
|
|
52
|
-
onBlur(id, event.target.files ? Array.from(event.target.files) : null);
|
|
53
|
-
}
|
|
54
|
-
}, [onBlur, id]);
|
|
55
|
-
return (_jsx("input", { id: id, type: 'file', className: 'file-input w-full', required: required, disabled: disabled || readonly, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, multiple: isMulti, accept: accept }));
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=FileWidget.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FileWidget.js","sourceRoot":"","sources":["../../../src/widgets/FileWidget/FileWidget.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA2B,WAAW,EAAE,MAAM,OAAO,CAAC;AAG7D;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,KAA2B;IAE3B,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;IAEpG,0CAA0C;IAC1C,MAAM,OAAO,GAAY,MAAM,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9E,wFAAwF;IACxF,MAAM,MAAM,GAAuB,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnG;;;OAGG;IACH,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,KAAoC,EAAE,EAAE;QACvC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACxB,OAAO;QACT,CAAC;QACD,0DAA0D;QAC1D,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChD,IAAI,OAAO,EAAE,CAAC;YACZ,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,gEAAgE;YAChE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;QAChC,CAAC;IACH,CAAC,EACD,CAAC,QAAQ,EAAE,OAAO,CAAC,CACpB,CAAC;IAEF;;;OAGG;IACH,MAAM,WAAW,GAAG,WAAW,CAC7B,CAAC,KAAmC,EAAE,EAAE;QACtC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,EAAE,CAAC,CACd,CAAC;IAEF;;;OAGG;IACH,MAAM,UAAU,GAAG,WAAW,CAC5B,CAAC,KAAmC,EAAE,EAAE;QACtC,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACzE,CAAC;IACH,CAAC,EACD,CAAC,MAAM,EAAE,EAAE,CAAC,CACb,CAAC;IAEF,OAAO,CACL,gBACE,EAAE,EAAE,EAAE,EACN,IAAI,EAAC,MAAM,EACX,SAAS,EAAC,mBAAmB,EAC7B,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,IAAI,QAAQ,EAC9B,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,MAAM,GACd,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/widgets/FileWidget/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,cAAc,cAAc,CAAC"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, FocusEvent, useCallback } from 'react';
|
|
2
|
-
import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjsf/utils';
|
|
3
|
-
|
|
4
|
-
/** The `FileWidget` component provides a file input with DaisyUI styling
|
|
5
|
-
*
|
|
6
|
-
* Features:
|
|
7
|
-
* - Handles both single and multiple file uploads
|
|
8
|
-
* - Supports file type filtering via accept attribute
|
|
9
|
-
* - Properly manages disabled and readonly states
|
|
10
|
-
* - Handles focus and blur events
|
|
11
|
-
*
|
|
12
|
-
* @param props - The `WidgetProps` for this component
|
|
13
|
-
*/
|
|
14
|
-
export default function FileWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(
|
|
15
|
-
props: WidgetProps<T, S, F>,
|
|
16
|
-
) {
|
|
17
|
-
const { id, required, disabled, readonly, schema, onChange, onFocus, onBlur, options = {} } = props;
|
|
18
|
-
|
|
19
|
-
// Ensure isMulti is explicitly a boolean.
|
|
20
|
-
const isMulti: boolean = schema.type === 'array' || Boolean(options.multiple);
|
|
21
|
-
|
|
22
|
-
// Accept attribute for restricting file types (e.g., "image/*"), if defined in options.
|
|
23
|
-
const accept: string | undefined = typeof options.accept === 'string' ? options.accept : undefined;
|
|
24
|
-
|
|
25
|
-
/** Handle file selection changes
|
|
26
|
-
*
|
|
27
|
-
* @param event - The change event from the file input
|
|
28
|
-
*/
|
|
29
|
-
const handleChange = useCallback(
|
|
30
|
-
(event: ChangeEvent<HTMLInputElement>) => {
|
|
31
|
-
if (!event.target.files) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
// Convert FileList to array for multiple upload handling.
|
|
35
|
-
const fileList = Array.from(event.target.files);
|
|
36
|
-
if (isMulti) {
|
|
37
|
-
onChange(fileList);
|
|
38
|
-
} else {
|
|
39
|
-
// For single file, send the first file (or null if none chosen)
|
|
40
|
-
onChange(fileList[0] || null);
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
[onChange, isMulti],
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
/** Handle focus events
|
|
47
|
-
*
|
|
48
|
-
* @param event - The focus event
|
|
49
|
-
*/
|
|
50
|
-
const handleFocus = useCallback(
|
|
51
|
-
(event: FocusEvent<HTMLInputElement>) => {
|
|
52
|
-
if (onFocus) {
|
|
53
|
-
onFocus(id, event.target.files ? Array.from(event.target.files) : null);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
[onFocus, id],
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
/** Handle blur events
|
|
60
|
-
*
|
|
61
|
-
* @param event - The blur event
|
|
62
|
-
*/
|
|
63
|
-
const handleBlur = useCallback(
|
|
64
|
-
(event: FocusEvent<HTMLInputElement>) => {
|
|
65
|
-
if (onBlur) {
|
|
66
|
-
onBlur(id, event.target.files ? Array.from(event.target.files) : null);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
[onBlur, id],
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<input
|
|
74
|
-
id={id}
|
|
75
|
-
type='file'
|
|
76
|
-
className='file-input w-full'
|
|
77
|
-
required={required}
|
|
78
|
-
disabled={disabled || readonly}
|
|
79
|
-
onChange={handleChange}
|
|
80
|
-
onFocus={handleFocus}
|
|
81
|
-
onBlur={handleBlur}
|
|
82
|
-
multiple={isMulti}
|
|
83
|
-
accept={accept}
|
|
84
|
-
/>
|
|
85
|
-
);
|
|
86
|
-
}
|