@geotab/zenith 1.26.4 → 1.26.5-beta.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/README.md +6 -0
- package/dist/absolute/absolute.js +2 -2
- package/dist/chip/chip.d.ts +35 -0
- package/dist/chip/chip.js +105 -0
- package/dist/chip/chipStatusProvider.d.ts +9 -0
- package/dist/chip/chipStatusProvider.js +13 -0
- package/dist/chip/utils/getChipStateClassName.d.ts +2 -0
- package/dist/chip/utils/getChipStateClassName.js +32 -0
- package/dist/chip/utils/useChip.d.ts +10 -0
- package/dist/chip/utils/useChip.js +24 -0
- package/dist/commonHelpers/hooks/useDebouncedMemo.d.ts +2 -0
- package/dist/commonHelpers/hooks/useDebouncedMemo.js +26 -0
- package/dist/commonStyles/shadows/shadows.less +4 -0
- package/dist/dateRange/dateRange.d.ts +2 -1
- package/dist/dateRange/dateRange.js +6 -2
- package/dist/dropdown/dropdown.d.ts +18 -3
- package/dist/dropdown/dropdown.js +63 -31
- package/dist/dropdown/dropdownHelper.d.ts +1 -1
- package/dist/dropdown/dropdownHelper.js +7 -3
- package/dist/dropdown/dropdownList.d.ts +1 -0
- package/dist/dropdown/dropdownList.js +2 -2
- package/dist/dropdown/dropdownPopup.d.ts +1 -0
- package/dist/dropdown/dropdownPopup.js +2 -2
- package/dist/dropdown/stateReducer/stateAction.d.ts +9 -1
- package/dist/dropdown/stateReducer/stateActionType.d.ts +1 -0
- package/dist/dropdown/stateReducer/stateActionType.js +1 -0
- package/dist/dropdown/stateReducer/stateReducer.js +35 -0
- package/dist/dropdown/useDropdownState.d.ts +7 -0
- package/dist/dropdown/useDropdownState.js +10 -0
- package/dist/filters/components/filtersChip.d.ts +9 -0
- package/dist/filters/components/filtersChip.js +28 -0
- package/dist/filters/components/filtersContainer.d.ts +12 -0
- package/dist/filters/components/filtersContainer.js +77 -0
- package/dist/filters/components/filtersCustom.d.ts +13 -0
- package/dist/filters/components/filtersCustom.js +15 -0
- package/dist/filters/components/filtersDateRange.d.ts +33 -0
- package/dist/filters/components/filtersDateRange.js +27 -0
- package/dist/filters/components/filtersDropdown.d.ts +32 -0
- package/dist/filters/components/filtersDropdown.js +42 -0
- package/dist/filters/components/filtersGroups.d.ts +14 -0
- package/dist/filters/components/filtersGroups.js +28 -0
- package/dist/filters/components/filtersItem.d.ts +25 -0
- package/dist/filters/components/filtersItem.js +23 -0
- package/dist/filters/components/filtersModal.d.ts +17 -0
- package/dist/filters/components/filtersModal.js +107 -0
- package/dist/filters/components/filtersModalItem.d.ts +9 -0
- package/dist/filters/components/filtersModalItem.js +74 -0
- package/dist/filters/components/filtersRange.d.ts +11 -0
- package/dist/filters/components/filtersRange.js +27 -0
- package/dist/filters/components/filtersSaveModal.d.ts +7 -0
- package/dist/filters/components/filtersSaveModal.js +53 -0
- package/dist/filters/components/filtersSavedChipComponent.d.ts +2 -0
- package/dist/filters/components/filtersSavedChipComponent.js +66 -0
- package/dist/filters/components/filtersSavedItemsProvider.d.ts +19 -0
- package/dist/filters/components/filtersSavedItemsProvider.js +13 -0
- package/dist/filters/components/filtersSearch.d.ts +16 -0
- package/dist/filters/components/filtersSearch.js +64 -0
- package/dist/filters/components/filtersSearchItemData.d.ts +16 -0
- package/dist/filters/components/filtersSearchItemData.js +42 -0
- package/dist/filters/components/filtersSearchList.d.ts +30 -0
- package/dist/filters/components/filtersSearchList.js +75 -0
- package/dist/filters/components/filtersSelect.d.ts +30 -0
- package/dist/filters/components/filtersSelect.js +51 -0
- package/dist/filters/components/filtersSelectListItem.d.ts +15 -0
- package/dist/filters/components/filtersSelectListItem.js +14 -0
- package/dist/filters/filters.d.ts +99 -0
- package/dist/filters/filters.js +246 -0
- package/dist/filters/filtersHelper.d.ts +40 -0
- package/dist/filters/filtersHelper.js +226 -0
- package/dist/filters/filtersHooks.d.ts +19 -0
- package/dist/filters/filtersHooks.js +25 -0
- package/dist/filtersBar/components/filtersBarDropdownWithCheckbox/filtersBarDropdownWithCheckbox.d.ts +5 -3
- package/dist/groupsFilter/groupsFilter.d.ts +10 -1
- package/dist/groupsFilter/groupsFilter.js +40 -11
- package/dist/header/components/collapsedItemsControl/collapsedItemsControl.js +7 -4
- package/dist/header/headerMenu.d.ts +1 -0
- package/dist/header/headerMenu.js +11 -4
- package/dist/index.css +3452 -2648
- package/dist/index.d.ts +18 -3
- package/dist/index.js +55 -15
- package/dist/layout/layout.js +5 -0
- package/dist/list/list.d.ts +1 -1
- package/dist/list/list.js +3 -2
- package/dist/modal/modal.d.ts +11 -1
- package/dist/modal/modal.js +8 -5
- package/dist/nav/nav.d.ts +1 -0
- package/dist/nav/nav.js +21 -7
- package/dist/nav/navHeader/navHeader.js +1 -1
- package/dist/nav/navItem/navItem.d.ts +4 -2
- package/dist/nav/navItem/navItem.js +25 -10
- package/dist/nav/navMobileBar/navMobileBar.d.ts +11 -0
- package/dist/nav/navMobileBar/navMobileBar.js +33 -0
- package/dist/nav/navSection/navSection.js +52 -1
- package/dist/nav/storyHelpers/storyDecorator.js +2 -1
- package/dist/nav/utils/navUtils.d.ts +6 -1
- package/dist/nav/utils/navUtils.js +48 -1
- package/dist/pageHeader/pageHeader.d.ts +16 -0
- package/dist/pageHeader/pageHeader.js +21 -0
- package/dist/pageHeader/pageHeaderActions.d.ts +10 -0
- package/dist/pageHeader/pageHeaderActions.js +35 -0
- package/dist/pageHeader/pageHeaderButton.d.ts +16 -0
- package/dist/pageHeader/pageHeaderButton.js +26 -0
- package/dist/pageHeader/pageHeaderFilters.d.ts +13 -0
- package/dist/pageHeader/pageHeaderFilters.js +7 -0
- package/dist/pageHeader/pageHeaderHelpers.d.ts +4 -0
- package/dist/pageHeader/pageHeaderHelpers.js +62 -0
- package/dist/pageHeader/pageHeaderMenu.d.ts +9 -0
- package/dist/pageHeader/pageHeaderMenu.js +9 -0
- package/dist/pillBox/components/pillBoxItem.js +1 -1
- package/dist/pillBox/pillBox.d.ts +1 -0
- package/dist/pillBox/pillBox.js +2 -2
- package/dist/range/range.d.ts +2 -1
- package/dist/range/range.js +11 -2
- package/dist/tabs/tabs.d.ts +1 -2
- package/dist/utils/localization/translations/en-json.d.ts +18 -0
- package/dist/utils/localization/translations/en-json.js +19 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -40,6 +40,12 @@ Zenith library provides components defined in Zenith Design System. It includes
|
|
|
40
40
|
|
|
41
41
|
## Change log
|
|
42
42
|
|
|
43
|
+
### 1.26.5
|
|
44
|
+
|
|
45
|
+
* Fix min width of side panel on mobile
|
|
46
|
+
* Fix updating title of pills in `PillBox`
|
|
47
|
+
* Fix top border appearance of columns dropdown in `Table`
|
|
48
|
+
|
|
43
49
|
### 1.26.4
|
|
44
50
|
|
|
45
51
|
* Improve accessibility of `Chart`
|
|
@@ -25,7 +25,7 @@ const Absolute = ({ isOpen, id, paddingX, paddingY, className, children, trigger
|
|
|
25
25
|
var _a;
|
|
26
26
|
prevScroll.current = (_a = e.target) === null || _a === void 0 ? void 0 : _a.scrollTop;
|
|
27
27
|
};
|
|
28
|
-
const
|
|
28
|
+
const accessibleAttr = (0, react_1.useMemo)(() => {
|
|
29
29
|
if (!role) {
|
|
30
30
|
return {};
|
|
31
31
|
}
|
|
@@ -34,7 +34,7 @@ const Absolute = ({ isOpen, id, paddingX, paddingY, className, children, trigger
|
|
|
34
34
|
const darkClassName = dark ? "zen-dark" : "";
|
|
35
35
|
const renderPopup = () => {
|
|
36
36
|
if (isOpen) {
|
|
37
|
-
const result = (0, jsx_runtime_1.jsx)("div", Object.assign({},
|
|
37
|
+
const result = (0, jsx_runtime_1.jsx)("div", Object.assign({}, accessibleAttr, { ref: popupRef, id: id, onScroll: shouldHoldScroll ? onScrollHandler : undefined, className: (0, classNames_1.classNames)(["zen-absolute", darkClassName, className || ""]), children: children }));
|
|
38
38
|
if (inline) {
|
|
39
39
|
return result;
|
|
40
40
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import "./chip.less";
|
|
3
|
+
import { IZenComponentProps } from "./../commonHelpers/zenComponent";
|
|
4
|
+
import { IIcon } from "../icons/icon";
|
|
5
|
+
export interface IChipsParent {
|
|
6
|
+
chip?: boolean;
|
|
7
|
+
chipId?: string;
|
|
8
|
+
chipIcon?: React.FC<IIcon>;
|
|
9
|
+
chipName?: string;
|
|
10
|
+
}
|
|
11
|
+
export type TChipStatus = "default" | "success" | "active" | "accent";
|
|
12
|
+
interface IChipBase extends IZenComponentProps {
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
icon?: React.FC<IIcon>;
|
|
15
|
+
id?: string;
|
|
16
|
+
status?: TChipStatus;
|
|
17
|
+
quantity?: undefined;
|
|
18
|
+
title?: string;
|
|
19
|
+
onClose?: (id: string) => void;
|
|
20
|
+
}
|
|
21
|
+
export interface IChip extends IChipBase {
|
|
22
|
+
readonly?: boolean;
|
|
23
|
+
onChange: (v: boolean) => void;
|
|
24
|
+
active: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface IChipTrigger extends Omit<IChipBase, "quantity"> {
|
|
27
|
+
triggerRef: React.Ref<HTMLElement>;
|
|
28
|
+
closeAriaText?: string;
|
|
29
|
+
isOpen: boolean;
|
|
30
|
+
quantity?: number;
|
|
31
|
+
onClick: (isOpen: boolean) => void;
|
|
32
|
+
}
|
|
33
|
+
type ChipProps = IChip | IChipTrigger;
|
|
34
|
+
export declare const Chip: (props: ChipProps) => React.ReactElement;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Chip = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const useDrive_1 = require("../utils/theme/useDrive");
|
|
7
|
+
const useDriveClassName_1 = require("../utils/theme/useDriveClassName");
|
|
8
|
+
const classNames_1 = require("../commonHelpers/classNames/classNames");
|
|
9
|
+
const getChipStateClassName_1 = require("./utils/getChipStateClassName");
|
|
10
|
+
const iconClose_1 = require("../icons/iconClose");
|
|
11
|
+
const useLanguage_1 = require("../utils/localization/useLanguage");
|
|
12
|
+
const useChip_1 = require("./utils/useChip");
|
|
13
|
+
function isChipTrigger(props) {
|
|
14
|
+
return "triggerRef" in props;
|
|
15
|
+
}
|
|
16
|
+
const Chip = (props) => {
|
|
17
|
+
const { className, children, disabled, icon, id, status, quantity, onClose, title } = props;
|
|
18
|
+
const isTriggerMode = isChipTrigger(props);
|
|
19
|
+
const readonly = !isTriggerMode ? props.readonly : undefined;
|
|
20
|
+
const onChange = !isTriggerMode ? props.onChange : undefined;
|
|
21
|
+
const active = !isTriggerMode ? props.active : false;
|
|
22
|
+
const triggerRef = isTriggerMode ? props.triggerRef : undefined;
|
|
23
|
+
const closeAriaText = isTriggerMode ? props.closeAriaText : undefined;
|
|
24
|
+
const isOpen = isTriggerMode ? props.isOpen : false;
|
|
25
|
+
const onClick = isTriggerMode ? props.onClick : undefined;
|
|
26
|
+
const hasQuantity = typeof quantity === "number";
|
|
27
|
+
const chipId = (0, react_1.useId)();
|
|
28
|
+
const isDrive = (0, useDrive_1.useDrive)();
|
|
29
|
+
const { translate } = (0, useLanguage_1.useLanguage)();
|
|
30
|
+
const driveTextClass = (0, useDriveClassName_1.useDriveClassName)("zen-chip-text-content");
|
|
31
|
+
const driveChipClass = (0, useDriveClassName_1.useDriveClassName)("zen-chip");
|
|
32
|
+
const hasIcon = !!icon;
|
|
33
|
+
const isClosable = !!onClose;
|
|
34
|
+
const hasContent = !!children;
|
|
35
|
+
const { ref, title: chipTitle } = (0, useChip_1.useChip)(title, isTriggerMode ? { triggerRef: triggerRef, children } : undefined);
|
|
36
|
+
const svgIcon = (0, react_1.useMemo)(() => hasIcon ? (0, react_1.createElement)(icon, {
|
|
37
|
+
className: "zen-chip__icon",
|
|
38
|
+
size: isDrive ? "huger" : "large"
|
|
39
|
+
}) : null, [hasIcon, icon, isDrive]);
|
|
40
|
+
const onChangeHandler = (0, react_1.useCallback)((e) => {
|
|
41
|
+
if (readonly || !onChange) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
onChange(e.target.checked);
|
|
45
|
+
}, [onChange, readonly]);
|
|
46
|
+
const handleClick = (0, react_1.useCallback)(() => {
|
|
47
|
+
if (onClick) {
|
|
48
|
+
onClick(!isOpen);
|
|
49
|
+
}
|
|
50
|
+
}, [onClick, isOpen]);
|
|
51
|
+
const onKeyDownHandler = (0, react_1.useCallback)((e) => {
|
|
52
|
+
if (e.key === "Enter" && !disabled && !readonly && onChange) {
|
|
53
|
+
onChange(!active);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (e.key === " " && !disabled && !readonly && onChange) {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
onChange(!active);
|
|
59
|
+
}
|
|
60
|
+
}, [disabled, readonly, active, onChange]);
|
|
61
|
+
const chipTriggerKeyDownHandler = (0, react_1.useCallback)((e) => {
|
|
62
|
+
var _a;
|
|
63
|
+
if ((_a = document.activeElement) === null || _a === void 0 ? void 0 : _a.classList.contains("zen-chip__close-button")) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (e.key === "Enter" && !disabled && !readonly) {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
handleClick();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (e.key === " " && !disabled && !readonly) {
|
|
72
|
+
handleClick();
|
|
73
|
+
}
|
|
74
|
+
}, [disabled, readonly, handleClick]);
|
|
75
|
+
const onKeyUpHandler = (0, react_1.useCallback)((e) => {
|
|
76
|
+
var _a;
|
|
77
|
+
if (e.key === "Tab" || e.key === "Enter" || e.key === " ") {
|
|
78
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.classList.add("zen-chip--keyboard-nav");
|
|
79
|
+
}
|
|
80
|
+
}, [ref]);
|
|
81
|
+
const onBlurHandler = (0, react_1.useCallback)(() => {
|
|
82
|
+
var _a;
|
|
83
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.classList.remove("zen-chip--keyboard-nav");
|
|
84
|
+
}, [ref]);
|
|
85
|
+
const handleClose = (0, react_1.useCallback)((e) => {
|
|
86
|
+
e.stopPropagation();
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
isClosable && onClose(id || chipId);
|
|
89
|
+
}, [isClosable, onClose, id, chipId]);
|
|
90
|
+
const memoizedClasses = (0, react_1.useMemo)(() => [
|
|
91
|
+
"zen-chip",
|
|
92
|
+
driveChipClass !== null && driveChipClass !== void 0 ? driveChipClass : "",
|
|
93
|
+
isTriggerMode ? (0, getChipStateClassName_1.getChipTriggerStateClassName)(!!disabled, isOpen, status) : (0, getChipStateClassName_1.getChipStateClassName)(!!disabled, !!readonly, active, status),
|
|
94
|
+
className !== null && className !== void 0 ? className : ""
|
|
95
|
+
], [driveChipClass, isTriggerMode, disabled, isOpen, status, readonly, active, className]);
|
|
96
|
+
const chipComponent = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsxs)("label", { className: (0, classNames_1.classNames)(memoizedClasses), ref: ref, title: chipTitle, htmlFor: id || chipId, children: [(0, jsx_runtime_1.jsx)("input", { checked: active, onBlur: onBlurHandler, onKeyUp: onKeyUpHandler, onKeyDown: onKeyDownHandler, onChange: onChangeHandler, id: id || chipId, className: "zen-chip__input", type: "checkbox", disabled: disabled, readOnly: readonly }), children ? (0, jsx_runtime_1.jsx)("div", { className: (0, classNames_1.classNames)(["zen-chip-text-content", driveTextClass !== null && driveTextClass !== void 0 ? driveTextClass : ""]), children: children }) : null, svgIcon, isClosable && (0, jsx_runtime_1.jsx)("button", { type: "button", className: "zen-chip__close-button", onClick: handleClose, title: closeAriaText || translate("Close"), "aria-label": closeAriaText || translate("Close"), children: (0, jsx_runtime_1.jsx)(iconClose_1.IconClose, { size: isDrive ? "huger" : "large", className: "zen-pill-non-actionable__close-icon" }) })] }), [memoizedClasses, ref, chipTitle, id, chipId, active, onBlurHandler, onKeyUpHandler, onKeyDownHandler, onChangeHandler, disabled, readonly, children, driveTextClass, svgIcon, isClosable,
|
|
97
|
+
handleClose, closeAriaText, translate, isDrive]);
|
|
98
|
+
const chipTriggerComponent = (0, react_1.useMemo)(() => {
|
|
99
|
+
const extraAttributes = chipTitle ? { "aria-label": chipTitle } : {};
|
|
100
|
+
return (0, jsx_runtime_1.jsx)("div", Object.assign({ role: "button", tabIndex: 0 }, extraAttributes, { onClick: handleClick, onKeyDown: chipTriggerKeyDownHandler, className: (0, classNames_1.classNames)(memoizedClasses), "data-id": id || chipId, ref: triggerRef, children: (0, jsx_runtime_1.jsxs)("div", { className: "zen-chip__content-wrapper", children: [hasContent ? (0, jsx_runtime_1.jsx)("div", { className: (0, classNames_1.classNames)(["zen-chip-text-content", driveTextClass !== null && driveTextClass !== void 0 ? driveTextClass : ""]), children: children }) : null, svgIcon, isClosable && (0, jsx_runtime_1.jsx)("button", { type: "button", className: "zen-chip__close-button", onClick: handleClose, title: closeAriaText || translate("Close"), "aria-label": closeAriaText || translate("Close"), children: (0, jsx_runtime_1.jsx)(iconClose_1.IconClose, { size: isDrive ? "huger" : "large", className: "zen-pill-non-actionable__close-icon" }) }), hasQuantity && quantity ? (0, jsx_runtime_1.jsx)("div", { className: "zen-chip__quantity", children: quantity }) : null] }) }));
|
|
101
|
+
}, [handleClick, chipTriggerKeyDownHandler, memoizedClasses, id, chipId, triggerRef, hasContent, chipTitle, driveTextClass, children, svgIcon, isClosable, handleClose,
|
|
102
|
+
closeAriaText, translate, isDrive, hasQuantity, quantity]);
|
|
103
|
+
return isTriggerMode ? chipTriggerComponent : chipComponent;
|
|
104
|
+
};
|
|
105
|
+
exports.Chip = Chip;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from "react";
|
|
2
|
+
import { TChipStatus } from "./chip";
|
|
3
|
+
export declare const chipStatusContext: import("react").Context<TChipStatus | undefined>;
|
|
4
|
+
interface IChipStatusProviderProps extends PropsWithChildren {
|
|
5
|
+
status?: TChipStatus;
|
|
6
|
+
}
|
|
7
|
+
export declare const ChipStatusProvider: FC<IChipStatusProviderProps>;
|
|
8
|
+
export declare const useChipStatus: () => TChipStatus | undefined;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useChipStatus = exports.ChipStatusProvider = exports.chipStatusContext = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
exports.chipStatusContext = (0, react_1.createContext)(undefined);
|
|
7
|
+
const ChipStatusProvider = ({ status, children }) => ((0, jsx_runtime_1.jsx)(exports.chipStatusContext.Provider, { value: status, children: children }));
|
|
8
|
+
exports.ChipStatusProvider = ChipStatusProvider;
|
|
9
|
+
const useChipStatus = () => {
|
|
10
|
+
const status = (0, react_1.useContext)(exports.chipStatusContext);
|
|
11
|
+
return status;
|
|
12
|
+
};
|
|
13
|
+
exports.useChipStatus = useChipStatus;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const getChipStateClassName: (disabled?: boolean, readonly?: boolean, active?: boolean, status?: "default" | "success" | "active" | "accent") => string;
|
|
2
|
+
export declare const getChipTriggerStateClassName: (disabled?: boolean, isOpen?: boolean, status?: "default" | "success" | "active" | "accent") => string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChipTriggerStateClassName = exports.getChipStateClassName = void 0;
|
|
4
|
+
const getChipStateClassName = (disabled = false, readonly = false, active = false, status) => {
|
|
5
|
+
if (status && !disabled) {
|
|
6
|
+
return `zen-chip--${status}`;
|
|
7
|
+
}
|
|
8
|
+
if (disabled) {
|
|
9
|
+
return "zen-chip--disabled";
|
|
10
|
+
}
|
|
11
|
+
if (readonly) {
|
|
12
|
+
return "zen-chip--readonly";
|
|
13
|
+
}
|
|
14
|
+
if (active) {
|
|
15
|
+
return "zen-chip--active";
|
|
16
|
+
}
|
|
17
|
+
return "zen-chip--default";
|
|
18
|
+
};
|
|
19
|
+
exports.getChipStateClassName = getChipStateClassName;
|
|
20
|
+
const getChipTriggerStateClassName = (disabled = false, isOpen = false, status) => {
|
|
21
|
+
if (status && !disabled) {
|
|
22
|
+
return `zen-chip--${status}`;
|
|
23
|
+
}
|
|
24
|
+
if (disabled) {
|
|
25
|
+
return "zen-chip--disabled";
|
|
26
|
+
}
|
|
27
|
+
if (isOpen) {
|
|
28
|
+
return "zen-chip--active";
|
|
29
|
+
}
|
|
30
|
+
return "zen-chip--default";
|
|
31
|
+
};
|
|
32
|
+
exports.getChipTriggerStateClassName = getChipTriggerStateClassName;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface ITriggerModeProps {
|
|
3
|
+
triggerRef: React.Ref<HTMLElement>;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const useChip: (initialTitle?: string, triggerModeProps?: ITriggerModeProps) => {
|
|
7
|
+
ref: import("react").RefObject<HTMLElement>;
|
|
8
|
+
title: string;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useChip = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useChip = (initialTitle, triggerModeProps) => {
|
|
6
|
+
const ref = (0, react_1.useRef)(null);
|
|
7
|
+
const [title, setTitle] = (0, react_1.useState)(initialTitle || "");
|
|
8
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
9
|
+
if (initialTitle) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (triggerModeProps === undefined && ref.current) {
|
|
13
|
+
setTitle(ref.current.textContent || "");
|
|
14
|
+
}
|
|
15
|
+
if (triggerModeProps !== undefined && triggerModeProps.triggerRef) {
|
|
16
|
+
const { triggerRef } = triggerModeProps;
|
|
17
|
+
if ("current" in triggerRef && triggerRef.current instanceof HTMLElement) {
|
|
18
|
+
setTitle(triggerRef.current.textContent || "");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}, [ref, initialTitle, triggerModeProps]);
|
|
22
|
+
return { ref, title };
|
|
23
|
+
};
|
|
24
|
+
exports.useChip = useChip;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebouncedMemo = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
function useDebouncedMemo(factory, deps, delay) {
|
|
6
|
+
const [state, setState] = (0, react_1.useState)(() => factory());
|
|
7
|
+
const mountedRef = (0, react_1.useRef)(false);
|
|
8
|
+
const timeoutRef = (0, react_1.useRef)(undefined);
|
|
9
|
+
(0, react_1.useEffect)(() => {
|
|
10
|
+
if (mountedRef.current) {
|
|
11
|
+
clearTimeout(timeoutRef.current);
|
|
12
|
+
timeoutRef.current = setTimeout(() => {
|
|
13
|
+
setState(factory());
|
|
14
|
+
}, delay);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
mountedRef.current = true;
|
|
18
|
+
}
|
|
19
|
+
return () => {
|
|
20
|
+
clearTimeout(timeoutRef.current);
|
|
21
|
+
};
|
|
22
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
23
|
+
}, [delay, factory, ...deps]);
|
|
24
|
+
return state;
|
|
25
|
+
}
|
|
26
|
+
exports.useDebouncedMemo = useDebouncedMemo;
|
|
@@ -3,7 +3,8 @@ import "./dateRange.less";
|
|
|
3
3
|
import { IZenComponentProps } from "./../commonHelpers/zenComponent";
|
|
4
4
|
import { IDateRangeValue, IDateRangeValueOptionalLabel, TDateRangeOption } from "./dateRangeUtils";
|
|
5
5
|
import { TButton } from "../button/buttonType";
|
|
6
|
-
|
|
6
|
+
import { IChipsParent } from "../chip/chip";
|
|
7
|
+
interface IDateRangeBase extends IZenComponentProps, IChipsParent {
|
|
7
8
|
options: TDateRangeOption[];
|
|
8
9
|
triggerLabel?: string;
|
|
9
10
|
className?: string;
|
|
@@ -25,6 +25,8 @@ const areMapsEqual_1 = require("./utils/areMapsEqual");
|
|
|
25
25
|
const iconChevronLeftSmall_1 = require("../icons/iconChevronLeftSmall");
|
|
26
26
|
const useDrive_1 = require("../utils/theme/useDrive");
|
|
27
27
|
const iconChevronRightSmall_1 = require("../icons/iconChevronRightSmall");
|
|
28
|
+
const chip_1 = require("../chip/chip");
|
|
29
|
+
const chipStatusProvider_1 = require("../chip/chipStatusProvider");
|
|
28
30
|
const parseLabel = (option, dateFormat, translate, toLacalFn) => {
|
|
29
31
|
const localeFrom = toLacalFn(option.from);
|
|
30
32
|
const localeTo = toLacalFn(option.to);
|
|
@@ -37,11 +39,12 @@ const parseLabel = (option, dateFormat, translate, toLacalFn) => {
|
|
|
37
39
|
};
|
|
38
40
|
exports.parseLabel = parseLabel;
|
|
39
41
|
// eslint-disable-next-line complexity
|
|
40
|
-
const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, options: optionsArg, type, id, disabled, dropDownTitle, hasApplyButton, disableFutureDates, disablePastDates, disableDatesBefore, triggerLabel, disableDatesAfter, withCalendar, lockStartDate, lockEndDate, timeSelect, error, allowUnsetValue = false, stepper = false, classNameWrapper }) => {
|
|
42
|
+
const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, options: optionsArg, type, id, disabled, dropDownTitle, hasApplyButton, disableFutureDates, disablePastDates, disableDatesBefore, triggerLabel, disableDatesAfter, withCalendar, lockStartDate, lockEndDate, timeSelect, error, allowUnsetValue = false, stepper = false, classNameWrapper, chip, chipId, chipName, chipIcon }) => {
|
|
41
43
|
var _a;
|
|
42
44
|
const { translate } = (0, useLanguage_1.useLanguage)();
|
|
43
45
|
const isMobile = (0, useMobile_1.useMobile)();
|
|
44
46
|
const isDrive = (0, useDrive_1.useDrive)();
|
|
47
|
+
const chipStatus = (0, chipStatusProvider_1.useChipStatus)();
|
|
45
48
|
const driveWrapperTriggerClassName = (0, useDriveClassName_1.useDriveClassName)("zen-date-range-wrapper");
|
|
46
49
|
const drivePopupClassName = (0, useDriveClassName_1.useDriveClassName)("zen-date-range-popup");
|
|
47
50
|
const driveWrapperPopupClassName = (0, useDriveClassName_1.useDriveClassName)("zen-date-range-popup-wrapper");
|
|
@@ -254,7 +257,8 @@ const DateRange = ({ className, classNamePopup, defaultValue, value, onChange, o
|
|
|
254
257
|
!defaultValue && !value || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.label) === currentLabel || type && type !== buttonType_1.ButtonType.Secondary ? "" : "zen-date-range--active"
|
|
255
258
|
]);
|
|
256
259
|
const popupTriggerComponent = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsx)(textIconButton_1.TextIconButton, { htmlType: "button", icon: iconCalendar_1.IconCalendar, iconPosition: textIconButton_1.ButtonIconPosition.Start, className: cssClass, type: type, disabled: disabled, onClick: toggleVisibility, ref: triggerRef, children: buttonLabel }), [cssClass, type, disabled, toggleVisibility, buttonLabel]);
|
|
257
|
-
|
|
260
|
+
const chipTriggerComponent = (0, react_1.useMemo)(() => (0, jsx_runtime_1.jsx)(chip_1.Chip, { status: isDefaultState ? undefined : chipStatus || "active", isOpen: isOpen, disabled: disabled, onClick: toggleVisibility, onClose: isDefaultState ? undefined : handleClearClick, triggerRef: triggerRef, icon: chipIcon || iconCalendar_1.IconCalendar, id: chipId, children: isDefaultState ? chipName : buttonLabel }), [isDefaultState, chipStatus, isOpen, disabled, toggleVisibility, handleClearClick, chipIcon, chipId, chipName, buttonLabel]);
|
|
261
|
+
return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [stepper ? (0, jsx_runtime_1.jsxs)("div", { className: (0, classNames_1.classNames)(["zen-date-range-wrapper", driveWrapperTriggerClassName || "", classNameWrapper || ""]), children: [(0, jsx_runtime_1.jsx)("button", { type: "button", disabled: checkIsRangeDisable(false), onClick: decreaseRange, className: (0, classNames_1.classNames)(["zen-date-range__stepper", "zen-date-range__stepper--left"]), title: translate("Previous"), children: (0, jsx_runtime_1.jsx)(iconChevronLeftSmall_1.IconChevronLeftSmall, { size: isDrive ? "huge" : "large" }) }), popupTriggerComponent, (0, jsx_runtime_1.jsx)("button", { type: "button", disabled: checkIsRangeDisable(true), onClick: increaseRange, className: (0, classNames_1.classNames)(["zen-date-range__stepper", "zen-date-range__stepper--right"]), title: translate("Next"), children: (0, jsx_runtime_1.jsx)(iconChevronRightSmall_1.IconChevronRightSmall, { size: isDrive ? "huge" : "large" }) })] }) : (chip ? chipTriggerComponent : popupTriggerComponent), isMobile ? memoizedMobileView : memoizedDesktopView, (0, jsx_runtime_1.jsx)(formFieldError_1.FormFieldError, { error: error })] });
|
|
258
262
|
};
|
|
259
263
|
exports.DateRange = DateRange;
|
|
260
264
|
exports.TRANSLATIONS = [
|
|
@@ -4,6 +4,7 @@ import { IEntityWithId } from "../commonHelpers/entity";
|
|
|
4
4
|
import { IColor } from "../groupsFilter/groupsFilterInterfaces";
|
|
5
5
|
import { TFilterButton } from "../filterButton/filterButton";
|
|
6
6
|
import { TAlignment } from "../absolute/absolute";
|
|
7
|
+
import { IChipsParent } from "../chip/chip";
|
|
7
8
|
export interface ISelectionItem {
|
|
8
9
|
id: string;
|
|
9
10
|
name?: string;
|
|
@@ -15,7 +16,14 @@ export interface IDropdownItem extends IEntityWithId {
|
|
|
15
16
|
color?: IColor;
|
|
16
17
|
disabled?: boolean;
|
|
17
18
|
}
|
|
18
|
-
interface
|
|
19
|
+
interface IFetchState<T> {
|
|
20
|
+
data: T | undefined;
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
error: Error | null;
|
|
23
|
+
}
|
|
24
|
+
export interface IFetchDropdownState extends IFetchState<IDropdownItem[]> {
|
|
25
|
+
}
|
|
26
|
+
interface IDropdownBase extends IChipsParent {
|
|
19
27
|
/**
|
|
20
28
|
* @deprecated
|
|
21
29
|
* @param translate - will be removed in the next major release
|
|
@@ -49,6 +57,9 @@ interface IDropdownBase {
|
|
|
49
57
|
error?: string;
|
|
50
58
|
sortFn?: (a: IDropdownItem, b: IDropdownItem) => number;
|
|
51
59
|
checkboxLabel?: string;
|
|
60
|
+
setSearch?: (value: string) => void;
|
|
61
|
+
setChecked?: (value: boolean) => void;
|
|
62
|
+
fetchState?: IFetchDropdownState;
|
|
52
63
|
}
|
|
53
64
|
export interface IDropdownValueFullSelection {
|
|
54
65
|
selected: string[];
|
|
@@ -98,14 +109,18 @@ export interface IDropdown extends IDropdownBase {
|
|
|
98
109
|
export interface IDropdownWithCheckbox extends Omit<IDropdown, "value" | "onChange" | "getData" | "defaultValue"> {
|
|
99
110
|
checkboxLabel: string;
|
|
100
111
|
value: IDropdownWithCheckboxValue;
|
|
101
|
-
getData
|
|
112
|
+
getData?: (signal?: AbortSignal, searchValue?: string, isChecked?: boolean) => Promise<IDropdownItem[]>;
|
|
113
|
+
setChecked?: (value: boolean) => void;
|
|
114
|
+
fetchState?: IFetchDropdownState;
|
|
102
115
|
defaultValue?: IDropdownWithCheckboxValue;
|
|
103
116
|
onChange: (selected: IDropdownWithCheckboxSelected) => void;
|
|
104
117
|
}
|
|
105
118
|
export interface IDropdownFullSelectionWithCheckbox extends Omit<IDropdownFullSelection, "value" | "onChange" | "getData" | "defaultValue"> {
|
|
106
119
|
checkboxLabel: string;
|
|
107
120
|
value: IDropdownValueFullSelectionWithCheckbox;
|
|
108
|
-
getData
|
|
121
|
+
getData?: (signal?: AbortSignal, searchValue?: string, isChecked?: boolean) => Promise<IDropdownItem[]>;
|
|
122
|
+
setChecked?: (value: boolean) => void;
|
|
123
|
+
fetchState?: IFetchDropdownState;
|
|
109
124
|
defaultValue?: IDropdownValueFullSelectionWithCheckbox;
|
|
110
125
|
onChange: (selected: IDropdownFullSelectedValueWithCheckbox) => void;
|
|
111
126
|
}
|
|
@@ -19,16 +19,20 @@ const dropdownPopup_1 = require("./dropdownPopup");
|
|
|
19
19
|
const useMobile_1 = require("../commonHelpers/hooks/useMobile");
|
|
20
20
|
const useDebounce_1 = require("../commonHelpers/hooks/useDebounce");
|
|
21
21
|
const skeletonList_1 = require("../skeletonList/skeletonList");
|
|
22
|
-
const
|
|
22
|
+
const chip_1 = require("../chip/chip");
|
|
23
|
+
const chipStatusProvider_1 = require("../chip/chipStatusProvider");
|
|
24
|
+
const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems, fetchState, onChange, value, defaultValue, placeholder, dialogAriaLabel, width, isLoading, title, triggerAriaLabel, disabled, inputId, filterName, showCounterPill = true, showSelection, fullWidthTriggerButton, hasApplyButton, searchField = true, multiselect = true, forceSelection = false, selectAllButton = true, getNamedItems, getSelectedItem, buttonType = "secondary", listLimit = 500, alignment = "bottom-left", error, sortFn, checkboxLabel, chip, chipId, chipName, chipIcon, setChecked, setSearch }) => {
|
|
23
25
|
var _a;
|
|
24
26
|
const isFullSelectionMode = (0, react_1.useMemo)(() => typeof value === "object" &&
|
|
25
27
|
"selected" in value &&
|
|
26
28
|
Array.isArray(value.selected) &&
|
|
27
29
|
"isAllSelected" in value &&
|
|
28
30
|
typeof value.isAllSelected === "boolean", [value]);
|
|
31
|
+
const isQueryMode = (0, react_1.useMemo)(() => typeof getData === "undefined" && typeof dataItems === "undefined", [getData, dataItems]);
|
|
29
32
|
const isCheckboxMode = (0, react_1.useMemo)(() => checkboxLabel && typeof value === "object" && "isChecked" in value && typeof value.isChecked === "boolean" || false, [checkboxLabel, value]);
|
|
30
33
|
const [initialInChecked] = (0, react_1.useState)(isCheckboxMode ? value.isChecked : undefined);
|
|
31
|
-
const [state, dispatchState] = (0, react_1.useReducer)(stateReducer_1.stateReducer, (0, stateReducer_1.getInitialState)(isFullSelectionMode, dataItems || [], isFullSelectionMode || isCheckboxMode ? value.selected : value, defaultValue ? (isFullSelectionMode || isCheckboxMode ? defaultValue.selected : defaultValue) : undefined, isFullSelectionMode ? value.isAllSelected : undefined, defaultValue ? (isFullSelectionMode ? defaultValue.isAllSelected : undefined) : undefined, isCheckboxMode ? value.isChecked : undefined, isCheckboxMode && defaultValue ? defaultValue.isChecked : undefined));
|
|
34
|
+
const [state, dispatchState] = (0, react_1.useReducer)(stateReducer_1.stateReducer, (0, stateReducer_1.getInitialState)(isFullSelectionMode, isQueryMode ? (fetchState === null || fetchState === void 0 ? void 0 : fetchState.data) || [] : dataItems || [], isFullSelectionMode || isCheckboxMode ? value.selected : value, defaultValue ? (isFullSelectionMode || isCheckboxMode ? defaultValue.selected : defaultValue) : undefined, isFullSelectionMode ? value.isAllSelected : undefined, defaultValue ? (isFullSelectionMode ? defaultValue.isAllSelected : undefined) : undefined, isCheckboxMode ? value.isChecked : undefined, isCheckboxMode && defaultValue ? defaultValue.isChecked : undefined));
|
|
35
|
+
const chipStatus = (0, chipStatusProvider_1.useChipStatus)();
|
|
32
36
|
const isMobile = (0, useMobile_1.useMobile)();
|
|
33
37
|
const abortToken = (0, react_1.useRef)(new AbortController());
|
|
34
38
|
const triggerRef = (0, react_1.useRef)(null);
|
|
@@ -40,7 +44,7 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
40
44
|
const { translate } = (0, useLanguage_1.useLanguage)();
|
|
41
45
|
const getNamedItemsHasBeenCalled = (0, react_1.useRef)(false);
|
|
42
46
|
const selectedItemsLoader = (0, react_1.useRef)(undefined);
|
|
43
|
-
const previousMapDataItems = (0, react_1.useRef)(!getData && (dataItems === null || dataItems === void 0 ? void 0 : dataItems.length) ? dataItems : []);
|
|
47
|
+
const previousMapDataItems = (0, react_1.useRef)(isQueryMode ? (fetchState === null || fetchState === void 0 ? void 0 : fetchState.data) || [] : (!getData && (dataItems === null || dataItems === void 0 ? void 0 : dataItems.length) ? dataItems : []));
|
|
44
48
|
const prevIsLoading = (0, react_1.useRef)(isLoading);
|
|
45
49
|
const prevIsChecked = (0, react_1.useRef)(isCheckboxMode ? value.isChecked : undefined);
|
|
46
50
|
const currentAllSelected = (0, react_1.useMemo)(() => (state.isNestedList || !multiselect || !isFullSelectionMode)
|
|
@@ -51,9 +55,9 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
51
55
|
const timeoutId = setTimeout(() => {
|
|
52
56
|
if (Object.keys(state.groupsMap).length === 0 && getData) {
|
|
53
57
|
const currentAbort = abortToken.current;
|
|
54
|
-
(initialInChecked !== undefined ? getData(currentAbort.signal, undefined, initialInChecked) : getData(currentAbort.signal, undefined)).then((
|
|
55
|
-
|
|
56
|
-
previousMapDataItems.current = [...
|
|
58
|
+
(initialInChecked !== undefined ? getData(currentAbort.signal, undefined, initialInChecked) : getData(currentAbort.signal, undefined)).then((dta) => {
|
|
59
|
+
dta.length && dispatchState({ type: stateActionType_1.StateActionType.CreateMap, payload: dta });
|
|
60
|
+
previousMapDataItems.current = [...dta];
|
|
57
61
|
}).catch(errorHandler);
|
|
58
62
|
}
|
|
59
63
|
});
|
|
@@ -96,7 +100,10 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
96
100
|
return;
|
|
97
101
|
}
|
|
98
102
|
const promises = [];
|
|
99
|
-
ids.forEach(id => {
|
|
103
|
+
Array.from(ids).forEach((id, ind) => {
|
|
104
|
+
if (ind > 99) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
100
107
|
const itemOrPromise = getSelectedItem(id);
|
|
101
108
|
promises.push(Promise.resolve(itemOrPromise));
|
|
102
109
|
});
|
|
@@ -125,7 +132,8 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
125
132
|
const handleChangeCurrentId = (0, react_1.useCallback)((id) => {
|
|
126
133
|
dispatchState({ type: stateActionType_1.StateActionType.SetCurrentId, payload: id });
|
|
127
134
|
dispatchState({ type: stateActionType_1.StateActionType.SetInputValue, payload: "" });
|
|
128
|
-
|
|
135
|
+
isQueryMode && setSearch && setSearch("");
|
|
136
|
+
}, [isQueryMode, setSearch]);
|
|
129
137
|
const handleBackButtonClick = (0, react_1.useCallback)(() => {
|
|
130
138
|
var _a, _b;
|
|
131
139
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -182,8 +190,8 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
182
190
|
dispatchState({ type: stateActionType_1.StateActionType.DeselectItemsFromAllSelected, payload: undefined });
|
|
183
191
|
return;
|
|
184
192
|
}
|
|
185
|
-
(0, dropdownHelper_1.getDataForChange)((0, dropdownHelper_1.getListDataWithDisabled)(state.listData, state.isNestedList), state.selectedIds, isAllSelect)
|
|
186
|
-
|
|
193
|
+
const dataForChange = (0, dropdownHelper_1.getDataForChange)((0, dropdownHelper_1.getListDataWithDisabled)(state.listData, state.isNestedList), state.selectedIds, isAllSelect);
|
|
194
|
+
dispatchState({ type: stateActionType_1.StateActionType.ChangeBulkSelection, payload: { itemsIds: dataForChange, value: !isAllSelect } });
|
|
187
195
|
}, [isFullSelectionMode, state.isAllSelected, state.listData, state.isNestedList, state.selectedIds]);
|
|
188
196
|
const handleClearClick = (0, react_1.useCallback)(() => {
|
|
189
197
|
dispatchState({ type: stateActionType_1.StateActionType.ResetSelection, payload: undefined });
|
|
@@ -221,25 +229,47 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
221
229
|
const customGetData = (0, react_1.useCallback)((str) => (str && dataItems
|
|
222
230
|
? Promise.resolve(dataItems.filter(el => { var _a; return (((_a = el.name) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) || "").indexOf(str.trim().toLocaleLowerCase()) > -1; }))
|
|
223
231
|
: Promise.resolve(dataItems || [])), [dataItems]);
|
|
224
|
-
const handleData = (0, react_1.useCallback)((
|
|
225
|
-
if (
|
|
226
|
-
dispatchState({ type: stateActionType_1.StateActionType.CreateMap, payload:
|
|
227
|
-
previousMapDataItems.current = [...
|
|
232
|
+
const handleData = (0, react_1.useCallback)((dta, searchVal) => {
|
|
233
|
+
if (dta.length && !searchVal && (getData || dataItems || isQueryMode)) {
|
|
234
|
+
dispatchState({ type: stateActionType_1.StateActionType.CreateMap, payload: dta });
|
|
235
|
+
previousMapDataItems.current = [...dta];
|
|
228
236
|
}
|
|
229
|
-
dispatchState({ type: stateActionType_1.StateActionType.SetListData, payload:
|
|
237
|
+
dispatchState({ type: stateActionType_1.StateActionType.SetListData, payload: dta });
|
|
230
238
|
searchVal && dispatchState({ type: stateActionType_1.StateActionType.SetCurrentId, payload: undefined });
|
|
231
|
-
|
|
232
|
-
}, [getData, dataItems]);
|
|
239
|
+
dta.length ? dispatchState({ type: stateActionType_1.StateActionType.ShowList, payload: undefined }) : dispatchState({ type: stateActionType_1.StateActionType.ShowEmptyList, payload: undefined });
|
|
240
|
+
}, [getData, dataItems, isQueryMode]);
|
|
233
241
|
const handleError = (0, react_1.useCallback)((e) => {
|
|
234
242
|
errorHandler(e);
|
|
235
243
|
dispatchState({ type: stateActionType_1.StateActionType.NothingToShow, payload: undefined });
|
|
236
244
|
}, [errorHandler]);
|
|
237
|
-
const
|
|
238
|
-
|
|
245
|
+
const handleDataQuery = (0, react_1.useCallback)((dta, searchVal) => {
|
|
246
|
+
if (dta.length && !searchVal && !(0, dropdownHelper_1.compareObjectsArrays)(dta, previousMapDataItems.current)) {
|
|
247
|
+
dispatchState({ type: stateActionType_1.StateActionType.CreateMap, payload: dta });
|
|
248
|
+
previousMapDataItems.current = [...dta];
|
|
249
|
+
}
|
|
250
|
+
dispatchState({ type: stateActionType_1.StateActionType.SetListData, payload: dta });
|
|
251
|
+
searchVal && dispatchState({ type: stateActionType_1.StateActionType.SetCurrentId, payload: undefined });
|
|
252
|
+
dta.length ? dispatchState({ type: stateActionType_1.StateActionType.ShowList, payload: undefined }) : dispatchState({ type: stateActionType_1.StateActionType.ShowEmptyList, payload: undefined });
|
|
253
|
+
}, []);
|
|
254
|
+
const handleQueryMode = (0, react_1.useCallback)((searchValue, isChecked) => {
|
|
255
|
+
setChecked && isChecked !== undefined && setChecked(isChecked);
|
|
256
|
+
setSearch && setSearch(searchValue || "");
|
|
257
|
+
}, [setChecked, setSearch]);
|
|
258
|
+
const debouncedGetData = (0, useDebounce_1.useDebounce)((signal, searchValue, isChecked) => getData ? (isCheckboxMode ? getData(signal, searchValue, isChecked) : getData(signal, searchValue)).then((dta) => handleData(dta, searchValue)).catch(handleError)
|
|
259
|
+
: customGetData(searchValue).then((dta) => handleData(dta, searchValue)).catch(handleError), 200);
|
|
239
260
|
const controlData = (0, react_1.useCallback)((signal, searchValue, isChecked) => {
|
|
240
|
-
dispatchState({ type: stateActionType_1.StateActionType.ShowWaiting, payload: undefined });
|
|
241
|
-
debouncedGetData(signal, searchValue, isChecked);
|
|
242
|
-
}, [debouncedGetData]);
|
|
261
|
+
!isQueryMode && dispatchState({ type: stateActionType_1.StateActionType.ShowWaiting, payload: undefined });
|
|
262
|
+
isQueryMode ? handleQueryMode(searchValue, isChecked) : debouncedGetData(signal, searchValue, isChecked);
|
|
263
|
+
}, [debouncedGetData, handleQueryMode, isQueryMode]);
|
|
264
|
+
(0, react_1.useEffect)(() => {
|
|
265
|
+
const timeoutId = setTimeout(() => {
|
|
266
|
+
if (!isQueryMode || (fetchState === null || fetchState === void 0 ? void 0 : fetchState.isLoading)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
handleDataQuery((fetchState === null || fetchState === void 0 ? void 0 : fetchState.data) || [], state.inputValue);
|
|
270
|
+
});
|
|
271
|
+
return () => clearTimeout(timeoutId);
|
|
272
|
+
}, [fetchState === null || fetchState === void 0 ? void 0 : fetchState.data, handleDataQuery, fetchState === null || fetchState === void 0 ? void 0 : fetchState.isLoading, isQueryMode, state.inputValue]);
|
|
243
273
|
(0, react_1.useEffect)(() => {
|
|
244
274
|
// when change inside
|
|
245
275
|
if (hasApplyButton) {
|
|
@@ -293,8 +323,8 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
293
323
|
dispatchState({ type: stateActionType_1.StateActionType.SetState,
|
|
294
324
|
payload: { selected: selectedValue, isAllSelected: isAllSelectedValue } });
|
|
295
325
|
isCheckboxMode && isCheckedValue !== undefined && dispatchState({ type: stateActionType_1.StateActionType.SetIsChecked, payload: isCheckedValue });
|
|
296
|
-
}, [value, state.selectedIds, state.globalSelectedIds, hasApplyButton, isFullSelectionMode, state.isAllSelected,
|
|
297
|
-
state.globalIsChecked, state.isChecked]);
|
|
326
|
+
}, [value, state.selectedIds, state.globalSelectedIds, hasApplyButton, isFullSelectionMode, state.isAllSelected,
|
|
327
|
+
state.globalIsAllSelected, isCheckboxMode, state.globalIsChecked, state.isChecked]);
|
|
298
328
|
(0, react_1.useEffect)(() => {
|
|
299
329
|
if (!isCheckboxMode || prevIsChecked.current === undefined) {
|
|
300
330
|
return;
|
|
@@ -425,12 +455,12 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
425
455
|
if (currentWidth && currentWidth < 180) {
|
|
426
456
|
currentWidth = 180;
|
|
427
457
|
}
|
|
428
|
-
if (state.showWaiting || isLoading) {
|
|
458
|
+
if (state.showWaiting || isLoading || (isQueryMode && (fetchState === null || fetchState === void 0 ? void 0 : fetchState.isLoading))) {
|
|
429
459
|
return (0, jsx_runtime_1.jsx)(skeletonList_1.SkeletonList, { className: "zen-dropdown-list__container zen-dropdown-list__container--empty", width: currentWidth });
|
|
430
460
|
}
|
|
431
|
-
if (state.showEmptyList) {
|
|
461
|
+
if (state.showEmptyList || (isQueryMode && (fetchState === null || fetchState === void 0 ? void 0 : fetchState.error))) {
|
|
432
462
|
const isClearButtonDisabled = (0, dropdownHelper_1.compareStringsArrays)(state.selectedIds, state.defaultValue);
|
|
433
|
-
return (0, jsx_runtime_1.jsx)(dropdownList_1.EmptyList, { width: currentWidth, onClearClick: handleClearClick, onCancelClick: handleCancelClick, onApplyClick: handleApplyClick, hasApplyButton: hasApplyButton, isApplyDisabled: (0, dropdownHelper_1.compareStringsArrays)(state.globalSelectedIds, state.selectedIds), isClearButtonDisabled: isClearButtonDisabled, isWithFooter: memoizedWithFooter && Object.keys(state.groupsMap).length === 0 && ((!hasApplyButton && !isClearButtonDisabled) || hasApplyButton || false) });
|
|
463
|
+
return (0, jsx_runtime_1.jsx)(dropdownList_1.EmptyList, { width: currentWidth, onClearClick: handleClearClick, onCancelClick: handleCancelClick, onApplyClick: handleApplyClick, hasApplyButton: hasApplyButton, isApplyDisabled: (0, dropdownHelper_1.compareStringsArrays)(state.globalSelectedIds, state.selectedIds), isClearButtonDisabled: isClearButtonDisabled, isWithFooter: memoizedWithFooter && Object.keys(state.groupsMap).length === 0 && ((!hasApplyButton && !isClearButtonDisabled) || hasApplyButton || false), hasError: state.showEmptyList && (isQueryMode && (fetchState === null || fetchState === void 0 ? void 0 : fetchState.error) !== null) });
|
|
434
464
|
}
|
|
435
465
|
if (state.showList) {
|
|
436
466
|
const isSearchMode = state.inputValue && !state.currentId;
|
|
@@ -449,15 +479,17 @@ const Dropdown = ({ className, classNamePopup, getData, errorHandler, dataItems,
|
|
|
449
479
|
(((_c = state.groupsMap[groupsHelper_1.ENTIRE_ORGANIZATION_GROUP_ID]) === null || _c === void 0 ? void 0 : _c.children) || []).map(el => el.id)), isClearButtonDisabled: memoizedIsClearButtonDisabled, isWithFooter: memoizedWithFooter && !isMobile, isMobile: isMobile, handleCheckboxChange: isCheckboxMode && !isMobile ? handleCheckboxChange : undefined, checkboxLabel: checkboxLabel, isChecked: state.isChecked });
|
|
450
480
|
}
|
|
451
481
|
return null;
|
|
452
|
-
}, [state, isLoading,
|
|
453
|
-
|
|
454
|
-
|
|
482
|
+
}, [state, isLoading, isQueryMode, fetchState === null || fetchState === void 0 ? void 0 : fetchState.isLoading, fetchState === null || fetchState === void 0 ? void 0 : fetchState.error, handleClearClick, handleCancelClick, handleApplyClick, hasApplyButton,
|
|
483
|
+
memoizedWithFooter, translate, sortFn, listLimit, multiselect, currentAllSelected, handleBackButtonClick, handleSelectAllInSearch,
|
|
484
|
+
handleSelectAllClick, handleSelect, handleChangeCurrentId, handleSingleSelection, isMobile, filterName, forceSelection, width,
|
|
485
|
+
selectAllButton, memoizedIsApplyButtonDisabled, memoizedIsClearButtonDisabled, isCheckboxMode, handleCheckboxChange, checkboxLabel]);
|
|
455
486
|
const currentStringFromSelected = isFullSelectionMode && hasApplyButton && state.globalIsAllSelected ||
|
|
456
487
|
isFullSelectionMode && !hasApplyButton && state.isAllSelected ? (0, dropdownHelper_1.getStringFromAllSelected)(state.groupsMap, translate)
|
|
457
488
|
: (0, dropdownHelper_1.getStringFromSelected)(hasApplyButton ? state.globalSelectedIds : state.selectedIds, state.groupsMapSelected, translate);
|
|
458
489
|
const memoizedCurrentSelection = (0, react_1.useMemo)(() => showSelection && !state.inputValue ? currentStringFromSelected : "", [showSelection, state.inputValue, currentStringFromSelected]);
|
|
459
490
|
const parentTriggerWidth = ((_a = comboboxRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) || 420;
|
|
460
|
-
return (0, jsx_runtime_1.jsxs)("div", { className: containerClassName, ref: comboboxRef, children: [(0, jsx_runtime_1.jsx)(
|
|
491
|
+
return (0, jsx_runtime_1.jsxs)("div", { className: containerClassName, ref: comboboxRef, children: [chip ? (0, jsx_runtime_1.jsx)(chip_1.Chip, { status: memoizedIsClearButtonDisabled ? undefined : chipStatus || "active", isOpen: state.isOpenCombo, disabled: disabled, onClick: handleTriggerClick, onClose: memoizedIsClearButtonDisabled ? undefined : handleClearClick, triggerRef: triggerRef, icon: chipIcon, id: chipId, children: currentStringFromSelected || chipName }) :
|
|
492
|
+
(0, jsx_runtime_1.jsx)(dropdownTrigger_1.DropdownTrigger, { className: (0, classNames_1.classNames)([!width && !fullWidthTriggerButton && parentTriggerWidth < 420 && !searchField ? "zen-dropdown__trigger-button--width-parent" : ""]), currentSelection: memoizedCurrentSelection, isActive: state.isOpenCombo, id: inputId, disabled: disabled, count: showCounterPill ? countSelected : 0, fullWidth: fullWidthTriggerButton, inputValue: state.inputValue, placeholder: placeholder || translate("Filter by group"), searchField: searchField && !isMobile ? searchField : false, onSearchChange: onSearchChange, handleClick: handleTriggerClick, width: width && width > 420 ? 420 : width, title: title, triggerAriaLabel: triggerAriaLabel, triggerRef: triggerRef, inputRef: inputRef, buttonType: buttonType, error: error }), (0, jsx_runtime_1.jsx)(dropdownPopup_1.DropdownPopup, { alignment: alignment, triggerRef: triggerRef, classNamePopup: classNamePopup, isMobile: isMobile, dialogAriaLabel: dialogAriaLabel, disabled: disabled, filterName: filterName, hasApplyButton: hasApplyButton, inputId: inputId, isClearButtonDisabled: memoizedIsClearButtonDisabled, isApplyButtonDisabled: memoizedIsApplyButtonDisabled, isWithFooter: memoizedWithFooter, isOpenCombo: state.isOpenCombo, searchField: searchField, placeholder: placeholder, inputValue: state.inputValue, handleApplyClick: handleApplyClick, handleClearClick: multiselect ? handleClearClick : handleSingleSelection.bind(this, true), handleTriggerClick: handleTriggerClick, onInputChange: onInputChange, inputRef: inputRef, contentRef: contentRef, onReadyForFocus: handleReadyForFocus, handleCheckboxChange: isCheckboxMode && isMobile ? handleCheckboxChange : undefined, checkboxLabel: checkboxLabel, isChecked: state.isChecked, isSearchInPopup: chip, children: getPopupContent })] });
|
|
461
493
|
};
|
|
462
494
|
exports.Dropdown = Dropdown;
|
|
463
495
|
exports.TRANSLATIONS = [
|