@react-fabric/form 1.0.0-beta.9 → 1.0.1
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 +95 -0
- package/{src/internal/Field.module.css → css/_field.css} +94 -33
- package/{src/input/File.module.css → css/_file.css} +21 -6
- package/css/styles.css +27 -0
- package/dist/cjs/builder/FileField.js +107 -78
- package/dist/cjs/builder/FormField.js +60 -39
- package/dist/cjs/builder/SchemaEditor.js +72 -0
- package/dist/cjs/builder/components/AddSchemaFields.js +64 -0
- package/dist/cjs/builder/components/SchemaArrayForm.js +146 -0
- package/dist/cjs/builder/components/SchemaField.js +423 -0
- package/dist/cjs/form/Controller.js +66 -19
- package/dist/cjs/form/Form.js +97 -39
- package/dist/cjs/form/useForm.js +32 -0
- package/dist/cjs/hooks/useFileUploader.js +74 -45
- package/dist/cjs/hooks/useFormBuilder.js +85 -31
- package/dist/cjs/i18n/{ar.json.js → ar/form.json.js} +5 -4
- package/dist/cjs/i18n/{en.json.js → en/form.json.js} +5 -5
- package/dist/cjs/i18n/index.js +4 -4
- package/dist/cjs/index.js +41 -2
- package/dist/cjs/input/ArrayInput.js +259 -135
- package/dist/cjs/input/AvatarInput.js +99 -63
- package/dist/cjs/input/Checkbox.js +24 -25
- package/dist/cjs/input/ColorInput.js +138 -81
- package/dist/cjs/input/ColorPicker.js +78 -95
- package/dist/cjs/input/DateInput.js +192 -0
- package/dist/cjs/input/Field.js +21 -20
- package/dist/cjs/input/File.js +85 -80
- package/dist/cjs/input/Hidden.js +27 -13
- package/dist/cjs/input/Input.js +49 -48
- package/dist/cjs/input/Number.js +46 -44
- package/dist/cjs/input/Password.js +51 -49
- package/dist/cjs/input/Radio.js +26 -16
- package/dist/cjs/input/RadioGroup.js +26 -11
- package/dist/cjs/input/{Range.js → RangeSlider.js} +61 -66
- package/dist/cjs/input/Search.js +58 -64
- package/dist/cjs/input/Slider.js +57 -66
- package/dist/cjs/input/Switch.js +29 -27
- package/dist/cjs/input/Textarea.js +65 -53
- package/dist/cjs/internal/ErrorIcon.js +9 -9
- package/dist/cjs/internal/FieldWrapper.js +23 -13
- package/dist/cjs/internal/InputWrapper.js +85 -87
- package/dist/cjs/ranger/index.js +7 -7
- package/dist/cjs/ranger/utils.js +9 -4
- package/dist/cjs/select/AutoComplete.js +93 -76
- package/dist/cjs/select/DualList.js +235 -154
- package/dist/cjs/select/List.js +122 -89
- package/dist/cjs/select/Options.js +58 -54
- package/dist/cjs/select/Select.js +119 -89
- package/dist/cjs/select/helpers.js +5 -5
- package/dist/cjs/select/useSelect.js +83 -58
- package/dist/cjs/types/schema.js +43 -0
- package/dist/cjs/utils/eventHandlers.js +16 -6
- package/dist/cjs/utils/getColor.js +6 -6
- package/dist/cjs/utils/getProps.js +49 -0
- package/dist/esm/builder/FileField.js +109 -80
- package/dist/esm/builder/FormField.js +60 -39
- package/dist/esm/builder/SchemaEditor.js +72 -0
- package/dist/esm/builder/components/AddSchemaFields.js +64 -0
- package/dist/esm/builder/components/SchemaArrayForm.js +146 -0
- package/dist/esm/builder/components/SchemaField.js +423 -0
- package/dist/esm/form/Controller.js +66 -19
- package/dist/esm/form/Form.js +97 -39
- package/dist/esm/form/useForm.js +32 -0
- package/dist/esm/hooks/useFileUploader.js +75 -46
- package/dist/esm/hooks/useFormBuilder.js +84 -30
- package/dist/esm/i18n/{ar.json.js → ar/form.json.js} +5 -4
- package/dist/esm/i18n/{en.json.js → en/form.json.js} +5 -5
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/index.js +36 -1
- package/dist/esm/input/ArrayInput.js +260 -136
- package/dist/esm/input/AvatarInput.js +99 -63
- package/dist/esm/input/Checkbox.js +26 -27
- package/dist/esm/input/ColorInput.js +141 -84
- package/dist/esm/input/ColorPicker.js +80 -97
- package/dist/esm/input/DateInput.js +192 -0
- package/dist/esm/input/Field.js +21 -20
- package/dist/esm/input/File.js +89 -84
- package/dist/esm/input/Hidden.js +28 -14
- package/dist/esm/input/Input.js +51 -50
- package/dist/esm/input/Number.js +48 -46
- package/dist/esm/input/Password.js +54 -52
- package/dist/esm/input/Radio.js +27 -17
- package/dist/esm/input/RadioGroup.js +27 -12
- package/dist/esm/input/{Range.js → RangeSlider.js} +62 -67
- package/dist/esm/input/Search.js +61 -67
- package/dist/esm/input/Slider.js +58 -67
- package/dist/esm/input/Switch.js +31 -29
- package/dist/esm/input/Textarea.js +67 -55
- package/dist/esm/internal/ErrorIcon.js +11 -11
- package/dist/esm/internal/FieldWrapper.js +23 -13
- package/dist/esm/internal/InputWrapper.js +88 -90
- package/dist/esm/ranger/index.js +7 -7
- package/dist/esm/ranger/utils.js +9 -4
- package/dist/esm/select/AutoComplete.js +95 -78
- package/dist/esm/select/DualList.js +233 -152
- package/dist/esm/select/List.js +125 -92
- package/dist/esm/select/Options.js +58 -54
- package/dist/esm/select/Select.js +122 -92
- package/dist/esm/select/helpers.js +5 -5
- package/dist/esm/select/useSelect.js +84 -59
- package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
- package/dist/esm/utils/eventHandlers.js +16 -6
- package/dist/esm/utils/getColor.js +6 -6
- package/dist/esm/utils/getProps.js +49 -0
- package/dist/types/builder/FileField.d.ts +7 -4
- package/dist/types/builder/FormField.d.ts +4 -2
- package/dist/types/builder/SchemaEditor.d.ts +6 -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 +12 -0
- package/dist/types/form/Controller.d.ts +45 -3
- package/dist/types/form/Form.d.ts +38 -7
- package/dist/types/form/useForm.d.ts +6 -0
- package/dist/types/hooks/useFileUploader.d.ts +24 -3
- package/dist/types/hooks/useFormBuilder.d.ts +41 -3
- package/dist/types/index.d.ts +32 -2
- package/dist/types/input/ArrayInput.d.ts +68 -13
- package/dist/types/input/AvatarInput.d.ts +23 -6
- package/dist/types/input/Checkbox.d.ts +12 -10
- package/dist/types/input/ColorInput.d.ts +15 -5
- package/dist/types/input/ColorPicker.d.ts +10 -2
- package/dist/types/input/DateInput.d.ts +21 -0
- package/dist/types/input/Field.d.ts +9 -36
- package/dist/types/input/File.d.ts +16 -4
- package/dist/types/input/Hidden.d.ts +7 -6
- package/dist/types/input/Input.d.ts +11 -4
- package/dist/types/input/Number.d.ts +9 -4
- package/dist/types/input/Password.d.ts +9 -4
- package/dist/types/input/Radio.d.ts +9 -4
- package/dist/types/input/RadioGroup.d.ts +14 -6
- package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +11 -6
- package/dist/types/input/Search.d.ts +14 -4
- package/dist/types/input/Slider.d.ts +9 -6
- package/dist/types/input/Switch.d.ts +13 -8
- package/dist/types/input/Textarea.d.ts +15 -4
- package/dist/types/internal/ErrorIcon.d.ts +4 -1
- package/dist/types/internal/FieldWrapper.d.ts +10 -1
- package/dist/types/internal/InputWrapper.d.ts +19 -1
- package/dist/types/ranger/index.d.ts +7 -3
- package/dist/types/ranger/utils.d.ts +2 -2
- package/dist/types/select/AutoComplete.d.ts +7 -2
- package/dist/types/select/DualList.d.ts +11 -37
- package/dist/types/select/List.d.ts +7 -2
- package/dist/types/select/Options.d.ts +8 -7
- package/dist/types/select/Select.d.ts +7 -2
- package/dist/types/select/helpers.d.ts +2 -2
- package/dist/types/select/useSelect.d.ts +10 -28
- package/dist/types/types/index.d.ts +73 -39
- package/dist/types/types/schema.d.ts +78 -32
- package/dist/types/utils/eventHandlers.d.ts +4 -4
- package/dist/types/utils/getColor.d.ts +4 -4
- package/dist/types/utils/getProps.d.ts +26 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +25 -25
- package/src/builder/FileField.tsx +73 -56
- package/src/builder/FormField.tsx +66 -58
- package/src/builder/SchemaEditor.tsx +78 -0
- package/src/builder/components/AddSchemaFields.tsx +64 -0
- package/src/builder/components/SchemaArrayForm.tsx +146 -0
- package/src/builder/components/SchemaField.tsx +405 -0
- package/src/form/Controller.tsx +61 -24
- package/src/form/Form.tsx +74 -50
- package/src/form/useForm.ts +53 -0
- package/src/hooks/useFileUploader.ts +115 -84
- package/src/hooks/useFormBuilder.tsx +80 -41
- package/src/i18n/{ar.json → ar/form.json} +5 -4
- package/src/i18n/{en.json → en/form.json} +5 -5
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +34 -20
- package/src/input/ArrayInput.tsx +255 -173
- package/src/input/AvatarInput.tsx +82 -39
- package/src/input/Checkbox.tsx +30 -54
- package/src/input/ColorInput.tsx +146 -105
- package/src/input/ColorPicker.tsx +76 -102
- package/src/input/DateInput.tsx +225 -0
- package/src/input/Field.tsx +23 -65
- package/src/input/File.tsx +76 -98
- package/src/input/Hidden.tsx +36 -24
- package/src/input/Input.tsx +55 -53
- package/src/input/Number.tsx +49 -54
- package/src/input/Password.tsx +61 -66
- package/src/input/Radio.tsx +28 -37
- package/src/input/RadioGroup.tsx +30 -25
- package/src/input/{Range.tsx → RangeSlider.tsx} +81 -109
- package/src/input/Search.tsx +64 -77
- package/src/input/Slider.tsx +80 -109
- package/src/input/Switch.tsx +39 -53
- package/src/input/Textarea.tsx +72 -59
- package/src/internal/ErrorIcon.tsx +22 -21
- package/src/internal/FieldWrapper.tsx +33 -23
- package/src/internal/InputWrapper.tsx +132 -143
- package/src/ranger/index.tsx +37 -117
- package/src/ranger/utils.ts +12 -11
- package/src/select/AutoComplete.tsx +113 -123
- package/src/select/DualList.tsx +218 -204
- package/src/select/List.tsx +130 -97
- package/src/select/Options.tsx +59 -57
- package/src/select/Select.tsx +148 -122
- package/src/select/helpers.ts +13 -8
- package/src/select/useSelect.tsx +110 -127
- package/src/types/index.ts +76 -45
- package/src/types/schema.ts +97 -40
- package/src/utils/eventHandlers.ts +24 -26
- package/src/utils/getColor.ts +9 -8
- package/src/utils/getProps.ts +47 -0
- package/src/utils/index.ts +1 -0
- 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
package/src/types/schema.ts
CHANGED
|
@@ -21,80 +21,137 @@
|
|
|
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
|
-
|
|
24
|
+
import type { ChildNode } from "@react-fabric/core/dist/types/types";
|
|
25
|
+
import { type DateLike } from "@react-fabric/date";
|
|
26
|
+
|
|
27
|
+
export enum DATA_TYPES {
|
|
28
|
+
TEXT = "text",
|
|
29
|
+
COLOR = "color",
|
|
30
|
+
BOOL = "bool",
|
|
31
|
+
DATE = "date",
|
|
32
|
+
DATETIME = "datetime",
|
|
33
|
+
STRING = "string",
|
|
34
|
+
NUMBER = "number",
|
|
35
|
+
RANGE = "range",
|
|
36
|
+
FILE = "file",
|
|
37
|
+
AVATAR = "avatar",
|
|
38
|
+
SCHEMA = "schema",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const SCHEMA_CUSTOM_LIST = "--CUSTOM--";
|
|
42
|
+
|
|
43
|
+
interface SingleValue {
|
|
44
|
+
multiple?: false;
|
|
45
|
+
minItems?: never;
|
|
46
|
+
maxItems?: never;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface MultipleValue {
|
|
50
|
+
multiple: true;
|
|
51
|
+
minItems?: number;
|
|
52
|
+
maxItems?: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type ValueType = SingleValue | MultipleValue;
|
|
56
|
+
|
|
57
|
+
interface BaseSchema {
|
|
25
58
|
id: string;
|
|
26
59
|
label: string;
|
|
27
60
|
datatype: string;
|
|
28
61
|
required?: boolean;
|
|
29
|
-
multiple?: boolean;
|
|
30
62
|
defaultValue?: AnyObject;
|
|
31
63
|
}
|
|
32
64
|
|
|
33
|
-
interface
|
|
34
|
-
datatype:
|
|
65
|
+
export interface DefaultSchema extends BaseSchema {
|
|
66
|
+
datatype: DATA_TYPES.TEXT | DATA_TYPES.COLOR;
|
|
35
67
|
}
|
|
36
68
|
|
|
37
|
-
interface BooleanSchema extends
|
|
38
|
-
datatype:
|
|
39
|
-
defaultValue?: boolean;
|
|
69
|
+
export interface BooleanSchema extends BaseSchema {
|
|
70
|
+
datatype: DATA_TYPES.BOOL;
|
|
40
71
|
}
|
|
41
72
|
|
|
42
|
-
interface StringSchema extends
|
|
43
|
-
datatype:
|
|
44
|
-
options?: string[];
|
|
73
|
+
export interface StringSchema extends BaseSchema {
|
|
74
|
+
datatype: DATA_TYPES.STRING;
|
|
45
75
|
regex?: string;
|
|
46
|
-
|
|
76
|
+
options?: string[];
|
|
77
|
+
optionList?: string;
|
|
78
|
+
allowCustom?: boolean;
|
|
47
79
|
}
|
|
48
80
|
|
|
49
|
-
interface RangeSchema extends
|
|
50
|
-
datatype:
|
|
81
|
+
export interface RangeSchema extends BaseSchema {
|
|
82
|
+
datatype: DATA_TYPES.RANGE;
|
|
51
83
|
min?: number;
|
|
52
84
|
max?: number;
|
|
53
85
|
step?: number;
|
|
54
|
-
defaultValue?: [number, number];
|
|
55
86
|
}
|
|
56
87
|
|
|
57
|
-
interface
|
|
58
|
-
datatype:
|
|
59
|
-
min?:
|
|
60
|
-
max?:
|
|
61
|
-
step?: number;
|
|
62
|
-
defaultValue?: number;
|
|
88
|
+
export interface DateSchema extends BaseSchema {
|
|
89
|
+
datatype: DATA_TYPES.DATE | DATA_TYPES.DATETIME;
|
|
90
|
+
min?: DateLike;
|
|
91
|
+
max?: DateLike;
|
|
63
92
|
}
|
|
64
93
|
|
|
65
|
-
interface
|
|
66
|
-
datatype:
|
|
94
|
+
export interface NumberSchema extends BaseSchema {
|
|
95
|
+
datatype: DATA_TYPES.NUMBER;
|
|
67
96
|
min?: number;
|
|
68
97
|
max?: number;
|
|
69
98
|
step?: number;
|
|
70
|
-
defaultValue?: number;
|
|
71
99
|
}
|
|
72
100
|
|
|
73
|
-
export interface FileSchema extends
|
|
74
|
-
datatype:
|
|
101
|
+
export interface FileSchema extends BaseSchema {
|
|
102
|
+
datatype: DATA_TYPES.FILE;
|
|
75
103
|
accept?: string;
|
|
76
104
|
}
|
|
77
105
|
|
|
78
|
-
export interface AvatarSchema extends
|
|
79
|
-
datatype:
|
|
106
|
+
export interface AvatarSchema extends BaseSchema {
|
|
107
|
+
datatype: DATA_TYPES.AVATAR;
|
|
80
108
|
multiple?: false;
|
|
81
109
|
}
|
|
82
110
|
|
|
83
111
|
export type SchemaType =
|
|
84
|
-
|
|
|
85
|
-
| BooleanSchema
|
|
86
|
-
| StringSchema
|
|
87
|
-
| RangeSchema
|
|
88
|
-
|
|
|
89
|
-
|
|
|
90
|
-
| FileSchema
|
|
91
|
-
| AvatarSchema;
|
|
92
|
-
|
|
93
|
-
export interface ChildSchema extends
|
|
94
|
-
datatype:
|
|
112
|
+
| (DefaultSchema & ValueType)
|
|
113
|
+
| (BooleanSchema & ValueType)
|
|
114
|
+
| (StringSchema & ValueType)
|
|
115
|
+
| (RangeSchema & ValueType)
|
|
116
|
+
| (DateSchema & ValueType)
|
|
117
|
+
| (NumberSchema & ValueType)
|
|
118
|
+
| (FileSchema & ValueType)
|
|
119
|
+
| (AvatarSchema & ValueType);
|
|
120
|
+
|
|
121
|
+
export interface ChildSchema extends BaseSchema {
|
|
122
|
+
datatype: DATA_TYPES.SCHEMA;
|
|
95
123
|
inline?: boolean;
|
|
96
124
|
schema: SchemaType[];
|
|
97
|
-
defaultValue?: never;
|
|
98
125
|
}
|
|
99
126
|
|
|
100
|
-
export type
|
|
127
|
+
export type SchemaDef = SchemaType | (ChildSchema & ValueType);
|
|
128
|
+
export type FormSchema = SchemaDef[];
|
|
129
|
+
|
|
130
|
+
export interface SchemaEditorProps {
|
|
131
|
+
/**
|
|
132
|
+
* default form schema
|
|
133
|
+
*/
|
|
134
|
+
schemaDef: FormSchema;
|
|
135
|
+
/**
|
|
136
|
+
* is dynamic schema (allow add/remove)
|
|
137
|
+
*/
|
|
138
|
+
dynamic?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* acceptable list of data types
|
|
141
|
+
*/
|
|
142
|
+
acceptableTypes?: DATA_TYPES[];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* available option lists in application
|
|
146
|
+
*/
|
|
147
|
+
optionLists?: string[];
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* footer actions
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
children?: ChildNode | Array<ChildNode>;
|
|
154
|
+
|
|
155
|
+
onChange?: (schema: FormSchema) => void;
|
|
156
|
+
onSubmit?: (schema: FormSchema) => void;
|
|
157
|
+
}
|
|
@@ -23,26 +23,27 @@
|
|
|
23
23
|
|
|
24
24
|
/* istanbul ignore file */
|
|
25
25
|
|
|
26
|
-
import {
|
|
26
|
+
import { useFloatingTree } from "@floating-ui/react";
|
|
27
|
+
import { useDebounce } from "@react-fabric/core";
|
|
27
28
|
import { type KeyboardEvent, type MouseEvent } from "react";
|
|
28
29
|
|
|
29
30
|
/** ***************** common handler for enter press *******************/
|
|
30
|
-
export
|
|
31
|
-
callback?: (e: KeyboardEvent) => void,
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
e.
|
|
44
|
-
|
|
45
|
-
) {
|
|
31
|
+
export function useHandleEnter<T extends HTMLElement = HTMLInputElement>(
|
|
32
|
+
callback?: (e: KeyboardEvent<T>) => void,
|
|
33
|
+
{ stopPropagation = false, preventDefault = false }: { stopPropagation?: boolean; preventDefault?: boolean } = {},
|
|
34
|
+
) {
|
|
35
|
+
const cbHandle = useDebounce(callback ?? (() => undefined), [callback], 100);
|
|
36
|
+
const tree = useFloatingTree();
|
|
37
|
+
return (e: KeyboardEvent<T>) => {
|
|
38
|
+
// prevent propagation of event if input within dropdown (work around for floating-ui typeahead)
|
|
39
|
+
if (tree && e.key !== "Escape") {
|
|
40
|
+
e?.stopPropagation();
|
|
41
|
+
}
|
|
42
|
+
// blur input on escape key press
|
|
43
|
+
if (e.key === "Escape") {
|
|
44
|
+
e.currentTarget.blur();
|
|
45
|
+
}
|
|
46
|
+
if (!e.shiftKey && !e.altKey && !e.metaKey && e.key === "Enter" && callback) {
|
|
46
47
|
if (stopPropagation) e?.stopPropagation();
|
|
47
48
|
cbHandle(e);
|
|
48
49
|
if (preventDefault) {
|
|
@@ -51,22 +52,19 @@ export const handleEnter = (
|
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
|
-
}
|
|
55
|
+
}
|
|
55
56
|
|
|
56
57
|
/** ***************** common handler for mouse primary click *******************/
|
|
57
|
-
export
|
|
58
|
+
export function handleClick(
|
|
58
59
|
callback?: (e: MouseEvent) => void,
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
preventDefault = false,
|
|
62
|
-
}: { stopPropagation?: boolean; preventDefault?: boolean } = {},
|
|
63
|
-
) => {
|
|
60
|
+
{ stopPropagation = false, preventDefault = false }: { stopPropagation?: boolean; preventDefault?: boolean } = {},
|
|
61
|
+
) {
|
|
64
62
|
return (e: MouseEvent) => {
|
|
65
63
|
if (stopPropagation) e?.stopPropagation();
|
|
66
|
-
(e?.button ?? 0) === 0
|
|
64
|
+
if ((e?.button ?? 0) === 0) callback?.(e);
|
|
67
65
|
if (preventDefault) {
|
|
68
66
|
e.preventDefault();
|
|
69
67
|
return false;
|
|
70
68
|
}
|
|
71
69
|
};
|
|
72
|
-
}
|
|
70
|
+
}
|
package/src/utils/getColor.ts
CHANGED
|
@@ -23,25 +23,26 @@
|
|
|
23
23
|
|
|
24
24
|
import { isColor } from "@react-fabric/utilities";
|
|
25
25
|
|
|
26
|
-
export
|
|
26
|
+
export function getColor(color?: string) {
|
|
27
27
|
if (color && isColor(color)) {
|
|
28
28
|
return color;
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
export
|
|
32
|
+
export function getBgClass(bg: string) {
|
|
33
33
|
if (bg && !isColor(bg)) {
|
|
34
34
|
return `bg-${bg}`;
|
|
35
35
|
}
|
|
36
|
-
}
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
export
|
|
38
|
+
export function getColorClass(color: string) {
|
|
39
39
|
if (color && !isColor(color)) {
|
|
40
40
|
return `text-${color}`;
|
|
41
41
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getBorderClass(color: string) {
|
|
44
45
|
if (color && !isColor(color)) {
|
|
45
46
|
return `border-${color}`;
|
|
46
47
|
}
|
|
47
|
-
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Fabric
|
|
3
|
+
* @version 1.0.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2024 Adarsh Pastakia
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { WrapperProps } from "../types";
|
|
27
|
+
|
|
28
|
+
export function getWrapperProps<T extends WrapperProps & KeyValue>(props: T): WrapperProps {
|
|
29
|
+
return {
|
|
30
|
+
appendLabel: props.appendLabel,
|
|
31
|
+
name: props.name,
|
|
32
|
+
info: props.info,
|
|
33
|
+
inline: props.inline,
|
|
34
|
+
label: props.label,
|
|
35
|
+
labelWidth: props.labelWidth,
|
|
36
|
+
required: props.required,
|
|
37
|
+
disabled: props.disabled,
|
|
38
|
+
width: props.width,
|
|
39
|
+
error: props.error,
|
|
40
|
+
invalid: props.invalid,
|
|
41
|
+
borderless: props.borderless,
|
|
42
|
+
decorateEnd: props.decorateEnd,
|
|
43
|
+
decorateEndHideWhenEmpty: props.decorateEndHideWhenEmpty,
|
|
44
|
+
decorateEndShowWhenEmpty: props.decorateEndShowWhenEmpty,
|
|
45
|
+
decorateStart: props.decorateStart,
|
|
46
|
+
};
|
|
47
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer var{.arrayInput{& [data-ref=fieldWrapper]{flex:1 1 0%}& .addButton :global(.buttonInner){color:theme(colors.tint.600);outline:1px dashed theme(colors.tint.600);&[data-invalid=true]{background-color:theme(colors.danger.100);color:theme(colors.danger.600);outline:1px dashed theme(colors.danger.600)}}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer comp{.colorPicker{--color-shadow:theme(borderColor.base);& input{@apply bg-base text-base !border !border-solid !rounded-sm !border-base focus:!border-primary !shadow-none;line-height:2;padding:0 4px!important}& label{@apply !text-base}& :global(.flexbox-fix){@apply !border-t-muted justify-center;&>div>div{@apply text-center}& span>div{box-shadow:inset 0 0 1px 1px theme(borderColor.base)!important}}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer comp{.fileInput{&::-webkit-file-upload-button{@apply bg-primary-500 opacity-80 hover:opacity-90 text-white rounded border-none py-0 cursor-pointer}&[aria-invalid=true]::-webkit-file-upload-button{@apply bg-danger-500}&:disabled::-webkit-file-upload-button{@apply bg-muted pointer-events-none}&[readOnly]{@apply pointer-events-none}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer comp{}@layer var{.inputWrapper{&:after{inset-inline:50%;transition:all .3s;transition-delay:.1s}& .decorate:has([data-ref=button]){align-self:stretch;display:flex}&:has(input[disabled],textarea[disabled]){background-color:theme(colors.tint.50);cursor:not-allowed;& input,& textarea{cursor:not-allowed}}&:focus-within,&:has([data-open=true]){background-color:var(--fabric-input-focus);outline-color:var(--primary);z-index:1;&:not(:has([aria-readonly=true]:not([hidden]))):after{inset-inline:0}}&:global(.fixed){box-shadow:0 0 2rem .5rem var(--fabric-shadow)}& input,& textarea{max-width:100%}&>input[type=number]+.inputClear{margin-inline:-3rem 2rem}& input::-ms-clear,& select::-ms-clear,& textarea::-ms-clear{display:none}& input[type=search]::-webkit-search-cancel-button{display:none}& input[type=password]:not(:placeholder-shown){font-family:caption;letter-spacing:2px}& input:-webkit-autofill{box-shadow:0 0 0 999em var(--fabric-input) inset;-webkit-text-fill-color:theme(colors.accent.700)}& input:-webkit-autofill:focus{box-shadow:0 0 0 999em var(--fabric-input-focus) inset;-webkit-text-fill-color:theme(colors.accent.700)}&.invalidWrapper{outline-color:theme(colors.danger.500);&:after{background-color:theme(colors.danger.500)}}}.fieldGroup{>*{line-height:1}>:not(:first-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-start-radius:0;border-start-start-radius:0}}>:not(:last-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-end-radius:0;border-start-end-radius:0}}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer var{.arrayInput{& [data-ref=fieldWrapper]{flex:1 1 0%}& .addButton :global(.buttonInner){color:theme(colors.tint.600);outline:1px dashed theme(colors.tint.600);&[data-invalid=true]{background-color:theme(colors.danger.100);color:theme(colors.danger.600);outline:1px dashed theme(colors.danger.600)}}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer comp{.colorPicker{--color-shadow:theme(borderColor.base);& input{@apply bg-base text-base !border !border-solid !rounded-sm !border-base focus:!border-primary !shadow-none;line-height:2;padding:0 4px!important}& label{@apply !text-base}& :global(.flexbox-fix){@apply !border-t-muted justify-center;&>div>div{@apply text-center}& span>div{box-shadow:inset 0 0 1px 1px theme(borderColor.base)!important}}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer comp{.fileInput{&::-webkit-file-upload-button{@apply bg-primary-500 opacity-80 hover:opacity-90 text-white rounded border-none py-0 cursor-pointer}&[aria-invalid=true]::-webkit-file-upload-button{@apply bg-danger-500}&:disabled::-webkit-file-upload-button{@apply bg-muted pointer-events-none}&[readOnly]{@apply pointer-events-none}}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
@layer comp{}@layer var{.inputWrapper{&:after{inset-inline:50%;transition:all .3s;transition-delay:.1s}& .decorate:has([data-ref=button]){align-self:stretch;display:flex}&:has(input[disabled],textarea[disabled]){background-color:theme(colors.tint.50);cursor:not-allowed;& input,& textarea{cursor:not-allowed}}&:focus-within,&:has([data-open=true]){background-color:var(--fabric-input-focus);outline-color:var(--primary);z-index:1;&:not(:has([aria-readonly=true]:not([hidden]))):after{inset-inline:0}}&:global(.fixed){box-shadow:0 0 2rem .5rem var(--fabric-shadow)}& input,& textarea{max-width:100%}&>input[type=number]+.inputClear{margin-inline:-3rem 2rem}& input::-ms-clear,& select::-ms-clear,& textarea::-ms-clear{display:none}& input[type=search]::-webkit-search-cancel-button{display:none}& input[type=password]:not(:placeholder-shown){font-family:caption;letter-spacing:2px}& input:-webkit-autofill{box-shadow:0 0 0 999em var(--fabric-input) inset;-webkit-text-fill-color:theme(colors.accent.700)}& input:-webkit-autofill:focus{box-shadow:0 0 0 999em var(--fabric-input-focus) inset;-webkit-text-fill-color:theme(colors.accent.700)}&.invalidWrapper{outline-color:theme(colors.danger.500);&:after{background-color:theme(colors.danger.500)}}}.fieldGroup{>*{line-height:1}>:not(:first-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-start-radius:0;border-start-start-radius:0}}>:not(:last-child){&,&>[data-ref=button]>[role=button],&>[role=button],&>div{border-end-end-radius:0;border-start-end-radius:0}}}}
|