@ozen-ui/kit 0.63.0 → 0.64.0
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/InputOTP/package.json +5 -0
- package/__inner__/cjs/components/InputOTP/InputOTP.css +60 -0
- package/__inner__/cjs/components/InputOTP/InputOTP.d.ts +4 -0
- package/__inner__/cjs/components/InputOTP/InputOTP.js +179 -0
- package/__inner__/cjs/components/InputOTP/constants.d.ts +8 -0
- package/__inner__/cjs/components/InputOTP/constants.js +13 -0
- package/__inner__/cjs/components/InputOTP/helper.d.ts +13 -0
- package/__inner__/cjs/components/InputOTP/helper.js +87 -0
- package/__inner__/cjs/components/InputOTP/hooks/index.d.ts +1 -0
- package/__inner__/cjs/components/InputOTP/hooks/index.js +4 -0
- package/__inner__/cjs/components/InputOTP/hooks/useInputOTPEvents.d.ts +20 -0
- package/__inner__/cjs/components/InputOTP/hooks/useInputOTPEvents.js +183 -0
- package/__inner__/cjs/components/InputOTP/index.d.ts +3 -0
- package/__inner__/cjs/components/InputOTP/index.js +6 -0
- package/__inner__/cjs/components/InputOTP/presets.d.ts +12 -0
- package/__inner__/cjs/components/InputOTP/presets.js +27 -0
- package/__inner__/cjs/components/InputOTP/types.d.ts +101 -0
- package/__inner__/cjs/components/InputOTP/types.js +7 -0
- package/__inner__/cjs/components/Tabs/Tabs.js +6 -2
- package/__inner__/cjs/components/ThemeProvider/types.d.ts +1 -0
- package/__inner__/cjs/hooks/useStoredValue/index.d.ts +3 -0
- package/__inner__/cjs/hooks/useStoredValue/index.js +6 -0
- package/__inner__/cjs/hooks/useStoredValue/types.d.ts +2 -0
- package/__inner__/cjs/hooks/useStoredValue/types.js +2 -0
- package/__inner__/cjs/hooks/useStoredValue/useStoredValue.d.ts +4 -0
- package/__inner__/cjs/hooks/useStoredValue/useStoredValue.js +16 -0
- package/__inner__/cjs/hooks/useStoredValue/utils.d.ts +2 -0
- package/__inner__/cjs/hooks/useStoredValue/utils.js +8 -0
- package/__inner__/cjs/utils/array/create-empty/createEmptyArray.d.ts +1 -0
- package/__inner__/cjs/utils/array/create-empty/createEmptyArray.js +8 -0
- package/__inner__/cjs/utils/array/create-empty/index.d.ts +1 -0
- package/__inner__/cjs/utils/array/create-empty/index.js +4 -0
- package/__inner__/cjs/utils/array/create-filled/createFilledArray.d.ts +1 -0
- package/__inner__/cjs/utils/array/create-filled/createFilledArray.js +7 -0
- package/__inner__/cjs/utils/array/create-filled/index.d.ts +1 -0
- package/__inner__/cjs/utils/array/create-filled/index.js +4 -0
- package/__inner__/cjs/utils/array/index.d.ts +2 -0
- package/__inner__/cjs/utils/array/index.js +5 -0
- package/__inner__/cjs/utils/isFunction.d.ts +1 -0
- package/__inner__/cjs/utils/isFunction.js +8 -0
- package/__inner__/esm/components/InputOTP/InputOTP.css +60 -0
- package/__inner__/esm/components/InputOTP/InputOTP.d.ts +4 -0
- package/__inner__/esm/components/InputOTP/InputOTP.js +176 -0
- package/__inner__/esm/components/InputOTP/constants.d.ts +8 -0
- package/__inner__/esm/components/InputOTP/constants.js +10 -0
- package/__inner__/esm/components/InputOTP/helper.d.ts +13 -0
- package/__inner__/esm/components/InputOTP/helper.js +79 -0
- package/__inner__/esm/components/InputOTP/hooks/index.d.ts +1 -0
- package/__inner__/esm/components/InputOTP/hooks/index.js +1 -0
- package/__inner__/esm/components/InputOTP/hooks/useInputOTPEvents.d.ts +20 -0
- package/__inner__/esm/components/InputOTP/hooks/useInputOTPEvents.js +179 -0
- package/__inner__/esm/components/InputOTP/index.d.ts +3 -0
- package/__inner__/esm/components/InputOTP/index.js +3 -0
- package/__inner__/esm/components/InputOTP/presets.d.ts +12 -0
- package/__inner__/esm/components/InputOTP/presets.js +24 -0
- package/__inner__/esm/components/InputOTP/types.d.ts +101 -0
- package/__inner__/esm/components/InputOTP/types.js +4 -0
- package/__inner__/esm/components/Tabs/Tabs.js +6 -2
- package/__inner__/esm/components/ThemeProvider/types.d.ts +1 -0
- package/__inner__/esm/hooks/useStoredValue/index.d.ts +3 -0
- package/__inner__/esm/hooks/useStoredValue/index.js +3 -0
- package/__inner__/esm/hooks/useStoredValue/types.d.ts +2 -0
- package/__inner__/esm/hooks/useStoredValue/types.js +1 -0
- package/__inner__/esm/hooks/useStoredValue/useStoredValue.d.ts +4 -0
- package/__inner__/esm/hooks/useStoredValue/useStoredValue.js +13 -0
- package/__inner__/esm/hooks/useStoredValue/utils.d.ts +2 -0
- package/__inner__/esm/hooks/useStoredValue/utils.js +5 -0
- package/__inner__/esm/utils/array/create-empty/createEmptyArray.d.ts +1 -0
- package/__inner__/esm/utils/array/create-empty/createEmptyArray.js +4 -0
- package/__inner__/esm/utils/array/create-empty/index.d.ts +1 -0
- package/__inner__/esm/utils/array/create-empty/index.js +1 -0
- package/__inner__/esm/utils/array/create-filled/createFilledArray.d.ts +1 -0
- package/__inner__/esm/utils/array/create-filled/createFilledArray.js +3 -0
- package/__inner__/esm/utils/array/create-filled/index.d.ts +1 -0
- package/__inner__/esm/utils/array/create-filled/index.js +1 -0
- package/__inner__/esm/utils/array/index.d.ts +2 -0
- package/__inner__/esm/utils/array/index.js +2 -0
- package/__inner__/esm/utils/isFunction.d.ts +1 -0
- package/__inner__/esm/utils/isFunction.js +4 -0
- package/package.json +4 -4
- package/useStoredValue/package.json +5 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ChangeEvent, ClipboardEvent, ClipboardEventHandler, KeyboardEvent, KeyboardEventHandler } from 'react';
|
|
2
|
+
import type { StoredValue } from '../../../hooks/useStoredValue';
|
|
3
|
+
import type { InputOTPRawValue, InputOTPInputs, InputOTPOnFinish, InputOTPValidate, InputOTPMask, InputOTPFinishBehavior } from '../types';
|
|
4
|
+
export declare const useInputOTPEvents: ({ inputs, valueByIndex, setValueByIndex, validate: validateFromProps, length, onPaste: onPasteFromProps, onKeyDown: onKeyDownFromProps, onFinish, mask, finishBehavior, }: {
|
|
5
|
+
inputs: StoredValue<InputOTPInputs>;
|
|
6
|
+
valueByIndex: InputOTPRawValue | undefined;
|
|
7
|
+
setValueByIndex: (valueByIndex: InputOTPRawValue) => void;
|
|
8
|
+
validate: InputOTPValidate | undefined;
|
|
9
|
+
length: number;
|
|
10
|
+
onKeyDown: KeyboardEventHandler<HTMLElement> | undefined;
|
|
11
|
+
onPaste: ClipboardEventHandler<HTMLElement> | undefined;
|
|
12
|
+
onFinish: InputOTPOnFinish | undefined;
|
|
13
|
+
mask: InputOTPMask | undefined;
|
|
14
|
+
finishBehavior: InputOTPFinishBehavior;
|
|
15
|
+
}) => {
|
|
16
|
+
onInputChange: (event: ChangeEvent<HTMLInputElement>, index: number) => void;
|
|
17
|
+
onKeyDown: (event: KeyboardEvent<HTMLInputElement>, index: number) => void;
|
|
18
|
+
onPaste: (event: ClipboardEvent<HTMLInputElement>, inputIndex: number) => void;
|
|
19
|
+
onInputSelect: (index: number) => void;
|
|
20
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
2
|
+
import { isFunction } from '../../../utils/isFunction';
|
|
3
|
+
import { isKey } from '../../../utils/isKey';
|
|
4
|
+
import { isKeys } from '../../../utils/isKeys';
|
|
5
|
+
import { isNumber } from '../../../utils/isNumber';
|
|
6
|
+
import { maskSymbol, maskValue, valueToString } from '../helper';
|
|
7
|
+
export var useInputOTPEvents = function (_a) {
|
|
8
|
+
var inputs = _a.inputs, valueByIndex = _a.valueByIndex, setValueByIndex = _a.setValueByIndex, validateFromProps = _a.validate, length = _a.length, onPasteFromProps = _a.onPaste, onKeyDownFromProps = _a.onKeyDown, onFinish = _a.onFinish, mask = _a.mask, finishBehavior = _a.finishBehavior;
|
|
9
|
+
var validate = function (value) {
|
|
10
|
+
if (isFunction(validateFromProps)) {
|
|
11
|
+
return validateFromProps(value);
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
};
|
|
15
|
+
var tryToFinish = function (valueByIndex, index, options) {
|
|
16
|
+
var _a;
|
|
17
|
+
var _b = (options !== null && options !== void 0 ? options : {}).isEnter, isEnter = _b === void 0 ? false : _b;
|
|
18
|
+
var requiredValueByIndex = valueByIndex !== null && valueByIndex !== void 0 ? valueByIndex : [];
|
|
19
|
+
var stringValue = valueToString(requiredValueByIndex);
|
|
20
|
+
var isFullFilledValue = requiredValueByIndex.filter(function (value) { return value !== ''; }).length === length;
|
|
21
|
+
var isChangeOnLastInput = index + 1 === length;
|
|
22
|
+
var maskedRawValue = maskValue(mask, valueByIndex);
|
|
23
|
+
var finishContext = {
|
|
24
|
+
isChangeOnLastInput: isChangeOnLastInput,
|
|
25
|
+
inputIndex: index,
|
|
26
|
+
value: valueToString(valueByIndex),
|
|
27
|
+
rawValue: valueByIndex !== null && valueByIndex !== void 0 ? valueByIndex : [],
|
|
28
|
+
maskedValue: valueToString(maskedRawValue),
|
|
29
|
+
maskedRawValue: maskedRawValue,
|
|
30
|
+
isFullFilled: isFullFilledValue,
|
|
31
|
+
isEnter: isEnter,
|
|
32
|
+
};
|
|
33
|
+
var isFinish = finishBehavior(finishContext);
|
|
34
|
+
if (isFinish) {
|
|
35
|
+
var activeElement = document.activeElement;
|
|
36
|
+
if (activeElement instanceof HTMLElement) {
|
|
37
|
+
activeElement.blur();
|
|
38
|
+
}
|
|
39
|
+
if (onFinish) {
|
|
40
|
+
var maskedValueByIndex = (_a = valueByIndex === null || valueByIndex === void 0 ? void 0 : valueByIndex.map(function (value, index) { return maskSymbol(mask, value, index); })) !== null && _a !== void 0 ? _a : [];
|
|
41
|
+
onFinish(stringValue, valueByIndex !== null && valueByIndex !== void 0 ? valueByIndex : [], valueToString(maskedValueByIndex), maskedValueByIndex);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var onInputChange = function (event, index) {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
var target = event.target;
|
|
48
|
+
var value = (function () {
|
|
49
|
+
var _a;
|
|
50
|
+
var previousValue = (_a = valueByIndex === null || valueByIndex === void 0 ? void 0 : valueByIndex[index]) !== null && _a !== void 0 ? _a : '';
|
|
51
|
+
var previousMaskedValue = maskSymbol(mask, previousValue, index);
|
|
52
|
+
var rawValue = target.value;
|
|
53
|
+
var changedValuePart = rawValue.replace(previousMaskedValue, '');
|
|
54
|
+
if (changedValuePart.length > 1) {
|
|
55
|
+
return changedValuePart.slice(0, 1);
|
|
56
|
+
}
|
|
57
|
+
return changedValuePart;
|
|
58
|
+
})();
|
|
59
|
+
var isValidValue = validate(value);
|
|
60
|
+
var newValueByIndex = valueByIndex ? __spreadArray([], __read(valueByIndex), false) : [];
|
|
61
|
+
if (isValidValue) {
|
|
62
|
+
newValueByIndex[index] = value;
|
|
63
|
+
var isLastInput = index === length - 1;
|
|
64
|
+
var firstEmptyInputIndex = newValueByIndex.findIndex(function (value) { return !value; });
|
|
65
|
+
if (isLastInput && firstEmptyInputIndex !== -1) {
|
|
66
|
+
var firstEmptyInput = inputs.current[firstEmptyInputIndex];
|
|
67
|
+
if (firstEmptyInput) {
|
|
68
|
+
firstEmptyInput.focus();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
var nextInput = inputs.current[index + 1];
|
|
73
|
+
if (nextInput) {
|
|
74
|
+
nextInput.disabled = false;
|
|
75
|
+
nextInput.focus();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
setValueByIndex(newValueByIndex);
|
|
79
|
+
}
|
|
80
|
+
tryToFinish(newValueByIndex, index);
|
|
81
|
+
};
|
|
82
|
+
var onKeyDown = function (event, index) {
|
|
83
|
+
if (onKeyDownFromProps) {
|
|
84
|
+
onKeyDownFromProps(event);
|
|
85
|
+
}
|
|
86
|
+
var target = event.target;
|
|
87
|
+
if (isKey(event, 'Backspace')) {
|
|
88
|
+
var newValueByIndex = valueByIndex ? __spreadArray([], __read(valueByIndex), false) : [];
|
|
89
|
+
if (target.value === '') {
|
|
90
|
+
var previousInput = inputs.current[index - 1];
|
|
91
|
+
var previousInputIndex = index - 1;
|
|
92
|
+
if (previousInput) {
|
|
93
|
+
newValueByIndex[previousInputIndex] = '';
|
|
94
|
+
previousInput.focus();
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
newValueByIndex[index] = '';
|
|
100
|
+
}
|
|
101
|
+
setValueByIndex(newValueByIndex);
|
|
102
|
+
}
|
|
103
|
+
else if (isKeys(event, ['ArrowLeft', 'ArrowDown'])) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
var previousInput = inputs.current[index - 1];
|
|
106
|
+
if (previousInput) {
|
|
107
|
+
previousInput.focus();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (isKeys(event, ['ArrowRight', 'ArrowUp'])) {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
var nextInput = inputs.current[index + 1];
|
|
113
|
+
if (nextInput) {
|
|
114
|
+
nextInput.focus();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (isKey(event, 'Enter')) {
|
|
118
|
+
tryToFinish(valueByIndex, index, {
|
|
119
|
+
isEnter: true,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var onPaste = function (event, inputIndex) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
if (onPasteFromProps) {
|
|
126
|
+
onPasteFromProps(event);
|
|
127
|
+
}
|
|
128
|
+
var currentInputs = inputs.current;
|
|
129
|
+
var pastedValue = event.clipboardData.getData('Text');
|
|
130
|
+
var newValueByIndex = valueByIndex ? __spreadArray([], __read(valueByIndex), false) : [];
|
|
131
|
+
var lastChangedInputIndex = {
|
|
132
|
+
current: null,
|
|
133
|
+
};
|
|
134
|
+
var focusedInputIndex = {
|
|
135
|
+
current: null,
|
|
136
|
+
};
|
|
137
|
+
__spreadArray([], __read(pastedValue), false).forEach(function (symbol, symbolIndex) {
|
|
138
|
+
var currentInputIndex = symbolIndex + inputIndex;
|
|
139
|
+
var isIndexExistInArray = currentInputIndex >= 0 && currentInputIndex < currentInputs.length;
|
|
140
|
+
if (isIndexExistInArray && validate(symbol)) {
|
|
141
|
+
lastChangedInputIndex.current = currentInputIndex;
|
|
142
|
+
newValueByIndex[currentInputIndex] = symbol;
|
|
143
|
+
var nextInput = currentInputs[currentInputIndex + 1];
|
|
144
|
+
if (nextInput) {
|
|
145
|
+
focusedInputIndex.current = currentInputIndex + 1;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
if (isNumber(focusedInputIndex.current)) {
|
|
150
|
+
var input = currentInputs[focusedInputIndex.current];
|
|
151
|
+
if (input) {
|
|
152
|
+
input.disabled = false;
|
|
153
|
+
input.focus();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
setValueByIndex(newValueByIndex);
|
|
157
|
+
if (lastChangedInputIndex.current !== null) {
|
|
158
|
+
tryToFinish(newValueByIndex, lastChangedInputIndex.current);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var onInputSelect = function (index) {
|
|
162
|
+
setTimeout(function () {
|
|
163
|
+
var currentInput = inputs.current[index];
|
|
164
|
+
if (!currentInput) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
var originalType = currentInput.type;
|
|
168
|
+
currentInput.type = 'text';
|
|
169
|
+
currentInput.setSelectionRange(1, 1);
|
|
170
|
+
currentInput.type = originalType;
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
onInputChange: onInputChange,
|
|
175
|
+
onKeyDown: onKeyDown,
|
|
176
|
+
onPaste: onPaste,
|
|
177
|
+
onInputSelect: onInputSelect,
|
|
178
|
+
};
|
|
179
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const INPUT_OTP_VALIDATE_PRESET: {
|
|
2
|
+
TEXT: (value: string) => boolean;
|
|
3
|
+
NUMERIC: (value: string) => boolean;
|
|
4
|
+
TEXT_NUMERIC: (value: string) => boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const INPUT_OTP_MASK_PRESET: {
|
|
7
|
+
PASSWORD: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const INPUT_OTP_FINISH_BEHAVIOR_PRESET: {
|
|
10
|
+
FULL_FILLED_NON_LAST_INPUT: ({ isFullFilled }: import("./types").InputOTPFinishBehaviorContext) => boolean;
|
|
11
|
+
FULL_FILLED_ON_LAST_INPUT: ({ isFullFilled, isChangeOnLastInput, isEnter, }: import("./types").InputOTPFinishBehaviorContext) => boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var INPUT_OTP_VALIDATE_PRESET = {
|
|
2
|
+
TEXT: function (value) { return /[a-zA-Z]{1}/.test(value); },
|
|
3
|
+
NUMERIC: function (value) { return /\d{1}/.test(value); },
|
|
4
|
+
TEXT_NUMERIC: function (value) { return /[a-zA-Z0-9]{1}/.test(value); },
|
|
5
|
+
};
|
|
6
|
+
export var INPUT_OTP_MASK_PRESET = {
|
|
7
|
+
PASSWORD: '•',
|
|
8
|
+
};
|
|
9
|
+
export var INPUT_OTP_FINISH_BEHAVIOR_PRESET = {
|
|
10
|
+
FULL_FILLED_NON_LAST_INPUT: function (_a) {
|
|
11
|
+
var isFullFilled = _a.isFullFilled;
|
|
12
|
+
return isFullFilled;
|
|
13
|
+
},
|
|
14
|
+
FULL_FILLED_ON_LAST_INPUT: function (_a) {
|
|
15
|
+
var isFullFilled = _a.isFullFilled, isChangeOnLastInput = _a.isChangeOnLastInput, isEnter = _a.isEnter;
|
|
16
|
+
if (isFullFilled && isChangeOnLastInput) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (isFullFilled && isEnter) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { ComponentPropsWithRef, ElementType } from 'react';
|
|
2
|
+
import type { PolymorphicComponentPropsWithRef } from '../../utils/polymorphicComponentWithRef';
|
|
3
|
+
import type { FIELD_CONTROL_DEFAULT_TAG, FieldControlBaseProps } from '../FieldControl';
|
|
4
|
+
import type { FieldInputProps } from '../FieldInput';
|
|
5
|
+
import type { INPUT_OTP_DEFAULT_TAG } from './constants';
|
|
6
|
+
export declare const inputOTPAutoCompleteMode: readonly ["firstOnly", "all"];
|
|
7
|
+
export type InputOTPAutoCompleteMode = (typeof inputOTPAutoCompleteMode)[number];
|
|
8
|
+
export declare const inputOTPSizeVariant: readonly ["s", "m"];
|
|
9
|
+
export type InputOTPSizeVariant = (typeof inputOTPSizeVariant)[number];
|
|
10
|
+
export type InputOTPValidate = (value: string) => boolean;
|
|
11
|
+
export type InputOTPRawValue = string[];
|
|
12
|
+
export type InputOTPValue = InputOTPRawValue | string;
|
|
13
|
+
export type InputOTPOnChange = (value: string, rawValue: InputOTPRawValue, maskedValue: string, maskedRawValue: InputOTPRawValue) => void;
|
|
14
|
+
export type InputOTPOnFinish = (value: string, rawValue: InputOTPRawValue, maskedValue: string, maskedRawValue: InputOTPRawValue) => void;
|
|
15
|
+
export type InputOTPInputs = HTMLInputElement[];
|
|
16
|
+
export type InputOTPInputProps = FieldInputProps;
|
|
17
|
+
export type InputOTPCalculatedInput = {
|
|
18
|
+
/** Значение input */
|
|
19
|
+
value: string;
|
|
20
|
+
/** Необработанное input */
|
|
21
|
+
rawValue: string;
|
|
22
|
+
/** Флаг: это предыдущий input */
|
|
23
|
+
isPrevious: boolean;
|
|
24
|
+
/** Флаг: это следующий input */
|
|
25
|
+
isNext: boolean;
|
|
26
|
+
/** Флаг: это текущий input */
|
|
27
|
+
isCurrentInput: boolean;
|
|
28
|
+
/** Флаг: это последний input */
|
|
29
|
+
isLast: boolean;
|
|
30
|
+
/** Флаг: input отключен */
|
|
31
|
+
isDisabled: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type InputOTPMask = string | ((value: string, index: number) => string);
|
|
34
|
+
export type InputOTPFinishBehaviorContext = {
|
|
35
|
+
/** Флаг: Поле полностью заполнено */
|
|
36
|
+
isFullFilled: boolean;
|
|
37
|
+
/** Значение */
|
|
38
|
+
value: string;
|
|
39
|
+
/** Необработанное значение */
|
|
40
|
+
rawValue: InputOTPRawValue;
|
|
41
|
+
/** Значение с маской */
|
|
42
|
+
maskedValue: string;
|
|
43
|
+
/** Необработанное значение с маской */
|
|
44
|
+
maskedRawValue: InputOTPRawValue;
|
|
45
|
+
/** Флаг: Это изменение на последнем input'е */
|
|
46
|
+
isChangeOnLastInput: boolean;
|
|
47
|
+
/** index input'а, на котором произошло изменение */
|
|
48
|
+
inputIndex: number;
|
|
49
|
+
/** Флаг: Был нажат enter */
|
|
50
|
+
isEnter: boolean;
|
|
51
|
+
};
|
|
52
|
+
export type InputOTPFinishBehavior = (context: InputOTPFinishBehaviorContext) => boolean;
|
|
53
|
+
export type InputOTPDynamicInputParameter<Parameter> = Parameter | ((calculatedInput: InputOTPCalculatedInput, index: number) => Parameter);
|
|
54
|
+
export type InputOTPBaseProps = {
|
|
55
|
+
/** Длина кода */
|
|
56
|
+
length: number;
|
|
57
|
+
/** Значение */
|
|
58
|
+
value?: InputOTPValue;
|
|
59
|
+
/** Значение по умолчанию */
|
|
60
|
+
defaultValue?: InputOTPValue;
|
|
61
|
+
/** Обработчик события на изменение значения поля */
|
|
62
|
+
onChange?: InputOTPOnChange;
|
|
63
|
+
/** Обработчик события на завершение ввода */
|
|
64
|
+
onFinish?: InputOTPOnFinish;
|
|
65
|
+
/** Маска значения */
|
|
66
|
+
mask?: InputOTPMask;
|
|
67
|
+
/** autoComplete */
|
|
68
|
+
autoComplete?: InputOTPInputProps['autoComplete'];
|
|
69
|
+
/**
|
|
70
|
+
* Мод autoComplete.
|
|
71
|
+
* В зависимости от режима, autoComplete будет устанавливаться разным input
|
|
72
|
+
*/
|
|
73
|
+
autoCompleteMode?: InputOTPAutoCompleteMode;
|
|
74
|
+
/** Если `true` переводит поле в состояние ошибки */
|
|
75
|
+
error?: boolean;
|
|
76
|
+
/** Если `true` делает элемент неактивным */
|
|
77
|
+
disabled?: boolean;
|
|
78
|
+
/** Функция-валидатор */
|
|
79
|
+
validate?: InputOTPValidate;
|
|
80
|
+
/** Размер */
|
|
81
|
+
size?: InputOTPSizeVariant;
|
|
82
|
+
/** Лейбл */
|
|
83
|
+
ariaLabel?: string;
|
|
84
|
+
/** Если `true` отключает обводку */
|
|
85
|
+
disableStroke?: boolean;
|
|
86
|
+
/** Подсказка. Отображается, когда значение не введено */
|
|
87
|
+
placeholder?: InputOTPDynamicInputParameter<string>;
|
|
88
|
+
/** Свойства Field */
|
|
89
|
+
fieldProps?: InputOTPDynamicInputParameter<PolymorphicComponentPropsWithRef<FieldControlBaseProps, typeof FIELD_CONTROL_DEFAULT_TAG>>;
|
|
90
|
+
/** Свойства Input */
|
|
91
|
+
inputProps?: InputOTPDynamicInputParameter<FieldInputProps>;
|
|
92
|
+
/** Свойства InputContainer */
|
|
93
|
+
inputContainerProps?: InputOTPDynamicInputParameter<ComponentPropsWithRef<'div'> & {
|
|
94
|
+
'data-testid'?: string;
|
|
95
|
+
}>;
|
|
96
|
+
/** Функция, которая определяет поведение финиша */
|
|
97
|
+
finishBehavior?: InputOTPFinishBehavior;
|
|
98
|
+
/** data-атрибут для тестирования */
|
|
99
|
+
'data-testid'?: string;
|
|
100
|
+
};
|
|
101
|
+
export type InputOTPProps<As extends ElementType = typeof INPUT_OTP_DEFAULT_TAG> = PolymorphicComponentPropsWithRef<InputOTPBaseProps, As>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __assign, __read, __rest } from "tslib";
|
|
2
2
|
import './Tabs.css';
|
|
3
3
|
import React, { useState, useCallback, useMemo, useEffect, forwardRef, useRef, } from 'react';
|
|
4
|
+
import { isFragment } from 'react-is';
|
|
4
5
|
import { useDebounceCallback } from '../../hooks/useDebounceCallback';
|
|
5
6
|
import { useEventListener } from '../../hooks/useEventListener';
|
|
6
7
|
import { animateProperty } from '../../utils/animateProperty';
|
|
@@ -28,9 +29,12 @@ export var Tabs = forwardRef(function (_a, ref) {
|
|
|
28
29
|
* для более точного контроля
|
|
29
30
|
*/
|
|
30
31
|
var tabsValueToIndex = useMemo(function () { return new Map(); }, [children]);
|
|
32
|
+
var resolvedChildren = isFragment(children)
|
|
33
|
+
? children.props.children
|
|
34
|
+
: children;
|
|
31
35
|
/** Children только ноды Табов */
|
|
32
36
|
var onlyTabsChildren = useMemo(function () {
|
|
33
|
-
return React.Children.toArray(
|
|
37
|
+
return React.Children.toArray(resolvedChildren)
|
|
34
38
|
.filter(function (child) { return React.isValidElement(child) && (child === null || child === void 0 ? void 0 : child.type) === Tab; })
|
|
35
39
|
.map(function (child, index) {
|
|
36
40
|
if (!React.isValidElement(child))
|
|
@@ -39,7 +43,7 @@ export var Tabs = forwardRef(function (_a, ref) {
|
|
|
39
43
|
tabsValueToIndex.set(childValue, index);
|
|
40
44
|
return React.cloneElement(child, { value: childValue });
|
|
41
45
|
});
|
|
42
|
-
}, [
|
|
46
|
+
}, [resolvedChildren]);
|
|
43
47
|
var isScrollButtonsActive = variant === 'scrollable' &&
|
|
44
48
|
!disableScrollButtons &&
|
|
45
49
|
tabsListRef.current &&
|
|
@@ -111,6 +111,7 @@ export type Theme = {
|
|
|
111
111
|
Indicator?: Partial<IndicatorProps>;
|
|
112
112
|
Input?: Partial<InputProps>;
|
|
113
113
|
InputNumber?: Partial<InputNumberProps>;
|
|
114
|
+
InputOTP?: Partial<InputProps>;
|
|
114
115
|
Link?: Partial<LinkProps>;
|
|
115
116
|
List?: Partial<ListProps>;
|
|
116
117
|
ListItem?: Partial<ListItemProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMemo, useRef } from 'react';
|
|
2
|
+
import { isFunction } from '../../utils/isFunction';
|
|
3
|
+
export function useStoredValue(
|
|
4
|
+
/** Изначальное значение */
|
|
5
|
+
initialValue) {
|
|
6
|
+
var processedInitialValue = useMemo(function () {
|
|
7
|
+
if (isFunction(initialValue)) {
|
|
8
|
+
return initialValue();
|
|
9
|
+
}
|
|
10
|
+
return initialValue;
|
|
11
|
+
}, []);
|
|
12
|
+
return useRef(processedInitialValue);
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createEmptyArray: (length: number) => null[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createEmptyArray';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createEmptyArray';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createFilledArray: <Value>(length: number, value: Value) => Value[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createFilledArray';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './createFilledArray';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isFunction: (data: unknown) => data is (...args: any[]) => any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ozen-ui/kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.0",
|
|
4
4
|
"description": "React component library",
|
|
5
5
|
"files": [
|
|
6
6
|
"*"
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"react-popper": "^2.3.0",
|
|
28
28
|
"react-transition-group": "^4.4.5",
|
|
29
29
|
"tslib": "^2.6.3",
|
|
30
|
-
"@ozen-ui/
|
|
31
|
-
"@ozen-ui/icons": "0.
|
|
32
|
-
"@ozen-ui/
|
|
30
|
+
"@ozen-ui/fonts": "0.64.0",
|
|
31
|
+
"@ozen-ui/icons": "0.64.0",
|
|
32
|
+
"@ozen-ui/logger": "0.64.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=17.0.2 <19.0.0",
|