@dbcdk/react-components 0.0.5 → 0.0.7
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/dist/assets/logo.js +2 -85
- package/dist/components/__stories__/_data/table.d.ts +15 -0
- package/dist/components/__stories__/_data/table.js +49 -0
- package/dist/components/__stories__/story-components/Colors.d.ts +2 -1
- package/dist/components/__stories__/story-components/Colors.js +87 -142
- package/dist/components/__stories__/story-components/Spacing.d.ts +1 -0
- package/dist/components/__stories__/story-components/Spacing.js +58 -166
- package/dist/components/app-header/AppHeader.d.ts +4 -3
- package/dist/components/app-header/AppHeader.js +3 -6
- package/dist/components/attribute-chip/AttributeChip.d.ts +1 -0
- package/dist/components/attribute-chip/AttributeChip.js +3 -14
- package/dist/components/avatar/Avatar.d.ts +2 -2
- package/dist/components/avatar/Avatar.js +37 -71
- package/dist/components/breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/components/breadcrumbs/Breadcrumbs.js +4 -13
- package/dist/components/button/Button.d.ts +3 -2
- package/dist/components/button/Button.js +54 -56
- package/dist/components/button/Button.module.css +1 -1
- package/dist/components/card/Card.d.ts +8 -7
- package/dist/components/card/Card.js +19 -60
- package/dist/components/card-container/CardContainer.d.ts +3 -3
- package/dist/components/card-container/CardContainer.js +4 -16
- package/dist/components/chip/Chip.d.ts +6 -5
- package/dist/components/chip/Chip.js +14 -38
- package/dist/components/chip/Chip.module.css +9 -1
- package/dist/components/circle/Circle.d.ts +3 -2
- package/dist/components/circle/Circle.js +3 -10
- package/dist/components/clear-button/ClearButton.d.ts +2 -1
- package/dist/components/clear-button/ClearButton.js +6 -17
- package/dist/components/code-block/CodeBlock.d.ts +1 -0
- package/dist/components/code-block/CodeBlock.js +4 -10
- package/dist/components/copy-button/CopyButton.d.ts +4 -3
- package/dist/components/copy-button/CopyButton.js +19 -26
- package/dist/components/datetime-picker/DateTimePicker.d.ts +8 -5
- package/dist/components/datetime-picker/DateTimePicker.js +262 -475
- package/dist/components/datetime-picker/dateTimeHelpers.d.ts +13 -0
- package/dist/components/datetime-picker/dateTimeHelpers.js +119 -0
- package/dist/components/filter-field/FilterField.d.ts +5 -2
- package/dist/components/filter-field/FilterField.js +130 -173
- package/dist/components/filter-field/FilterField.module.css +21 -5
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.d.ts +36 -0
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.js +53 -0
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.module.css +60 -0
- package/dist/components/forms/checkbox/Checkbox.d.ts +31 -0
- package/dist/components/forms/checkbox/Checkbox.js +27 -0
- package/dist/components/{checkbox → forms/checkbox}/Checkbox.module.css +0 -1
- package/dist/components/forms/checkbox-group/CheckboxGroup.d.ts +47 -0
- package/dist/components/forms/checkbox-group/CheckboxGroup.js +75 -0
- package/dist/components/forms/checkbox-group/CheckboxGroup.module.css +115 -0
- package/dist/components/{input → forms/input}/Input.d.ts +9 -5
- package/dist/components/forms/input/Input.js +70 -0
- package/dist/components/{input → forms/input}/Input.module.css +1 -0
- package/dist/components/forms/input-container/InputContainer.d.ts +15 -0
- package/dist/components/forms/input-container/InputContainer.js +15 -0
- package/dist/components/forms/input-container/InputContainer.module.css +34 -0
- package/dist/components/forms/multi-select/MultiSelect.d.ts +20 -0
- package/dist/components/forms/multi-select/MultiSelect.js +19 -0
- package/dist/components/forms/select/Select.d.ts +21 -0
- package/dist/components/forms/select/Select.js +94 -0
- package/dist/components/forms/text-area/Textarea.d.ts +17 -0
- package/dist/components/forms/text-area/Textarea.js +33 -0
- package/dist/components/forms/text-area/Textarea.module.css +26 -0
- package/dist/components/headline/Headline.js +18 -43
- package/dist/components/{link/Link.d.ts → hyperlink/Hyperlink.d.ts} +2 -2
- package/dist/components/hyperlink/Hyperlink.js +11 -0
- package/dist/components/{link/Link.module.css → hyperlink/Hyperlink.module.css} +5 -14
- package/dist/components/icon/Icon.d.ts +4 -3
- package/dist/components/icon/Icon.js +11 -17
- package/dist/components/interval-select/IntervalSelect.d.ts +30 -0
- package/dist/components/interval-select/IntervalSelect.js +82 -0
- package/dist/components/menu/Menu.js +25 -67
- package/dist/components/meta-bar/MetaBar.d.ts +4 -4
- package/dist/components/meta-bar/MetaBar.js +7 -20
- package/dist/components/nav-bar/NavBar.d.ts +5 -5
- package/dist/components/nav-bar/NavBar.js +15 -45
- package/dist/components/{modal → overlay/modal}/Modal.d.ts +4 -2
- package/dist/components/overlay/modal/Modal.js +92 -0
- package/dist/components/{modal → overlay/modal}/provider/ModalProvider.d.ts +0 -1
- package/dist/components/overlay/modal/provider/ModalProvider.js +70 -0
- package/dist/components/overlay/side-panel/SidePanel.d.ts +16 -0
- package/dist/components/overlay/side-panel/SidePanel.js +10 -0
- package/dist/components/overlay/side-panel/SidePanel.module.css +56 -0
- package/dist/components/overlay/side-panel/useSidePanel.d.ts +5 -0
- package/dist/components/overlay/side-panel/useSidePanel.js +11 -0
- package/dist/components/overlay/tooltip/Tooltip.d.ts +13 -0
- package/dist/components/overlay/tooltip/Tooltip.js +17 -0
- package/dist/components/overlay/tooltip/Tooltip.module.css +106 -0
- package/dist/components/overlay/tooltip/TooltipProvider.d.ts +20 -0
- package/dist/components/overlay/tooltip/TooltipProvider.js +244 -0
- package/dist/components/overlay/tooltip/useTooltipTrigger.d.ts +24 -0
- package/dist/components/overlay/tooltip/useTooltipTrigger.js +108 -0
- package/dist/components/page/Page.d.ts +7 -6
- package/dist/components/page/Page.js +4 -21
- package/dist/components/page-layout/PageLayout.d.ts +11 -12
- package/dist/components/page-layout/PageLayout.js +35 -71
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.js +4 -22
- package/dist/components/pagination/Pagination.d.ts +2 -1
- package/dist/components/pagination/Pagination.js +38 -121
- package/dist/components/panel/Panel.d.ts +4 -3
- package/dist/components/panel/Panel.js +5 -10
- package/dist/components/popover/Popover.d.ts +1 -0
- package/dist/components/popover/Popover.js +116 -141
- package/dist/components/search-box/SearchBox.d.ts +2 -2
- package/dist/components/search-box/SearchBox.js +112 -162
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.d.ts +1 -1
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +47 -94
- package/dist/components/sidebar/Sidebar.d.ts +1 -0
- package/dist/components/sidebar/Sidebar.js +5 -7
- package/dist/components/sidebar/components/SidebarItem.js +6 -14
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.d.ts +1 -1
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +48 -88
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.d.ts +3 -2
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +11 -41
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.d.ts +1 -0
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +4 -25
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +9 -23
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.js +19 -40
- package/dist/components/sidebar/providers/SidebarProvider.d.ts +2 -1
- package/dist/components/sidebar/providers/SidebarProvider.js +182 -165
- package/dist/components/skeleton-loader/SkeletonLoader.js +68 -266
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +11 -34
- package/dist/components/split-button/SplitButton.d.ts +7 -5
- package/dist/components/split-button/SplitButton.js +4 -27
- package/dist/components/split-pane/SplitPane.js +69 -105
- package/dist/components/split-pane/provider/SplitPaneContext.js +77 -71
- package/dist/components/table/Table.d.ts +9 -7
- package/dist/components/table/Table.js +115 -238
- package/dist/components/table/Table.module.css +5 -1
- package/dist/components/table/components/column-resizer/ColumnResizer.js +4 -15
- package/dist/components/table/components/empty-state/EmptyState.d.ts +6 -5
- package/dist/components/table/components/empty-state/EmptyState.js +22 -41
- package/dist/components/table/components/table-settings/TableSettings.d.ts +2 -1
- package/dist/components/table/components/table-settings/TableSettings.js +9 -27
- package/dist/components/table/tanstack.d.ts +1 -1
- package/dist/components/table/tanstack.js +154 -160
- package/dist/components/tabs/Tabs.d.ts +1 -0
- package/dist/components/tabs/Tabs.js +32 -81
- package/dist/components/toast/Toast.d.ts +1 -1
- package/dist/components/toast/Toast.js +4 -37
- package/dist/components/toast/Toast.module.css +1 -0
- package/dist/components/toast/provider/ToastProvider.d.ts +1 -1
- package/dist/components/toast/provider/ToastProvider.js +60 -87
- package/dist/components/user-display/UserDisplay.d.ts +2 -1
- package/dist/components/user-display/UserDisplay.js +4 -20
- package/dist/constants/severity.d.ts +1 -1
- package/dist/constants/severity.js +14 -16
- package/dist/constants/severity.types.d.ts +1 -1
- package/dist/constants/severity.types.js +1 -1
- package/dist/constants/sizes.js +6 -8
- package/dist/hooks/usePagination.d.ts +1 -1
- package/dist/hooks/usePagination.js +75 -82
- package/dist/hooks/useSorting.js +112 -110
- package/dist/hooks/useTableData.d.ts +1 -1
- package/dist/hooks/useTableData.js +42 -47
- package/dist/hooks/useTableSelection.js +121 -121
- package/dist/hooks/useTableSettings.js +23 -25
- package/dist/hooks/useTheme.d.ts +3 -7
- package/dist/hooks/useTheme.js +52 -47
- package/dist/hooks/useTimeDuration.d.ts +2 -2
- package/dist/hooks/useTimeDuration.js +33 -34
- package/dist/hooks/useViewportFill.d.ts +3 -2
- package/dist/hooks/useViewportFill.js +55 -48
- package/dist/index.d.ts +17 -8
- package/dist/index.js +18 -8
- package/dist/src/styles/styles.css +3 -3
- package/dist/styles/css-helper-classes/flex.css +4 -0
- package/dist/styles/styles.css +3 -3
- package/dist/styles/themes/dbc/dark.css +1 -1
- package/dist/styles/themes/dbc/light.css +2 -1
- package/dist/styles/themes/forfatterweb/light.css +1 -1
- package/dist/styles/themes/types.js +1 -1
- package/dist/types/a11y-props.types.d.ts +5 -5
- package/dist/types/a11y-props.types.js +1 -1
- package/dist/types/sizes.types.js +1 -1
- package/dist/utils/arrays/nested-filtering.js +43 -33
- package/dist/utils/date/formatDate.js +25 -16
- package/package.json +18 -9
- package/dist/assets/logo.cjs +0 -87
- package/dist/components/__stories__/story-components/Colors.cjs +0 -159
- package/dist/components/__stories__/story-components/Spacing.cjs +0 -190
- package/dist/components/app-header/AppHeader.cjs +0 -14
- package/dist/components/attribute-chip/AttributeChip.cjs +0 -22
- package/dist/components/avatar/Avatar.cjs +0 -101
- package/dist/components/breadcrumbs/Breadcrumbs.cjs +0 -22
- package/dist/components/button/Button.cjs +0 -87
- package/dist/components/card/Card.cjs +0 -69
- package/dist/components/card-container/CardContainer.cjs +0 -24
- package/dist/components/checkbox/Checkbox.cjs +0 -42
- package/dist/components/checkbox/Checkbox.d.ts +0 -12
- package/dist/components/checkbox/Checkbox.js +0 -36
- package/dist/components/chip/Chip.cjs +0 -50
- package/dist/components/circle/Circle.cjs +0 -18
- package/dist/components/clear-button/ClearButton.cjs +0 -26
- package/dist/components/code-block/CodeBlock.cjs +0 -18
- package/dist/components/copy-button/CopyButton.cjs +0 -35
- package/dist/components/datetime-picker/DateTimePicker.cjs +0 -504
- package/dist/components/filter-field/FilterField.cjs +0 -189
- package/dist/components/headline/Headline.cjs +0 -53
- package/dist/components/icon/Icon.cjs +0 -27
- package/dist/components/input/Input.cjs +0 -89
- package/dist/components/input/Input.js +0 -83
- package/dist/components/link/Link.cjs +0 -46
- package/dist/components/link/Link.js +0 -21
- package/dist/components/menu/Menu.cjs +0 -96
- package/dist/components/meta-bar/MetaBar.cjs +0 -29
- package/dist/components/modal/Modal.cjs +0 -134
- package/dist/components/modal/Modal.js +0 -128
- package/dist/components/modal/provider/ModalProvider.cjs +0 -80
- package/dist/components/modal/provider/ModalProvider.js +0 -77
- package/dist/components/multi-select/MultiSelect.cjs +0 -59
- package/dist/components/multi-select/MultiSelect.d.ts +0 -18
- package/dist/components/multi-select/MultiSelect.js +0 -57
- package/dist/components/nav-bar/NavBar.cjs +0 -55
- package/dist/components/page/Page.cjs +0 -30
- package/dist/components/page-layout/PageLayout.cjs +0 -84
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.cjs +0 -32
- package/dist/components/pagination/Pagination.cjs +0 -133
- package/dist/components/panel/Panel.cjs +0 -18
- package/dist/components/popover/Popover.cjs +0 -149
- package/dist/components/search-box/SearchBox.cjs +0 -175
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.cjs +0 -103
- package/dist/components/select/Select.cjs +0 -121
- package/dist/components/select/Select.d.ts +0 -12
- package/dist/components/select/Select.js +0 -119
- package/dist/components/sidebar/Sidebar.cjs +0 -11
- package/dist/components/sidebar/components/SidebarItem.cjs +0 -18
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +0 -100
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.cjs +0 -50
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.cjs +0 -34
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.cjs +0 -29
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.cjs +0 -52
- package/dist/components/sidebar/providers/SidebarProvider.cjs +0 -179
- package/dist/components/skeleton-loader/SkeletonLoader.cjs +0 -270
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.cjs +0 -42
- package/dist/components/split-button/SplitButton.cjs +0 -37
- package/dist/components/split-pane/SplitPane.cjs +0 -123
- package/dist/components/split-pane/provider/SplitPaneContext.cjs +0 -87
- package/dist/components/table/Table.cjs +0 -249
- package/dist/components/table/components/column-resizer/ColumnResizer.cjs +0 -22
- package/dist/components/table/components/empty-state/EmptyState.cjs +0 -52
- package/dist/components/table/components/table-settings/TableSettings.cjs +0 -32
- package/dist/components/table/tanstack.cjs +0 -193
- package/dist/components/tabs/Tabs.cjs +0 -90
- package/dist/components/text-area/Textarea.cjs +0 -62
- package/dist/components/text-area/Textarea.d.ts +0 -14
- package/dist/components/text-area/Textarea.js +0 -56
- package/dist/components/text-area/Textarea.module.css +0 -3
- package/dist/components/toast/Toast.cjs +0 -47
- package/dist/components/toast/provider/ToastProvider.cjs +0 -98
- package/dist/components/tooltip/Tooltip.cjs +0 -183
- package/dist/components/tooltip/Tooltip.d.ts +0 -11
- package/dist/components/tooltip/Tooltip.js +0 -177
- package/dist/components/tooltip/Tooltip.module.css +0 -66
- package/dist/components/user-display/UserDisplay.cjs +0 -28
- package/dist/constants/severity.cjs +0 -21
- package/dist/constants/severity.types.cjs +0 -2
- package/dist/constants/sizes.cjs +0 -11
- package/dist/hooks/usePagination.cjs +0 -88
- package/dist/hooks/useSorting.cjs +0 -118
- package/dist/hooks/useTableData.cjs +0 -52
- package/dist/hooks/useTableSelection.cjs +0 -130
- package/dist/hooks/useTableSettings.cjs +0 -28
- package/dist/hooks/useTheme.cjs +0 -58
- package/dist/hooks/useTimeDuration.cjs +0 -39
- package/dist/hooks/useViewportFill.cjs +0 -52
- package/dist/index.cjs +0 -383
- package/dist/styles/themes/types.cjs +0 -2
- package/dist/types/a11y-props.types.cjs +0 -2
- package/dist/types/assets.d.cjs +0 -2
- package/dist/types/assets.d.js +0 -1
- package/dist/types/css.d.cjs +0 -2
- package/dist/types/css.d.js +0 -1
- package/dist/types/sizes.types.cjs +0 -2
- package/dist/utils/arrays/nested-filtering.cjs +0 -40
- package/dist/utils/date/formatDate.cjs +0 -19
- /package/dist/components/{modal → overlay/modal}/Modal.module.css +0 -0
|
@@ -1,169 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Search } from 'lucide-react';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { Button } from '../../components/button/Button';
|
|
6
|
+
import { Input } from '../../components/forms/input/Input';
|
|
7
|
+
import { Menu } from '../../components/menu/Menu';
|
|
8
|
+
import { Popover } from '../../components/popover/Popover';
|
|
9
|
+
import { SkeletonLoaderItem } from '../../components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem';
|
|
9
10
|
import styles from './SearchBox.module.css';
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
loading,
|
|
27
|
-
enableHotkey = true,
|
|
28
|
-
onButtonClick,
|
|
29
|
-
value,
|
|
30
|
-
onChange,
|
|
31
|
-
...rest
|
|
32
|
-
}, ref) {
|
|
33
|
-
const isControlled = value !== void 0;
|
|
34
|
-
const [draft, setDraft] = useState(() => isControlled ? String(value != null ? value : "") : "");
|
|
35
|
-
const [searchQuery, setSearchQuery] = useState("");
|
|
36
|
-
const popoverRef = useRef(null);
|
|
37
|
-
const internalInputRef = useRef(null);
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (typeof ref === "function") {
|
|
40
|
-
ref(internalInputRef.current);
|
|
41
|
-
} else if (ref) {
|
|
42
|
-
ref.current = internalInputRef.current;
|
|
43
|
-
}
|
|
44
|
-
}, [ref]);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (!isControlled) return;
|
|
47
|
-
const next = String(value != null ? value : "");
|
|
48
|
-
if (next !== draft) setDraft(next);
|
|
49
|
-
}, [value]);
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (!onSearch) return;
|
|
52
|
-
if (!debounce) {
|
|
53
|
-
setSearchQuery(draft);
|
|
54
|
-
onSearch(draft);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const handler = setTimeout(() => {
|
|
58
|
-
setSearchQuery(draft);
|
|
59
|
-
onSearch(draft);
|
|
60
|
-
}, debounceMs);
|
|
61
|
-
return () => clearTimeout(handler);
|
|
62
|
-
}, [draft, onSearch, debounce, debounceMs]);
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
function handleKeyDown(event) {
|
|
65
|
-
var _a;
|
|
66
|
-
if (event.key === "k" && (event.metaKey || event.ctrlKey)) {
|
|
67
|
-
event.preventDefault();
|
|
68
|
-
(_a = internalInputRef.current) == null ? void 0 : _a.focus();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (enableHotkey) {
|
|
72
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
73
|
-
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
74
|
-
}
|
|
75
|
-
}, [enableHotkey]);
|
|
76
|
-
const handleChange = (e) => {
|
|
77
|
-
setDraft(e.target.value);
|
|
78
|
-
onChange == null ? void 0 : onChange(e);
|
|
79
|
-
};
|
|
80
|
-
function handleSelect(item) {
|
|
81
|
-
onSelect == null ? void 0 : onSelect(item);
|
|
82
|
-
reset();
|
|
83
|
-
}
|
|
84
|
-
function reset() {
|
|
85
|
-
var _a;
|
|
86
|
-
setDraft("");
|
|
87
|
-
setSearchQuery("");
|
|
88
|
-
(_a = popoverRef.current) == null ? void 0 : _a.close();
|
|
89
|
-
}
|
|
90
|
-
const inputProps = {
|
|
91
|
-
...rest,
|
|
92
|
-
value: draft,
|
|
93
|
-
onChange: handleChange
|
|
94
|
-
};
|
|
95
|
-
const inputField = useMemo(() => {
|
|
96
|
-
var _a;
|
|
97
|
-
if (displayPopover) {
|
|
98
|
-
return /* @__PURE__ */ jsx(
|
|
99
|
-
Popover,
|
|
100
|
-
{
|
|
101
|
-
ref: popoverRef,
|
|
102
|
-
minWidth: popoverMinWidth,
|
|
103
|
-
trigger: (event) => {
|
|
104
|
-
var _a2;
|
|
105
|
-
return /* @__PURE__ */ jsx(
|
|
106
|
-
Input,
|
|
107
|
-
{
|
|
108
|
-
ref: internalInputRef,
|
|
109
|
-
onFocusCapture: event,
|
|
110
|
-
onClick: event,
|
|
111
|
-
minWidth: inputWidth != null ? inputWidth : "300px",
|
|
112
|
-
width: inputWidth != null ? inputWidth : "300px",
|
|
113
|
-
icon: /* @__PURE__ */ jsx(Search, {}),
|
|
114
|
-
inputSize,
|
|
115
|
-
variant,
|
|
116
|
-
...inputProps,
|
|
117
|
-
placeholder: (_a2 = rest.placeholder) != null ? _a2 : "Indtast s\xF8geord"
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
},
|
|
121
|
-
children: resultTemplate ? resultTemplate : (result == null ? void 0 : result.length) ? /* @__PURE__ */ jsx(Menu, { children: /* @__PURE__ */ jsx("table", { children: /* @__PURE__ */ jsx("tbody", { children: result.map((item, index) => /* @__PURE__ */ jsx("tr", { onClick: () => handleSelect(item), role: "button", tabIndex: 0, children: resultKeys == null ? void 0 : resultKeys.map((key) => {
|
|
122
|
-
const raw = item[key];
|
|
123
|
-
const cell = raw != null ? String(raw) : "";
|
|
124
|
-
return /* @__PURE__ */ jsx(
|
|
125
|
-
"td",
|
|
126
|
-
{
|
|
127
|
-
style: { whiteSpace: cell.length < 10 ? "nowrap" : void 0 },
|
|
128
|
-
children: cell
|
|
129
|
-
},
|
|
130
|
-
key
|
|
131
|
-
);
|
|
132
|
-
}) }, index)) }) }) }) : !searchQuery && !loading ? initialTemplate || /* @__PURE__ */ jsx("div", { className: styles.resultContainer, children: "Indtast s\xF8geord" }) : loading ? /* @__PURE__ */ jsx("table", { style: { width: "100%" }, children: /* @__PURE__ */ jsx("tbody", { children: Array.from({ length: 5 }).map((_, index) => /* @__PURE__ */ jsx("tr", { children: resultKeys == null ? void 0 : resultKeys.map((key) => /* @__PURE__ */ jsx("td", { style: { padding: "8px" }, children: /* @__PURE__ */ jsx(SkeletonLoaderItem, { height: 20, width: "100%" }) }, key)) }, index)) }) }) : /* @__PURE__ */ jsx("div", { className: styles.resultContainer, children: noResultText })
|
|
11
|
+
export const SearchBox = forwardRef(function SearchBoxInner({ inputWidth, inputSize, variant, result, debounce = true, debounceMs = 800, onSearch, onSelect, displayPopover, resultKeys, resultTemplate, initialTemplate, popoverMinWidth = '500px', noResultText = 'Ingen resultater', loading, enableHotkey = true, onButtonClick, value, onChange, ...rest }, ref) {
|
|
12
|
+
const isControlled = value !== undefined;
|
|
13
|
+
// What the user sees immediately in the textbox
|
|
14
|
+
const [draft, setDraft] = useState(() => (isControlled ? String(value !== null && value !== void 0 ? value : '') : ''));
|
|
15
|
+
// Used only for UI state ("Indtast søgeord" vs results/no results)
|
|
16
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
17
|
+
const popoverRef = useRef(null);
|
|
18
|
+
const internalInputRef = useRef(null);
|
|
19
|
+
// Forward ref to parent
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (typeof ref === 'function') {
|
|
22
|
+
ref(internalInputRef.current);
|
|
23
|
+
}
|
|
24
|
+
else if (ref) {
|
|
25
|
+
;
|
|
26
|
+
ref.current = internalInputRef.current;
|
|
133
27
|
}
|
|
134
|
-
|
|
28
|
+
}, [ref]);
|
|
29
|
+
// If parent changes value (reset/select/navigation), update draft shown in the input
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!isControlled)
|
|
32
|
+
return;
|
|
33
|
+
const next = String(value !== null && value !== void 0 ? value : '');
|
|
34
|
+
if (next !== draft)
|
|
35
|
+
setDraft(next);
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
+
}, [value]);
|
|
38
|
+
// Debounced search side-effect (never debounce the displayed input)
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!onSearch)
|
|
41
|
+
return;
|
|
42
|
+
if (!debounce) {
|
|
43
|
+
setSearchQuery(draft);
|
|
44
|
+
onSearch(draft);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const handler = setTimeout(() => {
|
|
48
|
+
setSearchQuery(draft);
|
|
49
|
+
onSearch(draft);
|
|
50
|
+
}, debounceMs);
|
|
51
|
+
return () => clearTimeout(handler);
|
|
52
|
+
}, [draft, onSearch, debounce, debounceMs]);
|
|
53
|
+
// Keyboard shortcut (Cmd/Ctrl + K)
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
function handleKeyDown(event) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (event.key === 'k' && (event.metaKey || event.ctrlKey)) {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
(_a = internalInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (enableHotkey) {
|
|
63
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
64
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
65
|
+
}
|
|
66
|
+
}, [enableHotkey]);
|
|
67
|
+
const handleChange = React.useCallback((e) => {
|
|
68
|
+
setDraft(e.target.value); // immediate UI update
|
|
69
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e); // allow parent to react if it wants (optional)
|
|
70
|
+
}, [onChange]);
|
|
71
|
+
const handleSelect = React.useCallback((item) => {
|
|
72
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(item);
|
|
73
|
+
reset();
|
|
74
|
+
}, [onSelect]);
|
|
75
|
+
function reset() {
|
|
76
|
+
var _a;
|
|
77
|
+
setDraft(''); // always clear UI immediately
|
|
78
|
+
setSearchQuery('');
|
|
79
|
+
(_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
135
80
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
81
|
+
// Props for the input are now created inside useMemo to avoid unnecessary dependency changes
|
|
82
|
+
const inputField = useMemo(() => {
|
|
83
|
+
var _a;
|
|
84
|
+
const inputProps = {
|
|
85
|
+
...rest,
|
|
86
|
+
value: draft,
|
|
87
|
+
onChange: handleChange,
|
|
88
|
+
};
|
|
89
|
+
if (displayPopover) {
|
|
90
|
+
return (_jsx(Popover, { ref: popoverRef, minWidth: popoverMinWidth, trigger: event => {
|
|
91
|
+
var _a;
|
|
92
|
+
return (_jsx(Input, { ref: internalInputRef, onFocusCapture: event, onClick: event, minWidth: inputWidth !== null && inputWidth !== void 0 ? inputWidth : '300px', width: inputWidth !== null && inputWidth !== void 0 ? inputWidth : '300px', icon: _jsx(Search, {}), inputSize: inputSize, variant: variant, ...inputProps, placeholder: (_a = rest.placeholder) !== null && _a !== void 0 ? _a : 'Indtast søgeord' }));
|
|
93
|
+
}, children: resultTemplate ? (resultTemplate) : (result === null || result === void 0 ? void 0 : result.length) ? (_jsx(Menu, { children: _jsx("table", { children: _jsx("tbody", { children: result.map((item, index) => (_jsx("tr", { onClick: () => handleSelect(item), role: "button", tabIndex: 0, children: resultKeys === null || resultKeys === void 0 ? void 0 : resultKeys.map(key => {
|
|
94
|
+
const raw = item[key];
|
|
95
|
+
const cell = raw != null ? String(raw) : '';
|
|
96
|
+
return (_jsx("td", { style: { whiteSpace: cell.length < 10 ? 'nowrap' : undefined }, children: cell }, key));
|
|
97
|
+
}) }, index))) }) }) })) : !searchQuery && !loading ? (initialTemplate || _jsx("div", { className: styles.resultContainer, children: "Indtast s\u00F8geord" })) : loading ? (_jsx("table", { style: { width: '100%' }, children: _jsx("tbody", { children: Array.from({ length: 5 }).map((_, index) => (_jsx("tr", { children: resultKeys === null || resultKeys === void 0 ? void 0 : resultKeys.map(key => (_jsx("td", { style: { padding: '8px' }, children: _jsx(SkeletonLoaderItem, { height: 20, width: "100%" }) }, key))) }, index))) }) })) : (_jsx("div", { className: styles.resultContainer, children: noResultText })) }));
|
|
98
|
+
}
|
|
99
|
+
return (_jsx(Input, { ref: internalInputRef, icon: _jsx(Search, {}), minWidth: inputWidth !== null && inputWidth !== void 0 ? inputWidth : '300px', inputSize: inputSize, variant: variant, ...inputProps, placeholder: (_a = rest.placeholder) !== null && _a !== void 0 ? _a : 'Indtast søgeord' }));
|
|
100
|
+
}, [
|
|
101
|
+
rest,
|
|
102
|
+
draft,
|
|
103
|
+
handleChange,
|
|
104
|
+
displayPopover,
|
|
105
|
+
inputWidth,
|
|
142
106
|
inputSize,
|
|
143
107
|
variant,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
searchQuery,
|
|
156
|
-
loading,
|
|
157
|
-
inputWidth,
|
|
158
|
-
inputSize,
|
|
159
|
-
variant,
|
|
160
|
-
inputProps,
|
|
161
|
-
rest.placeholder
|
|
162
|
-
]);
|
|
163
|
-
return onButtonClick ? /* @__PURE__ */ jsxs("div", { className: styles.withButton, children: [
|
|
164
|
-
inputField,
|
|
165
|
-
/* @__PURE__ */ jsx(Button, { variant: "outlined", icon: /* @__PURE__ */ jsx(Search, {}), onClick: onButtonClick })
|
|
166
|
-
] }) : /* @__PURE__ */ jsx("div", { children: inputField });
|
|
108
|
+
popoverMinWidth,
|
|
109
|
+
resultTemplate,
|
|
110
|
+
result,
|
|
111
|
+
searchQuery,
|
|
112
|
+
loading,
|
|
113
|
+
initialTemplate,
|
|
114
|
+
noResultText,
|
|
115
|
+
resultKeys,
|
|
116
|
+
handleSelect,
|
|
117
|
+
]);
|
|
118
|
+
return onButtonClick ? (_jsxs("div", { className: styles.withButton, children: [inputField, _jsx(Button, { variant: "outlined", icon: _jsx(Search, {}), onClick: onButtonClick })] })) : (_jsx("div", { children: inputField }));
|
|
167
119
|
});
|
|
168
|
-
|
|
169
|
-
export { SearchBox };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { TooltipPlacement } from '../../components/overlay/tooltip/TooltipProvider';
|
|
2
3
|
import type { Severity } from '../../constants/severity.types';
|
|
3
|
-
import { type TooltipPlacement } from '../tooltip/Tooltip';
|
|
4
4
|
export type Segment = {
|
|
5
5
|
value: number;
|
|
6
6
|
severity?: Severity;
|
|
@@ -1,97 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useTooltipTrigger } from '../../components/overlay/tooltip/useTooltipTrigger';
|
|
2
4
|
import { SeverityBgColor, SeverityTextColor } from '../../constants/severity';
|
|
3
|
-
import { Tooltip } from '../tooltip/Tooltip';
|
|
4
5
|
import styles from './SegmentedProgressBar.module.css';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
height: height ? `${height}px` : `var(--component-size-xs)`,
|
|
50
|
-
borderRadius: rounded ? `var(--border-radius-rounded)` : `var(--border-radius-none)`,
|
|
51
|
-
background: trackColor
|
|
52
|
-
},
|
|
53
|
-
children: [
|
|
54
|
-
/* @__PURE__ */ jsx("span", { className: styles.segmentsContainer, children: filteredSergments == null ? void 0 : filteredSergments.map((seg, i) => {
|
|
55
|
-
var _a, _b, _c, _d, _e;
|
|
56
|
-
const bg = (_b = seg.color) != null ? _b : SeverityBgColor[(_a = seg.severity) != null ? _a : "neutral"];
|
|
57
|
-
const fg = SeverityTextColor[(_c = seg.severity) != null ? _c : "neutral"];
|
|
58
|
-
const tooltipText = typeof seg.label !== "undefined" ? seg.label : String((_d = seg.value) != null ? _d : 0);
|
|
59
|
-
return /* @__PURE__ */ jsx(
|
|
60
|
-
Tooltip,
|
|
61
|
-
{
|
|
62
|
-
content: tooltipText,
|
|
63
|
-
placement: tooltipPlacement,
|
|
64
|
-
className: styles.segmentWrapper,
|
|
65
|
-
style: {
|
|
66
|
-
flex: `${Math.max(seg.value || 0, 0)} 0 0`,
|
|
67
|
-
height: "100%",
|
|
68
|
-
minWidth: "2px"
|
|
69
|
-
},
|
|
70
|
-
children: /* @__PURE__ */ jsx(
|
|
71
|
-
"div",
|
|
72
|
-
{
|
|
73
|
-
className: styles.progressSegment,
|
|
74
|
-
"data-index": i,
|
|
75
|
-
"data-severity": (_e = seg.severity) != null ? _e : "neutral",
|
|
76
|
-
style: { background: bg, color: fg }
|
|
77
|
-
}
|
|
78
|
-
)
|
|
79
|
-
},
|
|
80
|
-
`${i}`
|
|
81
|
-
);
|
|
82
|
-
}) }),
|
|
83
|
-
/* @__PURE__ */ jsx(
|
|
84
|
-
"div",
|
|
85
|
-
{
|
|
86
|
-
className: `${styles.progressCenter} ${(filteredSergments == null ? void 0 : filteredSergments.length) === 0 ? styles.emptySegments : ""}`,
|
|
87
|
-
children: centerLabel ? typeof centerLabel === "function" ? centerLabel(pctFilled) : centerLabel : autoNumbers
|
|
88
|
-
}
|
|
89
|
-
)
|
|
90
|
-
]
|
|
91
|
-
}
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
);
|
|
6
|
+
function SegmentWithTooltip({ seg, index, tooltipPlacement, }) {
|
|
7
|
+
var _a, _b, _c, _d, _e;
|
|
8
|
+
const bg = (_a = seg.color) !== null && _a !== void 0 ? _a : SeverityBgColor[(_b = seg.severity) !== null && _b !== void 0 ? _b : 'neutral'];
|
|
9
|
+
const fg = SeverityTextColor[(_c = seg.severity) !== null && _c !== void 0 ? _c : 'neutral'];
|
|
10
|
+
const tooltipContent = typeof seg.label !== 'undefined' ? seg.label : String((_d = seg.value) !== null && _d !== void 0 ? _d : 0);
|
|
11
|
+
const tooltipEnabled = tooltipContent !== null && tooltipContent !== undefined && tooltipContent !== '';
|
|
12
|
+
const { triggerProps } = useTooltipTrigger({
|
|
13
|
+
content: tooltipEnabled ? tooltipContent : null,
|
|
14
|
+
placement: tooltipPlacement,
|
|
15
|
+
offset: 8,
|
|
16
|
+
});
|
|
17
|
+
return (_jsx("span", { className: styles.segmentWrapper, style: {
|
|
18
|
+
flex: `${Math.max(seg.value || 0, 0)} 0 0`,
|
|
19
|
+
height: '100%',
|
|
20
|
+
minWidth: '2px',
|
|
21
|
+
}, ...(tooltipEnabled ? triggerProps : {}), children: _jsx("div", { className: styles.progressSegment, "data-index": index, "data-severity": (_e = seg.severity) !== null && _e !== void 0 ? _e : 'neutral', style: { background: bg, color: fg } }) }));
|
|
22
|
+
}
|
|
23
|
+
export const SegmentedProgressBar = ({ segments, total, showRemainder = true, remainderSeverity = 'neutral', centerLabel, height, rounded = true, trackColor = 'var(--color-neutral)', tooltipPlacement = 'top', className, ...aria }) => {
|
|
24
|
+
const sum = segments.reduce((acc, s) => acc + (s.value || 0), 0);
|
|
25
|
+
const effectiveTotal = total !== null && total !== void 0 ? total : sum;
|
|
26
|
+
const safeTotal = Math.max(effectiveTotal, 0.0001);
|
|
27
|
+
const remainder = Math.max(effectiveTotal - sum, 0);
|
|
28
|
+
const pctFilled = Math.min(100, Math.max(0, (Math.min(sum, effectiveTotal) / safeTotal) * 100));
|
|
29
|
+
const computedSegments = [
|
|
30
|
+
...segments,
|
|
31
|
+
...(showRemainder && remainder > 0 ? [{ value: remainder, severity: remainderSeverity }] : []),
|
|
32
|
+
];
|
|
33
|
+
const autoNumbers = (() => {
|
|
34
|
+
const base = segments.map(s => s.value || 0);
|
|
35
|
+
if (showRemainder)
|
|
36
|
+
base.push(remainder);
|
|
37
|
+
return base.join('/');
|
|
38
|
+
})();
|
|
39
|
+
const rootClass = [styles.container, className].filter(Boolean).join(' ');
|
|
40
|
+
const filteredSegments = computedSegments.filter(x => x.value > 0);
|
|
41
|
+
return (_jsx("div", { className: rootClass, role: "progressbar", "aria-valuemin": 0, "aria-valuemax": effectiveTotal, "aria-valuenow": Math.min(sum, effectiveTotal), ...aria, children: _jsxs("div", { className: styles.progressBar, style: {
|
|
42
|
+
height: height ? `${height}px` : `var(--component-size-xs)`,
|
|
43
|
+
borderRadius: rounded ? `var(--border-radius-rounded)` : `var(--border-radius-none)`,
|
|
44
|
+
background: trackColor,
|
|
45
|
+
}, children: [_jsx("span", { className: styles.segmentsContainer, children: filteredSegments.map((seg, i) => (_jsx(SegmentWithTooltip, { seg: seg, index: i, tooltipPlacement: tooltipPlacement }, `${i}`))) }), _jsx("div", { className: `${styles.progressCenter} ${filteredSegments.length === 0 ? styles.emptySegments : ''}`, children: centerLabel
|
|
46
|
+
? typeof centerLabel === 'function'
|
|
47
|
+
? centerLabel(pctFilled)
|
|
48
|
+
: centerLabel
|
|
49
|
+
: autoNumbers })] }) }));
|
|
95
50
|
};
|
|
96
|
-
|
|
97
|
-
export { SegmentedProgressBar };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { SidebarContainer } from './components/sidebar-container/SidebarContainer';
|
|
4
|
-
|
|
5
|
-
function Sidebar({ items, productLogo, activeLink }) {
|
|
6
|
-
|
|
4
|
+
import { SidebarProvider } from './providers/SidebarProvider';
|
|
5
|
+
export function Sidebar({ items, productLogo, activeLink }) {
|
|
6
|
+
return (_jsx(SidebarProvider, { items: items, children: _jsx(SidebarContainer, { productLogo: productLogo, activeLink: activeLink }) }));
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
export { Sidebar };
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { jsx } from
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { SidebarItemContent } from './sidebar-item-content/SidebarItemContent';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
href
|
|
9
|
-
}) {
|
|
10
|
-
if (!Component) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
return /* @__PURE__ */ jsx(Component, { children: /* @__PURE__ */ jsx(SidebarItemContent, { icon, label, href }) });
|
|
3
|
+
export function SidebarItem({ component: Component, label, icon, href, }) {
|
|
4
|
+
if (!Component) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return (_jsx(Component, { children: _jsx(SidebarItemContent, { icon: icon, label: label, href: href }) }));
|
|
14
8
|
}
|
|
15
|
-
|
|
16
|
-
export { SidebarItem };
|
|
@@ -1,94 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { SidebarItemContent } from '../sidebar-item-content/SidebarItemContent';
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
3
|
import { ChevronDown } from 'lucide-react';
|
|
4
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
5
5
|
import styles from './ExpandableSidebarItem.module.css';
|
|
6
|
+
import { Button } from '../../../button/Button';
|
|
6
7
|
import { useSidebar } from '../../providers/SidebarProvider';
|
|
8
|
+
import { SidebarItemContent } from '../sidebar-item-content/SidebarItemContent';
|
|
7
9
|
import { SidebarItem } from '../SidebarItem';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
10
|
+
export function ExpandableSidebarItem({ items, label, icon, component: Component, href, }) {
|
|
11
|
+
const { defaultExpanded, resetExpandAll, isSidebarCollapsed, handleSidebarCollapseChange, expandedItems, } = useSidebar();
|
|
12
|
+
const [expanded, setExpanded] = useState(false);
|
|
13
|
+
const [closing, setClosing] = useState(false);
|
|
14
|
+
const [ready, setReady] = useState(false);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
setReady(true);
|
|
17
|
+
}, []);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (expandedItems.has(href)) {
|
|
20
|
+
setExpanded(true);
|
|
21
|
+
}
|
|
22
|
+
}, [expandedItems, href]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (defaultExpanded === null) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
setExpanded(defaultExpanded);
|
|
28
|
+
}, [defaultExpanded]);
|
|
29
|
+
const handleAnimationEnd = useCallback(() => {
|
|
30
|
+
if (ready) {
|
|
31
|
+
setExpanded(!closing);
|
|
32
|
+
setClosing(false);
|
|
33
|
+
}
|
|
34
|
+
}, [closing, ready]);
|
|
35
|
+
const toggleAccordion = useCallback((e, onlyExpand = false) => {
|
|
36
|
+
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
37
|
+
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
38
|
+
resetExpandAll();
|
|
39
|
+
handleSidebarCollapseChange === null || handleSidebarCollapseChange === void 0 ? void 0 : handleSidebarCollapseChange(false);
|
|
40
|
+
if (!expanded) {
|
|
41
|
+
setExpanded(true);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!isSidebarCollapsed && !onlyExpand) {
|
|
45
|
+
setClosing(true);
|
|
46
|
+
}
|
|
47
|
+
}, [expanded, handleSidebarCollapseChange, isSidebarCollapsed, resetExpandAll]);
|
|
48
|
+
if (!items)
|
|
49
|
+
return null;
|
|
50
|
+
if (!Component) {
|
|
51
|
+
return null;
|
|
45
52
|
}
|
|
46
|
-
|
|
47
|
-
const toggleAccordion = useCallback(
|
|
48
|
-
(e, onlyExpand = false) => {
|
|
49
|
-
e == null ? void 0 : e.preventDefault();
|
|
50
|
-
e == null ? void 0 : e.stopPropagation();
|
|
51
|
-
resetExpandAll();
|
|
52
|
-
handleSidebarCollapseChange == null ? void 0 : handleSidebarCollapseChange(false);
|
|
53
|
-
if (!expanded) {
|
|
54
|
-
setExpanded(true);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (!isSidebarCollapsed && !onlyExpand) {
|
|
58
|
-
setClosing(true);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
[expanded]
|
|
62
|
-
);
|
|
63
|
-
if (!items) return null;
|
|
64
|
-
if (!Component) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
return /* @__PURE__ */ jsxs("div", { className: `${styles.container} ${expanded ? styles.expanded : ""}`, children: [
|
|
68
|
-
/* @__PURE__ */ jsx(Component, { onClick: () => toggleAccordion(void 0, true), children: /* @__PURE__ */ jsx(
|
|
69
|
-
SidebarItemContent,
|
|
70
|
-
{
|
|
71
|
-
icon,
|
|
72
|
-
label,
|
|
73
|
-
href,
|
|
74
|
-
disableActiveStyles: expanded,
|
|
75
|
-
suffixIcon: isSidebarCollapsed ? null : /* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: toggleAccordion, children: /* @__PURE__ */ jsx(
|
|
76
|
-
ChevronDown,
|
|
77
|
-
{
|
|
78
|
-
className: `${styles.chevron} ${expanded ? styles.chevronExpanded : ""}`
|
|
79
|
-
}
|
|
80
|
-
) })
|
|
81
|
-
}
|
|
82
|
-
) }),
|
|
83
|
-
expanded && !isSidebarCollapsed && /* @__PURE__ */ jsx(
|
|
84
|
-
"div",
|
|
85
|
-
{
|
|
86
|
-
onAnimationEnd: handleAnimationEnd,
|
|
87
|
-
className: `${styles.childrenContainer} ${closing ? "animate--collapse" : ""} ${expanded ? "animate--expand" : "visually-hidden"}`,
|
|
88
|
-
children: items.map(({ component: Component2, label: label2, icon: icon2, href: href2 }, id) => /* @__PURE__ */ jsx(SidebarItem, { component: Component2, label: label2, icon: icon2, href: href2 }, id))
|
|
89
|
-
}
|
|
90
|
-
)
|
|
91
|
-
] });
|
|
53
|
+
return (_jsxs("div", { className: `${styles.container} ${expanded ? styles.expanded : ''}`, children: [_jsx(Component, { onClick: () => toggleAccordion(undefined, true), children: _jsx(SidebarItemContent, { icon: icon, label: label, href: href, disableActiveStyles: expanded, suffixIcon: isSidebarCollapsed ? null : (_jsx(Button, { variant: "outlined", onClick: toggleAccordion, children: _jsx(ChevronDown, { className: `${styles.chevron} ${expanded ? styles.chevronExpanded : ''}` }) })) }) }), expanded && !isSidebarCollapsed && (_jsx("div", { onAnimationEnd: handleAnimationEnd, className: `${styles.childrenContainer} ${closing ? 'animate--collapse' : ''} ${expanded ? 'animate--expand' : 'visually-hidden'}`, children: items.map(({ component: Component, label, icon, href }, id) => (_jsx(SidebarItem, { component: Component, label: label, icon: icon, href: href }, id))) }))] }));
|
|
92
54
|
}
|
|
93
|
-
|
|
94
|
-
export { ExpandableSidebarItem };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { ReactNode, JSX } from 'react';
|
|
1
2
|
interface SidebarContainerProps {
|
|
2
|
-
logo?:
|
|
3
|
+
logo?: ReactNode;
|
|
3
4
|
productName?: string;
|
|
4
|
-
productLogo?:
|
|
5
|
+
productLogo?: ReactNode;
|
|
5
6
|
activeLink?: string;
|
|
6
7
|
}
|
|
7
8
|
export declare function SidebarContainer({ logo, productName, productLogo, activeLink, }: SidebarContainerProps): JSX.Element;
|