@sima-land/ui-nucleons 44.2.10 → 45.0.0-alpha.1
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/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 +34 -3
- 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} +2 -2
- package/{colors.js → colors/index.js} +2 -1
- package/colors.scss +2 -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 +47 -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 +32 -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-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-util.scss +37 -0
- package/link/link.module.scss +19 -12
- 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 +56 -65
- 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 +7 -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/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 +59 -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 +96 -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-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/_internal/{checkbox/index.js → page-scroll-lock/types.js} +0 -0
- /package/{hint → hint-deprecated}/hint.module.scss +0 -0
- /package/{select → select-deprecated}/select.module.scss +0 -0
- /package/{upload → upload-area}/upload.svg +0 -0
package/select/index.js
CHANGED
|
@@ -1,111 +1,5 @@
|
|
|
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.Select =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const dropdown_item_1 = require("../dropdown-item");
|
|
44
|
-
const text_field_1 = require("../text-field");
|
|
45
|
-
const dropdown_2 = require("../_internal/utils/dropdown");
|
|
46
|
-
const bind_1 = __importDefault(require("classnames/bind"));
|
|
47
|
-
const down_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Stroked/Arrows/down"));
|
|
48
|
-
const up_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Stroked/Arrows/up"));
|
|
49
|
-
const select_module_scss_1 = __importDefault(require("./select.module.scss"));
|
|
50
|
-
const colors_1 = require("../colors");
|
|
51
|
-
const dropdown_loading_1 = require("../_internal/dropdown-loading");
|
|
52
|
-
const hooks_1 = require("../hooks");
|
|
53
|
-
const cx = bind_1.default.bind(select_module_scss_1.default);
|
|
54
|
-
/**
|
|
55
|
-
* Выводит иконку стрелки для поля Select по умолчанию.
|
|
56
|
-
* @param opened Открыт ли список опций.
|
|
57
|
-
* @return Элемент.
|
|
58
|
-
*/
|
|
59
|
-
const renderDefaultArrow = (opened) => {
|
|
60
|
-
const ArrowSVG = opened ? up_1.default : down_1.default;
|
|
61
|
-
return react_1.default.createElement(ArrowSVG, { fill: colors_1.COLORS.get('basic-gray38') });
|
|
62
|
-
};
|
|
63
|
-
exports.renderDefaultArrow = renderDefaultArrow;
|
|
64
|
-
/**
|
|
65
|
-
* Поле выбора из списка.
|
|
66
|
-
* @param props Свойства.
|
|
67
|
-
* @return Элемент.
|
|
68
|
-
*/
|
|
69
|
-
const Select = (_a) => {
|
|
70
|
-
var { options, optionSize, onSelect, style, className, label, onClick, value, loading, onMenuToggle, renderOption = String, 'data-testid': dataTestId, size, endAdornment = exports.renderDefaultArrow } = _a, restProps = __rest(_a, ["options", "optionSize", "onSelect", "style", "className", "label", "onClick", "value", "loading", "onMenuToggle", "renderOption", 'data-testid', "size", "endAdornment"]);
|
|
71
|
-
const rootRef = (0, react_1.useRef)(null);
|
|
72
|
-
const fieldRef = (0, react_1.useRef)(null);
|
|
73
|
-
const menuRef = (0, react_1.useRef)(null);
|
|
74
|
-
const [opened, toggleMenu] = (0, react_1.useState)(false);
|
|
75
|
-
(0, react_1.useEffect)(() => {
|
|
76
|
-
opened && menuRef.current && menuRef.current.focus();
|
|
77
|
-
onMenuToggle && onMenuToggle(opened);
|
|
78
|
-
}, [opened]);
|
|
79
|
-
(0, hooks_1.useOutsideClick)(rootRef, toggleMenu.bind(null, false));
|
|
80
|
-
return (react_1.default.createElement("div", { ref: rootRef, style: style, className: cx('root', className), "data-testid": dataTestId },
|
|
81
|
-
react_1.default.createElement(text_field_1.TextField, Object.assign({}, restProps, { size: size, blockProps: {
|
|
82
|
-
ref: fieldRef,
|
|
83
|
-
tabIndex: 0,
|
|
84
|
-
onMouseDown: () => {
|
|
85
|
-
toggleMenu(a => !a);
|
|
86
|
-
},
|
|
87
|
-
onKeyDown: e => {
|
|
88
|
-
e.key === 'Enter' && toggleMenu(true);
|
|
89
|
-
},
|
|
90
|
-
}, onClick: e => {
|
|
91
|
-
e.preventDefault();
|
|
92
|
-
onClick && onClick(e);
|
|
93
|
-
}, className: select_module_scss_1.default.field, "data-testid": 'select:field', label: label, focused: opened, baseInputProps: {
|
|
94
|
-
// чтобы не ловить фокус на поле
|
|
95
|
-
style: { pointerEvents: 'none' },
|
|
96
|
-
tabIndex: -1,
|
|
97
|
-
}, value: value, multiline: false, variant: 'desktop', readOnly: true, endAdornment: typeof endAdornment === 'function' ? endAdornment(opened) : endAdornment })),
|
|
98
|
-
opened && (loading || options.length > 0) && (react_1.default.createElement(dropdown_1.Dropdown, Object.assign({}, (0, dropdown_2.placeDropdown)(size), { ref: menuRef, "data-testid": 'select:menu', role: 'menu', tabIndex: -1, className: cx('menu'), onKeyDown: event => {
|
|
99
|
-
if (event.key === 'Enter') {
|
|
100
|
-
toggleMenu(false);
|
|
101
|
-
fieldRef.current && fieldRef.current.focus();
|
|
102
|
-
}
|
|
103
|
-
}, onBlur: () => {
|
|
104
|
-
toggleMenu(false);
|
|
105
|
-
fieldRef.current && fieldRef.current.focus();
|
|
106
|
-
} }), loading ? (react_1.default.createElement(dropdown_loading_1.DropdownLoading, { "data-testid": 'select:loading-area' })) : (options.map((option, index) => (react_1.default.createElement(dropdown_item_1.DropdownItem, { size: optionSize, key: index, role: 'menuitem', onClick: () => {
|
|
107
|
-
toggleMenu(false);
|
|
108
|
-
onSelect && onSelect(option);
|
|
109
|
-
} }, renderOption(option)))))))));
|
|
110
|
-
};
|
|
111
|
-
exports.Select = Select;
|
|
3
|
+
exports.Select = void 0;
|
|
4
|
+
var select_1 = require("./select");
|
|
5
|
+
Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return select_1.Select; } });
|
|
@@ -0,0 +1,70 @@
|
|
|
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.SelectFieldBlock = void 0;
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const utils_1 = require("../utils");
|
|
32
|
+
const field_block_1 = require("../../field-block");
|
|
33
|
+
const colors_1 = require("../../colors");
|
|
34
|
+
const up_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Stroked/Arrows/up"));
|
|
35
|
+
const down_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Stroked/Arrows/down"));
|
|
36
|
+
const block_module_scss_1 = __importDefault(require("./block.module.scss"));
|
|
37
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
38
|
+
/**
|
|
39
|
+
* Компонент открывашки в виде поля.
|
|
40
|
+
* @param props Свойства.
|
|
41
|
+
* @return Элемент.
|
|
42
|
+
*/
|
|
43
|
+
function SelectFieldBlock(props) {
|
|
44
|
+
var _a;
|
|
45
|
+
const binding = (0, react_1.useContext)(utils_1.SelectContext);
|
|
46
|
+
const [focused, setFocused] = (0, react_1.useState)(false);
|
|
47
|
+
const ArrowSVG = binding.opened ? up_1.default : down_1.default;
|
|
48
|
+
// @todo прокидывать ref в props.blockRef при необходимости
|
|
49
|
+
const ref = (0, react_1.useRef)(null);
|
|
50
|
+
(0, react_1.useImperativeHandle)(binding.anchorRef, () => ref.current);
|
|
51
|
+
(0, react_1.useImperativeHandle)(binding.openerRef, () => ref.current);
|
|
52
|
+
return (react_1.default.createElement(field_block_1.FieldBlock, Object.assign({ label: binding.label, adornmentEnd: react_1.default.createElement(ArrowSVG, { fill: colors_1.COLORS.get('basic-gray24') }) }, props, { failed: binding.failed, disabled: binding.disabled, fixedHeight: true, blockRef: ref, blockProps: Object.assign(Object.assign({}, props === null || props === void 0 ? void 0 : props.blockProps), { onFocus: event => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
setFocused(true);
|
|
55
|
+
(_b = (_a = props.blockProps) === null || _a === void 0 ? void 0 : _a.onFocus) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
56
|
+
}, onBlur: event => {
|
|
57
|
+
var _a, _b;
|
|
58
|
+
setFocused(false);
|
|
59
|
+
(_b = (_a = props.blockProps) === null || _a === void 0 ? void 0 : _a.onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
60
|
+
}, onKeyDown: event => {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
(_a = binding.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(binding, event);
|
|
63
|
+
(_c = (_b = props.blockProps) === null || _b === void 0 ? void 0 : _b.onKeyDown) === null || _c === void 0 ? void 0 : _c.call(_b, event);
|
|
64
|
+
}, onMouseDown: event => {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
(_a = binding.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(binding, event);
|
|
67
|
+
(_c = (_b = props.blockProps) === null || _b === void 0 ? void 0 : _b.onMouseDown) === null || _c === void 0 ? void 0 : _c.call(_b, event);
|
|
68
|
+
}, role: 'combobox', tabIndex: binding.disabled ? undefined : 0, className: (0, classnames_1.default)(block_module_scss_1.default.block, (_a = props.blockProps) === null || _a === void 0 ? void 0 : _a.className) }), focused: focused || binding.opened, labelAsPlaceholder: !binding.value, main: binding.value, mainProps: { className: block_module_scss_1.default.main } })));
|
|
69
|
+
}
|
|
70
|
+
exports.SelectFieldBlock = SelectFieldBlock;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TextButtonAsButtonProps } from '../../text-button';
|
|
3
|
+
/**
|
|
4
|
+
* Компонент открывашки в виде текстовой кнопки.
|
|
5
|
+
* @param props Свойства.
|
|
6
|
+
* @return Элемент.
|
|
7
|
+
*/
|
|
8
|
+
export declare function SelectTextButton({ buttonRef: buttonRefProp, children, onKeyDown, onMouseDown, ...props }: TextButtonAsButtonProps): JSX.Element;
|
|
@@ -0,0 +1,69 @@
|
|
|
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.SelectTextButton = void 0;
|
|
41
|
+
const react_1 = __importStar(require("react"));
|
|
42
|
+
const text_button_1 = require("../../text-button");
|
|
43
|
+
const utils_1 = require("../utils");
|
|
44
|
+
const up_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Stroked/Arrows/up"));
|
|
45
|
+
const down_1 = __importDefault(require("@sima-land/ui-quarks/icons/16x16/Stroked/Arrows/down"));
|
|
46
|
+
/**
|
|
47
|
+
* Компонент открывашки в виде текстовой кнопки.
|
|
48
|
+
* @param props Свойства.
|
|
49
|
+
* @return Элемент.
|
|
50
|
+
*/
|
|
51
|
+
function SelectTextButton(_a) {
|
|
52
|
+
var { buttonRef: buttonRefProp, children, onKeyDown, onMouseDown } = _a, props = __rest(_a, ["buttonRef", "children", "onKeyDown", "onMouseDown"]);
|
|
53
|
+
const buttonRef = (0, react_1.useRef)(null);
|
|
54
|
+
const binding = (0, react_1.useContext)(utils_1.SelectContext);
|
|
55
|
+
const ArrowSVG = binding.opened ? up_1.default : down_1.default;
|
|
56
|
+
(0, react_1.useImperativeHandle)(buttonRefProp, () => buttonRef.current);
|
|
57
|
+
(0, react_1.useImperativeHandle)(binding.anchorRef, () => buttonRef.current);
|
|
58
|
+
(0, react_1.useImperativeHandle)(binding.openerRef, () => buttonRef.current);
|
|
59
|
+
return (react_1.default.createElement(text_button_1.TextButton, Object.assign({ iconGutter: 4, endIcon: ArrowSVG }, props, { as: 'button', onMouseDown: event => {
|
|
60
|
+
var _a;
|
|
61
|
+
(_a = binding.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(binding, event);
|
|
62
|
+
onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
|
|
63
|
+
}, onKeyDown: event => {
|
|
64
|
+
var _a;
|
|
65
|
+
(_a = binding.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(binding, event);
|
|
66
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
67
|
+
}, disabled: binding.disabled, buttonRef: buttonRef, role: 'combobox' }), children !== null && children !== void 0 ? children : (binding.value || binding.label)));
|
|
68
|
+
}
|
|
69
|
+
exports.SelectTextButton = SelectTextButton;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SelectMenuProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Меню выбора для компонента Select.
|
|
5
|
+
* @param props Свойства.
|
|
6
|
+
* @return Элемент.
|
|
7
|
+
*/
|
|
8
|
+
export declare function SelectMenu({ loading, children, menuRef, value, onKeyDown, onItemSelect, ...restProps }: SelectMenuProps): JSX.Element;
|
|
@@ -0,0 +1,105 @@
|
|
|
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.SelectMenu = void 0;
|
|
41
|
+
const react_1 = __importStar(require("react"));
|
|
42
|
+
const dropdown_1 = require("../../dropdown");
|
|
43
|
+
const dropdown_item_1 = require("../../dropdown-item");
|
|
44
|
+
const utils_1 = require("../../dropdown-item/utils");
|
|
45
|
+
const dropdown_loading_1 = require("../../_internal/dropdown-loading");
|
|
46
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
47
|
+
const menu_module_scss_1 = __importDefault(require("./menu.module.scss"));
|
|
48
|
+
const MenuItemAttr = {
|
|
49
|
+
name: 'data-select-role',
|
|
50
|
+
value: 'option',
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Меню выбора для компонента Select.
|
|
54
|
+
* @param props Свойства.
|
|
55
|
+
* @return Элемент.
|
|
56
|
+
*/
|
|
57
|
+
function SelectMenu(_a) {
|
|
58
|
+
var { loading, children, menuRef, value, onKeyDown, onItemSelect } = _a, restProps = __rest(_a, ["loading", "children", "menuRef", "value", "onKeyDown", "onItemSelect"]);
|
|
59
|
+
const ref = (0, react_1.useRef)(null);
|
|
60
|
+
const osComponentRef = (0, react_1.useRef)(null);
|
|
61
|
+
const [activeIndex, setActiveIndex] = (0, react_1.useState)(-1);
|
|
62
|
+
const items = react_1.Children.toArray(children).filter(utils_1.DropdownItemUtils.is);
|
|
63
|
+
(0, react_1.useImperativeHandle)(menuRef, () => ref.current);
|
|
64
|
+
// прокрутка до элемента списка
|
|
65
|
+
(0, react_1.useEffect)(() => {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const menu = ref.current;
|
|
68
|
+
const itemSelector = `[${MenuItemAttr.name}="${MenuItemAttr.value}"]`;
|
|
69
|
+
const targetItem = menu === null || menu === void 0 ? void 0 : menu.querySelectorAll(itemSelector)[activeIndex];
|
|
70
|
+
if (targetItem instanceof HTMLElement) {
|
|
71
|
+
(_b = (_a = osComponentRef.current) === null || _a === void 0 ? void 0 : _a.osInstance()) === null || _b === void 0 ? void 0 : _b.scroll({
|
|
72
|
+
el: targetItem,
|
|
73
|
+
scroll: { y: 'ifneeded' },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}, [activeIndex]);
|
|
77
|
+
const handleMenuKeyDown = (0, react_1.useCallback)(event => {
|
|
78
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
79
|
+
switch (event.code) {
|
|
80
|
+
case 'Enter': {
|
|
81
|
+
const item = items[activeIndex];
|
|
82
|
+
if (item) {
|
|
83
|
+
onItemSelect === null || onItemSelect === void 0 ? void 0 : onItemSelect(item);
|
|
84
|
+
}
|
|
85
|
+
setActiveIndex(-1);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'ArrowUp':
|
|
89
|
+
setActiveIndex(n => { var _a; return (_a = utils_1.DropdownItemUtils.asLoopedIterator(items, n).prev()) !== null && _a !== void 0 ? _a : -1; });
|
|
90
|
+
break;
|
|
91
|
+
case 'ArrowDown':
|
|
92
|
+
setActiveIndex(n => { var _a; return (_a = utils_1.DropdownItemUtils.asLoopedIterator(items, n).next()) !== null && _a !== void 0 ? _a : -1; });
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}, [items, activeIndex, onKeyDown]);
|
|
96
|
+
const handleItemClick = (0, react_1.useCallback)((item) => item.props.disabled
|
|
97
|
+
? undefined
|
|
98
|
+
: event => {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
(_b = (_a = item.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
101
|
+
onItemSelect === null || onItemSelect === void 0 ? void 0 : onItemSelect(item);
|
|
102
|
+
}, [onItemSelect]);
|
|
103
|
+
return (react_1.default.createElement(dropdown_1.Dropdown, Object.assign({}, restProps, { ref: ref, tabIndex: 0, role: 'listbox', onKeyDown: handleMenuKeyDown, className: (0, classnames_1.default)(menu_module_scss_1.default.menu, restProps.className), customScrollbarProps: { osComponentRef } }), loading ? (react_1.default.createElement(dropdown_loading_1.DropdownLoading, { "data-testid": 'select:loading-area' })) : (items.map((item, index) => (react_1.default.createElement(dropdown_item_1.DropdownItem, Object.assign({ checked: activeIndex === index, selected: value === utils_1.DropdownItemUtils.getValue(item) }, item.props, { key: index, role: 'option', onClick: handleItemClick(item) }, { [MenuItemAttr.name]: MenuItemAttr.value })))))));
|
|
104
|
+
}
|
|
105
|
+
exports.SelectMenu = SelectMenu;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SelectProps } from './types';
|
|
3
|
+
import { SelectFieldBlock } from './parts/block';
|
|
4
|
+
import { SelectTextButton } from './parts/button';
|
|
5
|
+
/**
|
|
6
|
+
* Поле выбора из списка.
|
|
7
|
+
* @param props Свойства.
|
|
8
|
+
* @return Элемент.
|
|
9
|
+
*/
|
|
10
|
+
export declare function Select({ children, disabled, failed, loading, onValueChange, onMenuToggle, value, defaultValue, label, opener, renderValue, dropdownProps, }: SelectProps): JSX.Element;
|
|
11
|
+
export declare namespace Select {
|
|
12
|
+
var FieldBlock: typeof SelectFieldBlock;
|
|
13
|
+
var TextButton: typeof SelectTextButton;
|
|
14
|
+
}
|
package/select/select.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.Select = void 0;
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const utils_1 = require("./utils");
|
|
40
|
+
const identity_1 = require("../hooks/identity");
|
|
41
|
+
const utils_2 = require("../dropdown-item/utils");
|
|
42
|
+
const react_2 = require("@floating-ui/react");
|
|
43
|
+
const menu_1 = require("./parts/menu");
|
|
44
|
+
const block_1 = require("./parts/block");
|
|
45
|
+
const button_1 = require("./parts/button");
|
|
46
|
+
const utils_3 = require("../dropdown/utils");
|
|
47
|
+
/**
|
|
48
|
+
* Поле выбора из списка.
|
|
49
|
+
* @param props Свойства.
|
|
50
|
+
* @return Элемент.
|
|
51
|
+
*/
|
|
52
|
+
function Select({ children, disabled, failed, loading, onValueChange, onMenuToggle, value, defaultValue, label, opener = react_1.default.createElement(block_1.SelectFieldBlock, null), renderValue = v => v, dropdownProps, }) {
|
|
53
|
+
// @todo по аналогии с <select /> надо проверять, есть ли значение в списке переданных
|
|
54
|
+
const [initialValue] = (0, react_1.useState)(() => { var _a; return (_a = value !== null && value !== void 0 ? value : defaultValue) !== null && _a !== void 0 ? _a : ''; });
|
|
55
|
+
const [currentValue, setCurrentValue] = (0, react_1.useState)(initialValue);
|
|
56
|
+
const [needMenu, setNeedMenu] = (0, react_1.useState)(false);
|
|
57
|
+
const [menuElement, setMenuElement] = (0, react_1.useState)(null);
|
|
58
|
+
const [menuFocused, setMenuFocused] = (0, react_1.useState)(false);
|
|
59
|
+
const onMenuToggleRef = (0, identity_1.useIdentityRef)(onMenuToggle);
|
|
60
|
+
const openerRef = (0, react_1.useRef)(null);
|
|
61
|
+
const menuShown = needMenu && menuElement !== null;
|
|
62
|
+
const _a = (0, react_2.useFloating)(Object.assign({ open: needMenu }, (0, utils_3.dropdownFloatingConfig)())), { refs, isPositioned } = _a, floating = __rest(_a, ["refs", "isPositioned"]);
|
|
63
|
+
(0, react_1.useImperativeHandle)(refs.setFloating, () => menuElement, [menuElement]);
|
|
64
|
+
(0, react_1.useEffect)(() => {
|
|
65
|
+
if (typeof value !== 'undefined') {
|
|
66
|
+
// @todo по аналогии с <select /> надо проверять, есть ли значение в списке переданных
|
|
67
|
+
setCurrentValue(value);
|
|
68
|
+
}
|
|
69
|
+
}, [value]);
|
|
70
|
+
(0, react_1.useEffect)(() => {
|
|
71
|
+
var _a;
|
|
72
|
+
if (disabled) {
|
|
73
|
+
setNeedMenu(false);
|
|
74
|
+
}
|
|
75
|
+
if (!disabled && menuElement && isPositioned) {
|
|
76
|
+
menuElement.focus();
|
|
77
|
+
}
|
|
78
|
+
// @todo menuShown в зависимости или useCallback
|
|
79
|
+
(_a = onMenuToggleRef.current) === null || _a === void 0 ? void 0 : _a.call(onMenuToggleRef, { opened: menuShown });
|
|
80
|
+
}, [disabled, menuElement, isPositioned]);
|
|
81
|
+
const openerBinding = {
|
|
82
|
+
label,
|
|
83
|
+
anchorRef: refs.setReference,
|
|
84
|
+
openerRef,
|
|
85
|
+
value: renderValue(currentValue),
|
|
86
|
+
opened: menuShown,
|
|
87
|
+
failed,
|
|
88
|
+
disabled,
|
|
89
|
+
menuFocused,
|
|
90
|
+
onMouseDown: event => {
|
|
91
|
+
if (!disabled) {
|
|
92
|
+
!menuElement && event.preventDefault();
|
|
93
|
+
setNeedMenu(a => !a);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
onKeyDown: e => {
|
|
97
|
+
if (!disabled) {
|
|
98
|
+
switch (e.code) {
|
|
99
|
+
case 'Enter':
|
|
100
|
+
case 'ArrowUp':
|
|
101
|
+
case 'ArrowDown':
|
|
102
|
+
setNeedMenu(true);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const floatingStyle = (0, utils_3.useDropdownFloatingStyle)(Object.assign({ refs }, floating));
|
|
109
|
+
const menuProps = Object.assign(Object.assign({}, dropdownProps), { style: Object.assign(Object.assign({}, dropdownProps === null || dropdownProps === void 0 ? void 0 : dropdownProps.style), floatingStyle), menuRef: setMenuElement, value,
|
|
110
|
+
loading, onFocus: () => {
|
|
111
|
+
setMenuFocused(true);
|
|
112
|
+
}, onBlur: () => {
|
|
113
|
+
setNeedMenu(false);
|
|
114
|
+
setMenuFocused(false);
|
|
115
|
+
}, onKeyDown: event => {
|
|
116
|
+
var _a, _b;
|
|
117
|
+
switch (event.code) {
|
|
118
|
+
case 'ArrowUp':
|
|
119
|
+
case 'ArrowDown':
|
|
120
|
+
event.preventDefault(); // предотвращаем прокрутку страницы
|
|
121
|
+
break;
|
|
122
|
+
case 'Enter':
|
|
123
|
+
case 'Escape':
|
|
124
|
+
(_a = openerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
125
|
+
break;
|
|
126
|
+
case 'Tab':
|
|
127
|
+
event.preventDefault(); // предотвращаем фокус на следующем элементе
|
|
128
|
+
(_b = openerRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}, onItemSelect: item => {
|
|
132
|
+
var _a;
|
|
133
|
+
const nextValue = utils_2.DropdownItemUtils.getValue(item);
|
|
134
|
+
setCurrentValue(nextValue);
|
|
135
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(nextValue);
|
|
136
|
+
setNeedMenu(false);
|
|
137
|
+
(_a = openerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
138
|
+
} });
|
|
139
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
140
|
+
react_1.default.createElement(utils_1.SelectContext.Provider, { value: openerBinding }, (0, react_1.isValidElement)(opener) && opener),
|
|
141
|
+
react_1.default.createElement(react_2.FloatingPortal, { id: '' }, needMenu && react_1.default.createElement(menu_1.SelectMenu, Object.assign({}, menuProps), children))));
|
|
142
|
+
}
|
|
143
|
+
exports.Select = Select;
|
|
144
|
+
Select.FieldBlock = block_1.SelectFieldBlock;
|
|
145
|
+
Select.TextButton = button_1.SelectTextButton;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { FocusEventHandler, HTMLAttributes, ReactElement, ReactNode, Ref } from 'react';
|
|
2
|
+
import type { DropdownProps } from '../dropdown';
|
|
3
|
+
import type { DropdownItemElement } from '../dropdown-item/types';
|
|
4
|
+
import type { FieldBlockStyle } from '../field-block';
|
|
5
|
+
export interface SelectStyle extends FieldBlockStyle {
|
|
6
|
+
'--dropdown-width'?: string | number;
|
|
7
|
+
}
|
|
8
|
+
export interface SelectOpenerBinding {
|
|
9
|
+
label?: string;
|
|
10
|
+
failed?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
value: ReactNode;
|
|
13
|
+
opened: boolean;
|
|
14
|
+
menuFocused: boolean;
|
|
15
|
+
openerRef: Ref<HTMLElement | null>;
|
|
16
|
+
anchorRef: Ref<HTMLElement | null>;
|
|
17
|
+
onMouseDown: Required<HTMLAttributes<HTMLElement>>['onMouseDown'];
|
|
18
|
+
onKeyDown: Required<HTMLAttributes<HTMLElement>>['onKeyDown'];
|
|
19
|
+
}
|
|
20
|
+
export interface SelectMenuProps extends DropdownProps {
|
|
21
|
+
menuRef?: Ref<HTMLDivElement | null>;
|
|
22
|
+
value?: ReactNode;
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
onBlur?: FocusEventHandler;
|
|
26
|
+
onItemSelect?: (item: DropdownItemElement) => void;
|
|
27
|
+
}
|
|
28
|
+
export interface SelectProps {
|
|
29
|
+
/** Опции. */
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
/** Отключенное состояние. */
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
/** Ошибочное состояние. */
|
|
34
|
+
failed?: boolean;
|
|
35
|
+
/** Состояние загрузки опций. */
|
|
36
|
+
loading?: boolean;
|
|
37
|
+
/** Сработает при выборе опции. */
|
|
38
|
+
onValueChange?: (value: string) => void;
|
|
39
|
+
/** Сработает при открытии/закрытии меню. */
|
|
40
|
+
onMenuToggle?: (state: {
|
|
41
|
+
opened: boolean;
|
|
42
|
+
}) => void;
|
|
43
|
+
/** Значение, выводимое в качестве выбранного. При отсутствии будет выведено значение defaultValue. */
|
|
44
|
+
value?: string;
|
|
45
|
+
/** Значение по умолчанию. При отсутствии будет выведено значение label. */
|
|
46
|
+
defaultValue?: string;
|
|
47
|
+
/** Получив значение являющееся текущим или пустую строку, должна вернуть ReactNode. */
|
|
48
|
+
renderValue?: (value: string) => ReactNode;
|
|
49
|
+
/** Ярлык. */
|
|
50
|
+
label?: string;
|
|
51
|
+
/** Открывающий элемент. */
|
|
52
|
+
opener?: ReactElement;
|
|
53
|
+
/** Опции Dropdown. */
|
|
54
|
+
dropdownProps?: Pick<DropdownProps, 'className' | 'style'>;
|
|
55
|
+
}
|
package/select/types.js
ADDED
package/select/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectContext = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.SelectContext = (0, react_1.createContext)({
|
|
6
|
+
value: '',
|
|
7
|
+
opened: false,
|
|
8
|
+
menuFocused: false,
|
|
9
|
+
openerRef: (0, react_1.createRef)(),
|
|
10
|
+
anchorRef: (0, react_1.createRef)(),
|
|
11
|
+
onMouseDown: () => void 0,
|
|
12
|
+
onKeyDown: () => void 0,
|
|
13
|
+
});
|