@hh.ru/magritte-ui-select 12.9.27 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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,17 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
+
import { OptionsCount } from '@hh.ru/magritte-ui-select/types';
|
|
4
|
+
interface OnApply extends OptionsCount {
|
|
5
|
+
isMobile: boolean;
|
|
6
|
+
searchValue: string;
|
|
7
|
+
selectedOptionsCount: number;
|
|
8
|
+
}
|
|
9
|
+
interface ApplyChangesButtonProps {
|
|
10
|
+
/** Кнопка "Применить" */
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
/** Обработчик события клика на кнопку apply */
|
|
13
|
+
onApply?: (props: OnApply) => void;
|
|
14
|
+
}
|
|
15
|
+
/** Кнопка применения values */
|
|
16
|
+
declare const ApplyChangesButton: <DataType extends StaticDataFetcherItem>({ children, onApply, }: ApplyChangesButtonProps) => ReactNode;
|
|
17
|
+
export { ApplyChangesButton };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { isValidElement, cloneElement } from 'react';
|
|
3
|
+
import { useTranslation } from '@hh.ru/magritte-common-use-translation';
|
|
4
|
+
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
5
|
+
import { useSelectPicker } from './SelectPickerContext.js';
|
|
6
|
+
import { useSelectStore, useSelected } from './internal/SelectStateContext.js';
|
|
7
|
+
import { useRegisterSelectElementsSlot } from './internal/slots.js';
|
|
8
|
+
import { useDataProvider } from './useDataProvider.js';
|
|
9
|
+
import { useSearchState } from './useSearchState.js';
|
|
10
|
+
import 'react/jsx-runtime';
|
|
11
|
+
import './internal/SelectStore.js';
|
|
12
|
+
import './internal/utils.js';
|
|
13
|
+
import './useVisibility.js';
|
|
14
|
+
import './internal/VisibilityContext.js';
|
|
15
|
+
import './useSelectConfig.js';
|
|
16
|
+
import './internal/ConfigContext.js';
|
|
17
|
+
import '@hh.ru/magritte-internal-slot-registry';
|
|
18
|
+
import './internal/SelectDataProvider.js';
|
|
19
|
+
import '@hh.ru/magritte-common-data-provider';
|
|
20
|
+
import './internal/useDataProvider.js';
|
|
21
|
+
import './internal/SearchStateContext.js';
|
|
22
|
+
|
|
23
|
+
/** Кнопка применения values */
|
|
24
|
+
const ApplyChangesButton = ({ children, onApply, }) => {
|
|
25
|
+
const applyTrl = useTranslation('Select', 'apply');
|
|
26
|
+
const { isMobile } = useBreakpoint();
|
|
27
|
+
const { optionList } = useDataProvider();
|
|
28
|
+
const { searchValue } = useSearchState();
|
|
29
|
+
const selectDraftStore = useSelectStore();
|
|
30
|
+
const selectedValues = useSelected(selectDraftStore);
|
|
31
|
+
const { applyChanges, onCloseRequestWithUnsavedChanges } = useSelectPicker();
|
|
32
|
+
useRegisterSelectElementsSlot('commitModel', 'confirm');
|
|
33
|
+
const defaultDataQa = isMobile ? 'magritte-select-apply-on-xs' : 'magritte-select-apply';
|
|
34
|
+
const applyChangesButton = isValidElement(children) &&
|
|
35
|
+
cloneElement(children, {
|
|
36
|
+
key: children.key ?? 'applyChangesButton',
|
|
37
|
+
'data-qa': children.props['data-qa'] ?? defaultDataQa,
|
|
38
|
+
'aria-label': children.props['aria-label'] ?? applyTrl,
|
|
39
|
+
size: 'medium',
|
|
40
|
+
onClick: () => {
|
|
41
|
+
applyChanges();
|
|
42
|
+
onCloseRequestWithUnsavedChanges();
|
|
43
|
+
onApply?.({
|
|
44
|
+
isMobile,
|
|
45
|
+
searchValue,
|
|
46
|
+
optionsCount: optionList.length,
|
|
47
|
+
selectedOptionsCount: selectedValues.length,
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
return applyChangesButton;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export { ApplyChangesButton };
|
|
55
|
+
//# sourceMappingURL=ApplyChangesButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApplyChangesButton.js","sources":["src/ApplyChangesButton.tsx"],"sourcesContent":["import { isValidElement, cloneElement, ReactNode, ComponentProps } from 'react';\n\nimport { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';\nimport { useTranslation } from '@hh.ru/magritte-common-use-translation';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { Button } from '@hh.ru/magritte-ui-button';\nimport { useSelectPicker } from '@hh.ru/magritte-ui-select/SelectPickerContext';\nimport { useSelectStore, useSelected } from '@hh.ru/magritte-ui-select/internal/SelectStateContext';\nimport { useRegisterSelectElementsSlot } from '@hh.ru/magritte-ui-select/internal/slots';\nimport { OptionsCount } from '@hh.ru/magritte-ui-select/types';\nimport { useDataProvider } from '@hh.ru/magritte-ui-select/useDataProvider';\nimport { useSearchState } from '@hh.ru/magritte-ui-select/useSearchState';\n\ninterface OnApply extends OptionsCount {\n isMobile: boolean;\n searchValue: string;\n selectedOptionsCount: number;\n}\n\ninterface ApplyChangesButtonProps {\n /** Кнопка \"Применить\" */\n children?: ReactNode;\n /** Обработчик события клика на кнопку apply */\n onApply?: (props: OnApply) => void;\n}\n\n/** Кнопка применения values */\nconst ApplyChangesButton = <DataType extends StaticDataFetcherItem>({\n children,\n onApply,\n}: ApplyChangesButtonProps): ReactNode => {\n const applyTrl = useTranslation('Select', 'apply');\n const { isMobile } = useBreakpoint();\n const { optionList } = useDataProvider<DataType>();\n const { searchValue } = useSearchState();\n const selectDraftStore = useSelectStore<DataType>();\n const selectedValues = useSelected<DataType>(selectDraftStore);\n const { applyChanges, onCloseRequestWithUnsavedChanges } = useSelectPicker();\n\n useRegisterSelectElementsSlot('commitModel', 'confirm');\n\n const defaultDataQa = isMobile ? 'magritte-select-apply-on-xs' : 'magritte-select-apply';\n const applyChangesButton =\n isValidElement<ComponentProps<typeof Button>>(children) &&\n cloneElement(children, {\n key: children.key ?? 'applyChangesButton',\n 'data-qa': children.props['data-qa'] ?? defaultDataQa,\n 'aria-label': children.props['aria-label'] ?? applyTrl,\n size: 'medium',\n onClick: () => {\n applyChanges();\n onCloseRequestWithUnsavedChanges();\n onApply?.({\n isMobile,\n searchValue,\n optionsCount: optionList.length,\n selectedOptionsCount: selectedValues.length,\n });\n },\n } as Partial<ComponentProps<typeof Button>>);\n\n return applyChangesButton;\n};\n\nexport { ApplyChangesButton };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0BA;AACM,MAAA,kBAAkB,GAAG,CAAyC,EAChE,QAAQ,EACR,OAAO,GACe,KAAe;IACrC,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACnD,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;AACrC,IAAA,MAAM,EAAE,UAAU,EAAE,GAAG,eAAe,EAAY,CAAC;AACnD,IAAA,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,EAAE,CAAC;AACzC,IAAA,MAAM,gBAAgB,GAAG,cAAc,EAAY,CAAC;AACpD,IAAA,MAAM,cAAc,GAAG,WAAW,CAAW,gBAAgB,CAAC,CAAC;IAC/D,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,eAAe,EAAE,CAAC;AAE7E,IAAA,6BAA6B,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAExD,MAAM,aAAa,GAAG,QAAQ,GAAG,6BAA6B,GAAG,uBAAuB,CAAC;AACzF,IAAA,MAAM,kBAAkB,GACpB,cAAc,CAAgC,QAAQ,CAAC;QACvD,YAAY,CAAC,QAAQ,EAAE;AACnB,YAAA,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,oBAAoB;YACzC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,aAAa;YACrD,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,QAAQ;AACtD,YAAA,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,MAAK;AACV,gBAAA,YAAY,EAAE,CAAC;AACf,gBAAA,gCAAgC,EAAE,CAAC;AACnC,gBAAA,OAAO,GAAG;oBACN,QAAQ;oBACR,WAAW;oBACX,YAAY,EAAE,UAAU,CAAC,MAAM;oBAC/B,oBAAoB,EAAE,cAAc,CAAC,MAAM;AAC9C,iBAAA,CAAC,CAAC;aACN;AACsC,SAAA,CAAC,CAAC;AAEjD,IAAA,OAAO,kBAAkB,CAAC;AAC9B;;;;"}
|
package/ClearButton.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface ClearButtonProps {
|
|
3
|
+
/** Кнопка очистки */
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
/** Обработчик события клика на кнопку clear */
|
|
6
|
+
onClear?: VoidFunction;
|
|
7
|
+
/**
|
|
8
|
+
* Флаг управления поведением: clear применяет empty-состояние наружу и закрывает пикер.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
applyOnClear?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Кнопка сброса values */
|
|
14
|
+
declare const ClearButton: ({ children, onClear, applyOnClear }: ClearButtonProps) => ReactNode;
|
|
15
|
+
export { ClearButton };
|
package/ClearButton.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { isValidElement, cloneElement } from 'react';
|
|
3
|
+
import { useTranslation } from '@hh.ru/magritte-common-use-translation';
|
|
4
|
+
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
5
|
+
import { useSelectPicker } from './SelectPickerContext.js';
|
|
6
|
+
import 'react/jsx-runtime';
|
|
7
|
+
import './internal/SelectStateContext.js';
|
|
8
|
+
import './internal/SelectStore.js';
|
|
9
|
+
import './internal/utils.js';
|
|
10
|
+
import './useSelectConfig.js';
|
|
11
|
+
import './internal/ConfigContext.js';
|
|
12
|
+
import './internal/slots.js';
|
|
13
|
+
import '@hh.ru/magritte-internal-slot-registry';
|
|
14
|
+
import './useVisibility.js';
|
|
15
|
+
import './internal/VisibilityContext.js';
|
|
16
|
+
|
|
17
|
+
/** Кнопка сброса values */
|
|
18
|
+
const ClearButton = ({ children, onClear, applyOnClear = true }) => {
|
|
19
|
+
const { isMobile } = useBreakpoint();
|
|
20
|
+
const clearTrl = useTranslation('Select', 'clear');
|
|
21
|
+
const { clearChanges, onCloseRequestWithUnsavedChanges } = useSelectPicker();
|
|
22
|
+
const defaultDataQa = isMobile ? 'magritte-select-clear-action-on-xs' : 'magritte-select-clear-action';
|
|
23
|
+
const clearButton = children &&
|
|
24
|
+
isValidElement(children) &&
|
|
25
|
+
cloneElement(children, {
|
|
26
|
+
key: children.key ?? 'clearButton',
|
|
27
|
+
'data-qa': children.props['data-qa'] ?? defaultDataQa,
|
|
28
|
+
'aria-label': children.props['aria-label'] ?? clearTrl,
|
|
29
|
+
size: 'medium',
|
|
30
|
+
onClick: () => {
|
|
31
|
+
clearChanges(applyOnClear);
|
|
32
|
+
if (applyOnClear) {
|
|
33
|
+
onCloseRequestWithUnsavedChanges();
|
|
34
|
+
}
|
|
35
|
+
onClear?.();
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return clearButton;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { ClearButton };
|
|
42
|
+
//# sourceMappingURL=ClearButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClearButton.js","sources":["src/ClearButton.tsx"],"sourcesContent":["import { isValidElement, cloneElement, ReactNode, ComponentProps } from 'react';\n\nimport { useTranslation } from '@hh.ru/magritte-common-use-translation';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { Button } from '@hh.ru/magritte-ui-button';\nimport { useSelectPicker } from '@hh.ru/magritte-ui-select/SelectPickerContext';\n\nexport interface ClearButtonProps {\n /** Кнопка очистки */\n children?: ReactNode;\n /** Обработчик события клика на кнопку clear */\n onClear?: VoidFunction;\n /**\n * Флаг управления поведением: clear применяет empty-состояние наружу и закрывает пикер.\n * @default true\n */\n applyOnClear?: boolean;\n}\n\n/** Кнопка сброса values */\nconst ClearButton = ({ children, onClear, applyOnClear = true }: ClearButtonProps): ReactNode => {\n const { isMobile } = useBreakpoint();\n const clearTrl = useTranslation('Select', 'clear');\n const { clearChanges, onCloseRequestWithUnsavedChanges } = useSelectPicker();\n\n const defaultDataQa = isMobile ? 'magritte-select-clear-action-on-xs' : 'magritte-select-clear-action';\n const clearButton =\n children &&\n isValidElement<ComponentProps<typeof Button>>(children) &&\n cloneElement(children, {\n key: children.key ?? 'clearButton',\n 'data-qa': children.props['data-qa'] ?? defaultDataQa,\n 'aria-label': children.props['aria-label'] ?? clearTrl,\n size: 'medium',\n onClick: () => {\n clearChanges(applyOnClear);\n if (applyOnClear) {\n onCloseRequestWithUnsavedChanges();\n }\n onClear?.();\n },\n } as Partial<ComponentProps<typeof Button>>);\n\n return clearButton;\n};\n\nexport { ClearButton };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmBA;AACA,MAAM,WAAW,GAAG,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,EAAoB,KAAe;AAC5F,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,eAAe,EAAE,CAAC;IAE7E,MAAM,aAAa,GAAG,QAAQ,GAAG,oCAAoC,GAAG,8BAA8B,CAAC;IACvG,MAAM,WAAW,GACb,QAAQ;QACR,cAAc,CAAgC,QAAQ,CAAC;QACvD,YAAY,CAAC,QAAQ,EAAE;AACnB,YAAA,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,aAAa;YAClC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,aAAa;YACrD,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,QAAQ;AACtD,YAAA,IAAI,EAAE,QAAQ;YACd,OAAO,EAAE,MAAK;gBACV,YAAY,CAAC,YAAY,CAAC,CAAC;gBAC3B,IAAI,YAAY,EAAE;AACd,oBAAA,gCAAgC,EAAE,CAAC;iBACtC;gBACD,OAAO,IAAI,CAAC;aACf;AACsC,SAAA,CAAC,CAAC;AAEjD,IAAA,OAAO,WAAW,CAAC;AACvB;;;;"}
|
package/ClearCard.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { ClearButtonProps } from '@hh.ru/magritte-ui-select/ClearButton';
|
|
3
|
+
/** Кнопка сброса values в виде карточки */
|
|
4
|
+
declare const ClearCard: ({ onClear, applyOnClear, children }: ClearButtonProps) => ReactNode;
|
|
5
|
+
export { ClearCard };
|
package/ClearCard.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useTranslation } from '@hh.ru/magritte-common-use-translation';
|
|
4
|
+
import { Card } from '@hh.ru/magritte-ui-card';
|
|
5
|
+
import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
|
|
6
|
+
import { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
7
|
+
import { ClearButton } from './ClearButton.js';
|
|
8
|
+
import 'react';
|
|
9
|
+
import '@hh.ru/magritte-ui-breakpoint';
|
|
10
|
+
import './SelectPickerContext.js';
|
|
11
|
+
import './internal/SelectStateContext.js';
|
|
12
|
+
import './internal/SelectStore.js';
|
|
13
|
+
import './internal/utils.js';
|
|
14
|
+
import './useSelectConfig.js';
|
|
15
|
+
import './internal/ConfigContext.js';
|
|
16
|
+
import './internal/slots.js';
|
|
17
|
+
import '@hh.ru/magritte-internal-slot-registry';
|
|
18
|
+
import './useVisibility.js';
|
|
19
|
+
import './internal/VisibilityContext.js';
|
|
20
|
+
|
|
21
|
+
/** Кнопка сброса values в виде карточки */
|
|
22
|
+
const ClearCard = ({ onClear, applyOnClear = true, children }) => {
|
|
23
|
+
const clearTrl = useTranslation('Select', 'clear');
|
|
24
|
+
return (jsx(ClearButton, { onClear: onClear, applyOnClear: applyOnClear, children: jsx(Card, { borderWidth: "default", stretched: true, hoverStyle: "secondary", padding: 16, borderRadius: 16, children: jsx(Cell, { Element: "div", align: "center", left: jsx(CrossOutlinedSize24, {}), children: jsx(CellText, { maxLines: 1, children: children || clearTrl }) }) }) }));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { ClearCard };
|
|
28
|
+
//# sourceMappingURL=ClearCard.js.map
|
package/ClearCard.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClearCard.js","sources":["src/ClearCard.tsx"],"sourcesContent":["import { ReactNode } from 'react';\n\nimport { useTranslation } from '@hh.ru/magritte-common-use-translation';\nimport { Card } from '@hh.ru/magritte-ui-card';\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { CrossOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { ClearButton, ClearButtonProps } from '@hh.ru/magritte-ui-select/ClearButton';\n\n/** Кнопка сброса values в виде карточки */\nconst ClearCard = ({ onClear, applyOnClear = true, children }: ClearButtonProps): ReactNode => {\n const clearTrl = useTranslation('Select', 'clear');\n return (\n <ClearButton onClear={onClear} applyOnClear={applyOnClear}>\n <Card borderWidth=\"default\" stretched hoverStyle=\"secondary\" padding={16} borderRadius={16}>\n <Cell Element=\"div\" align=\"center\" left={<CrossOutlinedSize24 />}>\n <CellText maxLines={1}>{children || clearTrl}</CellText>\n </Cell>\n </Card>\n </ClearButton>\n );\n};\n\nexport { ClearCard };\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;AAQA;AACA,MAAM,SAAS,GAAG,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,EAAE,QAAQ,EAAoB,KAAe;IAC1F,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACnD,IAAA,QACIA,GAAA,CAAC,WAAW,EAAA,EAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAA,QAAA,EACrDA,IAAC,IAAI,EAAA,EAAC,WAAW,EAAC,SAAS,EAAC,SAAS,EAAA,IAAA,EAAC,UAAU,EAAC,WAAW,EAAC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EACtF,QAAA,EAAAA,GAAA,CAAC,IAAI,EAAA,EAAC,OAAO,EAAC,KAAK,EAAC,KAAK,EAAC,QAAQ,EAAC,IAAI,EAAEA,IAAC,mBAAmB,EAAA,EAAA,CAAG,EAC5D,QAAA,EAAAA,GAAA,CAAC,QAAQ,EAAA,EAAC,QAAQ,EAAE,CAAC,EAAG,QAAA,EAAA,QAAQ,IAAI,QAAQ,EAAY,CAAA,EAAA,CACrD,EACJ,CAAA,EAAA,CACG,EAChB;AACN;;;;"}
|
package/Select.d.ts
CHANGED
|
@@ -1,9 +1,50 @@
|
|
|
1
|
-
import { ReactElement
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
2
|
import { StaticDataFetcherItem } from '@hh.ru/magritte-common-data-provider';
|
|
3
|
+
import { ApplyChangesButton } from '@hh.ru/magritte-ui-select/ApplyChangesButton';
|
|
4
|
+
import { ClearButton } from '@hh.ru/magritte-ui-select/ClearButton';
|
|
5
|
+
import { ClearCard } from '@hh.ru/magritte-ui-select/ClearCard';
|
|
6
|
+
import { SelectBottomSheet } from '@hh.ru/magritte-ui-select/SelectBottomSheet';
|
|
7
|
+
import { SelectBottomSheetHeader } from '@hh.ru/magritte-ui-select/SelectBottomSheetHeader';
|
|
8
|
+
import { SelectDrop } from '@hh.ru/magritte-ui-select/SelectDrop';
|
|
9
|
+
import { SelectEmptyHint } from '@hh.ru/magritte-ui-select/SelectEmptyHint';
|
|
10
|
+
import { SelectOptions } from '@hh.ru/magritte-ui-select/SelectOptions';
|
|
11
|
+
import { SelectPickerCloseIcon } from '@hh.ru/magritte-ui-select/SelectPickerCloseIcon';
|
|
12
|
+
import { SelectPickerProvider } from '@hh.ru/magritte-ui-select/SelectPickerContext';
|
|
13
|
+
import { SelectSearchInput } from '@hh.ru/magritte-ui-select/SelectSearchInput';
|
|
14
|
+
import { SelectSearchTrigger } from '@hh.ru/magritte-ui-select/SelectSearchTrigger';
|
|
15
|
+
import { SelectTrigger } from '@hh.ru/magritte-ui-select/SelectTrigger';
|
|
3
16
|
import { SelectProps } from '@hh.ru/magritte-ui-select/types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
export interface SelectComponents {
|
|
18
|
+
/** Кнопка применения values */
|
|
19
|
+
ApplyChangesButton: typeof ApplyChangesButton;
|
|
20
|
+
/** Пикер Select в виде BottomSheet */
|
|
21
|
+
BottomSheet: typeof SelectBottomSheet;
|
|
22
|
+
/** Крест закрытия пикера (Drop/BottomSheet) */
|
|
23
|
+
PickerCloseIcon: typeof SelectPickerCloseIcon;
|
|
24
|
+
/** Default header для select bottom-sheet */
|
|
25
|
+
BottomSheetHeader: typeof SelectBottomSheetHeader;
|
|
26
|
+
/** Кнопка сброса values */
|
|
27
|
+
ClearButton: typeof ClearButton;
|
|
28
|
+
/** Кнопка сброса values в виде карточки */
|
|
29
|
+
ClearCard: typeof ClearCard;
|
|
30
|
+
/** Пикер Select в виде Drop */
|
|
31
|
+
Drop: typeof SelectDrop;
|
|
32
|
+
/** Триггер Select на основе компонента Trigger */
|
|
33
|
+
Trigger: typeof SelectTrigger;
|
|
34
|
+
/** Дефолтное вью подсказки о пустом списке, передаётся в свойства emptyHint/emptySearchHint */
|
|
35
|
+
EmptyHint: typeof SelectEmptyHint;
|
|
36
|
+
/** Поисковый триггер Select на основе компонента Trigger и Input */
|
|
37
|
+
SearchTrigger: typeof SelectSearchTrigger;
|
|
38
|
+
/** Поисковый Input для обновления стейта поиска (подходит для использования в NavBar) */
|
|
39
|
+
SearchInput: typeof SelectSearchInput;
|
|
40
|
+
/**
|
|
41
|
+
* Компонент позволяет создавать кастомные пикеры (например, select modal).
|
|
42
|
+
* Провайдер предоставляет набор функций для работы с моделью выбора.
|
|
43
|
+
*/
|
|
44
|
+
PickerProvider: typeof SelectPickerProvider;
|
|
45
|
+
/** Используется для отображения списка опций */
|
|
46
|
+
Options: typeof SelectOptions;
|
|
47
|
+
}
|
|
48
|
+
declare const SelectRoot: <MultipleType extends boolean, DataType extends StaticDataFetcherItem>({ children, dataProvider, maxSelectedOptions, multiple, name, loading, onBlur: onBlurExternal, onChange: onChangeExternal, onFocus: onFocusExternal, onOptionsChange: onOptionsChangeExternal, options, value, error, providerError, emptyHint, emptySearchHint, }: SelectProps<MultipleType, DataType>) => ReactElement;
|
|
49
|
+
declare const Select: typeof SelectRoot & SelectComponents;
|
|
9
50
|
export { Select };
|
package/Select.js
CHANGED
|
@@ -1,299 +1,93 @@
|
|
|
1
1
|
import './index.css';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
8
|
-
import { BaseInput } from '@hh.ru/magritte-ui-input/BaseInput';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { ApplyChangesButton } from './ApplyChangesButton.js';
|
|
5
|
+
import { ClearButton } from './ClearButton.js';
|
|
6
|
+
import { ClearCard } from './ClearCard.js';
|
|
9
7
|
import { SelectBottomSheet } from './SelectBottomSheet.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import '
|
|
8
|
+
import { SelectBottomSheetHeader } from './SelectBottomSheetHeader.js';
|
|
9
|
+
import { SelectDrop } from './SelectDrop.js';
|
|
10
|
+
import { SelectEmptyHint } from './SelectEmptyHint.js';
|
|
11
|
+
import { SelectOptions } from './SelectOptions.js';
|
|
12
|
+
import { SelectPickerCloseIcon } from './SelectPickerCloseIcon.js';
|
|
13
|
+
import { SelectPickerProvider } from './SelectPickerContext.js';
|
|
14
|
+
import { SelectSearchInput } from './SelectSearchInput.js';
|
|
15
|
+
import { SelectSearchTrigger } from './SelectSearchTrigger.js';
|
|
16
|
+
import { SelectTrigger } from './SelectTrigger.js';
|
|
17
|
+
import { ConfigProvider } from './internal/ConfigContext.js';
|
|
18
|
+
import { NavigationManagement } from './internal/NavigationManagement.js';
|
|
19
|
+
import { SearchStateProvider } from './internal/SearchStateContext.js';
|
|
20
|
+
import { SelectDataProvider } from './internal/SelectDataProvider.js';
|
|
21
|
+
import { SelectStateProvider } from './internal/SelectStateContext.js';
|
|
22
|
+
import { VisibilityProvider } from './internal/VisibilityContext.js';
|
|
23
|
+
import { FocusOrchestratorProvider } from './internal/focusOrchestrator.js';
|
|
24
|
+
import { SelectElementsSlotRegistryProvider } from './internal/slots.js';
|
|
25
|
+
import { useEventCallback } from './internal/utils.js';
|
|
17
26
|
import '@hh.ru/magritte-common-use-translation';
|
|
18
|
-
import '@hh.ru/magritte-ui-
|
|
19
|
-
import '
|
|
20
|
-
import '@hh.ru/magritte-
|
|
27
|
+
import '@hh.ru/magritte-ui-breakpoint';
|
|
28
|
+
import './useDataProvider.js';
|
|
29
|
+
import '@hh.ru/magritte-common-data-provider';
|
|
30
|
+
import './internal/useDataProvider.js';
|
|
31
|
+
import './useSearchState.js';
|
|
32
|
+
import './useVisibility.js';
|
|
33
|
+
import './internal/SelectStore.js';
|
|
34
|
+
import './useSelectConfig.js';
|
|
35
|
+
import '@hh.ru/magritte-internal-slot-registry';
|
|
36
|
+
import '@hh.ru/magritte-ui-card';
|
|
21
37
|
import '@hh.ru/magritte-ui-cell';
|
|
22
38
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
23
|
-
import '
|
|
39
|
+
import 'classnames';
|
|
40
|
+
import '@hh.ru/magritte-common-use-multiple-refs';
|
|
41
|
+
import '@hh.ru/magritte-ui-action-bar';
|
|
42
|
+
import '@hh.ru/magritte-ui-bottom-sheet';
|
|
24
43
|
import '@hh.ru/magritte-ui-loader';
|
|
25
|
-
import '
|
|
26
|
-
import './
|
|
27
|
-
import '@hh.ru/magritte-ui-
|
|
44
|
+
import './internal/SelectError.js';
|
|
45
|
+
import './internal/SelectReloadButton.js';
|
|
46
|
+
import '@hh.ru/magritte-ui-button';
|
|
47
|
+
import './useSelectError.js';
|
|
28
48
|
import '@hh.ru/magritte-ui-spacing';
|
|
29
49
|
import '@hh.ru/magritte-ui-title';
|
|
30
50
|
import '@hh.ru/magritte-ui-typography';
|
|
31
|
-
import './
|
|
51
|
+
import './usePickerRef.js';
|
|
52
|
+
import './useSelectContentState.js';
|
|
53
|
+
import './useSelectHint.js';
|
|
54
|
+
import '@hh.ru/magritte-ui-nav-bar';
|
|
55
|
+
import '@hh.ru/magritte-ui-drop';
|
|
56
|
+
import './internal/Option.js';
|
|
57
|
+
import '@hh.ru/magritte-common-keyboard';
|
|
58
|
+
import '@hh.ru/magritte-common-use-disabled';
|
|
32
59
|
import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
60
|
+
import './internal/OptionControl.js';
|
|
33
61
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
34
|
-
import '
|
|
35
|
-
import '
|
|
36
|
-
import '
|
|
37
|
-
import '@hh.ru/magritte-ui-
|
|
38
|
-
import '
|
|
39
|
-
import '@hh.ru/magritte-common-data-provider';
|
|
62
|
+
import '@hh.ru/magritte-ui-input';
|
|
63
|
+
import '@hh.ru/magritte-ui-input/BaseInput';
|
|
64
|
+
import './useSelectTrigger.js';
|
|
65
|
+
import '@hh.ru/magritte-ui-trigger';
|
|
66
|
+
import './internal/useFocusWithin.js';
|
|
40
67
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
nextFocusableElement.focus();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
const SEARCH_INPUT_STATE = {
|
|
54
|
-
useSearchInput: false,
|
|
55
|
-
emitEvents: false,
|
|
56
|
-
};
|
|
57
|
-
const DEFAULT_DATA_QA = 'magritte-select-activator';
|
|
58
|
-
const DEFAULT_TRIGGER_PROPS = {
|
|
59
|
-
size: 'medium',
|
|
60
|
-
'data-qa': DEFAULT_DATA_QA,
|
|
61
|
-
};
|
|
62
|
-
const SelectComponent = ({ type, multiple, value: _value, maxSelectedOptions, loading, error, searchable: _searchable, bottomSheetHeight = 'full-screen', onChange: onChangeHandler, renderTrigger = SelectTriggerDefault, triggerProps = DEFAULT_TRIGGER_PROPS, renderMobileItem, renderDesktopItem, name, maxWidth, maxHeight = 460, useInitialValuesOnClearAction, renderAlertOnExitWithoutSaving, renderButtonsContainer, renderHeader, headerTitle: _headerTitle, clearButton, applyChangesButton, forceDropVisibleWithEmptyOptions, plain = false, widthEqualToActivator = true, renderContentBefore, onBlur, onFocus, onDropOpen, onDropClose, onBottomSheetClose, onBottomSheetOpen, onSearchSubmit, onApply, onClear, onSelectOption, pickerRef, dataProvider, emptyOptionsHint, emptyOptionsSearchHint, onOptionsChange, innerErrorTrls, optionDataQa, pickerDesktopType = 'drop', modalProps, dropWidth, applyOnClear = true, }, ref) => {
|
|
63
|
-
const { isMobile } = useBreakpoint();
|
|
64
|
-
const inputRef = useRef(null);
|
|
65
|
-
const [searchInputState, setSearchInputState] = useState(SEARCH_INPUT_STATE);
|
|
66
|
-
const [forcedState, setForcedState] = useState(null);
|
|
67
|
-
const dropRef = useRef(null);
|
|
68
|
-
const useDefaultTrigger = renderTrigger === SelectTriggerDefault;
|
|
69
|
-
const dropId = useId();
|
|
70
|
-
const bottomSheetId = useId();
|
|
71
|
-
const { activatorRef, optionsListRef, onOptionsListClose, toggleListVisibility, showOptions } = useSelectOptionsList(isMobile, pickerDesktopType);
|
|
72
|
-
const activatorRefCallback = useMultipleRefs(activatorRef, ref);
|
|
73
|
-
const prevVisibleRef = useRef(showOptions);
|
|
74
|
-
const hasChangesApplyButton = Boolean(applyChangesButton);
|
|
75
|
-
const { values, onChange, clearSelectedValues, setInitialValues, setSelectedValues, clearSelectedValuesByTrigger, setInitialValuesOnClosePicker, initialValuesOnOpening, } = useSelectState(!!multiple, _value || [], showOptions, hasChangesApplyButton, onChangeHandler, onSelectOption, applyOnClear);
|
|
76
|
-
const valuesArray = useMemo(
|
|
77
|
-
// eslint-disable-next-line no-nested-ternary
|
|
78
|
-
() => (Array.isArray(values) ? values : values ? [values] : []), [values]);
|
|
79
|
-
const { optionList, internalLoading, searchValue, setSearchValue, searchInProgress, reload, internalError } = useSelectSearch(showOptions, valuesArray, dataProvider, onOptionsChange);
|
|
80
|
-
const selectedLabels = useMemo(() =>
|
|
81
|
-
// eslint-disable-next-line no-nested-ternary
|
|
82
|
-
Array.isArray(_value)
|
|
83
|
-
? _value.map((item) => item.text ?? item.value)
|
|
84
|
-
: _value
|
|
85
|
-
? [_value?.text ?? _value.value]
|
|
86
|
-
: [], [_value]);
|
|
87
|
-
const optionsListRefCallback = useMultipleRefs(optionsListRef, dropRef, pickerRef);
|
|
88
|
-
const showedByFocus = useRef(false);
|
|
89
|
-
const focusedByPointer = useRef(false);
|
|
90
|
-
const isLimitExceeded = maxSelectedOptions !== undefined && Array.isArray(values) && values.length >= maxSelectedOptions;
|
|
91
|
-
// часть свойств тригера влияет на поведение дефолтного input search
|
|
92
|
-
const { size, label: triggerLabel, disabled, 'aria-label': triggerAriaLabel } = triggerProps;
|
|
93
|
-
const forceDisabled = useDisabled();
|
|
94
|
-
const isComponentDisabled = disabled || forceDisabled;
|
|
95
|
-
const sizeProp = size === 'large' ? { size: 'large' } : { size: 'medium' };
|
|
96
|
-
const inputWrapperStyles = { maxWidth: activatorRef.current?.offsetWidth };
|
|
97
|
-
const searchable = _searchable && (size === 'large' || size === 'medium');
|
|
98
|
-
const dataQa = triggerProps?.['data-qa'] || DEFAULT_DATA_QA;
|
|
99
|
-
// селект без поиска (переключаем фокус и отправляем blur)
|
|
100
|
-
useLayoutEffect(() => {
|
|
101
|
-
if (searchable && !isMobile) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (!showOptions && prevVisibleRef.current) {
|
|
105
|
-
setInitialValuesOnClosePicker();
|
|
106
|
-
if (forcedState === 'focus') {
|
|
107
|
-
focusedByPointer.current = false;
|
|
108
|
-
activatorRef.current?.focus();
|
|
109
|
-
setForcedState?.(null);
|
|
110
|
-
showedByFocus.current = false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!forcedState && !showOptions && prevVisibleRef.current) {
|
|
114
|
-
onBlur?.();
|
|
115
|
-
}
|
|
116
|
-
prevVisibleRef.current = showOptions;
|
|
117
|
-
}, [activatorRef, forcedState, isMobile, onBlur, searchable, setInitialValuesOnClosePicker, showOptions]);
|
|
118
|
-
// селект с поиском (нужно подменить контрол)
|
|
119
|
-
useLayoutEffect(() => {
|
|
120
|
-
if (!searchable || isMobile || pickerDesktopType === 'modal') {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (forcedState === 'focus' || forcedState === 'focusAndSelect') {
|
|
124
|
-
setSearchInputState({
|
|
125
|
-
useSearchInput: useDefaultTrigger,
|
|
126
|
-
emitEvents: true,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}, [forcedState, isMobile, searchable, useDefaultTrigger, pickerDesktopType]);
|
|
130
|
-
// триггер подменяться на input (тут пачка логики + blur)
|
|
131
|
-
useLayoutEffect(() => {
|
|
132
|
-
if (!searchInputState.emitEvents) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
// немного магипуляций, если тригер дефотный
|
|
136
|
-
if (searchInputState.useSearchInput) {
|
|
137
|
-
if (!inputRef.current) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (forcedState === 'focus') {
|
|
141
|
-
inputRef.current.focus();
|
|
142
|
-
}
|
|
143
|
-
// например во время выбора опции, нужно выбрать текст
|
|
144
|
-
if (forcedState === 'focusAndSelect') {
|
|
145
|
-
inputRef.current?.focus();
|
|
146
|
-
inputRef.current?.select();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (!showOptions && prevVisibleRef.current) {
|
|
150
|
-
setInitialValuesOnClosePicker();
|
|
151
|
-
}
|
|
152
|
-
if (!forcedState && !showOptions) {
|
|
153
|
-
setSearchInputState({
|
|
154
|
-
useSearchInput: false,
|
|
155
|
-
emitEvents: false,
|
|
156
|
-
});
|
|
157
|
-
if (prevVisibleRef.current) {
|
|
158
|
-
onBlur?.();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
prevVisibleRef.current = showOptions;
|
|
162
|
-
}, [forcedState, onBlur, setForcedState, searchInputState, showOptions, setInitialValuesOnClosePicker]);
|
|
163
|
-
// в onFocus нужно отличить клик от Tab
|
|
164
|
-
useEffect(() => {
|
|
165
|
-
const onPointerDown = () => {
|
|
166
|
-
focusedByPointer.current = true;
|
|
167
|
-
};
|
|
168
|
-
const onKeyDown = () => {
|
|
169
|
-
focusedByPointer.current = false;
|
|
170
|
-
};
|
|
171
|
-
document.addEventListener('pointerdown', onPointerDown, true);
|
|
172
|
-
document.addEventListener('keydown', onKeyDown, true);
|
|
173
|
-
return () => {
|
|
174
|
-
document.removeEventListener('pointerdown', onPointerDown, true);
|
|
175
|
-
document.removeEventListener('keydown', onKeyDown, true);
|
|
176
|
-
};
|
|
177
|
-
}, []);
|
|
178
|
-
useEffect(() => {
|
|
179
|
-
if (!optionsListRef.current || !showOptions) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
// на дестопе в поиском селекте оставим фокус на инпуте
|
|
183
|
-
if (!isMobile && searchable && pickerDesktopType === 'drop') {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
// ставим фокус на первый выбранный элемент или на первый элемент списка
|
|
187
|
-
const selectedOrFirstElement = optionsListRef.current.querySelector('[data-magritte-select-option][aria-selected="true"]') ??
|
|
188
|
-
optionsListRef.current.querySelector('[data-magritte-select-option]');
|
|
189
|
-
selectedOrFirstElement?.focus();
|
|
190
|
-
}, [showOptions, searchable, isMobile, optionsListRef, pickerDesktopType]);
|
|
191
|
-
const handleKeyDown = useCallback((event) => {
|
|
192
|
-
// не хотим скролить дроп при использовании пробела
|
|
193
|
-
if (!showOptions && !searchable && keyboardMatches(event.nativeEvent, [keyboardKeys.Space])) {
|
|
194
|
-
event.preventDefault();
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (showOptions && keyboardMatch(event.nativeEvent, keyboardKeys.Escape)) {
|
|
198
|
-
showedByFocus.current = false;
|
|
199
|
-
setForcedState('focus');
|
|
200
|
-
toggleListVisibility();
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
// движение по списку опций
|
|
204
|
-
if (showOptions && keyboardMatch(event.nativeEvent, keyboardKeys.ArrowUp)) {
|
|
205
|
-
focusOptionsList(event, dropRef?.current, 'up');
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
if (showOptions && keyboardMatch(event.nativeEvent, keyboardKeys.ArrowDown)) {
|
|
209
|
-
focusOptionsList(event, dropRef?.current, 'down');
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (showOptions && keyboardMatch(event.nativeEvent, keyboardKeys.Tab)) {
|
|
213
|
-
focusOptionsList(event, dropRef?.current, 'down');
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
// после закрытия пользователь решил что-то поделать опять
|
|
217
|
-
if (!showOptions &&
|
|
218
|
-
!keyboardMatches(event.nativeEvent, [keyboardKeys.Tab, keyboardKeys.Escape, keyboardKeys.Space])) {
|
|
219
|
-
toggleListVisibility();
|
|
220
|
-
}
|
|
221
|
-
}, [showOptions, toggleListVisibility, searchable]);
|
|
222
|
-
const clearSelectedValuesOrUseInitialValues = () => {
|
|
223
|
-
if (useInitialValuesOnClearAction) {
|
|
224
|
-
setInitialValues();
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
clearSelectedValues();
|
|
228
|
-
}
|
|
229
|
-
if (applyOnClear) {
|
|
230
|
-
onOptionsListClose();
|
|
231
|
-
}
|
|
232
|
-
onClear?.();
|
|
233
|
-
};
|
|
234
|
-
return (jsxs(Fragment, { children: [!searchInputState.useSearchInput &&
|
|
235
|
-
renderTrigger({
|
|
236
|
-
values: selectedLabels,
|
|
237
|
-
expanded: showOptions,
|
|
238
|
-
toggleExpanded: toggleListVisibility,
|
|
239
|
-
onChange: () => {
|
|
240
|
-
if (isComponentDisabled) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
// открываем по фокусу, закрываем по клику
|
|
244
|
-
// повторно открываем по клику (события фокуса уже не будет)
|
|
245
|
-
if (showedByFocus.current) {
|
|
246
|
-
showedByFocus.current = false;
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
toggleListVisibility();
|
|
250
|
-
},
|
|
251
|
-
onClear: () => clearSelectedValuesByTrigger(),
|
|
252
|
-
ref: activatorRefCallback,
|
|
253
|
-
onKeyDown: handleKeyDown,
|
|
254
|
-
onBlur: () => {
|
|
255
|
-
setForcedState(null);
|
|
256
|
-
if (showOptions && optionList.length === 0 && !emptyOptionsHint) {
|
|
257
|
-
toggleListVisibility();
|
|
258
|
-
}
|
|
259
|
-
if (!showOptions && forcedState === null) {
|
|
260
|
-
onBlur?.();
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
onFocus: () => {
|
|
264
|
-
if (isComponentDisabled || showOptions) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
if (forcedState !== 'focus' && forcedState !== 'focusAndSelect') {
|
|
268
|
-
onFocus?.();
|
|
269
|
-
setForcedState('focus');
|
|
270
|
-
}
|
|
271
|
-
// при клике раскрыть select надо сразу (+ из-за подмены onChange не вызоветься)
|
|
272
|
-
if (_searchable && focusedByPointer.current) {
|
|
273
|
-
showedByFocus.current = true;
|
|
274
|
-
toggleListVisibility();
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
'data-qa': dataQa,
|
|
278
|
-
setSearchValue,
|
|
279
|
-
optionsCount: optionList.length,
|
|
280
|
-
'aria-label': triggerAriaLabel,
|
|
281
|
-
...triggerProps,
|
|
282
|
-
role: 'combobox',
|
|
283
|
-
'aria-haspopup': isMobile ? 'dialog' : getDropRole(clearButton, applyChangesButton, multiple),
|
|
284
|
-
'aria-controls': isMobile ? bottomSheetId : dropId,
|
|
285
|
-
disabled: isComponentDisabled,
|
|
286
|
-
}), searchInputState.useSearchInput && (jsx("div", { style: inputWrapperStyles, children: jsx(BaseInput, { ...sizeProp, ref: inputRef, wrapperRef: activatorRefCallback, value: searchValue, onChange: setSearchValue, onKeyDown: handleKeyDown, onFocus: () => {
|
|
287
|
-
setForcedState('focus');
|
|
288
|
-
}, onBlur: () => {
|
|
289
|
-
setForcedState(null);
|
|
290
|
-
if (showOptions && optionList.length === 0 && !emptyOptionsHint) {
|
|
291
|
-
toggleListVisibility();
|
|
292
|
-
}
|
|
293
|
-
}, "data-qa": "magritte-select-activator-input", placeholder: selectedLabels.length > 0 ? selectedLabels.join(', ') : triggerLabel, autoComplete: "off", "aria-expanded": showOptions, role: "combobox", "aria-label": triggerAriaLabel, "aria-autocomplete": "list", "aria-controls": isMobile ? bottomSheetId : dropId }) })), isMobile && (jsx(SelectBottomSheet, { id: bottomSheetId, applyChangesButton: applyChangesButton, clearButton: clearButton, clearSelectedValuesOrUseInitialValues: clearSelectedValuesOrUseInitialValues, error: error, height: searchable || Boolean(error) || loading ? 'full-screen' : bottomSheetHeight, visible: Boolean(showOptions || internalLoading), value: values, isLimitExceeded: isLimitExceeded, name: name, multiple: multiple, type: type, loading: loading || internalLoading, searchable: _searchable, useInitialValuesOnClearAction: useInitialValuesOnClearAction, initialValuesOnOpening: initialValuesOnOpening, renderItem: renderMobileItem, renderAlertOnExitWithoutSaving: renderAlertOnExitWithoutSaving, renderButtonsContainer: renderButtonsContainer, renderHeader: renderHeader, headerTitle: _headerTitle || triggerLabel, optionList: optionList, optionsListRef: optionsListRefCallback, onChange: onChange, onClose: onOptionsListClose, searchValue: searchValue, setSearchValue: setSearchValue, setSelectedValues: setSelectedValues, onBottomSheetClose: onBottomSheetClose, onBottomSheetOpen: onBottomSheetOpen, onSearchSubmit: onSearchSubmit, onApply: onApply, onClear: onClear, emptyOptionsHint: emptyOptionsHint, emptyOptionsSearchHint: emptyOptionsSearchHint, searchInProgress: searchInProgress, internalError: internalError, reload: reload, innerErrorTrls: innerErrorTrls, optionDataQa: optionDataQa, hasChangesApplyButton: hasChangesApplyButton })), !isMobile && (jsxs(Fragment, { children: [pickerDesktopType === 'drop' && (jsx(SelectDrop, { id: dropId, activatorRef: activatorRef, applyChangesButton: applyChangesButton, clearButton: clearButton, clearSelectedValuesOrUseInitialValues: clearSelectedValuesOrUseInitialValues, isLimitExceeded: isLimitExceeded, name: name, multiple: multiple, maxWidth: maxWidth, type: type, loading: loading || internalLoading, useInitialValuesOnClearAction: useInitialValuesOnClearAction, onClose: onOptionsListClose, renderItem: renderDesktopItem, renderButtonsContainer: renderButtonsContainer, plain: plain, optionList: optionList, optionsListRef: optionsListRefCallback, value: values, onChange: onChange, searchValue: searchValue, searchable: searchable, forceDropVisibleWithEmptyOptions: forceDropVisibleWithEmptyOptions || internalLoading, setSearchValue: setSearchValue, visible: !error && (showOptions || internalLoading), widthEqualToActivator: widthEqualToActivator, renderContentBefore: renderContentBefore, setForcedState: setForcedState, setSelectedValues: setSelectedValues, maxHeight: maxHeight, onDropOpen: onDropOpen, onDropClose: onDropClose, onApply: onApply, onClear: onClear, emptyOptionsHint: emptyOptionsHint, emptyOptionsSearchHint: emptyOptionsSearchHint, searchInProgress: searchInProgress, internalError: internalError, reload: reload, innerErrorTrls: innerErrorTrls, optionDataQa: optionDataQa, dropWidth: dropWidth, hasChangesApplyButton: hasChangesApplyButton })), pickerDesktopType === 'modal' && (jsx(SelectModal, { ...modalProps, applyChangesButton: applyChangesButton, clearButton: clearButton, clearSelectedValuesOrUseInitialValues: clearSelectedValuesOrUseInitialValues, isLimitExceeded: isLimitExceeded, name: name, multiple: multiple, type: type, loading: loading || internalLoading, useInitialValuesOnClearAction: useInitialValuesOnClearAction, onClose: onOptionsListClose, renderItem: renderDesktopItem, renderButtonsContainer: renderButtonsContainer, plain: plain, optionList: optionList, optionsListRef: optionsListRefCallback, value: values, onChange: onChange, searchValue: searchValue, searchable: searchable, setSearchValue: setSearchValue, visible: Boolean(showOptions || internalLoading), setForcedState: setForcedState, setSelectedValues: setSelectedValues, onApply: onApply, onClear: onClear, emptyOptionsHint: emptyOptionsHint, emptyOptionsSearchHint: emptyOptionsSearchHint, searchInProgress: searchInProgress, internalError: internalError, reload: reload, innerErrorTrls: innerErrorTrls, optionDataQa: optionDataQa, renderAlertOnExitWithoutSaving: renderAlertOnExitWithoutSaving, initialValuesOnOpening: initialValuesOnOpening, hasChangesApplyButton: hasChangesApplyButton }))] }))] }));
|
|
68
|
+
const SelectRoot = ({ children, dataProvider, maxSelectedOptions, multiple, name, loading, onBlur: onBlurExternal, onChange: onChangeExternal, onFocus: onFocusExternal, onOptionsChange: onOptionsChangeExternal, options, value, error, providerError, emptyHint, emptySearchHint, }) => {
|
|
69
|
+
const onBlur = useEventCallback(onBlurExternal);
|
|
70
|
+
const onFocus = useEventCallback(onFocusExternal);
|
|
71
|
+
const onChange = useEventCallback(onChangeExternal);
|
|
72
|
+
const onOptionsChange = useEventCallback(onOptionsChangeExternal);
|
|
73
|
+
const [showOptions, setShowOptions] = useState(false);
|
|
74
|
+
const [searchValue, setSearchValue] = useState('');
|
|
75
|
+
return (jsx(SelectElementsSlotRegistryProvider, { children: jsx(ConfigProvider, { maxSelectedOptions: maxSelectedOptions, multiple: multiple, name: name, loading: loading, error: error || undefined, providerError: providerError || undefined, emptyHint: emptyHint, emptySearchHint: emptySearchHint, children: jsx(VisibilityProvider, { showOptions: showOptions, setShowOptions: setShowOptions, children: jsx(SelectStateProvider, { onChange: onChange, value: value, children: jsx(SearchStateProvider, { searchValue: searchValue, setSearchValue: setSearchValue, children: jsx(SelectDataProvider, { dataProvider: dataProvider, options: options, onOptionsChange: onOptionsChange, children: jsx(FocusOrchestratorProvider, { children: jsx(NavigationManagement, { onBlur: onBlur, onFocus: onFocus, children: children }) }) }) }) }) }) }) }));
|
|
294
76
|
};
|
|
295
|
-
const Select =
|
|
296
|
-
Select.
|
|
77
|
+
const Select = SelectRoot;
|
|
78
|
+
Select.ApplyChangesButton = ApplyChangesButton;
|
|
79
|
+
Select.BottomSheet = SelectBottomSheet;
|
|
80
|
+
Select.PickerCloseIcon = SelectPickerCloseIcon;
|
|
81
|
+
Select.BottomSheetHeader = SelectBottomSheetHeader;
|
|
82
|
+
Select.ClearButton = ClearButton;
|
|
83
|
+
Select.ClearCard = ClearCard;
|
|
84
|
+
Select.Drop = SelectDrop;
|
|
85
|
+
Select.EmptyHint = SelectEmptyHint;
|
|
86
|
+
Select.Trigger = SelectTrigger;
|
|
87
|
+
Select.PickerProvider = SelectPickerProvider;
|
|
88
|
+
Select.SearchTrigger = SelectSearchTrigger;
|
|
89
|
+
Select.SearchInput = SelectSearchInput;
|
|
90
|
+
Select.Options = SelectOptions;
|
|
297
91
|
|
|
298
92
|
export { Select };
|
|
299
93
|
//# sourceMappingURL=Select.js.map
|