@react-fabric/form 1.0.0-beta.4 → 1.0.0-beta.40
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/{src/input/ArrayInput.module.css → css/_arrayInput.css} +8 -8
- package/css/_colorPicker.css +65 -0
- package/{src/internal/Field.module.css → css/_field.css} +26 -15
- package/{src/input/File.module.css → css/_file.css} +20 -6
- package/css/styles.css +27 -0
- package/dist/cjs/builder/FileField.js +37 -25
- package/dist/cjs/builder/FormField.js +44 -34
- package/dist/cjs/builder/SchemaEditor.js +72 -0
- package/dist/cjs/builder/components/AddSchemaFields.js +62 -0
- package/dist/cjs/builder/components/SchemaArrayForm.js +143 -0
- package/dist/cjs/builder/components/SchemaField.js +413 -0
- package/dist/cjs/form/Controller.js +1 -1
- package/dist/cjs/form/Form.js +19 -10
- package/dist/cjs/hooks/useFormBuilder.js +27 -15
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/input/ArrayInput.js +36 -25
- package/dist/cjs/input/AvatarInput.js +1 -1
- package/dist/cjs/input/Checkbox.js +5 -4
- package/dist/cjs/input/ColorInput.js +70 -28
- package/dist/cjs/input/ColorPicker.js +1 -35
- package/dist/cjs/input/DateInput.js +183 -0
- package/dist/cjs/input/Field.js +4 -4
- package/dist/cjs/input/File.js +2 -3
- package/dist/cjs/input/Hidden.js +3 -1
- package/dist/cjs/input/Input.js +1 -1
- package/dist/cjs/input/Number.js +1 -1
- package/dist/cjs/input/Password.js +1 -1
- package/dist/cjs/input/Radio.js +1 -1
- package/dist/cjs/input/RadioGroup.js +6 -3
- package/dist/cjs/input/{Range.js → RangeSlider.js} +3 -3
- package/dist/cjs/input/Search.js +1 -1
- package/dist/cjs/input/Slider.js +1 -1
- package/dist/cjs/input/Switch.js +27 -5
- package/dist/cjs/input/Textarea.js +7 -3
- package/dist/cjs/internal/ErrorIcon.js +1 -1
- package/dist/cjs/internal/FieldWrapper.js +4 -3
- package/dist/cjs/internal/InputWrapper.js +14 -16
- package/dist/cjs/select/AutoComplete.js +1 -1
- package/dist/cjs/select/List.js +41 -20
- package/dist/cjs/select/Options.js +2 -2
- package/dist/cjs/select/Select.js +11 -8
- package/dist/cjs/select/useSelect.js +12 -7
- package/{src/input/ColorPicker.module.css → dist/cjs/types/schema.js} +18 -27
- package/dist/cjs/utils/getColor.js +6 -0
- package/dist/esm/builder/FileField.js +39 -27
- package/dist/esm/builder/FormField.js +44 -34
- package/dist/esm/builder/SchemaEditor.js +72 -0
- package/dist/esm/builder/components/AddSchemaFields.js +62 -0
- package/dist/esm/builder/components/SchemaArrayForm.js +143 -0
- package/dist/esm/builder/components/SchemaField.js +413 -0
- package/dist/esm/form/Controller.js +1 -1
- package/dist/esm/form/Form.js +19 -10
- package/dist/esm/hooks/useFormBuilder.js +25 -13
- package/dist/esm/index.js +4 -1
- package/dist/esm/input/ArrayInput.js +38 -27
- package/dist/esm/input/AvatarInput.js +1 -1
- package/dist/esm/input/Checkbox.js +5 -4
- package/dist/esm/input/ColorInput.js +72 -30
- package/dist/esm/input/ColorPicker.js +1 -35
- package/dist/esm/input/DateInput.js +183 -0
- package/dist/esm/input/Field.js +5 -5
- package/dist/esm/input/File.js +2 -3
- package/dist/esm/input/Hidden.js +3 -1
- package/dist/esm/input/Input.js +1 -1
- package/dist/esm/input/Number.js +1 -1
- package/dist/esm/input/Password.js +1 -1
- package/dist/esm/input/Radio.js +1 -1
- package/dist/esm/input/RadioGroup.js +7 -4
- package/dist/esm/input/{Range.js → RangeSlider.js} +3 -3
- package/dist/esm/input/Search.js +1 -1
- package/dist/esm/input/Slider.js +1 -1
- package/dist/esm/input/Switch.js +29 -7
- package/dist/esm/input/Textarea.js +7 -3
- package/dist/esm/internal/ErrorIcon.js +1 -1
- package/dist/esm/internal/FieldWrapper.js +4 -3
- package/dist/esm/internal/InputWrapper.js +14 -16
- package/dist/esm/select/AutoComplete.js +1 -1
- package/dist/esm/select/List.js +42 -21
- package/dist/esm/select/Options.js +2 -2
- package/dist/esm/select/Select.js +11 -8
- package/dist/esm/select/useSelect.js +13 -8
- package/dist/esm/types/schema.js +41 -0
- package/dist/esm/utils/getColor.js +6 -1
- package/dist/types/builder/FileField.d.ts +4 -2
- package/dist/types/builder/FormField.d.ts +3 -1
- package/dist/types/builder/SchemaEditor.d.ts +2 -0
- package/dist/types/builder/components/AddSchemaFields.d.ts +2 -0
- package/dist/types/builder/components/SchemaArrayForm.d.ts +2 -0
- package/dist/types/builder/components/SchemaField.d.ts +10 -0
- package/dist/types/form/Controller.d.ts +1 -1
- package/dist/types/hooks/useFormBuilder.d.ts +3 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/input/ArrayInput.d.ts +20 -3
- package/dist/types/input/Checkbox.d.ts +4 -3
- package/dist/types/input/ColorInput.d.ts +1 -1
- package/dist/types/input/DateInput.d.ts +19 -0
- package/dist/types/input/RadioGroup.d.ts +18 -2
- package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +1 -1
- package/dist/types/input/Switch.d.ts +7 -3
- package/dist/types/input/Textarea.d.ts +5 -1
- package/dist/types/internal/InputWrapper.d.ts +1 -1
- package/dist/types/select/List.d.ts +1 -1
- package/dist/types/types/index.d.ts +9 -5
- package/dist/types/types/schema.d.ts +79 -33
- package/package.json +10 -7
- package/src/builder/FileField.tsx +53 -27
- package/src/builder/FormField.tsx +45 -32
- package/src/builder/SchemaEditor.tsx +72 -0
- package/src/builder/components/AddSchemaFields.tsx +74 -0
- package/src/builder/components/SchemaArrayForm.tsx +158 -0
- package/src/builder/components/SchemaField.tsx +435 -0
- package/src/form/Controller.tsx +2 -2
- package/src/form/Form.tsx +15 -8
- package/src/hooks/useFormBuilder.tsx +29 -15
- package/src/index.ts +10 -2
- package/src/input/ArrayInput.tsx +80 -42
- package/src/input/AvatarInput.tsx +1 -1
- package/src/input/Checkbox.tsx +5 -4
- package/src/input/ColorInput.tsx +102 -34
- package/src/input/ColorPicker.tsx +1 -35
- package/src/input/DateInput.tsx +248 -0
- package/src/input/Field.tsx +9 -11
- package/src/input/File.tsx +3 -6
- package/src/input/Hidden.tsx +4 -1
- package/src/input/Input.tsx +2 -2
- package/src/input/Number.tsx +2 -2
- package/src/input/Password.tsx +2 -2
- package/src/input/Radio.tsx +1 -1
- package/src/input/RadioGroup.tsx +27 -4
- package/src/input/{Range.tsx → RangeSlider.tsx} +2 -2
- package/src/input/Search.tsx +2 -2
- package/src/input/Slider.tsx +1 -1
- package/src/input/Switch.tsx +42 -6
- package/src/input/Textarea.tsx +11 -3
- package/src/internal/ErrorIcon.tsx +1 -1
- package/src/internal/FieldWrapper.tsx +3 -3
- package/src/internal/InputWrapper.tsx +21 -20
- package/src/select/AutoComplete.tsx +1 -1
- package/src/select/List.tsx +34 -7
- package/src/select/Options.tsx +1 -1
- package/src/select/Select.tsx +5 -2
- package/src/select/useSelect.tsx +27 -18
- package/src/types/index.ts +14 -7
- package/src/types/schema.ts +96 -41
- package/dist/cjs/input/ArrayInput.module.css +0 -1
- package/dist/cjs/input/ColorPicker.module.css +0 -1
- package/dist/cjs/input/File.module.css +0 -1
- package/dist/cjs/internal/Field.module.css +0 -1
- package/dist/esm/input/ArrayInput.module.css +0 -1
- package/dist/esm/input/ColorPicker.module.css +0 -1
- package/dist/esm/input/File.module.css +0 -1
- package/dist/esm/internal/Field.module.css +0 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version: 1.0.0
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
* Copyright (c) 2025 Adarsh Pastakia
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
10
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
11
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
13
|
+
* subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
16
|
+
* portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
20
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
arrow,
|
|
26
|
+
autoUpdate,
|
|
27
|
+
flip,
|
|
28
|
+
FloatingArrow,
|
|
29
|
+
offset,
|
|
30
|
+
shift,
|
|
31
|
+
useClick,
|
|
32
|
+
useDismiss,
|
|
33
|
+
useFloating,
|
|
34
|
+
useFocus,
|
|
35
|
+
useInteractions,
|
|
36
|
+
} from "@floating-ui/react";
|
|
37
|
+
import { type RefProp } from "@react-fabric/core/dist/types/types";
|
|
38
|
+
import { type DateLike, DatePanel, DateUtil } from "@react-fabric/date";
|
|
39
|
+
import { mergeRefs } from "@react-fabric/utilities";
|
|
40
|
+
import {
|
|
41
|
+
type ChangeEvent,
|
|
42
|
+
startTransition,
|
|
43
|
+
useCallback,
|
|
44
|
+
useDeferredValue,
|
|
45
|
+
useEffect,
|
|
46
|
+
useMemo,
|
|
47
|
+
useRef,
|
|
48
|
+
useState,
|
|
49
|
+
} from "react";
|
|
50
|
+
import { InputWrapper } from "../internal/InputWrapper";
|
|
51
|
+
import { type InputProps } from "../types";
|
|
52
|
+
import { handleEnter } from "../utils";
|
|
53
|
+
import classNames from "classnames";
|
|
54
|
+
|
|
55
|
+
export interface DateProps
|
|
56
|
+
extends InputProps<string>,
|
|
57
|
+
RefProp<HTMLInputElement> {
|
|
58
|
+
type?: "date" | "datetime";
|
|
59
|
+
/**
|
|
60
|
+
* date format
|
|
61
|
+
*/
|
|
62
|
+
format?: string;
|
|
63
|
+
/**
|
|
64
|
+
* minimum value
|
|
65
|
+
*/
|
|
66
|
+
min?: DateLike;
|
|
67
|
+
/**
|
|
68
|
+
* maximum value
|
|
69
|
+
*/
|
|
70
|
+
max?: DateLike;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const DateInput = ({
|
|
74
|
+
ref,
|
|
75
|
+
name,
|
|
76
|
+
value,
|
|
77
|
+
invalid,
|
|
78
|
+
readOnly,
|
|
79
|
+
disabled,
|
|
80
|
+
required,
|
|
81
|
+
placeholder,
|
|
82
|
+
autoFocus,
|
|
83
|
+
error,
|
|
84
|
+
type = "date",
|
|
85
|
+
onChange,
|
|
86
|
+
onEnterPressed,
|
|
87
|
+
format = "dd/MM/yyyy",
|
|
88
|
+
min,
|
|
89
|
+
max,
|
|
90
|
+
...rest
|
|
91
|
+
}: DateProps) => {
|
|
92
|
+
const [actualValue, setActualValue] = useState("");
|
|
93
|
+
const [inputValue, setInputValue] = useState("");
|
|
94
|
+
const deferred = useDeferredValue(value);
|
|
95
|
+
|
|
96
|
+
const inputFormat = useMemo(
|
|
97
|
+
() => (type === "datetime" ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd"),
|
|
98
|
+
[type],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
setActualValue(deferred ?? "");
|
|
103
|
+
setInputValue(deferred ? DateUtil.format(deferred, inputFormat) : "");
|
|
104
|
+
}, [deferred, inputFormat]);
|
|
105
|
+
|
|
106
|
+
const handleEnterPressed = useMemo(
|
|
107
|
+
() => handleEnter(onEnterPressed),
|
|
108
|
+
[onEnterPressed],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const handleChange = useCallback(
|
|
112
|
+
(e?: ChangeEvent<HTMLInputElement>) => {
|
|
113
|
+
const value = e?.currentTarget.value;
|
|
114
|
+
if (value) {
|
|
115
|
+
const parsed = DateUtil.parseDate(value);
|
|
116
|
+
setActualValue(parsed?.toISOString?.());
|
|
117
|
+
setInputValue(DateUtil.format(parsed, inputFormat));
|
|
118
|
+
onChange != null &&
|
|
119
|
+
startTransition(() => onChange(parsed?.toISOString?.()));
|
|
120
|
+
} else {
|
|
121
|
+
setActualValue("");
|
|
122
|
+
setInputValue("");
|
|
123
|
+
onChange != null && startTransition(() => onChange(null));
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
[onChange, inputFormat],
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const handleDateChange = useCallback(
|
|
130
|
+
(value?: string) => {
|
|
131
|
+
if (value) {
|
|
132
|
+
const parsed = DateUtil.parseDate(value);
|
|
133
|
+
setActualValue(parsed?.toISOString?.());
|
|
134
|
+
setInputValue(DateUtil.format(parsed, inputFormat));
|
|
135
|
+
onChange != null &&
|
|
136
|
+
startTransition(() => onChange(parsed?.toISOString?.()));
|
|
137
|
+
} else {
|
|
138
|
+
setActualValue("");
|
|
139
|
+
setInputValue("");
|
|
140
|
+
onChange != null && startTransition(() => onChange(null));
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
[onChange, inputFormat],
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const arrowRef = useRef(null);
|
|
147
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
148
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
149
|
+
open: isOpen,
|
|
150
|
+
onOpenChange: (open, _, reason) => {
|
|
151
|
+
console.log(reason);
|
|
152
|
+
if (reason === "reference-press") return;
|
|
153
|
+
setIsOpen(open);
|
|
154
|
+
},
|
|
155
|
+
strategy: "fixed",
|
|
156
|
+
placement: "bottom-start",
|
|
157
|
+
whileElementsMounted: autoUpdate,
|
|
158
|
+
middleware: [
|
|
159
|
+
shift({ padding: 8 }),
|
|
160
|
+
flip(),
|
|
161
|
+
offset(9),
|
|
162
|
+
arrow({
|
|
163
|
+
element: arrowRef,
|
|
164
|
+
}),
|
|
165
|
+
],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const focus = useFocus(context, {
|
|
169
|
+
enabled: !disabled,
|
|
170
|
+
});
|
|
171
|
+
const click = useClick(context, {
|
|
172
|
+
enabled: !disabled,
|
|
173
|
+
toggle: false,
|
|
174
|
+
});
|
|
175
|
+
const dismiss = useDismiss(context, {
|
|
176
|
+
referencePress: true,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
180
|
+
dismiss,
|
|
181
|
+
click,
|
|
182
|
+
focus,
|
|
183
|
+
]);
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<InputWrapper
|
|
187
|
+
showClear={!!actualValue}
|
|
188
|
+
onClear={handleChange}
|
|
189
|
+
invalid={invalid}
|
|
190
|
+
readOnly={readOnly}
|
|
191
|
+
disabled={disabled}
|
|
192
|
+
required={required}
|
|
193
|
+
error={error}
|
|
194
|
+
{...rest}
|
|
195
|
+
>
|
|
196
|
+
<input
|
|
197
|
+
className={classNames(
|
|
198
|
+
"appearance-none bg-transparent py-1 px-2 flex-1 border-none outline-none ring-0 peer",
|
|
199
|
+
!value && "empty",
|
|
200
|
+
)}
|
|
201
|
+
aria-invalid={invalid}
|
|
202
|
+
aria-disabled={disabled}
|
|
203
|
+
aria-readonly={readOnly}
|
|
204
|
+
aria-errormessage={error}
|
|
205
|
+
placeholder={placeholder}
|
|
206
|
+
disabled={disabled}
|
|
207
|
+
readOnly={readOnly}
|
|
208
|
+
data-testid={name}
|
|
209
|
+
name={name}
|
|
210
|
+
size={1}
|
|
211
|
+
type={type === "datetime" ? "datetime-local" : "date"}
|
|
212
|
+
autoComplete="off"
|
|
213
|
+
autoFocus={autoFocus}
|
|
214
|
+
value={inputValue}
|
|
215
|
+
ref={mergeRefs(ref, refs.setReference)}
|
|
216
|
+
{...getReferenceProps()}
|
|
217
|
+
onChange={handleChange}
|
|
218
|
+
onKeyDown={handleEnterPressed}
|
|
219
|
+
/>
|
|
220
|
+
{isOpen && (
|
|
221
|
+
<div
|
|
222
|
+
ref={refs.setFloating}
|
|
223
|
+
style={{
|
|
224
|
+
zIndex: "var(--z-popover)",
|
|
225
|
+
...floatingStyles,
|
|
226
|
+
}}
|
|
227
|
+
className="shadow-lg bg-base ring-1 ring-tint-100"
|
|
228
|
+
data-ref="dropdownBody"
|
|
229
|
+
{...getFloatingProps()}
|
|
230
|
+
>
|
|
231
|
+
<DatePanel
|
|
232
|
+
withTime={type === "datetime"}
|
|
233
|
+
value={actualValue}
|
|
234
|
+
max={max}
|
|
235
|
+
min={min}
|
|
236
|
+
onChange={handleDateChange}
|
|
237
|
+
/>
|
|
238
|
+
<FloatingArrow
|
|
239
|
+
ref={arrowRef}
|
|
240
|
+
context={context}
|
|
241
|
+
strokeWidth={0.5}
|
|
242
|
+
className="fill-base stroke-muted"
|
|
243
|
+
/>
|
|
244
|
+
</div>
|
|
245
|
+
)}
|
|
246
|
+
</InputWrapper>
|
|
247
|
+
);
|
|
248
|
+
};
|
package/src/input/Field.tsx
CHANGED
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { cloneChildren } from "@react-fabric/core";
|
|
24
25
|
import {
|
|
25
26
|
type ChildrenProp,
|
|
26
27
|
type CssProp,
|
|
27
28
|
} from "@react-fabric/core/dist/types/types";
|
|
28
29
|
import classNames from "classnames";
|
|
29
|
-
import {
|
|
30
|
-
import classes from "../internal/Field.module.css";
|
|
30
|
+
import { cloneElement } from "react";
|
|
31
31
|
import { FieldWrapper } from "../internal/FieldWrapper";
|
|
32
32
|
|
|
33
33
|
export interface FieldProps extends ChildrenProp, CssProp {
|
|
@@ -83,20 +83,18 @@ export const Field = ({
|
|
|
83
83
|
<FieldWrapper {...rest}>
|
|
84
84
|
<div
|
|
85
85
|
className={classNames(
|
|
86
|
-
|
|
86
|
+
"fabric-fieldGroup",
|
|
87
87
|
!plain && !noOutline && "outline",
|
|
88
88
|
!plain && "bg-base",
|
|
89
|
+
plain && "flex-wrap",
|
|
89
90
|
"flex-1 rounded",
|
|
90
|
-
!vertical && "flex
|
|
91
|
+
!vertical && "flex",
|
|
91
92
|
)}
|
|
92
93
|
>
|
|
93
|
-
{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
cloneElement(child as AnyObject, {
|
|
98
|
-
"data-inner": true,
|
|
99
|
-
}),
|
|
94
|
+
{cloneChildren(children, (child: AnyObject) =>
|
|
95
|
+
cloneElement(child, {
|
|
96
|
+
"data-inner": true,
|
|
97
|
+
}),
|
|
100
98
|
)}
|
|
101
99
|
</div>
|
|
102
100
|
</FieldWrapper>
|
package/src/input/File.tsx
CHANGED
|
@@ -44,7 +44,6 @@ import {
|
|
|
44
44
|
import { InputWrapper } from "../internal/InputWrapper";
|
|
45
45
|
import { type InputProps } from "../types";
|
|
46
46
|
import { handleEnter } from "../utils";
|
|
47
|
-
import classes from "./File.module.css";
|
|
48
47
|
|
|
49
48
|
export interface FileInputProps
|
|
50
49
|
extends InputProps<AnyObject>,
|
|
@@ -134,7 +133,7 @@ export const FileInput = ({
|
|
|
134
133
|
}
|
|
135
134
|
} else {
|
|
136
135
|
setActualValue(e?.target.files?.item(0));
|
|
137
|
-
onChange?.(e?.target.files?.item(0) ??
|
|
136
|
+
onChange?.(e?.target.files?.item(0) ?? null);
|
|
138
137
|
if (!e && inputRef.current) inputRef.current.value = "";
|
|
139
138
|
}
|
|
140
139
|
},
|
|
@@ -195,10 +194,8 @@ export const FileInput = ({
|
|
|
195
194
|
<input
|
|
196
195
|
className={classNames(
|
|
197
196
|
"appearance-none bg-transparent py-1 px-2 flex-1 border-none outline-none ring-0",
|
|
198
|
-
|
|
199
|
-
isArray(actualValue) &&
|
|
200
|
-
actualValue?.length &&
|
|
201
|
-
"text-[var(--fabric-bg)]",
|
|
197
|
+
"fabric-fileInput",
|
|
198
|
+
isArray(actualValue) && actualValue?.length && "text-(--fabric-bg)",
|
|
202
199
|
)}
|
|
203
200
|
aria-invalid={invalid}
|
|
204
201
|
aria-disabled={disabled}
|
package/src/input/Hidden.tsx
CHANGED
package/src/input/Input.tsx
CHANGED
|
@@ -73,7 +73,7 @@ export const Input = ({
|
|
|
73
73
|
(e?: ChangeEvent<HTMLInputElement>) => {
|
|
74
74
|
const value = e?.target.value;
|
|
75
75
|
setActualValue(value ?? "");
|
|
76
|
-
onChange?.(value ??
|
|
76
|
+
onChange?.(value ?? null);
|
|
77
77
|
},
|
|
78
78
|
[onchange],
|
|
79
79
|
);
|
|
@@ -104,7 +104,7 @@ export const Input = ({
|
|
|
104
104
|
type={type}
|
|
105
105
|
ref={ref}
|
|
106
106
|
autoComplete="off"
|
|
107
|
-
{
|
|
107
|
+
autoFocus={autoFocus}
|
|
108
108
|
value={actualValue}
|
|
109
109
|
onChange={handleChange}
|
|
110
110
|
onKeyDown={handleEnterPressed}
|
package/src/input/Number.tsx
CHANGED
|
@@ -84,7 +84,7 @@ export const Number = ({
|
|
|
84
84
|
(e?: ChangeEvent<HTMLInputElement>) => {
|
|
85
85
|
const number = e?.target.valueAsNumber;
|
|
86
86
|
setActualValue(number ?? "");
|
|
87
|
-
onChange?.(number ??
|
|
87
|
+
onChange?.(number ?? null);
|
|
88
88
|
},
|
|
89
89
|
[onChange],
|
|
90
90
|
);
|
|
@@ -116,7 +116,7 @@ export const Number = ({
|
|
|
116
116
|
step={step}
|
|
117
117
|
ref={ref}
|
|
118
118
|
autoComplete="off"
|
|
119
|
-
{
|
|
119
|
+
autoFocus={autoFocus}
|
|
120
120
|
value={actualValue}
|
|
121
121
|
onChange={handleChange}
|
|
122
122
|
onKeyDown={handleEnterPressed}
|
package/src/input/Password.tsx
CHANGED
|
@@ -83,7 +83,7 @@ export const Password = ({
|
|
|
83
83
|
(e?: ChangeEvent<HTMLInputElement>) => {
|
|
84
84
|
const value = e?.target.value;
|
|
85
85
|
setActualValue(value ?? "");
|
|
86
|
-
onChange?.(value ??
|
|
86
|
+
onChange?.(value ?? null);
|
|
87
87
|
},
|
|
88
88
|
[onChange],
|
|
89
89
|
);
|
|
@@ -129,7 +129,7 @@ export const Password = ({
|
|
|
129
129
|
type={show ? "text" : "password"}
|
|
130
130
|
ref={ref}
|
|
131
131
|
autoComplete="off"
|
|
132
|
-
{
|
|
132
|
+
autoFocus={autoFocus}
|
|
133
133
|
value={actualValue}
|
|
134
134
|
onChange={handleChange}
|
|
135
135
|
onKeyDown={handleEnterPressed}
|
package/src/input/Radio.tsx
CHANGED
|
@@ -126,7 +126,7 @@ export const Radio = ({
|
|
|
126
126
|
<Icon
|
|
127
127
|
className={classNames(
|
|
128
128
|
"p-0.5 hidden peer-checked:inline-block",
|
|
129
|
-
icon && !iconChecked && "bg-primary-500 text-white",
|
|
129
|
+
icon && !iconChecked && "bg-primary-500 text-white!",
|
|
130
130
|
)}
|
|
131
131
|
color={invalid ? "danger" : "primary"}
|
|
132
132
|
size="1.25em"
|
package/src/input/RadioGroup.tsx
CHANGED
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { cloneChildren } from "@react-fabric/core";
|
|
24
25
|
import {
|
|
25
|
-
type CssProp,
|
|
26
26
|
type ChildrenProp,
|
|
27
|
+
type CssProp,
|
|
27
28
|
} from "@react-fabric/core/dist/types/types";
|
|
28
|
-
import {
|
|
29
|
+
import { cloneElement } from "react";
|
|
29
30
|
import { FieldWrapper } from "../internal/FieldWrapper";
|
|
30
31
|
import { type Radio } from "./Radio";
|
|
31
32
|
|
|
@@ -42,6 +43,23 @@ export interface RadioGroupProps extends ChildrenProp<typeof Radio>, CssProp {
|
|
|
42
43
|
* field info
|
|
43
44
|
*/
|
|
44
45
|
info?: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* field width
|
|
49
|
+
*/
|
|
50
|
+
width?: number | string;
|
|
51
|
+
/**
|
|
52
|
+
* inline label and input
|
|
53
|
+
*/
|
|
54
|
+
inline?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* label width for inline
|
|
57
|
+
*/
|
|
58
|
+
labelWidth?: string;
|
|
59
|
+
/**
|
|
60
|
+
* label width for inline
|
|
61
|
+
*/
|
|
62
|
+
optionWidth?: string;
|
|
45
63
|
/**
|
|
46
64
|
* field name
|
|
47
65
|
*/
|
|
@@ -60,14 +78,19 @@ export const RadioGroup = ({
|
|
|
60
78
|
children,
|
|
61
79
|
name,
|
|
62
80
|
className,
|
|
81
|
+
optionWidth,
|
|
63
82
|
onChange,
|
|
64
83
|
...rest
|
|
65
84
|
}: RadioGroupProps) => {
|
|
66
85
|
return (
|
|
67
86
|
<FieldWrapper {...rest}>
|
|
68
87
|
<div className={className}>
|
|
69
|
-
{
|
|
70
|
-
cloneElement(child
|
|
88
|
+
{cloneChildren(children, (child: AnyObject) =>
|
|
89
|
+
cloneElement(child, {
|
|
90
|
+
name,
|
|
91
|
+
onChange,
|
|
92
|
+
width: optionWidth,
|
|
93
|
+
}),
|
|
71
94
|
)}
|
|
72
95
|
</div>
|
|
73
96
|
</FieldWrapper>
|
|
@@ -97,7 +97,7 @@ export interface RangeProps
|
|
|
97
97
|
/**
|
|
98
98
|
* Number Range input
|
|
99
99
|
*/
|
|
100
|
-
export const
|
|
100
|
+
export const RangeSlider = ({
|
|
101
101
|
error,
|
|
102
102
|
name,
|
|
103
103
|
value,
|
|
@@ -141,7 +141,7 @@ export const Range = ({
|
|
|
141
141
|
const handleChange = useCallback(
|
|
142
142
|
(val: [number, number]) => {
|
|
143
143
|
setActualValue(val ?? [min, max]);
|
|
144
|
-
onChange?.(val ??
|
|
144
|
+
onChange?.(val ?? null);
|
|
145
145
|
},
|
|
146
146
|
[onChange, min, max],
|
|
147
147
|
);
|
package/src/input/Search.tsx
CHANGED
|
@@ -96,7 +96,7 @@ export const Search = ({
|
|
|
96
96
|
const value = e?.target.value;
|
|
97
97
|
refValue.current = value ?? "";
|
|
98
98
|
setActualValue(value ?? "");
|
|
99
|
-
onChange?.(value ??
|
|
99
|
+
onChange?.(value ?? null);
|
|
100
100
|
|
|
101
101
|
// value was cleared so force fire onSearch
|
|
102
102
|
if (searchOnChange) {
|
|
@@ -150,7 +150,7 @@ export const Search = ({
|
|
|
150
150
|
type="search"
|
|
151
151
|
ref={ref}
|
|
152
152
|
autoComplete="off"
|
|
153
|
-
{
|
|
153
|
+
autoFocus={autoFocus}
|
|
154
154
|
value={actualValue}
|
|
155
155
|
onChange={handleChange}
|
|
156
156
|
onKeyDown={handleEnterPressed}
|
package/src/input/Slider.tsx
CHANGED
|
@@ -146,7 +146,7 @@ export const Slider = ({
|
|
|
146
146
|
(value: number) => {
|
|
147
147
|
const val = useInfinity && value === max ? Infinity : value;
|
|
148
148
|
setActualValue(val ?? 0);
|
|
149
|
-
onChange?.(val ??
|
|
149
|
+
onChange?.(val ?? null);
|
|
150
150
|
},
|
|
151
151
|
[onChange, max, useInfinity],
|
|
152
152
|
);
|
package/src/input/Switch.tsx
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from "@react-fabric/core/dist/types/types";
|
|
28
28
|
import classNames from "classnames";
|
|
29
29
|
import {
|
|
30
|
+
Fragment,
|
|
30
31
|
useCallback,
|
|
31
32
|
useDeferredValue,
|
|
32
33
|
useEffect,
|
|
@@ -34,7 +35,7 @@ import {
|
|
|
34
35
|
type ChangeEvent,
|
|
35
36
|
} from "react";
|
|
36
37
|
import { ErrorIcon } from "../internal/ErrorIcon";
|
|
37
|
-
import { getBgClass, getColor } from "../utils";
|
|
38
|
+
import { getBgClass, getColor, getColorClass } from "../utils";
|
|
38
39
|
|
|
39
40
|
export interface SwitchProps extends RefProp<HTMLInputElement> {
|
|
40
41
|
/**
|
|
@@ -71,13 +72,19 @@ export interface SwitchProps extends RefProp<HTMLInputElement> {
|
|
|
71
72
|
/**
|
|
72
73
|
* cutom Switch icon
|
|
73
74
|
*/
|
|
74
|
-
color?: ColorType;
|
|
75
|
+
color?: string | ColorType;
|
|
75
76
|
/**
|
|
76
77
|
* cutom Switch icon
|
|
77
78
|
*/
|
|
78
|
-
defaultColor?: ColorType;
|
|
79
|
+
defaultColor?: string | ColorType;
|
|
79
80
|
|
|
80
81
|
name?: string;
|
|
82
|
+
|
|
83
|
+
onLabel?: string;
|
|
84
|
+
onLabelColor?: string | ColorType;
|
|
85
|
+
|
|
86
|
+
offLabel?: string;
|
|
87
|
+
offLabelColor?: string | ColorType;
|
|
81
88
|
}
|
|
82
89
|
|
|
83
90
|
export const Switch = ({
|
|
@@ -90,7 +97,13 @@ export const Switch = ({
|
|
|
90
97
|
width,
|
|
91
98
|
color,
|
|
92
99
|
name,
|
|
100
|
+
onLabel,
|
|
101
|
+
offLabel,
|
|
102
|
+
onLabelColor,
|
|
103
|
+
offLabelColor,
|
|
93
104
|
defaultColor,
|
|
105
|
+
// @ts-expect-error ignore
|
|
106
|
+
required,
|
|
94
107
|
onChange,
|
|
95
108
|
...rest
|
|
96
109
|
}: SwitchProps) => {
|
|
@@ -125,7 +138,7 @@ export const Switch = ({
|
|
|
125
138
|
actualValue && getBgClass(color ? `${color}-500` : "primary-500"),
|
|
126
139
|
!actualValue &&
|
|
127
140
|
(defaultColor ? getBgClass(`${defaultColor}-500`) : "bg-tint-200"),
|
|
128
|
-
"relative
|
|
141
|
+
"relative grid grid-cols-2 items-center h-6 min-w-10 cursor-pointer rounded-full p-1 transition-colors duration-200 ease-in-out",
|
|
129
142
|
)}
|
|
130
143
|
style={{
|
|
131
144
|
backgroundColor: actualValue
|
|
@@ -154,10 +167,33 @@ export const Switch = ({
|
|
|
154
167
|
aria-hidden="true"
|
|
155
168
|
className={classNames(
|
|
156
169
|
!disabled && "shadow-sm",
|
|
157
|
-
actualValue ? "translate-x-
|
|
158
|
-
"pointer-events-none inline-block
|
|
170
|
+
actualValue ? "translate-x-[100%]" : "translate-x-0",
|
|
171
|
+
"pointer-events-none inline-block h-4 start-1 absolute rounded-full bg-white ring-0 transition duration-200 ease-in-out",
|
|
159
172
|
)}
|
|
173
|
+
style={{
|
|
174
|
+
width: "calc(50% - 0.25rem)",
|
|
175
|
+
}}
|
|
160
176
|
/>
|
|
177
|
+
{(!!onLabel || !!offLabel) && (
|
|
178
|
+
<Fragment>
|
|
179
|
+
<span
|
|
180
|
+
className={`whitespace-nowrap text-xs px-1 ${getColorClass(onLabelColor ?? "white")}`}
|
|
181
|
+
style={{
|
|
182
|
+
color: getColor(onLabelColor),
|
|
183
|
+
}}
|
|
184
|
+
>
|
|
185
|
+
{onLabel ?? " "}
|
|
186
|
+
</span>
|
|
187
|
+
<span
|
|
188
|
+
className={`whitespace-nowrap text-xs px-1 ${getColorClass(offLabelColor ?? "base")}`}
|
|
189
|
+
style={{
|
|
190
|
+
color: getColor(offLabelColor),
|
|
191
|
+
}}
|
|
192
|
+
>
|
|
193
|
+
{offLabel ?? " "}
|
|
194
|
+
</span>
|
|
195
|
+
</Fragment>
|
|
196
|
+
)}
|
|
161
197
|
</div>
|
|
162
198
|
<ErrorIcon invalid={invalid} error={error} />
|
|
163
199
|
{label && (
|
package/src/input/Textarea.tsx
CHANGED
|
@@ -49,6 +49,10 @@ export interface TextareaProps
|
|
|
49
49
|
* increment rows on value change
|
|
50
50
|
*/
|
|
51
51
|
variableRows?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* expandable textarea
|
|
54
|
+
*/
|
|
55
|
+
expandable?: boolean;
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
export const Textarea = ({
|
|
@@ -64,6 +68,7 @@ export const Textarea = ({
|
|
|
64
68
|
rows = 5,
|
|
65
69
|
maxRows = 12,
|
|
66
70
|
variableRows,
|
|
71
|
+
expandable,
|
|
67
72
|
onChange,
|
|
68
73
|
onEnterPressed,
|
|
69
74
|
...rest
|
|
@@ -81,7 +86,7 @@ export const Textarea = ({
|
|
|
81
86
|
(e?: ChangeEvent<HTMLTextAreaElement>) => {
|
|
82
87
|
const value = e?.target.value;
|
|
83
88
|
setActualValue(value ?? "");
|
|
84
|
-
onChange?.(value ??
|
|
89
|
+
onChange?.(value ?? null);
|
|
85
90
|
},
|
|
86
91
|
[onChange],
|
|
87
92
|
);
|
|
@@ -104,6 +109,7 @@ export const Textarea = ({
|
|
|
104
109
|
disabled={disabled}
|
|
105
110
|
required={required}
|
|
106
111
|
wrapperRef={wrapperRef}
|
|
112
|
+
textareaExpandable={expandable}
|
|
107
113
|
textarea
|
|
108
114
|
{...rest}
|
|
109
115
|
>
|
|
@@ -120,10 +126,12 @@ export const Textarea = ({
|
|
|
120
126
|
name={name}
|
|
121
127
|
ref={ref}
|
|
122
128
|
autoComplete="off"
|
|
123
|
-
{
|
|
129
|
+
autoFocus={autoFocus}
|
|
124
130
|
value={actualValue}
|
|
125
131
|
onChange={handleChange}
|
|
126
|
-
onKeyDown={handleEnter(onEnterPressed
|
|
132
|
+
onKeyDown={handleEnter(onEnterPressed, {
|
|
133
|
+
preventDefault: !!onEnterPressed,
|
|
134
|
+
})}
|
|
127
135
|
/>
|
|
128
136
|
</InputWrapper>
|
|
129
137
|
);
|