colibri-ui 0.8.84 → 0.8.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Accordion/Accordion.module.css +4 -0
- package/Accordion/index.js +15 -23
- package/Autocomplete/Autocomplete.js +101 -132
- package/Avatar/Avatar.module.css +6 -0
- package/Avatar/index.js +102 -89
- package/Badge/Badge.module.css +2 -1
- package/Badge/Control/index.js +5 -3
- package/Badge/index.js +16 -16
- package/Button/index.js +23 -20
- package/Button/tokens.js +2 -2
- package/Calendar/Calendar.js +171 -269
- package/Card/Card.js +26 -32
- package/Checkbox/index.js +46 -43
- package/Chip/Chip.module.css +2 -1
- package/Chip/index.js +15 -15
- package/ClickOutside/index.js +10 -13
- package/CodeField/CodeField.js +113 -170
- package/Counter/Counter.module.css +2 -1
- package/Counter/index.js +21 -20
- package/Datepicker/components/DatePicker/index.js +81 -102
- package/Datepicker/index.js +17 -16
- package/DotsLoader/index.js +23 -15
- package/Drawer/Drawer.js +84 -98
- package/Drawer/Drawer.module.css +2 -1
- package/Drawer/index.props.d.ts +2 -0
- package/Dropdown/index.js +55 -68
- package/Dropzone/Dropzone.js +78 -168
- package/Dropzone/Dropzone.module.css +2 -1
- package/Editable/Editable.js +44 -57
- package/Grid/Item/index.js +11 -13
- package/Grid/index.js +15 -21
- package/Icons/ArrowNext.js +7 -8
- package/Icons/Cart.js +7 -8
- package/Icons/Check.js +7 -8
- package/Icons/Chevron.js +7 -8
- package/Icons/Close.js +6 -6
- package/Icons/Copy.js +7 -8
- package/Icons/Cross.js +6 -6
- package/Icons/CrossFill.js +7 -8
- package/Icons/Edit.js +7 -8
- package/Icons/Exit.js +7 -8
- package/Icons/EyeClosed.js +7 -8
- package/Icons/EyeOpen.js +7 -8
- package/Icons/Help.js +6 -6
- package/Icons/Info.js +7 -8
- package/Icons/Minus.js +7 -8
- package/Icons/More.js +7 -8
- package/Icons/Plus.js +7 -8
- package/Icons/Setting.js +7 -8
- package/Icons/Shield.js +7 -8
- package/Icons/Trash.js +7 -8
- package/Icons/User.js +7 -8
- package/Image/Image.module.css +4 -0
- package/Image/index.d.ts +1 -1
- package/Image/index.js +44 -37
- package/Input/index.d.ts +1 -1
- package/Input/index.js +37 -25
- package/Input/index.props.d.ts +1 -1
- package/InputRadio/index.js +32 -24
- package/List/List.js +81 -76
- package/Menu/Menu.module.css +2 -1
- package/Menu/components/MenuItem/index.js +17 -14
- package/Menu/index.js +22 -23
- package/Modal/components/Body/index.js +9 -8
- package/Modal/components/Close/Close.module.css +4 -0
- package/Modal/components/Close/index.js +13 -14
- package/Modal/components/Content/index.js +5 -6
- package/Modal/components/Footer/index.js +5 -3
- package/Modal/components/Header/index.js +13 -12
- package/Modal/components/Title/index.js +10 -9
- package/Modal/context.js +3 -3
- package/Modal/index.js +46 -68
- package/MultiSelect/components/MenuOverlay/index.js +48 -61
- package/MultiSelect/components/MenuOverlayItem/index.js +13 -14
- package/MultiSelect/index.js +72 -100
- package/MultiSelect/index.module.css +2 -1
- package/MultiSelect/utils/index.js +8 -18
- package/NumberInput/NumberInput.js +80 -112
- package/Portal/index.js +6 -10
- package/Progress/Progress.js +45 -58
- package/RadioGroup/Radio.js +29 -32
- package/RadioGroup/index.js +43 -46
- package/Rating/Rating.js +50 -63
- package/Select/components/MenuOverlay/index.js +16 -25
- package/Select/components/MenuOverlayItem/index.js +13 -11
- package/Select/index.js +39 -48
- package/Select/index.module.css +2 -1
- package/Separator/index.js +5 -6
- package/Sheet/Sheet.js +98 -122
- package/Sheet/Sheet.module.css +4 -2
- package/Sheet/index.props.d.ts +2 -0
- package/Skeleton/index.js +25 -30
- package/Slider/Slider.js +83 -119
- package/Status/index.js +17 -18
- package/Switch/Switch.module.css +2 -1
- package/Switch/index.js +22 -15
- package/TabsMenu/Tab/Tab.js +14 -10
- package/TabsMenu/Tab/Tab.module.css +2 -1
- package/TabsMenu/index.js +25 -26
- package/TabsPanels/Panel/index.js +6 -4
- package/TabsPanels/index.js +13 -10
- package/TextArea/index.d.ts +1 -1
- package/TextArea/index.js +30 -19
- package/Theme/breakpoints.js +5 -11
- package/Theme/colors/theme_buenos_aires.js +14 -14
- package/Theme/colors/theme_jaipur.js +14 -14
- package/Theme/global.css +0 -1
- package/Theme/index.js +1 -1
- package/TimeSelect/Label/index.js +11 -13
- package/TimeSelect/helpers.js +23 -42
- package/TimeSelect/index.js +32 -38
- package/Tooltip/index.js +36 -42
- package/Typography/Typography.module.css +1365 -0
- package/Typography/index.js +24 -13
- package/Typography/index.props.d.ts +13 -1
- package/base/BaseInput/index.js +10 -8
- package/base/FormField/index.d.ts +1 -1
- package/base/FormField/index.js +27 -22
- package/base/FormField/index.props.d.ts +4 -0
- package/base/InputRoot/index.js +27 -27
- package/esm/Accordion/Accordion.module.css +4 -0
- package/esm/Accordion/index.js +15 -21
- package/esm/Autocomplete/Autocomplete.js +101 -130
- package/esm/Avatar/Avatar.module.css +6 -0
- package/esm/Avatar/index.js +102 -88
- package/esm/Badge/Badge.module.css +2 -1
- package/esm/Badge/Control/index.js +5 -3
- package/esm/Badge/index.js +16 -15
- package/esm/Button/index.js +23 -19
- package/esm/Button/tokens.js +2 -2
- package/esm/Calendar/Calendar.js +171 -267
- package/esm/Card/Card.js +26 -32
- package/esm/Checkbox/index.js +46 -42
- package/esm/Chip/Chip.module.css +2 -1
- package/esm/Chip/index.js +15 -14
- package/esm/ClickOutside/index.js +10 -13
- package/esm/CodeField/CodeField.js +113 -169
- package/esm/Counter/Counter.module.css +2 -1
- package/esm/Counter/index.js +21 -19
- package/esm/Datepicker/components/DatePicker/index.js +81 -101
- package/esm/Datepicker/index.js +17 -16
- package/esm/DotsLoader/index.js +23 -14
- package/esm/Drawer/Drawer.js +84 -97
- package/esm/Drawer/Drawer.module.css +2 -1
- package/esm/Drawer/index.props.d.ts +2 -0
- package/esm/Dropdown/index.js +55 -66
- package/esm/Dropzone/Dropzone.js +78 -165
- package/esm/Dropzone/Dropzone.module.css +2 -1
- package/esm/Editable/Editable.js +44 -56
- package/esm/Grid/Item/index.js +11 -12
- package/esm/Grid/index.js +15 -21
- package/esm/Icons/ArrowNext.js +7 -8
- package/esm/Icons/Cart.js +7 -8
- package/esm/Icons/Check.js +7 -8
- package/esm/Icons/Chevron.js +7 -8
- package/esm/Icons/Close.js +6 -6
- package/esm/Icons/Copy.js +7 -8
- package/esm/Icons/Cross.js +6 -6
- package/esm/Icons/CrossFill.js +7 -8
- package/esm/Icons/Edit.js +7 -8
- package/esm/Icons/Exit.js +7 -8
- package/esm/Icons/EyeClosed.js +7 -8
- package/esm/Icons/EyeOpen.js +7 -8
- package/esm/Icons/Help.js +6 -6
- package/esm/Icons/Info.js +7 -8
- package/esm/Icons/Minus.js +7 -8
- package/esm/Icons/More.js +7 -8
- package/esm/Icons/Plus.js +7 -8
- package/esm/Icons/Setting.js +7 -8
- package/esm/Icons/Shield.js +7 -8
- package/esm/Icons/Trash.js +7 -8
- package/esm/Icons/User.js +7 -8
- package/esm/Image/Image.module.css +4 -0
- package/esm/Image/index.d.ts +1 -1
- package/esm/Image/index.js +44 -36
- package/esm/Input/index.d.ts +1 -1
- package/esm/Input/index.js +38 -26
- package/esm/Input/index.props.d.ts +1 -1
- package/esm/InputRadio/index.js +32 -23
- package/esm/List/List.js +81 -75
- package/esm/Menu/Menu.module.css +2 -1
- package/esm/Menu/components/MenuItem/index.js +17 -13
- package/esm/Menu/index.js +22 -23
- package/esm/Modal/components/Body/index.js +9 -7
- package/esm/Modal/components/Close/Close.module.css +4 -0
- package/esm/Modal/components/Close/index.js +13 -14
- package/esm/Modal/components/Content/index.js +5 -6
- package/esm/Modal/components/Footer/index.js +5 -3
- package/esm/Modal/components/Header/index.js +13 -11
- package/esm/Modal/components/Title/index.js +10 -9
- package/esm/Modal/context.js +3 -3
- package/esm/Modal/index.js +50 -70
- package/esm/MultiSelect/components/MenuOverlay/index.js +48 -60
- package/esm/MultiSelect/components/MenuOverlayItem/index.js +13 -14
- package/esm/MultiSelect/index.js +72 -97
- package/esm/MultiSelect/index.module.css +2 -1
- package/esm/MultiSelect/utils/index.js +8 -14
- package/esm/NumberInput/NumberInput.js +80 -111
- package/esm/Portal/index.js +6 -9
- package/esm/Progress/Progress.js +45 -58
- package/esm/RadioGroup/Radio.js +29 -32
- package/esm/RadioGroup/index.js +43 -45
- package/esm/Rating/Rating.js +50 -63
- package/esm/Select/components/MenuOverlay/index.js +16 -24
- package/esm/Select/components/MenuOverlayItem/index.js +13 -11
- package/esm/Select/index.js +39 -46
- package/esm/Select/index.module.css +2 -1
- package/esm/Separator/index.js +5 -6
- package/esm/Sheet/Sheet.js +98 -120
- package/esm/Sheet/Sheet.module.css +4 -2
- package/esm/Sheet/index.props.d.ts +2 -0
- package/esm/Skeleton/index.js +25 -30
- package/esm/Slider/Slider.js +83 -119
- package/esm/Status/index.js +17 -17
- package/esm/Switch/Switch.module.css +2 -1
- package/esm/Switch/index.js +22 -14
- package/esm/TabsMenu/Tab/Tab.js +14 -9
- package/esm/TabsMenu/Tab/Tab.module.css +2 -1
- package/esm/TabsMenu/index.js +25 -26
- package/esm/TabsPanels/Panel/index.js +6 -4
- package/esm/TabsPanels/index.js +13 -10
- package/esm/TextArea/index.d.ts +1 -1
- package/esm/TextArea/index.js +31 -20
- package/esm/Theme/breakpoints.js +5 -11
- package/esm/Theme/colors/theme_buenos_aires.js +14 -14
- package/esm/Theme/colors/theme_jaipur.js +14 -14
- package/esm/Theme/global.css +0 -1
- package/esm/Theme/index.js +1 -1
- package/esm/TimeSelect/Label/index.js +11 -13
- package/esm/TimeSelect/helpers.js +22 -37
- package/esm/TimeSelect/index.js +32 -38
- package/esm/Tooltip/index.js +36 -41
- package/esm/Typography/Typography.module.css +1365 -0
- package/esm/Typography/index.js +24 -12
- package/esm/Typography/index.props.d.ts +13 -1
- package/esm/base/BaseInput/index.js +10 -8
- package/esm/base/FormField/index.d.ts +1 -1
- package/esm/base/FormField/index.js +27 -21
- package/esm/base/FormField/index.props.d.ts +4 -0
- package/esm/base/InputRoot/index.js +27 -26
- package/esm/helpers/date/index.js +4 -8
- package/esm/hooks/useMediaSizes/index.js +9 -15
- package/esm/hooks/useModalStack/index.js +6 -9
- package/esm/hooks/useOnClickOutside/index.js +6 -6
- package/esm/hooks/useScrollLock/index.js +10 -9
- package/esm/hooks/useTrapFocus/index.js +8 -10
- package/esm/index.d.ts +1 -1
- package/esm/lib/keyboard.js +2 -4
- package/helpers/date/index.js +21 -32
- package/hooks/useMediaSizes/index.js +9 -15
- package/hooks/useModalStack/index.js +6 -9
- package/hooks/useOnClickOutside/index.js +6 -6
- package/hooks/useScrollLock/index.js +10 -9
- package/hooks/useTrapFocus/index.js +8 -10
- package/index.d.ts +1 -1
- package/lib/keyboard.js +2 -4
- package/package.json +5 -1
package/CodeField/CodeField.js
CHANGED
|
@@ -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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
const CodeField = /*#__PURE__*/React.forwardRef(function CodeFieldComponent(_a, forwardedRef) {
|
|
35
26
|
var _b;
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
},
|
|
73
|
+
}, (_, index) => {
|
|
110
74
|
var _a;
|
|
111
75
|
return (_a = currentValue[index]) !== null && _a !== void 0 ? _a : "";
|
|
112
76
|
});
|
|
113
|
-
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
var input = inputRef.current;
|
|
86
|
+
const selectPosition = React.useCallback((position, end = position) => {
|
|
87
|
+
const input = inputRef.current;
|
|
125
88
|
if (!input) return;
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
150
|
-
|
|
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(
|
|
157
|
-
return selectPosition(index);
|
|
158
|
-
});
|
|
115
|
+
requestAnimationFrame(() => selectPosition(index));
|
|
159
116
|
}, 300);
|
|
160
117
|
}, [itemErrorBehavior, onChange, pattern, publishValue, selectPosition, value]);
|
|
161
|
-
React.useEffect(
|
|
162
|
-
if (value === undefined) setInternalValue(
|
|
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(
|
|
167
|
-
|
|
168
|
-
if (timerRef.current) clearTimeout(timerRef.current);
|
|
169
|
-
};
|
|
121
|
+
React.useEffect(() => () => {
|
|
122
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
170
123
|
}, []);
|
|
171
|
-
React.useEffect(
|
|
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(
|
|
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(
|
|
146
|
+
timerRef.current = setTimeout(() => {
|
|
194
147
|
setShaking(false);
|
|
195
148
|
if (codeErrorBehavior === "remove-code") publishValue("");
|
|
196
|
-
requestAnimationFrame(
|
|
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
|
-
|
|
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
|
-
|
|
211
|
-
|
|
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(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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:
|
|
200
|
+
onChange: event => {
|
|
248
201
|
if (disabled) return;
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
256
|
-
return testSymbol(pattern, symbol);
|
|
257
|
-
}).join("");
|
|
206
|
+
const cleaned = rawValue.split("").filter(symbol => testSymbol(pattern, symbol)).join("");
|
|
258
207
|
publishValue(cleaned);
|
|
259
|
-
requestAnimationFrame(
|
|
260
|
-
return selectPosition(nextInvalidIndex);
|
|
261
|
-
});
|
|
208
|
+
requestAnimationFrame(() => selectPosition(nextInvalidIndex));
|
|
262
209
|
} else showTemporaryItemError(rawValue, nextInvalidIndex);
|
|
263
210
|
},
|
|
264
|
-
onPaste:
|
|
211
|
+
onPaste: event => {
|
|
265
212
|
var _a, _b;
|
|
266
|
-
|
|
213
|
+
onPaste === null || onPaste === void 0 ? void 0 : onPaste(event);
|
|
267
214
|
if (event.defaultPrevented || disabled) return;
|
|
268
215
|
event.preventDefault();
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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(
|
|
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:
|
|
224
|
+
onKeyDown: event => {
|
|
282
225
|
if (!disabled && ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Delete"].includes(event.key)) {
|
|
283
226
|
event.preventDefault();
|
|
284
227
|
}
|
|
285
|
-
|
|
228
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
286
229
|
},
|
|
287
|
-
onFocus:
|
|
230
|
+
onFocus: event => {
|
|
288
231
|
selectPosition(currentValue.length);
|
|
289
|
-
|
|
232
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
290
233
|
},
|
|
291
|
-
onBlur:
|
|
234
|
+
onBlur: event => {
|
|
292
235
|
setActiveIndex(null);
|
|
293
236
|
setSelectedIndex(null);
|
|
294
|
-
|
|
237
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
295
238
|
},
|
|
296
|
-
onSelect:
|
|
239
|
+
onSelect: event => {
|
|
297
240
|
var _a, _b;
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
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),
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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,
|
|
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,
|
|
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:
|
|
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:
|
|
62
|
+
onClick: event => {
|
|
62
63
|
event.stopPropagation();
|
|
63
64
|
handleChange(1);
|
|
64
65
|
},
|