@hh.ru/magritte-ui-select 12.9.27 → 13.0.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/ApplyChangesButton.d.ts +17 -0
- package/ApplyChangesButton.js +55 -0
- package/ApplyChangesButton.js.map +1 -0
- package/ClearButton.d.ts +15 -0
- package/ClearButton.js +42 -0
- package/ClearButton.js.map +1 -0
- package/ClearCard.d.ts +5 -0
- package/ClearCard.js +28 -0
- package/ClearCard.js.map +1 -0
- package/Select.d.ts +47 -6
- package/Select.js +77 -283
- package/Select.js.map +1 -1
- package/SelectBottomSheet.d.ts +6 -5
- package/SelectBottomSheet.js +62 -167
- package/SelectBottomSheet.js.map +1 -1
- package/SelectBottomSheetHeader.d.ts +10 -0
- package/SelectBottomSheetHeader.js +35 -0
- package/SelectBottomSheetHeader.js.map +1 -0
- package/SelectDrop.d.ts +16 -6
- package/SelectDrop.js +90 -139
- package/SelectDrop.js.map +1 -1
- package/SelectEmptyHint.d.ts +26 -3
- package/SelectEmptyHint.js +13 -4
- package/SelectEmptyHint.js.map +1 -1
- package/SelectOptions.d.ts +30 -0
- package/SelectOptions.js +104 -0
- package/SelectOptions.js.map +1 -0
- package/SelectPickerCloseIcon.d.ts +6 -0
- package/SelectPickerCloseIcon.js +31 -0
- package/SelectPickerCloseIcon.js.map +1 -0
- package/SelectPickerContext.d.ts +33 -0
- package/SelectPickerContext.js +106 -0
- package/SelectPickerContext.js.map +1 -0
- package/SelectSearchInput.d.ts +8 -0
- package/SelectSearchInput.js +20 -0
- package/SelectSearchInput.js.map +1 -0
- package/SelectSearchTrigger.d.ts +4 -0
- package/SelectSearchTrigger.js +71 -0
- package/SelectSearchTrigger.js.map +1 -0
- package/SelectTrigger.d.ts +4 -0
- package/SelectTrigger.js +48 -0
- package/SelectTrigger.js.map +1 -0
- package/UncontrolledSelect.d.ts +1 -1
- package/UncontrolledSelect.js +56 -28
- package/UncontrolledSelect.js.map +1 -1
- package/index.css +116 -102
- package/index.d.ts +16 -5
- package/index.js +60 -26
- package/index.js.map +1 -1
- package/index.mock.d.ts +46 -4
- package/index.mock.js +63 -7
- package/index.mock.js.map +1 -1
- package/internal/ConfigContext.d.ts +27 -0
- package/internal/ConfigContext.js +51 -0
- package/internal/ConfigContext.js.map +1 -0
- package/internal/NavigationManagement.d.ts +9 -0
- package/internal/NavigationManagement.js +65 -0
- package/internal/NavigationManagement.js.map +1 -0
- package/internal/Option.d.ts +26 -0
- package/internal/Option.js +70 -0
- package/internal/Option.js.map +1 -0
- package/internal/OptionControl.d.ts +18 -0
- package/internal/OptionControl.js +17 -0
- package/internal/OptionControl.js.map +1 -0
- package/internal/SearchStateContext.d.ts +9 -0
- package/internal/SearchStateContext.js +25 -0
- package/internal/SearchStateContext.js.map +1 -0
- package/internal/SelectDataProvider.d.ts +11 -0
- package/internal/SelectDataProvider.js +28 -0
- package/internal/SelectDataProvider.js.map +1 -0
- package/internal/SelectError.d.ts +3 -0
- package/internal/SelectError.js +41 -0
- package/internal/SelectError.js.map +1 -0
- package/internal/SelectReloadButton.d.ts +4 -0
- package/internal/SelectReloadButton.js +22 -0
- package/internal/SelectReloadButton.js.map +1 -0
- package/internal/SelectStateContext.d.ts +19 -0
- package/internal/SelectStateContext.js +61 -0
- package/internal/SelectStateContext.js.map +1 -0
- package/internal/SelectStore.d.ts +16 -0
- package/internal/SelectStore.js +59 -0
- package/internal/SelectStore.js.map +1 -0
- package/internal/VisibilityContext.d.ts +13 -0
- package/internal/VisibilityContext.js +17 -0
- package/internal/VisibilityContext.js.map +1 -0
- package/internal/focusOrchestrator.d.ts +26 -0
- package/internal/focusOrchestrator.js +67 -0
- package/internal/focusOrchestrator.js.map +1 -0
- package/internal/slots.d.ts +40 -0
- package/internal/slots.js +8 -0
- package/internal/slots.js.map +1 -0
- package/internal/useDataProvider.d.ts +11 -0
- package/internal/useDataProvider.js +116 -0
- package/internal/useDataProvider.js.map +1 -0
- package/internal/useFocusWithin.d.ts +1 -0
- package/internal/useFocusWithin.js +54 -0
- package/internal/useFocusWithin.js.map +1 -0
- package/internal/utils.d.ts +18 -0
- package/internal/utils.js +70 -0
- package/internal/utils.js.map +1 -0
- package/legacy/SelectLegacy.d.ts +10 -0
- package/legacy/SelectLegacy.js +122 -0
- package/legacy/SelectLegacy.js.map +1 -0
- package/legacy/UncontrolledSelectLegacy.d.ts +9 -0
- package/legacy/UncontrolledSelectLegacy.js +88 -0
- package/legacy/UncontrolledSelectLegacy.js.map +1 -0
- package/legacy/internal/BottomSheetHeaderLegacy.d.ts +11 -0
- package/legacy/internal/BottomSheetHeaderLegacy.js +66 -0
- package/legacy/internal/BottomSheetHeaderLegacy.js.map +1 -0
- package/legacy/internal/ContentBeforeLegacy.d.ts +10 -0
- package/legacy/internal/ContentBeforeLegacy.js +42 -0
- package/legacy/internal/ContentBeforeLegacy.js.map +1 -0
- package/legacy/internal/FooterLegacy.d.ts +14 -0
- package/legacy/internal/FooterLegacy.js +59 -0
- package/legacy/internal/FooterLegacy.js.map +1 -0
- package/legacy/internal/OptionLayoutLegacy.d.ts +12 -0
- package/legacy/internal/OptionLayoutLegacy.js +42 -0
- package/legacy/internal/OptionLayoutLegacy.js.map +1 -0
- package/legacy/internal/TriggerLegacy.d.ts +12 -0
- package/legacy/internal/TriggerLegacy.js +60 -0
- package/legacy/internal/TriggerLegacy.js.map +1 -0
- package/legacy/internal/UnsavedChangesAlertLegacy.d.ts +8 -0
- package/legacy/internal/UnsavedChangesAlertLegacy.js +27 -0
- package/legacy/internal/UnsavedChangesAlertLegacy.js.map +1 -0
- package/legacy/types.d.ts +191 -0
- package/legacy/types.js +3 -0
- package/legacy/types.js.map +1 -0
- package/package.json +8 -7
- package/types.d.ts +57 -291
- package/useDataProvider.d.ts +5 -0
- package/useDataProvider.js +19 -0
- package/useDataProvider.js.map +1 -0
- package/usePickerRef.d.ts +3 -0
- package/usePickerRef.js +14 -0
- package/usePickerRef.js.map +1 -0
- package/useSearchState.d.ts +4 -0
- package/useSearchState.js +15 -0
- package/useSearchState.js.map +1 -0
- package/useSelectConfig.d.ts +3 -0
- package/useSelectConfig.js +13 -0
- package/useSelectConfig.js.map +1 -0
- package/useSelectContentState.d.ts +16 -0
- package/useSelectContentState.js +43 -0
- package/useSelectContentState.js.map +1 -0
- package/useSelectError.d.ts +3 -0
- package/useSelectError.js +13 -0
- package/useSelectError.js.map +1 -0
- package/useSelectHint.d.ts +3 -0
- package/useSelectHint.js +13 -0
- package/useSelectHint.js.map +1 -0
- package/useSelectTrigger.d.ts +12 -0
- package/useSelectTrigger.js +137 -0
- package/useSelectTrigger.js.map +1 -0
- package/useVisibility.d.ts +3 -0
- package/useVisibility.js +13 -0
- package/useVisibility.js.map +1 -0
- package/SelectError.d.ts +0 -6
- package/SelectError.js +0 -21
- package/SelectError.js.map +0 -1
- package/SelectModal.d.ts +0 -4
- package/SelectModal.js +0 -155
- package/SelectModal.js.map +0 -1
- package/SelectOption.d.ts +0 -4
- package/SelectOption.js +0 -88
- package/SelectOption.js.map +0 -1
- package/getChecked.d.ts +0 -2
- package/getChecked.js +0 -7
- package/getChecked.js.map +0 -1
- package/isArraysEquals.d.ts +0 -1
- package/isArraysEquals.js +0 -5
- package/isArraysEquals.js.map +0 -1
- package/useSelectOptionsList.d.ts +0 -11
- package/useSelectOptionsList.js +0 -48
- package/useSelectOptionsList.js.map +0 -1
- package/useSelectSearch.d.ts +0 -3
- package/useSelectSearch.js +0 -131
- package/useSelectSearch.js.map +0 -1
- package/useSelectState.d.ts +0 -3
- package/useSelectState.js +0 -122
- package/useSelectState.js.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode, type ReactElement } from 'react';
|
|
2
|
+
export declare const useIsFocusWithin: () => boolean;
|
|
3
|
+
interface NavigationManagementProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
onFocus: VoidFunction;
|
|
6
|
+
onBlur: VoidFunction;
|
|
7
|
+
}
|
|
8
|
+
export declare const NavigationManagement: ({ children, onFocus: onFocusExternal, onBlur: onBlurExternal, }: NavigationManagementProps) => ReactElement;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { createContext, useContext, useState, useRef, useCallback, useLayoutEffect } from 'react';
|
|
4
|
+
import { keyboardKeys, keyboardMatches } from '@hh.ru/magritte-common-keyboard';
|
|
5
|
+
import { useFocusOrchestrator, FocusTarget } from './focusOrchestrator.js';
|
|
6
|
+
import { useSelectElementsValue } from './slots.js';
|
|
7
|
+
import { useFocusWithin } from './useFocusWithin.js';
|
|
8
|
+
import { useLastInputSource, useEventCallback, isRefContainsTarget } from './utils.js';
|
|
9
|
+
import { useVisibility } from '../useVisibility.js';
|
|
10
|
+
import '@hh.ru/magritte-internal-slot-registry';
|
|
11
|
+
import './VisibilityContext.js';
|
|
12
|
+
|
|
13
|
+
var styles = {"select-layout":"magritte-select-layout___3THUn_13-0-1","selectLayout":"magritte-select-layout___3THUn_13-0-1"};
|
|
14
|
+
|
|
15
|
+
const CLOSED_BY_USER_KEYS = [keyboardKeys.Escape, keyboardKeys.Enter, keyboardKeys.Space];
|
|
16
|
+
const FocusWithinContext = createContext(false);
|
|
17
|
+
const useIsFocusWithin = () => {
|
|
18
|
+
return useContext(FocusWithinContext);
|
|
19
|
+
};
|
|
20
|
+
const NavigationManagement = ({ children, onFocus: onFocusExternal, onBlur: onBlurExternal, }) => {
|
|
21
|
+
const [isFocusWithin, setIsFocusWithin] = useState(false);
|
|
22
|
+
const { showOptions } = useVisibility();
|
|
23
|
+
const activatorRef = useSelectElementsValue('activatorRef');
|
|
24
|
+
const pickerRef = useSelectElementsValue('pickerRef');
|
|
25
|
+
const orchestrator = useFocusOrchestrator();
|
|
26
|
+
const lastInputSource = useLastInputSource();
|
|
27
|
+
const isElementInsideActivatorEventCallback = useEventCallback((node) => isRefContainsTarget(activatorRef, node));
|
|
28
|
+
const onFocus = useEventCallback(() => {
|
|
29
|
+
setIsFocusWithin(true);
|
|
30
|
+
onFocusExternal();
|
|
31
|
+
});
|
|
32
|
+
const onBlur = useEventCallback(() => {
|
|
33
|
+
setIsFocusWithin(false);
|
|
34
|
+
onBlurExternal();
|
|
35
|
+
});
|
|
36
|
+
useFocusWithin(onFocus, onBlur, isElementInsideActivatorEventCallback, showOptions);
|
|
37
|
+
/**
|
|
38
|
+
* Клавиатурное закрытие предполагает возврат фокуса на тригер
|
|
39
|
+
* - ESC в пикере
|
|
40
|
+
* - Space/Enter на кнопках и опции (касается действий, которые переключают видимость)
|
|
41
|
+
*/
|
|
42
|
+
const closedByUserKeyRef = useRef(false);
|
|
43
|
+
const prevShowOptions = useRef(showOptions);
|
|
44
|
+
const onKeyDownCaptureHandler = useCallback((event) => {
|
|
45
|
+
if (!showOptions) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
closedByUserKeyRef.current = keyboardMatches(event.nativeEvent, CLOSED_BY_USER_KEYS);
|
|
49
|
+
}, [showOptions]);
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
if (prevShowOptions.current !== showOptions && !showOptions) {
|
|
52
|
+
if (lastInputSource.current === 'keyboard' &&
|
|
53
|
+
closedByUserKeyRef.current &&
|
|
54
|
+
isRefContainsTarget(pickerRef, document.activeElement)) {
|
|
55
|
+
orchestrator.yieldFocus(FocusTarget.Trigger);
|
|
56
|
+
}
|
|
57
|
+
closedByUserKeyRef.current = false;
|
|
58
|
+
}
|
|
59
|
+
prevShowOptions.current = showOptions;
|
|
60
|
+
}, [showOptions, orchestrator, pickerRef, lastInputSource]);
|
|
61
|
+
return (jsx(FocusWithinContext.Provider, { value: isFocusWithin, children: jsx("div", { className: styles.selectLayout, onKeyDownCapture: onKeyDownCaptureHandler, children: children }) }));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export { NavigationManagement, useIsFocusWithin };
|
|
65
|
+
//# sourceMappingURL=NavigationManagement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationManagement.js","sources":["src/internal/NavigationManagement.tsx"],"sourcesContent":["import {\n type ReactNode,\n type ReactElement,\n createContext,\n useContext,\n useState,\n useRef,\n useLayoutEffect,\n useCallback,\n type KeyboardEventHandler,\n} from 'react';\n\nimport { keyboardKeys, keyboardMatches } from '@hh.ru/magritte-common-keyboard';\nimport { useFocusOrchestrator, FocusTarget } from '@hh.ru/magritte-ui-select/internal/focusOrchestrator';\nimport { useSelectElementsValue } from '@hh.ru/magritte-ui-select/internal/slots';\nimport { useFocusWithin } from '@hh.ru/magritte-ui-select/internal/useFocusWithin';\nimport { isRefContainsTarget, useEventCallback, useLastInputSource } from '@hh.ru/magritte-ui-select/internal/utils';\nimport { useVisibility } from '@hh.ru/magritte-ui-select/useVisibility';\n\nimport styles from './select-layout.less';\n\nconst CLOSED_BY_USER_KEYS = [keyboardKeys.Escape, keyboardKeys.Enter, keyboardKeys.Space];\n\nconst FocusWithinContext = createContext<boolean>(false);\n\nexport const useIsFocusWithin = (): boolean => {\n return useContext(FocusWithinContext);\n};\n\ninterface NavigationManagementProps {\n children: ReactNode;\n onFocus: VoidFunction;\n onBlur: VoidFunction;\n}\n\nexport const NavigationManagement = ({\n children,\n onFocus: onFocusExternal,\n onBlur: onBlurExternal,\n}: NavigationManagementProps): ReactElement => {\n const [isFocusWithin, setIsFocusWithin] = useState(false);\n const { showOptions } = useVisibility();\n\n const activatorRef = useSelectElementsValue('activatorRef');\n const pickerRef = useSelectElementsValue('pickerRef');\n\n const orchestrator = useFocusOrchestrator();\n const lastInputSource = useLastInputSource();\n\n const isElementInsideActivatorEventCallback = useEventCallback((node: Node | null) =>\n isRefContainsTarget(activatorRef, node)\n );\n const onFocus = useEventCallback(() => {\n setIsFocusWithin(true);\n onFocusExternal();\n });\n const onBlur = useEventCallback(() => {\n setIsFocusWithin(false);\n onBlurExternal();\n });\n\n useFocusWithin(onFocus, onBlur, isElementInsideActivatorEventCallback, showOptions);\n\n /**\n * Клавиатурное закрытие предполагает возврат фокуса на тригер\n * - ESC в пикере\n * - Space/Enter на кнопках и опции (касается действий, которые переключают видимость)\n */\n const closedByUserKeyRef = useRef(false);\n const prevShowOptions = useRef(showOptions);\n const onKeyDownCaptureHandler = useCallback<KeyboardEventHandler<HTMLDivElement>>(\n (event) => {\n if (!showOptions) {\n return;\n }\n closedByUserKeyRef.current = keyboardMatches(event.nativeEvent, CLOSED_BY_USER_KEYS);\n },\n [showOptions]\n );\n useLayoutEffect(() => {\n if (prevShowOptions.current !== showOptions && !showOptions) {\n if (\n lastInputSource.current === 'keyboard' &&\n closedByUserKeyRef.current &&\n isRefContainsTarget(pickerRef, document.activeElement)\n ) {\n orchestrator.yieldFocus(FocusTarget.Trigger);\n }\n closedByUserKeyRef.current = false;\n }\n prevShowOptions.current = showOptions;\n }, [showOptions, orchestrator, pickerRef, lastInputSource]);\n\n return (\n <FocusWithinContext.Provider value={isFocusWithin}>\n <div className={styles.selectLayout} onKeyDownCapture={onKeyDownCaptureHandler}>\n {children}\n </div>\n </FocusWithinContext.Provider>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,mBAAmB,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;AAE1F,MAAM,kBAAkB,GAAG,aAAa,CAAU,KAAK,CAAC,CAAC;AAElD,MAAM,gBAAgB,GAAG,MAAc;AAC1C,IAAA,OAAO,UAAU,CAAC,kBAAkB,CAAC,CAAC;AAC1C,EAAE;AAQW,MAAA,oBAAoB,GAAG,CAAC,EACjC,QAAQ,EACR,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,cAAc,GACE,KAAkB;IAC1C,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1D,IAAA,MAAM,EAAE,WAAW,EAAE,GAAG,aAAa,EA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AU;AACtC,gBAAA,kBAAkB,CAAC,OAAO;gBAC1B,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,aAAa,CAAC,EACxD;AACE,gBAAA,YAAY,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;aAChD;AACD,YAAA,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC;SACtC;AACD,QAAA,eAAe,CAAC,OAAO,GAAG,WAAW,CAAC;KACzC,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC;IAE5D,QACIA,GAAC,CAAA,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,aAAa,EAAA,QAAA,EAC7CA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,YAAY,EAAE,gBAAgB,EAAE,uBAAuB,EAAA,QAAA,EACzE,QAAQ,EAAA,CACP,EACoB,CAAA,EAChC;AACN;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ComponentType, type ReactElement } from 'react';
|
|
2
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
+
import { OnChangeAction } from '@hh.ru/magritte-ui-select/internal/OptionControl';
|
|
4
|
+
import { SelectOptionType, DelimiterOptionType } from '@hh.ru/magritte-ui-select/types';
|
|
5
|
+
interface OptionProps<DataType extends StaticDataFetcherItem> {
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
data: DataType;
|
|
8
|
+
checked: boolean;
|
|
9
|
+
name?: string;
|
|
10
|
+
type: SelectOptionType | DelimiterOptionType;
|
|
11
|
+
optionLayoutComponent: OptionCustomLayoutComponent<DataType>;
|
|
12
|
+
onChange: OnChangeAction<DataType>;
|
|
13
|
+
plain: boolean;
|
|
14
|
+
multiple?: boolean;
|
|
15
|
+
isMobile?: boolean;
|
|
16
|
+
'data-qa'?: string;
|
|
17
|
+
}
|
|
18
|
+
type OptionCustomLayoutBaseProps<DataType extends StaticDataFetcherItem> = Pick<OptionProps<DataType>, 'data' | 'plain' | 'checked' | 'isMobile' | 'disabled' | 'onChange' | 'multiple'>;
|
|
19
|
+
export type OptionCustomLayoutProps<DataType extends StaticDataFetcherItem> = OptionCustomLayoutBaseProps<DataType> & {
|
|
20
|
+
type: SelectOptionType | DelimiterOptionType;
|
|
21
|
+
input?: ReactElement;
|
|
22
|
+
};
|
|
23
|
+
export type OptionCustomLayoutComponent<DataType extends StaticDataFetcherItem> = ComponentType<OptionCustomLayoutProps<DataType>>;
|
|
24
|
+
export declare const OptionLayoutComponentDefault: <DataType extends StaticDataFetcherItem>({ data, type, plain, checked, isMobile, input, }: OptionCustomLayoutProps<DataType>) => ReactElement;
|
|
25
|
+
export declare const Option: <DataType extends StaticDataFetcherItem>({ checked, name, disabled, optionLayoutComponent: OptionLayoutComponent, type, onChange, plain, data, multiple, isMobile, "data-qa": dataQa, }: OptionProps<DataType>) => ReactElement;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { keyboardMatches, keyboardKeys } from '@hh.ru/magritte-common-keyboard';
|
|
6
|
+
import { DisabledContext } from '@hh.ru/magritte-common-use-disabled';
|
|
7
|
+
import { CellText, Cell } from '@hh.ru/magritte-ui-cell';
|
|
8
|
+
import { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
9
|
+
import { CheckOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
10
|
+
import { OptionControl } from './OptionControl.js';
|
|
11
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
12
|
+
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
13
|
+
|
|
14
|
+
var styles = {"select-option-plain":"magritte-select-option-plain___u9kSx_13-0-1","selectOptionPlain":"magritte-select-option-plain___u9kSx_13-0-1","select-option-plain_active":"magritte-select-option-plain_active___ynHQP_13-0-1","selectOptionPlainActive":"magritte-select-option-plain_active___ynHQP_13-0-1","select-label-option":"magritte-select-label-option___wyUhk_13-0-1","selectLabelOption":"magritte-select-label-option___wyUhk_13-0-1","select-delimiter":"magritte-select-delimiter___SsBtb_13-0-1","selectDelimiter":"magritte-select-delimiter___SsBtb_13-0-1"};
|
|
15
|
+
|
|
16
|
+
const OptionLayoutComponentDefault = ({ data, type, plain, checked, isMobile, input, }) => {
|
|
17
|
+
if (type === 'delimiter') {
|
|
18
|
+
return (jsx(CellText, { maxLines: 1, style: "secondary", children: data.text }));
|
|
19
|
+
}
|
|
20
|
+
if (type === 'label') {
|
|
21
|
+
return (jsx(Cell, { Element: "div", right: checked && plain ? jsx(CheckOutlinedSize24, {}) : undefined, vertPadding: isMobile, children: jsx("div", { className: classnames({ [styles.selectLabelOption]: !plain }), children: jsx(CellText, { maxLines: 1, children: data.text }) }) }));
|
|
22
|
+
}
|
|
23
|
+
return (jsx(Cell, { Element: "div", align: "center", left: isMobile ? undefined : input, right: isMobile ? input : undefined, children: jsx(CellText, { maxLines: 1, children: data.text }) }));
|
|
24
|
+
};
|
|
25
|
+
const Option = ({ checked, name, disabled, optionLayoutComponent: OptionLayoutComponent, type, onChange, plain, data, multiple, isMobile, 'data-qa': dataQa, }) => {
|
|
26
|
+
const [focusVisible, setFocusVisible] = useState(false);
|
|
27
|
+
if (type === 'delimiter') {
|
|
28
|
+
return (jsx("div", { className: classnames({ [styles.selectDelimiter]: !plain }), children: jsx(Text, { typography: "label-3-regular", children: jsx(OptionLayoutComponent, { data: data, type: type, plain: plain, checked: checked, isMobile: isMobile, disabled: disabled, onChange: onChange, multiple: multiple }) }) }));
|
|
29
|
+
}
|
|
30
|
+
const optionLayoutComponentProps = {
|
|
31
|
+
data,
|
|
32
|
+
input: (jsx(OptionControl, { type: type, data: data, checked: checked, name: name, onChange: onChange, "data-qa": dataQa })),
|
|
33
|
+
type,
|
|
34
|
+
plain,
|
|
35
|
+
checked,
|
|
36
|
+
isMobile,
|
|
37
|
+
disabled,
|
|
38
|
+
onChange,
|
|
39
|
+
multiple,
|
|
40
|
+
};
|
|
41
|
+
if (plain) {
|
|
42
|
+
return (jsx("div", { className: classnames(styles.selectOptionPlain, { [styles.selectOptionPlainActive]: !disabled }), "data-qa": `magritte-select-option-${data.value}`, "data-magritte-select-option": data.value, role: "option", "aria-selected": checked, tabIndex: disabled ? -1 : 0, "aria-disabled": disabled, onClick: () => {
|
|
43
|
+
if (disabled) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
onChange(data);
|
|
47
|
+
}, onKeyDown: (event) => {
|
|
48
|
+
if (disabled) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (keyboardMatches(event.nativeEvent, [keyboardKeys.Enter, keyboardKeys.Space])) {
|
|
52
|
+
onChange(data);
|
|
53
|
+
}
|
|
54
|
+
}, children: jsx(DisabledContext.Provider, { value: !!disabled, children: jsx(OptionLayoutComponent, { ...optionLayoutComponentProps }) }) }));
|
|
55
|
+
}
|
|
56
|
+
return (jsx(CheckableCardElement, { Element: "label", role: "option", padding: 16, borderRadius: 12, flexible: false, checked: checked, "data-magritte-select-option": data.value, focusVisible: focusVisible, "data-qa": `magritte-select-option-${data.value}`, disabled: disabled, "aria-selected": checked, toneHover: true, onClick: () => {
|
|
57
|
+
if (type === 'label' && !disabled) {
|
|
58
|
+
onChange(data);
|
|
59
|
+
}
|
|
60
|
+
}, onKeyDown: (event) => {
|
|
61
|
+
if (keyboardMatches(event.nativeEvent, [keyboardKeys.Enter, keyboardKeys.Space])) {
|
|
62
|
+
onChange(data);
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
setFocusVisible(true);
|
|
65
|
+
}
|
|
66
|
+
}, onBlur: () => setFocusVisible(false), children: jsx(OptionLayoutComponent, { ...optionLayoutComponentProps }) }));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { Option, OptionLayoutComponentDefault };
|
|
70
|
+
//# sourceMappingURL=Option.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Option.js","sources":["src/internal/Option.tsx"],"sourcesContent":["import { type ComponentType, type ReactElement, useState } from 'react';\nimport classnames from 'classnames';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { keyboardMatches, keyboardKeys } from '@hh.ru/magritte-common-keyboard';\nimport { DisabledContext } from '@hh.ru/magritte-common-use-disabled';\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';\nimport { CheckOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { OptionControl, OnChangeAction } from '@hh.ru/magritte-ui-select/internal/OptionControl';\nimport { SelectOptionType, DelimiterOptionType } from '@hh.ru/magritte-ui-select/types';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './option.less';\n\ninterface OptionProps<DataType extends StaticDataFetcherItem> {\n disabled?: boolean;\n data: DataType;\n checked: boolean;\n name?: string;\n type: SelectOptionType | DelimiterOptionType;\n optionLayoutComponent: OptionCustomLayoutComponent<DataType>;\n onChange: OnChangeAction<DataType>;\n plain: boolean;\n multiple?: boolean;\n isMobile?: boolean;\n 'data-qa'?: string;\n}\n\ntype OptionCustomLayoutBaseProps<DataType extends StaticDataFetcherItem> = Pick<\n OptionProps<DataType>,\n 'data' | 'plain' | 'checked' | 'isMobile' | 'disabled' | 'onChange' | 'multiple'\n>;\n\n// для delimiter input не создается, но delimiter через рендер компонент пропустить нужно\nexport type OptionCustomLayoutProps<DataType extends StaticDataFetcherItem> = OptionCustomLayoutBaseProps<DataType> & {\n type: SelectOptionType | DelimiterOptionType;\n input?: ReactElement;\n};\n\nexport type OptionCustomLayoutComponent<DataType extends StaticDataFetcherItem> = ComponentType<\n OptionCustomLayoutProps<DataType>\n>;\n\nexport const OptionLayoutComponentDefault = <DataType extends StaticDataFetcherItem>({\n data,\n type,\n plain,\n checked,\n isMobile,\n input,\n}: OptionCustomLayoutProps<DataType>): ReactElement => {\n if (type === 'delimiter') {\n return (\n <CellText maxLines={1} style=\"secondary\">\n {data.text}\n </CellText>\n );\n }\n\n if (type === 'label') {\n return (\n <Cell Element=\"div\" right={checked && plain ? <CheckOutlinedSize24 /> : undefined} vertPadding={isMobile}>\n <div className={classnames({ [styles.selectLabelOption]: !plain })}>\n <CellText maxLines={1}>{data.text}</CellText>\n </div>\n </Cell>\n );\n }\n\n return (\n <Cell Element=\"div\" align=\"center\" left={isMobile ? undefined : input} right={isMobile ? input : undefined}>\n <CellText maxLines={1}>{data.text}</CellText>\n </Cell>\n );\n};\n\nexport const Option = <DataType extends StaticDataFetcherItem>({\n checked,\n name,\n disabled,\n optionLayoutComponent: OptionLayoutComponent,\n type,\n onChange,\n plain,\n data,\n multiple,\n isMobile,\n 'data-qa': dataQa,\n}: OptionProps<DataType>): ReactElement => {\n const [focusVisible, setFocusVisible] = useState(false);\n\n if (type === 'delimiter') {\n return (\n <div className={classnames({ [styles.selectDelimiter]: !plain })}>\n <Text typography=\"label-3-regular\">\n <OptionLayoutComponent\n data={data}\n type={type}\n plain={plain}\n checked={checked}\n isMobile={isMobile}\n disabled={disabled}\n onChange={onChange}\n multiple={multiple}\n />\n </Text>\n </div>\n );\n }\n\n const optionLayoutComponentProps = {\n data,\n input: (\n <OptionControl type={type} data={data} checked={checked} name={name} onChange={onChange} data-qa={dataQa} />\n ),\n type,\n plain,\n checked,\n isMobile,\n disabled,\n onChange,\n multiple,\n };\n\n if (plain) {\n return (\n <div\n className={classnames(styles.selectOptionPlain, { [styles.selectOptionPlainActive]: !disabled })}\n data-qa={`magritte-select-option-${data.value}`}\n data-magritte-select-option={data.value}\n role=\"option\"\n aria-selected={checked}\n tabIndex={disabled ? -1 : 0}\n aria-disabled={disabled}\n onClick={() => {\n if (disabled) {\n return;\n }\n onChange(data);\n }}\n onKeyDown={(event) => {\n if (disabled) {\n return;\n }\n if (keyboardMatches(event.nativeEvent, [keyboardKeys.Enter, keyboardKeys.Space])) {\n onChange(data);\n }\n }}\n >\n <DisabledContext.Provider value={!!disabled}>\n <OptionLayoutComponent {...optionLayoutComponentProps} />\n </DisabledContext.Provider>\n </div>\n );\n }\n return (\n <CheckableCardElement\n Element=\"label\"\n role=\"option\"\n padding={16}\n borderRadius={12}\n flexible={false}\n checked={checked}\n data-magritte-select-option={data.value}\n focusVisible={focusVisible}\n data-qa={`magritte-select-option-${data.value}`}\n disabled={disabled}\n aria-selected={checked}\n toneHover\n onClick={() => {\n if (type === 'label' && !disabled) {\n onChange(data);\n }\n }}\n onKeyDown={(event) => {\n if (keyboardMatches(event.nativeEvent, [keyboardKeys.Enter, keyboardKeys.Space])) {\n onChange(data);\n event.preventDefault();\n setFocusVisible(true);\n }\n }}\n onBlur={() => setFocusVisible(false)}\n >\n <OptionLayoutComponent {...optionLayoutComponentProps} />\n </CheckableCardElement>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;AA4Ca,MAAA,4BAA4B,GAAG,CAAyC,EACjF,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,KAAK,GAC2B,KAAkB;AAClD,IAAA,IAAI,IAAI,KAAK,WAAW,EAAE;AACtB,QAAA,QACIA,GAAC,CAAA,QAAQ,EAAC,EAAA,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAC,WAAW,EACnC,QAAA,EAAA,IAAI,CAAC,IAAI,EAAA,CACH,EACb;KACL;AAED,IAAA,IAAI,IAAI,KAAK,OAAO,EAAE;QAClB,QACIA,GAAC,CAAA,IAAI,EAAC,EAAA,OAAO,EAAC,KAAK,EAAC,KAAK,EAAE,OAAO,IAAI,KAAK,GAAGA,GAAA,CAAC,mBAAmB,EAAA,EAAA,CAAG,GAAG,SAAS,EAAE,WAAW,EAAE,QAAQ,EACpG,QAAA,EAAAA,GAAA,CAAA,KAAA,EA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
1
|
+
import { type ReactElement } from 'react';
|
|
2
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
+
import { SelectOptionType } from '@hh.ru/magritte-ui-select/types';
|
|
4
|
+
export interface OnChangeAction<DataType extends StaticDataFetcherItem> {
|
|
5
|
+
(value: DataType): void;
|
|
6
|
+
}
|
|
7
|
+
export interface OptionControlProps<DataType extends StaticDataFetcherItem> {
|
|
8
|
+
type: SelectOptionType;
|
|
9
|
+
data: DataType;
|
|
10
|
+
checked: boolean;
|
|
11
|
+
name?: string;
|
|
12
|
+
onChange: OnChangeAction<DataType>;
|
|
13
|
+
'data-qa'?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const OptionControl: {
|
|
16
|
+
<DataType extends StaticDataFetcherItem>({ type, data, checked, name, onChange, "data-qa": dataQa, }: OptionControlProps<DataType>): ReactElement;
|
|
17
|
+
displayName: string;
|
|
18
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Radio, Checkbox } from '@hh.ru/magritte-ui-checkbox-radio';
|
|
4
|
+
|
|
5
|
+
const OptionControl = ({ type, data, checked, name, onChange, 'data-qa': dataQa, }) => {
|
|
6
|
+
if (type === 'label') {
|
|
7
|
+
return jsx("input", { type: "hidden", name: name, value: data.value, "data-qa": dataQa });
|
|
8
|
+
}
|
|
9
|
+
if (type === 'radio') {
|
|
10
|
+
return (jsx(Radio, { "data-focus-visible-skip": "true", "data-qa": dataQa, tabIndex: -1, name: name, value: data.value, checked: checked, onChange: () => onChange(data) }));
|
|
11
|
+
}
|
|
12
|
+
return (jsx(Checkbox, { "data-focus-visible-skip": "true", "data-qa": dataQa, tabIndex: -1, name: name, value: data.value, checked: checked, onChange: () => onChange(data) }));
|
|
13
|
+
};
|
|
14
|
+
OptionControl.displayName = 'OptionControl';
|
|
15
|
+
|
|
16
|
+
export { OptionControl };
|
|
17
|
+
//# sourceMappingURL=OptionControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionControl.js","sources":["src/internal/OptionControl.tsx"],"sourcesContent":["import { type ReactElement } from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { Radio, Checkbox } from '@hh.ru/magritte-ui-checkbox-radio';\nimport { SelectOptionType } from '@hh.ru/magritte-ui-select/types';\n\nexport interface OnChangeAction<DataType extends StaticDataFetcherItem> {\n (value: DataType): void;\n}\n\nexport interface OptionControlProps<DataType extends StaticDataFetcherItem> {\n type: SelectOptionType;\n data: DataType;\n checked: boolean;\n name?: string;\n onChange: OnChangeAction<DataType>;\n 'data-qa'?: string;\n}\n\nexport const OptionControl = <DataType extends StaticDataFetcherItem>({\n type,\n data,\n checked,\n name,\n onChange,\n 'data-qa': dataQa,\n}: OptionControlProps<DataType>): ReactElement => {\n if (type === 'label') {\n return <input type=\"hidden\" name={name} value={data.value} data-qa={dataQa} />;\n }\n if (type === 'radio') {\n return (\n <Radio\n data-focus-visible-skip=\"true\"\n data-qa={dataQa}\n tabIndex={-1}\n name={name}\n value={data.value}\n checked={checked}\n onChange={() => onChange(data)}\n />\n );\n }\n return (\n <Checkbox\n data-focus-visible-skip=\"true\"\n data-qa={dataQa}\n tabIndex={-1}\n name={name}\n value={data.value}\n checked={checked}\n onChange={() => onChange(data)}\n />\n );\n};\n\nOptionControl.displayName = 'OptionControl';\n"],"names":["_jsx"],"mappings":";;;MAmBa,aAAa,GAAG,CAAyC,EAClE,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,SAAS,EAAE,MAAM,GACU,KAAkB;AAC7C,IAAA,IAAI,IAAI,KAAK,OAAO,EAAE;AAClB,QAAA,OAAOA,eAAO,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAW,SAAA,EAAA,MAAM,GAAI,CAAC;KAClF;AACD,IAAA,IAAI,IAAI,KAAK,OAAO,EAAE;AAClB,QAAA,QACIA,GAAC,CAAA,KAAK,EACsB,EAAA,yBAAA,EAAA,MAAM,aACrB,MAAM,EACf,QAAQ,EAAE,CAAC,CAAC,EACZ,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,EAAA,CAChC,EACJ;KACL;AACD,IAAA,QACIA,GAAC,CAAA,QAAQ,EACmB,EAAA,yBAAA,EAAA,MAAM,aACrB,MAAM,EACf,QAAQ,EAAE,CAAC,CAAC,EACZ,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,EAAA,CAChC,EACJ;AACN,EAAE;AAEF,aAAa,CAAC,WAAW,GAAG,eAAe;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode, type ReactElement, SetStateAction, Dispatch } from 'react';
|
|
2
|
+
export interface SearchContextValue {
|
|
3
|
+
searchValue: string;
|
|
4
|
+
setSearchValue: Dispatch<SetStateAction<string>>;
|
|
5
|
+
}
|
|
6
|
+
export declare const SearchContext: import("react").Context<SearchContextValue | null>;
|
|
7
|
+
export declare const SearchStateProvider: ({ children, searchValue, setSearchValue, }: {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
} & SearchContextValue) => ReactElement;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { createContext, useMemo, useEffect } from 'react';
|
|
4
|
+
import { useVisibility } from '../useVisibility.js';
|
|
5
|
+
import './VisibilityContext.js';
|
|
6
|
+
import './utils.js';
|
|
7
|
+
|
|
8
|
+
const SearchContext = createContext(null);
|
|
9
|
+
// стейт поиска
|
|
10
|
+
const SearchStateProvider = ({ children, searchValue, setSearchValue, }) => {
|
|
11
|
+
const value = useMemo(() => ({
|
|
12
|
+
searchValue,
|
|
13
|
+
setSearchValue,
|
|
14
|
+
}), [searchValue, setSearchValue]);
|
|
15
|
+
const { showOptions } = useVisibility();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!showOptions) {
|
|
18
|
+
setSearchValue('');
|
|
19
|
+
}
|
|
20
|
+
}, [showOptions, setSearchValue]);
|
|
21
|
+
return jsx(SearchContext.Provider, { value: value, children: children });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { SearchContext, SearchStateProvider };
|
|
25
|
+
//# sourceMappingURL=SearchStateContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchStateContext.js","sources":["src/internal/SearchStateContext.tsx"],"sourcesContent":["import { createContext, useMemo, type ReactNode, type ReactElement, SetStateAction, Dispatch, useEffect } from 'react';\n\nimport { useVisibility } from '@hh.ru/magritte-ui-select/useVisibility';\n\nexport interface SearchContextValue {\n searchValue: string;\n setSearchValue: Dispatch<SetStateAction<string>>;\n}\n\nexport const SearchContext = createContext<SearchContextValue | null>(null);\n\n// стейт поиска\nexport const SearchStateProvider = ({\n children,\n searchValue,\n setSearchValue,\n}: { children: ReactNode } & SearchContextValue): ReactElement => {\n const value = useMemo<SearchContextValue>(\n () => ({\n searchValue,\n setSearchValue,\n }),\n [searchValue, setSearchValue]\n );\n\n const { showOptions } = useVisibility();\n useEffect(() => {\n if (!showOptions) {\n setSearchValue('');\n }\n }, [showOptions, setSearchValue]);\n\n return <SearchContext.Provider value={value}>{children}</SearchContext.Provider>;\n};\n"],"names":["_jsx"],"mappings":";;;;;;MASa,aAAa,GAAG,aAAa,CAA4B,IAAI,EAAE;AAE5E;AACO,MAAM,mBAAmB,GAAG,CAAC,EAChC,QAAQ,EACR,WAAW,EACX,cAAc,GAC6B,KAAkB;AAC7D,IAAA,MAAM,KAAK,GAAG,OAAO,CACjB,OAAO;QACH,WAAW;QACX,cAAc;AACjB,KAAA,CAAC,EACF,CAAC,WAAW,EAAE,cAAc,CAAC,CAChC,CAAC;AAEF,IAAA,MAAM,EAAE,WAAW,EAAE,GAAG,aAAa,EAAE,CAAC;IACxC,SAAS,CAAC,MAAK;QACX,IAAI,CAAC,WAAW,EAAE;YACd,cAAc,CAAC,EAAE,CAAC,CAAC;SACtB;AACL,KAAC,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;IAElC,OAAOA,GAAA,CAAC,aAAa,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAAA,QAAA,EAAG,QAAQ,EAAA,CAA0B,CAAC;AACrF;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode, ReactElement } from 'react';
|
|
2
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
+
import { type UseDataProvider } from '@hh.ru/magritte-ui-select/internal/useDataProvider';
|
|
4
|
+
import { OnOptionsChangeCallback, UseDataProviderParams } from '@hh.ru/magritte-ui-select/types';
|
|
5
|
+
export declare const DataProviderContext: import("react").Context<UseDataProvider<StaticDataFetcherItem> | null>;
|
|
6
|
+
interface SelectDataProviderProps<DataType extends StaticDataFetcherItem> extends UseDataProviderParams<DataType> {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
onOptionsChange?: OnOptionsChangeCallback<DataType>;
|
|
9
|
+
}
|
|
10
|
+
declare const SelectDataProvider: <DataType extends StaticDataFetcherItem>({ children, onOptionsChange, options, dataProvider: dataProviderExternal, }: SelectDataProviderProps<DataType>) => ReactElement;
|
|
11
|
+
export { SelectDataProvider };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { createContext, useMemo } from 'react';
|
|
4
|
+
import { createStaticDataProvider } from '@hh.ru/magritte-common-data-provider';
|
|
5
|
+
import { useDataProvider } from './useDataProvider.js';
|
|
6
|
+
import './utils.js';
|
|
7
|
+
import '../useSearchState.js';
|
|
8
|
+
import './SearchStateContext.js';
|
|
9
|
+
import '../useVisibility.js';
|
|
10
|
+
import './VisibilityContext.js';
|
|
11
|
+
|
|
12
|
+
const DataProviderContext = createContext(null);
|
|
13
|
+
const SelectDataProvider = ({ children, onOptionsChange, options, dataProvider: dataProviderExternal, }) => {
|
|
14
|
+
const dataProvider = useMemo(() => {
|
|
15
|
+
if (!options && !dataProviderExternal) {
|
|
16
|
+
throw new Error(`dataProvider or options must be used within <Select>`);
|
|
17
|
+
}
|
|
18
|
+
if (options) {
|
|
19
|
+
return createStaticDataProvider(options);
|
|
20
|
+
}
|
|
21
|
+
return dataProviderExternal;
|
|
22
|
+
}, [dataProviderExternal, options]);
|
|
23
|
+
const searchData = useDataProvider(dataProvider, onOptionsChange);
|
|
24
|
+
return jsx(DataProviderContext.Provider, { value: searchData, children: children });
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { DataProviderContext, SelectDataProvider };
|
|
28
|
+
//# sourceMappingURL=SelectDataProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectDataProvider.js","sources":["src/internal/SelectDataProvider.tsx"],"sourcesContent":["import { type ReactNode, useMemo, ReactElement, createContext } from 'react';\n\nimport {\n StaticDataFetcherItem,\n createStaticDataProvider,\n DataProvider as DataProviderType,\n} from '@hh.ru/magritte-common-data-provider';\nimport {\n useDataProvider as useDataProviderInternal,\n type UseDataProvider,\n} from '@hh.ru/magritte-ui-select/internal/useDataProvider';\nimport { OnOptionsChangeCallback, UseDataProviderParams } from '@hh.ru/magritte-ui-select/types';\n\nexport const DataProviderContext = createContext<UseDataProvider<StaticDataFetcherItem> | null>(null);\n\ninterface SelectDataProviderProps<DataType extends StaticDataFetcherItem> extends UseDataProviderParams<DataType> {\n children: ReactNode;\n onOptionsChange?: OnOptionsChangeCallback<DataType>;\n}\n\nconst SelectDataProvider = <DataType extends StaticDataFetcherItem>({\n children,\n onOptionsChange,\n options,\n dataProvider: dataProviderExternal,\n}: SelectDataProviderProps<DataType>): ReactElement => {\n const dataProvider = useMemo(() => {\n if (!options && !dataProviderExternal) {\n throw new Error(`dataProvider or options must be used within <Select>`);\n }\n if (options) {\n return createStaticDataProvider<DataType>(options);\n }\n return dataProviderExternal as DataProviderType<DataType>;\n }, [dataProviderExternal, options]);\n\n const searchData = useDataProviderInternal<DataType>(dataProvider, onOptionsChange);\n\n return <DataProviderContext.Provider value={searchData}>{children}</DataProviderContext.Provider>;\n};\n\nexport { SelectDataProvider };\n"],"names":["useDataProviderInternal","_jsx"],"mappings":";;;;;;;;;;MAaa,mBAAmB,GAAG,aAAa,CAAgD,IAAI,EAAE;AAOtG,MAAM,kBAAkB,GAAG,CAAyC,EAChE,QAAQ,EACR,eAAe,EACf,OAAO,EACP,YAAY,EAAE,oBAAoB,GACF,KAAkB;AAClD,IAAA,MAAM,YAAY,GAAG,OAAO,CAAC,MAAK;AAC9B,QAAA,IAAI,CAAC,OAAO,IAAI,CAAC,oBAAoB,EAAE;AACnC,YAAA,MAAM,IAAI,KAAK,CAAC,CAAA,oDAAA,CAAsD,CAAC,CAAC;SAC3E;QACD,IAAI,OAAO,EAAE;AACT,YAAA,OAAO,wBAAwB,CAAW,OAAO,CAAC,CAAC;SACtD;AACD,QAAA,OAAO,oBAAkD,CAAC;AAC9D,KAAC,EAAE,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,CAAC;IAEpC,MAAM,UAAU,GAAGA,eAAuB,CAAW,YAAY,EAAE,eAAe,CAAC,CAAC;IAEpF,OAAOC,GAAA,CAAC,mBAAmB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,UAAU,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAgC,CAAC;AACtG;;;;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
4
|
+
import { SelectReloadButton } from './SelectReloadButton.js';
|
|
5
|
+
import { useSelectError } from '../useSelectError.js';
|
|
6
|
+
import { VSpacing } from '@hh.ru/magritte-ui-spacing';
|
|
7
|
+
import { Title } from '@hh.ru/magritte-ui-title';
|
|
8
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
9
|
+
import '@hh.ru/magritte-ui-button';
|
|
10
|
+
import '@hh.ru/magritte-ui-icon/icon';
|
|
11
|
+
import '../useDataProvider.js';
|
|
12
|
+
import 'react';
|
|
13
|
+
import './SelectDataProvider.js';
|
|
14
|
+
import '@hh.ru/magritte-common-data-provider';
|
|
15
|
+
import './useDataProvider.js';
|
|
16
|
+
import './utils.js';
|
|
17
|
+
import '../useSearchState.js';
|
|
18
|
+
import './SearchStateContext.js';
|
|
19
|
+
import '../useVisibility.js';
|
|
20
|
+
import './VisibilityContext.js';
|
|
21
|
+
import './ConfigContext.js';
|
|
22
|
+
|
|
23
|
+
var styles = {"error-container":"magritte-error-container___ICGpQ_13-0-1","errorContainer":"magritte-error-container___ICGpQ_13-0-1"};
|
|
24
|
+
|
|
25
|
+
/** Ошибка дата-провайдера, показывать решает пикер */
|
|
26
|
+
const SelectError = () => {
|
|
27
|
+
const { isMobile } = useBreakpoint();
|
|
28
|
+
const { providerError } = useSelectError();
|
|
29
|
+
if (!providerError) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const { title, description, reloadButton: reloadButtonExternal } = providerError;
|
|
33
|
+
const errorContent = (jsxs(Fragment, { children: [jsx(Title, { Element: "h3", size: "small", alignment: "center", children: title }), jsx(VSpacing, { default: 8 }), jsx(Text, { typography: "paragraph-2-regular", style: "secondary", children: description })] }));
|
|
34
|
+
if (isMobile) {
|
|
35
|
+
return (jsx("div", { className: styles.errorContainer, "data-qa": "magritte-select-error-xs", children: errorContent }));
|
|
36
|
+
}
|
|
37
|
+
return (jsxs("div", { className: styles.errorContainer, "data-qa": "magritte-select-error", children: [errorContent, jsx(VSpacing, { default: 32 }), jsx(SelectReloadButton, { label: reloadButtonExternal })] }));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { SelectError };
|
|
41
|
+
//# sourceMappingURL=SelectError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectError.js","sources":["src/internal/SelectError.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { SelectReloadButton } from '@hh.ru/magritte-ui-select/internal/SelectReloadButton';\nimport { useSelectError } from '@hh.ru/magritte-ui-select/useSelectError';\nimport { VSpacing } from '@hh.ru/magritte-ui-spacing';\nimport { Title } from '@hh.ru/magritte-ui-title';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './select-error.less';\n\n/** Ошибка дата-провайдера, показывать решает пикер */\nexport const SelectError: FC = () => {\n const { isMobile } = useBreakpoint();\n const { providerError } = useSelectError();\n\n if (!providerError) {\n return null;\n }\n\n const { title, description, reloadButton: reloadButtonExternal } = providerError;\n\n const errorContent = (\n <>\n <Title Element=\"h3\" size=\"small\" alignment=\"center\">\n {title}\n </Title>\n <VSpacing default={8} />\n <Text typography=\"paragraph-2-regular\" style=\"secondary\">\n {description}\n </Text>\n </>\n );\n\n if (isMobile) {\n return (\n <div className={styles.errorContainer} data-qa=\"magritte-select-error-xs\">\n {errorContent}\n </div>\n );\n }\n return (\n <div className={styles.errorContainer} data-qa=\"magritte-select-error\">\n {errorContent}\n <VSpacing default={32} />\n <SelectReloadButton label={reloadButtonExternal} />\n </div>\n );\n};\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWA;AACO,MAAM,WAAW,GAAO,MAAK;AAChC,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;AACrC,IAAA,MAAM,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE,CAAC;IAE3C,IAAI,CAAC,aAAa,EAAE;AAChB,QAAA,OAAO,IAAI,CAAC;KACf;IAED,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAAG,aAAa,CAAC;IAEjF,MAAM,YAAY,IACdA,IAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CACIC,IAAC,KAAK,EAAA,EAAC,OAAO,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,QAAQ,EAAA,QAAA,EAC9C,KAAK,EACF,CAAA,EACRA,IAAC,QAAQ,EAAA,EAAC,OAAO,EAAE,CAAC,GAAI,EACxBA,GAAA,CAAC,IAAI,EAAC,EAAA,UAAU,EAAC,qBAAqB,EAAC,KAAK,EAAC,WAAW,YACnD,WAAW,EAAA,CACT,CACR,EAAA,CAAA,CACN,CAAC;IAEF,IAAI,QAAQ,EAAE;AACV,QAAA,QACIA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,cAAc,EAAA,SAAA,EAAU,0BAA0B,EAAA,QAAA,EACpE,YAAY,EAAA,CACX,EACR;KACL;AACD,IAAA,QACIF,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,cAAc,EAAA,SAAA,EAAU,uBAAuB,EAAA,QAAA,EAAA,CACjE,YAAY,EACbE,GAAC,CAAA,QAAQ,EAAC,EAAA,OAAO,EAAE,EAAE,EAAI,CAAA,EACzBA,GAAC,CAAA,kBAAkB,EAAC,EAAA,KAAK,EAAE,oBAAoB,EAAI,CAAA,CAAA,EAAA,CACjD,EACR;AACN;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Button } from '@hh.ru/magritte-ui-button';
|
|
4
|
+
import { ArrowPathClockwiseOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
5
|
+
import { useDataProvider } from '../useDataProvider.js';
|
|
6
|
+
import 'react';
|
|
7
|
+
import './SelectDataProvider.js';
|
|
8
|
+
import '@hh.ru/magritte-common-data-provider';
|
|
9
|
+
import './useDataProvider.js';
|
|
10
|
+
import './utils.js';
|
|
11
|
+
import '../useSearchState.js';
|
|
12
|
+
import './SearchStateContext.js';
|
|
13
|
+
import '../useVisibility.js';
|
|
14
|
+
import './VisibilityContext.js';
|
|
15
|
+
|
|
16
|
+
const SelectReloadButton = ({ label }) => {
|
|
17
|
+
const { reloadRequest } = useDataProvider();
|
|
18
|
+
return (jsx(Button, { mode: "primary", style: "accent", size: "medium", onClick: reloadRequest, icon: jsx(ArrowPathClockwiseOutlinedSize24, {}), children: label }));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { SelectReloadButton };
|
|
22
|
+
//# sourceMappingURL=SelectReloadButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectReloadButton.js","sources":["src/internal/SelectReloadButton.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { Button } from '@hh.ru/magritte-ui-button';\nimport { ArrowPathClockwiseOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { useDataProvider } from '@hh.ru/magritte-ui-select/useDataProvider';\n\nexport const SelectReloadButton: FC<{ label: string }> = ({ label }) => {\n const { reloadRequest } = useDataProvider();\n return (\n <Button\n mode=\"primary\"\n style=\"accent\"\n size=\"medium\"\n onClick={reloadRequest}\n icon={<ArrowPathClockwiseOutlinedSize24 />}\n >\n {label}\n </Button>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;MAMa,kBAAkB,GAA0B,CAAC,EAAE,KAAK,EAAE,KAAI;AACnE,IAAA,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe,EAAE,CAAC;AAC5C,IAAA,QACIA,GAAA,CAAC,MAAM,EAAA,EACH,IAAI,EAAC,SAAS,EACd,KAAK,EAAC,QAAQ,EACd,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,aAAa,EACtB,IAAI,EAAEA,GAAC,CAAA,gCAAgC,EAAG,EAAA,CAAA,EAAA,QAAA,EAEzC,KAAK,EAAA,CACD,EACX;AACN;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ReactNode, type ReactElement } from 'react';
|
|
2
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
+
import { SelectStore } from '@hh.ru/magritte-ui-select/internal/SelectStore';
|
|
4
|
+
import { ValueTypeHelper } from '@hh.ru/magritte-ui-select/types';
|
|
5
|
+
export declare const SelectDraftStoreContext: import("react").Context<SelectStore<StaticDataFetcherItem> | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Возвращает ссылку на драфт стор, если такой зарегистрирован.
|
|
8
|
+
* Иначе даем работать с общим стором.
|
|
9
|
+
* Даем возможность получить доступ напрямую к CommittedStore (например, для Apply к Drop).
|
|
10
|
+
*/
|
|
11
|
+
export declare const useSelectStore: <DataType extends StaticDataFetcherItem>() => SelectStore<DataType>;
|
|
12
|
+
export declare const useSelected: <DataType extends StaticDataFetcherItem>(store: SelectStore<DataType>) => readonly DataType[];
|
|
13
|
+
interface SelectStateProviderNewProps<MultipleType extends boolean, DataType extends StaticDataFetcherItem> {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
onChange?: (value: ValueTypeHelper<MultipleType, DataType>) => void;
|
|
16
|
+
value?: ValueTypeHelper<MultipleType, DataType>;
|
|
17
|
+
}
|
|
18
|
+
export declare const SelectStateProvider: <MultipleType extends boolean, DataType extends StaticDataFetcherItem>({ children, onChange, value: valueOrValuesExternal, }: SelectStateProviderNewProps<MultipleType, DataType>) => ReactElement;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { createContext, useContext, useSyncExternalStore, useState, useRef, useEffect } from 'react';
|
|
4
|
+
import { SelectStore } from './SelectStore.js';
|
|
5
|
+
import { assertSelectContext, value2Array } from './utils.js';
|
|
6
|
+
import { useSelectConfig } from '../useSelectConfig.js';
|
|
7
|
+
import './ConfigContext.js';
|
|
8
|
+
|
|
9
|
+
const SelectStoreContext = createContext(null);
|
|
10
|
+
const SelectDraftStoreContext = createContext(null);
|
|
11
|
+
/**
|
|
12
|
+
* Возвращает ссылку на драфт стор, если такой зарегистрирован.
|
|
13
|
+
* Иначе даем работать с общим стором.
|
|
14
|
+
* Даем возможность получить доступ напрямую к CommittedStore (например, для Apply к Drop).
|
|
15
|
+
*/
|
|
16
|
+
const useSelectStore = () => {
|
|
17
|
+
const draftStore = useContext(SelectDraftStoreContext);
|
|
18
|
+
const committedStore = useContext(SelectStoreContext);
|
|
19
|
+
if (draftStore) {
|
|
20
|
+
return draftStore;
|
|
21
|
+
}
|
|
22
|
+
return assertSelectContext(committedStore, 'useSelectStore');
|
|
23
|
+
};
|
|
24
|
+
// возвращает реактивное состояние стора
|
|
25
|
+
const useSelected = (store) => {
|
|
26
|
+
return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
27
|
+
};
|
|
28
|
+
// выбранные значения, операции над ними и эмит внешнего onChange
|
|
29
|
+
const SelectStateProvider = ({ children, onChange, value: valueOrValuesExternal, }) => {
|
|
30
|
+
const [store] = useState(() => new SelectStore(value2Array(valueOrValuesExternal)));
|
|
31
|
+
const { multiple } = useSelectConfig();
|
|
32
|
+
// во время реакции на внешнее обновление value
|
|
33
|
+
// - эмитить внешний onChange НЕ нужно
|
|
34
|
+
// - но обновить дерево селекта нужно
|
|
35
|
+
const suppressOnChangeRef = useRef(false);
|
|
36
|
+
// эмит внешнего onChange для потребителей
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const storeUnsubscribe = store.subscribe(() => {
|
|
39
|
+
if (suppressOnChangeRef.current) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const selected = store.getSnapshot();
|
|
43
|
+
onChange?.((multiple ? [...selected] : selected[0]));
|
|
44
|
+
});
|
|
45
|
+
return storeUnsubscribe;
|
|
46
|
+
}, [store, multiple, onChange]);
|
|
47
|
+
// синк стора с внешним свойством
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
suppressOnChangeRef.current = true;
|
|
50
|
+
try {
|
|
51
|
+
store.replace(value2Array(valueOrValuesExternal));
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
suppressOnChangeRef.current = false;
|
|
55
|
+
}
|
|
56
|
+
}, [store, valueOrValuesExternal]);
|
|
57
|
+
return jsx(SelectStoreContext.Provider, { value: store, children: children });
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { SelectDraftStoreContext, SelectStateProvider, useSelectStore, useSelected };
|
|
61
|
+
//# sourceMappingURL=SelectStateContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectStateContext.js","sources":["src/internal/SelectStateContext.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n type ReactNode,\n type ReactElement,\n useState,\n useSyncExternalStore,\n useEffect,\n useRef,\n} from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { SelectStore } from '@hh.ru/magritte-ui-select/internal/SelectStore';\nimport { assertSelectContext, value2Array } from '@hh.ru/magritte-ui-select/internal/utils';\nimport { ValueTypeHelper } from '@hh.ru/magritte-ui-select/types';\nimport { useSelectConfig } from '@hh.ru/magritte-ui-select/useSelectConfig';\n\nconst SelectStoreContext = createContext<SelectStore<StaticDataFetcherItem> | null>(null);\n\nexport const SelectDraftStoreContext = createContext<SelectStore<StaticDataFetcherItem> | null>(null);\n\n/**\n * Возвращает ссылку на драфт стор, если такой зарегистрирован.\n * Иначе даем работать с общим стором.\n * Даем возможность получить доступ напрямую к CommittedStore (например, для Apply к Drop).\n */\nexport const useSelectStore = <DataType extends StaticDataFetcherItem>(): SelectStore<DataType> => {\n const draftStore = useContext(SelectDraftStoreContext);\n const committedStore = useContext(SelectStoreContext);\n if (draftStore) {\n return draftStore as SelectStore<DataType>;\n }\n return assertSelectContext(committedStore, 'useSelectStore') as SelectStore<DataType>;\n};\n\n// возвращает реактивное состояние стора\nexport const useSelected = <DataType extends StaticDataFetcherItem>(\n store: SelectStore<DataType>\n): readonly DataType[] => {\n return useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n};\n\ninterface SelectStateProviderNewProps<MultipleType extends boolean, DataType extends StaticDataFetcherItem> {\n children: ReactNode;\n onChange?: (value: ValueTypeHelper<MultipleType, DataType>) => void;\n value?: ValueTypeHelper<MultipleType, DataType>;\n}\n\n// выбранные значения, операции над ними и эмит внешнего onChange\nexport const SelectStateProvider = <MultipleType extends boolean, DataType extends StaticDataFetcherItem>({\n children,\n onChange,\n value: valueOrValuesExternal,\n}: SelectStateProviderNewProps<MultipleType, DataType>): ReactElement => {\n const [store] = useState(() => new SelectStore(value2Array<MultipleType, DataType>(valueOrValuesExternal)));\n const { multiple } = useSelectConfig();\n\n // во время реакции на внешнее обновление value\n // - эмитить внешний onChange НЕ нужно\n // - но обновить дерево селекта нужно\n const suppressOnChangeRef = useRef(false);\n\n // эмит внешнего onChange для потребителей\n useEffect(() => {\n const storeUnsubscribe = store.subscribe(() => {\n if (suppressOnChangeRef.current) {\n return;\n }\n const selected = store.getSnapshot();\n onChange?.((multiple ? [...selected] : selected[0]) as ValueTypeHelper<MultipleType, DataType>);\n });\n return storeUnsubscribe;\n }, [store, multiple, onChange]);\n\n // синк стора с внешним свойством\n useEffect(() => {\n suppressOnChangeRef.current = true;\n try {\n store.replace(value2Array<MultipleType, DataType>(valueOrValuesExternal));\n } finally {\n suppressOnChangeRef.current = false;\n }\n }, [store, valueOrValuesExternal]);\n\n return <SelectStoreContext.Provider value={store}>{children}</SelectStoreContext.Provider>;\n};\n"],"names":["_jsx"],"mappings":";;;;;;;AAiBA,M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C,CAAC,EAA6C,CAAC;AACpG,SAAC,CAAC,CAAC;AACH,QAAA,OAAO,gBAAgB,CAAC;KAC3B,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;;IAGhC,SAAS,CAAC,MAAK;AACX,QAAA,mBAAmB,CAAC,OAAO,GAAG,IAAI,CAAC;AACnC,QAAA,IAAI;YACA,KAAK,CAAC,OAAO,CAAC,WAAW,CAAyB,qBAAqB,CAAC,CAAC,CAAC;SAC7E;gBAAS;AACN,YAAA,mBAAmB,CAAC,OAAO,GAAG,KAAK,CAAC;SACvC;AACL,KAAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAEnC,OAAOA,GAAA,CAAC,kBAAkB,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAAA,QAAA,EAAG,QAAQ,EAAA,CAA+B,CAAC;AAC/F;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
2
|
+
type Listener = () => void;
|
|
3
|
+
type Value = StaticDataFetcherItem['value'];
|
|
4
|
+
export declare class SelectStore<DataType extends StaticDataFetcherItem> {
|
|
5
|
+
private values;
|
|
6
|
+
private readonly listeners;
|
|
7
|
+
constructor(initial?: readonly DataType[]);
|
|
8
|
+
getSnapshot: () => readonly DataType[];
|
|
9
|
+
subscribe: (listener: Listener) => VoidFunction;
|
|
10
|
+
replace(source: readonly DataType[]): void;
|
|
11
|
+
add(value: DataType): void;
|
|
12
|
+
remove(id: Value): void;
|
|
13
|
+
clear(): void;
|
|
14
|
+
private emit;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import './../index.css';
|
|
2
|
+
import { isArraysEquals, extractValues } from './utils.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
// стор хранит выбранные объекты, а не ids
|
|
6
|
+
// внешний onChange должен получать DataType | DataType[]
|
|
7
|
+
// массив опций меняется дата провайдером => нужно место, где хранить обьекты DataType
|
|
8
|
+
class SelectStore {
|
|
9
|
+
values;
|
|
10
|
+
listeners = new Set();
|
|
11
|
+
constructor(initial = []) {
|
|
12
|
+
this.values = [...initial];
|
|
13
|
+
}
|
|
14
|
+
getSnapshot = () => {
|
|
15
|
+
return this.values;
|
|
16
|
+
};
|
|
17
|
+
subscribe = (listener) => {
|
|
18
|
+
this.listeners.add(listener);
|
|
19
|
+
return () => {
|
|
20
|
+
this.listeners.delete(listener);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
replace(source) {
|
|
24
|
+
// идентичность выбранных элементов определяется через поле value
|
|
25
|
+
// так как value единственное поле которое StaticDataFetcherItem гарантирует
|
|
26
|
+
if (isArraysEquals(extractValues(this.values), extractValues(source))) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.values = [...source];
|
|
30
|
+
this.emit();
|
|
31
|
+
}
|
|
32
|
+
add(value) {
|
|
33
|
+
if (this.values.some((item) => item.value === value.value)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.values = [...this.values, value];
|
|
37
|
+
this.emit();
|
|
38
|
+
}
|
|
39
|
+
remove(id) {
|
|
40
|
+
if (!this.values.some((item) => item.value === id)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.values = this.values.filter((item) => item.value !== id);
|
|
44
|
+
this.emit();
|
|
45
|
+
}
|
|
46
|
+
clear() {
|
|
47
|
+
if (this.values.length === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.values = [];
|
|
51
|
+
this.emit();
|
|
52
|
+
}
|
|
53
|
+
emit() {
|
|
54
|
+
this.listeners.forEach((listener) => listener());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { SelectStore };
|
|
59
|
+
//# sourceMappingURL=SelectStore.js.map
|