@sima-land/ui-nucleons 44.2.10 → 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 +1 -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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@use 'sass:math';
|
|
2
|
+
@use '../colors';
|
|
3
|
+
|
|
4
|
+
.root {
|
|
5
|
+
border-radius: 4px;
|
|
6
|
+
background: colors.$basic-gray76;
|
|
7
|
+
padding: 8px;
|
|
8
|
+
max-width: 280px;
|
|
9
|
+
min-width: 36px;
|
|
10
|
+
min-height: 36px;
|
|
11
|
+
display: inline-flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
color: #fff;
|
|
14
|
+
font-size: 14px;
|
|
15
|
+
line-height: 20px;
|
|
16
|
+
font-weight: 400;
|
|
17
|
+
text-align: center;
|
|
18
|
+
overflow-wrap: break-word;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.arrow {
|
|
22
|
+
position: absolute;
|
|
23
|
+
width: 1px * math.sqrt((4 * 4) + (4 * 4));
|
|
24
|
+
height: 1px * math.sqrt((4 * 4) + (4 * 4));
|
|
25
|
+
transform: rotate(45deg);
|
|
26
|
+
background: colors.$basic-gray76;
|
|
27
|
+
top: var(--hint-arrow-top);
|
|
28
|
+
left: var(--hint-arrow-left);
|
|
29
|
+
right: var(--hint-arrow-right);
|
|
30
|
+
bottom: var(--hint-arrow-bottom);
|
|
31
|
+
}
|
package/hint/hint.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { HintViewProps } from './hint-view';
|
|
3
|
+
export interface HintProps extends HintViewProps {
|
|
4
|
+
/** Нужно ли показать хинт. */
|
|
5
|
+
open?: boolean;
|
|
6
|
+
/** Ref элемента "стрелки". */
|
|
7
|
+
arrowRef?: Ref<HTMLDivElement>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Всплывающий хинт.
|
|
11
|
+
* @param props Свойства.
|
|
12
|
+
* @return Элемент.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Hint({ open, ...rest }: HintProps): JSX.Element;
|
package/hint/hint.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Hint = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
const portal_1 = require("../portal");
|
|
20
|
+
const hint_view_1 = require("./hint-view");
|
|
21
|
+
/**
|
|
22
|
+
* Всплывающий хинт.
|
|
23
|
+
* @param props Свойства.
|
|
24
|
+
* @return Элемент.
|
|
25
|
+
*/
|
|
26
|
+
function Hint(_a) {
|
|
27
|
+
var { open } = _a, rest = __rest(_a, ["open"]);
|
|
28
|
+
return react_1.default.createElement(portal_1.Portal, null, open && react_1.default.createElement(HintInner, Object.assign({}, rest)));
|
|
29
|
+
}
|
|
30
|
+
exports.Hint = Hint;
|
|
31
|
+
/**
|
|
32
|
+
* Внутренний компонент, необходим из-за использования портала.
|
|
33
|
+
* @param props Свойства.
|
|
34
|
+
* @return Элемент.
|
|
35
|
+
*/
|
|
36
|
+
function HintInner(_a) {
|
|
37
|
+
var { arrowRef, children } = _a, rest = __rest(_a, ["arrowRef", "children"]);
|
|
38
|
+
return (react_1.default.createElement(hint_view_1.HintView, Object.assign({}, rest),
|
|
39
|
+
children,
|
|
40
|
+
react_1.default.createElement(hint_view_1.HintView.Arrow, { arrowRef: arrowRef })));
|
|
41
|
+
}
|
package/hint/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export declare const Hint: React.ForwardRefExoticComponent<HintProps & React.RefAttributes<HTMLDivElement | null>>;
|
|
8
|
-
export {};
|
|
1
|
+
import { HintView, type HintViewProps } from './hint-view';
|
|
2
|
+
import { Hint, type HintProps } from './hint';
|
|
3
|
+
import { hintFloatingConfig, useHintFloating, useHintOnHover, useHintOnClick, useTempHintState, useHintFloatingStyle, getArrowFloatingStyle } from './utils';
|
|
4
|
+
export type { HintProps, HintViewProps };
|
|
5
|
+
export { Hint, HintView, hintFloatingConfig, useHintFloating, useHintOnHover, useHintOnClick, useTempHintState, useHintFloatingStyle, getArrowFloatingStyle, };
|
package/hint/index.js
CHANGED
|
@@ -1,50 +1,15 @@
|
|
|
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.Hint = void 0;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
exports
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
3
|
+
exports.getArrowFloatingStyle = exports.useHintFloatingStyle = exports.useTempHintState = exports.useHintOnClick = exports.useHintOnHover = exports.useHintFloating = exports.hintFloatingConfig = exports.HintView = exports.Hint = void 0;
|
|
4
|
+
const hint_view_1 = require("./hint-view");
|
|
5
|
+
Object.defineProperty(exports, "HintView", { enumerable: true, get: function () { return hint_view_1.HintView; } });
|
|
6
|
+
const hint_1 = require("./hint");
|
|
7
|
+
Object.defineProperty(exports, "Hint", { enumerable: true, get: function () { return hint_1.Hint; } });
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
Object.defineProperty(exports, "hintFloatingConfig", { enumerable: true, get: function () { return utils_1.hintFloatingConfig; } });
|
|
10
|
+
Object.defineProperty(exports, "useHintFloating", { enumerable: true, get: function () { return utils_1.useHintFloating; } });
|
|
11
|
+
Object.defineProperty(exports, "useHintOnHover", { enumerable: true, get: function () { return utils_1.useHintOnHover; } });
|
|
12
|
+
Object.defineProperty(exports, "useHintOnClick", { enumerable: true, get: function () { return utils_1.useHintOnClick; } });
|
|
13
|
+
Object.defineProperty(exports, "useTempHintState", { enumerable: true, get: function () { return utils_1.useTempHintState; } });
|
|
14
|
+
Object.defineProperty(exports, "useHintFloatingStyle", { enumerable: true, get: function () { return utils_1.useHintFloatingStyle; } });
|
|
15
|
+
Object.defineProperty(exports, "getArrowFloatingStyle", { enumerable: true, get: function () { return utils_1.getArrowFloatingStyle; } });
|
package/hint/utils.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CSSProperties, Dispatch, MutableRefObject, SetStateAction } from 'react';
|
|
2
|
+
import { ExtendedRefs, ReferenceType, UseFloatingProps, UseFloatingReturn } from '@floating-ui/react';
|
|
3
|
+
interface HintExtendedRefs<RT> extends ExtendedRefs<RT> {
|
|
4
|
+
setArrow: (el: HTMLElement | null) => void;
|
|
5
|
+
}
|
|
6
|
+
interface UseHintFloatingReturn<RT extends ReferenceType = ReferenceType> extends UseFloatingReturn<RT> {
|
|
7
|
+
refs: HintExtendedRefs<RT>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Возвращает конфигурацию для `useFloating` по дизайн-гайдам.
|
|
11
|
+
* @param options Опции.
|
|
12
|
+
* @return Конфигурация для `useFloating` по дизайн-гайдам.
|
|
13
|
+
*/
|
|
14
|
+
export declare function hintFloatingConfig({ arrowRef, }?: {
|
|
15
|
+
arrowRef?: MutableRefObject<HTMLElement | null>;
|
|
16
|
+
}): Partial<UseFloatingProps>;
|
|
17
|
+
/**
|
|
18
|
+
* Расширенная версия `useFloating` для использования с `Hint`.
|
|
19
|
+
* @param props Свойства useFloating.
|
|
20
|
+
* @return Результат useFloating.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useHintFloating<RT extends ReferenceType = ReferenceType>(props?: Partial<UseFloatingProps>): UseHintFloatingReturn<RT>;
|
|
23
|
+
/**
|
|
24
|
+
* Возвращает стили для всплывающего хинта с учетом "слоя".
|
|
25
|
+
* @param floating Результат вызова useFloating.
|
|
26
|
+
* @return Стили для элемента с учетом "слоя".
|
|
27
|
+
*/
|
|
28
|
+
export declare function useHintFloatingStyle(floating: Pick<UseFloatingReturn, 'strategy' | 'x' | 'y' | 'placement' | 'middlewareData'>): CSSProperties;
|
|
29
|
+
/**
|
|
30
|
+
* Возвращает стили для стрелки между хинтом и триггером.
|
|
31
|
+
* @param floating Результат вызова useFloating.
|
|
32
|
+
* @return Стили для элемента с учетом "слоя".
|
|
33
|
+
*/
|
|
34
|
+
export declare function getArrowFloatingStyle({ placement, middlewareData, }: Pick<UseFloatingReturn, 'placement' | 'middlewareData'>): CSSProperties;
|
|
35
|
+
/**
|
|
36
|
+
* Показ всплывающего хинта при наведении.
|
|
37
|
+
* @param floating Результат вызова useFloating.
|
|
38
|
+
* @return Опции для открывающего и всплывающего элемента.
|
|
39
|
+
*/
|
|
40
|
+
export declare function useHintOnHover(floating: Pick<UseFloatingReturn, 'context' | 'strategy' | 'placement' | 'x' | 'y' | 'middlewareData'>): {
|
|
41
|
+
getReferenceProps: (userProps?: import("react").HTMLProps<Element> | undefined) => Record<string, unknown>;
|
|
42
|
+
getFloatingProps: (userProps?: import("react").HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
|
|
43
|
+
getItemProps: (userProps?: import("react").HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Показ всплывающего хинта при клике.
|
|
47
|
+
* @param floating Результат вызова useFloating.
|
|
48
|
+
* @return Опции для открывающего и всплывающего элемента.
|
|
49
|
+
*/
|
|
50
|
+
export declare function useHintOnClick(floating: Pick<UseFloatingReturn, 'context' | 'strategy' | 'placement' | 'x' | 'y' | 'middlewareData'>): {
|
|
51
|
+
getReferenceProps: (userProps?: import("react").HTMLProps<Element> | undefined) => Record<string, unknown>;
|
|
52
|
+
getFloatingProps: (userProps?: import("react").HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
|
|
53
|
+
getItemProps: (userProps?: import("react").HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Состояние хинта с автоматическим скрытием по таймауту.
|
|
57
|
+
* @param initialState Начальное состояние.
|
|
58
|
+
* @return Результат вызова `useState`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function useTempHintState(initialState: boolean): readonly [boolean, Dispatch<SetStateAction<boolean>>];
|
|
61
|
+
export {};
|
package/hint/utils.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTempHintState = exports.useHintOnClick = exports.useHintOnHover = exports.getArrowFloatingStyle = exports.useHintFloatingStyle = exports.useHintFloating = exports.hintFloatingConfig = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_2 = require("@floating-ui/react");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const layer_1 = require("../helpers/layer");
|
|
8
|
+
const hint_view_1 = require("./hint-view");
|
|
9
|
+
const identity_1 = require("../hooks/identity");
|
|
10
|
+
/**
|
|
11
|
+
* Возвращает конфигурацию для `useFloating` по дизайн-гайдам.
|
|
12
|
+
* @param options Опции.
|
|
13
|
+
* @return Конфигурация для `useFloating` по дизайн-гайдам.
|
|
14
|
+
*/
|
|
15
|
+
function hintFloatingConfig({ arrowRef, } = {}) {
|
|
16
|
+
return {
|
|
17
|
+
placement: 'top',
|
|
18
|
+
middleware: [
|
|
19
|
+
(0, react_2.offset)(4 + (arrowRef ? 4 : 0)),
|
|
20
|
+
(0, react_2.flip)({
|
|
21
|
+
padding: 16,
|
|
22
|
+
crossAxis: false,
|
|
23
|
+
fallbackAxisSideDirection: 'start',
|
|
24
|
+
}),
|
|
25
|
+
(0, react_2.shift)({
|
|
26
|
+
padding: 16,
|
|
27
|
+
}),
|
|
28
|
+
arrowRef &&
|
|
29
|
+
(0, react_2.arrow)({
|
|
30
|
+
element: arrowRef,
|
|
31
|
+
padding: 4,
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
whileElementsMounted: react_2.autoUpdate,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.hintFloatingConfig = hintFloatingConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Расширенная версия `useFloating` для использования с `Hint`.
|
|
40
|
+
* @param props Свойства useFloating.
|
|
41
|
+
* @return Результат useFloating.
|
|
42
|
+
*/
|
|
43
|
+
function useHintFloating(props) {
|
|
44
|
+
const [arrowEl, setArrowEl] = (0, react_1.useState)(null);
|
|
45
|
+
const arrowRef = (0, identity_1.useIdentityRef)(arrowEl);
|
|
46
|
+
const floating = (0, react_2.useFloating)(Object.assign(Object.assign({}, hintFloatingConfig(arrowEl ? { arrowRef } : undefined)), props));
|
|
47
|
+
return Object.assign(Object.assign({}, floating), { refs: Object.assign(Object.assign({}, floating.refs), { setArrow: setArrowEl }) });
|
|
48
|
+
}
|
|
49
|
+
exports.useHintFloating = useHintFloating;
|
|
50
|
+
/**
|
|
51
|
+
* Возвращает стили для всплывающего хинта с учетом "слоя".
|
|
52
|
+
* @param floating Результат вызова useFloating.
|
|
53
|
+
* @return Стили для элемента с учетом "слоя".
|
|
54
|
+
*/
|
|
55
|
+
function useHintFloatingStyle(floating) {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const layer = (0, layer_1.useLayer)();
|
|
58
|
+
return Object.assign({ position: floating.strategy, top: (_a = floating.y) !== null && _a !== void 0 ? _a : 0, left: (_b = floating.x) !== null && _b !== void 0 ? _b : 0, zIndex: layer + 2 }, (0, lodash_1.mapKeys)(getArrowFloatingStyle(floating), (value, key) => `--hint-arrow-${key}`));
|
|
59
|
+
}
|
|
60
|
+
exports.useHintFloatingStyle = useHintFloatingStyle;
|
|
61
|
+
/**
|
|
62
|
+
* Возвращает стили для стрелки между хинтом и триггером.
|
|
63
|
+
* @param floating Результат вызова useFloating.
|
|
64
|
+
* @return Стили для элемента с учетом "слоя".
|
|
65
|
+
*/
|
|
66
|
+
function getArrowFloatingStyle({ placement, middlewareData, }) {
|
|
67
|
+
const { arrow: arrowData } = middlewareData;
|
|
68
|
+
if (!arrowData) {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
const side = placement.split('-')[0];
|
|
72
|
+
// eslint-disable-next-line require-jsdoc
|
|
73
|
+
const maybe = (value) => (value ? `${value}px` : '');
|
|
74
|
+
// eslint-disable-next-line require-jsdoc
|
|
75
|
+
const arrowShift = () => `${-hint_view_1.arrowSquareSize / 2}px`;
|
|
76
|
+
let arrowStyle = {};
|
|
77
|
+
switch (side) {
|
|
78
|
+
case 'top': {
|
|
79
|
+
arrowStyle = {
|
|
80
|
+
left: maybe(arrowData === null || arrowData === void 0 ? void 0 : arrowData.x),
|
|
81
|
+
bottom: arrowShift(),
|
|
82
|
+
};
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 'bottom': {
|
|
86
|
+
arrowStyle = {
|
|
87
|
+
left: maybe(arrowData === null || arrowData === void 0 ? void 0 : arrowData.x),
|
|
88
|
+
top: arrowShift(),
|
|
89
|
+
};
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'left': {
|
|
93
|
+
arrowStyle = {
|
|
94
|
+
top: maybe(arrowData === null || arrowData === void 0 ? void 0 : arrowData.y),
|
|
95
|
+
right: arrowShift(),
|
|
96
|
+
};
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 'right': {
|
|
100
|
+
arrowStyle = {
|
|
101
|
+
top: maybe(arrowData === null || arrowData === void 0 ? void 0 : arrowData.y),
|
|
102
|
+
left: arrowShift(),
|
|
103
|
+
};
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return arrowStyle;
|
|
108
|
+
}
|
|
109
|
+
exports.getArrowFloatingStyle = getArrowFloatingStyle;
|
|
110
|
+
/**
|
|
111
|
+
* Показ всплывающего хинта при наведении.
|
|
112
|
+
* @param floating Результат вызова useFloating.
|
|
113
|
+
* @return Опции для открывающего и всплывающего элемента.
|
|
114
|
+
*/
|
|
115
|
+
function useHintOnHover(floating) {
|
|
116
|
+
const style = useHintFloatingStyle(floating);
|
|
117
|
+
const hover = (0, react_2.useHover)(floating.context, { delay: { close: 120 } });
|
|
118
|
+
return (0, react_2.useInteractions)([hover, { floating: { style } }]);
|
|
119
|
+
}
|
|
120
|
+
exports.useHintOnHover = useHintOnHover;
|
|
121
|
+
/**
|
|
122
|
+
* Показ всплывающего хинта при клике.
|
|
123
|
+
* @param floating Результат вызова useFloating.
|
|
124
|
+
* @return Опции для открывающего и всплывающего элемента.
|
|
125
|
+
*/
|
|
126
|
+
function useHintOnClick(floating) {
|
|
127
|
+
const style = useHintFloatingStyle(floating);
|
|
128
|
+
const click = (0, react_2.useClick)(floating.context);
|
|
129
|
+
const dismiss = (0, react_2.useDismiss)(floating.context);
|
|
130
|
+
return (0, react_2.useInteractions)([click, dismiss, { floating: { style } }]);
|
|
131
|
+
}
|
|
132
|
+
exports.useHintOnClick = useHintOnClick;
|
|
133
|
+
/**
|
|
134
|
+
* Состояние хинта с автоматическим скрытием по таймауту.
|
|
135
|
+
* @param initialState Начальное состояние.
|
|
136
|
+
* @return Результат вызова `useState`.
|
|
137
|
+
*/
|
|
138
|
+
function useTempHintState(initialState) {
|
|
139
|
+
const [open, setOpen] = (0, react_1.useState)(initialState);
|
|
140
|
+
const timerRef = (0, react_1.useRef)(null);
|
|
141
|
+
const updateTimer = (0, react_1.useCallback)((value) => {
|
|
142
|
+
// сбрасываем предыдущий таймер если был
|
|
143
|
+
if (timerRef.current !== null) {
|
|
144
|
+
window.clearTimeout(timerRef.current);
|
|
145
|
+
}
|
|
146
|
+
// запускаем новый таймер если надо
|
|
147
|
+
if (value) {
|
|
148
|
+
timerRef.current = window.setTimeout(() => setOpen(false), 2000);
|
|
149
|
+
}
|
|
150
|
+
}, []);
|
|
151
|
+
(0, react_1.useEffect)(() => {
|
|
152
|
+
updateTimer(open);
|
|
153
|
+
}, []);
|
|
154
|
+
const toggle = (0, react_1.useCallback)(next => {
|
|
155
|
+
const state = typeof next === 'function' ? next(open) : next;
|
|
156
|
+
updateTimer(state);
|
|
157
|
+
setOpen(state);
|
|
158
|
+
}, [open, setOpen, updateTimer]);
|
|
159
|
+
return [open, toggle];
|
|
160
|
+
}
|
|
161
|
+
exports.useTempHintState = useTempHintState;
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type Direction = 'top' | 'left' | 'bottom' | 'right';
|
|
3
|
+
export interface HintProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** С какой стороны появляется хинт. */
|
|
5
|
+
direction: Direction;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Теперь нужно использовать `hint`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const Hint: React.ForwardRefExoticComponent<HintProps & React.RefAttributes<HTMLDivElement | null>>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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.Hint = void 0;
|
|
41
|
+
const react_1 = __importStar(require("react"));
|
|
42
|
+
const shadows_1 = require("../styling/shadows");
|
|
43
|
+
const bind_1 = __importDefault(require("classnames/bind"));
|
|
44
|
+
const hint_module_scss_1 = __importDefault(require("./hint.module.scss"));
|
|
45
|
+
const cx = bind_1.default.bind(hint_module_scss_1.default);
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Теперь нужно использовать `hint`.
|
|
48
|
+
*/
|
|
49
|
+
exports.Hint = (0, react_1.forwardRef)((_a, ref) => {
|
|
50
|
+
var { children, className, direction } = _a, restProps = __rest(_a, ["children", "className", "direction"]);
|
|
51
|
+
return (react_1.default.createElement("div", Object.assign({}, restProps, { ref: ref, className: cx('root', className, direction), "data-testid": 'hint' }),
|
|
52
|
+
react_1.default.createElement("div", { className: cx('body', shadows_1.BoxShadow.z4) }, children)));
|
|
53
|
+
});
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* Провайдер,
|
|
3
|
+
* Провайдер, предоставляющий контекст для использования хуком useBreakpoint.
|
|
4
|
+
* Не является обязательным, используется в целях оптимизации.
|
|
4
5
|
* @param props Свойства.
|
|
5
6
|
* @return Элемент.
|
|
6
7
|
*/
|
|
7
|
-
export declare
|
|
8
|
+
export declare function BreakpointProvider({ children }: {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): JSX.Element;
|
|
8
11
|
/**
|
|
9
12
|
* Хук обработки медиа-запроса на основе breakpoint'а дизайн-системы.
|
|
10
13
|
* @param query Запрос, например "xs+".
|
|
11
14
|
* @return Соответствует ли ширина экрана заданному запросу.
|
|
12
15
|
*/
|
|
13
|
-
export declare
|
|
16
|
+
export declare function useBreakpoint(query: string): boolean;
|
|
@@ -33,38 +33,46 @@ const is_browser_1 = __importDefault(require("../../helpers/is-browser"));
|
|
|
33
33
|
const utils_1 = require("./utils");
|
|
34
34
|
const Context = (0, react_1.createContext)(null);
|
|
35
35
|
/**
|
|
36
|
-
* Провайдер,
|
|
36
|
+
* Провайдер, предоставляющий контекст для использования хуком useBreakpoint.
|
|
37
|
+
* Не является обязательным, используется в целях оптимизации.
|
|
37
38
|
* @param props Свойства.
|
|
38
39
|
* @return Элемент.
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
function BreakpointProvider({ children }) {
|
|
41
42
|
const [contextValue, setRegistry] = (0, react_1.useState)(null);
|
|
42
43
|
(0, __1.useIsomorphicLayoutEffect)(() => {
|
|
43
44
|
(0, is_browser_1.default)() && setRegistry((0, utils_1.createRegistry)());
|
|
44
45
|
}, []);
|
|
45
46
|
return react_1.default.createElement(Context.Provider, { value: contextValue }, children);
|
|
46
|
-
}
|
|
47
|
+
}
|
|
47
48
|
exports.BreakpointProvider = BreakpointProvider;
|
|
48
49
|
/**
|
|
49
50
|
* Хук обработки медиа-запроса на основе breakpoint'а дизайн-системы.
|
|
50
51
|
* @param query Запрос, например "xs+".
|
|
51
52
|
* @return Соответствует ли ширина экрана заданному запросу.
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
function useBreakpoint(query) {
|
|
54
55
|
if (!utils_1.BreakpointQuery.isValid(query)) {
|
|
55
56
|
throw Error(`useBreakpoint: Invalid query, "${query}"`);
|
|
56
57
|
}
|
|
57
|
-
const
|
|
58
|
+
const [, setRegistry] = (0, react_1.useState)(null);
|
|
59
|
+
const registryFromContext = (0, react_1.useContext)(Context);
|
|
58
60
|
const [matches, setMatches] = (0, react_1.useState)(false);
|
|
59
61
|
(0, __1.useIsomorphicLayoutEffect)(() => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
let registry;
|
|
63
|
+
if (registryFromContext) {
|
|
64
|
+
registry = registryFromContext;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
registry = (0, utils_1.createRegistry)();
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
setRegistry(registryFromContext);
|
|
70
|
+
const subscription = registry.subscribe(query, e => {
|
|
71
|
+
setMatches(e.matches);
|
|
72
|
+
});
|
|
73
|
+
setMatches(subscription.matches);
|
|
74
|
+
return subscription.unsubscribe;
|
|
75
|
+
}, [registryFromContext]);
|
|
68
76
|
return matches;
|
|
69
|
-
}
|
|
77
|
+
}
|
|
70
78
|
exports.useBreakpoint = useBreakpoint;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export declare type ChangeHandler = (event: {
|
|
1
|
+
export type Direction = '+' | '-';
|
|
2
|
+
export type ChangeHandler = (event: {
|
|
4
3
|
matches: boolean;
|
|
5
4
|
}) => void;
|
|
6
5
|
export interface RegistryItem {
|
|
@@ -11,7 +10,7 @@ export interface Subscription {
|
|
|
11
10
|
matches: boolean;
|
|
12
11
|
unsubscribe: () => void;
|
|
13
12
|
}
|
|
14
|
-
export
|
|
13
|
+
export type Registry = {
|
|
15
14
|
items: Record<string, RegistryItem | undefined>;
|
|
16
15
|
subscribe: (query: string, handler: ChangeHandler) => Subscription;
|
|
17
16
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Breakpoint
|
|
1
|
+
import { Breakpoint } from '../../types';
|
|
2
|
+
import { Direction, Registry } from './types';
|
|
2
3
|
export declare const BreakpointQuery: {
|
|
3
4
|
readonly getBreakpoint: (query: string) => string;
|
|
4
5
|
readonly getDirection: (query: string) => string;
|
|
@@ -43,7 +43,8 @@ const createRegistry = () => {
|
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
45
|
const newItem = {
|
|
46
|
-
|
|
46
|
+
// ВАЖНО: используем "window.matchMedia" вместо "matchMedia" тк падают ошибки в некоторых браузерах
|
|
47
|
+
mql: window.matchMedia(exports.BreakpointQuery.toMediaQuery(query)),
|
|
47
48
|
handlers: new Set([listener]),
|
|
48
49
|
};
|
|
49
50
|
// не предусматриваем отписку и удаление mql за ненадобностью
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect, RefObject, MutableRefObject, DependencyList } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* При монтировании проверяет, поддерживает ли устройство touch события.
|
|
4
4
|
* @return True - если поддерживает, false - если нет.
|
|
5
5
|
*/
|
|
6
|
-
export declare
|
|
6
|
+
export declare function useIsTouchDevice(): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Реализует подписку на событие полной прокрутки списка.
|
|
9
9
|
* @param ref Реф прокручиваемого элемента.
|
|
@@ -12,18 +12,18 @@ export declare const useIsTouchDevice: () => boolean;
|
|
|
12
12
|
* @param options.threshold Отступ от конца списка по которому событие должно срабатывать.
|
|
13
13
|
* @param moreDeps Зависимости эффекта (нужны, когда ref заполняется не на этапе render'а).
|
|
14
14
|
*/
|
|
15
|
-
export declare
|
|
16
|
-
onFullScroll?: (
|
|
17
|
-
threshold?: number
|
|
18
|
-
}, moreDeps?:
|
|
15
|
+
export declare function useInfiniteScroll(ref: MutableRefObject<HTMLElement | undefined | null>, { onFullScroll, threshold, }: {
|
|
16
|
+
onFullScroll?: (event: UIEvent) => void;
|
|
17
|
+
threshold?: number;
|
|
18
|
+
}, moreDeps?: DependencyList): void;
|
|
19
19
|
/**
|
|
20
20
|
* Запускает переданный обработчик при клике вне элемента.
|
|
21
21
|
* @param elementRef Ref элемента, клик вне которого нужно обработать.
|
|
22
22
|
* @param callback Сработает при клике вне элемента.
|
|
23
23
|
*/
|
|
24
|
-
export declare
|
|
24
|
+
export declare function useOutsideClick(elementRef: RefObject<Element | undefined | null> | RefObject<Element | undefined | null>[], callback: undefined | ((e: MouseEvent) => void)): void;
|
|
25
25
|
/**
|
|
26
26
|
* Нужен для того чтобы не получать ошибку при использовании в SSR с NodeJS.
|
|
27
27
|
* @see {@link https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85#gistcomment-2911761}
|
|
28
28
|
*/
|
|
29
|
-
export declare const useIsomorphicLayoutEffect: typeof
|
|
29
|
+
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|