@sima-land/ui-nucleons 42.0.0 → 42.1.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/package.json +1 -1
- package/select/index.d.ts +9 -2
- package/select/index.js +13 -4
package/package.json
CHANGED
package/select/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TextFieldProps } from '../text-field';
|
|
3
3
|
declare type Size = 's' | 'm' | 'l' | 'xl';
|
|
4
|
-
export interface SelectProps extends Omit<TextFieldProps, 'style'> {
|
|
4
|
+
export interface SelectProps extends Omit<TextFieldProps, 'style' | 'endAdornment'> {
|
|
5
5
|
/** Нужно ли выводить состояние загрузки списка. */
|
|
6
6
|
loading?: boolean;
|
|
7
7
|
/** Сработает при открытии/закрытии меню. */
|
|
@@ -16,11 +16,18 @@ export interface SelectProps extends Omit<TextFieldProps, 'style'> {
|
|
|
16
16
|
renderOption?: (option: any) => React.ReactNode;
|
|
17
17
|
/** Стили. */
|
|
18
18
|
style?: React.CSSProperties;
|
|
19
|
+
endAdornment?: TextFieldProps['endAdornment'] | ((opened: boolean) => React.ReactNode);
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Выводит иконку стрелки для поля Select по умолчанию.
|
|
23
|
+
* @param opened Открыт ли список опций.
|
|
24
|
+
* @return Элемент.
|
|
25
|
+
*/
|
|
26
|
+
export declare const renderDefaultArrow: (opened: boolean) => JSX.Element;
|
|
20
27
|
/**
|
|
21
28
|
* Поле выбора из списка.
|
|
22
29
|
* @param props Свойства.
|
|
23
30
|
* @return Элемент.
|
|
24
31
|
*/
|
|
25
|
-
export declare const Select: ({ options, optionSize, onSelect, style, className, label, onClick, value, loading, onMenuToggle, renderOption, "data-testid": dataTestId, size, ...restProps }: SelectProps) => JSX.Element;
|
|
32
|
+
export declare const Select: ({ options, optionSize, onSelect, style, className, label, onClick, value, loading, onMenuToggle, renderOption, "data-testid": dataTestId, size, endAdornment, ...restProps }: SelectProps) => JSX.Element;
|
|
26
33
|
export {};
|
package/select/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
33
33
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Select = void 0;
|
|
36
|
+
exports.Select = exports.renderDefaultArrow = void 0;
|
|
37
37
|
const react_1 = __importStar(require("react"));
|
|
38
38
|
const dropdown_1 = require("../dropdown");
|
|
39
39
|
const dropdown_item_1 = require("../dropdown-item");
|
|
@@ -47,18 +47,27 @@ const colors_1 = require("../colors");
|
|
|
47
47
|
const dropdown_loading_1 = require("../_internal/dropdown-loading");
|
|
48
48
|
const hooks_1 = require("../hooks");
|
|
49
49
|
const cx = bind_1.default.bind(select_module_scss_1.default);
|
|
50
|
+
/**
|
|
51
|
+
* Выводит иконку стрелки для поля Select по умолчанию.
|
|
52
|
+
* @param opened Открыт ли список опций.
|
|
53
|
+
* @return Элемент.
|
|
54
|
+
*/
|
|
55
|
+
const renderDefaultArrow = (opened) => {
|
|
56
|
+
const ArrowSVG = opened ? up_1.default : down_1.default;
|
|
57
|
+
return react_1.default.createElement(ArrowSVG, { fill: colors_1.COLORS.get('gray38') });
|
|
58
|
+
};
|
|
59
|
+
exports.renderDefaultArrow = renderDefaultArrow;
|
|
50
60
|
/**
|
|
51
61
|
* Поле выбора из списка.
|
|
52
62
|
* @param props Свойства.
|
|
53
63
|
* @return Элемент.
|
|
54
64
|
*/
|
|
55
65
|
const Select = (_a) => {
|
|
56
|
-
var { options, optionSize, onSelect, style, className, label, onClick, value, loading, onMenuToggle, renderOption = String, 'data-testid': dataTestId, size } = _a, restProps = __rest(_a, ["options", "optionSize", "onSelect", "style", "className", "label", "onClick", "value", "loading", "onMenuToggle", "renderOption", 'data-testid', "size"]);
|
|
66
|
+
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"]);
|
|
57
67
|
const rootRef = (0, react_1.useRef)(null);
|
|
58
68
|
const fieldRef = (0, react_1.useRef)(null);
|
|
59
69
|
const menuRef = (0, react_1.useRef)(null);
|
|
60
70
|
const [opened, toggleMenu] = (0, react_1.useState)(false);
|
|
61
|
-
const ArrowSVG = opened ? up_1.default : down_1.default;
|
|
62
71
|
(0, react_1.useEffect)(() => {
|
|
63
72
|
opened && menuRef.current && menuRef.current.focus();
|
|
64
73
|
onMenuToggle && onMenuToggle(opened);
|
|
@@ -82,7 +91,7 @@ const Select = (_a) => {
|
|
|
82
91
|
// чтобы не ловить фокус на поле
|
|
83
92
|
style: { pointerEvents: 'none' },
|
|
84
93
|
tabIndex: -1,
|
|
85
|
-
}, value: value, multiline: false, variant: 'desktop', readOnly: true, endAdornment:
|
|
94
|
+
}, value: value, multiline: false, variant: 'desktop', readOnly: true, endAdornment: typeof endAdornment === 'function' ? endAdornment(opened) : endAdornment })),
|
|
86
95
|
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 => {
|
|
87
96
|
if (event.key === 'Enter') {
|
|
88
97
|
toggleMenu(false);
|