@via-profit/ui-kit 0.2.1-alpha.3 → 0.2.3
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/Autocomplete/AutocompleteContainer.d.ts +5 -4
- package/Autocomplete/AutocompleteContainer.js +146 -152
- package/Autocomplete/AutocompleteItem.js +1 -1
- package/Autocomplete/context.d.ts +3 -5
- package/Autocomplete/context.js +22 -14
- package/CountryFlags/SwiperOverview.d.ts +257 -0
- package/CountryFlags/SwiperOverview.js +524 -0
- package/Highlighted/index.js +10 -5
- package/Highlighted/splitTextIntoParts.d.ts +5 -0
- package/Highlighted/splitTextIntoParts.js +46 -0
- package/MaskedField/index.d.ts +1 -0
- package/MaskedField/index.js +44 -36
- package/MaskedField/useMasked.js +7 -5
- package/Menu/MenuContainer.d.ts +24 -2
- package/Menu/MenuContainer.js +194 -243
- package/Menu/MenuList.d.ts +1 -0
- package/Menu/MenuList.js +15 -16
- package/Popper/Popper.d.ts +3 -2
- package/Popper/Popper.js +9 -7
- package/Popper/PopperContainer.d.ts +0 -1
- package/Popper/PopperContainer.js +8 -3
- package/Popper/index.d.ts +1 -1
- package/Popper/index.js +1 -1
- package/Popper/usePopper.d.ts +111 -0
- package/Popper/usePopper.js +522 -0
- package/Selectbox/SelectboxButton.js +2 -27
- package/Selectbox/SelectboxMenu.d.ts +0 -2
- package/Selectbox/SelectboxMenu.js +13 -5
- package/Selectbox/index.d.ts +5 -3
- package/Selectbox/index.js +4 -4
- package/Swiper/Swiper.d.ts +28 -17
- package/Swiper/Swiper.js +294 -38
- package/Swiper/SwiperContainer.d.ts +3 -3
- package/Swiper/SwiperContainer.js +1 -0
- package/Swiper/SwiperSlide.d.ts +10 -5
- package/Swiper/SwiperSlide.js +6 -3
- package/Swiper/SwiperSlidesRenderer.d.ts +11 -0
- package/Swiper/SwiperSlidesRenderer.js +74 -0
- package/Swiper/SwiperTrack.d.ts +4 -0
- package/Swiper/SwiperTrack.js +4 -7
- package/Swiper/SwiperWrapper.d.ts +2 -0
- package/package.json +1 -1
package/MaskedField/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
17
|
var t = {};
|
|
4
18
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -17,61 +31,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
31
|
const react_1 = __importDefault(require("react"));
|
|
18
32
|
const useMasked_1 = require("./useMasked");
|
|
19
33
|
const TextField_1 = __importDefault(require("../TextField"));
|
|
34
|
+
__exportStar(require("./useMasked"), exports);
|
|
20
35
|
const MaskedField = (props, ref) => {
|
|
21
36
|
const { value: propValue, mask, parseInput, onChange, transform } = props, nativeProps = __rest(props, ["value", "mask", "parseInput", "onChange", "transform"]);
|
|
22
|
-
const propValueRef = react_1.default.useRef(propValue);
|
|
23
|
-
const textInputRef = react_1.default.useRef(null);
|
|
24
|
-
const decoratorsErrorDisplayed = react_1.default.useRef(false);
|
|
25
37
|
const masked = (0, useMasked_1.useMasked)();
|
|
26
38
|
const parseInputFn = parseInput || masked.parseInput;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
currentMask.find(elem => typeof elem === 'string' &&
|
|
31
|
-
typeof parseInput === 'undefined' &&
|
|
32
|
-
elem.match(/[0-9a-zа-яё]/i))) {
|
|
33
|
-
decoratorsErrorDisplayed.current = true;
|
|
34
|
-
console.warn('[MaskedField component] You use symbols as decorators, which should be replaced with RegExp or provide the «parseInput» function instead');
|
|
35
|
-
}
|
|
36
|
-
return currentMask;
|
|
37
|
-
}, [mask, parseInput]);
|
|
39
|
+
const inputRef = react_1.default.useRef(null);
|
|
40
|
+
const lastPropValue = react_1.default.useRef(propValue);
|
|
41
|
+
const getMask = react_1.default.useCallback((input) => (typeof mask === 'function' ? mask(input) : mask), [mask]);
|
|
38
42
|
const getInputValue = react_1.default.useCallback((v) => {
|
|
39
43
|
var _a;
|
|
40
|
-
const
|
|
41
|
-
const parsed = parseInputFn(v
|
|
42
|
-
const
|
|
43
|
-
return text;
|
|
44
|
-
}, [getMask,
|
|
44
|
+
const m = getMask(v);
|
|
45
|
+
const parsed = parseInputFn(v, m, ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) || 0);
|
|
46
|
+
const formatted = masked.formatParsedInput(parsed.text, m, parsed.caret);
|
|
47
|
+
return formatted.text;
|
|
48
|
+
}, [getMask, parseInputFn, masked]);
|
|
45
49
|
const [inputValue, setInputValue] = react_1.default.useState(getInputValue(propValue || ''));
|
|
50
|
+
// Обновление при изменении внешнего значения
|
|
46
51
|
react_1.default.useEffect(() => {
|
|
47
|
-
if (
|
|
48
|
-
|
|
52
|
+
if (lastPropValue.current !== propValue) {
|
|
53
|
+
lastPropValue.current = propValue;
|
|
49
54
|
setInputValue(getInputValue(propValue || ''));
|
|
50
55
|
}
|
|
51
|
-
}, [
|
|
56
|
+
}, [propValue, getInputValue]);
|
|
52
57
|
const handleOnChange = react_1.default.useCallback(event => {
|
|
53
58
|
var _a;
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
+
const raw = event.currentTarget.value;
|
|
60
|
+
const caret = ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) || 0;
|
|
61
|
+
const m = getMask(raw);
|
|
62
|
+
const parsed = parseInputFn(raw, m, caret);
|
|
63
|
+
const formatted = masked.formatParsedInput(parsed.text, m, parsed.caret);
|
|
64
|
+
const finalText = transform ? transform(formatted.text) : formatted.text;
|
|
65
|
+
setInputValue(finalText);
|
|
59
66
|
onChange({
|
|
60
|
-
caret,
|
|
61
|
-
isValid,
|
|
62
|
-
text:
|
|
67
|
+
caret: formatted.caret,
|
|
68
|
+
isValid: formatted.isValid,
|
|
69
|
+
text: finalText,
|
|
63
70
|
});
|
|
64
|
-
|
|
71
|
+
// Устанавливаем caret после рендера
|
|
72
|
+
requestAnimationFrame(() => {
|
|
65
73
|
var _a;
|
|
66
|
-
(_a =
|
|
67
|
-
}
|
|
68
|
-
}, [getMask, masked, transform, onChange
|
|
74
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(formatted.caret, formatted.caret);
|
|
75
|
+
});
|
|
76
|
+
}, [getMask, parseInputFn, masked, transform, onChange]);
|
|
69
77
|
const setInputRef = react_1.default.useCallback((elem) => {
|
|
70
|
-
|
|
78
|
+
inputRef.current = elem;
|
|
71
79
|
if (typeof nativeProps.inputRef === 'function') {
|
|
72
80
|
nativeProps.inputRef(elem);
|
|
73
81
|
}
|
|
74
|
-
if (nativeProps.inputRef
|
|
82
|
+
else if (nativeProps.inputRef && typeof nativeProps.inputRef === 'object') {
|
|
75
83
|
nativeProps.inputRef.current = elem;
|
|
76
84
|
}
|
|
77
85
|
}, [nativeProps]);
|
package/MaskedField/useMasked.js
CHANGED
|
@@ -12,13 +12,12 @@ const useMasked = () => {
|
|
|
12
12
|
caret: 0,
|
|
13
13
|
};
|
|
14
14
|
value
|
|
15
|
-
.replace(/\s
|
|
15
|
+
.replace(/\s+/g, '')
|
|
16
16
|
.split('')
|
|
17
17
|
.forEach((character, charIndex) => {
|
|
18
18
|
const isMatch = mask.some(pattern => {
|
|
19
19
|
if (typeof pattern === 'string') {
|
|
20
|
-
return
|
|
21
|
-
// return character === pattern && character;
|
|
20
|
+
return character === pattern && character;
|
|
22
21
|
}
|
|
23
22
|
if (pattern instanceof RegExp) {
|
|
24
23
|
return new RegExp(pattern).test(character);
|
|
@@ -45,7 +44,9 @@ const useMasked = () => {
|
|
|
45
44
|
if (parsedValue === '') {
|
|
46
45
|
return data;
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
let patternIndex = 0;
|
|
48
|
+
for (patternIndex = 0; patternIndex < mask.length; patternIndex++) {
|
|
49
|
+
data.isValid = false;
|
|
49
50
|
if (data.charIndex >= parsedValue.length) {
|
|
50
51
|
break;
|
|
51
52
|
}
|
|
@@ -57,6 +58,7 @@ const useMasked = () => {
|
|
|
57
58
|
if (pattern instanceof RegExp && new RegExp(pattern).test(char)) {
|
|
58
59
|
data.text = `${data.text}${char}`;
|
|
59
60
|
data.charIndex += 1;
|
|
61
|
+
data.isValid = true;
|
|
60
62
|
}
|
|
61
63
|
// If char is correct (equal with pattern string)
|
|
62
64
|
// then accept char into text
|
|
@@ -79,7 +81,7 @@ const useMasked = () => {
|
|
|
79
81
|
const result = {
|
|
80
82
|
text: data.text,
|
|
81
83
|
caret: data.caret,
|
|
82
|
-
isValid: data.
|
|
84
|
+
isValid: data.isValid,
|
|
83
85
|
};
|
|
84
86
|
return result;
|
|
85
87
|
}, []);
|
package/Menu/MenuContainer.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ export interface MenuProps<T, Multiple extends boolean | undefined = undefined>
|
|
|
90
90
|
* Default: `bottom`
|
|
91
91
|
*/
|
|
92
92
|
readonly anchorPos?: AnchorPos;
|
|
93
|
+
readonly alternativePlacements?: readonly AnchorPos[];
|
|
93
94
|
readonly onAnchorPosChanged?: (anchorPos: AnchorPos) => void;
|
|
94
95
|
/**
|
|
95
96
|
* When enabled, the popper will automatically try to find the best placement
|
|
@@ -164,6 +165,28 @@ export interface MenuProps<T, Multiple extends boolean | undefined = undefined>
|
|
|
164
165
|
* The function that will be called at the moment when you want to close the menu
|
|
165
166
|
*/
|
|
166
167
|
readonly onRequestClose?: OnRequestClose;
|
|
168
|
+
/**
|
|
169
|
+
* List menu maximum width (px, em, etc.)\
|
|
170
|
+
* Using pixels:
|
|
171
|
+
* ```tsx
|
|
172
|
+
* <Menu
|
|
173
|
+
* maxWidth={250}
|
|
174
|
+
* >
|
|
175
|
+
* ```
|
|
176
|
+
* Using em:
|
|
177
|
+
* ```tsx
|
|
178
|
+
* <Menu
|
|
179
|
+
* maxWidth="16em"
|
|
180
|
+
* >
|
|
181
|
+
* ```
|
|
182
|
+
* Using pixels:
|
|
183
|
+
* ```tsx
|
|
184
|
+
* <Menu
|
|
185
|
+
* maxWidth="16px"
|
|
186
|
+
* >
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
readonly maxWidth?: number | string;
|
|
167
190
|
}
|
|
168
191
|
export interface MenuOverrides {
|
|
169
192
|
/**
|
|
@@ -220,9 +243,8 @@ export type MenuRef = {
|
|
|
220
243
|
* Returns the list HTML container
|
|
221
244
|
*/
|
|
222
245
|
getListElement: () => HTMLDivElement | null;
|
|
223
|
-
setActualPlacement: (placement: AnchorPos) => void;
|
|
224
246
|
};
|
|
225
|
-
export type Value<T, Multiple> = Multiple extends undefined
|
|
247
|
+
export type Value<T, Multiple> = Multiple extends undefined ? T | null : readonly T[];
|
|
226
248
|
export type GetOptionSelected<T> = (payload: {
|
|
227
249
|
readonly item: T;
|
|
228
250
|
readonly value: T;
|