@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
|
@@ -6,32 +6,45 @@ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
|
6
6
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
7
7
|
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
8
8
|
import { Avatar, Icon, ProgressBar } from '@react-fabric/core';
|
|
9
|
+
import { cn } from '@react-fabric/utilities';
|
|
9
10
|
import { useState, useEffect } from 'react';
|
|
10
11
|
import { useFileUploader } from '../hooks/useFileUploader.js';
|
|
11
12
|
import { HiddenInput } from './Hidden.js';
|
|
12
13
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
14
|
|
|
14
|
-
var _excluded = ["
|
|
15
|
+
var _excluded = ["size", "avatarName", "avatarClassName", "value", "rounded", "defaultValue", "fallbackIcon", "variant", "fileUrl", "uploadHandler", "onChange"];
|
|
15
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
/**
|
|
19
|
+
* Avatar input component for uploading and displaying user avatars.
|
|
20
|
+
* It allows users to select an image file, upload it, and display the avatar.
|
|
21
|
+
* It also provides a way to remove the uploaded file and shows upload progress.
|
|
22
|
+
*/
|
|
17
23
|
var AvatarInput = function AvatarInput(_ref) {
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
_ref$size = _ref.size,
|
|
24
|
+
var _files$2;
|
|
25
|
+
var _ref$size = _ref.size,
|
|
21
26
|
size = _ref$size === void 0 ? "6rem" : _ref$size,
|
|
27
|
+
avatarName = _ref.avatarName,
|
|
28
|
+
avatarClassName = _ref.avatarClassName,
|
|
29
|
+
value = _ref.value,
|
|
30
|
+
rounded = _ref.rounded,
|
|
31
|
+
defaultValue = _ref.defaultValue,
|
|
32
|
+
fallbackIcon = _ref.fallbackIcon,
|
|
33
|
+
variant = _ref.variant,
|
|
22
34
|
fileUrl = _ref.fileUrl,
|
|
23
35
|
uploadHandler = _ref.uploadHandler,
|
|
36
|
+
_onChange = _ref.onChange,
|
|
24
37
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
-
var _useFileUploader = useFileUploader(
|
|
26
|
-
var _ref2 = _asyncToGenerator(
|
|
27
|
-
return _regeneratorRuntime.wrap(function
|
|
38
|
+
var _useFileUploader = useFileUploader(/*#__PURE__*/function () {
|
|
39
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, config) {
|
|
40
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
28
41
|
while (1) switch (_context.prev = _context.next) {
|
|
29
42
|
case 0:
|
|
30
|
-
_context.next =
|
|
43
|
+
_context.next = 1;
|
|
31
44
|
return uploadHandler === null || uploadHandler === void 0 ? void 0 : uploadHandler(data, config);
|
|
32
|
-
case
|
|
45
|
+
case 1:
|
|
33
46
|
return _context.abrupt("return", _context.sent);
|
|
34
|
-
case
|
|
47
|
+
case 2:
|
|
35
48
|
case "end":
|
|
36
49
|
return _context.stop();
|
|
37
50
|
}
|
|
@@ -40,9 +53,14 @@ var AvatarInput = function AvatarInput(_ref) {
|
|
|
40
53
|
return function (_x, _x2) {
|
|
41
54
|
return _ref2.apply(this, arguments);
|
|
42
55
|
};
|
|
43
|
-
}(),
|
|
56
|
+
}(), value !== null && value !== void 0 ? value : defaultValue, {
|
|
57
|
+
multiple: false,
|
|
58
|
+
onChange: function onChange(files) {
|
|
59
|
+
var _files$path;
|
|
60
|
+
return _onChange === null || _onChange === void 0 ? void 0 : _onChange((_files$path = files === null || files === void 0 ? void 0 : files.path) !== null && _files$path !== void 0 ? _files$path : null);
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
44
63
|
files = _useFileUploader.files,
|
|
45
|
-
list = _useFileUploader.list,
|
|
46
64
|
upload = _useFileUploader.upload,
|
|
47
65
|
remove = _useFileUploader.remove;
|
|
48
66
|
var _useState = useState(""),
|
|
@@ -50,7 +68,7 @@ var AvatarInput = function AvatarInput(_ref) {
|
|
|
50
68
|
base64 = _useState2[0],
|
|
51
69
|
setBase64 = _useState2[1];
|
|
52
70
|
useEffect(function () {
|
|
53
|
-
if (
|
|
71
|
+
if (files !== null && files !== void 0 && files.length) {
|
|
54
72
|
var _files$;
|
|
55
73
|
var file = files === null || files === void 0 || (_files$ = files[0]) === null || _files$ === void 0 ? void 0 : _files$.file;
|
|
56
74
|
void (file && new Response(file).blob().then(function (blob) {
|
|
@@ -64,23 +82,32 @@ var AvatarInput = function AvatarInput(_ref) {
|
|
|
64
82
|
reader.readAsDataURL(blob);
|
|
65
83
|
}));
|
|
66
84
|
} else {
|
|
67
|
-
|
|
85
|
+
var _ref3, _fileUrl;
|
|
86
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
87
|
+
setBase64((_ref3 = (_fileUrl = fileUrl === null || fileUrl === void 0 ? void 0 : fileUrl(defaultValue !== null && defaultValue !== void 0 ? defaultValue : "")) !== null && _fileUrl !== void 0 ? _fileUrl : defaultValue) !== null && _ref3 !== void 0 ? _ref3 : "");
|
|
68
88
|
}
|
|
69
|
-
}, [files,
|
|
89
|
+
}, [files, defaultValue, fileUrl]);
|
|
70
90
|
useEffect(function () {
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
var _fileUrl2, _fileUrl3;
|
|
92
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
93
|
+
if (!value && defaultValue) setBase64((_fileUrl2 = fileUrl === null || fileUrl === void 0 ? void 0 : fileUrl(defaultValue)) !== null && _fileUrl2 !== void 0 ? _fileUrl2 : defaultValue);
|
|
94
|
+
// eslint-disable-next-line @eslint-react/set-state-in-effect
|
|
95
|
+
if (value) setBase64((_fileUrl3 = fileUrl === null || fileUrl === void 0 ? void 0 : fileUrl(value)) !== null && _fileUrl3 !== void 0 ? _fileUrl3 : value);
|
|
96
|
+
}, [value, defaultValue, fileUrl]);
|
|
74
97
|
return /*#__PURE__*/jsxs("div", {
|
|
75
|
-
className: "flex flex-nowrap items-end",
|
|
98
|
+
className: "flex flex-nowrap items-end overflow-hidden p-px",
|
|
76
99
|
children: [/*#__PURE__*/jsxs("div", {
|
|
77
|
-
className: "inline-block leading-none
|
|
100
|
+
className: cn("inline-block leading-none relative outline overflow-hidden", rounded && "rounded-full", !rounded && "rounded"),
|
|
78
101
|
children: [/*#__PURE__*/jsx(Avatar, {
|
|
79
|
-
name: "temp",
|
|
102
|
+
name: avatarName !== null && avatarName !== void 0 ? avatarName : "temp",
|
|
80
103
|
size: size,
|
|
81
|
-
avatar: base64
|
|
104
|
+
avatar: base64,
|
|
105
|
+
rounded: rounded,
|
|
106
|
+
variant: variant,
|
|
107
|
+
fallbackIcon: fallbackIcon,
|
|
108
|
+
className: avatarClassName
|
|
82
109
|
}), /*#__PURE__*/jsxs("div", {
|
|
83
|
-
className: "absolute inset-x-0 bottom-0 cursor-pointer
|
|
110
|
+
className: "absolute inset-x-0 bottom-0 cursor-pointer opacity-50 bg-black/50 hover:opacity-90 text-white text-xs text-center py-1",
|
|
84
111
|
children: [/*#__PURE__*/jsx("span", {
|
|
85
112
|
children: "Edit"
|
|
86
113
|
}), /*#__PURE__*/jsx("input", {
|
|
@@ -93,47 +120,56 @@ var AvatarInput = function AvatarInput(_ref) {
|
|
|
93
120
|
})]
|
|
94
121
|
})]
|
|
95
122
|
}), /*#__PURE__*/jsx(HiddenInput, _objectSpread({
|
|
96
|
-
hiddenValue:
|
|
123
|
+
hiddenValue: files === null || files === void 0 || (_files$2 = files[0]) === null || _files$2 === void 0 ? void 0 : _files$2.path
|
|
97
124
|
}, rest)), files.map(function (file, idx) {
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
return (
|
|
126
|
+
/*#__PURE__*/
|
|
127
|
+
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
128
|
+
jsxs("div", {
|
|
129
|
+
className: "px-2 py-1 flex-1 overflow-hidden",
|
|
130
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
131
|
+
className: "flex flex-nowrap gap-1 items-center",
|
|
132
|
+
children: [file.error && /*#__PURE__*/jsx("div", {
|
|
133
|
+
className: "flex-1 truncate px-2",
|
|
134
|
+
children: /*#__PURE__*/jsx("span", {
|
|
135
|
+
className: "text-danger-600",
|
|
136
|
+
children: file.error
|
|
137
|
+
})
|
|
138
|
+
}), file.progress && /*#__PURE__*/jsx("button", {
|
|
139
|
+
type: "button",
|
|
140
|
+
className: cn("size-fit flex-content leading-0 cursor-pointer"),
|
|
141
|
+
onClick: function onClick() {
|
|
142
|
+
var _file$abort;
|
|
143
|
+
return (_file$abort = file.abort) === null || _file$abort === void 0 ? void 0 : _file$abort.call(file);
|
|
144
|
+
},
|
|
145
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
146
|
+
icon: "icon-[mdi--stop]",
|
|
147
|
+
bg: "danger",
|
|
148
|
+
color: "white",
|
|
149
|
+
size: "sm",
|
|
150
|
+
className: "p-0.5",
|
|
151
|
+
"aria-label": "abort"
|
|
152
|
+
})
|
|
153
|
+
}), !file.progress && /*#__PURE__*/jsx("button", {
|
|
154
|
+
type: "button",
|
|
155
|
+
className: cn("size-fit flex-content leading-0 cursor-pointer"),
|
|
156
|
+
onClick: function onClick() {
|
|
157
|
+
return remove(file.key);
|
|
158
|
+
},
|
|
159
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
160
|
+
icon: "icon-[mdi--trash-can-outline]",
|
|
161
|
+
color: "danger",
|
|
162
|
+
size: "sm",
|
|
163
|
+
"aria-label": "remove"
|
|
164
|
+
})
|
|
165
|
+
})]
|
|
166
|
+
}), file.progress && /*#__PURE__*/jsx(ProgressBar, {
|
|
167
|
+
animate: true,
|
|
168
|
+
value: file.progress * 100,
|
|
169
|
+
size: "xxs"
|
|
130
170
|
})]
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
value: file.progress * 100,
|
|
134
|
-
size: "xxs"
|
|
135
|
-
})]
|
|
136
|
-
}, idx);
|
|
171
|
+
}, idx)
|
|
172
|
+
);
|
|
137
173
|
})]
|
|
138
174
|
});
|
|
139
175
|
};
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
4
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
5
|
+
import { useControlledValue, Icon } from '@react-fabric/core';
|
|
6
|
+
import { cn } from '@react-fabric/utilities';
|
|
7
|
+
import { useMemo, useCallback } from 'react';
|
|
9
8
|
import { ErrorIcon } from '../internal/ErrorIcon.js';
|
|
10
9
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
11
10
|
|
|
12
|
-
var _excluded = ["ref", "label", "
|
|
11
|
+
var _excluded = ["ref", "label", "name", "checked", "invalid", "disabled", "error", "width", "icon", "iconChecked", "onChange"];
|
|
13
12
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
15
|
-
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
+
/**
|
|
15
|
+
* Checkbox component for rendering a checkbox input with label and error handling.
|
|
16
|
+
* It supports custom icons for checked and unchecked states, and handles disabled and invalid states.
|
|
17
|
+
* The component uses a deferred value to manage the checked state, ensuring smooth updates.
|
|
18
|
+
* It also provides an error icon to indicate validation errors.
|
|
19
|
+
*/
|
|
20
|
+
function Checkbox(_ref) {
|
|
16
21
|
var ref = _ref.ref,
|
|
17
22
|
label = _ref.label,
|
|
18
|
-
value = _ref.value,
|
|
19
23
|
name = _ref.name,
|
|
20
24
|
checked = _ref.checked,
|
|
21
25
|
invalid = _ref.invalid,
|
|
@@ -26,33 +30,28 @@ var Checkbox = function Checkbox(_ref) {
|
|
|
26
30
|
iconChecked = _ref.iconChecked,
|
|
27
31
|
onChange = _ref.onChange,
|
|
28
32
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
setActualValue = _useState2[1];
|
|
33
|
-
var deferred = useDeferredValue(!!checked);
|
|
33
|
+
var _useControlledValue = useControlledValue(!!checked, false),
|
|
34
|
+
currentValue = _useControlledValue.currentValue,
|
|
35
|
+
updateValue = _useControlledValue.updateValue;
|
|
34
36
|
var iconOn = useMemo(function () {
|
|
35
37
|
var _ref2;
|
|
36
|
-
return (_ref2 = iconChecked !== null && iconChecked !== void 0 ? iconChecked : icon) !== null && _ref2 !== void 0 ? _ref2 :
|
|
38
|
+
return (_ref2 = iconChecked !== null && iconChecked !== void 0 ? iconChecked : icon) !== null && _ref2 !== void 0 ? _ref2 : "icon-[mdi--checkbox-marked]";
|
|
37
39
|
}, [icon, iconChecked]);
|
|
38
40
|
var iconOff = useMemo(function () {
|
|
39
|
-
return icon !== null && icon !== void 0 ? icon :
|
|
41
|
+
return icon !== null && icon !== void 0 ? icon : "icon-[mdi--checkbox-blank-outline]";
|
|
40
42
|
}, [icon]);
|
|
41
|
-
useEffect(function () {
|
|
42
|
-
setActualValue(deferred);
|
|
43
|
-
}, [deferred]);
|
|
44
43
|
var handleChange = useCallback(function (e) {
|
|
45
44
|
var _e$target$checked, _e$target$checked2;
|
|
46
|
-
|
|
45
|
+
updateValue((_e$target$checked = e === null || e === void 0 ? void 0 : e.target.checked) !== null && _e$target$checked !== void 0 ? _e$target$checked : false);
|
|
47
46
|
onChange === null || onChange === void 0 || onChange((_e$target$checked2 = e === null || e === void 0 ? void 0 : e.target.checked) !== null && _e$target$checked2 !== void 0 ? _e$target$checked2 : false);
|
|
48
|
-
}, [onChange,
|
|
47
|
+
}, [onChange, updateValue]);
|
|
49
48
|
return /*#__PURE__*/jsxs("label", {
|
|
50
|
-
className:
|
|
49
|
+
className: cn(invalid ? "ring-danger-500" : "ring-primary-500", disabled ? "opacity-50 cursor-not-allowed" : " opacity-85 hover:opacity-100 cursor-pointer", "inline-flex gap-1 py-1 items-center relative rounded ring-offset-2 has-focus-visible:ring-1"),
|
|
51
50
|
style: {
|
|
52
51
|
width: width
|
|
53
52
|
},
|
|
54
53
|
children: [/*#__PURE__*/jsx("input", _objectSpread({
|
|
55
|
-
className:
|
|
54
|
+
className: cn("appearance-none absolute opacity-0 inset-0 bg-transparent border-none outline-none ring-0"),
|
|
56
55
|
"aria-invalid": invalid,
|
|
57
56
|
"aria-disabled": disabled,
|
|
58
57
|
disabled: disabled,
|
|
@@ -63,21 +62,21 @@ var Checkbox = function Checkbox(_ref) {
|
|
|
63
62
|
tabIndex: 0,
|
|
64
63
|
name: name,
|
|
65
64
|
autoComplete: "off",
|
|
66
|
-
checked:
|
|
65
|
+
checked: !!currentValue,
|
|
67
66
|
onChange: handleChange
|
|
68
67
|
}, rest)), /*#__PURE__*/jsx(Icon, {
|
|
69
|
-
className:
|
|
68
|
+
className: cn("p-0.5", currentValue && icon && !iconChecked && "bg-primary-500 text-white!"),
|
|
70
69
|
size: "1.25em",
|
|
71
70
|
color: invalid ? "danger" : "primary",
|
|
72
|
-
icon:
|
|
71
|
+
icon: currentValue ? iconOn : iconOff
|
|
73
72
|
}), /*#__PURE__*/jsx(ErrorIcon, {
|
|
74
73
|
invalid: invalid,
|
|
75
74
|
error: error
|
|
76
75
|
}), label && /*#__PURE__*/jsx("span", {
|
|
77
|
-
className: "flex-initial leading-
|
|
76
|
+
className: "flex-initial leading-tight truncate",
|
|
78
77
|
children: label
|
|
79
78
|
})]
|
|
80
79
|
});
|
|
81
|
-
}
|
|
80
|
+
}
|
|
82
81
|
|
|
83
82
|
export { Checkbox };
|
|
@@ -2,99 +2,156 @@
|
|
|
2
2
|
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
5
|
+
import { useFloating, autoUpdate, shift, flip, offset, arrow, useClick, useDismiss, useInteractions, FloatingFocusManager, FloatingArrow } from '@floating-ui/react';
|
|
6
|
+
import { useControlledValue, Icon } from '@react-fabric/core';
|
|
7
|
+
import { mergeRefs } from '@react-fabric/utilities';
|
|
8
|
+
import { useCallback, startTransition, useRef, useState } from 'react';
|
|
9
|
+
import { InputWrapper } from '../internal/InputWrapper.js';
|
|
10
|
+
import { getWrapperProps } from '../utils/getProps.js';
|
|
10
11
|
import { ColorPicker } from './ColorPicker.js';
|
|
11
12
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
12
13
|
|
|
13
|
-
var _excluded = ["ref", "required", "disabled", "allowClear", "invalid", "error", "value", "showPicker", "defaultColor", "decorateEnd", "decorateStart", "onChange", "noOutline"];
|
|
14
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
/**
|
|
17
|
+
* Color input component that allows users to select a color
|
|
18
|
+
* and optionally use an eye dropper to pick a color from the screen.
|
|
19
|
+
* It uses the Floating UI library for positioning the color picker.
|
|
20
|
+
* It also provides a button to clear the selected color.
|
|
21
|
+
*
|
|
22
|
+
* This component is a wrapper around the `ColorPicker` component
|
|
23
|
+
* and provides additional functionality such as showing an eye dropper
|
|
24
|
+
* and handling the color selection state.
|
|
25
|
+
*/
|
|
26
|
+
function ColorInput(props) {
|
|
27
|
+
var ref = props.ref,
|
|
28
|
+
disabled = props.disabled,
|
|
29
|
+
readOnly = props.readOnly,
|
|
30
|
+
value = props.value,
|
|
31
|
+
invalid = props.invalid,
|
|
32
|
+
allowClear = props.allowClear,
|
|
33
|
+
showPicker = props.showPicker,
|
|
34
|
+
_props$defaultColor = props.defaultColor,
|
|
35
|
+
defaultColor = _props$defaultColor === void 0 ? "" : _props$defaultColor,
|
|
36
|
+
onBlur = props.onBlur,
|
|
37
|
+
onFocus = props.onFocus,
|
|
38
|
+
onChange = props.onChange;
|
|
39
|
+
var _useControlledValue = useControlledValue(value, defaultColor),
|
|
40
|
+
currentValue = _useControlledValue.currentValue,
|
|
41
|
+
updateValue = _useControlledValue.updateValue;
|
|
40
42
|
var handleChange = useCallback(function (e) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
var value = e !== null && e !== void 0 ? e : defaultColor;
|
|
44
|
+
updateValue(value);
|
|
45
|
+
if (onChange) startTransition(function () {
|
|
46
|
+
return onChange(value !== null && value !== void 0 ? value : null);
|
|
44
47
|
});
|
|
45
|
-
}, [onChange]);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
48
|
+
}, [defaultColor, updateValue, onChange]);
|
|
49
|
+
var arrowRef = useRef(null);
|
|
50
|
+
var _useState = useState(false),
|
|
51
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
52
|
+
isOpen = _useState2[0],
|
|
53
|
+
setIsOpen = _useState2[1];
|
|
54
|
+
var _useFloating = useFloating({
|
|
55
|
+
open: isOpen,
|
|
56
|
+
onOpenChange: function onOpenChange(open, _, reason) {
|
|
57
|
+
if (reason === "reference-press") return;
|
|
58
|
+
setIsOpen(open);
|
|
59
|
+
},
|
|
60
|
+
strategy: "fixed",
|
|
61
|
+
placement: "bottom",
|
|
62
|
+
whileElementsMounted: autoUpdate,
|
|
63
|
+
middleware: [shift({
|
|
64
|
+
padding: 8
|
|
65
|
+
}), flip(), offset(9), arrow({
|
|
66
|
+
element: arrowRef
|
|
67
|
+
})]
|
|
68
|
+
}),
|
|
69
|
+
refs = _useFloating.refs,
|
|
70
|
+
floatingStyles = _useFloating.floatingStyles,
|
|
71
|
+
context = _useFloating.context;
|
|
72
|
+
var click = useClick(context, {
|
|
73
|
+
enabled: !disabled && !readOnly
|
|
74
|
+
});
|
|
75
|
+
var dismiss = useDismiss(context, {
|
|
76
|
+
referencePress: true
|
|
77
|
+
});
|
|
78
|
+
var _useInteractions = useInteractions([dismiss, click]),
|
|
79
|
+
getReferenceProps = _useInteractions.getReferenceProps,
|
|
80
|
+
getFloatingProps = _useInteractions.getFloatingProps;
|
|
81
|
+
return /*#__PURE__*/jsxs(InputWrapper, _objectSpread(_objectSpread({
|
|
82
|
+
showClear: allowClear && currentValue !== defaultColor && !disabled && !readOnly,
|
|
83
|
+
onClear: handleChange
|
|
84
|
+
}, getWrapperProps(props)), {}, {
|
|
85
|
+
children: [/*#__PURE__*/jsx("button", _objectSpread(_objectSpread({
|
|
86
|
+
"data-ref": "button",
|
|
87
|
+
type: "button",
|
|
88
|
+
className: "flex-1 flex items-center",
|
|
89
|
+
ref: mergeRefs(ref, function (el) {
|
|
90
|
+
return refs.setReference(el);
|
|
91
|
+
})
|
|
92
|
+
}, getReferenceProps({
|
|
93
|
+
onBlur: onBlur,
|
|
94
|
+
onFocus: onFocus
|
|
95
|
+
})), {}, {
|
|
96
|
+
"data-inner-clickable": "true",
|
|
97
|
+
"data-dropdown-open": isOpen ? true : undefined,
|
|
98
|
+
children: /*#__PURE__*/jsx("div", {
|
|
99
|
+
className: "h-[1.5em] min-w-[1.5em] flex-1 flex items-center justify-center self-stretch cursor-pointer m-[0.25em] rounded outline outline-tint-100",
|
|
100
|
+
"aria-invalid": invalid,
|
|
101
|
+
style: {
|
|
102
|
+
backgroundColor: currentValue !== null && currentValue !== void 0 ? currentValue : "",
|
|
103
|
+
opacity: disabled ? 0.65 : 1,
|
|
104
|
+
pointerEvents: disabled ? "none" : undefined
|
|
105
|
+
},
|
|
106
|
+
children: !currentValue && /*#__PURE__*/jsx(Icon, {
|
|
107
|
+
size: "md",
|
|
108
|
+
className: "text-muted",
|
|
109
|
+
icon: "icon-[mdi--palette]"
|
|
74
110
|
})
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
111
|
+
})
|
|
112
|
+
})), isOpen && /*#__PURE__*/jsx(FloatingFocusManager, {
|
|
113
|
+
context: context,
|
|
114
|
+
closeOnFocusOut: true,
|
|
115
|
+
children: /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
116
|
+
ref: function ref(el) {
|
|
117
|
+
return refs.setFloating(el);
|
|
118
|
+
},
|
|
119
|
+
style: _objectSpread({
|
|
120
|
+
zIndex: "var(--z-popover)"
|
|
121
|
+
}, floatingStyles),
|
|
122
|
+
"data-ref": "dropdownBody"
|
|
123
|
+
}, getFloatingProps()), {}, {
|
|
124
|
+
children: [/*#__PURE__*/jsx(ColorPicker, _objectSpread(_objectSpread({}, props), {}, {
|
|
125
|
+
onChange: handleChange,
|
|
126
|
+
defaultColor: defaultColor,
|
|
127
|
+
value: currentValue
|
|
128
|
+
})), /*#__PURE__*/jsx(FloatingArrow, {
|
|
129
|
+
ref: arrowRef,
|
|
130
|
+
context: context,
|
|
131
|
+
strokeWidth: 0.5,
|
|
132
|
+
className: "stroke-muted",
|
|
133
|
+
style: {
|
|
134
|
+
fill: currentValue || "var(--bg-color-default)"
|
|
135
|
+
}
|
|
136
|
+
})]
|
|
137
|
+
}))
|
|
138
|
+
}), !disabled && showPicker && /*#__PURE__*/jsx("button", {
|
|
139
|
+
type: "button",
|
|
140
|
+
className: "size-fit leading-0 cursor-pointer",
|
|
92
141
|
onClick: function onClick() {
|
|
93
|
-
|
|
142
|
+
var ED = window.EyeDropper;
|
|
143
|
+
if (ED) {
|
|
144
|
+
void new ED().open().then(function (resp) {
|
|
145
|
+
return handleChange(resp.sRGBHex);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
94
148
|
},
|
|
95
|
-
|
|
149
|
+
children: /*#__PURE__*/jsx(Icon, {
|
|
150
|
+
className: "flex-content p-1",
|
|
151
|
+
icon: "icon-[mdi--eyedropper]"
|
|
152
|
+
})
|
|
96
153
|
})]
|
|
97
|
-
});
|
|
98
|
-
}
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
99
156
|
|
|
100
157
|
export { ColorInput };
|