colibri-ui 0.8.83 → 0.8.86

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 (249) hide show
  1. package/Accordion/Accordion.module.css +4 -0
  2. package/Accordion/index.js +15 -23
  3. package/Autocomplete/Autocomplete.js +101 -132
  4. package/Avatar/Avatar.module.css +6 -0
  5. package/Avatar/index.js +102 -89
  6. package/Badge/Badge.module.css +2 -1
  7. package/Badge/Control/index.js +5 -3
  8. package/Badge/index.js +16 -16
  9. package/Button/index.js +23 -20
  10. package/Button/tokens.js +2 -2
  11. package/Calendar/Calendar.js +171 -269
  12. package/Card/Card.js +26 -32
  13. package/Checkbox/index.js +46 -43
  14. package/Chip/Chip.module.css +2 -1
  15. package/Chip/index.js +15 -15
  16. package/ClickOutside/index.js +10 -13
  17. package/CodeField/CodeField.js +113 -170
  18. package/Counter/Counter.module.css +2 -1
  19. package/Counter/index.js +21 -20
  20. package/Datepicker/components/DatePicker/index.js +81 -102
  21. package/Datepicker/index.js +17 -16
  22. package/DotsLoader/index.js +23 -15
  23. package/Drawer/Drawer.js +75 -97
  24. package/Drawer/Drawer.module.css +2 -1
  25. package/Dropdown/index.js +55 -68
  26. package/Dropzone/Dropzone.js +78 -168
  27. package/Dropzone/Dropzone.module.css +2 -1
  28. package/Editable/Editable.js +44 -57
  29. package/Grid/Item/index.js +11 -13
  30. package/Grid/index.js +15 -21
  31. package/Icons/ArrowNext.js +7 -8
  32. package/Icons/Cart.js +7 -8
  33. package/Icons/Check.js +7 -8
  34. package/Icons/Chevron.js +7 -8
  35. package/Icons/Close.js +6 -6
  36. package/Icons/Copy.js +7 -8
  37. package/Icons/Cross.js +6 -6
  38. package/Icons/CrossFill.js +7 -8
  39. package/Icons/Edit.js +7 -8
  40. package/Icons/Exit.js +7 -8
  41. package/Icons/EyeClosed.js +7 -8
  42. package/Icons/EyeOpen.js +7 -8
  43. package/Icons/Help.js +6 -6
  44. package/Icons/Info.js +7 -8
  45. package/Icons/Minus.js +7 -8
  46. package/Icons/More.js +7 -8
  47. package/Icons/Plus.js +7 -8
  48. package/Icons/Setting.js +7 -8
  49. package/Icons/Shield.js +7 -8
  50. package/Icons/Trash.js +7 -8
  51. package/Icons/User.js +7 -8
  52. package/Image/Image.module.css +4 -0
  53. package/Image/index.d.ts +1 -1
  54. package/Image/index.js +44 -37
  55. package/Input/index.d.ts +1 -1
  56. package/Input/index.js +38 -25
  57. package/Input/index.props.d.ts +1 -1
  58. package/InputRadio/index.js +32 -24
  59. package/List/List.js +81 -76
  60. package/Menu/Menu.module.css +2 -1
  61. package/Menu/components/MenuItem/index.js +17 -14
  62. package/Menu/index.js +22 -23
  63. package/Modal/components/Body/index.js +9 -8
  64. package/Modal/components/Close/Close.module.css +4 -0
  65. package/Modal/components/Close/index.js +13 -14
  66. package/Modal/components/Content/index.js +5 -6
  67. package/Modal/components/Footer/index.js +5 -3
  68. package/Modal/components/Header/index.js +13 -12
  69. package/Modal/components/Title/index.js +10 -9
  70. package/Modal/context.js +3 -3
  71. package/Modal/index.js +46 -68
  72. package/MultiSelect/components/MenuOverlay/index.js +48 -61
  73. package/MultiSelect/components/MenuOverlayItem/index.js +13 -14
  74. package/MultiSelect/index.js +72 -100
  75. package/MultiSelect/index.module.css +2 -1
  76. package/MultiSelect/utils/index.js +8 -18
  77. package/NumberInput/NumberInput.js +80 -112
  78. package/Portal/index.js +6 -10
  79. package/Progress/Progress.js +45 -58
  80. package/RadioGroup/Radio.js +29 -32
  81. package/RadioGroup/index.js +43 -46
  82. package/Rating/Rating.js +50 -63
  83. package/Select/components/MenuOverlay/index.js +16 -25
  84. package/Select/components/MenuOverlayItem/index.js +13 -11
  85. package/Select/index.js +39 -48
  86. package/Select/index.module.css +2 -1
  87. package/Separator/index.js +5 -6
  88. package/Sheet/Sheet.js +89 -121
  89. package/Sheet/Sheet.module.css +4 -2
  90. package/Skeleton/index.js +25 -30
  91. package/Slider/Slider.js +83 -119
  92. package/Status/index.js +17 -18
  93. package/Switch/Switch.module.css +2 -1
  94. package/Switch/index.js +22 -15
  95. package/TabsMenu/Tab/Tab.js +14 -10
  96. package/TabsMenu/Tab/Tab.module.css +2 -1
  97. package/TabsMenu/index.js +25 -26
  98. package/TabsPanels/Panel/index.js +6 -4
  99. package/TabsPanels/index.js +13 -10
  100. package/TextArea/index.d.ts +1 -1
  101. package/TextArea/index.js +31 -19
  102. package/Theme/breakpoints.js +5 -11
  103. package/Theme/colors/theme_buenos_aires.js +14 -14
  104. package/Theme/colors/theme_jaipur.js +14 -14
  105. package/Theme/global.css +0 -1
  106. package/Theme/index.js +1 -1
  107. package/TimeSelect/Label/index.js +11 -13
  108. package/TimeSelect/helpers.js +23 -42
  109. package/TimeSelect/index.js +32 -38
  110. package/Tooltip/index.js +36 -42
  111. package/Typography/index.js +17 -13
  112. package/Typography/index.props.d.ts +3 -0
  113. package/base/BaseInput/index.js +10 -8
  114. package/base/FormField/index.d.ts +1 -1
  115. package/base/FormField/index.js +27 -22
  116. package/base/FormField/index.props.d.ts +4 -0
  117. package/base/InputRoot/index.js +27 -27
  118. package/esm/Accordion/Accordion.module.css +4 -0
  119. package/esm/Accordion/index.js +15 -21
  120. package/esm/Autocomplete/Autocomplete.js +101 -130
  121. package/esm/Avatar/Avatar.module.css +6 -0
  122. package/esm/Avatar/index.js +102 -88
  123. package/esm/Badge/Badge.module.css +2 -1
  124. package/esm/Badge/Control/index.js +5 -3
  125. package/esm/Badge/index.js +16 -15
  126. package/esm/Button/index.js +23 -19
  127. package/esm/Button/tokens.js +2 -2
  128. package/esm/Calendar/Calendar.js +171 -267
  129. package/esm/Card/Card.js +26 -32
  130. package/esm/Checkbox/index.js +46 -42
  131. package/esm/Chip/Chip.module.css +2 -1
  132. package/esm/Chip/index.js +15 -14
  133. package/esm/ClickOutside/index.js +10 -13
  134. package/esm/CodeField/CodeField.js +113 -169
  135. package/esm/Counter/Counter.module.css +2 -1
  136. package/esm/Counter/index.js +21 -19
  137. package/esm/Datepicker/components/DatePicker/index.js +81 -101
  138. package/esm/Datepicker/index.js +17 -16
  139. package/esm/DotsLoader/index.js +23 -14
  140. package/esm/Drawer/Drawer.js +75 -96
  141. package/esm/Drawer/Drawer.module.css +2 -1
  142. package/esm/Dropdown/index.js +55 -66
  143. package/esm/Dropzone/Dropzone.js +78 -165
  144. package/esm/Dropzone/Dropzone.module.css +2 -1
  145. package/esm/Editable/Editable.js +44 -56
  146. package/esm/Grid/Item/index.js +11 -12
  147. package/esm/Grid/index.js +15 -21
  148. package/esm/Icons/ArrowNext.js +7 -8
  149. package/esm/Icons/Cart.js +7 -8
  150. package/esm/Icons/Check.js +7 -8
  151. package/esm/Icons/Chevron.js +7 -8
  152. package/esm/Icons/Close.js +6 -6
  153. package/esm/Icons/Copy.js +7 -8
  154. package/esm/Icons/Cross.js +6 -6
  155. package/esm/Icons/CrossFill.js +7 -8
  156. package/esm/Icons/Edit.js +7 -8
  157. package/esm/Icons/Exit.js +7 -8
  158. package/esm/Icons/EyeClosed.js +7 -8
  159. package/esm/Icons/EyeOpen.js +7 -8
  160. package/esm/Icons/Help.js +6 -6
  161. package/esm/Icons/Info.js +7 -8
  162. package/esm/Icons/Minus.js +7 -8
  163. package/esm/Icons/More.js +7 -8
  164. package/esm/Icons/Plus.js +7 -8
  165. package/esm/Icons/Setting.js +7 -8
  166. package/esm/Icons/Shield.js +7 -8
  167. package/esm/Icons/Trash.js +7 -8
  168. package/esm/Icons/User.js +7 -8
  169. package/esm/Image/Image.module.css +4 -0
  170. package/esm/Image/index.d.ts +1 -1
  171. package/esm/Image/index.js +44 -36
  172. package/esm/Input/index.d.ts +1 -1
  173. package/esm/Input/index.js +39 -26
  174. package/esm/Input/index.props.d.ts +1 -1
  175. package/esm/InputRadio/index.js +32 -23
  176. package/esm/List/List.js +81 -75
  177. package/esm/Menu/Menu.module.css +2 -1
  178. package/esm/Menu/components/MenuItem/index.js +17 -13
  179. package/esm/Menu/index.js +22 -23
  180. package/esm/Modal/components/Body/index.js +9 -7
  181. package/esm/Modal/components/Close/Close.module.css +4 -0
  182. package/esm/Modal/components/Close/index.js +13 -14
  183. package/esm/Modal/components/Content/index.js +5 -6
  184. package/esm/Modal/components/Footer/index.js +5 -3
  185. package/esm/Modal/components/Header/index.js +13 -11
  186. package/esm/Modal/components/Title/index.js +10 -9
  187. package/esm/Modal/context.js +3 -3
  188. package/esm/Modal/index.js +50 -70
  189. package/esm/MultiSelect/components/MenuOverlay/index.js +48 -60
  190. package/esm/MultiSelect/components/MenuOverlayItem/index.js +13 -14
  191. package/esm/MultiSelect/index.js +72 -97
  192. package/esm/MultiSelect/index.module.css +2 -1
  193. package/esm/MultiSelect/utils/index.js +8 -14
  194. package/esm/NumberInput/NumberInput.js +80 -111
  195. package/esm/Portal/index.js +6 -9
  196. package/esm/Progress/Progress.js +45 -58
  197. package/esm/RadioGroup/Radio.js +29 -32
  198. package/esm/RadioGroup/index.js +43 -45
  199. package/esm/Rating/Rating.js +50 -63
  200. package/esm/Select/components/MenuOverlay/index.js +16 -24
  201. package/esm/Select/components/MenuOverlayItem/index.js +13 -11
  202. package/esm/Select/index.js +39 -46
  203. package/esm/Select/index.module.css +2 -1
  204. package/esm/Separator/index.js +5 -6
  205. package/esm/Sheet/Sheet.js +89 -119
  206. package/esm/Sheet/Sheet.module.css +4 -2
  207. package/esm/Skeleton/index.js +25 -30
  208. package/esm/Slider/Slider.js +83 -119
  209. package/esm/Status/index.js +17 -17
  210. package/esm/Switch/Switch.module.css +2 -1
  211. package/esm/Switch/index.js +22 -14
  212. package/esm/TabsMenu/Tab/Tab.js +14 -9
  213. package/esm/TabsMenu/Tab/Tab.module.css +2 -1
  214. package/esm/TabsMenu/index.js +25 -26
  215. package/esm/TabsPanels/Panel/index.js +6 -4
  216. package/esm/TabsPanels/index.js +13 -10
  217. package/esm/TextArea/index.d.ts +1 -1
  218. package/esm/TextArea/index.js +32 -20
  219. package/esm/Theme/breakpoints.js +5 -11
  220. package/esm/Theme/colors/theme_buenos_aires.js +14 -14
  221. package/esm/Theme/colors/theme_jaipur.js +14 -14
  222. package/esm/Theme/global.css +0 -1
  223. package/esm/Theme/index.js +1 -1
  224. package/esm/TimeSelect/Label/index.js +11 -13
  225. package/esm/TimeSelect/helpers.js +22 -37
  226. package/esm/TimeSelect/index.js +32 -38
  227. package/esm/Tooltip/index.js +36 -41
  228. package/esm/Typography/index.js +17 -12
  229. package/esm/Typography/index.props.d.ts +3 -0
  230. package/esm/base/BaseInput/index.js +10 -8
  231. package/esm/base/FormField/index.d.ts +1 -1
  232. package/esm/base/FormField/index.js +27 -21
  233. package/esm/base/FormField/index.props.d.ts +4 -0
  234. package/esm/base/InputRoot/index.js +27 -26
  235. package/esm/helpers/date/index.js +4 -8
  236. package/esm/hooks/useMediaSizes/index.js +9 -15
  237. package/esm/hooks/useModalStack/index.js +6 -9
  238. package/esm/hooks/useOnClickOutside/index.js +6 -6
  239. package/esm/hooks/useScrollLock/index.js +10 -9
  240. package/esm/hooks/useTrapFocus/index.js +8 -10
  241. package/esm/lib/keyboard.js +2 -4
  242. package/helpers/date/index.js +21 -32
  243. package/hooks/useMediaSizes/index.js +9 -15
  244. package/hooks/useModalStack/index.js +6 -9
  245. package/hooks/useOnClickOutside/index.js +6 -6
  246. package/hooks/useScrollLock/index.js +10 -9
  247. package/hooks/useTrapFocus/index.js +8 -10
  248. package/lib/keyboard.js +2 -4
  249. package/package.json +5 -1
@@ -1,174 +1,127 @@
1
1
  'use strict';
2
2
 
3
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
3
  var tslib = require('tslib');
5
4
  var React = require('react');
6
5
  var styles = require('./CodeField.module.css');
7
6
 
8
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
8
 
10
- var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
11
9
  var React__default = /*#__PURE__*/_interopDefault(React);
12
10
  var styles__default = /*#__PURE__*/_interopDefault(styles);
13
11
 
14
- var ONLY_DIGITS_PATTERN = "^\\d+$";
15
- var ONLY_CHARS_PATTERN = "^[a-zA-Z]+$";
16
- var ONLY_DIGITS_AND_CHARS_PATTERN = "^[a-zA-Z0-9]+$";
17
- var cx = function cx() {
18
- for (var _len = arguments.length, classNames = new Array(_len), _key = 0; _key < _len; _key++) {
19
- classNames[_key] = arguments[_key];
20
- }
21
- return classNames.filter(Boolean).join(" ");
22
- };
23
- var getPattern = function getPattern(pattern) {
24
- return typeof pattern === "string" ? new RegExp(pattern) : pattern;
25
- };
26
- var testSymbol = function testSymbol(pattern, symbol) {
12
+ const ONLY_DIGITS_PATTERN = "^\\d+$";
13
+ const ONLY_CHARS_PATTERN = "^[a-zA-Z]+$";
14
+ const ONLY_DIGITS_AND_CHARS_PATTERN = "^[a-zA-Z0-9]+$";
15
+ const cx = (...classNames) => classNames.filter(Boolean).join(" ");
16
+ const getPattern = pattern => typeof pattern === "string" ? new RegExp(pattern) : pattern;
17
+ const testSymbol = (pattern, symbol) => {
27
18
  pattern.lastIndex = 0;
28
19
  return pattern.test(symbol);
29
20
  };
30
- var getPlaceholder = function getPlaceholder(placeholder, length) {
21
+ const getPlaceholder = (placeholder, length) => {
31
22
  if (!placeholder) return [];
32
23
  return placeholder.length === 1 ? Array(length).fill(placeholder) : placeholder.slice(0, length).split("");
33
24
  };
34
- var CodeField = /*#__PURE__*/React.forwardRef(function CodeFieldComponent(_a, forwardedRef) {
25
+ const CodeField = /*#__PURE__*/React.forwardRef(function CodeFieldComponent(_a, forwardedRef) {
35
26
  var _b;
36
- var value = _a.value,
37
- placeholder = _a.placeholder,
38
- _a$codeLength = _a.codeLength,
39
- codeLength = _a$codeLength === void 0 ? 6 : _a$codeLength,
40
- caption = _a.caption,
41
- _a$captionAlign = _a.captionAlign,
42
- captionAlign = _a$captionAlign === void 0 ? "left" : _a$captionAlign,
43
- width = _a.width,
44
- _a$view = _a.view,
45
- view = _a$view === void 0 ? "default" : _a$view,
46
- _a$shape = _a.shape,
47
- shape = _a$shape === void 0 ? "default" : _a$shape,
48
- _a$size = _a.size,
49
- size = _a$size === void 0 ? "l" : _a$size,
50
- _a$disabled = _a.disabled,
51
- disabled = _a$disabled === void 0 ? false : _a$disabled,
52
- _a$isError = _a.isError,
53
- isError = _a$isError === void 0 ? false : _a$isError,
54
- setIsError = _a.setIsError,
55
- _a$allowedSymbols = _a.allowedSymbols,
56
- allowedSymbols = _a$allowedSymbols === void 0 ? ONLY_DIGITS_PATTERN : _a$allowedSymbols,
57
- _a$itemErrorBehavior = _a.itemErrorBehavior,
58
- itemErrorBehavior = _a$itemErrorBehavior === void 0 ? "remove-symbol" : _a$itemErrorBehavior,
59
- _a$codeErrorBehavior = _a.codeErrorBehavior,
60
- codeErrorBehavior = _a$codeErrorBehavior === void 0 ? "remove-code" : _a$codeErrorBehavior,
61
- _a$autoComplete = _a.autoComplete,
62
- autoComplete = _a$autoComplete === void 0 ? "one-time-code" : _a$autoComplete,
63
- _a$inputMode = _a.inputMode,
64
- inputMode = _a$inputMode === void 0 ? "numeric" : _a$inputMode,
65
- autoFocus = _a.autoFocus,
66
- className = _a.className,
67
- style = _a.style,
68
- onChange = _a.onChange,
69
- onFullCodeEnter = _a.onFullCodeEnter,
70
- onClick = _a.onClick,
71
- _onFocus = _a.onFocus,
72
- _onBlur = _a.onBlur,
73
- _onSelect = _a.onSelect,
74
- _onPaste = _a.onPaste,
75
- _onKeyDown = _a.onKeyDown,
27
+ var {
28
+ value,
29
+ placeholder,
30
+ codeLength = 6,
31
+ caption,
32
+ captionAlign = "left",
33
+ width,
34
+ view = "default",
35
+ shape = "default",
36
+ size = "l",
37
+ disabled = false,
38
+ isError = false,
39
+ setIsError,
40
+ allowedSymbols = ONLY_DIGITS_PATTERN,
41
+ itemErrorBehavior = "remove-symbol",
42
+ codeErrorBehavior = "remove-code",
43
+ autoComplete = "one-time-code",
44
+ inputMode = "numeric",
45
+ autoFocus,
46
+ className,
47
+ style,
48
+ onChange,
49
+ onFullCodeEnter,
50
+ onClick,
51
+ onFocus,
52
+ onBlur,
53
+ onSelect,
54
+ onPaste,
55
+ onKeyDown
56
+ } = _a,
76
57
  inputProps = tslib.__rest(_a, ["value", "placeholder", "codeLength", "caption", "captionAlign", "width", "view", "shape", "size", "disabled", "isError", "setIsError", "allowedSymbols", "itemErrorBehavior", "codeErrorBehavior", "autoComplete", "inputMode", "autoFocus", "className", "style", "onChange", "onFullCodeEnter", "onClick", "onFocus", "onBlur", "onSelect", "onPaste", "onKeyDown"]);
77
- var inputRef = React.useRef(null);
78
- var _useState = React.useState((_b = value === null || value === void 0 ? void 0 : value.slice(0, codeLength)) !== null && _b !== void 0 ? _b : ""),
79
- _useState2 = _slicedToArray__default.default(_useState, 2),
80
- internalValue = _useState2[0],
81
- setInternalValue = _useState2[1];
82
- var _useState3 = React.useState(null),
83
- _useState4 = _slicedToArray__default.default(_useState3, 2),
84
- activeIndex = _useState4[0],
85
- setActiveIndex = _useState4[1];
86
- var _useState5 = React.useState(null),
87
- _useState6 = _slicedToArray__default.default(_useState5, 2),
88
- selectedIndex = _useState6[0],
89
- setSelectedIndex = _useState6[1];
90
- var _useState7 = React.useState(null),
91
- _useState8 = _slicedToArray__default.default(_useState7, 2),
92
- invalidIndex = _useState8[0],
93
- setInvalidIndex = _useState8[1];
94
- var _useState9 = React.useState(false),
95
- _useState0 = _slicedToArray__default.default(_useState9, 2),
96
- shaking = _useState0[0],
97
- setShaking = _useState0[1];
98
- var completedCode = React.useRef(null);
99
- var fullCodeEffectMounted = React.useRef(false);
100
- var errorEffectMounted = React.useRef(false);
101
- var timerRef = React.useRef(null);
102
- var pattern = React.useMemo(function () {
103
- return getPattern(allowedSymbols);
104
- }, [allowedSymbols]);
105
- var currentValue = value === undefined ? internalValue : value.slice(0, codeLength);
106
- var placeholders = getPlaceholder(placeholder, codeLength);
107
- var items = Array.from({
58
+ const inputRef = React.useRef(null);
59
+ const [internalValue, setInternalValue] = React.useState((_b = value === null || value === void 0 ? void 0 : value.slice(0, codeLength)) !== null && _b !== void 0 ? _b : "");
60
+ const [activeIndex, setActiveIndex] = React.useState(null);
61
+ const [selectedIndex, setSelectedIndex] = React.useState(null);
62
+ const [invalidIndex, setInvalidIndex] = React.useState(null);
63
+ const [shaking, setShaking] = React.useState(false);
64
+ const completedCode = React.useRef(null);
65
+ const fullCodeEffectMounted = React.useRef(false);
66
+ const errorEffectMounted = React.useRef(false);
67
+ const timerRef = React.useRef(null);
68
+ const pattern = React.useMemo(() => getPattern(allowedSymbols), [allowedSymbols]);
69
+ const currentValue = value === undefined ? internalValue : value.slice(0, codeLength);
70
+ const placeholders = getPlaceholder(placeholder, codeLength);
71
+ const items = Array.from({
108
72
  length: codeLength
109
- }, function (_, index) {
73
+ }, (_, index) => {
110
74
  var _a;
111
75
  return (_a = currentValue[index]) !== null && _a !== void 0 ? _a : "";
112
76
  });
113
- var setInputRef = function setInputRef(element) {
77
+ const setInputRef = element => {
114
78
  inputRef.current = element;
115
79
  if (typeof forwardedRef === "function") forwardedRef(element);else if (forwardedRef) forwardedRef.current = element;
116
80
  };
117
- var publishValue = React.useCallback(function (nextValue) {
118
- var normalized = nextValue.slice(0, codeLength);
81
+ const publishValue = React.useCallback(nextValue => {
82
+ const normalized = nextValue.slice(0, codeLength);
119
83
  if (value === undefined) setInternalValue(normalized);
120
84
  onChange === null || onChange === void 0 ? void 0 : onChange(normalized);
121
85
  }, [codeLength, onChange, value]);
122
- var selectPosition = React.useCallback(function (position) {
123
- var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : position;
124
- var input = inputRef.current;
86
+ const selectPosition = React.useCallback((position, end = position) => {
87
+ const input = inputRef.current;
125
88
  if (!input) return;
126
- var safePosition = Math.min(position, currentValue.length, codeLength);
89
+ const safePosition = Math.min(position, currentValue.length, codeLength);
127
90
  input.setSelectionRange(safePosition, Math.min(end, currentValue.length));
128
91
  setActiveIndex(Math.min(safePosition, codeLength - 1));
129
92
  setSelectedIndex(safePosition < end ? Math.min(safePosition, codeLength - 1) : null);
130
93
  }, [codeLength, currentValue.length]);
131
- var clearError = React.useCallback(function () {
94
+ const clearError = React.useCallback(() => {
132
95
  setInvalidIndex(null);
133
96
  setShaking(false);
134
97
  if (isError) setIsError === null || setIsError === void 0 ? void 0 : setIsError(false);
135
98
  }, [isError, setIsError]);
136
- var showTemporaryItemError = React.useCallback(function (rawValue, index) {
99
+ const showTemporaryItemError = React.useCallback((rawValue, index) => {
137
100
  if (timerRef.current) clearTimeout(timerRef.current);
138
101
  setInvalidIndex(index);
139
102
  setShaking(true);
140
103
  if (itemErrorBehavior === "keep") {
141
104
  publishValue(rawValue);
142
- timerRef.current = setTimeout(function () {
143
- return setShaking(false);
144
- }, 300);
105
+ timerRef.current = setTimeout(() => setShaking(false), 300);
145
106
  return;
146
107
  }
147
108
  if (value === undefined) setInternalValue(rawValue);
148
109
  onChange === null || onChange === void 0 ? void 0 : onChange(rawValue);
149
- timerRef.current = setTimeout(function () {
150
- var cleaned = rawValue.split("").filter(function (symbol) {
151
- return testSymbol(pattern, symbol);
152
- }).join("");
110
+ timerRef.current = setTimeout(() => {
111
+ const cleaned = rawValue.split("").filter(symbol => testSymbol(pattern, symbol)).join("");
153
112
  setInvalidIndex(null);
154
113
  setShaking(false);
155
114
  publishValue(cleaned);
156
- requestAnimationFrame(function () {
157
- return selectPosition(index);
158
- });
115
+ requestAnimationFrame(() => selectPosition(index));
159
116
  }, 300);
160
117
  }, [itemErrorBehavior, onChange, pattern, publishValue, selectPosition, value]);
161
- React.useEffect(function () {
162
- if (value === undefined) setInternalValue(function (current) {
163
- return current.slice(0, codeLength);
164
- });
118
+ React.useEffect(() => {
119
+ if (value === undefined) setInternalValue(current => current.slice(0, codeLength));
165
120
  }, [codeLength, value]);
166
- React.useEffect(function () {
167
- return function () {
168
- if (timerRef.current) clearTimeout(timerRef.current);
169
- };
121
+ React.useEffect(() => () => {
122
+ if (timerRef.current) clearTimeout(timerRef.current);
170
123
  }, []);
171
- React.useEffect(function () {
124
+ React.useEffect(() => {
172
125
  if (!fullCodeEffectMounted.current) {
173
126
  fullCodeEffectMounted.current = true;
174
127
  return;
@@ -182,7 +135,7 @@ var CodeField = /*#__PURE__*/React.forwardRef(function CodeFieldComponent(_a, fo
182
135
  onFullCodeEnter === null || onFullCodeEnter === void 0 ? void 0 : onFullCodeEnter(currentValue);
183
136
  }
184
137
  }, [codeLength, currentValue, onFullCodeEnter]);
185
- React.useEffect(function () {
138
+ React.useEffect(() => {
186
139
  if (!errorEffectMounted.current) {
187
140
  errorEffectMounted.current = true;
188
141
  return;
@@ -190,25 +143,25 @@ var CodeField = /*#__PURE__*/React.forwardRef(function CodeFieldComponent(_a, fo
190
143
  if (!isError) return;
191
144
  setShaking(true);
192
145
  if (timerRef.current) clearTimeout(timerRef.current);
193
- timerRef.current = setTimeout(function () {
146
+ timerRef.current = setTimeout(() => {
194
147
  setShaking(false);
195
148
  if (codeErrorBehavior === "remove-code") publishValue("");
196
- requestAnimationFrame(function () {
149
+ requestAnimationFrame(() => {
197
150
  var _a;
198
151
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
199
152
  selectPosition(codeErrorBehavior === "remove-code" ? 0 : codeLength - 1, codeLength);
200
153
  });
201
154
  }, 300);
202
155
  }, [codeErrorBehavior, codeLength, isError, publishValue, selectPosition]);
203
- var handleRootClick = function handleRootClick(event) {
156
+ const handleRootClick = event => {
204
157
  var _a;
205
158
  onClick === null || onClick === void 0 ? void 0 : onClick(event);
206
159
  if (event.defaultPrevented || disabled) return;
207
160
  (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
208
161
  selectPosition(currentValue.length);
209
162
  };
210
- var rootWidth = typeof width === "number" ? "".concat(width, "rem") : width;
211
- var isGrouped = codeLength === 6;
163
+ const rootWidth = typeof width === "number" ? `${width}rem` : width;
164
+ const isGrouped = codeLength === 6;
212
165
  return /*#__PURE__*/React__default.default.createElement("div", {
213
166
  className: cx(styles__default.default.root, styles__default.default[view], styles__default.default[size], styles__default.default[shape], disabled && styles__default.default.disabled, className),
214
167
  style: Object.assign(Object.assign({}, style), {
@@ -218,21 +171,19 @@ var CodeField = /*#__PURE__*/React.forwardRef(function CodeFieldComponent(_a, fo
218
171
  role: "presentation"
219
172
  }, /*#__PURE__*/React__default.default.createElement("div", {
220
173
  className: cx(styles__default.default.code_wrapper, (isError || shaking) && styles__default.default.code_error, shaking && styles__default.default.shaking)
221
- }, items.map(function (symbol, index) {
222
- return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, {
223
- key: index
224
- }, isGrouped && index === codeLength / 2 && (/*#__PURE__*/React__default.default.createElement("span", {
225
- className: styles__default.default.separator
226
- })), /*#__PURE__*/React__default.default.createElement("span", {
227
- className: cx(styles__default.default.item, activeIndex === index && styles__default.default.focused, selectedIndex === index && styles__default.default.selected, invalidIndex === index && styles__default.default.item_error),
228
- "aria-hidden": "true",
229
- "data-code-field-item": ""
230
- }, /*#__PURE__*/React__default.default.createElement("span", {
231
- className: symbol ? styles__default.default.value : styles__default.default.placeholder
232
- }, symbol || placeholders[index] || ""), activeIndex === index && selectedIndex === null && (/*#__PURE__*/React__default.default.createElement("span", {
233
- className: styles__default.default.caret
234
- }))));
235
- }), /*#__PURE__*/React__default.default.createElement("input", Object.assign({}, inputProps, {
174
+ }, items.map((symbol, index) => (/*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, {
175
+ key: index
176
+ }, isGrouped && index === codeLength / 2 && (/*#__PURE__*/React__default.default.createElement("span", {
177
+ className: styles__default.default.separator
178
+ })), /*#__PURE__*/React__default.default.createElement("span", {
179
+ className: cx(styles__default.default.item, activeIndex === index && styles__default.default.focused, selectedIndex === index && styles__default.default.selected, invalidIndex === index && styles__default.default.item_error),
180
+ "aria-hidden": "true",
181
+ "data-code-field-item": ""
182
+ }, /*#__PURE__*/React__default.default.createElement("span", {
183
+ className: symbol ? styles__default.default.value : styles__default.default.placeholder
184
+ }, symbol || placeholders[index] || ""), activeIndex === index && selectedIndex === null && (/*#__PURE__*/React__default.default.createElement("span", {
185
+ className: styles__default.default.caret
186
+ })))))), /*#__PURE__*/React__default.default.createElement("input", Object.assign({}, inputProps, {
236
187
  ref: setInputRef,
237
188
  className: styles__default.default.native_input,
238
189
  type: "text",
@@ -241,65 +192,57 @@ var CodeField = /*#__PURE__*/React.forwardRef(function CodeFieldComponent(_a, fo
241
192
  maxLength: codeLength,
242
193
  autoComplete: autoComplete,
243
194
  inputMode: inputMode,
195
+ // Opt-in public prop: consumers decide when autofocus is appropriate.
196
+ // eslint-disable-next-line jsx-a11y/no-autofocus
244
197
  autoFocus: autoFocus,
245
198
  disabled: disabled,
246
199
  spellCheck: false,
247
- onChange: function onChange(event) {
200
+ onChange: event => {
248
201
  if (disabled) return;
249
- var rawValue = event.currentTarget.value.slice(0, codeLength);
250
- var nextInvalidIndex = rawValue.split("").findIndex(function (symbol) {
251
- return !testSymbol(pattern, symbol);
252
- });
202
+ const rawValue = event.currentTarget.value.slice(0, codeLength);
203
+ const nextInvalidIndex = rawValue.split("").findIndex(symbol => !testSymbol(pattern, symbol));
253
204
  clearError();
254
205
  if (nextInvalidIndex < 0) publishValue(rawValue);else if (itemErrorBehavior === "forbid-enter") {
255
- var cleaned = rawValue.split("").filter(function (symbol) {
256
- return testSymbol(pattern, symbol);
257
- }).join("");
206
+ const cleaned = rawValue.split("").filter(symbol => testSymbol(pattern, symbol)).join("");
258
207
  publishValue(cleaned);
259
- requestAnimationFrame(function () {
260
- return selectPosition(nextInvalidIndex);
261
- });
208
+ requestAnimationFrame(() => selectPosition(nextInvalidIndex));
262
209
  } else showTemporaryItemError(rawValue, nextInvalidIndex);
263
210
  },
264
- onPaste: function onPaste(event) {
211
+ onPaste: event => {
265
212
  var _a, _b;
266
- _onPaste === null || _onPaste === void 0 ? void 0 : _onPaste(event);
213
+ onPaste === null || onPaste === void 0 ? void 0 : onPaste(event);
267
214
  if (event.defaultPrevented || disabled) return;
268
215
  event.preventDefault();
269
- var pasted = event.clipboardData.getData("text/plain").split("").filter(function (symbol) {
270
- return testSymbol(pattern, symbol);
271
- });
272
- var start = (_a = event.currentTarget.selectionStart) !== null && _a !== void 0 ? _a : 0;
273
- var end = (_b = event.currentTarget.selectionEnd) !== null && _b !== void 0 ? _b : start;
274
- var nextValue = (pasted.length >= codeLength ? pasted.join("") : "".concat(currentValue.slice(0, start)).concat(pasted.join("")).concat(currentValue.slice(end))).slice(0, codeLength);
216
+ const pasted = event.clipboardData.getData("text/plain").split("").filter(symbol => testSymbol(pattern, symbol));
217
+ const start = (_a = event.currentTarget.selectionStart) !== null && _a !== void 0 ? _a : 0;
218
+ const end = (_b = event.currentTarget.selectionEnd) !== null && _b !== void 0 ? _b : start;
219
+ const nextValue = (pasted.length >= codeLength ? pasted.join("") : `${currentValue.slice(0, start)}${pasted.join("")}${currentValue.slice(end)}`).slice(0, codeLength);
275
220
  clearError();
276
221
  publishValue(nextValue);
277
- requestAnimationFrame(function () {
278
- return selectPosition(Math.min(start + pasted.length, nextValue.length));
279
- });
222
+ requestAnimationFrame(() => selectPosition(Math.min(start + pasted.length, nextValue.length)));
280
223
  },
281
- onKeyDown: function onKeyDown(event) {
224
+ onKeyDown: event => {
282
225
  if (!disabled && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Delete"].includes(event.key)) {
283
226
  event.preventDefault();
284
227
  }
285
- _onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(event);
228
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
286
229
  },
287
- onFocus: function onFocus(event) {
230
+ onFocus: event => {
288
231
  selectPosition(currentValue.length);
289
- _onFocus === null || _onFocus === void 0 ? void 0 : _onFocus(event);
232
+ onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
290
233
  },
291
- onBlur: function onBlur(event) {
234
+ onBlur: event => {
292
235
  setActiveIndex(null);
293
236
  setSelectedIndex(null);
294
- _onBlur === null || _onBlur === void 0 ? void 0 : _onBlur(event);
237
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
295
238
  },
296
- onSelect: function onSelect(event) {
239
+ onSelect: event => {
297
240
  var _a, _b;
298
- var start = (_a = event.currentTarget.selectionStart) !== null && _a !== void 0 ? _a : currentValue.length;
299
- var end = (_b = event.currentTarget.selectionEnd) !== null && _b !== void 0 ? _b : start;
241
+ const start = (_a = event.currentTarget.selectionStart) !== null && _a !== void 0 ? _a : currentValue.length;
242
+ const end = (_b = event.currentTarget.selectionEnd) !== null && _b !== void 0 ? _b : start;
300
243
  setActiveIndex(Math.min(start, codeLength - 1));
301
244
  setSelectedIndex(start < end ? Math.min(start, codeLength - 1) : null);
302
- _onSelect === null || _onSelect === void 0 ? void 0 : _onSelect(event);
245
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect(event);
303
246
  }
304
247
  }))), caption && (/*#__PURE__*/React__default.default.createElement("div", {
305
248
  className: cx(styles__default.default.caption, isError && styles__default.default.caption_error),
@@ -30,5 +30,6 @@
30
30
  font-weight: var(--font-weight-medium, 500);
31
31
  inline-size: var(--component-counter-value-inline-size);
32
32
  text-align: center;
33
- user-select: none;
33
+ -webkit-user-select: none;
34
+ user-select: none;
34
35
  }
package/Counter/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
3
  var React = require('react');
5
4
  var clsx = require('clsx');
6
5
  var index = require('../Button/index.js');
@@ -10,33 +9,35 @@ var styles = require('./Counter.module.css');
10
9
 
11
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
11
 
13
- var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
14
12
  var React__default = /*#__PURE__*/_interopDefault(React);
15
13
  var clsx__default = /*#__PURE__*/_interopDefault(clsx);
16
14
  var styles__default = /*#__PURE__*/_interopDefault(styles);
17
15
 
18
- var Counter = function Counter(_ref) {
19
- var _ref$value = _ref.value,
20
- value = _ref$value === void 0 ? 1 : _ref$value,
21
- max = _ref.max,
22
- _ref$min = _ref.min,
23
- min = _ref$min === void 0 ? 0 : _ref$min,
24
- fullWidth = _ref.fullWidth,
25
- onChange = _ref.onChange,
26
- disabled = _ref.disabled,
27
- className = _ref.className;
28
- var minusDisabled = disabled || value <= min;
29
- var plusDisabled = disabled || value >= max;
30
- var handleChange = function handleChange(delta) {
16
+ const Counter = ({
17
+ value = 1,
18
+ max,
19
+ min = 0,
20
+ fullWidth,
21
+ onChange,
22
+ disabled,
23
+ className
24
+ }) => {
25
+ const minusDisabled = disabled || value <= min;
26
+ const plusDisabled = disabled || value >= max;
27
+ const handleChange = delta => {
31
28
  if (disabled) return;
32
- var newValue = value + delta;
29
+ const newValue = value + delta;
33
30
  if (newValue < min || newValue > max) return;
34
31
  onChange(newValue);
35
32
  };
36
33
  return /*#__PURE__*/React__default.default.createElement("div", {
37
- className: clsx__default.default(styles__default.default.root, _defineProperty__default.default({}, styles__default.default["root_fullWidth"], Boolean(fullWidth)), className)
34
+ className: clsx__default.default(styles__default.default.root, {
35
+ [styles__default.default["root_fullWidth"]]: Boolean(fullWidth)
36
+ }, className)
38
37
  }, /*#__PURE__*/React__default.default.createElement("div", {
39
- className: clsx__default.default(styles__default.default.control, _defineProperty__default.default({}, styles__default.default["control_fullWidth"], Boolean(fullWidth)))
38
+ className: clsx__default.default(styles__default.default.control, {
39
+ [styles__default.default["control_fullWidth"]]: Boolean(fullWidth)
40
+ })
40
41
  }, /*#__PURE__*/React__default.default.createElement(index.Button, {
41
42
  icon: /*#__PURE__*/React__default.default.createElement(Minus.Minus, {
42
43
  width: 16,
@@ -44,7 +45,7 @@ var Counter = function Counter(_ref) {
44
45
  }),
45
46
  disabled: minusDisabled,
46
47
  type: "button",
47
- onClick: function onClick(event) {
48
+ onClick: event => {
48
49
  event.stopPropagation();
49
50
  handleChange(-1);
50
51
  },
@@ -58,7 +59,7 @@ var Counter = function Counter(_ref) {
58
59
  }),
59
60
  disabled: plusDisabled,
60
61
  type: "button",
61
- onClick: function onClick(event) {
62
+ onClick: event => {
62
63
  event.stopPropagation();
63
64
  handleChange(1);
64
65
  },