@hh.ru/magritte-ui-select 5.1.8

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/Select.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { ReactElement } from 'react';
2
+ import type { SelectProps } from './types';
3
+ declare const Select: {
4
+ <ShowClearButtonType extends boolean, MultipleType extends boolean, T>({ multiple, showClearButton, showCloseButtonInNavigationBar, onChange: onChangeHandler, value: valueSelect, renderItem, renderItemForDesktop, options, maxHeight, widthEqualToActivator, maxWidth, bottomSheetHeight, dropHost, maxSelectedOptions, searchable, ...props }: SelectProps<ShowClearButtonType, MultipleType, T>): ReactElement;
5
+ displayName: string;
6
+ };
7
+ export { Select };
package/Select.js ADDED
@@ -0,0 +1,142 @@
1
+ import './index.css';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { useState, useRef, useEffect, useCallback } from 'react';
4
+ import { match } from '@hh.ru/magritte-common-fuzzy-search';
5
+ import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
6
+ import { SelectForDesktopDevice } from './SelectForDesktopDevice.js';
7
+ import { SelectForMobileDevice } from './SelectForMobileDevice.js';
8
+ import { useSelectOptionsList } from './useSelectOptionsList.js';
9
+ import { useSelectState } from './useSelectState.js';
10
+ import '@hh.ru/magritte-common-keyboard';
11
+ import '@hh.ru/magritte-common-use-multiple-refs';
12
+ import '@hh.ru/magritte-ui-card';
13
+ import '@hh.ru/magritte-ui-cell';
14
+ import '@hh.ru/magritte-ui-drop';
15
+ import '@hh.ru/magritte-ui-icon/icon';
16
+ import './SelectActivator-e0a9d95a.js';
17
+ import 'classnames';
18
+ import '@hh.ru/magritte-internal-field-hint';
19
+ import '@hh.ru/magritte-ui-counter';
20
+ import '@hh.ru/magritte-ui-input/BaseInput';
21
+ import '@hh.ru/magritte-ui-typography';
22
+ import './SelectOption.js';
23
+ import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
24
+ import '@hh.ru/magritte-ui-checkbox-radio';
25
+ import './getChecked.js';
26
+ import '@hh.ru/magritte-ui-bottom-sheet';
27
+ import '@hh.ru/magritte-ui-input';
28
+ import '@hh.ru/magritte-ui-navigation-bar';
29
+
30
+ const getValue = (values) => {
31
+ if (values === undefined) {
32
+ return [];
33
+ }
34
+ return typeof values === 'string' ? [values] : values;
35
+ };
36
+ const Select = ({ multiple, showClearButton, showCloseButtonInNavigationBar = false, onChange: onChangeHandler, value: valueSelect, renderItem, renderItemForDesktop, options, maxHeight = 460, widthEqualToActivator = true, maxWidth, bottomSheetHeight = 'full-screen', dropHost, maxSelectedOptions, searchable, ...props }) => {
37
+ const { isMobile } = useBreakpoint();
38
+ const [commitChanges, setCommitChanges] = useState();
39
+ const previousCommitChanges = useRef(commitChanges);
40
+ const [searchValue, setSearchValue] = useState('');
41
+ const [optionList, setOptionList] = useState(options);
42
+ const optionListSearchText = useRef([]);
43
+ const valueSelectArray = getValue(valueSelect);
44
+ const [selectedOptions, setSelectedOptions] = useState(() => valueSelectArray ? options.filter(({ value }) => valueSelectArray.includes(value)) : []);
45
+ const { optionsListRef, activatorRef, onActivatorClick, onClearSelectionClick, onOptionsListClose, showOptions } = useSelectOptionsList(!!searchable);
46
+ const { values, onChange, clearSelectedValues, setLastValues } = useSelectState(!!multiple, valueSelect || []);
47
+ useEffect(() => {
48
+ const nextSelectedOptions = options.filter(({ value }) => valueSelectArray.includes(value));
49
+ const isEqualsSelect = nextSelectedOptions.every((item) => {
50
+ return selectedOptions.includes(item);
51
+ });
52
+ if (!isEqualsSelect) {
53
+ setSelectedOptions(options.filter(({ value }) => valueSelectArray.includes(value)));
54
+ }
55
+ }, [options, valueSelectArray, selectedOptions]);
56
+ const optionListProps = {
57
+ ...props,
58
+ searchable,
59
+ onChange,
60
+ maxWidth,
61
+ widthEqualToActivator,
62
+ visible: showOptions,
63
+ setLastValues,
64
+ clearSelectedValues: () => {
65
+ clearSelectedValues();
66
+ setCommitChanges(performance.now());
67
+ onClearSelectionClick();
68
+ },
69
+ maxHeight,
70
+ bottomSheetHeight,
71
+ onActivatorClick,
72
+ values,
73
+ multiple,
74
+ selectedOptions,
75
+ onOptionsListClose,
76
+ searchValue,
77
+ setSearchValue,
78
+ optionsListRef,
79
+ activatorRef,
80
+ options: optionList,
81
+ optionsCount: options.length,
82
+ setCommitChanges,
83
+ showClearButton,
84
+ isLimitExceeded: maxSelectedOptions !== undefined && Array.isArray(values) && values.length >= maxSelectedOptions,
85
+ };
86
+ useEffect(() => {
87
+ if (optionListSearchText.current.length === 0 && showOptions && optionsListRef.current) {
88
+ const options = optionsListRef.current.querySelectorAll('[data-magritte-option]');
89
+ optionListSearchText.current = [...options].map((optionElement) => {
90
+ return {
91
+ search: optionElement.innerText ?? optionElement.textContent,
92
+ value: optionElement.dataset.magritteOption,
93
+ };
94
+ });
95
+ }
96
+ if (!showOptions) {
97
+ setSearchValue('');
98
+ }
99
+ }, [optionsListRef, showOptions]);
100
+ useEffect(() => {
101
+ if (searchValue === '') {
102
+ setOptionList(options);
103
+ }
104
+ else {
105
+ const optionToVisible = optionListSearchText.current
106
+ .filter(({ search }) => {
107
+ const result = match(searchValue, search);
108
+ return result;
109
+ })
110
+ .map(({ value }) => value);
111
+ const nextOptions = options.filter(({ value }) => optionToVisible.includes(value));
112
+ setOptionList(nextOptions);
113
+ }
114
+ }, [searchValue, options]);
115
+ const onChangeSelect = useCallback(() => onChangeHandler(values), [values, onChangeHandler]);
116
+ // обработка выбора значения селекта
117
+ useEffect(() => {
118
+ // если изменения не было, то ничего не делаем
119
+ if (previousCommitChanges.current === commitChanges) {
120
+ return;
121
+ }
122
+ if (!multiple) {
123
+ onOptionsListClose();
124
+ }
125
+ onChangeSelect();
126
+ }, [isMobile, onChangeSelect, commitChanges, multiple, onOptionsListClose]);
127
+ useEffect(() => {
128
+ if (previousCommitChanges.current !== commitChanges) {
129
+ const nextSelectedOptions = options.filter(({ value }) => Array.isArray(values) ? values.includes(value) : values === value);
130
+ setSelectedOptions(nextSelectedOptions);
131
+ previousCommitChanges.current = commitChanges;
132
+ }
133
+ }, [options, values, commitChanges]);
134
+ if (isMobile) {
135
+ return (jsx(SelectForMobileDevice, { ...optionListProps, showCloseButtonInNavigationBar: showCloseButtonInNavigationBar, renderItem: renderItem }));
136
+ }
137
+ return (jsx(SelectForDesktopDevice, { ...optionListProps, renderItemForDesktop: renderItemForDesktop, dropHost: dropHost }));
138
+ };
139
+ Select.displayName = 'Select';
140
+
141
+ export { Select };
142
+ //# sourceMappingURL=Select.js.map
package/Select.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Select.js","sources":["../src/Select.tsx"],"sourcesContent":["import { ReactElement, useState, useEffect, useRef, useCallback } from 'react';\n\nimport { match } from '@hh.ru/magritte-common-fuzzy-search';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { SelectForDesktopDevice } from '@hh.ru/magritte-ui-select/SelectForDesktopDevice';\nimport { SelectForMobileDevice } from '@hh.ru/magritte-ui-select/SelectForMobileDevice';\nimport type { SelectProps, SelectOption } from '@hh.ru/magritte-ui-select/types';\nimport { useSelectOptionsList } from '@hh.ru/magritte-ui-select/useSelectOptionsList';\nimport { useSelectState } from '@hh.ru/magritte-ui-select/useSelectState';\n\nconst getValue = (values?: string | string[]): string[] => {\n if (values === undefined) {\n return [];\n }\n return typeof values === 'string' ? [values] : values;\n};\n\nconst Select = <ShowClearButtonType extends boolean, MultipleType extends boolean, T>({\n multiple,\n showClearButton,\n showCloseButtonInNavigationBar = false,\n onChange: onChangeHandler,\n value: valueSelect,\n renderItem,\n renderItemForDesktop,\n options,\n maxHeight = 460,\n widthEqualToActivator = true,\n maxWidth,\n bottomSheetHeight = 'full-screen',\n dropHost,\n maxSelectedOptions,\n searchable,\n ...props\n}: SelectProps<ShowClearButtonType, MultipleType, T>): ReactElement => {\n const { isMobile } = useBreakpoint();\n const [commitChanges, setCommitChanges] = useState<number | undefined>();\n const previousCommitChanges = useRef(commitChanges);\n const [searchValue, setSearchValue] = useState('');\n const [optionList, setOptionList] = useState(options);\n const optionListSearchText = useRef<{ search: string; value: string }[]>([]);\n\n const valueSelectArray = getValue(valueSelect);\n const [selectedOptions, setSelectedOptions] = useState<SelectOption<T>[]>(() =>\n valueSelectArray ? options.filter(({ value }) => valueSelectArray.includes(value)) : []\n );\n\n const { optionsListRef, activatorRef, onActivatorClick, onClearSelectionClick, onOptionsListClose, showOptions } =\n useSelectOptionsList(!!searchable);\n\n const { values, onChange, clearSelectedValues, setLastValues } = useSelectState<MultipleType>(\n !!multiple,\n valueSelect || []\n );\n\n useEffect(() => {\n const nextSelectedOptions = options.filter(({ value }) => valueSelectArray.includes(value));\n const isEqualsSelect = nextSelectedOptions.every((item) => {\n return selectedOptions.includes(item);\n });\n\n if (!isEqualsSelect) {\n setSelectedOptions(options.filter(({ value }) => valueSelectArray.includes(value)));\n }\n }, [options, valueSelectArray, selectedOptions]);\n\n const optionListProps = {\n ...props,\n searchable,\n onChange,\n maxWidth,\n widthEqualToActivator,\n visible: showOptions,\n setLastValues,\n clearSelectedValues: () => {\n clearSelectedValues();\n setCommitChanges(performance.now());\n onClearSelectionClick();\n },\n maxHeight,\n bottomSheetHeight,\n onActivatorClick,\n values,\n multiple,\n selectedOptions,\n onOptionsListClose,\n searchValue,\n setSearchValue,\n optionsListRef,\n activatorRef,\n options: optionList,\n optionsCount: options.length,\n setCommitChanges,\n showClearButton,\n isLimitExceeded:\n maxSelectedOptions !== undefined && Array.isArray(values) && values.length >= maxSelectedOptions,\n };\n\n useEffect(() => {\n if (optionListSearchText.current.length === 0 && showOptions && optionsListRef.current) {\n const options = optionsListRef.current.querySelectorAll<HTMLDivElement>('[data-magritte-option]');\n optionListSearchText.current = [...options].map((optionElement) => {\n return {\n search: optionElement.innerText ?? optionElement.textContent,\n value: optionElement.dataset.magritteOption as string,\n };\n });\n }\n if (!showOptions) {\n setSearchValue('');\n }\n }, [optionsListRef, showOptions]);\n\n useEffect(() => {\n if (searchValue === '') {\n setOptionList(options);\n } else {\n const optionToVisible = optionListSearchText.current\n .filter(({ search }) => {\n const result = match(searchValue, search);\n return result;\n })\n .map(({ value }) => value);\n const nextOptions = options.filter(({ value }) => optionToVisible.includes(value));\n\n setOptionList(nextOptions);\n }\n }, [searchValue, options]);\n\n const onChangeSelect = useCallback(() => onChangeHandler(values), [values, onChangeHandler]);\n\n // обработка выбора значения селекта\n useEffect(() => {\n // если изменения не было, то ничего не делаем\n if (previousCommitChanges.current === commitChanges) {\n return;\n }\n\n if (!multiple) {\n onOptionsListClose();\n }\n\n onChangeSelect();\n }, [isMobile, onChangeSelect, commitChanges, multiple, onOptionsListClose]);\n\n useEffect(() => {\n if (previousCommitChanges.current !== commitChanges) {\n const nextSelectedOptions = options.filter(({ value }) =>\n Array.isArray(values) ? values.includes(value) : values === value\n );\n setSelectedOptions(nextSelectedOptions);\n previousCommitChanges.current = commitChanges;\n }\n }, [options, values, commitChanges]);\n\n if (isMobile) {\n return (\n <SelectForMobileDevice\n {...optionListProps}\n showCloseButtonInNavigationBar={showCloseButtonInNavigationBar}\n renderItem={renderItem}\n />\n );\n }\n\n return (\n <SelectForDesktopDevice {...optionListProps} renderItemForDesktop={renderItemForDesktop} dropHost={dropHost} />\n );\n};\n\nSelect.displayName = 'Select';\n\nexport { Select };\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,QAAQ,GAAG,CAAC,MAA0B,KAAc;IACtD,IAAI,MAAM,KAAK,SAAS,EAAE;AACtB,QAAA,OAAO,EAAE,CAAC;AACb,KAAA;AACD,IAAA,OAAO,OAAO,MAAM,KAAK,QAAQ,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;AAC1D,CAAC,CAAC;AAEI,MAAA,MAAM,GAAG,CAAuE,EAClF,QAAQ,EACR,eAAe,EACf,8BAA8B,GAAG,KAAK,EACtC,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE,WAAW,EAClB,UAAU,EACV,oBAAoB,EAC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+ import './index.css';
2
+ import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
3
+ import { forwardRef, useRef, Fragment, useEffect } from 'react';
4
+ import classnames from 'classnames';
5
+ import { keyboardMatches, keyboardKeys } from '@hh.ru/magritte-common-keyboard';
6
+ import { FieldHint } from '@hh.ru/magritte-internal-field-hint';
7
+ import { Counter } from '@hh.ru/magritte-ui-counter';
8
+ import { ChevronDownOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
9
+ import { BaseInput } from '@hh.ru/magritte-ui-input/BaseInput';
10
+ import { Text } from '@hh.ru/magritte-ui-typography';
11
+
12
+ var styles = {"select-activator":"magritte-select-activator___9XXwA_5-1-8","selectActivator":"magritte-select-activator___9XXwA_5-1-8","select-activator-label":"magritte-select-activator-label___Mc49R_5-1-8","selectActivatorLabel":"magritte-select-activator-label___Mc49R_5-1-8","select-activator-placeholder":"magritte-select-activator-placeholder___7ODSn_5-1-8","selectActivatorPlaceholder":"magritte-select-activator-placeholder___7ODSn_5-1-8","select-activator-value":"magritte-select-activator-value___wDbVR_5-1-8","selectActivatorValue":"magritte-select-activator-value___wDbVR_5-1-8","select-activator-chevron":"magritte-select-activator-chevron___DHIUH_5-1-8","selectActivatorChevron":"magritte-select-activator-chevron___DHIUH_5-1-8","select-activator-disabled":"magritte-select-activator-disabled___mYKi2_5-1-8","selectActivatorDisabled":"magritte-select-activator-disabled___mYKi2_5-1-8","select-activator-item":"magritte-select-activator-item___JsY4v_5-1-8","selectActivatorItem":"magritte-select-activator-item___JsY4v_5-1-8","select-activator-invalid":"magritte-select-activator-invalid___IdlRp_5-1-8","selectActivatorInvalid":"magritte-select-activator-invalid___IdlRp_5-1-8","select-activator-size-large":"magritte-select-activator-size-large___MIXAH_5-1-8","selectActivatorSizeLarge":"magritte-select-activator-size-large___MIXAH_5-1-8","select-activator-with-label":"magritte-select-activator-with-label___DwcKr_5-1-8","selectActivatorWithLabel":"magritte-select-activator-with-label___DwcKr_5-1-8","select-activator-label-root":"magritte-select-activator-label-root___eYIWQ_5-1-8","selectActivatorLabelRoot":"magritte-select-activator-label-root___eYIWQ_5-1-8","select-activator-has-counter":"magritte-select-activator-has-counter___k2Kc2_5-1-8","selectActivatorHasCounter":"magritte-select-activator-has-counter___k2Kc2_5-1-8","select-activator-ellipsis":"magritte-select-activator-ellipsis___16zkC_5-1-8","selectActivatorEllipsis":"magritte-select-activator-ellipsis___16zkC_5-1-8","select-activator-chevron-animation-timeout":"magritte-select-activator-chevron-animation-timeout___y19bf_5-1-8","selectActivatorChevronAnimationTimeout":"magritte-select-activator-chevron-animation-timeout___y19bf_5-1-8","select-activator-chevron-up":"magritte-select-activator-chevron-up___gtPyi_5-1-8","selectActivatorChevronUp":"magritte-select-activator-chevron-up___gtPyi_5-1-8","select-options":"magritte-select-options___y2KYZ_5-1-8","selectOptions":"magritte-select-options___y2KYZ_5-1-8","select-options-xs":"magritte-select-options-xs___BiiPo_5-1-8","selectOptionsXs":"magritte-select-options-xs___BiiPo_5-1-8","optionDelimiter":"magritte-optionDelimiter___OaKsB_5-1-8"};
13
+
14
+ const SelectActivator = forwardRef(({ placeholder, size = 'medium', elevatePlaceholder = false, disabled = false, multiple, invalid = false, searchable = false, selectedOptions, onClick, onFocus, onBlur, searchValue, setSearchValue, description, errorMessage, visible, dropRef, searchRef, }, ref) => {
15
+ const prevVisibleRef = useRef(visible);
16
+ const focusedRef = useRef(false);
17
+ const counter = multiple ? selectedOptions?.length ?? 0 : 0;
18
+ const value = selectedOptions?.map(({ label, value }, index) => (jsxs(Fragment, { children: [label, index === selectedOptions.length - 1 ? '' : ', '] }, value)));
19
+ const hintContent = (jsx(FieldHint, { description: description, errorMessage: errorMessage, disabled: disabled, focused: visible, invalid: invalid }, "hint"));
20
+ useEffect(() => {
21
+ if (prevVisibleRef.current && !visible) {
22
+ onBlur?.();
23
+ }
24
+ else if (visible) {
25
+ onFocus?.();
26
+ }
27
+ prevVisibleRef.current = visible;
28
+ }, [visible, onBlur, onFocus]);
29
+ if (searchable && visible) {
30
+ const sizeProp = size === 'large' ? { size: 'large' } : { size: 'medium' };
31
+ return (jsxs(Fragment$1, { children: [jsx(BaseInput, { ...sizeProp, wrapperRef: ref, onKeyDown: (event) => {
32
+ if (dropRef?.current &&
33
+ keyboardMatches(event.nativeEvent, [keyboardKeys.ArrowDown, keyboardKeys.Tab])) {
34
+ const focusableElement = dropRef.current.querySelector('[data-magritte-option-first-active-element]');
35
+ event.preventDefault();
36
+ event.stopPropagation();
37
+ focusableElement?.focus();
38
+ }
39
+ if (visible && keyboardMatches(event.nativeEvent, [keyboardKeys.Escape])) {
40
+ event.stopPropagation();
41
+ const dropHost = dropRef?.current || document.body;
42
+ dropHost?.dispatchEvent(new KeyboardEvent(event.type, { key: event.key, code: event.code }));
43
+ }
44
+ }, ref: (input) => {
45
+ input?.focus();
46
+ if (searchRef) {
47
+ searchRef.current = input;
48
+ }
49
+ }, value: searchValue, onChange: setSearchValue, "data-qa": "magritte-select-activator-input", placeholder: selectedOptions.length > 0 ? value : placeholder, counter: counter === 0 ? undefined : counter, autoComplete: "off" }), hintContent] }));
50
+ }
51
+ const showValue = selectedOptions.length > 0;
52
+ const showPlaceholder = !!(placeholder && !showValue);
53
+ const isLargeSize = size === 'large';
54
+ const showLabel = !!(isLargeSize && placeholder && elevatePlaceholder && showValue);
55
+ return (jsxs(Fragment$1, { children: [jsxs("div", { ref: ref, "data-qa": "magritte-select-activator", className: classnames(styles.selectActivator, {
56
+ [styles.selectActivatorSizeLarge]: isLargeSize,
57
+ [styles.selectActivatorWithLabel]: showLabel,
58
+ [styles.selectActivatorHasCounter]: counter > 0,
59
+ [styles.selectActivatorDisabled]: disabled,
60
+ [styles.selectActivatorInvalid]: invalid,
61
+ }), onClick: () => {
62
+ if (disabled) {
63
+ return;
64
+ }
65
+ if (!focusedRef.current) {
66
+ onClick(!visible);
67
+ }
68
+ focusedRef.current = false;
69
+ }, onFocus: () => {
70
+ if (disabled) {
71
+ return;
72
+ }
73
+ onClick(true);
74
+ focusedRef.current = true;
75
+ }, onBlur: () => {
76
+ focusedRef.current = false;
77
+ }, tabIndex: disabled ? -1 : 0, children: [jsxs("div", { className: styles.selectActivatorLabelRoot, children: [showPlaceholder && (jsx("div", { className: styles.selectActivatorPlaceholder, children: jsx(Text, { typography: "label-2-regular", children: jsx("div", { className: styles.selectActivatorEllipsis, children: placeholder }) }) })), showLabel && (jsx("div", { className: styles.selectActivatorLabel, children: jsx(Text, { typography: "label-4-regular", children: jsx("div", { className: styles.selectActivatorEllipsis, children: placeholder }) }) })), showValue && (jsx("div", { className: styles.selectActivatorValue, children: jsx(Text, { typography: "label-2-regular", children: jsx("div", { className: styles.selectActivatorEllipsis, children: value }) }) }))] }), jsxs("div", { className: styles.selectActivatorItem, children: [counter > 0 && jsx(Counter, { label: counter }), jsx("div", { className: classnames(styles.selectActivatorChevron, {
78
+ [styles.selectActivatorChevronUp]: visible,
79
+ }), children: jsx(ChevronDownOutlinedSize24, {}) })] })] }), hintContent] }));
80
+ });
81
+ SelectActivator.displayName = 'SelectActivator';
82
+ const renderSelectActivator = (props) => {
83
+ return jsx(SelectActivator, { ...props });
84
+ };
85
+
86
+ export { SelectActivator as S, renderSelectActivator as r, styles as s };
87
+ //# sourceMappingURL=SelectActivator-e0a9d95a.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectActivator-e0a9d95a.js","sources":["../src/SelectActivator.tsx"],"sourcesContent":["import { type ForwardedRef, type ReactNode, forwardRef, useEffect, Fragment, useRef, RefObject } from 'react';\nimport classnames from 'classnames';\n\nimport { keyboardMatches, keyboardKeys } from '@hh.ru/magritte-common-keyboard';\nimport { FieldHint } from '@hh.ru/magritte-internal-field-hint';\nimport { Counter } from '@hh.ru/magritte-ui-counter';\nimport { ChevronDownOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { BaseInput } from '@hh.ru/magritte-ui-input/BaseInput';\nimport { type SelectActivatorProps } from '@hh.ru/magritte-ui-select/types';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './styles.less';\n\nconst SelectActivator = forwardRef(\n <T,>(\n {\n placeholder,\n size = 'medium',\n elevatePlaceholder = false,\n disabled = false,\n multiple,\n invalid = false,\n searchable = false,\n selectedOptions,\n onClick,\n onFocus,\n onBlur,\n searchValue,\n setSearchValue,\n description,\n errorMessage,\n visible,\n dropRef,\n searchRef,\n }: SelectActivatorProps<T>,\n ref: ForwardedRef<HTMLElement>\n ) => {\n const prevVisibleRef = useRef(visible);\n const focusedRef = useRef(false);\n const counter = multiple ? selectedOptions?.length ?? 0 : 0;\n const value = selectedOptions?.map(({ label, value }, index) => (\n <Fragment key={value}>\n {label}\n {index === selectedOptions.length - 1 ? '' : ', '}\n </Fragment>\n ));\n\n const hintContent = (\n <FieldHint\n key=\"hint\"\n description={description}\n errorMessage={errorMessage}\n disabled={disabled}\n focused={visible}\n invalid={invalid}\n />\n );\n\n useEffect(() => {\n if (prevVisibleRef.current && !visible) {\n onBlur?.();\n } else if (visible) {\n onFocus?.();\n }\n prevVisibleRef.current = visible;\n }, [visible, onBlur, onFocus]);\n\n if (searchable && visible) {\n const sizeProp = size === 'large' ? ({ size: 'large' } as const) : ({ size: 'medium' } as const);\n\n return (\n <>\n <BaseInput\n {...sizeProp}\n wrapperRef={ref as ForwardedRef<HTMLDivElement> | undefined}\n onKeyDown={(event) => {\n if (\n dropRef?.current &&\n keyboardMatches(event.nativeEvent, [keyboardKeys.ArrowDown, keyboardKeys.Tab])\n ) {\n const focusableElement = dropRef.current.querySelector(\n '[data-magritte-option-first-active-element]'\n ) as HTMLElement;\n event.preventDefault();\n event.stopPropagation();\n focusableElement?.focus();\n }\n if (visible && keyboardMatches(event.nativeEvent, [keyboardKeys.Escape])) {\n event.stopPropagation();\n const dropHost = dropRef?.current || document.body;\n dropHost?.dispatchEvent(\n new KeyboardEvent(event.type, { key: event.key, code: event.code })\n );\n }\n }}\n ref={(input) => {\n input?.focus();\n if (searchRef) {\n searchRef.current = input;\n }\n }}\n value={searchValue}\n onChange={setSearchValue}\n data-qa=\"magritte-select-activator-input\"\n placeholder={selectedOptions.length > 0 ? value : placeholder}\n counter={counter === 0 ? undefined : counter}\n autoComplete=\"off\"\n />\n {hintContent}\n </>\n );\n }\n\n const showValue = selectedOptions.length > 0;\n const showPlaceholder = !!(placeholder && !showValue);\n const isLargeSize = size === 'large';\n const showLabel = !!(isLargeSize && placeholder && elevatePlaceholder && showValue);\n\n return (\n <>\n <div\n ref={ref as RefObject<HTMLDivElement>}\n data-qa=\"magritte-select-activator\"\n className={classnames(styles.selectActivator, {\n [styles.selectActivatorSizeLarge]: isLargeSize,\n [styles.selectActivatorWithLabel]: showLabel,\n [styles.selectActivatorHasCounter]: counter > 0,\n [styles.selectActivatorDisabled]: disabled,\n [styles.selectActivatorInvalid]: invalid,\n })}\n onClick={() => {\n if (disabled) {\n return;\n }\n\n if (!focusedRef.current) {\n onClick(!visible);\n }\n focusedRef.current = false;\n }}\n onFocus={() => {\n if (disabled) {\n return;\n }\n onClick(true);\n focusedRef.current = true;\n }}\n onBlur={() => {\n focusedRef.current = false;\n }}\n tabIndex={disabled ? -1 : 0}\n >\n <div className={styles.selectActivatorLabelRoot}>\n {showPlaceholder && (\n <div className={styles.selectActivatorPlaceholder}>\n <Text typography=\"label-2-regular\">\n <div className={styles.selectActivatorEllipsis}>{placeholder}</div>\n </Text>\n </div>\n )}\n {showLabel && (\n <div className={styles.selectActivatorLabel}>\n <Text typography=\"label-4-regular\">\n <div className={styles.selectActivatorEllipsis}>{placeholder}</div>\n </Text>\n </div>\n )}\n {showValue && (\n <div className={styles.selectActivatorValue}>\n <Text typography=\"label-2-regular\">\n <div className={styles.selectActivatorEllipsis}>{value}</div>\n </Text>\n </div>\n )}\n </div>\n <div className={styles.selectActivatorItem}>\n {counter > 0 && <Counter label={counter} />}\n <div\n className={classnames(styles.selectActivatorChevron, {\n [styles.selectActivatorChevronUp]: visible,\n })}\n >\n <ChevronDownOutlinedSize24 />\n </div>\n </div>\n </div>\n {hintContent}\n </>\n );\n }\n);\n\nSelectActivator.displayName = 'SelectActivator';\n\nconst renderSelectActivator = <T,>(props: SelectActivatorProps<T>): ReactNode => {\n return <SelectActivator {...props} />;\n};\n\nexport { SelectActivator, renderSelectActivator };\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;;;;;;;;;;AAaM,MAAA,eAAe,GAAG,UAAU,CAC9B,CACI,EACI,WAAW,EACX,IAAI,GAAG,QAAQ,EACf,kBAAkB,GAAG,KAAK,EAC1B,QAAQ,GAAG,KAAK,EAChB,QAAQ,EACR,OAAO,GAAG,KAAK,EACf,UAAU,GAAG,KAAK,EAClB,eAAe,EACf,OAAO,EACP,OAAO,EACP,MAAM,EACN,WAAW,EACX,cAAc,EACd,WAAW,EACX,YAAY,EACZ,OAAO,EACP,OAAO,EACP,SAAS,GACa,EAC1B,GAA8B,KAC9B;AACA,IAAA,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AACvC,IAAA,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC,IAAA,MAAM,OAAO,GAAG,QAAQ,GAAG,eAAe,EAAE,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5D,IAAA,MAAM,KAAK,GAAG,eAAe,EAAE,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,MACvDA,KAAC,QAAQ,EAAA,EAAA,QAAA,EAAA,CACJ,KAAK,EACL,KAAK,KAAK,eAAe,CAAC,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA,EAAA,EAFtC,KAAK,CAGT,CACd,CAAC,CAAC;AAEH,IAAA,MAAM,WAAW,IACbC,GAAA,CAAC,SAAS,EAAA,EAEN,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAAA,EALZ,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'./types';
3
+ declare const SelectActivator: import("react").ForwardRefExoticComponent<SelectActivatorProps<unknown> & import("react").RefAttributes<HTMLElement>>;
4
+ declare const renderSelectActivator: <T>(props: SelectActivatorProps<T>) => ReactNode;
5
+ export { SelectActivator, renderSelectActivator };
@@ -0,0 +1,12 @@
1
+ import './index.css';
2
+ import 'react/jsx-runtime';
3
+ import 'react';
4
+ import 'classnames';
5
+ import '@hh.ru/magritte-common-keyboard';
6
+ import '@hh.ru/magritte-internal-field-hint';
7
+ import '@hh.ru/magritte-ui-counter';
8
+ import '@hh.ru/magritte-ui-icon/icon';
9
+ import '@hh.ru/magritte-ui-input/BaseInput';
10
+ import '@hh.ru/magritte-ui-typography';
11
+ export { S as SelectActivator, r as renderSelectActivator } from './SelectActivator-e0a9d95a.js';
12
+ //# sourceMappingURL=SelectActivator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectActivator.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1,22 @@
1
+ import { type ReactElement, RefObject } from 'react';
2
+ import type { InternalSelectProps, RenderItem } from './types';
3
+ export declare const SelectForDesktopDevice: {
4
+ <T, MultipleType extends boolean>({ name, options, disabled, multiple, onChange, onActivatorClick, maxHeight, values, visible, onOptionsListClose, selectedOptions, renderItemForDesktop, clearSelectedValues, setCommitChanges, searchValue, showClearButton, trls, optionsListRef, size, elevatePlaceholder, widthEqualToActivator, maxWidth, dropHost, isLimitExceeded, activatorRef, ...activatorProps }: Omit<import("./types").SelectProps<boolean, boolean, T>, "onChange" | "value" | "renderItemForDesktop" | "renderItem"> & {
5
+ onActivatorClick: (visible: boolean) => void;
6
+ selectedOptions: import("@hh.ru/magritte-ui-select/types").SelectOption<T>[];
7
+ values: [MultipleType] extends [true] ? string[] : string;
8
+ visible: boolean;
9
+ onOptionsListClose: VoidFunction;
10
+ optionsListRef: RefObject<HTMLElement>;
11
+ activatorRef: RefObject<HTMLElement>;
12
+ onChange: import("@hh.ru/magritte-ui-select/types").OnChangeAction;
13
+ clearSelectedValues: VoidFunction;
14
+ setCommitChanges: import("react").Dispatch<import("react").SetStateAction<number | undefined>>;
15
+ setLastValues: VoidFunction;
16
+ isLimitExceeded: boolean;
17
+ } & Pick<import("@hh.ru/magritte-ui-select/types").SelectActivatorProps<T>, "searchValue" | "setSearchValue" | "optionsCount"> & {
18
+ renderItemForDesktop?: RenderItem<T> | undefined;
19
+ dropHost?: RefObject<HTMLElement> | undefined;
20
+ }): ReactElement;
21
+ displayName: string;
22
+ };
@@ -0,0 +1,69 @@
1
+ import './index.css';
2
+ import { useRef, createElement } from 'react';
3
+ import { jsxs, jsx } from 'react/jsx-runtime';
4
+ import { keyboardMatch, keyboardKeys } from '@hh.ru/magritte-common-keyboard';
5
+ import { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';
6
+ import { Card } from '@hh.ru/magritte-ui-card';
7
+ import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
8
+ import { Drop } from '@hh.ru/magritte-ui-drop';
9
+ import { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
10
+ import { S as SelectActivator, s as styles } from './SelectActivator-e0a9d95a.js';
11
+ import { SelectOption } from './SelectOption.js';
12
+ import { getChecked } from './getChecked.js';
13
+ import 'classnames';
14
+ import '@hh.ru/magritte-internal-field-hint';
15
+ import '@hh.ru/magritte-ui-counter';
16
+ import '@hh.ru/magritte-ui-input/BaseInput';
17
+ import '@hh.ru/magritte-ui-typography';
18
+ import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
19
+ import '@hh.ru/magritte-ui-checkbox-radio';
20
+
21
+ const SelectForDesktopDevice = ({ name, options, disabled, multiple = false, onChange, onActivatorClick, maxHeight, values, visible, onOptionsListClose, selectedOptions, renderItemForDesktop, clearSelectedValues, setCommitChanges, searchValue, showClearButton, trls, optionsListRef, size, elevatePlaceholder, widthEqualToActivator, maxWidth, dropHost, isLimitExceeded, activatorRef, ...activatorProps }) => {
22
+ const wrapperRef = useRef(null);
23
+ const dropRef = useRef(null);
24
+ const optionsMultiRef = useMultipleRefs(optionsListRef, dropRef);
25
+ const searchRef = useRef(null);
26
+ const rawOptions = options.filter(({ type }) => type !== 'delimiter');
27
+ const firstOption = rawOptions?.[0];
28
+ const lastOption = rawOptions?.[rawOptions.length - 1];
29
+ const sizeProp = size === 'large' ? { size: 'large', elevatePlaceholder } : { size: 'medium' };
30
+ return (jsxs("div", { ref: wrapperRef, tabIndex: -1, children: [jsx(SelectActivator, { ...sizeProp, ...activatorProps, disabled: disabled, selectedOptions: selectedOptions, onClick: onActivatorClick, searchValue: searchValue, ref: activatorRef, multiple: multiple, visible: visible, dropRef: dropRef, searchRef: searchRef }), jsx(Drop, { ref: optionsMultiRef, maxWidth: maxWidth, visible: options.length > 0 && visible, direction: "bottom", alignment: "left", activatorRef: activatorRef, role: activatorProps.searchable ? 'status' : 'listbox', space: 400, widthEqualToActivator: widthEqualToActivator, host: dropHost, arrowNavigation: true, forcePosition: true, closeByClickOutside: false, onClose: () => {
31
+ wrapperRef.current?.focus();
32
+ onOptionsListClose();
33
+ }, onKeyDown: ({ nativeEvent }) => {
34
+ const activeElement = document.activeElement;
35
+ const searchInput = searchRef.current;
36
+ if (searchInput !== null &&
37
+ keyboardMatch(nativeEvent, keyboardKeys.ArrowUp) &&
38
+ activeElement?.dataset.magritteOptionFirstActiveElement) {
39
+ searchInput.focus();
40
+ }
41
+ }, children: jsx("div", { style: { maxHeight: `${maxHeight}px` }, children: jsxs("div", { "data-qa": "magritte-select-option-list", className: styles.selectOptions, children: [showClearButton && (jsx(Card, { actionCard: true, showBorder: true, borderRadius: 12, padding: 16, stretched: true, hoverStyle: "neutral", onClick: () => {
42
+ clearSelectedValues();
43
+ wrapperRef.current?.focus();
44
+ }, "data-qa": "magritte-select-clear-action", "data-magritte-option-first-active-element": "true", children: jsx(Cell, { left: jsx(CrossOutlinedSize24, { initial: "secondary" }), children: jsx(CellText, { children: trls?.clearButton }) }) })), options?.map((option) => {
45
+ const checked = getChecked(option.value, values, multiple);
46
+ const props = {
47
+ ...option,
48
+ name,
49
+ onChange: (value, needToPut) => {
50
+ onChange(value, needToPut);
51
+ setCommitChanges(performance.now());
52
+ if (searchRef.current && searchValue) {
53
+ searchRef.current?.focus();
54
+ searchRef.current?.select();
55
+ }
56
+ // return focus after select item
57
+ !multiple && wrapperRef.current?.focus();
58
+ },
59
+ checked,
60
+ multiple,
61
+ isLimitExceeded,
62
+ };
63
+ return (createElement(SelectOption, { ...props, isFirstActiveElement: !showClearButton && firstOption?.value === option.value, isLastActiveElement: lastOption?.value === option.value, key: option.value, onOptionsListClose: onOptionsListClose, render: renderItemForDesktop }));
64
+ })] }) }) })] }));
65
+ };
66
+ SelectForDesktopDevice.displayName = 'SelectForDesktopDevice';
67
+
68
+ export { SelectForDesktopDevice };
69
+ //# sourceMappingURL=SelectForDesktopDevice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectForDesktopDevice.js","sources":["../src/SelectForDesktopDevice.tsx"],"sourcesContent":["import { type ReactElement, useRef, RefObject } from 'react';\n\nimport { keyboardKeys, keyboardMatch } from '@hh.ru/magritte-common-keyboard';\nimport { useMultipleRefs } from '@hh.ru/magritte-common-use-multiple-refs';\nimport { Card } from '@hh.ru/magritte-ui-card';\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { Drop } from '@hh.ru/magritte-ui-drop';\nimport { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { SelectActivator } from '@hh.ru/magritte-ui-select/SelectActivator';\nimport { SelectOption } from '@hh.ru/magritte-ui-select/SelectOption';\nimport { getChecked } from '@hh.ru/magritte-ui-select/getChecked';\nimport type { InternalSelectProps, RenderItem } from '@hh.ru/magritte-ui-select/types';\n\nimport styles from './styles.less';\n\nexport const SelectForDesktopDevice = <T, MultipleType extends boolean>({\n name,\n options,\n disabled,\n multiple = false,\n onChange,\n onActivatorClick,\n maxHeight,\n values,\n visible,\n onOptionsListClose,\n selectedOptions,\n renderItemForDesktop,\n clearSelectedValues,\n setCommitChanges,\n searchValue,\n showClearButton,\n trls,\n optionsListRef,\n size,\n elevatePlaceholder,\n widthEqualToActivator,\n maxWidth,\n dropHost,\n isLimitExceeded,\n activatorRef,\n ...activatorProps\n}: InternalSelectProps<T, MultipleType> & {\n renderItemForDesktop?: RenderItem<T>;\n dropHost?: RefObject<HTMLElement>;\n}): ReactElement => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const dropRef = useRef<HTMLDivElement>(null);\n const optionsMultiRef = useMultipleRefs(optionsListRef, dropRef);\n const searchRef = useRef<HTMLInputElement>(null);\n const rawOptions = options.filter(({ type }) => type !== 'delimiter');\n const firstOption = rawOptions?.[0];\n const lastOption = rawOptions?.[rawOptions.length - 1];\n const sizeProp =\n size === 'large' ? ({ size: 'large', elevatePlaceholder } as const) : ({ size: 'medium' } as const);\n\n return (\n <div ref={wrapperRef} tabIndex={-1}>\n <SelectActivator\n {...sizeProp}\n {...activatorProps}\n disabled={disabled}\n selectedOptions={selectedOptions}\n onClick={onActivatorClick}\n searchValue={searchValue}\n ref={activatorRef}\n multiple={multiple}\n visible={visible}\n dropRef={dropRef}\n searchRef={searchRef}\n />\n <Drop\n ref={optionsMultiRef}\n maxWidth={maxWidth}\n visible={options.length > 0 && visible}\n direction=\"bottom\"\n alignment=\"left\"\n activatorRef={activatorRef}\n role={activatorProps.searchable ? 'status' : 'listbox'}\n space={400}\n widthEqualToActivator={widthEqualToActivator}\n host={dropHost}\n arrowNavigation\n forcePosition\n closeByClickOutside={false}\n onClose={() => {\n wrapperRef.current?.focus();\n onOptionsListClose();\n }}\n onKeyDown={({ nativeEvent }: { nativeEvent: KeyboardEvent }) => {\n const activeElement = document.activeElement as HTMLElement;\n const searchInput = searchRef.current;\n\n if (\n searchInput !== null &&\n keyboardMatch(nativeEvent, keyboardKeys.ArrowUp) &&\n activeElement?.dataset.magritteOptionFirstActiveElement\n ) {\n searchInput.focus();\n }\n }}\n >\n <div style={{ maxHeight: `${maxHeight}px` }}>\n <div data-qa=\"magritte-select-option-list\" className={styles.selectOptions}>\n {showClearButton && (\n <Card\n actionCard\n showBorder\n borderRadius={12}\n padding={16}\n stretched\n hoverStyle=\"neutral\"\n onClick={() => {\n clearSelectedValues();\n wrapperRef.current?.focus();\n }}\n data-qa=\"magritte-select-clear-action\"\n data-magritte-option-first-active-element=\"true\"\n >\n <Cell left={<CrossOutlinedSize24 initial=\"secondary\" />}>\n <CellText>{trls?.clearButton}</CellText>\n </Cell>\n </Card>\n )}\n {options?.map((option) => {\n const checked = getChecked(option.value, values, multiple);\n const props = {\n ...option,\n name,\n onChange: (value: string, needToPut: boolean) => {\n onChange(value, needToPut);\n setCommitChanges(performance.now());\n if (searchRef.current && searchValue) {\n searchRef.current?.focus();\n searchRef.current?.select();\n }\n // return focus after select item\n !multiple && wrapperRef.current?.focus();\n },\n checked,\n multiple,\n isLimitExceeded,\n };\n return (\n <SelectOption\n {...props}\n isFirstActiveElement={!showClearButton && firstOption?.value === option.value}\n isLastActiveElement={lastOption?.value === option.value}\n key={option.value}\n onOptionsListClose={onOptionsListClose}\n render={renderItemForDesktop}\n />\n );\n })}\n </div>\n </div>\n </Drop>\n </div>\n );\n};\n\nSelectForDesktopDevice.displayName = 'SelectForDesktopDevice';\n"],"names":["_jsxs","_jsx","_createElement"],"mappings":";;;;;;;;;;;;;;;;;;;AAeO,MAAM,sBAAsB,GAAG,CAAkC,EACpE,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,GAAG,KAAK,EAChB,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACT,MAAM,EACN,OAAO,EACP,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,IAAI,EACJ,cAAc,EACd,IAAI,EACJ,kBAAkB,EAClB,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,GAAG,cAAc,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AAoB,EAAA,CAC9B,EACJ;AACN,6BAAC,CAAC,CACA,EAAA,CAAA,EAAA,CACJ,EACH,CAAA,CAAA,EAAA,CACL,EACR;AACN,EAAE;AAEF,sBAAsB,CAAC,WAAW,GAAG,wBAAwB;;;;"}
@@ -0,0 +1,22 @@
1
+ import { type ReactElement, RefObject } from 'react';
2
+ import type { InternalSelectProps, RenderItem, OnChangeAction } from './types';
3
+ export declare const SelectForMobileDevice: {
4
+ <T, MultipleType extends boolean>({ name, options, disabled, multiple, onChange, onActivatorClick, renderItem, renderActivator, values, visible, onOptionsListClose, selectedOptions, searchable, clearSelectedValues, setCommitChanges, trls, bottomSheetHeight, optionsListRef, activatorRef, searchValue, showClearButton, showCloseButtonInNavigationBar, setSearchValue, size, elevatePlaceholder, setLastValues, placeholder, applyChangesButton: _applyChangesButton, clearButton: _clearButton, isLimitExceeded, ...activatorProps }: Omit<import("./types").SelectProps<boolean, boolean, T>, "onChange" | "value" | "renderItemForDesktop" | "renderItem"> & {
5
+ onActivatorClick: (visible: boolean) => void;
6
+ selectedOptions: import("@hh.ru/magritte-ui-select/types").SelectOption<T>[];
7
+ values: [MultipleType] extends [true] ? string[] : string;
8
+ visible: boolean;
9
+ onOptionsListClose: VoidFunction;
10
+ optionsListRef: RefObject<HTMLElement>;
11
+ activatorRef: RefObject<HTMLElement>;
12
+ onChange: OnChangeAction;
13
+ clearSelectedValues: VoidFunction;
14
+ setCommitChanges: import("react").Dispatch<import("react").SetStateAction<number | undefined>>;
15
+ setLastValues: VoidFunction;
16
+ isLimitExceeded: boolean;
17
+ } & Pick<import("@hh.ru/magritte-ui-select/types").SelectActivatorProps<T>, "searchValue" | "setSearchValue" | "optionsCount"> & {
18
+ showCloseButtonInNavigationBar: boolean;
19
+ renderItem?: RenderItem<T> | undefined;
20
+ }): ReactElement;
21
+ displayName: string;
22
+ };
@@ -0,0 +1,86 @@
1
+ import './index.css';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { cloneElement, useCallback } from 'react';
4
+ import { BottomSheet, BottomSheetFooter } from '@hh.ru/magritte-ui-bottom-sheet';
5
+ import { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
6
+ import { SearchInput } from '@hh.ru/magritte-ui-input';
7
+ import { NavigationBar } from '@hh.ru/magritte-ui-navigation-bar';
8
+ import { s as styles, r as renderSelectActivator } from './SelectActivator-e0a9d95a.js';
9
+ import { SelectOption } from './SelectOption.js';
10
+ import { getChecked } from './getChecked.js';
11
+ import 'classnames';
12
+ import '@hh.ru/magritte-common-keyboard';
13
+ import '@hh.ru/magritte-internal-field-hint';
14
+ import '@hh.ru/magritte-ui-counter';
15
+ import '@hh.ru/magritte-ui-input/BaseInput';
16
+ import '@hh.ru/magritte-ui-typography';
17
+ import '@hh.ru/magritte-ui-card';
18
+ import '@hh.ru/magritte-ui-cell';
19
+ import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
20
+ import '@hh.ru/magritte-ui-checkbox-radio';
21
+
22
+ const SelectForMobileDevice = ({ name, options, disabled, multiple = false, onChange, onActivatorClick, renderItem, renderActivator = renderSelectActivator, values, visible, onOptionsListClose, selectedOptions, searchable, clearSelectedValues, setCommitChanges, trls, bottomSheetHeight, optionsListRef, activatorRef, searchValue, showClearButton, showCloseButtonInNavigationBar, setSearchValue, size, elevatePlaceholder, setLastValues, placeholder, applyChangesButton: _applyChangesButton, clearButton: _clearButton, isLimitExceeded, ...activatorProps }) => {
23
+ const sizeProp = size === 'large' ? { size: 'large', elevatePlaceholder } : { size: 'medium' };
24
+ const clearButton = showClearButton &&
25
+ _clearButton &&
26
+ cloneElement(_clearButton, {
27
+ 'data-qa': 'magritte-select-clear-action-on-xs',
28
+ onClick: clearSelectedValues,
29
+ });
30
+ const applyButton = multiple &&
31
+ _applyChangesButton &&
32
+ cloneElement(_applyChangesButton, {
33
+ 'data-qa': 'magritte-select-apply-on-xs',
34
+ onClick: () => {
35
+ setCommitChanges(performance.now());
36
+ onOptionsListClose();
37
+ },
38
+ });
39
+ const handleChange = useCallback((...args) => {
40
+ if (!multiple) {
41
+ setCommitChanges(performance.now());
42
+ onOptionsListClose();
43
+ }
44
+ onChange(...args);
45
+ }, [onChange, setCommitChanges, onOptionsListClose, multiple]);
46
+ return (jsxs("div", { ref: activatorRef, children: [renderActivator({
47
+ ...sizeProp,
48
+ ...activatorProps,
49
+ onClick: onActivatorClick,
50
+ selectedOptions,
51
+ multiple,
52
+ searchValue,
53
+ setSearchValue,
54
+ visible,
55
+ disabled,
56
+ placeholder,
57
+ }), jsx(BottomSheet, { allowScrollWhileFocused: true, keyboardOverlaysContent: false, visible: visible, onClose: () => {
58
+ onOptionsListClose();
59
+ setLastValues();
60
+ }, ref: optionsListRef, height: searchable ? 'full-screen' : bottomSheetHeight, header: jsx(NavigationBar, { title: placeholder, right: showCloseButtonInNavigationBar
61
+ ? [
62
+ {
63
+ key: 'close',
64
+ icon: CrossOutlinedSize24,
65
+ onClick: onOptionsListClose,
66
+ 'data-qa': 'bottom-sheet-navigation-close',
67
+ },
68
+ ]
69
+ : undefined, options: searchable && (jsx(SearchInput, { clearable: true, value: searchValue, onChange: setSearchValue, "data-qa": "bottom-sheet-navigation-input", autoComplete: "off" })) }), footer: multiple || showClearButton ? (jsxs(BottomSheetFooter, { children: [clearButton, applyButton] })) : null, children: jsx("div", { "data-qa": "magritte-select-option-list-on-xs", className: `${styles.selectOptions} ${styles['select-options-xs']}`, children: options?.map((option) => {
70
+ const checked = getChecked(option.value, values, multiple);
71
+ const props = {
72
+ ...option,
73
+ name,
74
+ onChange: handleChange,
75
+ checked,
76
+ multiple,
77
+ isXS: true,
78
+ isLimitExceeded,
79
+ };
80
+ return (jsx(SelectOption, { ...props, onOptionsListClose: onOptionsListClose, render: renderItem }, option.value));
81
+ }) }) })] }));
82
+ };
83
+ SelectForMobileDevice.displayName = 'SelectForMobileDevice';
84
+
85
+ export { SelectForMobileDevice };
86
+ //# sourceMappingURL=SelectForMobileDevice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectForMobileDevice.js","sources":["../src/SelectForMobileDevice.tsx"],"sourcesContent":["import { type ReactElement, useCallback, cloneElement, RefObject } from 'react';\n\nimport { BottomSheet, BottomSheetFooter } from '@hh.ru/magritte-ui-bottom-sheet';\nimport { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { SearchInput } from '@hh.ru/magritte-ui-input';\nimport { NavigationBar } from '@hh.ru/magritte-ui-navigation-bar';\nimport { renderSelectActivator } from '@hh.ru/magritte-ui-select/SelectActivator';\nimport { SelectOption } from '@hh.ru/magritte-ui-select/SelectOption';\nimport { getChecked } from '@hh.ru/magritte-ui-select/getChecked';\nimport type { InternalSelectProps, RenderItem, OnChangeAction } from '@hh.ru/magritte-ui-select/types';\n\nimport styles from './styles.less';\n\nexport const SelectForMobileDevice = <T, MultipleType extends boolean>({\n name,\n options,\n disabled,\n multiple = false,\n onChange,\n onActivatorClick,\n renderItem,\n renderActivator = renderSelectActivator,\n values,\n visible,\n onOptionsListClose,\n selectedOptions,\n searchable,\n clearSelectedValues,\n setCommitChanges,\n trls,\n bottomSheetHeight,\n optionsListRef,\n activatorRef,\n searchValue,\n showClearButton,\n showCloseButtonInNavigationBar,\n setSearchValue,\n size,\n elevatePlaceholder,\n setLastValues,\n placeholder,\n applyChangesButton: _applyChangesButton,\n clearButton: _clearButton,\n isLimitExceeded,\n ...activatorProps\n}: InternalSelectProps<T, MultipleType> & {\n showCloseButtonInNavigationBar: boolean;\n renderItem?: RenderItem<T>;\n}): ReactElement => {\n const sizeProp =\n size === 'large' ? ({ size: 'large', elevatePlaceholder } as const) : ({ size: 'medium' } as const);\n\n const clearButton =\n showClearButton &&\n _clearButton &&\n cloneElement(_clearButton, {\n 'data-qa': 'magritte-select-clear-action-on-xs',\n onClick: clearSelectedValues,\n });\n\n const applyButton =\n multiple &&\n _applyChangesButton &&\n cloneElement(_applyChangesButton, {\n 'data-qa': 'magritte-select-apply-on-xs',\n onClick: () => {\n setCommitChanges(performance.now());\n onOptionsListClose();\n },\n });\n\n const handleChange: OnChangeAction = useCallback(\n (...args) => {\n if (!multiple) {\n setCommitChanges(performance.now());\n onOptionsListClose();\n }\n onChange(...args);\n },\n [onChange, setCommitChanges, onOptionsListClose, multiple]\n );\n\n return (\n <div ref={activatorRef as RefObject<HTMLDivElement>}>\n {renderActivator({\n ...sizeProp,\n ...activatorProps,\n onClick: onActivatorClick,\n selectedOptions,\n multiple,\n searchValue,\n setSearchValue,\n visible,\n disabled,\n placeholder,\n })}\n <BottomSheet\n allowScrollWhileFocused\n keyboardOverlaysContent={false}\n visible={visible}\n onClose={() => {\n onOptionsListClose();\n setLastValues();\n }}\n ref={optionsListRef as React.RefObject<HTMLDivElement>}\n height={searchable ? 'full-screen' : bottomSheetHeight}\n header={\n <NavigationBar\n title={placeholder}\n right={\n showCloseButtonInNavigationBar\n ? [\n {\n key: 'close',\n icon: CrossOutlinedSize24,\n onClick: onOptionsListClose,\n 'data-qa': 'bottom-sheet-navigation-close',\n },\n ]\n : undefined\n }\n options={\n searchable && (\n <SearchInput\n clearable\n value={searchValue}\n onChange={setSearchValue}\n data-qa=\"bottom-sheet-navigation-input\"\n autoComplete=\"off\"\n />\n )\n }\n />\n }\n footer={\n multiple || showClearButton ? (\n <BottomSheetFooter>\n {clearButton}\n {applyButton}\n </BottomSheetFooter>\n ) : null\n }\n >\n <div\n data-qa=\"magritte-select-option-list-on-xs\"\n className={`${styles.selectOptions} ${styles['select-options-xs']}`}\n >\n {options?.map((option) => {\n const checked = getChecked(option.value, values, multiple);\n const props = {\n ...option,\n name,\n onChange: handleChange,\n checked,\n multiple,\n isXS: true,\n isLimitExceeded,\n };\n return (\n <SelectOption\n key={option.value}\n {...props}\n onOptionsListClose={onOptionsListClose}\n render={renderItem}\n />\n );\n })}\n </div>\n </BottomSheet>\n </div>\n );\n};\n\nSelectForMobileDevice.displayName = 'SelectForMobileDevice';\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;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AQ,IAAI,eAAe,IACvBD,KAAC,iBAAiB,EAAA,EAAA,QAAA,EAAA,CACb,WAAW,EACX,WAAW,CACI,EAAA,CAAA,IACpB,IAAI,EAAA,QAAA,EAGZC,GACY,CAAA,KAAA,EAAA,EAAA,SAAA,EAAA,mCAAmC,EAC3C,SAAS,EAAE,CAAG,EAAA,MAAM,CAAC,aAAa,CAAA,CAAA,EAAI,MAAM,CAAC,mBAAmB,CAAC,CAAA,CAAE,EAElE,QAAA,EAAA,OAAO,EAAE,GAAG,CAAC,CAAC,MAAM,KAAI;AACrB,wBAAA,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC3D,wBAAA,MAAM,KAAK,GAAG;AACV,4BAAA,GAAG,MAAM;4BACT,IAAI;AACJ,4BAAA,QAAQ,EAAE,YAAY;4BACtB,OAAO;4BACP,QAAQ;AACR,4BAAA,IAAI,EAAE,IAAI;4BACV,eAAe;yBAClB,CAAC;AACF,wBAAA,QACIA,GAAC,CAAA,YAAY,OAEL,KAAK,EACT,kBAAkB,EAAE,kBAAkB,EACtC,MAAM,EAAE,UAAU,EAHb,EAAA,MAAM,CAAC,KAAK,CAInB,EACJ;AACN,qBAAC,CAAC,EAAA,CACA,EACI,CAAA,CAAA,EAAA,CACZ,EACR;AACN,EAAE;AAEF,qBAAqB,CAAC,WAAW,GAAG,uBAAuB;;;;"}
@@ -0,0 +1,8 @@
1
+ import { type ReactElement } from 'react';
2
+ import type { SelectOptionProps, SelectOptionWrapperProps } from './types';
3
+ declare const SelectOptionBase: {
4
+ <T>({ label, type, input, isXS }: SelectOptionProps<T>): ReactElement;
5
+ displayName: string;
6
+ };
7
+ declare const SelectOption: <T>({ checked, multiple, name, value, disabled, onChange, render, type, isFirstActiveElement, isLastActiveElement, isLimitExceeded, onOptionsListClose, ...props }: SelectOptionWrapperProps<T>) => ReactElement;
8
+ export { SelectOptionBase, SelectOption };