@react-fabric/form 1.0.0-beta.3 → 1.0.0-beta.31

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.
Files changed (66) hide show
  1. package/dist/cjs/form/Form.js +12 -5
  2. package/dist/cjs/input/ArrayInput.js +35 -23
  3. package/dist/cjs/input/ColorInput.js +68 -26
  4. package/dist/cjs/input/ColorPicker.js +0 -33
  5. package/dist/cjs/input/ColorPicker.module.css +1 -1
  6. package/dist/cjs/input/Field.js +3 -2
  7. package/dist/cjs/input/File.module.css +1 -1
  8. package/dist/cjs/input/Hidden.js +3 -1
  9. package/dist/cjs/input/RadioGroup.js +6 -3
  10. package/dist/cjs/input/Switch.js +25 -4
  11. package/dist/cjs/input/Textarea.js +6 -2
  12. package/dist/cjs/internal/FieldWrapper.js +3 -1
  13. package/dist/cjs/internal/InputWrapper.js +7 -10
  14. package/dist/cjs/select/List.js +41 -20
  15. package/dist/cjs/select/Options.js +2 -2
  16. package/dist/cjs/select/Select.js +10 -7
  17. package/dist/cjs/select/useSelect.js +12 -7
  18. package/dist/cjs/utils/getColor.js +6 -0
  19. package/dist/esm/form/Form.js +13 -6
  20. package/dist/esm/input/ArrayInput.js +37 -25
  21. package/dist/esm/input/ColorInput.js +70 -28
  22. package/dist/esm/input/ColorPicker.js +0 -33
  23. package/dist/esm/input/ColorPicker.module.css +1 -1
  24. package/dist/esm/input/Field.js +4 -3
  25. package/dist/esm/input/File.module.css +1 -1
  26. package/dist/esm/input/Hidden.js +3 -1
  27. package/dist/esm/input/RadioGroup.js +7 -4
  28. package/dist/esm/input/Switch.js +27 -6
  29. package/dist/esm/input/Textarea.js +6 -2
  30. package/dist/esm/internal/FieldWrapper.js +3 -1
  31. package/dist/esm/internal/InputWrapper.js +7 -10
  32. package/dist/esm/select/List.js +42 -21
  33. package/dist/esm/select/Options.js +2 -2
  34. package/dist/esm/select/Select.js +10 -7
  35. package/dist/esm/select/useSelect.js +13 -8
  36. package/dist/esm/utils/getColor.js +6 -1
  37. package/dist/types/input/ArrayInput.d.ts +20 -3
  38. package/dist/types/input/RadioGroup.d.ts +18 -2
  39. package/dist/types/input/Switch.d.ts +7 -3
  40. package/dist/types/input/Textarea.d.ts +5 -1
  41. package/dist/types/internal/InputWrapper.d.ts +1 -1
  42. package/dist/types/select/List.d.ts +1 -1
  43. package/dist/types/types/index.d.ts +2 -2
  44. package/package.json +7 -7
  45. package/src/form/Form.tsx +13 -5
  46. package/src/input/ArrayInput.tsx +78 -40
  47. package/src/input/ColorInput.tsx +96 -31
  48. package/src/input/ColorPicker.module.css +19 -5
  49. package/src/input/ColorPicker.tsx +0 -33
  50. package/src/input/Field.tsx +6 -8
  51. package/src/input/File.module.css +18 -4
  52. package/src/input/Hidden.tsx +3 -1
  53. package/src/input/Input.tsx +1 -1
  54. package/src/input/Number.tsx +1 -1
  55. package/src/input/Password.tsx +1 -1
  56. package/src/input/RadioGroup.tsx +27 -4
  57. package/src/input/Search.tsx +1 -1
  58. package/src/input/Switch.tsx +40 -6
  59. package/src/input/Textarea.tsx +10 -2
  60. package/src/internal/FieldWrapper.tsx +2 -1
  61. package/src/internal/InputWrapper.tsx +8 -11
  62. package/src/select/List.tsx +34 -7
  63. package/src/select/Options.tsx +1 -1
  64. package/src/select/Select.tsx +4 -1
  65. package/src/select/useSelect.tsx +27 -18
  66. package/src/types/index.ts +5 -2
@@ -2,26 +2,29 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
- import { Children, cloneElement } from 'react';
5
+ import { cloneChildren } from '@react-fabric/core';
6
+ import { cloneElement } from 'react';
6
7
  import { FieldWrapper } from '../internal/FieldWrapper.js';
7
8
  import { jsx } from 'react/jsx-runtime';
8
9
 
9
- var _excluded = ["children", "name", "className", "onChange"];
10
+ var _excluded = ["children", "name", "className", "optionWidth", "onChange"];
10
11
  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; }
11
12
  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; }
12
13
  var RadioGroup = function RadioGroup(_ref) {
13
14
  var children = _ref.children,
14
15
  name = _ref.name,
15
16
  className = _ref.className,
17
+ optionWidth = _ref.optionWidth,
16
18
  onChange = _ref.onChange,
17
19
  rest = _objectWithoutProperties(_ref, _excluded);
18
20
  return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
19
21
  children: /*#__PURE__*/jsx("div", {
20
22
  className: className,
21
- children: Children.map(children, function (child) {
23
+ children: cloneChildren(children, function (child) {
22
24
  return /*#__PURE__*/cloneElement(child, {
23
25
  name: name,
24
- onChange: onChange
26
+ onChange: onChange,
27
+ width: optionWidth
25
28
  });
26
29
  })
27
30
  })
@@ -4,13 +4,13 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
5
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
6
6
  import classNames from 'classnames';
7
- import { useState, useDeferredValue, useEffect, useCallback } from 'react';
7
+ import { useState, useDeferredValue, useEffect, useCallback, Fragment } from 'react';
8
8
  import { ErrorIcon } from '../internal/ErrorIcon.js';
9
9
  import '@react-fabric/utilities';
10
- import { getBgClass, getColor } from '../utils/getColor.js';
10
+ import { getBgClass, getColor, getColorClass } from '../utils/getColor.js';
11
11
  import { jsxs, jsx } from 'react/jsx-runtime';
12
12
 
13
- var _excluded = ["ref", "label", "checked", "invalid", "disabled", "error", "width", "color", "name", "defaultColor", "onChange"];
13
+ var _excluded = ["ref", "label", "checked", "invalid", "disabled", "error", "width", "color", "name", "onLabel", "offLabel", "onLabelColor", "offLabelColor", "defaultColor", "onChange"];
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
15
  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; }
16
16
  var Switch = function Switch(_ref) {
@@ -23,7 +23,11 @@ var Switch = function Switch(_ref) {
23
23
  width = _ref.width,
24
24
  color = _ref.color;
25
25
  _ref.name;
26
- var defaultColor = _ref.defaultColor,
26
+ var onLabel = _ref.onLabel,
27
+ offLabel = _ref.offLabel,
28
+ onLabelColor = _ref.onLabelColor,
29
+ offLabelColor = _ref.offLabelColor,
30
+ defaultColor = _ref.defaultColor,
27
31
  onChange = _ref.onChange,
28
32
  rest = _objectWithoutProperties(_ref, _excluded);
29
33
  var _useState = useState(false),
@@ -45,7 +49,7 @@ var Switch = function Switch(_ref) {
45
49
  width: width
46
50
  },
47
51
  children: [/*#__PURE__*/jsxs("div", {
48
- className: classNames(actualValue && getBgClass(color ? "".concat(color, "-500") : "primary-500"), !actualValue && (defaultColor ? getBgClass("".concat(defaultColor, "-500")) : "bg-tint-200"), "relative flex h-6 w-10 cursor-pointer rounded-full p-1 transition-colors duration-200 ease-in-out"),
52
+ className: classNames(actualValue && getBgClass(color ? "".concat(color, "-500") : "primary-500"), !actualValue && (defaultColor ? getBgClass("".concat(defaultColor, "-500")) : "bg-tint-200"), "relative grid grid-cols-2 items-center h-6 min-w-10 cursor-pointer rounded-full p-1 transition-colors duration-200 ease-in-out"),
49
53
  style: {
50
54
  backgroundColor: actualValue ? getColor(color) : getColor(defaultColor)
51
55
  },
@@ -64,7 +68,24 @@ var Switch = function Switch(_ref) {
64
68
  onChange: handleChange
65
69
  }, rest)), /*#__PURE__*/jsx("span", {
66
70
  "aria-hidden": "true",
67
- className: classNames(!disabled && "shadow-sm", actualValue ? "translate-x-4" : "translate-x-0", "pointer-events-none inline-block size-4 rounded-full bg-white ring-0 transition duration-200 ease-in-out")
71
+ className: classNames(!disabled && "shadow-sm", actualValue ? "translate-x-[100%]" : "translate-x-0", "pointer-events-none inline-block h-4 start-1 absolute rounded-full bg-white ring-0 transition duration-200 ease-in-out"),
72
+ style: {
73
+ width: "calc(50% - 0.25rem)"
74
+ }
75
+ }), (!!onLabel || !!offLabel) && /*#__PURE__*/jsxs(Fragment, {
76
+ children: [/*#__PURE__*/jsx("span", {
77
+ className: "whitespace-nowrap text-xs px-1 ".concat(getColorClass(onLabelColor !== null && onLabelColor !== void 0 ? onLabelColor : "white")),
78
+ style: {
79
+ color: getColor(onLabelColor)
80
+ },
81
+ children: onLabel !== null && onLabel !== void 0 ? onLabel : " "
82
+ }), /*#__PURE__*/jsx("span", {
83
+ className: "whitespace-nowrap text-xs px-1 ".concat(getColorClass(offLabelColor !== null && offLabelColor !== void 0 ? offLabelColor : "base")),
84
+ style: {
85
+ color: getColor(offLabelColor)
86
+ },
87
+ children: offLabel !== null && offLabel !== void 0 ? offLabel : " "
88
+ })]
68
89
  })]
69
90
  }), /*#__PURE__*/jsx(ErrorIcon, {
70
91
  invalid: invalid,
@@ -9,7 +9,7 @@ import { handleEnter } from '../utils/eventHandlers.js';
9
9
  import '@react-fabric/utilities';
10
10
  import { jsx } from 'react/jsx-runtime';
11
11
 
12
- var _excluded = ["ref", "value", "name", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "rows", "maxRows", "variableRows", "onChange", "onEnterPressed"];
12
+ var _excluded = ["ref", "value", "name", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "rows", "maxRows", "variableRows", "expandable", "onChange", "onEnterPressed"];
13
13
  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
14
  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; }
15
15
  var Textarea = function Textarea(_ref) {
@@ -27,6 +27,7 @@ var Textarea = function Textarea(_ref) {
27
27
  _ref$maxRows = _ref.maxRows,
28
28
  maxRows = _ref$maxRows === void 0 ? 12 : _ref$maxRows,
29
29
  variableRows = _ref.variableRows,
30
+ expandable = _ref.expandable,
30
31
  onChange = _ref.onChange,
31
32
  onEnterPressed = _ref.onEnterPressed,
32
33
  rest = _objectWithoutProperties(_ref, _excluded);
@@ -65,6 +66,7 @@ var Textarea = function Textarea(_ref) {
65
66
  disabled: disabled,
66
67
  required: required,
67
68
  wrapperRef: wrapperRef,
69
+ textareaExpandable: expandable,
68
70
  textarea: true
69
71
  }, rest), {}, {
70
72
  children: /*#__PURE__*/jsx("textarea", {
@@ -83,7 +85,9 @@ var Textarea = function Textarea(_ref) {
83
85
  autoFocus: autoFocus,
84
86
  value: actualValue,
85
87
  onChange: handleChange,
86
- onKeyDown: handleEnter(onEnterPressed)
88
+ onKeyDown: handleEnter(onEnterPressed, {
89
+ preventDefault: !!onEnterPressed
90
+ })
87
91
  })
88
92
  }));
89
93
  };
@@ -49,7 +49,7 @@ var FieldWrapper = function FieldWrapper(_ref) {
49
49
  flexBasis: width
50
50
  },
51
51
  children: [!isInner && /*#__PURE__*/jsxs("div", {
52
- className: "flex flex-nowrap flex-content gap-1 py-0.5 px-2",
52
+ className: "flex flex-nowrap flex-content items-end gap-1 py-0.5 px-2",
53
53
  style: {
54
54
  width: inline ? labelWidth : undefined
55
55
  },
@@ -64,6 +64,8 @@ var FieldWrapper = function FieldWrapper(_ref) {
64
64
  }), required && /*#__PURE__*/jsx("span", {
65
65
  className: "text-danger-500 select-none flex-content text-[10px]",
66
66
  children: "\u273D"
67
+ }), /*#__PURE__*/jsx("div", {
68
+ className: "flex-1"
67
69
  }), appendLabel && /*#__PURE__*/jsx("span", {
68
70
  className: "flex-content",
69
71
  children: appendLabel
@@ -3,7 +3,6 @@
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
5
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
6
- import { FloatingPortal } from '@floating-ui/react';
7
6
  import { Icon, CoreIcons } from '@react-fabric/core';
8
7
  import { isString } from '@react-fabric/utilities';
9
8
  import classNames from 'classnames';
@@ -13,11 +12,10 @@ import { ErrorIcon } from './ErrorIcon.js';
13
12
  import classes from './Field.module.css';
14
13
  import { FieldWrapper } from './FieldWrapper.js';
15
14
 
16
- var _excluded = ["invalid", "error", "allowClear", "showClear", "decorateStart", "decorateEnd", "children", "onClear", "noOutline", "noBorder", "textarea", "data-inner", "data-open", "floatingExpand", "wrapperRef", "width"];
15
+ var _excluded = ["invalid", "error", "allowClear", "showClear", "decorateStart", "decorateEnd", "children", "onClear", "noOutline", "noBorder", "textarea", "textareaExpandable", "data-inner", "data-open", "floatingExpand", "wrapperRef", "width"];
17
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; }
18
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; }
19
18
  var InputWrapper = function InputWrapper(_ref) {
20
- var _elRef$current;
21
19
  var invalid = _ref.invalid,
22
20
  error = _ref.error,
23
21
  allowClear = _ref.allowClear,
@@ -30,6 +28,8 @@ var InputWrapper = function InputWrapper(_ref) {
30
28
  noBorder = _ref.noBorder,
31
29
  _ref$textarea = _ref.textarea,
32
30
  textarea = _ref$textarea === void 0 ? false : _ref$textarea,
31
+ _ref$textareaExpandab = _ref.textareaExpandable,
32
+ textareaExpandable = _ref$textareaExpandab === void 0 ? false : _ref$textareaExpandab,
33
33
  isInner = _ref["data-inner"];
34
34
  _ref["data-open"];
35
35
  var floatingExpand = _ref.floatingExpand,
@@ -69,7 +69,7 @@ var InputWrapper = function InputWrapper(_ref) {
69
69
  ref: wrapperRef,
70
70
  className: classNames(classes.inputWrapper, invalid && classes.invalidWrapper, !noOutline && !noBorder && "bg-[var(--fabric-input)] outline overflow-hidden", "flex flex-nowrap items-center", textarea ? "rounded-capped group" : "rounded", isExpanded ? "fixed inset-4 z-[99]" : floatingExpand ? "absolute inset-x-0" : "relative", !noOutline && "after:absolute after:bottom-0 after:h-px after:bg-primary-500 after:mx-auto"),
71
71
  onKeyDown: function onKeyDown(e) {
72
- return e.key === "Escape" && setExpanded(false);
72
+ return e.key === "Escape" && isExpanded && (setExpanded(false), e.stopPropagation());
73
73
  },
74
74
  children: [decorateStart && /*#__PURE__*/jsx("div", {
75
75
  onClickCapture: doFocus,
@@ -86,7 +86,7 @@ var InputWrapper = function InputWrapper(_ref) {
86
86
  onClickCapture: doFocus,
87
87
  className: classNames(classes.decorate, "text-muted leading-none flex-content", isString(decorateEnd) && "px-1"),
88
88
  children: decorateEnd
89
- }), textarea && /*#__PURE__*/jsx(Icon, {
89
+ }), textareaExpandable && /*#__PURE__*/jsx(Icon, {
90
90
  onClick: function onClick() {
91
91
  return setExpanded(!isExpanded);
92
92
  },
@@ -95,17 +95,14 @@ var InputWrapper = function InputWrapper(_ref) {
95
95
  })]
96
96
  });
97
97
  return /*#__PURE__*/jsx(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
98
- children: /*#__PURE__*/jsxs("div", {
98
+ children: /*#__PURE__*/jsx("div", {
99
99
  ref: elRef,
100
100
  className: "flex-1 relative min-h-8",
101
101
  style: {
102
102
  width: width,
103
103
  flexBasis: width
104
104
  },
105
- children: [!isExpanded && el, isExpanded && /*#__PURE__*/jsx(FloatingPortal, {
106
- root: (_elRef$current = elRef.current) === null || _elRef$current === void 0 ? void 0 : _elRef$current.closest(".theme-base"),
107
- children: el
108
- })]
105
+ children: el
109
106
  })
110
107
  }));
111
108
  };
@@ -6,33 +6,34 @@ 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", "multiple", "allowCreate", "searchable", "createOption", "matcher", "renderer", "onQuery", "onChange", "onSelect", "onEnterPressed", "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
- var name = _ref.name,
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
- var options = _ref.options,
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
34
  multiple = _ref.multiple,
35
35
  allowCreate = _ref.allowCreate,
36
+ searchable = _ref.searchable,
36
37
  createOption = _ref.createOption,
37
38
  matcher = _ref.matcher,
38
39
  renderer = _ref.renderer,
@@ -138,9 +139,10 @@ var List = function List(_ref) {
138
139
  }
139
140
  } else if (evt.key === "Backspace") {
140
141
  !state.query && handleRemove();
141
- } else if (["ArrowUp", "ArrowDown"].includes(evt.key)) {
142
- if (state.activeIndex === null) {
143
- setActiveIndex(state.selectedIndex);
142
+ } else if (!searchable || ["ArrowUp", "ArrowDown"].includes(evt.key)) {
143
+ if (["ArrowUp", "ArrowDown"].includes(evt.key) && state.activeIndex === null) {
144
+ var _state$selectedIndex;
145
+ setActiveIndex((_state$selectedIndex = state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0);
144
146
  }
145
147
  setTimeout(function () {
146
148
  var _props$onKeyDown;
@@ -185,6 +187,14 @@ var List = function List(_ref) {
185
187
  });
186
188
  }
187
189
  }, [state.value, state.query, placeholder, renderer]);
190
+ useLayoutEffect(function () {
191
+ setTimeout(function () {
192
+ var _listRef$current$stat;
193
+ state.selectedIndex && ((_listRef$current$stat = listRef.current[state.selectedIndex]) === null || _listRef$current$stat === void 0 ? void 0 : _listRef$current$stat.scrollIntoView({
194
+ block: "center"
195
+ }));
196
+ }, 100);
197
+ }, [state.selectedIndex]);
188
198
  return /*#__PURE__*/jsxs(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
189
199
  children: [/*#__PURE__*/jsx(InputWrapper, {
190
200
  showClear: !isEmpty(state.value),
@@ -197,23 +207,32 @@ var List = function List(_ref) {
197
207
  className: "z-1 rounded-b-none",
198
208
  "data-inner": true,
199
209
  wrapperRef: refs.setReference,
200
- children: /*#__PURE__*/jsxs("div", {
210
+ children: /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
211
+ role: "none",
201
212
  "data-select-display": "true",
202
- className: "group flex-1 py-1 px-2 truncate text-start flex gap-1 flex-wrap",
203
- children: [!hideSelected && displayValue, /*#__PURE__*/jsx("input", _objectSpread(_objectSpread({
213
+ 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")
214
+ }, referenceProps), {}, {
215
+ onMouseUp: function onMouseUp(e) {
216
+ var _e$currentTarget$quer;
217
+ return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
218
+ },
219
+ children: [!hideSelected && displayValue, /*#__PURE__*/jsx("input", {
220
+ readOnly: !searchable || readOnly,
204
221
  disabled: disabled,
205
222
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
206
223
  "aria-invalid": invalid,
207
224
  "data-testid": name,
208
225
  name: name,
209
- className: classNames("appearance-none bg-transparent outline-none border-none ring-0 flex-1 min-w-24", disabled && "cursor-not-allowed pointer-events-none"),
210
- placeholder: isEmpty(state.value) ? placeholder : ""
211
- }, referenceProps), {}, {
226
+ size: 1,
227
+ ref: ref,
228
+ autoFocus: autoFocus,
229
+ 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"),
230
+ placeholder: isEmpty(state.value) ? placeholder : "",
212
231
  onChange: function onChange(evt) {
213
232
  return handleQuery(evt.target.value);
214
233
  }
215
- }))]
216
- })
234
+ })]
235
+ }))
217
236
  }), /*#__PURE__*/jsx(FloatingFocusManager, {
218
237
  context: context,
219
238
  initialFocus: -1,
@@ -227,11 +246,13 @@ var List = function List(_ref) {
227
246
  }, floatingProps), {}, {
228
247
  items: state.items,
229
248
  active: state.activeIndex,
249
+ valueProperty: valueProperty,
250
+ labelProperty: labelProperty,
230
251
  itemRef: setItemRef,
231
252
  itemProps: makeItemProps,
232
- children: function children(item) {
233
- var _ref4, _renderer3;
234
- return (_ref4 = (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : item[labelProperty]) !== null && _ref4 !== void 0 ? _ref4 : item;
253
+ children: function children(item, label) {
254
+ var _renderer3;
255
+ return (_renderer3 = renderer === null || renderer === void 0 ? void 0 : renderer(item)) !== null && _renderer3 !== void 0 ? _renderer3 : label;
235
256
  }
236
257
  }))
237
258
  })]
@@ -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"
@@ -140,6 +140,9 @@ var Select = function Select(_ref) {
140
140
  return false;
141
141
  } else if (state.query) {
142
142
  handleQuery("");
143
+ evt.preventDefault();
144
+ evt.stopPropagation();
145
+ return false;
143
146
  } else {
144
147
  onEnterPressed === null || onEnterPressed === void 0 || onEnterPressed(evt);
145
148
  }
@@ -217,15 +220,16 @@ var Select = function Select(_ref) {
217
220
  wrapperRef: refs.setReference,
218
221
  className: state.open ? "!z-[99]" : ""
219
222
  }, rest), {}, {
220
- children: [/*#__PURE__*/jsxs("div", {
223
+ children: [/*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
221
224
  role: "none",
222
225
  "data-select-display": "true",
223
- 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"),
226
+ 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")
227
+ }, referenceProps), {}, {
224
228
  onMouseUp: function onMouseUp(e) {
225
229
  var _e$currentTarget$quer;
226
230
  return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
227
231
  },
228
- children: [displayValue, /*#__PURE__*/jsx("input", _objectSpread(_objectSpread({
232
+ children: [displayValue, /*#__PURE__*/jsx("input", {
229
233
  readOnly: !searchable || readOnly,
230
234
  disabled: disabled,
231
235
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
@@ -236,13 +240,12 @@ var Select = function Select(_ref) {
236
240
  ref: ref,
237
241
  autoFocus: autoFocus,
238
242
  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"),
239
- placeholder: isEmpty(state.value) ? placeholder : ""
240
- }, referenceProps), {}, {
243
+ placeholder: isEmpty(state.value) ? placeholder : "",
241
244
  onChange: function onChange(evt) {
242
245
  return handleQuery(evt.target.value);
243
246
  }
244
- }))]
245
- }), !state.loading && /*#__PURE__*/jsx(Icon, {
247
+ })]
248
+ })), !state.loading && /*#__PURE__*/jsx(Icon, {
246
249
  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
250
  onClick: function onClick() {
248
251
  return !disabled && openDropdown();
@@ -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, 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
 
@@ -88,7 +88,7 @@ var useSelect = function useSelect(_ref) {
88
88
  if (action.value !== undefined) {
89
89
  if (multiple) {
90
90
  var values = [];
91
- if (action.value && autoComplete) values.push.apply(values, _toConsumableArray(action.value.split(/,\s?/)));else if (action.value) values.push(action.value);
91
+ if (isString(action.value)) values.push.apply(values, _toConsumableArray(action.value.split(/,\s?/)));else values.push(action.value);
92
92
  newState.value = _toConsumableArray(state.value);
93
93
  values.forEach(function (value) {
94
94
  var _newState$value$inclu, _newState$value;
@@ -133,13 +133,14 @@ var useSelect = function useSelect(_ref) {
133
133
  if (autoComplete && action.query !== undefined) {
134
134
  optionList = dedupe([action.query].concat(_toConsumableArray(optionList)));
135
135
  }
136
+ optionList = optionList.sort(compareValues("asc", labelProperty));
136
137
  var grouped = groupBy(optionList, groupProperty, "");
137
138
  if (action.open) _newState.open = true;
138
139
  _newState.items = [];
139
140
  // add new item if allowCreate
140
141
  if (allowCreate && action.query) _newState.items.push({
141
142
  ___create___: true,
142
- value: createOption(action.query)
143
+ value: action.query
143
144
  });
144
145
  Object.entries(grouped).forEach(function (_ref2) {
145
146
  var _newState$items;
@@ -201,22 +202,22 @@ var useSelect = function useSelect(_ref) {
201
202
  });
202
203
  dispatch({
203
204
  type: "setValue",
204
- value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : ""
205
+ value: (_ref4 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref4 !== void 0 ? _ref4 : deferred
205
206
  });
206
207
  }
207
208
  if (multiple) {
208
209
  optionsRef.current = [];
209
- var _value = (deferred !== null && deferred !== void 0 ? deferred : []).map(function (item) {
210
+ var _value = (isArray(deferred) ? deferred : []).map(function (item) {
210
211
  var _ref5;
211
212
  var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
212
213
  var hasValue = options.find(function (opt) {
213
214
  var _opt$valueProperty2;
214
- return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === deferred;
215
+ return ((_opt$valueProperty2 = opt[valueProperty]) !== null && _opt$valueProperty2 !== void 0 ? _opt$valueProperty2 : opt) === item;
215
216
  });
216
217
  if (!hasValue && newOption) {
217
218
  optionsRef.current.push(newOption);
218
219
  }
219
- return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : "";
220
+ return (_ref5 = hasValue !== null && hasValue !== void 0 ? hasValue : newOption) !== null && _ref5 !== void 0 ? _ref5 : item;
220
221
  });
221
222
  optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(options !== null && options !== void 0 ? options : []));
222
223
  dispatch({
@@ -285,7 +286,11 @@ var useSelect = function useSelect(_ref) {
285
286
  value: value !== null && value !== void 0 && value.___create___ ? value.value : value
286
287
  });
287
288
  if (value !== null && value !== void 0 && value.___create___) {
288
- optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), [createOption(value.value)]);
289
+ var val = [value.value];
290
+ if (multiple) {
291
+ val = value.value.split(/,\s?/);
292
+ }
293
+ optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(val.map(createOption)));
289
294
  }
290
295
  if (autoComplete) {
291
296
  optionsRef.current = dedupe([].concat(_toConsumableArray(isArray(values) ? values : [values]), _toConsumableArray(optionsRef.current)));
@@ -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,4 +1,4 @@
1
- import { type ReactNode, type RefObject } from "react";
1
+ import { type ReactNode, type Ref } from "react";
2
2
  export interface ArrayInputProps {
3
3
  /**
4
4
  * input label
@@ -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,11 +52,12 @@ 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?: RefObject<{
60
+ arrayRef?: Ref<{
56
61
  addItem: (item: AnyObject) => void;
57
62
  removeItem: (idx: number) => void;
58
63
  }>;
@@ -60,5 +65,17 @@ export interface ArrayInputProps {
60
65
  * Add item
61
66
  */
62
67
  onAdd?: () => AnyObject;
68
+ /**
69
+ * field width
70
+ */
71
+ width?: number | string;
72
+ /**
73
+ * inline label and input
74
+ */
75
+ inline?: boolean;
76
+ /**
77
+ * label width for inline
78
+ */
79
+ labelWidth?: string;
63
80
  }
64
- export declare const ArrayInput: ({ name, children, addLabel, fixedList, focusName, onAdd, arrayRef, enableSorting, disabled, readOnly, minItems, ...rest }: ArrayInputProps) => import("react/jsx-runtime").JSX.Element;
81
+ export declare const ArrayInput: ({ name, children, addLabel, fixedList, focusName, buttonPosition, onAdd, arrayRef, enableSorting, disabled, readOnly, minItems, maxItems, ...rest }: ArrayInputProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { type CssProp, type ChildrenProp } from "@react-fabric/core/dist/types/types";
2
+ import { type ChildrenProp, type CssProp } from "@react-fabric/core/dist/types/types";
3
3
  import { type Radio } from "./Radio";
4
4
  export interface RadioGroupProps extends ChildrenProp<typeof Radio>, CssProp {
5
5
  /**
@@ -14,6 +14,22 @@ export interface RadioGroupProps extends ChildrenProp<typeof Radio>, CssProp {
14
14
  * field info
15
15
  */
16
16
  info?: string;
17
+ /**
18
+ * field width
19
+ */
20
+ width?: number | string;
21
+ /**
22
+ * inline label and input
23
+ */
24
+ inline?: boolean;
25
+ /**
26
+ * label width for inline
27
+ */
28
+ labelWidth?: string;
29
+ /**
30
+ * label width for inline
31
+ */
32
+ optionWidth?: string;
17
33
  /**
18
34
  * field name
19
35
  */
@@ -27,4 +43,4 @@ export interface RadioGroupProps extends ChildrenProp<typeof Radio>, CssProp {
27
43
  */
28
44
  onChange?: (value: AnyObject) => void;
29
45
  }
30
- export declare const RadioGroup: ({ children, name, className, onChange, ...rest }: RadioGroupProps) => import("react/jsx-runtime").JSX.Element;
46
+ export declare const RadioGroup: ({ children, name, className, optionWidth, onChange, ...rest }: RadioGroupProps) => import("react/jsx-runtime").JSX.Element;
@@ -32,11 +32,15 @@ export interface SwitchProps extends RefProp<HTMLInputElement> {
32
32
  /**
33
33
  * cutom Switch icon
34
34
  */
35
- color?: ColorType;
35
+ color?: string | ColorType;
36
36
  /**
37
37
  * cutom Switch icon
38
38
  */
39
- defaultColor?: ColorType;
39
+ defaultColor?: string | ColorType;
40
40
  name?: string;
41
+ onLabel?: string;
42
+ onLabelColor?: string | ColorType;
43
+ offLabel?: string;
44
+ offLabelColor?: string | ColorType;
41
45
  }
42
- export declare const Switch: ({ ref, label, checked, invalid, disabled, error, width, color, name, defaultColor, onChange, ...rest }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
46
+ export declare const Switch: ({ ref, label, checked, invalid, disabled, error, width, color, name, onLabel, offLabel, onLabelColor, offLabelColor, defaultColor, onChange, ...rest }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
@@ -13,5 +13,9 @@ export interface TextareaProps extends InputProps, RefProp<HTMLTextAreaElement>
13
13
  * increment rows on value change
14
14
  */
15
15
  variableRows?: boolean;
16
+ /**
17
+ * expandable textarea
18
+ */
19
+ expandable?: boolean;
16
20
  }
17
- export declare const Textarea: ({ ref, value, name, invalid, readOnly, disabled, required, placeholder, autoFocus, rows, maxRows, variableRows, onChange, onEnterPressed, ...rest }: TextareaProps) => import("react/jsx-runtime").JSX.Element;
21
+ export declare const Textarea: ({ ref, value, name, invalid, readOnly, disabled, required, placeholder, autoFocus, rows, maxRows, variableRows, expandable, onChange, onEnterPressed, ...rest }: TextareaProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const InputWrapper: ({ invalid, error, allowClear, showClear, decorateStart, decorateEnd, children, onClear, noOutline, noBorder, textarea, "data-inner": isInner, "data-open": isOpen, floatingExpand, wrapperRef, width, ...rest }: KeyValue) => import("react/jsx-runtime").JSX.Element;
1
+ export declare const InputWrapper: ({ invalid, error, allowClear, showClear, decorateStart, decorateEnd, children, onClear, noOutline, noBorder, textarea, textareaExpandable, "data-inner": isInner, "data-open": isOpen, floatingExpand, wrapperRef, width, ...rest }: KeyValue) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
1
  import { type SelectProps } from "../types";
2
- export declare const List: <T extends unknown = string>({ 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": isInner, "data-hide-selected": hideSelected, ...rest }: SelectProps<T> & {
2
+ export declare const List: <T extends unknown = string>({ ref, name, value, readOnly, disabled, required, placeholder, autoFocus, options, height, groupProperty, labelProperty, valueProperty, multiple, allowCreate, searchable, createOption, matcher, renderer, onQuery, onChange, onSelect, onEnterPressed, invalid, error, allowClear, decorateStart, decorateEnd, "data-inner": isInner, "data-hide-selected": hideSelected, ...rest }: SelectProps<T> & {
3
3
  height?: string | number;
4
4
  }) => import("react/jsx-runtime").JSX.Element;