@react-fabric/form 1.0.0-beta.5 → 1.0.0-beta.51
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} +64 -29
- package/{src/input/File.module.css → css/_file.css} +21 -6
- package/css/styles.css +27 -0
- package/dist/cjs/builder/FileField.js +37 -25
- package/dist/cjs/builder/FormField.js +50 -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 +414 -0
- package/dist/cjs/form/Controller.js +1 -1
- package/dist/cjs/form/Form.js +11 -6
- package/dist/cjs/hooks/useFormBuilder.js +27 -15
- package/dist/cjs/index.js +11 -2
- package/dist/cjs/input/ArrayInput.js +61 -33
- package/dist/cjs/input/AvatarInput.js +9 -8
- package/dist/cjs/input/Checkbox.js +6 -5
- package/dist/cjs/input/ColorInput.js +95 -56
- package/dist/cjs/input/ColorPicker.js +1 -35
- package/dist/cjs/input/DateInput.js +186 -0
- package/dist/cjs/input/Field.js +5 -4
- package/dist/cjs/input/File.js +4 -7
- package/dist/cjs/input/Hidden.js +3 -1
- package/dist/cjs/input/Input.js +11 -7
- package/dist/cjs/input/Number.js +9 -7
- package/dist/cjs/input/Password.js +10 -8
- package/dist/cjs/input/Radio.js +2 -2
- package/dist/cjs/input/RadioGroup.js +6 -3
- package/dist/cjs/input/{Range.js → RangeSlider.js} +5 -5
- package/dist/cjs/input/Search.js +16 -16
- package/dist/cjs/input/Slider.js +3 -3
- package/dist/cjs/input/Switch.js +30 -7
- package/dist/cjs/input/Textarea.js +13 -4
- package/dist/cjs/internal/ErrorIcon.js +1 -1
- package/dist/cjs/internal/FieldWrapper.js +11 -4
- package/dist/cjs/internal/InputWrapper.js +19 -16
- package/dist/cjs/select/AutoComplete.js +12 -8
- package/dist/cjs/select/DualList.js +4 -1
- package/dist/cjs/select/List.js +45 -20
- package/dist/cjs/select/Options.js +2 -2
- package/dist/cjs/select/Select.js +14 -4
- package/dist/cjs/select/useSelect.js +10 -6
- package/dist/cjs/types/schema.js +43 -0
- package/dist/cjs/utils/eventHandlers.js +11 -5
- package/dist/cjs/utils/getColor.js +6 -0
- package/dist/esm/builder/FileField.js +39 -27
- package/dist/esm/builder/FormField.js +50 -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 +414 -0
- package/dist/esm/form/Controller.js +1 -1
- package/dist/esm/form/Form.js +11 -6
- package/dist/esm/hooks/useFormBuilder.js +25 -13
- package/dist/esm/index.js +5 -1
- package/dist/esm/input/ArrayInput.js +61 -33
- package/dist/esm/input/AvatarInput.js +9 -8
- package/dist/esm/input/Checkbox.js +6 -5
- package/dist/esm/input/ColorInput.js +97 -58
- package/dist/esm/input/ColorPicker.js +1 -35
- package/dist/esm/input/DateInput.js +186 -0
- package/dist/esm/input/Field.js +6 -5
- package/dist/esm/input/File.js +6 -9
- package/dist/esm/input/Hidden.js +3 -1
- package/dist/esm/input/Input.js +13 -9
- package/dist/esm/input/Number.js +11 -9
- package/dist/esm/input/Password.js +12 -10
- package/dist/esm/input/Radio.js +2 -2
- package/dist/esm/input/RadioGroup.js +7 -4
- package/dist/esm/input/{Range.js → RangeSlider.js} +5 -5
- package/dist/esm/input/Search.js +18 -18
- package/dist/esm/input/Slider.js +3 -3
- package/dist/esm/input/Switch.js +32 -9
- package/dist/esm/input/Textarea.js +14 -5
- package/dist/esm/internal/ErrorIcon.js +1 -1
- package/dist/esm/internal/FieldWrapper.js +11 -4
- package/dist/esm/internal/InputWrapper.js +19 -16
- package/dist/esm/select/AutoComplete.js +12 -8
- package/dist/esm/select/DualList.js +4 -1
- package/dist/esm/select/List.js +46 -21
- package/dist/esm/select/Options.js +2 -2
- package/dist/esm/select/Select.js +14 -4
- package/dist/esm/select/useSelect.js +11 -7
- package/{src/input/ColorPicker.module.css → dist/esm/types/schema.js} +18 -27
- package/dist/esm/utils/eventHandlers.js +11 -5
- 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 +2 -2
- package/dist/types/form/Form.d.ts +5 -1
- package/dist/types/hooks/useFormBuilder.d.ts +3 -1
- package/dist/types/index.d.ts +5 -2
- package/dist/types/input/ArrayInput.d.ts +39 -6
- package/dist/types/input/AvatarInput.d.ts +6 -3
- package/dist/types/input/Checkbox.d.ts +4 -4
- package/dist/types/input/ColorInput.d.ts +2 -2
- package/dist/types/input/ColorPicker.d.ts +1 -1
- package/dist/types/input/DateInput.d.ts +19 -0
- package/dist/types/input/Field.d.ts +0 -1
- package/dist/types/input/Input.d.ts +1 -1
- package/dist/types/input/Number.d.ts +1 -1
- package/dist/types/input/Password.d.ts +1 -1
- package/dist/types/input/Radio.d.ts +0 -1
- package/dist/types/input/RadioGroup.d.ts +18 -3
- package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +1 -1
- package/dist/types/input/Search.d.ts +5 -1
- package/dist/types/input/Switch.d.ts +7 -4
- package/dist/types/input/Textarea.d.ts +5 -1
- package/dist/types/internal/FieldWrapper.d.ts +1 -1
- package/dist/types/internal/InputWrapper.d.ts +1 -1
- package/dist/types/ranger/index.d.ts +2 -2
- package/dist/types/select/AutoComplete.d.ts +1 -1
- package/dist/types/select/DualList.d.ts +6 -2
- package/dist/types/select/List.d.ts +1 -1
- package/dist/types/select/Select.d.ts +1 -1
- package/dist/types/select/useSelect.d.ts +7 -15
- package/dist/types/types/index.d.ts +28 -7
- package/dist/types/types/schema.d.ts +78 -33
- package/dist/types/utils/eventHandlers.d.ts +1 -1
- package/package.json +15 -12
- package/src/builder/FileField.tsx +53 -27
- package/src/builder/FormField.tsx +52 -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 +436 -0
- package/src/form/Controller.tsx +3 -3
- package/src/form/Form.tsx +14 -5
- package/src/hooks/useFormBuilder.tsx +29 -15
- package/src/index.ts +11 -2
- package/src/input/ArrayInput.tsx +130 -54
- package/src/input/AvatarInput.tsx +12 -8
- package/src/input/Checkbox.tsx +6 -5
- package/src/input/ColorInput.tsx +113 -69
- package/src/input/ColorPicker.tsx +2 -36
- package/src/input/DateInput.tsx +250 -0
- package/src/input/Field.tsx +10 -11
- package/src/input/File.tsx +7 -14
- package/src/input/Hidden.tsx +4 -1
- package/src/input/Input.tsx +15 -10
- package/src/input/Number.tsx +10 -10
- package/src/input/Password.tsx +13 -12
- package/src/input/Radio.tsx +2 -2
- package/src/input/RadioGroup.tsx +27 -4
- package/src/input/{Range.tsx → RangeSlider.tsx} +4 -4
- package/src/input/Search.tsx +20 -19
- package/src/input/Slider.tsx +3 -3
- package/src/input/Switch.tsx +43 -7
- package/src/input/Textarea.tsx +19 -5
- package/src/internal/ErrorIcon.tsx +1 -1
- package/src/internal/FieldWrapper.tsx +8 -4
- package/src/internal/InputWrapper.tsx +36 -20
- package/src/select/AutoComplete.tsx +5 -1
- package/src/select/DualList.tsx +8 -0
- package/src/select/List.tsx +41 -8
- package/src/select/Options.tsx +1 -1
- package/src/select/Select.tsx +13 -3
- package/src/select/useSelect.tsx +13 -5
- package/src/types/index.ts +34 -8
- package/src/types/schema.ts +96 -41
- package/src/utils/eventHandlers.ts +9 -3
- 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/dist/esm/select/List.js
CHANGED
|
@@ -6,33 +6,35 @@ import { useFloating, autoUpdate, useListNavigation, useTypeahead, useInteractio
|
|
|
6
6
|
import { Chip } from '@react-fabric/core';
|
|
7
7
|
import { isArray, isEmpty } from '@react-fabric/utilities';
|
|
8
8
|
import classNames from 'classnames';
|
|
9
|
-
import { useMemo, Fragment, useId, useCallback } from 'react';
|
|
9
|
+
import { useMemo, Fragment, useId, useCallback, useLayoutEffect } from 'react';
|
|
10
10
|
import { FieldWrapper } from '../internal/FieldWrapper.js';
|
|
11
11
|
import { InputWrapper } from '../internal/InputWrapper.js';
|
|
12
12
|
import { Options } from './Options.js';
|
|
13
13
|
import { useSelect } from './useSelect.js';
|
|
14
14
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
15
15
|
|
|
16
|
-
var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "multiple", "allowCreate", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
|
|
16
|
+
var _excluded = ["ref", "name", "value", "readOnly", "disabled", "required", "placeholder", "autoFocus", "options", "height", "groupProperty", "labelProperty", "valueProperty", "sortProperty", "multiple", "allowCreate", "searchable", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "emptyDisplay", "invalid", "error", "allowClear", "decorateStart", "decorateEnd", "data-inner", "data-hide-selected"];
|
|
17
17
|
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; }
|
|
18
18
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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; }
|
|
19
19
|
var List = function List(_ref) {
|
|
20
20
|
var _state$query;
|
|
21
|
-
_ref.ref
|
|
22
|
-
|
|
21
|
+
var ref = _ref.ref,
|
|
22
|
+
name = _ref.name,
|
|
23
23
|
value = _ref.value,
|
|
24
24
|
readOnly = _ref.readOnly,
|
|
25
25
|
disabled = _ref.disabled,
|
|
26
26
|
required = _ref.required,
|
|
27
|
-
placeholder = _ref.placeholder
|
|
28
|
-
_ref.autoFocus
|
|
29
|
-
|
|
27
|
+
placeholder = _ref.placeholder,
|
|
28
|
+
autoFocus = _ref.autoFocus,
|
|
29
|
+
options = _ref.options,
|
|
30
30
|
height = _ref.height,
|
|
31
31
|
groupProperty = _ref.groupProperty,
|
|
32
32
|
labelProperty = _ref.labelProperty,
|
|
33
33
|
valueProperty = _ref.valueProperty,
|
|
34
|
+
sortProperty = _ref.sortProperty,
|
|
34
35
|
multiple = _ref.multiple,
|
|
35
36
|
allowCreate = _ref.allowCreate,
|
|
37
|
+
searchable = _ref.searchable,
|
|
36
38
|
createOption = _ref.createOption,
|
|
37
39
|
matcher = _ref.matcher,
|
|
38
40
|
renderer = _ref.renderer,
|
|
@@ -40,6 +42,7 @@ var List = function List(_ref) {
|
|
|
40
42
|
onChange = _ref.onChange,
|
|
41
43
|
onSelect = _ref.onSelect,
|
|
42
44
|
onEnterPressed = _ref.onEnterPressed,
|
|
45
|
+
emptyDisplay = _ref.emptyDisplay,
|
|
43
46
|
invalid = _ref.invalid,
|
|
44
47
|
error = _ref.error;
|
|
45
48
|
_ref.allowClear;
|
|
@@ -61,6 +64,7 @@ var List = function List(_ref) {
|
|
|
61
64
|
groupProperty: groupProperty,
|
|
62
65
|
labelProperty: labelProperty,
|
|
63
66
|
valueProperty: valueProperty,
|
|
67
|
+
sortProperty: sortProperty,
|
|
64
68
|
allowCreate: allowCreate,
|
|
65
69
|
createOption: createOption,
|
|
66
70
|
matcher: matcher,
|
|
@@ -138,9 +142,10 @@ var List = function List(_ref) {
|
|
|
138
142
|
}
|
|
139
143
|
} else if (evt.key === "Backspace") {
|
|
140
144
|
!state.query && handleRemove();
|
|
141
|
-
} else if (["ArrowUp", "ArrowDown"].includes(evt.key)) {
|
|
142
|
-
if (state.activeIndex === null) {
|
|
143
|
-
|
|
145
|
+
} else if (!searchable || ["ArrowUp", "ArrowDown"].includes(evt.key)) {
|
|
146
|
+
if (["ArrowUp", "ArrowDown"].includes(evt.key) && state.activeIndex === null) {
|
|
147
|
+
var _state$selectedIndex;
|
|
148
|
+
setActiveIndex((_state$selectedIndex = state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0);
|
|
144
149
|
}
|
|
145
150
|
setTimeout(function () {
|
|
146
151
|
var _props$onKeyDown;
|
|
@@ -185,6 +190,14 @@ var List = function List(_ref) {
|
|
|
185
190
|
});
|
|
186
191
|
}
|
|
187
192
|
}, [state.value, state.query, placeholder, renderer]);
|
|
193
|
+
useLayoutEffect(function () {
|
|
194
|
+
setTimeout(function () {
|
|
195
|
+
var _listRef$current$stat;
|
|
196
|
+
state.selectedIndex && ((_listRef$current$stat = listRef.current[state.selectedIndex]) === null || _listRef$current$stat === void 0 ? void 0 : _listRef$current$stat.scrollIntoView({
|
|
197
|
+
block: "center"
|
|
198
|
+
}));
|
|
199
|
+
}, 100);
|
|
200
|
+
}, [state.selectedIndex]);
|
|
188
201
|
return /*#__PURE__*/jsxs(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
|
|
189
202
|
children: [/*#__PURE__*/jsx(InputWrapper, {
|
|
190
203
|
showClear: !isEmpty(state.value),
|
|
@@ -197,23 +210,32 @@ var List = function List(_ref) {
|
|
|
197
210
|
className: "z-1 rounded-b-none",
|
|
198
211
|
"data-inner": true,
|
|
199
212
|
wrapperRef: refs.setReference,
|
|
200
|
-
children: /*#__PURE__*/jsxs("div", {
|
|
213
|
+
children: /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
214
|
+
role: "none",
|
|
201
215
|
"data-select-display": "true",
|
|
202
|
-
className: "group flex-1 py-1 px-2 truncate text-start flex gap-1 flex-wrap"
|
|
203
|
-
|
|
216
|
+
className: classNames("group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start", multiple ? "flex-wrap" : "flex-nowrap overflow-hidden")
|
|
217
|
+
}, referenceProps), {}, {
|
|
218
|
+
onMouseUp: function onMouseUp(e) {
|
|
219
|
+
var _e$currentTarget$quer;
|
|
220
|
+
return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
|
|
221
|
+
},
|
|
222
|
+
children: [!hideSelected && displayValue, /*#__PURE__*/jsx("input", {
|
|
223
|
+
readOnly: !searchable || readOnly,
|
|
204
224
|
disabled: disabled,
|
|
205
225
|
value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
|
|
206
226
|
"aria-invalid": invalid,
|
|
207
227
|
"data-testid": name,
|
|
208
228
|
name: name,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
229
|
+
size: 1,
|
|
230
|
+
ref: ref,
|
|
231
|
+
autoFocus: autoFocus,
|
|
232
|
+
className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
|
|
233
|
+
placeholder: isEmpty(state.value) ? placeholder : "",
|
|
212
234
|
onChange: function onChange(evt) {
|
|
213
235
|
return handleQuery(evt.target.value);
|
|
214
236
|
}
|
|
215
|
-
})
|
|
216
|
-
})
|
|
237
|
+
})]
|
|
238
|
+
}))
|
|
217
239
|
}), /*#__PURE__*/jsx(FloatingFocusManager, {
|
|
218
240
|
context: context,
|
|
219
241
|
initialFocus: -1,
|
|
@@ -227,11 +249,14 @@ var List = function List(_ref) {
|
|
|
227
249
|
}, floatingProps), {}, {
|
|
228
250
|
items: state.items,
|
|
229
251
|
active: state.activeIndex,
|
|
252
|
+
valueProperty: valueProperty,
|
|
253
|
+
labelProperty: labelProperty,
|
|
230
254
|
itemRef: setItemRef,
|
|
231
255
|
itemProps: makeItemProps,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
256
|
+
empty: emptyDisplay,
|
|
257
|
+
children: function children(item, label) {
|
|
258
|
+
var _renderer3;
|
|
259
|
+
return (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : label;
|
|
235
260
|
}
|
|
236
261
|
}))
|
|
237
262
|
})]
|
|
@@ -34,7 +34,7 @@ var Options = function Options(_ref) {
|
|
|
34
34
|
i18nKey: "form:select.emptyList"
|
|
35
35
|
})
|
|
36
36
|
})), items.map(function (item, index) {
|
|
37
|
-
var _item$labelProperty;
|
|
37
|
+
var _item$value, _item$labelProperty;
|
|
38
38
|
if (item.___group___) return /*#__PURE__*/jsx("p", {
|
|
39
39
|
className: "px-2 py-1 text-muted text-xs sticky -top-px z-2 bg-base border-t",
|
|
40
40
|
children: item.label
|
|
@@ -51,7 +51,7 @@ var Options = function Options(_ref) {
|
|
|
51
51
|
children: /*#__PURE__*/jsx(Trans, {
|
|
52
52
|
i18nKey: "form:select.createOption",
|
|
53
53
|
values: {
|
|
54
|
-
query: item.value
|
|
54
|
+
query: (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : item
|
|
55
55
|
},
|
|
56
56
|
components: [/*#__PURE__*/jsx("strong", {
|
|
57
57
|
children: "query"
|
|
@@ -12,7 +12,7 @@ import { Options } from './Options.js';
|
|
|
12
12
|
import { useSelect } from './useSelect.js';
|
|
13
13
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
14
|
|
|
15
|
-
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "options", "groupProperty", "labelProperty", "valueProperty", "multiple", "searchable", "allowCreate", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed"];
|
|
15
|
+
var _excluded = ["ref", "name", "value", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "error", "options", "defaultOpen", "hideHandle", "groupProperty", "labelProperty", "valueProperty", "sortProperty", "multiple", "searchable", "allowCreate", "emptyDisplay", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed"];
|
|
16
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; }
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).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
18
|
var Select = function Select(_ref) {
|
|
@@ -28,14 +28,18 @@ var Select = function Select(_ref) {
|
|
|
28
28
|
autoFocus = _ref.autoFocus,
|
|
29
29
|
error = _ref.error,
|
|
30
30
|
options = _ref.options,
|
|
31
|
+
defaultOpen = _ref.defaultOpen,
|
|
32
|
+
hideHandle = _ref.hideHandle,
|
|
31
33
|
groupProperty = _ref.groupProperty,
|
|
32
34
|
_ref$labelProperty = _ref.labelProperty,
|
|
33
35
|
labelProperty = _ref$labelProperty === void 0 ? "label" : _ref$labelProperty,
|
|
34
36
|
_ref$valueProperty = _ref.valueProperty,
|
|
35
37
|
valueProperty = _ref$valueProperty === void 0 ? "id" : _ref$valueProperty,
|
|
38
|
+
sortProperty = _ref.sortProperty,
|
|
36
39
|
multiple = _ref.multiple,
|
|
37
40
|
searchable = _ref.searchable,
|
|
38
41
|
allowCreate = _ref.allowCreate,
|
|
42
|
+
emptyDisplay = _ref.emptyDisplay,
|
|
39
43
|
createOption = _ref.createOption,
|
|
40
44
|
matcher = _ref.matcher,
|
|
41
45
|
renderer = _ref.renderer,
|
|
@@ -48,9 +52,11 @@ var Select = function Select(_ref) {
|
|
|
48
52
|
value: value,
|
|
49
53
|
options: options,
|
|
50
54
|
multiple: multiple,
|
|
55
|
+
defaultOpen: defaultOpen,
|
|
51
56
|
groupProperty: groupProperty,
|
|
52
57
|
labelProperty: labelProperty,
|
|
53
58
|
valueProperty: valueProperty,
|
|
59
|
+
sortProperty: sortProperty,
|
|
54
60
|
allowCreate: allowCreate,
|
|
55
61
|
createOption: createOption,
|
|
56
62
|
matcher: matcher,
|
|
@@ -140,6 +146,9 @@ var Select = function Select(_ref) {
|
|
|
140
146
|
return false;
|
|
141
147
|
} else if (state.query) {
|
|
142
148
|
handleQuery("");
|
|
149
|
+
evt.preventDefault();
|
|
150
|
+
evt.stopPropagation();
|
|
151
|
+
return false;
|
|
143
152
|
} else {
|
|
144
153
|
onEnterPressed === null || onEnterPressed === void 0 || onEnterPressed(evt);
|
|
145
154
|
}
|
|
@@ -236,13 +245,13 @@ var Select = function Select(_ref) {
|
|
|
236
245
|
size: 1,
|
|
237
246
|
ref: ref,
|
|
238
247
|
autoFocus: autoFocus,
|
|
239
|
-
className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
|
|
248
|
+
className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 peer", disabled && "cursor-not-allowed pointer-events-none", multiple && "min-w-24"),
|
|
240
249
|
placeholder: isEmpty(state.value) ? placeholder : "",
|
|
241
250
|
onChange: function onChange(evt) {
|
|
242
251
|
return handleQuery(evt.target.value);
|
|
243
252
|
}
|
|
244
253
|
})]
|
|
245
|
-
})), !state.loading && /*#__PURE__*/jsx(Icon, {
|
|
254
|
+
})), !state.loading && !hideHandle && /*#__PURE__*/jsx(Icon, {
|
|
246
255
|
className: classNames("flex-content p-2 z-0 order-9 text-muted cursor-pointer self-stretch flex items-center h-auto", state.open && "-scale-y-100 pointer-events-none", disabled && "pointer-events-none"),
|
|
247
256
|
onClick: function onClick() {
|
|
248
257
|
return !disabled && openDropdown();
|
|
@@ -259,7 +268,7 @@ var Select = function Select(_ref) {
|
|
|
259
268
|
visuallyHiddenDismiss: true,
|
|
260
269
|
children: /*#__PURE__*/jsx(Options, _objectSpread(_objectSpread({
|
|
261
270
|
ref: refs.setFloating,
|
|
262
|
-
className: "outline shadow-lg max-h-[40vh] z-
|
|
271
|
+
className: "outline shadow-lg max-h-[40vh] z-(--z-popover)",
|
|
263
272
|
style: _objectSpread({
|
|
264
273
|
width: (_refs$reference$curre = refs.reference.current) === null || _refs$reference$curre === void 0 ? void 0 : _refs$reference$curre.getBoundingClientRect().width
|
|
265
274
|
}, floatingStyles)
|
|
@@ -270,6 +279,7 @@ var Select = function Select(_ref) {
|
|
|
270
279
|
labelProperty: labelProperty,
|
|
271
280
|
itemRef: setItemRef,
|
|
272
281
|
itemProps: makeItemProps,
|
|
282
|
+
empty: emptyDisplay,
|
|
273
283
|
children: function children(item, label) {
|
|
274
284
|
var _renderer3;
|
|
275
285
|
return (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : label;
|
|
@@ -4,7 +4,7 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
|
4
4
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
5
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
6
|
import { useDebounce } from '@react-fabric/core';
|
|
7
|
-
import { matchString, isString, dedupe, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
7
|
+
import { matchString, isString, dedupe, compareValues, groupBy, isArray, EMPTY_ARRAY } from '@react-fabric/utilities';
|
|
8
8
|
import { useMemo, useDeferredValue, useRef, useCallback, useReducer, useEffect } from 'react';
|
|
9
9
|
import { getSelectedValue, makeOption } from './helpers.js';
|
|
10
10
|
|
|
@@ -14,6 +14,8 @@ var useSelect = function useSelect(_ref) {
|
|
|
14
14
|
var _ref$options = _ref.options,
|
|
15
15
|
options = _ref$options === void 0 ? EMPTY_ARRAY : _ref$options,
|
|
16
16
|
value = _ref.value,
|
|
17
|
+
_ref$defaultOpen = _ref.defaultOpen,
|
|
18
|
+
defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
|
|
17
19
|
autoComplete = _ref.autoComplete,
|
|
18
20
|
_ref$multiple = _ref.multiple,
|
|
19
21
|
multiple = _ref$multiple === void 0 ? false : _ref$multiple,
|
|
@@ -25,6 +27,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
25
27
|
valueProperty = _ref$valueProperty === void 0 ? "id" : _ref$valueProperty,
|
|
26
28
|
_ref$labelProperty = _ref.labelProperty,
|
|
27
29
|
labelProperty = _ref$labelProperty === void 0 ? "label" : _ref$labelProperty,
|
|
30
|
+
sortProperty = _ref.sortProperty,
|
|
28
31
|
_ref$createOption = _ref.createOption,
|
|
29
32
|
createOption = _ref$createOption === void 0 ? makeOption : _ref$createOption,
|
|
30
33
|
matcher = _ref.matcher,
|
|
@@ -133,13 +136,14 @@ var useSelect = function useSelect(_ref) {
|
|
|
133
136
|
if (autoComplete && action.query !== undefined) {
|
|
134
137
|
optionList = dedupe([action.query].concat(_toConsumableArray(optionList)));
|
|
135
138
|
}
|
|
139
|
+
if (sortProperty) optionList = optionList.sort(compareValues("asc", sortProperty));
|
|
136
140
|
var grouped = groupBy(optionList, groupProperty, "");
|
|
137
141
|
if (action.open) _newState.open = true;
|
|
138
142
|
_newState.items = [];
|
|
139
143
|
// add new item if allowCreate
|
|
140
144
|
if (allowCreate && action.query) _newState.items.push({
|
|
141
145
|
___create___: true,
|
|
142
|
-
value:
|
|
146
|
+
value: action.query
|
|
143
147
|
});
|
|
144
148
|
Object.entries(grouped).forEach(function (_ref2) {
|
|
145
149
|
var _newState$items;
|
|
@@ -169,7 +173,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
169
173
|
}, {
|
|
170
174
|
multiple: multiple,
|
|
171
175
|
emptyValue: emptyValue,
|
|
172
|
-
open:
|
|
176
|
+
open: defaultOpen,
|
|
173
177
|
loading: false,
|
|
174
178
|
activeIndex: null,
|
|
175
179
|
selectedIndex: null,
|
|
@@ -201,7 +205,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
201
205
|
});
|
|
202
206
|
dispatch({
|
|
203
207
|
type: "setValue",
|
|
204
|
-
value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 :
|
|
208
|
+
value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : deferred
|
|
205
209
|
});
|
|
206
210
|
}
|
|
207
211
|
if (multiple) {
|
|
@@ -211,12 +215,12 @@ var useSelect = function useSelect(_ref) {
|
|
|
211
215
|
var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
|
|
212
216
|
var hasValue = options.find(function (opt) {
|
|
213
217
|
var _opt$valueProperty2;
|
|
214
|
-
return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) ===
|
|
218
|
+
return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === item;
|
|
215
219
|
});
|
|
216
220
|
if (!hasValue && newOption) {
|
|
217
221
|
optionsRef.current.push(newOption);
|
|
218
222
|
}
|
|
219
|
-
return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 :
|
|
223
|
+
return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : item;
|
|
220
224
|
});
|
|
221
225
|
optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(options !== null && options !== void 0 ? options : []));
|
|
222
226
|
dispatch({
|
|
@@ -246,7 +250,7 @@ var useSelect = function useSelect(_ref) {
|
|
|
246
250
|
setActive: true
|
|
247
251
|
});
|
|
248
252
|
});
|
|
249
|
-
}, [onQuery]);
|
|
253
|
+
}, [onQuery], 300);
|
|
250
254
|
|
|
251
255
|
// handlers
|
|
252
256
|
var handleQuery = useCallback(function (query) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
* React Fabric
|
|
3
5
|
* @version: 1.0.0
|
|
@@ -21,31 +23,20 @@
|
|
|
21
23
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
& :global(.flexbox-fix) {
|
|
40
|
-
@apply !border-t-muted justify-center;
|
|
41
|
-
|
|
42
|
-
& > div > div {
|
|
43
|
-
@apply text-center;
|
|
44
|
-
}
|
|
26
|
+
var DATA_TYPES = /*#__PURE__*/function (DATA_TYPES) {
|
|
27
|
+
DATA_TYPES["TEXT"] = "text";
|
|
28
|
+
DATA_TYPES["COLOR"] = "color";
|
|
29
|
+
DATA_TYPES["BOOL"] = "bool";
|
|
30
|
+
DATA_TYPES["DATE"] = "date";
|
|
31
|
+
DATA_TYPES["DATETIME"] = "datetime";
|
|
32
|
+
DATA_TYPES["STRING"] = "string";
|
|
33
|
+
DATA_TYPES["NUMBER"] = "number";
|
|
34
|
+
DATA_TYPES["RANGE"] = "range";
|
|
35
|
+
DATA_TYPES["FILE"] = "file";
|
|
36
|
+
DATA_TYPES["AVATAR"] = "avatar";
|
|
37
|
+
DATA_TYPES["SCHEMA"] = "schema";
|
|
38
|
+
return DATA_TYPES;
|
|
39
|
+
}({});
|
|
40
|
+
var SCHEMA_CUSTOM_LIST = "--CUSTOM--";
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
box-shadow: 0 0 1px 1px theme(borderColor.base) inset !important;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
42
|
+
export { DATA_TYPES, SCHEMA_CUSTOM_LIST };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useFloatingTree } from '@floating-ui/react';
|
|
4
|
+
import { useDebounce } from '@react-fabric/core';
|
|
4
5
|
|
|
5
6
|
/*
|
|
6
7
|
* React Fabric
|
|
@@ -26,16 +27,21 @@ import { debounce } from '@react-fabric/utilities';
|
|
|
26
27
|
*/
|
|
27
28
|
|
|
28
29
|
/** ***************** common handler for enter press *******************/
|
|
29
|
-
var
|
|
30
|
+
var useHandleEnter = function useHandleEnter(callback) {
|
|
30
31
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
31
32
|
_ref$stopPropagation = _ref.stopPropagation,
|
|
32
33
|
stopPropagation = _ref$stopPropagation === void 0 ? false : _ref$stopPropagation,
|
|
33
34
|
_ref$preventDefault = _ref.preventDefault,
|
|
34
35
|
preventDefault = _ref$preventDefault === void 0 ? false : _ref$preventDefault;
|
|
35
|
-
var cbHandle =
|
|
36
|
+
var cbHandle = useDebounce(callback !== null && callback !== void 0 ? callback : function () {
|
|
36
37
|
return undefined;
|
|
37
|
-
}, 100);
|
|
38
|
+
}, [callback], 100);
|
|
39
|
+
var tree = useFloatingTree();
|
|
38
40
|
return function (e) {
|
|
41
|
+
// prevent propagation of event if input within dropdown (work around for floating-ui typeahead)
|
|
42
|
+
if (tree && e.key !== "Escape") {
|
|
43
|
+
e === null || e === void 0 || e.stopPropagation();
|
|
44
|
+
}
|
|
39
45
|
if (!e.shiftKey && !e.altKey && !e.metaKey && e.key === "Enter" && callback) {
|
|
40
46
|
if (stopPropagation) e === null || e === void 0 || e.stopPropagation();
|
|
41
47
|
cbHandle(e);
|
|
@@ -47,4 +53,4 @@ var handleEnter = function handleEnter(callback) {
|
|
|
47
53
|
};
|
|
48
54
|
};
|
|
49
55
|
|
|
50
|
-
export {
|
|
56
|
+
export { useHandleEnter };
|
|
@@ -35,5 +35,10 @@ var getBgClass = function getBgClass(bg) {
|
|
|
35
35
|
return "bg-".concat(bg);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var getColorClass = function getColorClass(color) {
|
|
39
|
+
if (color && !isColor(color)) {
|
|
40
|
+
return "text-".concat(color);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
38
43
|
|
|
39
|
-
export { getBgClass, getColor };
|
|
44
|
+
export { getBgClass, getColor, getColorClass };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type UploadHandler } from "../hooks/useFileUploader";
|
|
2
|
-
import { type FileSchema } from "../types/schema";
|
|
3
|
-
export declare const FileField: ({ uploadHandler, inline, label, accept, multiple,
|
|
2
|
+
import { type FileSchema, type ValueType } from "../types/schema";
|
|
3
|
+
export declare const FileField: ({ uploadHandler, inline, label, accept, value, fileUrl, multiple, invalid, error, ...rest }: Partial<FileSchema & ValueType> & {
|
|
4
4
|
value?: AnyObject;
|
|
5
5
|
inline?: boolean;
|
|
6
|
+
invalid?: boolean;
|
|
7
|
+
error?: AnyObject;
|
|
6
8
|
fileUrl?: (path: string) => string;
|
|
7
9
|
uploadHandler: UploadHandler;
|
|
8
10
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type UploadHandler } from "../hooks/useFileUploader";
|
|
2
|
+
import { type BaseSelectProps } from "../types";
|
|
2
3
|
import { type SchemaType } from "../types/schema";
|
|
3
|
-
export declare const FormField: ({ id, label, required, inline, prefix, autoFocus,
|
|
4
|
+
export declare const FormField: ({ id, label, required, inline, prefix, autoFocus, optionLists, fileUrl, uploadHandler, ...rest }: SchemaType & {
|
|
4
5
|
inline?: boolean;
|
|
5
6
|
prefix?: string;
|
|
6
7
|
autoFocus?: boolean;
|
|
8
|
+
optionLists?: KeyValue<BaseSelectProps<any>>;
|
|
7
9
|
fileUrl?: (path: string) => string;
|
|
8
10
|
uploadHandler?: UploadHandler;
|
|
9
11
|
}) => import("react/jsx-runtime").JSX.Element | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type SchemaEditorProps } from "../../types/schema";
|
|
2
|
+
export declare const SchemaField: ({ id, field, fieldId, getModel, onRemove, defaultOpen, optionLists, dynamic, onTypeChange, acceptableTypes, }: {
|
|
3
|
+
id: string;
|
|
4
|
+
field: string;
|
|
5
|
+
fieldId: string;
|
|
6
|
+
defaultOpen?: boolean;
|
|
7
|
+
onRemove: () => void;
|
|
8
|
+
getModel: () => KeyValue;
|
|
9
|
+
onTypeChange: (val: KeyValue) => void;
|
|
10
|
+
} & Omit<SchemaEditorProps, "schemaDef" | "onChange">) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,7 +4,7 @@ export interface ControllerProps {
|
|
|
4
4
|
* field name
|
|
5
5
|
*/
|
|
6
6
|
name?: string;
|
|
7
|
-
children: ReactElement | ((props: {
|
|
7
|
+
children: ReactElement<KeyValue> | ((props: {
|
|
8
8
|
name: string;
|
|
9
9
|
error?: string;
|
|
10
10
|
checked: boolean;
|
|
@@ -14,7 +14,7 @@ export interface ControllerProps {
|
|
|
14
14
|
disabled?: boolean;
|
|
15
15
|
onBlur: () => void;
|
|
16
16
|
onChange: (value: AnyObject) => void;
|
|
17
|
-
|
|
17
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
18
18
|
}) => ReactElement);
|
|
19
19
|
}
|
|
20
20
|
export declare const Controller: ({ name, children, ...rest }: ControllerProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type yup } from "@react-fabric/utilities";
|
|
2
2
|
import { type PropsWithChildren, type Ref } from "react";
|
|
3
3
|
import { type FormState } from "react-hook-form";
|
|
4
|
+
type NestedKeyOf<T extends object> = {
|
|
5
|
+
[K in keyof T & (string | number)]: T[K] extends object ? `${K}` | `${K}.${NestedKeyOf<T[K]>}` : K;
|
|
6
|
+
}[keyof T & (string | number)];
|
|
4
7
|
export interface FormRef<K extends KeyValue> {
|
|
5
8
|
state: FormState<K>;
|
|
6
9
|
reset: () => void;
|
|
@@ -8,7 +11,7 @@ export interface FormRef<K extends KeyValue> {
|
|
|
8
11
|
submit: () => void;
|
|
9
12
|
validate: () => Promise<boolean>;
|
|
10
13
|
getValues: () => K;
|
|
11
|
-
setValue: (key:
|
|
14
|
+
setValue: (key: NestedKeyOf<K>, value: AnyObject) => void;
|
|
12
15
|
setValues: (values: K) => void;
|
|
13
16
|
}
|
|
14
17
|
export interface FormProps<K extends KeyValue = KeyValue> {
|
|
@@ -31,3 +34,4 @@ export interface FormProps<K extends KeyValue = KeyValue> {
|
|
|
31
34
|
onSubmit?: (values: K) => void;
|
|
32
35
|
}
|
|
33
36
|
export declare const Form: <K extends KeyValue<any>>({ formRef, schema, children, defaultValues, onSubmit, onChange, ...rest }: PropsWithChildren<FormProps<K>>) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { yup } from "@react-fabric/utilities";
|
|
2
|
+
import { type BaseSelectProps } from "../types";
|
|
2
3
|
import { type FormSchema } from "../types/schema";
|
|
3
4
|
import { type UploadHandler } from "./useFileUploader";
|
|
4
|
-
export declare const useFormBuilder: (schema: FormSchema
|
|
5
|
+
export declare const useFormBuilder: <T extends unknown = string>(schema: FormSchema, options?: {
|
|
5
6
|
prefix?: string;
|
|
6
7
|
inline?: boolean;
|
|
7
8
|
fileUrl?: (path: string) => string;
|
|
8
9
|
uploadHandler?: UploadHandler;
|
|
10
|
+
optionLists?: KeyValue<BaseSelectProps<T>>;
|
|
9
11
|
}) => {
|
|
10
12
|
formDef: import("react/jsx-runtime").JSX.Element;
|
|
11
13
|
schemaDef: yup.ObjectSchema<{
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import "./i18n";
|
|
2
2
|
export { Controller } from "./form/Controller";
|
|
3
3
|
export { Form, type FormRef } from "./form/Form";
|
|
4
|
+
export { SchemaEditor } from "./builder/SchemaEditor";
|
|
4
5
|
export { useFileUploader } from "./hooks/useFileUploader";
|
|
5
6
|
export { useFormBuilder } from "./hooks/useFormBuilder";
|
|
6
|
-
export { type FormSchema } from "./types/schema";
|
|
7
|
+
export { DATA_TYPES, SCHEMA_CUSTOM_LIST, type FormSchema, type SchemaDef, } from "./types/schema";
|
|
7
8
|
export { ArrayInput } from "./input/ArrayInput";
|
|
9
|
+
export { AvatarInput } from "./input/AvatarInput";
|
|
8
10
|
export { Checkbox } from "./input/Checkbox";
|
|
9
11
|
export { ColorInput } from "./input/ColorInput";
|
|
10
12
|
export { ColorPicker } from "./input/ColorPicker";
|
|
13
|
+
export { DateInput } from "./input/DateInput";
|
|
11
14
|
export { Field } from "./input/Field";
|
|
12
15
|
export { FileInput } from "./input/File";
|
|
13
16
|
export { HiddenInput } from "./input/Hidden";
|
|
@@ -16,7 +19,7 @@ export { Number } from "./input/Number";
|
|
|
16
19
|
export { Password } from "./input/Password";
|
|
17
20
|
export { Radio } from "./input/Radio";
|
|
18
21
|
export { RadioGroup } from "./input/RadioGroup";
|
|
19
|
-
export {
|
|
22
|
+
export { RangeSlider } from "./input/RangeSlider";
|
|
20
23
|
export { Search } from "./input/Search";
|
|
21
24
|
export { Slider } from "./input/Slider";
|
|
22
25
|
export { Switch } from "./input/Switch";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ReactNode, type
|
|
2
|
-
export interface ArrayInputProps {
|
|
1
|
+
import { type ReactNode, type Ref } from "react";
|
|
2
|
+
export interface ArrayInputProps<T extends AnyObject = string> {
|
|
3
3
|
/**
|
|
4
4
|
* input label
|
|
5
5
|
*/
|
|
@@ -32,6 +32,10 @@ export interface ArrayInputProps {
|
|
|
32
32
|
* minimum required length
|
|
33
33
|
*/
|
|
34
34
|
minItems?: number;
|
|
35
|
+
/**
|
|
36
|
+
* maximum length
|
|
37
|
+
*/
|
|
38
|
+
maxItems?: number;
|
|
35
39
|
/**
|
|
36
40
|
* field name to focus on add
|
|
37
41
|
*/
|
|
@@ -48,17 +52,46 @@ export interface ArrayInputProps {
|
|
|
48
52
|
* add item button label
|
|
49
53
|
*/
|
|
50
54
|
addLabel?: string;
|
|
55
|
+
buttonPosition?: "top" | "bottom" | "both";
|
|
51
56
|
/**
|
|
52
57
|
* fixed length list
|
|
53
58
|
*/
|
|
54
59
|
fixedList?: boolean;
|
|
55
|
-
arrayRef?:
|
|
56
|
-
addItem: (item:
|
|
60
|
+
arrayRef?: Ref<{
|
|
61
|
+
addItem: (item: T) => void;
|
|
57
62
|
removeItem: (idx: number) => void;
|
|
58
63
|
}>;
|
|
59
64
|
/**
|
|
60
|
-
*
|
|
65
|
+
* add new item
|
|
61
66
|
*/
|
|
62
67
|
onAdd?: () => AnyObject;
|
|
68
|
+
/**
|
|
69
|
+
* on item remove
|
|
70
|
+
*/
|
|
71
|
+
onRemove?: (item: T, idx: number) => void;
|
|
72
|
+
/**
|
|
73
|
+
* before item remove
|
|
74
|
+
*/
|
|
75
|
+
onBeforeRemove?: (item: T, idx: number) => Promise<boolean> | boolean;
|
|
76
|
+
/**
|
|
77
|
+
* can remove item
|
|
78
|
+
*/
|
|
79
|
+
canRemove?: (props: {
|
|
80
|
+
item: T;
|
|
81
|
+
index: number;
|
|
82
|
+
lastItem: boolean;
|
|
83
|
+
}) => boolean;
|
|
84
|
+
/**
|
|
85
|
+
* field width
|
|
86
|
+
*/
|
|
87
|
+
width?: number | string;
|
|
88
|
+
/**
|
|
89
|
+
* inline label and input
|
|
90
|
+
*/
|
|
91
|
+
inline?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* label width for inline
|
|
94
|
+
*/
|
|
95
|
+
labelWidth?: string;
|
|
63
96
|
}
|
|
64
|
-
export declare const ArrayInput: ({ name, children, addLabel, fixedList, focusName, onAdd, arrayRef, enableSorting, disabled, readOnly, minItems, ...rest }: ArrayInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
97
|
+
export declare const ArrayInput: <T extends unknown = string>({ name, children, addLabel, fixedList, focusName, buttonPosition, onAdd, onRemove, onBeforeRemove, canRemove, arrayRef, enableSorting, disabled, readOnly, minItems, maxItems, ...rest }: ArrayInputProps<T>) => import("react/jsx-runtime").JSX.Element;
|