@react-fabric/form 1.0.0-beta.1 → 1.0.0-beta.12

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.
@@ -89,13 +89,17 @@ var Form = function Form(_ref) {
89
89
  return form.getValues();
90
90
  },
91
91
  setValues: function setValues(v) {
92
- return form.reset(v);
92
+ return setTimeout(function () {
93
+ return form.reset(v);
94
+ }, 50);
93
95
  },
94
96
  setValue: function setValue(k, v) {
95
- return form.setValue(k, v, {
96
- shouldDirty: false,
97
- shouldTouch: false
98
- });
97
+ return setTimeout(function () {
98
+ return form.setValue(k, v, {
99
+ shouldDirty: false,
100
+ shouldTouch: false
101
+ });
102
+ }, 50);
99
103
  }
100
104
  };
101
105
  }, [onSubmit, form, form.formState, defaultValues]);
@@ -8,17 +8,18 @@ var Field_module = require('../internal/Field.module.css');
8
8
  var FieldWrapper = require('../internal/FieldWrapper.js');
9
9
  var jsxRuntime = require('react/jsx-runtime');
10
10
 
11
- var _excluded = ["children", "noOutline", "plain"];
11
+ var _excluded = ["children", "vertical", "noOutline", "plain"];
12
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; }
13
13
  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; }
14
14
  var Field = function Field(_ref) {
15
15
  var children = _ref.children,
16
+ vertical = _ref.vertical,
16
17
  noOutline = _ref.noOutline,
17
18
  plain = _ref.plain,
18
19
  rest = _objectWithoutProperties(_ref, _excluded);
19
20
  return /*#__PURE__*/jsxRuntime.jsx(FieldWrapper.FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
20
21
  children: /*#__PURE__*/jsxRuntime.jsx("div", {
21
- className: classNames(Field_module.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex flex-nowrap flex-1 rounded"),
22
+ className: classNames(Field_module.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex-1 rounded", !vertical && "flex flex-nowrap"),
22
23
  children: react.Children.map(children, function (child) {
23
24
  return child && /*#__PURE__*/react.cloneElement(child, {
24
25
  "data-inner": true
@@ -6,13 +6,14 @@ var react = require('react');
6
6
  var FieldWrapper = require('../internal/FieldWrapper.js');
7
7
  var jsxRuntime = require('react/jsx-runtime');
8
8
 
9
- var _excluded = ["children", "name", "className", "onChange"];
9
+ var _excluded = ["children", "name", "className", "optionWidth", "onChange"];
10
10
  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
11
  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
12
  var RadioGroup = function RadioGroup(_ref) {
13
13
  var children = _ref.children,
14
14
  name = _ref.name,
15
15
  className = _ref.className,
16
+ optionWidth = _ref.optionWidth,
16
17
  onChange = _ref.onChange,
17
18
  rest = _objectWithoutProperties(_ref, _excluded);
18
19
  return /*#__PURE__*/jsxRuntime.jsx(FieldWrapper.FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
@@ -21,7 +22,8 @@ var RadioGroup = function RadioGroup(_ref) {
21
22
  children: react.Children.map(children, function (child) {
22
23
  return /*#__PURE__*/react.cloneElement(child, {
23
24
  name: name,
24
- onChange: onChange
25
+ onChange: onChange,
26
+ width: optionWidth
25
27
  });
26
28
  })
27
29
  })
@@ -10,7 +10,7 @@ require('@react-fabric/utilities');
10
10
  var getColor = require('../utils/getColor.js');
11
11
  var jsxRuntime = require('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 = react.useState(false),
@@ -45,7 +49,7 @@ var Switch = function Switch(_ref) {
45
49
  width: width
46
50
  },
47
51
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
48
- className: classNames(actualValue && getColor.getBgClass(color ? "".concat(color, "-500") : "primary-500"), !actualValue && (defaultColor ? getColor.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 && getColor.getBgClass(color ? "".concat(color, "-500") : "primary-500"), !actualValue && (defaultColor ? getColor.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.getColor(color) : getColor.getColor(defaultColor)
51
55
  },
@@ -64,7 +68,24 @@ var Switch = function Switch(_ref) {
64
68
  onChange: handleChange
65
69
  }, rest)), /*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsxs(react.Fragment, {
76
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
77
+ className: "whitespace-nowrap text-xs px-1 ".concat(getColor.getColorClass(onLabelColor !== null && onLabelColor !== void 0 ? onLabelColor : "white")),
78
+ style: {
79
+ color: getColor.getColor(onLabelColor)
80
+ },
81
+ children: onLabel !== null && onLabel !== void 0 ? onLabel : " "
82
+ }), /*#__PURE__*/jsxRuntime.jsx("span", {
83
+ className: "whitespace-nowrap text-xs px-1 ".concat(getColor.getColorClass(offLabelColor !== null && offLabelColor !== void 0 ? offLabelColor : "base")),
84
+ style: {
85
+ color: getColor.getColor(offLabelColor)
86
+ },
87
+ children: offLabel !== null && offLabel !== void 0 ? offLabel : " "
88
+ })]
68
89
  })]
69
90
  }), /*#__PURE__*/jsxRuntime.jsx(ErrorIcon.ErrorIcon, {
70
91
  invalid: invalid,
@@ -5,9 +5,11 @@ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
5
5
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
6
6
  var react = require('react');
7
7
  var InputWrapper = require('../internal/InputWrapper.js');
8
+ var eventHandlers = require('../utils/eventHandlers.js');
9
+ require('@react-fabric/utilities');
8
10
  var jsxRuntime = require('react/jsx-runtime');
9
11
 
10
- var _excluded = ["ref", "value", "name", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "rows", "maxRows", "variableRows", "onChange"];
12
+ var _excluded = ["ref", "value", "name", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "rows", "maxRows", "variableRows", "onChange", "onEnterPressed"];
11
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; }
12
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; }
13
15
  var Textarea = function Textarea(_ref) {
@@ -26,6 +28,7 @@ var Textarea = function Textarea(_ref) {
26
28
  maxRows = _ref$maxRows === void 0 ? 12 : _ref$maxRows,
27
29
  variableRows = _ref.variableRows,
28
30
  onChange = _ref.onChange,
31
+ onEnterPressed = _ref.onEnterPressed,
29
32
  rest = _objectWithoutProperties(_ref, _excluded);
30
33
  var _useState = react.useState(""),
31
34
  _useState2 = _slicedToArray(_useState, 2),
@@ -79,7 +82,8 @@ var Textarea = function Textarea(_ref) {
79
82
  autoComplete: "off",
80
83
  autoFocus: autoFocus,
81
84
  value: actualValue,
82
- onChange: handleChange
85
+ onChange: handleChange,
86
+ onKeyDown: eventHandlers.handleEnter(onEnterPressed)
83
87
  })
84
88
  }));
85
89
  };
@@ -217,15 +217,16 @@ var Select = function Select(_ref) {
217
217
  wrapperRef: refs.setReference,
218
218
  className: state.open ? "!z-[99]" : ""
219
219
  }, rest), {}, {
220
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
220
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
221
221
  role: "none",
222
222
  "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"),
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")
224
+ }, referenceProps), {}, {
224
225
  onMouseUp: function onMouseUp(e) {
225
226
  var _e$currentTarget$quer;
226
227
  return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
227
228
  },
228
- children: [displayValue, /*#__PURE__*/jsxRuntime.jsx("input", _objectSpread(_objectSpread({
229
+ children: [displayValue, /*#__PURE__*/jsxRuntime.jsx("input", {
229
230
  readOnly: !searchable || readOnly,
230
231
  disabled: disabled,
231
232
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
@@ -236,13 +237,12 @@ var Select = function Select(_ref) {
236
237
  ref: ref,
237
238
  autoFocus: autoFocus,
238
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"),
239
- placeholder: utilities.isEmpty(state.value) ? placeholder : ""
240
- }, referenceProps), {}, {
240
+ placeholder: utilities.isEmpty(state.value) ? placeholder : "",
241
241
  onChange: function onChange(evt) {
242
242
  return handleQuery(evt.target.value);
243
243
  }
244
- }))]
245
- }), !state.loading && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
244
+ })]
245
+ })), !state.loading && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
246
246
  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
247
  onClick: function onClick() {
248
248
  return !disabled && openDropdown();
@@ -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 (utilities.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;
@@ -206,7 +206,7 @@ var useSelect = function useSelect(_ref) {
206
206
  }
207
207
  if (multiple) {
208
208
  optionsRef.current = [];
209
- var _value = (deferred !== null && deferred !== void 0 ? deferred : []).map(function (item) {
209
+ var _value = (utilities.isArray(deferred) ? deferred : []).map(function (item) {
210
210
  var _ref5;
211
211
  var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
212
212
  var hasValue = options.find(function (opt) {
@@ -285,7 +285,11 @@ var useSelect = function useSelect(_ref) {
285
285
  value: value !== null && value !== void 0 && value.___create___ ? value.value : value
286
286
  });
287
287
  if (value !== null && value !== void 0 && value.___create___) {
288
- optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), [createOption(value.value)]);
288
+ var val = [value.value];
289
+ if (multiple) {
290
+ val = value.value.split(/,\s?/);
291
+ }
292
+ optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(val.map(createOption)));
289
293
  }
290
294
  if (autoComplete) {
291
295
  optionsRef.current = utilities.dedupe([].concat(_toConsumableArray(utilities.isArray(values) ? values : [values]), _toConsumableArray(optionsRef.current)));
@@ -35,6 +35,12 @@ var getBgClass = function getBgClass(bg) {
35
35
  return "bg-".concat(bg);
36
36
  }
37
37
  };
38
+ var getColorClass = function getColorClass(color) {
39
+ if (color && !utilities.isColor(color)) {
40
+ return "text-".concat(color);
41
+ }
42
+ };
38
43
 
39
44
  exports.getBgClass = getBgClass;
40
45
  exports.getColor = getColor;
46
+ exports.getColorClass = getColorClass;
@@ -89,13 +89,17 @@ var Form = function Form(_ref) {
89
89
  return form.getValues();
90
90
  },
91
91
  setValues: function setValues(v) {
92
- return form.reset(v);
92
+ return setTimeout(function () {
93
+ return form.reset(v);
94
+ }, 50);
93
95
  },
94
96
  setValue: function setValue(k, v) {
95
- return form.setValue(k, v, {
96
- shouldDirty: false,
97
- shouldTouch: false
98
- });
97
+ return setTimeout(function () {
98
+ return form.setValue(k, v, {
99
+ shouldDirty: false,
100
+ shouldTouch: false
101
+ });
102
+ }, 50);
99
103
  }
100
104
  };
101
105
  }, [onSubmit, form, form.formState, defaultValues]);
@@ -8,17 +8,18 @@ import classes from '../internal/Field.module.css';
8
8
  import { FieldWrapper } from '../internal/FieldWrapper.js';
9
9
  import { jsx } from 'react/jsx-runtime';
10
10
 
11
- var _excluded = ["children", "noOutline", "plain"];
11
+ var _excluded = ["children", "vertical", "noOutline", "plain"];
12
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; }
13
13
  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; }
14
14
  var Field = function Field(_ref) {
15
15
  var children = _ref.children,
16
+ vertical = _ref.vertical,
16
17
  noOutline = _ref.noOutline,
17
18
  plain = _ref.plain,
18
19
  rest = _objectWithoutProperties(_ref, _excluded);
19
20
  return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
20
21
  children: /*#__PURE__*/jsx("div", {
21
- className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex flex-nowrap flex-1 rounded"),
22
+ className: classNames(classes.fieldGroup, !plain && !noOutline && "outline", !plain && "bg-base", "flex-1 rounded", !vertical && "flex flex-nowrap"),
22
23
  children: Children.map(children, function (child) {
23
24
  return child && /*#__PURE__*/cloneElement(child, {
24
25
  "data-inner": true
@@ -6,13 +6,14 @@ import { Children, cloneElement } from 'react';
6
6
  import { FieldWrapper } from '../internal/FieldWrapper.js';
7
7
  import { jsx } from 'react/jsx-runtime';
8
8
 
9
- var _excluded = ["children", "name", "className", "onChange"];
9
+ var _excluded = ["children", "name", "className", "optionWidth", "onChange"];
10
10
  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
11
  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
12
  var RadioGroup = function RadioGroup(_ref) {
13
13
  var children = _ref.children,
14
14
  name = _ref.name,
15
15
  className = _ref.className,
16
+ optionWidth = _ref.optionWidth,
16
17
  onChange = _ref.onChange,
17
18
  rest = _objectWithoutProperties(_ref, _excluded);
18
19
  return /*#__PURE__*/jsx(FieldWrapper, _objectSpread(_objectSpread({}, rest), {}, {
@@ -21,7 +22,8 @@ var RadioGroup = function RadioGroup(_ref) {
21
22
  children: Children.map(children, function (child) {
22
23
  return /*#__PURE__*/cloneElement(child, {
23
24
  name: name,
24
- onChange: onChange
25
+ onChange: onChange,
26
+ width: optionWidth
25
27
  });
26
28
  })
27
29
  })
@@ -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,
@@ -5,9 +5,11 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
5
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
6
6
  import { useState, useDeferredValue, useRef, useEffect, useCallback } from 'react';
7
7
  import { InputWrapper } from '../internal/InputWrapper.js';
8
+ import { handleEnter } from '../utils/eventHandlers.js';
9
+ import '@react-fabric/utilities';
8
10
  import { jsx } from 'react/jsx-runtime';
9
11
 
10
- var _excluded = ["ref", "value", "name", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "rows", "maxRows", "variableRows", "onChange"];
12
+ var _excluded = ["ref", "value", "name", "invalid", "readOnly", "disabled", "required", "placeholder", "autoFocus", "rows", "maxRows", "variableRows", "onChange", "onEnterPressed"];
11
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; }
12
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; }
13
15
  var Textarea = function Textarea(_ref) {
@@ -26,6 +28,7 @@ var Textarea = function Textarea(_ref) {
26
28
  maxRows = _ref$maxRows === void 0 ? 12 : _ref$maxRows,
27
29
  variableRows = _ref.variableRows,
28
30
  onChange = _ref.onChange,
31
+ onEnterPressed = _ref.onEnterPressed,
29
32
  rest = _objectWithoutProperties(_ref, _excluded);
30
33
  var _useState = useState(""),
31
34
  _useState2 = _slicedToArray(_useState, 2),
@@ -79,7 +82,8 @@ var Textarea = function Textarea(_ref) {
79
82
  autoComplete: "off",
80
83
  autoFocus: autoFocus,
81
84
  value: actualValue,
82
- onChange: handleChange
85
+ onChange: handleChange,
86
+ onKeyDown: handleEnter(onEnterPressed)
83
87
  })
84
88
  }));
85
89
  };
@@ -217,15 +217,16 @@ var Select = function Select(_ref) {
217
217
  wrapperRef: refs.setReference,
218
218
  className: state.open ? "!z-[99]" : ""
219
219
  }, rest), {}, {
220
- children: [/*#__PURE__*/jsxs("div", {
220
+ children: [/*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
221
221
  role: "none",
222
222
  "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"),
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")
224
+ }, referenceProps), {}, {
224
225
  onMouseUp: function onMouseUp(e) {
225
226
  var _e$currentTarget$quer;
226
227
  return (_e$currentTarget$quer = e.currentTarget.querySelector("input")) === null || _e$currentTarget$quer === void 0 ? void 0 : _e$currentTarget$quer.focus();
227
228
  },
228
- children: [displayValue, /*#__PURE__*/jsx("input", _objectSpread(_objectSpread({
229
+ children: [displayValue, /*#__PURE__*/jsx("input", {
229
230
  readOnly: !searchable || readOnly,
230
231
  disabled: disabled,
231
232
  value: (_state$query = state.query) !== null && _state$query !== void 0 ? _state$query : "",
@@ -236,13 +237,12 @@ var Select = function Select(_ref) {
236
237
  ref: ref,
237
238
  autoFocus: autoFocus,
238
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"),
239
- placeholder: isEmpty(state.value) ? placeholder : ""
240
- }, referenceProps), {}, {
240
+ placeholder: isEmpty(state.value) ? placeholder : "",
241
241
  onChange: function onChange(evt) {
242
242
  return handleQuery(evt.target.value);
243
243
  }
244
- }))]
245
- }), !state.loading && /*#__PURE__*/jsx(Icon, {
244
+ })]
245
+ })), !state.loading && /*#__PURE__*/jsx(Icon, {
246
246
  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
247
  onClick: function onClick() {
248
248
  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, 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;
@@ -206,7 +206,7 @@ var useSelect = function useSelect(_ref) {
206
206
  }
207
207
  if (multiple) {
208
208
  optionsRef.current = [];
209
- var _value = (deferred !== null && deferred !== void 0 ? deferred : []).map(function (item) {
209
+ var _value = (isArray(deferred) ? deferred : []).map(function (item) {
210
210
  var _ref5;
211
211
  var newOption = (allowCreate || autoComplete) && item ? createOption(item) : undefined;
212
212
  var hasValue = options.find(function (opt) {
@@ -285,7 +285,11 @@ var useSelect = function useSelect(_ref) {
285
285
  value: value !== null && value !== void 0 && value.___create___ ? value.value : value
286
286
  });
287
287
  if (value !== null && value !== void 0 && value.___create___) {
288
- optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), [createOption(value.value)]);
288
+ var val = [value.value];
289
+ if (multiple) {
290
+ val = value.value.split(/,\s?/);
291
+ }
292
+ optionsRef.current = [].concat(_toConsumableArray(optionsRef.current), _toConsumableArray(val.map(createOption)));
289
293
  }
290
294
  if (autoComplete) {
291
295
  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 };
@@ -60,5 +60,17 @@ export interface ArrayInputProps {
60
60
  * Add item
61
61
  */
62
62
  onAdd?: () => AnyObject;
63
+ /**
64
+ * field width
65
+ */
66
+ width?: number | string;
67
+ /**
68
+ * inline label and input
69
+ */
70
+ inline?: boolean;
71
+ /**
72
+ * label width for inline
73
+ */
74
+ labelWidth?: string;
63
75
  }
64
76
  export declare const ArrayInput: ({ name, children, addLabel, fixedList, focusName, onAdd, arrayRef, enableSorting, disabled, readOnly, minItems, ...rest }: ArrayInputProps) => import("react/jsx-runtime").JSX.Element;
@@ -37,5 +37,6 @@ export interface FieldProps extends ChildrenProp, CssProp {
37
37
  * dont apply bg and outline
38
38
  */
39
39
  plain?: boolean;
40
+ vertical?: boolean;
40
41
  }
41
- export declare const Field: ({ children, noOutline, plain, ...rest }: FieldProps) => import("react/jsx-runtime").JSX.Element;
42
+ export declare const Field: ({ children, vertical, noOutline, plain, ...rest }: FieldProps) => 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;
@@ -1,6 +1,6 @@
1
1
  import { type RefProp } from "@react-fabric/core/dist/types/types";
2
2
  import { type InputProps } from "../types";
3
- export interface TextareaProps extends Omit<InputProps, "onEnterPressed">, RefProp<HTMLTextAreaElement> {
3
+ export interface TextareaProps extends InputProps, RefProp<HTMLTextAreaElement> {
4
4
  /**
5
5
  * textarae rows
6
6
  */
@@ -14,4 +14,4 @@ export interface TextareaProps extends Omit<InputProps, "onEnterPressed">, RefPr
14
14
  */
15
15
  variableRows?: boolean;
16
16
  }
17
- export declare const Textarea: ({ ref, value, name, invalid, readOnly, disabled, required, placeholder, autoFocus, rows, maxRows, variableRows, onChange, ...rest }: TextareaProps) => import("react/jsx-runtime").JSX.Element;
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;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { type RefProp } from "@react-fabric/core/dist/types/types";
3
- export interface InputProps<V = string> {
2
+ import { type RefProp, type TestProps } from "@react-fabric/core/dist/types/types";
3
+ export interface InputProps<V = string> extends TestProps {
4
4
  /**
5
5
  * value
6
6
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/form",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "RUF: Form package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -39,8 +39,8 @@
39
39
  "@dnd-kit/utilities": "^3.2.2",
40
40
  "@floating-ui/react": "0.26.24",
41
41
  "@hookform/resolvers": "^3.9.0",
42
- "@react-fabric/core": "^1.0.0-beta.1",
43
- "@react-fabric/utilities": "^1.0.0-beta.1",
42
+ "@react-fabric/core": "^1.0.0-beta.12",
43
+ "@react-fabric/utilities": "^1.0.0-beta.12",
44
44
  "classnames": "^2.5.1",
45
45
  "color": "^4.2.3",
46
46
  "react-color": "^2.19.3",
@@ -60,5 +60,5 @@
60
60
  "node": ">=18.12.0",
61
61
  "npm": ">=8.19.0"
62
62
  },
63
- "gitHead": "e0712d7ea2c945de876bef813b5d2dcec1218ed7"
63
+ "gitHead": "7f5a400622fb0266331b527b2078d4dc6886c95e"
64
64
  }
package/src/form/Form.tsx CHANGED
@@ -118,12 +118,16 @@ export const Form = <K extends KeyValue>({
118
118
  submit: () => form.handleSubmit(onSubmit),
119
119
  validate: async () => await form.trigger(),
120
120
  getValues: () => form.getValues(),
121
- setValues: (v) => form.reset(v),
121
+ setValues: (v) => setTimeout(() => form.reset(v), 50),
122
122
  setValue: (k, v) =>
123
- form.setValue(k as AnyObject, v, {
124
- shouldDirty: false,
125
- shouldTouch: false,
126
- }),
123
+ setTimeout(
124
+ () =>
125
+ form.setValue(k as AnyObject, v, {
126
+ shouldDirty: false,
127
+ shouldTouch: false,
128
+ }),
129
+ 50,
130
+ ),
127
131
  }),
128
132
  [onSubmit, form, form.formState, defaultValues],
129
133
  );
@@ -104,6 +104,19 @@ export interface ArrayInputProps {
104
104
  * Add item
105
105
  */
106
106
  onAdd?: () => AnyObject;
107
+
108
+ /**
109
+ * field width
110
+ */
111
+ width?: number | string;
112
+ /**
113
+ * inline label and input
114
+ */
115
+ inline?: boolean;
116
+ /**
117
+ * label width for inline
118
+ */
119
+ labelWidth?: string;
107
120
  }
108
121
 
109
122
  export const ArrayInput = ({
@@ -69,9 +69,16 @@ export interface FieldProps extends ChildrenProp, CssProp {
69
69
  * dont apply bg and outline
70
70
  */
71
71
  plain?: boolean;
72
+ vertical?: boolean;
72
73
  }
73
74
 
74
- export const Field = ({ children, noOutline, plain, ...rest }: FieldProps) => {
75
+ export const Field = ({
76
+ children,
77
+ vertical,
78
+ noOutline,
79
+ plain,
80
+ ...rest
81
+ }: FieldProps) => {
75
82
  return (
76
83
  <FieldWrapper {...rest}>
77
84
  <div
@@ -79,7 +86,8 @@ export const Field = ({ children, noOutline, plain, ...rest }: FieldProps) => {
79
86
  classes.fieldGroup,
80
87
  !plain && !noOutline && "outline",
81
88
  !plain && "bg-base",
82
- "flex flex-nowrap flex-1 rounded",
89
+ "flex-1 rounded",
90
+ !vertical && "flex flex-nowrap",
83
91
  )}
84
92
  >
85
93
  {Children.map(
@@ -22,8 +22,8 @@
22
22
  */
23
23
 
24
24
  import {
25
- type CssProp,
26
25
  type ChildrenProp,
26
+ type CssProp,
27
27
  } from "@react-fabric/core/dist/types/types";
28
28
  import { Children, cloneElement } from "react";
29
29
  import { FieldWrapper } from "../internal/FieldWrapper";
@@ -42,6 +42,23 @@ export interface RadioGroupProps extends ChildrenProp<typeof Radio>, CssProp {
42
42
  * field info
43
43
  */
44
44
  info?: string;
45
+
46
+ /**
47
+ * field width
48
+ */
49
+ width?: number | string;
50
+ /**
51
+ * inline label and input
52
+ */
53
+ inline?: boolean;
54
+ /**
55
+ * label width for inline
56
+ */
57
+ labelWidth?: string;
58
+ /**
59
+ * label width for inline
60
+ */
61
+ optionWidth?: string;
45
62
  /**
46
63
  * field name
47
64
  */
@@ -60,6 +77,7 @@ export const RadioGroup = ({
60
77
  children,
61
78
  name,
62
79
  className,
80
+ optionWidth,
63
81
  onChange,
64
82
  ...rest
65
83
  }: RadioGroupProps) => {
@@ -67,7 +85,11 @@ export const RadioGroup = ({
67
85
  <FieldWrapper {...rest}>
68
86
  <div className={className}>
69
87
  {Children.map(children, (child) =>
70
- cloneElement(child as AnyObject, { name, onChange }),
88
+ cloneElement(child as AnyObject, {
89
+ name,
90
+ onChange,
91
+ width: optionWidth,
92
+ }),
71
93
  )}
72
94
  </div>
73
95
  </FieldWrapper>
@@ -27,6 +27,7 @@ import {
27
27
  } from "@react-fabric/core/dist/types/types";
28
28
  import classNames from "classnames";
29
29
  import {
30
+ Fragment,
30
31
  useCallback,
31
32
  useDeferredValue,
32
33
  useEffect,
@@ -34,7 +35,7 @@ import {
34
35
  type ChangeEvent,
35
36
  } from "react";
36
37
  import { ErrorIcon } from "../internal/ErrorIcon";
37
- import { getBgClass, getColor } from "../utils";
38
+ import { getBgClass, getColor, getColorClass } from "../utils";
38
39
 
39
40
  export interface SwitchProps extends RefProp<HTMLInputElement> {
40
41
  /**
@@ -71,13 +72,19 @@ export interface SwitchProps extends RefProp<HTMLInputElement> {
71
72
  /**
72
73
  * cutom Switch icon
73
74
  */
74
- color?: ColorType;
75
+ color?: string | ColorType;
75
76
  /**
76
77
  * cutom Switch icon
77
78
  */
78
- defaultColor?: ColorType;
79
+ defaultColor?: string | ColorType;
79
80
 
80
81
  name?: string;
82
+
83
+ onLabel?: string;
84
+ onLabelColor?: string | ColorType;
85
+
86
+ offLabel?: string;
87
+ offLabelColor?: string | ColorType;
81
88
  }
82
89
 
83
90
  export const Switch = ({
@@ -90,6 +97,10 @@ export const Switch = ({
90
97
  width,
91
98
  color,
92
99
  name,
100
+ onLabel,
101
+ offLabel,
102
+ onLabelColor,
103
+ offLabelColor,
93
104
  defaultColor,
94
105
  onChange,
95
106
  ...rest
@@ -125,7 +136,7 @@ export const Switch = ({
125
136
  actualValue && getBgClass(color ? `${color}-500` : "primary-500"),
126
137
  !actualValue &&
127
138
  (defaultColor ? getBgClass(`${defaultColor}-500`) : "bg-tint-200"),
128
- "relative flex h-6 w-10 cursor-pointer rounded-full p-1 transition-colors duration-200 ease-in-out",
139
+ "relative grid grid-cols-2 items-center h-6 min-w-10 cursor-pointer rounded-full p-1 transition-colors duration-200 ease-in-out",
129
140
  )}
130
141
  style={{
131
142
  backgroundColor: actualValue
@@ -154,10 +165,33 @@ export const Switch = ({
154
165
  aria-hidden="true"
155
166
  className={classNames(
156
167
  !disabled && "shadow-sm",
157
- actualValue ? "translate-x-4" : "translate-x-0",
158
- "pointer-events-none inline-block size-4 rounded-full bg-white ring-0 transition duration-200 ease-in-out",
168
+ actualValue ? "translate-x-[100%]" : "translate-x-0",
169
+ "pointer-events-none inline-block h-4 start-1 absolute rounded-full bg-white ring-0 transition duration-200 ease-in-out",
159
170
  )}
171
+ style={{
172
+ width: "calc(50% - 0.25rem)",
173
+ }}
160
174
  />
175
+ {(!!onLabel || !!offLabel) && (
176
+ <Fragment>
177
+ <span
178
+ className={`whitespace-nowrap text-xs px-1 ${getColorClass(onLabelColor ?? "white")}`}
179
+ style={{
180
+ color: getColor(onLabelColor),
181
+ }}
182
+ >
183
+ {onLabel ?? " "}
184
+ </span>
185
+ <span
186
+ className={`whitespace-nowrap text-xs px-1 ${getColorClass(offLabelColor ?? "base")}`}
187
+ style={{
188
+ color: getColor(offLabelColor),
189
+ }}
190
+ >
191
+ {offLabel ?? " "}
192
+ </span>
193
+ </Fragment>
194
+ )}
161
195
  </div>
162
196
  <ErrorIcon invalid={invalid} error={error} />
163
197
  {label && (
@@ -32,9 +32,10 @@ import {
32
32
  } from "react";
33
33
  import { InputWrapper } from "../internal/InputWrapper";
34
34
  import { type InputProps } from "../types";
35
+ import { handleEnter } from "../utils";
35
36
 
36
37
  export interface TextareaProps
37
- extends Omit<InputProps, "onEnterPressed">,
38
+ extends InputProps,
38
39
  RefProp<HTMLTextAreaElement> {
39
40
  /**
40
41
  * textarae rows
@@ -64,6 +65,7 @@ export const Textarea = ({
64
65
  maxRows = 12,
65
66
  variableRows,
66
67
  onChange,
68
+ onEnterPressed,
67
69
  ...rest
68
70
  }: TextareaProps) => {
69
71
  const [actualValue, setActualValue] = useState("");
@@ -121,6 +123,7 @@ export const Textarea = ({
121
123
  {...{ autoFocus }}
122
124
  value={actualValue}
123
125
  onChange={handleChange}
126
+ onKeyDown={handleEnter(onEnterPressed)}
124
127
  />
125
128
  </InputWrapper>
126
129
  );
@@ -273,6 +273,7 @@ export const Select = <T extends AnyObject = string>({
273
273
  "group flex-1 py-1 px-2 truncate text-start flex gap-1 relative min-h-5 justify-start",
274
274
  multiple ? "flex-wrap" : "flex-nowrap overflow-hidden",
275
275
  )}
276
+ {...referenceProps}
276
277
  onMouseUp={(e) =>
277
278
  e.currentTarget.querySelector<HTMLElement>("input")?.focus()
278
279
  }
@@ -294,7 +295,6 @@ export const Select = <T extends AnyObject = string>({
294
295
  multiple && "min-w-24",
295
296
  )}
296
297
  placeholder={isEmpty(state.value) ? placeholder : ""}
297
- {...referenceProps}
298
298
  onChange={(evt) => handleQuery(evt.target.value)}
299
299
  />
300
300
  </div>
@@ -27,6 +27,7 @@ import {
27
27
  EMPTY_ARRAY,
28
28
  groupBy,
29
29
  isArray,
30
+ isString,
30
31
  matchString,
31
32
  } from "@react-fabric/utilities";
32
33
  import {
@@ -173,9 +174,9 @@ export const useSelect = ({
173
174
  if (action.value !== undefined) {
174
175
  if (multiple) {
175
176
  const values = [];
176
- if (action.value && autoComplete)
177
+ if (isString(action.value))
177
178
  values.push(...action.value.split(/,\s?/));
178
- else if (action.value) values.push(action.value);
179
+ else values.push(action.value);
179
180
  newState.value = [...state.value];
180
181
  values.forEach((value: AnyObject) => {
181
182
  newState.value = newState.value.includes?.(value)
@@ -287,19 +288,21 @@ export const useSelect = ({
287
288
  }
288
289
  if (multiple) {
289
290
  optionsRef.current = [];
290
- const value = (deferred ?? []).map((item: AnyObject) => {
291
- const newOption =
292
- (allowCreate || autoComplete) && item
293
- ? createOption(item)
294
- : undefined;
295
- const hasValue = options.find(
296
- (opt: AnyObject) => (opt[valueProperty] ?? opt) === deferred,
297
- );
298
- if (!hasValue && newOption) {
299
- optionsRef.current.push(newOption);
300
- }
301
- return hasValue ?? newOption ?? "";
302
- });
291
+ const value = (isArray(deferred) ? deferred : []).map(
292
+ (item: AnyObject) => {
293
+ const newOption =
294
+ (allowCreate || autoComplete) && item
295
+ ? createOption(item)
296
+ : undefined;
297
+ const hasValue = options.find(
298
+ (opt: AnyObject) => (opt[valueProperty] ?? opt) === deferred,
299
+ );
300
+ if (!hasValue && newOption) {
301
+ optionsRef.current.push(newOption);
302
+ }
303
+ return hasValue ?? newOption ?? "";
304
+ },
305
+ );
303
306
  optionsRef.current = [...optionsRef.current, ...(options ?? [])];
304
307
  dispatch({ type: "options", options: optionsRef.current });
305
308
  dispatch({
@@ -367,7 +370,11 @@ export const useSelect = ({
367
370
  value: value?.___create___ ? value.value : value,
368
371
  });
369
372
  if (value?.___create___) {
370
- optionsRef.current = [...optionsRef.current, createOption(value.value)];
373
+ let val = [value.value];
374
+ if (multiple) {
375
+ val = value.value.split(/,\s?/);
376
+ }
377
+ optionsRef.current = [...optionsRef.current, ...val.map(createOption)];
371
378
  }
372
379
  if (autoComplete) {
373
380
  optionsRef.current = dedupe([
@@ -21,9 +21,12 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import { type RefProp } from "@react-fabric/core/dist/types/types";
24
+ import {
25
+ type RefProp,
26
+ type TestProps,
27
+ } from "@react-fabric/core/dist/types/types";
25
28
 
26
- export interface InputProps<V = string> {
29
+ export interface InputProps<V = string> extends TestProps {
27
30
  /**
28
31
  * value
29
32
  */