@sima-land/ui-nucleons 44.2.9 → 45.0.0-alpha.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/_internal/custom-scrollbar/index.d.ts +13 -7
- package/_internal/custom-scrollbar/index.js +29 -15
- package/_internal/dropdown-loading/index.d.ts +3 -3
- package/_internal/dropdown-loading/index.js +4 -2
- package/_internal/page-scroll-lock/adapters/body-scroll-lock.d.ts +39 -0
- package/_internal/page-scroll-lock/adapters/body-scroll-lock.js +62 -0
- package/_internal/page-scroll-lock/adapters/ui-nucleons.d.ts +25 -0
- package/_internal/page-scroll-lock/adapters/ui-nucleons.js +103 -0
- package/_internal/page-scroll-lock/context.d.ts +13 -0
- package/_internal/page-scroll-lock/context.js +54 -0
- package/_internal/page-scroll-lock/hook.d.ts +12 -0
- package/_internal/page-scroll-lock/hook.js +26 -0
- package/_internal/page-scroll-lock/index.d.ts +4 -0
- package/_internal/page-scroll-lock/index.js +9 -0
- package/_internal/page-scroll-lock/types.d.ts +22 -0
- package/_internal/{checkbox/index.js → page-scroll-lock/types.js} +0 -0
- package/_internal/readme.md +2 -0
- package/_internal/utils/dropdown.d.ts +1 -0
- package/_internal/utils/dropdown.js +1 -0
- package/alert/alert.module.scss +1 -24
- package/alert/index.d.ts +11 -17
- package/alert/index.js +33 -16
- package/arrow-button/arrow-button.module.scss +2 -0
- package/arrow-button/index.d.ts +2 -2
- package/autocomplete/autocomplete.d.ts +8 -0
- package/autocomplete/autocomplete.js +190 -0
- package/autocomplete/autocomplete.module.scss +2 -15
- package/autocomplete/index.d.ts +2 -27
- package/autocomplete/index.js +2 -126
- package/autocomplete/types.d.ts +19 -0
- package/autocomplete/types.js +2 -0
- package/autocomplete-deprecated/autocomplete.module.scss +20 -0
- package/autocomplete-deprecated/index.d.ts +28 -0
- package/autocomplete-deprecated/index.js +130 -0
- package/avatar/index.d.ts +2 -2
- package/avatar/user.d.ts +1 -1
- package/base-input/base-input.d.ts +11 -0
- package/base-input/base-input.js +96 -0
- package/base-input/base-input.module.scss +3 -3
- package/base-input/index.d.ts +2 -23
- package/base-input/index.js +2 -76
- package/base-input/types.d.ts +31 -0
- package/base-input/types.js +2 -0
- package/base-input/utils.d.ts +6 -0
- package/base-input/utils.js +14 -0
- package/base-input-deprecated/base-input.module.scss +66 -0
- package/base-input-deprecated/index.d.ts +24 -0
- package/base-input-deprecated/index.js +80 -0
- package/bordered-layout/index.d.ts +1 -0
- package/bordered-layout/index.js +1 -0
- package/bottom-bar/bottom-bar-util.scss +20 -0
- package/bottom-bar/bottom-bar.d.ts +12 -0
- package/bottom-bar/bottom-bar.js +47 -0
- package/bottom-bar/bottom-bar.module.scss +14 -0
- package/bottom-bar/index.d.ts +2 -21
- package/bottom-bar/index.js +5 -44
- package/bottom-bar/types.d.ts +10 -0
- package/bottom-bar/types.js +2 -0
- package/box/index.d.ts +1 -1
- package/breakpoints.scss +1 -1
- package/button/button.module.scss +70 -53
- package/button/index.d.ts +26 -41
- package/button/index.js +22 -46
- package/card/index.d.ts +2 -1
- package/card/index.js +23 -6
- package/card/slots.d.ts +17 -3
- package/card/slots.js +15 -13
- package/carousel/draggable.d.ts +7 -3
- package/carousel/draggable.js +10 -3
- package/carousel/helpers/draggable-event.d.ts +5 -2
- package/carousel/helpers/draggable-event.js +5 -0
- package/carousel/index.d.ts +1 -1
- package/carousel/index.js +24 -24
- package/checkbox/checkbox.module.scss +2 -0
- package/checkbox/index.d.ts +3 -3
- package/checkbox-field/index.d.ts +3 -0
- package/checkbox-field/index.js +3 -0
- package/clean-buttons/clean-buttons-util.scss +15 -0
- package/clean-buttons/clean-buttons.module.scss +5 -3
- package/clean-buttons/index.d.ts +16 -7
- package/clean-buttons/index.js +17 -14
- package/clean-buttons/types.d.ts +1 -1
- package/clean-buttons/utils.d.ts +5 -1
- package/clean-buttons/utils.js +4 -0
- package/{colors.d.ts → colors/index.d.ts} +1 -1
- package/{colors.js → colors/index.js} +0 -0
- package/dot-nav/index.d.ts +1 -1
- package/dropdown/index.d.ts +1 -0
- package/dropdown/utils.d.ts +19 -0
- package/dropdown/utils.js +45 -0
- package/dropdown-item/dropdown-item.module.scss +80 -15
- package/dropdown-item/index.d.ts +20 -9
- package/dropdown-item/index.js +12 -9
- package/dropdown-item/types.d.ts +3 -0
- package/dropdown-item/types.js +2 -0
- package/dropdown-item/utils.d.ts +45 -0
- package/dropdown-item/utils.js +89 -0
- package/expandable/utils.js +3 -3
- package/field-block/field-block.module.scss +155 -0
- package/field-block/index.d.ts +63 -0
- package/field-block/index.js +43 -0
- package/field-grid/index.d.ts +5 -4
- package/field-grid/index.js +1 -0
- package/helpers/bounds-of.d.ts +5 -1
- package/helpers/bounds-of.js +5 -0
- package/helpers/center-of.d.ts +4 -1
- package/helpers/center-of.js +8 -1
- package/helpers/create-container.d.ts +5 -2
- package/helpers/create-container.js +7 -2
- package/helpers/define-slots.d.ts +3 -3
- package/helpers/define-slots.js +5 -3
- package/helpers/events.d.ts +16 -8
- package/helpers/events.js +41 -15
- package/helpers/find-child-element.d.ts +12 -9
- package/helpers/find-child-element.js +9 -5
- package/helpers/find-offset-parent.d.ts +1 -2
- package/helpers/find-offset-parent.js +2 -2
- package/helpers/find-sibling-index.d.ts +11 -8
- package/helpers/find-sibling-index.js +8 -3
- package/helpers/fit-element-height.d.ts +5 -5
- package/helpers/fit-element-height.js +9 -7
- package/helpers/format-date.d.ts +11 -11
- package/helpers/format-date.js +15 -13
- package/helpers/format-number.d.ts +1 -1
- package/helpers/format-number.js +2 -2
- package/helpers/get-date-interval-data.d.ts +4 -1
- package/helpers/get-date-interval-data.js +7 -2
- package/helpers/get-declination.d.ts +5 -1
- package/helpers/get-declination.js +5 -0
- package/helpers/get-fraction-depth.d.ts +1 -1
- package/helpers/get-fraction-depth.js +2 -2
- package/helpers/get-no-index.d.ts +2 -2
- package/helpers/get-no-index.js +4 -3
- package/helpers/get-relative-pos.d.ts +4 -1
- package/helpers/get-relative-pos.js +7 -2
- package/helpers/get-scroll-parent.d.ts +1 -2
- package/helpers/get-scroll-parent.js +5 -5
- package/helpers/is-browser.d.ts +4 -1
- package/helpers/is-browser.js +8 -1
- package/helpers/is-fully-scrolled.d.ts +3 -3
- package/helpers/is-fully-scrolled.js +2 -2
- package/helpers/is-touch-device.d.ts +1 -1
- package/helpers/is-touch-device.js +4 -5
- package/helpers/layer.d.ts +1 -1
- package/helpers/layer.js +2 -2
- package/helpers/max-index-of.d.ts +4 -1
- package/helpers/max-index-of.js +7 -2
- package/helpers/media-query-list.d.ts +1 -1
- package/helpers/media-query-list.js +2 -2
- package/helpers/on.d.ts +4 -1
- package/helpers/on.js +7 -2
- package/helpers/point.d.ts +4 -1
- package/helpers/point.js +8 -1
- package/helpers/rename.d.ts +3 -1
- package/helpers/rename.js +1 -0
- package/helpers/scroll-to-child.d.ts +1 -1
- package/helpers/scroll-to-child.js +3 -2
- package/helpers/styles.d.ts +8 -2
- package/helpers/styles.js +18 -4
- package/helpers/with-prevent.d.ts +9 -6
- package/helpers/with-prevent.js +16 -9
- package/hint/hint-view.d.ts +26 -0
- package/hint/hint-view.js +43 -0
- package/hint/hint-view.module.scss +31 -0
- package/hint/hint.d.ts +14 -0
- package/hint/hint.js +41 -0
- package/hint/index.d.ts +5 -8
- package/hint/index.js +13 -48
- package/hint/utils.d.ts +61 -0
- package/hint/utils.js +161 -0
- package/{hint → hint-deprecated}/hint.module.scss +0 -0
- package/hint-deprecated/index.d.ts +11 -0
- package/hint-deprecated/index.js +53 -0
- package/hooks/breakpoint/index.d.ts +7 -4
- package/hooks/breakpoint/index.js +21 -13
- package/hooks/breakpoint/types.d.ts +3 -4
- package/hooks/breakpoint/utils.d.ts +2 -1
- package/hooks/breakpoint/utils.js +2 -1
- package/hooks/index.d.ts +8 -8
- package/hooks/index.js +27 -19
- package/hooks/intersection/test-utils.d.ts +1 -1
- package/hooks/intersection/test-utils.js +2 -1
- package/hooks/styles.d.ts +6 -0
- package/hooks/styles.js +26 -0
- package/info-text/index.d.ts +23 -0
- package/info-text/index.js +60 -0
- package/info-text/info-text.module.scss +28 -0
- package/input/index.d.ts +32 -0
- package/input/index.js +96 -0
- package/input/input.module.scss +20 -0
- package/input/utils.d.ts +36 -0
- package/input/utils.js +71 -0
- package/layout/index.d.ts +6 -11
- package/layout/index.js +6 -60
- package/layout/layout.d.ts +10 -0
- package/layout/layout.js +32 -0
- package/layout/layout.module.scss +33 -26
- package/layout/legacy.d.ts +15 -0
- package/layout/legacy.js +68 -0
- package/layout/legacy.module.scss +49 -0
- package/layout/types.d.ts +6 -0
- package/layout/types.js +2 -0
- package/link/index.d.ts +4 -1
- package/link/index.js +2 -2
- package/link/link.module.scss +10 -0
- package/loading-overlay/index.d.ts +1 -0
- package/loading-overlay/index.js +1 -0
- package/masked-field/index.d.ts +1 -0
- package/masked-field/index.js +1 -0
- package/masked-input/hook.d.ts +8 -0
- package/masked-input/hook.js +72 -0
- package/masked-input/index.d.ts +5 -0
- package/masked-input/index.js +7 -0
- package/masked-input/masked-input.d.ts +8 -0
- package/masked-input/masked-input.js +73 -0
- package/masked-input/types.d.ts +51 -0
- package/masked-input/types.js +2 -0
- package/masked-input/utils.d.ts +15 -0
- package/masked-input/utils.js +49 -0
- package/modal/index.d.ts +10 -12
- package/modal/index.js +27 -64
- package/modal/modal.module.scss +98 -55
- package/modal/slots.d.ts +13 -10
- package/modal/slots.js +30 -28
- package/modal/utils.d.ts +8 -10
- package/modal/utils.js +2 -26
- package/modal-overlay/index.d.ts +13 -0
- package/modal-overlay/index.js +60 -0
- package/modal-overlay/modal-overlay-util.scss +1 -0
- package/modal-overlay/modal-overlay.module.scss +14 -0
- package/modal-overlay/utils.d.ts +14 -0
- package/modal-overlay/utils.js +32 -0
- package/package.json +49 -41
- package/pagination/utils.d.ts +2 -2
- package/panel/index.d.ts +27 -13
- package/panel/index.js +43 -9
- package/panel/panel.module.scss +49 -8
- package/phone-input/index.d.ts +4 -28
- package/phone-input/index.js +2 -121
- package/phone-input/phone-input.d.ts +8 -0
- package/phone-input/phone-input.js +133 -0
- package/phone-input/phone-input.module.scss +8 -32
- package/phone-input/presets.d.ts +21 -22
- package/phone-input/presets.js +1 -2
- package/phone-input/types.d.ts +6 -0
- package/phone-input/types.js +2 -0
- package/phone-input/utils.d.ts +30 -1
- package/phone-input/utils.js +52 -3
- package/phone-input-deprecated/index.d.ts +29 -0
- package/phone-input-deprecated/index.js +124 -0
- package/phone-input-deprecated/phone-input.module.scss +41 -0
- package/plate/index.d.ts +3 -3
- package/plate/index.js +2 -2
- package/plate/plate.module.scss +3 -0
- package/popup/index.d.ts +5 -0
- package/popup/index.js +12 -0
- package/popup/popup-view.d.ts +14 -0
- package/popup/popup-view.js +35 -0
- package/popup/popup-view.module.scss +40 -0
- package/popup/popup.d.ts +17 -0
- package/popup/popup.js +73 -0
- package/popup/utils.d.ts +38 -0
- package/popup/utils.js +83 -0
- package/price/index.d.ts +1 -1
- package/price/index.js +3 -3
- package/price/utils.d.ts +5 -5
- package/price/utils.js +33 -23
- package/radio-button/index.d.ts +10 -0
- package/radio-button/index.js +33 -0
- package/radio-button/radio-button.module.scss +46 -0
- package/rating/index.d.ts +2 -1
- package/rating/types.d.ts +1 -1
- package/readme.md +34 -41
- package/screen/index.d.ts +4 -2
- package/screen/index.js +34 -3
- package/screen/screen.module.scss +0 -2
- package/screen/slots.d.ts +2 -8
- package/screen/slots.js +8 -9
- package/screen/utils.d.ts +2 -1
- package/select/index.d.ts +2 -33
- package/select/index.js +3 -109
- package/select/parts/block.d.ts +8 -0
- package/select/parts/block.js +70 -0
- package/select/parts/block.module.scss +3 -0
- package/select/parts/button.d.ts +8 -0
- package/select/parts/button.js +69 -0
- package/select/parts/menu.d.ts +8 -0
- package/select/parts/menu.js +105 -0
- package/select/parts/menu.module.scss +4 -0
- package/select/select.d.ts +14 -0
- package/select/select.js +145 -0
- package/select/types.d.ts +55 -0
- package/select/types.js +2 -0
- package/select/utils.d.ts +3 -0
- package/select/utils.js +13 -0
- package/select-deprecated/index.d.ts +34 -0
- package/select-deprecated/index.js +112 -0
- package/{select → select-deprecated}/select.module.scss +0 -0
- package/shadows.scss +18 -0
- package/side-page/index.d.ts +11 -26
- package/side-page/index.js +21 -26
- package/side-page/side-page.module.scss +35 -29
- package/side-page/slots.d.ts +12 -20
- package/side-page/slots.js +16 -28
- package/spinner/index.d.ts +18 -6
- package/spinner/index.js +25 -12
- package/spinner/spinner.module.scss +8 -0
- package/stepper/index.d.ts +18 -10
- package/stepper/index.js +17 -8
- package/stepper/stepper.module.scss +14 -15
- package/styling/fonts.d.ts +3 -3
- package/switcher-row/index.d.ts +42 -0
- package/switcher-row/index.js +59 -0
- package/switcher-row/switcher-row.module.scss +55 -0
- package/text/index.d.ts +1 -1
- package/text-button/index.d.ts +42 -0
- package/text-button/index.js +46 -0
- package/text-button/text-button.module.scss +99 -0
- package/text-field/index.d.ts +7 -6
- package/text-field/index.js +3 -2
- package/textarea/index.d.ts +21 -0
- package/textarea/index.js +85 -0
- package/textarea/textarea.module.scss +15 -0
- package/toggle/index.d.ts +3 -3
- package/toggle/toggle.module.scss +17 -8
- package/tooltip/index.d.ts +1 -0
- package/tooltip/index.js +1 -0
- package/top-bar/index.d.ts +3 -40
- package/top-bar/index.js +4 -60
- package/top-bar/top-bar-util.scss +29 -0
- package/top-bar/top-bar.d.ts +9 -0
- package/top-bar/top-bar.js +101 -0
- package/top-bar/top-bar.module.scss +129 -67
- package/top-bar/types.d.ts +31 -0
- package/top-bar/types.js +2 -0
- package/top-bar/utils.d.ts +14 -0
- package/top-bar/utils.js +56 -0
- package/touch-slider/index.d.ts +1 -0
- package/touch-slider/index.js +3 -2
- package/types.d.ts +18 -0
- package/types.js +2 -0
- package/unknown-content/index.d.ts +3 -3
- package/unknown-content/index.js +3 -3
- package/unknown-content/unknown-content.module.scss +16 -12
- package/upload-area/index.d.ts +2 -0
- package/upload-area/index.js +5 -0
- package/upload-area/types.d.ts +32 -0
- package/upload-area/types.js +2 -0
- package/upload-area/upload-area-util.scss +17 -0
- package/upload-area/upload-area.d.ts +8 -0
- package/upload-area/upload-area.js +105 -0
- package/upload-area/upload-area.module.scss +78 -0
- package/{upload → upload-area}/upload.svg +0 -0
- package/upload-area/utils.d.ts +17 -0
- package/upload-area/utils.js +48 -0
- package/utils.scss +74 -1
- package/with-hint/index.d.ts +3 -2
- package/with-hint/index.js +1 -0
- package/with-hint/positioning-hint.d.ts +1 -1
- package/with-hint/positioning-hint.js +2 -2
- package/with-tooltip/index.d.ts +2 -1
- package/with-tooltip/index.js +1 -0
- package/with-tooltip/utils.d.ts +2 -2
- package/_internal/body-scroll.d.ts +0 -23
- package/_internal/body-scroll.js +0 -41
- package/_internal/checkbox/index.d.ts +0 -5
- package/constants.d.ts +0 -6
- package/constants.js +0 -9
- package/nav-bar/index.d.ts +0 -46
- package/nav-bar/index.js +0 -76
- package/nav-bar/nav-bar.module.scss +0 -95
- package/upload/area.d.ts +0 -25
- package/upload/area.js +0 -65
- package/upload/area.module.scss +0 -44
- package/upload/utils.d.ts +0 -29
- package/upload/utils.js +0 -45
package/hooks/index.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.useIsomorphicLayoutEffect = exports.useOutsideClick = exports.useInfiniteScroll = exports.useIsTouchDevice = void 0;
|
|
7
4
|
const react_1 = require("react");
|
|
8
5
|
const is_touch_device_1 = require("../helpers/is-touch-device");
|
|
9
|
-
const on_1 =
|
|
6
|
+
const on_1 = require("../helpers/on");
|
|
10
7
|
const identity_1 = require("./identity");
|
|
11
8
|
/**
|
|
12
9
|
* При монтировании проверяет, поддерживает ли устройство touch события.
|
|
13
10
|
* @return True - если поддерживает, false - если нет.
|
|
14
11
|
*/
|
|
15
|
-
|
|
12
|
+
function useIsTouchDevice() {
|
|
16
13
|
const [isTouch, setTouch] = (0, react_1.useState)(false);
|
|
17
14
|
(0, react_1.useEffect)(() => {
|
|
18
15
|
setTouch((0, is_touch_device_1.isTouchDevice)());
|
|
19
16
|
}, []);
|
|
20
17
|
return isTouch;
|
|
21
|
-
}
|
|
18
|
+
}
|
|
22
19
|
exports.useIsTouchDevice = useIsTouchDevice;
|
|
23
20
|
/**
|
|
24
21
|
* Реализует подписку на событие полной прокрутки списка.
|
|
@@ -28,12 +25,12 @@ exports.useIsTouchDevice = useIsTouchDevice;
|
|
|
28
25
|
* @param options.threshold Отступ от конца списка по которому событие должно срабатывать.
|
|
29
26
|
* @param moreDeps Зависимости эффекта (нужны, когда ref заполняется не на этапе render'а).
|
|
30
27
|
*/
|
|
31
|
-
|
|
28
|
+
function useInfiniteScroll(ref, { onFullScroll, threshold = 0, }, moreDeps) {
|
|
32
29
|
const callbackRef = (0, identity_1.useIdentityRef)(onFullScroll);
|
|
33
30
|
(0, react_1.useEffect)(() => {
|
|
34
31
|
const element = ref.current;
|
|
35
32
|
if (element) {
|
|
36
|
-
return (0, on_1.
|
|
33
|
+
return (0, on_1.on)(element, 'scroll', event => {
|
|
37
34
|
var _a;
|
|
38
35
|
const { scrollTop, clientHeight, scrollHeight } = event.target;
|
|
39
36
|
const bottom = threshold + scrollTop + clientHeight;
|
|
@@ -42,24 +39,35 @@ const useInfiniteScroll = (ref, { onFullScroll, threshold = 0, }, moreDeps) => {
|
|
|
42
39
|
});
|
|
43
40
|
}
|
|
44
41
|
}, [ref, threshold, ...(moreDeps || [])]);
|
|
45
|
-
}
|
|
42
|
+
}
|
|
46
43
|
exports.useInfiniteScroll = useInfiniteScroll;
|
|
47
44
|
/**
|
|
48
45
|
* Запускает переданный обработчик при клике вне элемента.
|
|
49
46
|
* @param elementRef Ref элемента, клик вне которого нужно обработать.
|
|
50
47
|
* @param callback Сработает при клике вне элемента.
|
|
51
48
|
*/
|
|
52
|
-
|
|
49
|
+
function useOutsideClick(elementRef, callback) {
|
|
50
|
+
const innerRef = (0, identity_1.useIdentityRef)(elementRef);
|
|
53
51
|
const callbackRef = (0, identity_1.useIdentityRef)(callback);
|
|
54
|
-
(0, react_1.useEffect)(() =>
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
(0, react_1.useEffect)(() => {
|
|
53
|
+
const off = (0, on_1.on)(document.documentElement, 'click', event => {
|
|
54
|
+
var _a;
|
|
55
|
+
const arg = innerRef.current;
|
|
56
|
+
const refs = Array.isArray(arg) ? arg : [arg];
|
|
57
|
+
let isOutsideClick = true;
|
|
58
|
+
for (const { current: element } of refs) {
|
|
59
|
+
if (element &&
|
|
60
|
+
event.target instanceof Node &&
|
|
61
|
+
(element === event.target || element.contains(event.target))) {
|
|
62
|
+
isOutsideClick = false;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
isOutsideClick && ((_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, event));
|
|
67
|
+
});
|
|
68
|
+
return off;
|
|
69
|
+
}, []);
|
|
70
|
+
}
|
|
63
71
|
exports.useOutsideClick = useOutsideClick;
|
|
64
72
|
/**
|
|
65
73
|
* Нужен для того чтобы не получать ошибку при использовании в SSR с NodeJS.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type IntersectionObserverEntryBase = Omit<IntersectionObserverEntry, 'time' | 'rootBounds' | 'boundingClientRect' | 'intersectionRect'>;
|
|
2
2
|
/**
|
|
3
3
|
* Возвращает новый объект, частично реализующий IntersectionObserverEntry.
|
|
4
4
|
* @param base Базовая информация.
|
|
@@ -47,6 +47,7 @@ class IntersectionMock {
|
|
|
47
47
|
if (intersectionMock) {
|
|
48
48
|
throw Error('Already mocked');
|
|
49
49
|
}
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
50
51
|
intersectionMock = this;
|
|
51
52
|
window.IntersectionObserver = FakeIntersectionObserver;
|
|
52
53
|
}
|
|
@@ -87,7 +88,7 @@ class IntersectionMock {
|
|
|
87
88
|
* @param observer Observer.
|
|
88
89
|
*/
|
|
89
90
|
_unregisterObserver(observer) {
|
|
90
|
-
this._observers.splice(this._observers.indexOf(observer));
|
|
91
|
+
this._observers.splice(this._observers.indexOf(observer), 1);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
exports.IntersectionMock = IntersectionMock;
|
package/hooks/styles.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useViewportHeightUnit = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const on_1 = require("../helpers/on");
|
|
6
|
+
const styles_1 = require("../helpers/styles");
|
|
7
|
+
/**
|
|
8
|
+
* Хук, устанавливающий css-переменную "--vh" на переданный элемент.
|
|
9
|
+
* @param ref Ref элемента.
|
|
10
|
+
*/
|
|
11
|
+
function useViewportHeightUnit(ref) {
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
const { visualViewport } = window;
|
|
14
|
+
const offList = [];
|
|
15
|
+
// eslint-disable-next-line require-jsdoc, jsdoc/require-jsdoc
|
|
16
|
+
function setVariable() {
|
|
17
|
+
ref.current && (0, styles_1.setViewportHeightUnit)(ref.current);
|
|
18
|
+
}
|
|
19
|
+
offList.push((0, on_1.on)(window, 'resize', setVariable));
|
|
20
|
+
offList.push((0, on_1.on)(window, 'orientationchange', setVariable));
|
|
21
|
+
visualViewport && offList.push((0, on_1.on)(visualViewport, 'resize', setVariable));
|
|
22
|
+
setVariable();
|
|
23
|
+
return () => offList.forEach(fn => fn());
|
|
24
|
+
}, []);
|
|
25
|
+
}
|
|
26
|
+
exports.useViewportHeightUnit = useViewportHeightUnit;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CSSProperties, MouseEventHandler, ReactNode, Ref } from 'react';
|
|
2
|
+
import { WithTestId } from '../types';
|
|
3
|
+
export interface InfoTextProps extends WithTestId {
|
|
4
|
+
/** Текст. */
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
/** Класс. */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Стили. */
|
|
9
|
+
style?: CSSProperties;
|
|
10
|
+
/** Ref элемента иконки. */
|
|
11
|
+
iconRef?: Ref<HTMLButtonElement>;
|
|
12
|
+
/** Нужно ли выводить иконку как "активную". */
|
|
13
|
+
iconActive?: boolean;
|
|
14
|
+
/** Сработает при клике на иконку. */
|
|
15
|
+
onIconClick?: MouseEventHandler;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Позволяет выводить в конце произвольного текста иконку.
|
|
19
|
+
* Иконка не переносится на следующую строку без предыдущего слова и может обрабатывать действие при клике.
|
|
20
|
+
* @param props Свойства.
|
|
21
|
+
* @return Элемент.
|
|
22
|
+
*/
|
|
23
|
+
export declare function InfoText({ children, style, className, iconRef, onIconClick, iconActive, 'data-testid': testId, }: InfoTextProps): JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.InfoText = void 0;
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const information_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Stroked/information"));
|
|
32
|
+
const bind_1 = __importDefault(require("classnames/bind"));
|
|
33
|
+
const info_text_module_scss_1 = __importDefault(require("./info-text.module.scss"));
|
|
34
|
+
const cx = bind_1.default.bind(info_text_module_scss_1.default);
|
|
35
|
+
/**
|
|
36
|
+
* Позволяет выводить в конце произвольного текста иконку.
|
|
37
|
+
* Иконка не переносится на следующую строку без предыдущего слова и может обрабатывать действие при клике.
|
|
38
|
+
* @param props Свойства.
|
|
39
|
+
* @return Элемент.
|
|
40
|
+
*/
|
|
41
|
+
function InfoText({ children, style, className, iconRef, onIconClick, iconActive, 'data-testid': testId = 'info-text', }) {
|
|
42
|
+
return (react_1.default.createElement("span", { style: style, className: className, "data-testid": testId }, react_1.Children.toArray(children).map((item, index, array) => {
|
|
43
|
+
if (index < array.length - 1) {
|
|
44
|
+
return item;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const text = String(item);
|
|
48
|
+
const lastSpaceIndex = text.lastIndexOf(' ');
|
|
49
|
+
const head = text.slice(0, lastSpaceIndex);
|
|
50
|
+
const last = text.slice(lastSpaceIndex);
|
|
51
|
+
return (react_1.default.createElement(react_1.Fragment, { key: index },
|
|
52
|
+
head,
|
|
53
|
+
last && (react_1.default.createElement("span", { className: info_text_module_scss_1.default.last },
|
|
54
|
+
last,
|
|
55
|
+
react_1.default.createElement("button", { ref: iconRef, type: 'button', "aria-label": '\u041F\u043E\u0434\u0440\u043E\u0431\u043D\u0435\u0435', disabled: !onIconClick, "aria-hidden": !onIconClick, onClick: onIconClick, className: cx('button', { active: iconActive }), "data-testid": 'info-text:icon' },
|
|
56
|
+
react_1.default.createElement(information_1.default, { className: cx('icon') }))))));
|
|
57
|
+
}
|
|
58
|
+
})));
|
|
59
|
+
}
|
|
60
|
+
exports.InfoText = InfoText;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
@use '../colors';
|
|
2
|
+
@use '../utils';
|
|
3
|
+
|
|
4
|
+
.last {
|
|
5
|
+
white-space: nowrap;
|
|
6
|
+
line-height: inherit;
|
|
7
|
+
font-size: inherit;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.button {
|
|
11
|
+
@include utils.reset-button;
|
|
12
|
+
@include utils.focus-visible;
|
|
13
|
+
display: inline-block;
|
|
14
|
+
vertical-align: -0.125em; // не понятно почему, но это значение ставит блок ровно по середине строки
|
|
15
|
+
margin-left: 4px;
|
|
16
|
+
color: colors.$basic-gray38;
|
|
17
|
+
&.active,
|
|
18
|
+
&:hover,
|
|
19
|
+
&:focus-visible {
|
|
20
|
+
color: colors.$basic-gray54;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.icon {
|
|
26
|
+
display: block;
|
|
27
|
+
fill: currentColor;
|
|
28
|
+
}
|
package/input/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InputHTMLAttributes, MouseEventHandler, Ref } from 'react';
|
|
2
|
+
import { BaseInputAsInputProps } from '../base-input';
|
|
3
|
+
import { FieldBlockProps } from '../field-block';
|
|
4
|
+
type HTMLInputProps = Pick<InputHTMLAttributes<HTMLInputElement>, 'autoComplete' | 'autoFocus' | 'defaultValue' | 'disabled' | 'id' | 'name' | 'onBlur' | 'onChange' | 'onFocus' | 'onInput' | 'placeholder' | 'readOnly' | 'required' | 'type' | 'value'>;
|
|
5
|
+
export type InputType = Extract<InputHTMLAttributes<HTMLInputElement>['type'], 'text' | 'password' | 'search' | 'email' | 'tel' | 'number'>;
|
|
6
|
+
export interface InputProps extends HTMLInputProps, FieldBlockProps {
|
|
7
|
+
/** Ref элемента input. */
|
|
8
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
9
|
+
/** Свойства BaseInputProps. */
|
|
10
|
+
baseInputProps?: BaseInputAsInputProps;
|
|
11
|
+
/** Тип поля. */
|
|
12
|
+
type?: InputType;
|
|
13
|
+
/** Нужно ли выводить кнопку очистки поля. */
|
|
14
|
+
clearable?: boolean;
|
|
15
|
+
/** Сработает при очистке поля. */
|
|
16
|
+
onClear?: MouseEventHandler<SVGSVGElement>;
|
|
17
|
+
/** Значение. */
|
|
18
|
+
value?: string;
|
|
19
|
+
/** Значение по умолчанию. */
|
|
20
|
+
defaultValue?: string;
|
|
21
|
+
/** Стили корневого элемента. */
|
|
22
|
+
style?: Required<FieldBlockProps>['rootProps']['style'];
|
|
23
|
+
/** CSS-класс корневого элемента. */
|
|
24
|
+
className?: Required<FieldBlockProps>['rootProps']['className'];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Текстовое поле.
|
|
28
|
+
* @param props Свойства.
|
|
29
|
+
* @return Элемент.
|
|
30
|
+
*/
|
|
31
|
+
export declare function Input({ inputRef, baseInputProps, clearable, onClear, style, className, autoComplete, autoFocus, defaultValue, disabled, id, name, onBlur, onChange, onFocus, onInput, placeholder, readOnly, required, type, value, size, label, failed, caption, blockProps, 'data-testid': testId, focused: focusedProp, ...restProps }: InputProps): JSX.Element;
|
|
32
|
+
export {};
|
package/input/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.Input = void 0;
|
|
41
|
+
const react_1 = __importStar(require("react"));
|
|
42
|
+
const base_input_1 = require("../base-input");
|
|
43
|
+
const field_block_1 = require("../field-block");
|
|
44
|
+
const utils_1 = require("./utils");
|
|
45
|
+
const events_1 = require("../helpers/events");
|
|
46
|
+
const cross_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Filled/cross"));
|
|
47
|
+
const cross_2 = __importDefault(require("@sima-land/ui-quarks/icons/24x24/Filled/cross"));
|
|
48
|
+
const bind_1 = __importDefault(require("classnames/bind"));
|
|
49
|
+
const input_module_scss_1 = __importDefault(require("./input.module.scss"));
|
|
50
|
+
const cx = bind_1.default.bind(input_module_scss_1.default);
|
|
51
|
+
/**
|
|
52
|
+
* Текстовое поле.
|
|
53
|
+
* @param props Свойства.
|
|
54
|
+
* @return Элемент.
|
|
55
|
+
*/
|
|
56
|
+
function Input(_a) {
|
|
57
|
+
var {
|
|
58
|
+
// specific Input props
|
|
59
|
+
inputRef, baseInputProps, clearable, onClear,
|
|
60
|
+
// root props
|
|
61
|
+
style, className,
|
|
62
|
+
// input element props (popular)
|
|
63
|
+
autoComplete, autoFocus, defaultValue, disabled, id, name, onBlur, onChange, onFocus, onInput, placeholder, readOnly, required, type, value,
|
|
64
|
+
// FieldBlock props
|
|
65
|
+
size, label, failed, caption, blockProps, 'data-testid': testId = 'input', focused: focusedProp } = _a, restProps = __rest(_a, ["inputRef", "baseInputProps", "clearable", "onClear", "style", "className", "autoComplete", "autoFocus", "defaultValue", "disabled", "id", "name", "onBlur", "onChange", "onFocus", "onInput", "placeholder", "readOnly", "required", "type", "value", "size", "label", "failed", "caption", "blockProps", 'data-testid', "focused"]);
|
|
66
|
+
const ref = (0, react_1.useRef)(null);
|
|
67
|
+
const [filled, updateFilled] = (0, utils_1.useFilledState)(ref, { value, defaultValue });
|
|
68
|
+
const [focused, setFocused] = (0, react_1.useState)(false);
|
|
69
|
+
const CrossSVG = size === 's' ? cross_1.default : cross_2.default;
|
|
70
|
+
const handleMouseDown = (0, utils_1.useFieldMouseDown)(ref, blockProps === null || blockProps === void 0 ? void 0 : blockProps.onMouseDown);
|
|
71
|
+
(0, react_1.useImperativeHandle)(inputRef, () => ref.current);
|
|
72
|
+
return (react_1.default.createElement(field_block_1.FieldBlock, Object.assign({}, restProps, { rootProps: Object.assign(Object.assign({}, restProps.rootProps), { style,
|
|
73
|
+
className }), "data-testid": testId, caption: caption, disabled: disabled, failed: failed, focused: focusedProp !== null && focusedProp !== void 0 ? focusedProp : focused, label: label, labelAsPlaceholder: !focused && !filled, labelProps: { htmlFor: id }, size: size }, (clearable &&
|
|
74
|
+
focused &&
|
|
75
|
+
filled && {
|
|
76
|
+
adornmentEnd: (react_1.default.createElement(CrossSVG, { "data-testid": 'input:clear-button', role: 'button', "aria-label": '\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u043F\u043E\u043B\u0435', className: cx('clear-button'), onClick: e => {
|
|
77
|
+
ref.current && (0, events_1.triggerInput)(ref.current, '');
|
|
78
|
+
onClear === null || onClear === void 0 ? void 0 : onClear(e);
|
|
79
|
+
} })),
|
|
80
|
+
}), { blockProps: Object.assign(Object.assign({}, blockProps), { onMouseDown: handleMouseDown }), main: react_1.default.createElement(base_input_1.BaseInput, Object.assign({}, baseInputProps, { inputRef: ref, multiline: false, className: cx('input', baseInputProps === null || baseInputProps === void 0 ? void 0 : baseInputProps.className), style: Object.assign(Object.assign({}, baseInputProps === null || baseInputProps === void 0 ? void 0 : baseInputProps.style), { '--placeholder-color': (0, utils_1.definePlaceholderColor)({ failed, disabled }) }), autoComplete: autoComplete, autoFocus: autoFocus, defaultValue: defaultValue, disabled: disabled, id: id, name: name, placeholder: !focused ? label || placeholder : placeholder, readOnly: readOnly, required: required, type: type, value: value, onFocus: event => {
|
|
81
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
82
|
+
updateFilled(event);
|
|
83
|
+
setFocused(true);
|
|
84
|
+
}, onBlur: event => {
|
|
85
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
86
|
+
updateFilled(event);
|
|
87
|
+
setFocused(false);
|
|
88
|
+
}, onInput: event => {
|
|
89
|
+
onInput === null || onInput === void 0 ? void 0 : onInput(event);
|
|
90
|
+
updateFilled(event);
|
|
91
|
+
}, onChange: event => {
|
|
92
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
93
|
+
updateFilled(event);
|
|
94
|
+
} })), mainProps: { className: cx('main') } })));
|
|
95
|
+
}
|
|
96
|
+
exports.Input = Input;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
@use '../colors';
|
|
2
|
+
|
|
3
|
+
.main {
|
|
4
|
+
display: flex;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.input {
|
|
9
|
+
min-width: 0;
|
|
10
|
+
width: 0;
|
|
11
|
+
flex-grow: 1;
|
|
12
|
+
background: inherit;
|
|
13
|
+
font: inherit;
|
|
14
|
+
line-height: inherit;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.clear-button {
|
|
18
|
+
fill: colors.$basic-gray38;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
}
|
package/input/utils.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventHandler, MouseEventHandler, RefObject, SyntheticEvent } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Получив значения value и defaultValue для поля, определяет является ли оно заполненным.
|
|
4
|
+
* @param value Значение value.
|
|
5
|
+
* @param defaultValue Значение defaultValue.
|
|
6
|
+
* @return Является ли поле заполненным.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineFilled(value: unknown, defaultValue: unknown): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Получи информацию о состоянии поля возвращает цвет placeholder.
|
|
11
|
+
* @param state Состояние.
|
|
12
|
+
* @return Цвет.
|
|
13
|
+
*/
|
|
14
|
+
export declare function definePlaceholderColor({ failed, disabled, }: {
|
|
15
|
+
failed?: boolean;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Хук состояния заполненности поля текстовым значением.
|
|
20
|
+
* @param ref Ref элемента поля.
|
|
21
|
+
* @param affectProps Свойства, влияющие на состояние заполненности.
|
|
22
|
+
* @return Кортеж: состояние; функция обновления состояния.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useFilledState(ref: RefObject<HTMLInputElement> | RefObject<HTMLTextAreaElement>, { value, defaultValue, }: {
|
|
25
|
+
value: unknown;
|
|
26
|
+
defaultValue: unknown;
|
|
27
|
+
}): [boolean, EventHandler<SyntheticEvent<{
|
|
28
|
+
value: string;
|
|
29
|
+
}>>];
|
|
30
|
+
/**
|
|
31
|
+
* Хук, формирующий callback события mousedown на блоке поля, фокусирующий пользователя на поле.
|
|
32
|
+
* @param fieldRef Ref элемента поля.
|
|
33
|
+
* @param callback Будет вызвана по событию mousedown.
|
|
34
|
+
* @return Функция обратного вызова.
|
|
35
|
+
*/
|
|
36
|
+
export declare function useFieldMouseDown(fieldRef: RefObject<HTMLInputElement | HTMLTextAreaElement>, callback?: MouseEventHandler<HTMLDivElement>): MouseEventHandler<HTMLDivElement>;
|
package/input/utils.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFieldMouseDown = exports.useFilledState = exports.definePlaceholderColor = exports.defineFilled = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const colors_1 = require("../colors");
|
|
6
|
+
/**
|
|
7
|
+
* Получив значения value и defaultValue для поля, определяет является ли оно заполненным.
|
|
8
|
+
* @param value Значение value.
|
|
9
|
+
* @param defaultValue Значение defaultValue.
|
|
10
|
+
* @return Является ли поле заполненным.
|
|
11
|
+
*/
|
|
12
|
+
function defineFilled(value, defaultValue) {
|
|
13
|
+
return [value, defaultValue].some(v => typeof v !== 'undefined' && `${v}` !== '');
|
|
14
|
+
}
|
|
15
|
+
exports.defineFilled = defineFilled;
|
|
16
|
+
/**
|
|
17
|
+
* Получи информацию о состоянии поля возвращает цвет placeholder.
|
|
18
|
+
* @param state Состояние.
|
|
19
|
+
* @return Цвет.
|
|
20
|
+
*/
|
|
21
|
+
function definePlaceholderColor({ failed, disabled, }) {
|
|
22
|
+
let placeholderColor = undefined;
|
|
23
|
+
switch (true) {
|
|
24
|
+
case failed:
|
|
25
|
+
placeholderColor = colors_1.COLORS.get('additional-deep-red');
|
|
26
|
+
break;
|
|
27
|
+
case disabled:
|
|
28
|
+
placeholderColor = colors_1.COLORS.get('basic-gray24');
|
|
29
|
+
break;
|
|
30
|
+
case !disabled:
|
|
31
|
+
placeholderColor = colors_1.COLORS.get('basic-gray38');
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
return placeholderColor;
|
|
35
|
+
}
|
|
36
|
+
exports.definePlaceholderColor = definePlaceholderColor;
|
|
37
|
+
/**
|
|
38
|
+
* Хук состояния заполненности поля текстовым значением.
|
|
39
|
+
* @param ref Ref элемента поля.
|
|
40
|
+
* @param affectProps Свойства, влияющие на состояние заполненности.
|
|
41
|
+
* @return Кортеж: состояние; функция обновления состояния.
|
|
42
|
+
*/
|
|
43
|
+
function useFilledState(ref, { value, defaultValue, }) {
|
|
44
|
+
const [filled, setFilled] = (0, react_1.useState)(() => defineFilled(value, defaultValue));
|
|
45
|
+
const updateFilled = (0, react_1.useCallback)(event => {
|
|
46
|
+
setFilled(Boolean(event.currentTarget.value));
|
|
47
|
+
}, []);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
var _a;
|
|
50
|
+
setFilled(Boolean((_a = ref.current) === null || _a === void 0 ? void 0 : _a.value));
|
|
51
|
+
});
|
|
52
|
+
return [filled, updateFilled];
|
|
53
|
+
}
|
|
54
|
+
exports.useFilledState = useFilledState;
|
|
55
|
+
/**
|
|
56
|
+
* Хук, формирующий callback события mousedown на блоке поля, фокусирующий пользователя на поле.
|
|
57
|
+
* @param fieldRef Ref элемента поля.
|
|
58
|
+
* @param callback Будет вызвана по событию mousedown.
|
|
59
|
+
* @return Функция обратного вызова.
|
|
60
|
+
*/
|
|
61
|
+
function useFieldMouseDown(fieldRef, callback) {
|
|
62
|
+
return (0, react_1.useCallback)(event => {
|
|
63
|
+
const field = fieldRef.current;
|
|
64
|
+
callback === null || callback === void 0 ? void 0 : callback(event);
|
|
65
|
+
if (!event.defaultPrevented && field && event.target !== field) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
field.focus();
|
|
68
|
+
}
|
|
69
|
+
}, [fieldRef, callback]);
|
|
70
|
+
}
|
|
71
|
+
exports.useFieldMouseDown = useFieldMouseDown;
|
package/layout/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
disabledOn?: Array<Breakpoint>;
|
|
8
|
-
}
|
|
9
|
-
declare const DesktopLayout: React.ForwardRefExoticComponent<LayoutProps & React.RefAttributes<HTMLElement>>;
|
|
10
|
-
declare const MobileLayout: React.ForwardRefExoticComponent<LayoutProps & React.RefAttributes<HTMLElement>>;
|
|
11
|
-
export { DesktopLayout, MobileLayout };
|
|
1
|
+
import { Breakpoint } from '../types';
|
|
2
|
+
import { LayoutProps } from './types';
|
|
3
|
+
import { Layout } from './layout';
|
|
4
|
+
import { MobileLayout, DesktopLayout } from './legacy';
|
|
5
|
+
export type { Breakpoint, LayoutProps };
|
|
6
|
+
export { Layout, MobileLayout, DesktopLayout };
|
package/layout/index.js
CHANGED
|
@@ -1,62 +1,8 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
-
var t = {};
|
|
27
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
-
t[p] = s[p];
|
|
29
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
-
t[p[i]] = s[p[i]];
|
|
33
|
-
}
|
|
34
|
-
return t;
|
|
35
|
-
};
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.MobileLayout = exports.
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* Возвращает созданный функциональный компонент, формирующий Layout.
|
|
47
|
-
* @param specificClass Специальный класс.
|
|
48
|
-
* @param displayName Отображаемое имя компонента.
|
|
49
|
-
* @return Элемент.
|
|
50
|
-
*/
|
|
51
|
-
const createLayout = (specificClass, displayName) => {
|
|
52
|
-
const Component = (0, react_1.forwardRef)((_a, ref) => {
|
|
53
|
-
var { className, element: Element = 'div', disabledOn = [] } = _a, restProps = __rest(_a, ["className", "element", "disabledOn"]);
|
|
54
|
-
return (react_1.default.createElement(Element, Object.assign({}, restProps, { ref: ref, className: cx('layout', specificClass, className, disabledOn.map(key => `disabled-${key}`)) })));
|
|
55
|
-
});
|
|
56
|
-
Component.displayName = displayName;
|
|
57
|
-
return Component;
|
|
58
|
-
};
|
|
59
|
-
const DesktopLayout = createLayout('desktop', 'DesktopLayout');
|
|
60
|
-
exports.DesktopLayout = DesktopLayout;
|
|
61
|
-
const MobileLayout = createLayout('mobile', 'MobileLayout');
|
|
62
|
-
exports.MobileLayout = MobileLayout;
|
|
3
|
+
exports.DesktopLayout = exports.MobileLayout = exports.Layout = void 0;
|
|
4
|
+
const layout_1 = require("./layout");
|
|
5
|
+
Object.defineProperty(exports, "Layout", { enumerable: true, get: function () { return layout_1.Layout; } });
|
|
6
|
+
const legacy_1 = require("./legacy");
|
|
7
|
+
Object.defineProperty(exports, "MobileLayout", { enumerable: true, get: function () { return legacy_1.MobileLayout; } });
|
|
8
|
+
Object.defineProperty(exports, "DesktopLayout", { enumerable: true, get: function () { return legacy_1.DesktopLayout; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { LayoutProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Контейнер, формирующий отступы по горизонтали в соответствии с дизайн-гайдами.
|
|
5
|
+
* @param props Свойства.
|
|
6
|
+
* @return Элемент.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Layout({ children, className, disabledOn, rootRef, ...rest }: Omit<LayoutProps, 'element'> & {
|
|
9
|
+
rootRef?: Ref<HTMLDivElement>;
|
|
10
|
+
}): JSX.Element;
|