@dbcdk/react-components 0.0.96 → 0.0.97
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/components/table/Table.d.ts +1 -1
- package/dist/components/table/Table.types.d.ts +3 -0
- package/dist/components/table/components/TableHeader.d.ts +2 -1
- package/dist/index.cjs +12750 -0
- package/dist/index.css +7149 -0
- package/dist/index.js +12641 -79
- package/dist/tanstack.cjs +2674 -0
- package/dist/tanstack.css +1267 -0
- package/dist/tanstack.js +2650 -3
- package/dist/themes/dbc.css +3 -0
- package/dist/themes/forfatterweb.css +2 -0
- package/package.json +11 -10
- package/dist/assets/logo.js +0 -2
- package/dist/components/__stories__/_data/table.d.ts +0 -15
- package/dist/components/__stories__/_data/table.js +0 -55
- package/dist/components/__stories__/_data/tabs.d.ts +0 -9
- package/dist/components/__stories__/_data/tabs.js +0 -31
- package/dist/components/__stories__/story-components/Colors.d.ts +0 -11
- package/dist/components/__stories__/story-components/Colors.js +0 -96
- package/dist/components/__stories__/story-components/Colors.module.css +0 -27
- package/dist/components/__stories__/story-components/ComponentSizes.d.ts +0 -2
- package/dist/components/__stories__/story-components/ComponentSizes.js +0 -26
- package/dist/components/__stories__/story-components/Elevation.d.ts +0 -2
- package/dist/components/__stories__/story-components/Elevation.js +0 -49
- package/dist/components/__stories__/story-components/Flex.d.ts +0 -2
- package/dist/components/__stories__/story-components/Flex.js +0 -177
- package/dist/components/__stories__/story-components/Flex.module.css +0 -317
- package/dist/components/__stories__/story-components/Spacing.d.ts +0 -6
- package/dist/components/__stories__/story-components/Spacing.js +0 -76
- package/dist/components/__stories__/story-components/Spacing.module.css +0 -154
- package/dist/components/accordion/Accordion.js +0 -70
- package/dist/components/accordion/Accordion.module.css +0 -28
- package/dist/components/accordion/components/AccordionRow.js +0 -53
- package/dist/components/accordion/components/AccordionRow.module.css +0 -90
- package/dist/components/alert/Alert.js +0 -17
- package/dist/components/alert/Alert.module.css +0 -98
- package/dist/components/app-header/AppHeader.js +0 -5
- package/dist/components/app-header/AppHeader.module.css +0 -74
- package/dist/components/attribute-chip/AttributeChip.js +0 -5
- package/dist/components/attribute-chip/AttributeChip.module.css +0 -65
- package/dist/components/avatar/Avatar.js +0 -48
- package/dist/components/avatar/Avatar.module.css +0 -91
- package/dist/components/breadcrumbs/Breadcrumbs.js +0 -6
- package/dist/components/breadcrumbs/Breadcrumbs.module.css +0 -80
- package/dist/components/button/Button.js +0 -81
- package/dist/components/button/Button.module.css +0 -249
- package/dist/components/button-select/ButtonSelect.js +0 -7
- package/dist/components/button-select/ButtonSelect.module.css +0 -40
- package/dist/components/card/Card.js +0 -71
- package/dist/components/card/Card.module.css +0 -160
- package/dist/components/card/components/CardMeta.js +0 -26
- package/dist/components/card/components/CardMeta.module.css +0 -55
- package/dist/components/card-container/CardContainer.js +0 -6
- package/dist/components/card-container/CardContainer.module.css +0 -61
- package/dist/components/chip/Chip.js +0 -31
- package/dist/components/chip/Chip.module.css +0 -236
- package/dist/components/circle/Circle.js +0 -5
- package/dist/components/circle/Circle.module.css +0 -128
- package/dist/components/clear-button/ClearButton.js +0 -13
- package/dist/components/clear-button/ClearButton.module.css +0 -26
- package/dist/components/code-block/CodeBlock.js +0 -58
- package/dist/components/code-block/CodeBlock.module.css +0 -124
- package/dist/components/copy-button/CopyButton.js +0 -78
- package/dist/components/copy-button/CopyButton.module.css +0 -22
- package/dist/components/datetime-picker/DateTimePicker.js +0 -403
- package/dist/components/datetime-picker/DateTimePicker.module.css +0 -155
- package/dist/components/datetime-picker/dateTimeHelpers.js +0 -248
- package/dist/components/divider/Divider.js +0 -12
- package/dist/components/filter-field/FilterField.js +0 -191
- package/dist/components/filter-field/FilterField.module.css +0 -379
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.js +0 -52
- package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.module.css +0 -59
- package/dist/components/forms/checkbox/Checkbox.js +0 -28
- package/dist/components/forms/checkbox/Checkbox.module.css +0 -103
- package/dist/components/forms/checkbox-group/CheckboxGroup.js +0 -75
- package/dist/components/forms/checkbox-group/CheckboxGroup.module.css +0 -115
- package/dist/components/forms/form-select/FormSelect.js +0 -86
- package/dist/components/forms/form-select/FormSelect.module.css +0 -236
- package/dist/components/forms/input/Input.js +0 -77
- package/dist/components/forms/input/Input.module.css +0 -468
- package/dist/components/forms/input-container/InputContainer.js +0 -15
- package/dist/components/forms/input-container/InputContainer.module.css +0 -60
- package/dist/components/forms/multi-select/MultiSelect.js +0 -122
- package/dist/components/forms/radio-buttons/RadioButton.js +0 -26
- package/dist/components/forms/radio-buttons/RadioButtonGroup.js +0 -19
- package/dist/components/forms/radio-buttons/RadioButtons.module.css +0 -118
- package/dist/components/forms/select/Select.js +0 -185
- package/dist/components/forms/select/Select.module.css +0 -32
- package/dist/components/forms/text-area/Textarea.js +0 -47
- package/dist/components/forms/text-area/Textarea.module.css +0 -70
- package/dist/components/forms/typeahead/Typeahead.js +0 -668
- package/dist/components/forms/typeahead/Typeahead.module.css +0 -38
- package/dist/components/grid/Grid.js +0 -23
- package/dist/components/grid/Grid.module.css +0 -35
- package/dist/components/headline/CollapsibleHeadline.js +0 -29
- package/dist/components/headline/Headline.js +0 -26
- package/dist/components/headline/Headline.module.css +0 -185
- package/dist/components/hyperlink/Hyperlink.js +0 -40
- package/dist/components/hyperlink/Hyperlink.module.css +0 -107
- package/dist/components/icon/Icon.js +0 -14
- package/dist/components/icon/Icon.module.css +0 -36
- package/dist/components/interval-select/IntervalSelect.js +0 -99
- package/dist/components/json-viewer/HighlightedText.js +0 -6
- package/dist/components/json-viewer/JsonNode.js +0 -30
- package/dist/components/json-viewer/JsonViewer.js +0 -68
- package/dist/components/json-viewer/JsonViewer.module.css +0 -346
- package/dist/components/json-viewer/types.js +0 -1
- package/dist/components/json-viewer/useClipboardStatus.js +0 -11
- package/dist/components/json-viewer/utils.js +0 -125
- package/dist/components/menu/Menu.js +0 -165
- package/dist/components/menu/Menu.module.css +0 -220
- package/dist/components/meta-bar/MetaBar.js +0 -9
- package/dist/components/meta-bar/MetaBar.module.css +0 -27
- package/dist/components/nav-bar/NavBar.js +0 -29
- package/dist/components/nav-bar/NavBar.module.css +0 -221
- package/dist/components/overlay/fade-overlay/FadeOverlay.js +0 -8
- package/dist/components/overlay/fade-overlay/FadeOverlay.module.css +0 -54
- package/dist/components/overlay/modal/Modal.js +0 -115
- package/dist/components/overlay/modal/Modal.module.css +0 -109
- package/dist/components/overlay/modal/provider/ModalProvider.js +0 -73
- package/dist/components/overlay/side-panel/SidePanel.js +0 -83
- package/dist/components/overlay/side-panel/SidePanel.module.css +0 -177
- package/dist/components/overlay/side-panel/useSidePanel.js +0 -11
- package/dist/components/overlay/tooltip/Tooltip.js +0 -17
- package/dist/components/overlay/tooltip/Tooltip.module.css +0 -104
- package/dist/components/overlay/tooltip/TooltipProvider.js +0 -255
- package/dist/components/overlay/tooltip/useTooltipTrigger.js +0 -118
- package/dist/components/page/Page.js +0 -11
- package/dist/components/page/Page.module.css +0 -89
- package/dist/components/page-layout/PageLayout.js +0 -76
- package/dist/components/page-layout/PageLayout.module.css +0 -236
- package/dist/components/page-layout/components/layout-footer/LayoutFooter.js +0 -27
- package/dist/components/page-layout/components/layout-footer/LayoutFooter.module.css +0 -89
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.js +0 -14
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.module.css +0 -84
- package/dist/components/pagination/Pagination.js +0 -56
- package/dist/components/pagination/Pagination.module.css +0 -25
- package/dist/components/panel/Panel.js +0 -7
- package/dist/components/panel/Panel.module.css +0 -29
- package/dist/components/popover/Popover.js +0 -257
- package/dist/components/popover/Popover.module.css +0 -54
- package/dist/components/search-box/SearchBox.js +0 -170
- package/dist/components/search-box/SearchBox.module.css +0 -21
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +0 -48
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.module.css +0 -167
- package/dist/components/sidebar/Sidebar.js +0 -6
- package/dist/components/sidebar/components/SidebarItem.js +0 -8
- package/dist/components/sidebar/components/SidebarItem.module.css +0 -0
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +0 -63
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +0 -29
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +0 -153
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +0 -260
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +0 -18
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +0 -106
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +0 -26
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.module.css +0 -20
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.js +0 -30
- package/dist/components/sidebar/providers/SidebarProvider.js +0 -229
- package/dist/components/skeleton-loader/SkeletonLoader.js +0 -73
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +0 -13
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +0 -51
- package/dist/components/split-button/SplitButton.js +0 -10
- package/dist/components/split-button/SplitButton.module.css +0 -32
- package/dist/components/split-pane/SplitPane.js +0 -107
- package/dist/components/split-pane/SplitPane.module.css +0 -111
- package/dist/components/split-pane/provider/SplitPaneContext.js +0 -124
- package/dist/components/stack/Stack.js +0 -33
- package/dist/components/stack/Stack.module.css +0 -61
- package/dist/components/state-page/StatePage.js +0 -20
- package/dist/components/state-page/StatePage.module.css +0 -9
- package/dist/components/state-page/empty.js +0 -2
- package/dist/components/state-page/error.js +0 -2
- package/dist/components/state-page/notFound.js +0 -2
- package/dist/components/sticky-footer-layout/StickyFooterLayout.js +0 -64
- package/dist/components/table/Table.js +0 -50
- package/dist/components/table/Table.module.css +0 -536
- package/dist/components/table/Table.types.js +0 -1
- package/dist/components/table/TanstackTable.js +0 -111
- package/dist/components/table/components/TableBody.js +0 -10
- package/dist/components/table/components/TableHeader.js +0 -7
- package/dist/components/table/components/TableHeaderCell.js +0 -24
- package/dist/components/table/components/TableLoadingBody.js +0 -26
- package/dist/components/table/components/TablePagination.js +0 -1
- package/dist/components/table/components/TableRow.js +0 -54
- package/dist/components/table/components/TableSelectionCell.js +0 -16
- package/dist/components/table/components/column-resizer/ColumnResizer.js +0 -5
- package/dist/components/table/components/column-resizer/ColumnResizer.module.css +0 -22
- package/dist/components/table/components/empty-state/EmptyState.js +0 -23
- package/dist/components/table/components/empty-state/EmptyState.module.css +0 -4
- package/dist/components/table/components/table-settings/TableSettings.js +0 -63
- package/dist/components/table/hooks/useTableRowInteractions.js +0 -30
- package/dist/components/table/table.classes.js +0 -23
- package/dist/components/table/table.utils.js +0 -47
- package/dist/components/table/tanstackTable.utils.js +0 -175
- package/dist/components/tabs/Tabs.js +0 -125
- package/dist/components/tabs/Tabs.module.css +0 -233
- package/dist/components/theme-button/ThemeButton.js +0 -23
- package/dist/components/toast/Toast.js +0 -20
- package/dist/components/toast/Toast.module.css +0 -161
- package/dist/components/toast/provider/ToastProvider.js +0 -70
- package/dist/components/user-display/UserDisplay.js +0 -6
- package/dist/components/user-display/UserDisplay.module.css +0 -25
- package/dist/constants/severity.js +0 -24
- package/dist/constants/severity.types.js +0 -1
- package/dist/constants/sizes.js +0 -7
- package/dist/hooks/useDeviceSize.js +0 -32
- package/dist/hooks/useListNavigation.js +0 -234
- package/dist/hooks/usePagination.js +0 -140
- package/dist/hooks/useSorting.js +0 -118
- package/dist/hooks/useTableData.js +0 -45
- package/dist/hooks/useTableSelection.js +0 -164
- package/dist/hooks/useTableSettings.js +0 -71
- package/dist/hooks/useTheme.js +0 -66
- package/dist/hooks/useTimeDuration.js +0 -68
- package/dist/hooks/useViewportFill.js +0 -77
- package/dist/styles/animation.js +0 -5
- package/dist/styles/themes/types.js +0 -1
- package/dist/types/a11y-props.types.js +0 -1
- package/dist/types/sizes.types.js +0 -1
- package/dist/utils/arrays/nested-filtering.js +0 -48
- package/dist/utils/date/formatDate.js +0 -51
- package/dist/utils/localStorage.utils.js +0 -78
- package/dist/utils/text/get-highlighted-segments.js +0 -46
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { ChevronDown, ChevronUp } from 'lucide-react';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { forwardRef, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useRef, useState, } from 'react';
|
|
6
|
-
import { createPortal } from 'react-dom';
|
|
7
|
-
import styles from './Popover.module.css';
|
|
8
|
-
function assignRef(ref, value) {
|
|
9
|
-
if (!ref)
|
|
10
|
-
return;
|
|
11
|
-
if (typeof ref === 'function') {
|
|
12
|
-
ref(value);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
;
|
|
16
|
-
ref.current = value;
|
|
17
|
-
}
|
|
18
|
-
function getFocusable(container) {
|
|
19
|
-
const els = container.querySelectorAll([
|
|
20
|
-
'a[href]',
|
|
21
|
-
'button:not([disabled])',
|
|
22
|
-
'input:not([disabled])',
|
|
23
|
-
'select:not([disabled])',
|
|
24
|
-
'textarea:not([disabled])',
|
|
25
|
-
'[tabindex]:not([tabindex="-1"])',
|
|
26
|
-
].join(','));
|
|
27
|
-
return Array.from(els).filter(el => !el.hasAttribute('disabled') && !el.getAttribute('aria-hidden'));
|
|
28
|
-
}
|
|
29
|
-
function parseMinWidthPx(minWidth, elForEm) {
|
|
30
|
-
const v = minWidth.trim();
|
|
31
|
-
if (v.endsWith('px')) {
|
|
32
|
-
const n = Number.parseFloat(v);
|
|
33
|
-
return Number.isFinite(n) ? n : 0;
|
|
34
|
-
}
|
|
35
|
-
if (typeof window !== 'undefined' && v.endsWith('rem')) {
|
|
36
|
-
const n = Number.parseFloat(v);
|
|
37
|
-
if (!Number.isFinite(n))
|
|
38
|
-
return 0;
|
|
39
|
-
const rootFont = Number.parseFloat(getComputedStyle(document.documentElement).fontSize || '16');
|
|
40
|
-
return n * (Number.isFinite(rootFont) ? rootFont : 16);
|
|
41
|
-
}
|
|
42
|
-
if (typeof window !== 'undefined' && v.endsWith('em')) {
|
|
43
|
-
const n = Number.parseFloat(v);
|
|
44
|
-
if (!Number.isFinite(n))
|
|
45
|
-
return 0;
|
|
46
|
-
const font = elForEm ? Number.parseFloat(getComputedStyle(elForEm).fontSize || '16') : 16;
|
|
47
|
-
return n * (Number.isFinite(font) ? font : 16);
|
|
48
|
-
}
|
|
49
|
-
return 0;
|
|
50
|
-
}
|
|
51
|
-
export const Popover = forwardRef(function Popover({ trigger: Trigger, children, open, defaultOpen = false, onOpenChange, contentId, minWidth = '200px', matchTriggerWidth = true, viewportPadding = 8, contentMaxHeightPx = 400, edgeBuffer = 100, dataCy, fullWidth = false, fillTrigger = false, autoFocusContent = false, returnFocus = true, anchorRef, overlayRef, }, ref) {
|
|
52
|
-
const internalId = useId();
|
|
53
|
-
const resolvedContentId = contentId !== null && contentId !== void 0 ? contentId : `popover-${internalId}`;
|
|
54
|
-
const isControlled = open !== undefined;
|
|
55
|
-
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
|
|
56
|
-
const isOpen = isControlled ? !!open : uncontrolledOpen;
|
|
57
|
-
const [pos, setPos] = useState({ top: 0, left: 0 });
|
|
58
|
-
const [positioned, setPositioned] = useState(false);
|
|
59
|
-
const [triggerWidth, setTriggerWidth] = useState(null);
|
|
60
|
-
const containerRef = useRef(null);
|
|
61
|
-
const contentRef = useRef(null);
|
|
62
|
-
const triggerElRef = useRef(null);
|
|
63
|
-
const lastCloseReasonRef = useRef('unknown');
|
|
64
|
-
const [mounted, setMounted] = useState(false);
|
|
65
|
-
useEffect(() => setMounted(true), []);
|
|
66
|
-
const setOpen = useCallback((next) => {
|
|
67
|
-
if (!isControlled)
|
|
68
|
-
setUncontrolledOpen(next);
|
|
69
|
-
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(next);
|
|
70
|
-
}, [isControlled, onOpenChange]);
|
|
71
|
-
const openPopover = useCallback(() => {
|
|
72
|
-
setPositioned(false);
|
|
73
|
-
setOpen(true);
|
|
74
|
-
}, [setOpen]);
|
|
75
|
-
const closePopover = useCallback((reason = 'api') => {
|
|
76
|
-
lastCloseReasonRef.current = reason;
|
|
77
|
-
setOpen(false);
|
|
78
|
-
}, [setOpen]);
|
|
79
|
-
const togglePopover = useCallback((e) => {
|
|
80
|
-
var _a, _b;
|
|
81
|
-
triggerElRef.current =
|
|
82
|
-
(_b = (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : e.currentTarget) !== null && _b !== void 0 ? _b : containerRef.current;
|
|
83
|
-
if (isOpen)
|
|
84
|
-
closePopover('trigger');
|
|
85
|
-
else
|
|
86
|
-
openPopover();
|
|
87
|
-
}, [isOpen, closePopover, openPopover, anchorRef]);
|
|
88
|
-
useImperativeHandle(ref, () => ({
|
|
89
|
-
close: () => closePopover('api'),
|
|
90
|
-
open: openPopover,
|
|
91
|
-
isOpen: () => isOpen,
|
|
92
|
-
}), [closePopover, openPopover, isOpen]);
|
|
93
|
-
const computeAndSetPosition = useCallback(() => {
|
|
94
|
-
var _a, _b;
|
|
95
|
-
const content = contentRef.current;
|
|
96
|
-
if (!content)
|
|
97
|
-
return;
|
|
98
|
-
const triggerEl = (_b = (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : triggerElRef.current) !== null && _b !== void 0 ? _b : containerRef.current;
|
|
99
|
-
if (!triggerEl)
|
|
100
|
-
return;
|
|
101
|
-
const triggerRect = triggerEl.getBoundingClientRect();
|
|
102
|
-
const overlayWidthBuffer = 8;
|
|
103
|
-
let forcedWidthPx = null;
|
|
104
|
-
if (matchTriggerWidth) {
|
|
105
|
-
const minWidthPx = parseMinWidthPx(minWidth, triggerEl);
|
|
106
|
-
forcedWidthPx = Math.max(triggerRect.width + overlayWidthBuffer, minWidthPx || 0);
|
|
107
|
-
setTriggerWidth(forcedWidthPx);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
setTriggerWidth(null);
|
|
111
|
-
}
|
|
112
|
-
const prevHidden = content.hidden;
|
|
113
|
-
const prevVis = content.style.visibility;
|
|
114
|
-
const prevDisp = content.style.display;
|
|
115
|
-
const prevMinWidth = content.style.minWidth;
|
|
116
|
-
const prevWidth = content.style.width;
|
|
117
|
-
const prevTop = content.style.top;
|
|
118
|
-
const prevLeft = content.style.left;
|
|
119
|
-
content.hidden = false;
|
|
120
|
-
content.style.visibility = 'hidden';
|
|
121
|
-
content.style.display = 'block';
|
|
122
|
-
content.style.top = '0px';
|
|
123
|
-
content.style.left = '0px';
|
|
124
|
-
content.style.minWidth = minWidth;
|
|
125
|
-
content.style.width = forcedWidthPx != null ? `${forcedWidthPx}px` : 'auto';
|
|
126
|
-
const contentWidth = content.offsetWidth;
|
|
127
|
-
const contentHeight = content.offsetHeight;
|
|
128
|
-
content.hidden = prevHidden;
|
|
129
|
-
content.style.visibility = prevVis;
|
|
130
|
-
content.style.display = prevDisp;
|
|
131
|
-
content.style.minWidth = prevMinWidth;
|
|
132
|
-
content.style.width = prevWidth;
|
|
133
|
-
content.style.top = prevTop;
|
|
134
|
-
content.style.left = prevLeft;
|
|
135
|
-
const vw = window.innerWidth;
|
|
136
|
-
const vh = window.innerHeight;
|
|
137
|
-
const spaceAbove = Math.max(0, triggerRect.top);
|
|
138
|
-
const spaceBelow = Math.max(0, vh - triggerRect.bottom);
|
|
139
|
-
const spaceLeft = Math.max(0, triggerRect.left);
|
|
140
|
-
const spaceRight = Math.max(0, vw - triggerRect.right);
|
|
141
|
-
const preferBelow = spaceBelow >= contentHeight + edgeBuffer || spaceBelow >= spaceAbove;
|
|
142
|
-
const spacing = viewportPadding;
|
|
143
|
-
const rawTop = preferBelow
|
|
144
|
-
? triggerRect.bottom + spacing
|
|
145
|
-
: triggerRect.top - contentHeight - spacing;
|
|
146
|
-
const placeRightOfLeftEdge = spaceRight >= contentWidth + edgeBuffer;
|
|
147
|
-
const placeLeftOfRightEdge = spaceLeft >= contentWidth + edgeBuffer;
|
|
148
|
-
let rawLeft;
|
|
149
|
-
if (placeRightOfLeftEdge)
|
|
150
|
-
rawLeft = triggerRect.left;
|
|
151
|
-
else if (placeLeftOfRightEdge)
|
|
152
|
-
rawLeft = triggerRect.right - contentWidth;
|
|
153
|
-
else
|
|
154
|
-
rawLeft = triggerRect.left + (triggerRect.width - contentWidth) / 2;
|
|
155
|
-
const clampedLeft = Math.max(viewportPadding, Math.min(rawLeft, vw - contentWidth - viewportPadding));
|
|
156
|
-
const clampedTop = Math.max(viewportPadding, Math.min(rawTop, vh - contentHeight - viewportPadding));
|
|
157
|
-
setPos({ top: clampedTop, left: clampedLeft });
|
|
158
|
-
setPositioned(true);
|
|
159
|
-
}, [anchorRef, edgeBuffer, viewportPadding, minWidth, matchTriggerWidth]);
|
|
160
|
-
useLayoutEffect(() => {
|
|
161
|
-
if (!isOpen)
|
|
162
|
-
return;
|
|
163
|
-
computeAndSetPosition();
|
|
164
|
-
}, [isOpen, computeAndSetPosition]);
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
var _a, _b, _c;
|
|
167
|
-
if (!isOpen)
|
|
168
|
-
return;
|
|
169
|
-
const content = contentRef.current;
|
|
170
|
-
if (!content)
|
|
171
|
-
return;
|
|
172
|
-
const triggerEl = (_b = (_a = anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) !== null && _a !== void 0 ? _a : triggerElRef.current) !== null && _b !== void 0 ? _b : containerRef.current;
|
|
173
|
-
if (autoFocusContent) {
|
|
174
|
-
const focusables = getFocusable(content);
|
|
175
|
-
(_c = focusables[0]) === null || _c === void 0 ? void 0 : _c.focus();
|
|
176
|
-
}
|
|
177
|
-
const handlePointerDownCapture = (e) => {
|
|
178
|
-
const container = containerRef.current;
|
|
179
|
-
const contentEl = contentRef.current;
|
|
180
|
-
if (!container || !contentEl)
|
|
181
|
-
return;
|
|
182
|
-
const target = e.target;
|
|
183
|
-
if (!container.contains(target) && !contentEl.contains(target)) {
|
|
184
|
-
closePopover('outside');
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const handleEscape = (e) => {
|
|
188
|
-
if (e.key === 'Escape')
|
|
189
|
-
closePopover('escape');
|
|
190
|
-
};
|
|
191
|
-
const handleReposition = () => computeAndSetPosition();
|
|
192
|
-
const resizeObserver = typeof ResizeObserver !== 'undefined'
|
|
193
|
-
? new ResizeObserver(() => {
|
|
194
|
-
handleReposition();
|
|
195
|
-
})
|
|
196
|
-
: null;
|
|
197
|
-
document.addEventListener('pointerdown', handlePointerDownCapture, true);
|
|
198
|
-
document.addEventListener('keydown', handleEscape, true);
|
|
199
|
-
window.addEventListener('resize', handleReposition);
|
|
200
|
-
window.addEventListener('scroll', handleReposition, true);
|
|
201
|
-
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(content);
|
|
202
|
-
if (triggerEl)
|
|
203
|
-
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(triggerEl);
|
|
204
|
-
return () => {
|
|
205
|
-
document.removeEventListener('pointerdown', handlePointerDownCapture, true);
|
|
206
|
-
document.removeEventListener('keydown', handleEscape, true);
|
|
207
|
-
window.removeEventListener('resize', handleReposition);
|
|
208
|
-
window.removeEventListener('scroll', handleReposition, true);
|
|
209
|
-
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
210
|
-
};
|
|
211
|
-
}, [isOpen, closePopover, computeAndSetPosition, autoFocusContent, anchorRef]);
|
|
212
|
-
useEffect(() => {
|
|
213
|
-
var _a, _b;
|
|
214
|
-
if (isOpen)
|
|
215
|
-
return;
|
|
216
|
-
if (!returnFocus)
|
|
217
|
-
return;
|
|
218
|
-
if (lastCloseReasonRef.current === 'outside')
|
|
219
|
-
return;
|
|
220
|
-
(_b = (_a = triggerElRef.current) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
221
|
-
}, [isOpen, returnFocus]);
|
|
222
|
-
const icon = isOpen ? (_jsx(ChevronUp, { className: "dbc-muted-text", size: 20 })) : (_jsx(ChevronDown, { className: "dbc-muted-text", size: 20 }));
|
|
223
|
-
const setOverlayRef = React.useCallback((node) => {
|
|
224
|
-
assignRef(overlayRef, node);
|
|
225
|
-
}, [overlayRef]);
|
|
226
|
-
return (_jsxs("div", { className: [
|
|
227
|
-
styles.container,
|
|
228
|
-
fullWidth ? styles.fullWidth : '',
|
|
229
|
-
fillTrigger ? styles.fillTrigger : '',
|
|
230
|
-
]
|
|
231
|
-
.filter(Boolean)
|
|
232
|
-
.join(' '), ref: containerRef, children: [_jsx("div", { className: [
|
|
233
|
-
styles.triggerSlot,
|
|
234
|
-
fullWidth ? styles.fullWidth : '',
|
|
235
|
-
fillTrigger ? styles.fillTrigger : '',
|
|
236
|
-
]
|
|
237
|
-
.filter(Boolean)
|
|
238
|
-
.join(' '), children: Trigger(togglePopover, icon, isOpen) }), mounted &&
|
|
239
|
-
isOpen &&
|
|
240
|
-
createPortal(_jsx("div", { id: resolvedContentId, ref: node => {
|
|
241
|
-
;
|
|
242
|
-
contentRef.current = node;
|
|
243
|
-
setOverlayRef(node);
|
|
244
|
-
}, className: styles.content, style: {
|
|
245
|
-
top: pos.top,
|
|
246
|
-
left: pos.left,
|
|
247
|
-
minWidth,
|
|
248
|
-
width: triggerWidth != null ? `${triggerWidth}px` : undefined,
|
|
249
|
-
maxWidth: `calc(100vw - ${viewportPadding * 2}px)`,
|
|
250
|
-
maxHeight: `clamp(100px, calc(100vh - ${viewportPadding * 2}px), ${contentMaxHeightPx}px)`,
|
|
251
|
-
visibility: positioned ? undefined : 'hidden',
|
|
252
|
-
}, "data-cy": dataCy !== null && dataCy !== void 0 ? dataCy : 'popover-content', children: typeof children === 'function'
|
|
253
|
-
? // eslint-disable-next-line react-hooks/refs
|
|
254
|
-
children(() => closePopover('api'))
|
|
255
|
-
: children }), document.body)] }));
|
|
256
|
-
});
|
|
257
|
-
Popover.displayName = 'Popover';
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
.container {
|
|
2
|
-
position: relative;
|
|
3
|
-
display: flex;
|
|
4
|
-
align-items: stretch;
|
|
5
|
-
height: 100%;
|
|
6
|
-
min-width: 0;
|
|
7
|
-
width: auto;
|
|
8
|
-
flex: 0 0 auto;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.container > * {
|
|
12
|
-
min-width: 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.triggerSlot {
|
|
16
|
-
display: flex;
|
|
17
|
-
align-items: stretch;
|
|
18
|
-
min-width: 0;
|
|
19
|
-
width: auto;
|
|
20
|
-
flex: 0 0 auto;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.triggerSlot > * {
|
|
24
|
-
min-width: 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.fullWidth,
|
|
28
|
-
.fillTrigger {
|
|
29
|
-
width: 100%;
|
|
30
|
-
flex: 1 1 auto;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.fullWidth > *,
|
|
34
|
-
.fillTrigger > * {
|
|
35
|
-
width: 100%;
|
|
36
|
-
min-width: 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.content {
|
|
40
|
-
position: fixed;
|
|
41
|
-
border: 1px solid var(--color-border-subtle);
|
|
42
|
-
background-color: var(--color-bg-surface);
|
|
43
|
-
border-radius: var(--border-radius-lg);
|
|
44
|
-
padding: var(--spacing-xxs);
|
|
45
|
-
z-index: var(--z-popover);
|
|
46
|
-
overflow: auto;
|
|
47
|
-
box-shadow:
|
|
48
|
-
0 0 0 1px rgba(0, 0, 0, 0.01),
|
|
49
|
-
var(--shadow-sm);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.content[hidden] {
|
|
53
|
-
display: none;
|
|
54
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { Search } from 'lucide-react';
|
|
4
|
-
import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import { Input } from '../../components/forms/input/Input';
|
|
6
|
-
import { Menu } from '../../components/menu/Menu';
|
|
7
|
-
import { Popover } from '../../components/popover/Popover';
|
|
8
|
-
import { SkeletonLoaderItem } from '../../components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem';
|
|
9
|
-
import styles from './SearchBox.module.css';
|
|
10
|
-
export const SearchBox = forwardRef(function SearchBoxInner({ inputWidth, maxWidth, inputSize, variant, result, debounce = true, debounceMs = 800, onSearch, onSelect, displayPopover, resultKeys, resultTemplate, initialTemplate, popoverMinWidth = '500px', noResultText = 'Ingen resultater', loading, enableHotkey = true, onButtonClick, buttonLabel, buttonIcon, fullWidth = false, value, onChange, ...rest }, ref) {
|
|
11
|
-
const isControlled = value !== undefined;
|
|
12
|
-
// What the user sees immediately in the textbox
|
|
13
|
-
const [draft, setDraft] = useState(() => (isControlled ? String(value !== null && value !== void 0 ? value : '') : ''));
|
|
14
|
-
// Used only for UI state ("Indtast søgeord" vs results/no results)
|
|
15
|
-
const [searchQuery, setSearchQuery] = useState('');
|
|
16
|
-
const [activeIndex, setActiveIndex] = useState(null);
|
|
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;
|
|
27
|
-
}
|
|
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
|
-
setActiveIndex(null);
|
|
80
|
-
(_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
81
|
-
}
|
|
82
|
-
const handleClear = React.useCallback(() => {
|
|
83
|
-
var _a;
|
|
84
|
-
reset();
|
|
85
|
-
onSearch === null || onSearch === void 0 ? void 0 : onSearch('');
|
|
86
|
-
(_a = internalInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
87
|
-
}, [onSearch]);
|
|
88
|
-
// Reset active index when results change
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
setActiveIndex(null);
|
|
91
|
-
}, [result]);
|
|
92
|
-
// Props for the input are now created inside useMemo to avoid unnecessary dependency changes
|
|
93
|
-
const inputField = useMemo(() => {
|
|
94
|
-
var _a;
|
|
95
|
-
const inputProps = {
|
|
96
|
-
...rest,
|
|
97
|
-
value: draft,
|
|
98
|
-
onChange: handleChange,
|
|
99
|
-
};
|
|
100
|
-
const showInputIcon = !onButtonClick || !!buttonLabel || !!buttonIcon;
|
|
101
|
-
const trailingButtonIcon = onButtonClick && !buttonLabel && !buttonIcon ? _jsx(Search, {}) : buttonIcon;
|
|
102
|
-
if (displayPopover) {
|
|
103
|
-
return (_jsx(Popover, { ref: popoverRef, minWidth: popoverMinWidth, fullWidth: fullWidth, trigger: event => {
|
|
104
|
-
var _a;
|
|
105
|
-
return (_jsx(Input, { ref: internalInputRef, onFocusCapture: event, onClick: () => {
|
|
106
|
-
var _a, _b;
|
|
107
|
-
if (!((_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.isOpen()))
|
|
108
|
-
(_b = popoverRef.current) === null || _b === void 0 ? void 0 : _b.open();
|
|
109
|
-
}, minWidth: fullWidth ? undefined : (inputWidth !== null && inputWidth !== void 0 ? inputWidth : '300px'), width: fullWidth ? undefined : (inputWidth !== null && inputWidth !== void 0 ? inputWidth : '300px'), fullWidth: fullWidth, icon: showInputIcon ? _jsx(Search, {}) : undefined, inputSize: inputSize, variant: variant, autoComplete: "off", onClear: handleClear, onButtonClick: onButtonClick, buttonLabel: buttonLabel, buttonIcon: trailingButtonIcon, ...inputProps, onKeyDown: e => {
|
|
110
|
-
var _a;
|
|
111
|
-
if (result === null || result === void 0 ? void 0 : result.length) {
|
|
112
|
-
if (e.key === 'ArrowDown') {
|
|
113
|
-
e.preventDefault();
|
|
114
|
-
setActiveIndex(prev => prev === null || prev === result.length - 1 ? 0 : prev + 1);
|
|
115
|
-
}
|
|
116
|
-
else if (e.key === 'ArrowUp') {
|
|
117
|
-
e.preventDefault();
|
|
118
|
-
setActiveIndex(prev => prev === null || prev === 0 ? result.length - 1 : prev - 1);
|
|
119
|
-
}
|
|
120
|
-
else if (e.key === 'Enter') {
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
if (activeIndex !== null) {
|
|
123
|
-
handleSelect(result[activeIndex]);
|
|
124
|
-
}
|
|
125
|
-
else if (onButtonClick) {
|
|
126
|
-
onButtonClick();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else if (e.key === 'Escape') {
|
|
130
|
-
reset();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
(_a = inputProps.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(inputProps, e);
|
|
134
|
-
}, placeholder: (_a = rest.placeholder) !== null && _a !== void 0 ? _a : 'Indtast søgeord' }));
|
|
135
|
-
}, children: resultTemplate ? (resultTemplate) : (result === null || result === void 0 ? void 0 : result.length) ? (_jsx(Menu, { children: _jsx("table", { className: styles.suggestionTable, children: _jsx("tbody", { children: result.map((item, index) => (_jsx("tr", { onClick: () => handleSelect(item), role: "button", tabIndex: 0, className: `${styles.suggestionRow}${index === activeIndex ? ` ${styles.suggestionRowActive}` : ''}`, children: resultKeys === null || resultKeys === void 0 ? void 0 : resultKeys.map(key => {
|
|
136
|
-
const raw = item[key];
|
|
137
|
-
const cell = raw != null ? String(raw) : '';
|
|
138
|
-
return (_jsx("td", { className: styles.suggestionCell, style: { whiteSpace: cell.length < 10 ? 'nowrap' : undefined }, children: cell }, key));
|
|
139
|
-
}) }, 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 })) }));
|
|
140
|
-
}
|
|
141
|
-
return (_jsx(Input, { ref: internalInputRef, icon: showInputIcon ? _jsx(Search, {}) : undefined, minWidth: fullWidth ? undefined : (inputWidth !== null && inputWidth !== void 0 ? inputWidth : '300px'), fullWidth: fullWidth, inputSize: inputSize, variant: variant, onClear: handleClear, onButtonClick: onButtonClick, buttonLabel: buttonLabel, buttonIcon: trailingButtonIcon, ...inputProps, placeholder: (_a = rest.placeholder) !== null && _a !== void 0 ? _a : 'Indtast søgeord' }));
|
|
142
|
-
}, [
|
|
143
|
-
rest,
|
|
144
|
-
draft,
|
|
145
|
-
handleChange,
|
|
146
|
-
handleClear,
|
|
147
|
-
displayPopover,
|
|
148
|
-
inputWidth,
|
|
149
|
-
inputSize,
|
|
150
|
-
variant,
|
|
151
|
-
popoverMinWidth,
|
|
152
|
-
resultTemplate,
|
|
153
|
-
result,
|
|
154
|
-
searchQuery,
|
|
155
|
-
loading,
|
|
156
|
-
initialTemplate,
|
|
157
|
-
noResultText,
|
|
158
|
-
resultKeys,
|
|
159
|
-
handleSelect,
|
|
160
|
-
activeIndex,
|
|
161
|
-
onButtonClick,
|
|
162
|
-
buttonLabel,
|
|
163
|
-
buttonIcon,
|
|
164
|
-
fullWidth,
|
|
165
|
-
]);
|
|
166
|
-
return (_jsx("div", { style: {
|
|
167
|
-
...(fullWidth ? { width: '100%' } : undefined),
|
|
168
|
-
...(maxWidth !== undefined ? { maxWidth } : undefined),
|
|
169
|
-
}, children: inputField }));
|
|
170
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
.resultContainer {
|
|
2
|
-
padding: var(--spacing-sm);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.suggestionTable {
|
|
6
|
-
border-collapse: collapse;
|
|
7
|
-
width: 100%;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.suggestionRow {
|
|
11
|
-
cursor: pointer;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.suggestionRow:hover > .suggestionCell,
|
|
15
|
-
.suggestionRowActive > .suggestionCell {
|
|
16
|
-
background-color: var(--table-row-bg-hover);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.suggestionCell {
|
|
20
|
-
padding: var(--spacing-xs) var(--spacing-sm);
|
|
21
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useTooltipTrigger } from '../../components/overlay/tooltip/useTooltipTrigger';
|
|
4
|
-
import styles from './SegmentedProgressBar.module.css';
|
|
5
|
-
function SegmentWithTooltip({ seg, index, tooltipPlacement, }) {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
const tooltipContent = typeof seg.label !== 'undefined' ? seg.label : String((_a = seg.value) !== null && _a !== void 0 ? _a : 0);
|
|
8
|
-
const tooltipEnabled = tooltipContent !== null && tooltipContent !== undefined && tooltipContent !== '';
|
|
9
|
-
const { triggerProps } = useTooltipTrigger({
|
|
10
|
-
content: tooltipEnabled ? tooltipContent : null,
|
|
11
|
-
placement: tooltipPlacement,
|
|
12
|
-
offset: 8,
|
|
13
|
-
});
|
|
14
|
-
return (_jsx("span", { className: styles.segmentWrapper, style: {
|
|
15
|
-
flex: `${Math.max(seg.value || 0, 0)} 0 0`,
|
|
16
|
-
}, ...(tooltipEnabled ? triggerProps : {}), children: _jsx("span", { className: styles.progressSegment, "data-index": index, "data-severity": (_b = seg.severity) !== null && _b !== void 0 ? _b : 'neutral', style: seg.color
|
|
17
|
-
? {
|
|
18
|
-
['--segment-color']: seg.color,
|
|
19
|
-
}
|
|
20
|
-
: undefined }) }));
|
|
21
|
-
}
|
|
22
|
-
export const SegmentedProgressBar = ({ segments, total, showRemainder = true, remainderSeverity = 'neutral', centerLabel, height, rounded = true, trackColor, tooltipPlacement = 'top', className, ...aria }) => {
|
|
23
|
-
const sum = segments.reduce((acc, s) => acc + (s.value || 0), 0);
|
|
24
|
-
const effectiveTotal = total !== null && total !== void 0 ? total : sum;
|
|
25
|
-
const safeTotal = Math.max(effectiveTotal, 0.0001);
|
|
26
|
-
const remainder = Math.max(effectiveTotal - sum, 0);
|
|
27
|
-
const pctFilled = Math.min(100, Math.max(0, (Math.min(sum, effectiveTotal) / safeTotal) * 100));
|
|
28
|
-
const computedSegments = [
|
|
29
|
-
...segments,
|
|
30
|
-
...(showRemainder && remainder > 0 ? [{ value: remainder, severity: remainderSeverity }] : []),
|
|
31
|
-
];
|
|
32
|
-
const autoNumbers = (() => {
|
|
33
|
-
const base = segments.map(s => s.value || 0);
|
|
34
|
-
if (showRemainder)
|
|
35
|
-
base.push(remainder);
|
|
36
|
-
return base.join('/');
|
|
37
|
-
})();
|
|
38
|
-
const filteredSegments = computedSegments.filter(x => x.value > 0);
|
|
39
|
-
const rootClass = [styles.container, className].filter(Boolean).join(' ');
|
|
40
|
-
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, "data-rounded": rounded ? 'true' : 'false', style: {
|
|
41
|
-
height: height ? `${height}px` : '24px',
|
|
42
|
-
background: trackColor !== null && trackColor !== void 0 ? trackColor : 'var(--color-bg-surface-subtle)',
|
|
43
|
-
}, 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: _jsx("span", { className: styles.progressCenterLabel, children: centerLabel
|
|
44
|
-
? typeof centerLabel === 'function'
|
|
45
|
-
? centerLabel(pctFilled)
|
|
46
|
-
: centerLabel
|
|
47
|
-
: autoNumbers }) })] }) }));
|
|
48
|
-
};
|