@dbcdk/react-components 0.0.4 → 0.0.6
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 +11 -0
- package/dist/components/__stories__/story-components/Colors.js +96 -0
- package/dist/components/__stories__/story-components/Colors.module.css +27 -0
- package/dist/components/__stories__/story-components/Spacing.d.ts +2 -0
- package/dist/components/__stories__/story-components/Spacing.js +76 -0
- package/dist/components/__stories__/story-components/Spacing.module.css +154 -0
- package/dist/components/app-header/AppHeader.d.ts +4 -3
- package/dist/components/app-header/AppHeader.js +3 -6
- package/dist/components/app-header/AppHeader.module.css +10 -15
- package/dist/components/attribute-chip/AttributeChip.d.ts +9 -0
- package/dist/components/attribute-chip/AttributeChip.js +5 -0
- package/dist/components/attribute-chip/AttributeChip.module.css +65 -0
- package/dist/components/avatar/Avatar.d.ts +5 -3
- package/dist/components/avatar/Avatar.js +37 -37
- package/dist/components/avatar/Avatar.module.css +27 -0
- package/dist/components/breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/components/breadcrumbs/Breadcrumbs.js +4 -14
- package/dist/components/breadcrumbs/Breadcrumbs.module.css +19 -22
- package/dist/components/button/Button.d.ts +6 -2
- package/dist/components/button/Button.js +56 -50
- package/dist/components/button/Button.module.css +119 -56
- package/dist/components/card/Card.d.ts +23 -7
- package/dist/components/card/Card.js +20 -21
- package/dist/components/card/Card.module.css +148 -44
- package/dist/components/card-container/CardContainer.d.ts +6 -3
- package/dist/components/card-container/CardContainer.js +4 -15
- package/dist/components/card-container/CardContainer.module.css +40 -0
- package/dist/components/chip/Chip.d.ts +7 -5
- package/dist/components/chip/Chip.js +14 -37
- package/dist/components/chip/Chip.module.css +50 -27
- package/dist/components/circle/Circle.d.ts +3 -2
- package/dist/components/circle/Circle.js +3 -10
- package/dist/components/circle/Circle.module.css +11 -11
- package/dist/components/clear-button/ClearButton.d.ts +2 -1
- package/dist/components/clear-button/ClearButton.js +6 -17
- package/dist/components/clear-button/ClearButton.module.css +8 -7
- package/dist/components/code-block/CodeBlock.d.ts +7 -0
- package/dist/components/code-block/CodeBlock.js +6 -0
- package/dist/components/code-block/CodeBlock.module.css +60 -0
- package/dist/components/copy-button/CopyButton.d.ts +10 -0
- package/dist/components/copy-button/CopyButton.js +22 -0
- package/dist/components/copy-button/CopyButton.module.css +6 -0
- package/dist/components/datetime-picker/DateTimePicker.d.ts +42 -0
- package/dist/components/datetime-picker/DateTimePicker.js +403 -0
- package/dist/components/datetime-picker/DateTimePicker.module.css +144 -0
- package/dist/components/filter-field/FilterField.d.ts +6 -3
- package/dist/components/filter-field/FilterField.js +130 -158
- package/dist/components/filter-field/FilterField.module.css +35 -25
- 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 +10 -11
- 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/forms/input/Input.d.ts +22 -0
- package/dist/components/forms/input/Input.js +70 -0
- package/dist/components/forms/input/Input.module.css +160 -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.d.ts +9 -1
- package/dist/components/headline/Headline.js +18 -37
- package/dist/components/headline/Headline.module.css +32 -7
- package/dist/components/hyperlink/Hyperlink.d.ts +9 -0
- package/dist/components/hyperlink/Hyperlink.js +11 -0
- package/dist/components/hyperlink/Hyperlink.module.css +23 -0
- package/dist/components/icon/Icon.d.ts +4 -3
- package/dist/components/icon/Icon.js +11 -17
- package/dist/components/icon/Icon.module.css +10 -9
- package/dist/components/menu/Menu.js +25 -67
- package/dist/components/menu/Menu.module.css +10 -32
- package/dist/components/meta-bar/MetaBar.d.ts +11 -0
- package/dist/components/meta-bar/MetaBar.js +9 -0
- package/dist/components/meta-bar/MetaBar.module.css +12 -0
- package/dist/components/nav-bar/NavBar.d.ts +5 -5
- package/dist/components/nav-bar/NavBar.js +15 -45
- package/dist/components/nav-bar/NavBar.module.css +11 -16
- package/dist/components/overlay/modal/Modal.d.ts +23 -0
- package/dist/components/overlay/modal/Modal.js +92 -0
- package/dist/components/overlay/modal/Modal.module.css +66 -0
- package/dist/components/overlay/modal/provider/ModalProvider.d.ts +20 -0
- 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/Page.module.css +2 -2
- package/dist/components/page-layout/PageLayout.d.ts +12 -20
- package/dist/components/page-layout/PageLayout.js +35 -88
- package/dist/components/page-layout/PageLayout.module.css +4 -80
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.d.ts +11 -0
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.js +7 -0
- package/dist/components/page-layout/components/page-layout-hero/PageLayoutHero.module.css +84 -0
- package/dist/components/pagination/Pagination.d.ts +4 -1
- package/dist/components/pagination/Pagination.js +38 -105
- package/dist/components/pagination/Pagination.module.css +11 -3
- package/dist/components/panel/Panel.d.ts +4 -3
- package/dist/components/panel/Panel.js +5 -10
- package/dist/components/panel/Panel.module.css +5 -7
- package/dist/components/popover/Popover.d.ts +3 -1
- package/dist/components/popover/Popover.js +116 -124
- package/dist/components/popover/Popover.module.css +4 -6
- package/dist/components/search-box/SearchBox.d.ts +11 -8
- package/dist/components/search-box/SearchBox.js +112 -149
- package/dist/components/search-box/SearchBox.module.css +0 -1
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.d.ts +1 -1
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +47 -88
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.module.css +5 -1
- package/dist/components/sidebar/Sidebar.d.ts +3 -1
- package/dist/components/sidebar/Sidebar.js +5 -29
- package/dist/components/sidebar/components/SidebarItem.js +6 -12
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.d.ts +4 -2
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +48 -62
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +9 -38
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.d.ts +9 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +13 -0
- package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +155 -0
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.d.ts +3 -1
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.js +4 -18
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +25 -12
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.d.ts +1 -1
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.js +9 -22
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.js +20 -18
- package/dist/components/sidebar/providers/SidebarProvider.d.ts +9 -4
- package/dist/components/sidebar/providers/SidebarProvider.js +188 -73
- package/dist/components/skeleton-loader/SkeletonLoader.js +68 -266
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +11 -34
- package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +0 -12
- 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.d.ts +34 -0
- package/dist/components/split-pane/SplitPane.js +78 -0
- package/dist/components/split-pane/SplitPane.module.css +106 -0
- package/dist/components/split-pane/provider/SplitPaneContext.d.ts +23 -0
- package/dist/components/split-pane/provider/SplitPaneContext.js +85 -0
- package/dist/components/table/Table.d.ts +28 -10
- package/dist/components/table/Table.js +117 -172
- package/dist/components/table/Table.module.css +78 -47
- package/dist/components/table/components/column-resizer/ColumnResizer.js +4 -15
- package/dist/components/table/components/empty-state/EmptyState.d.ts +41 -0
- package/dist/components/table/components/empty-state/EmptyState.js +27 -0
- package/dist/components/table/components/empty-state/EmptyState.module.css +16 -0
- package/dist/components/table/components/table-settings/TableSettings.d.ts +8 -0
- package/dist/components/table/components/table-settings/TableSettings.js +12 -0
- package/dist/components/table/tanstack.d.ts +14 -0
- package/dist/components/table/tanstack.js +162 -0
- package/dist/components/tabs/Tabs.d.ts +7 -3
- package/dist/components/tabs/Tabs.js +32 -65
- package/dist/components/tabs/Tabs.module.css +9 -9
- package/dist/components/toast/Toast.d.ts +14 -0
- package/dist/components/toast/Toast.js +8 -0
- package/dist/components/toast/Toast.module.css +102 -0
- package/dist/components/toast/provider/ToastProvider.d.ts +23 -0
- package/dist/components/toast/provider/ToastProvider.js +64 -0
- package/dist/components/user-display/UserDisplay.d.ts +2 -1
- package/dist/components/user-display/UserDisplay.js +4 -20
- package/dist/components/user-display/UserDisplay.module.css +2 -2
- 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.d.ts +1 -1
- package/dist/constants/sizes.js +6 -7
- package/dist/hooks/usePagination.d.ts +33 -0
- package/dist/hooks/usePagination.js +79 -0
- package/dist/hooks/useSorting.d.ts +49 -0
- package/dist/hooks/useSorting.js +118 -0
- package/dist/hooks/useTableData.d.ts +40 -0
- package/dist/hooks/useTableData.js +45 -0
- package/dist/hooks/useTableSelection.d.ts +25 -0
- package/dist/hooks/useTableSelection.js +128 -0
- package/dist/hooks/useTableSettings.d.ts +7 -0
- package/dist/hooks/useTableSettings.js +24 -0
- package/dist/hooks/useTheme.d.ts +3 -7
- package/dist/hooks/useTheme.js +52 -47
- package/dist/hooks/useTimeDuration.d.ts +22 -0
- package/dist/hooks/useTimeDuration.js +36 -0
- package/dist/hooks/useViewportFill.d.ts +3 -2
- package/dist/hooks/useViewportFill.js +55 -48
- package/dist/index.d.ts +32 -6
- package/dist/index.js +33 -6
- package/dist/src/styles/styles.css +101 -8
- package/dist/styles/css-helper-classes/flex.css +101 -0
- package/dist/styles/css-helper-classes/typography.css +7 -0
- package/dist/styles/styles.css +101 -8
- package/dist/styles/themes/dbc/dark.css +207 -100
- package/dist/styles/themes/dbc/light.css +185 -90
- 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.d.ts +2 -2
- 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 +33 -18
- package/dist/assets/logo.cjs +0 -87
- package/dist/components/app-header/AppHeader.cjs +0 -14
- package/dist/components/avatar/Avatar.cjs +0 -67
- package/dist/components/breadcrumbs/Breadcrumbs.cjs +0 -23
- package/dist/components/button/Button.cjs +0 -79
- package/dist/components/card/Card.cjs +0 -29
- package/dist/components/card-container/CardContainer.cjs +0 -23
- package/dist/components/checkbox/Checkbox.cjs +0 -43
- package/dist/components/checkbox/Checkbox.d.ts +0 -12
- package/dist/components/checkbox/Checkbox.js +0 -37
- package/dist/components/chip/Chip.cjs +0 -49
- package/dist/components/circle/Circle.cjs +0 -18
- package/dist/components/clear-button/ClearButton.cjs +0 -26
- package/dist/components/data-summary/DataSummary.cjs +0 -49
- package/dist/components/data-summary/DataSummary.d.ts +0 -19
- package/dist/components/data-summary/DataSummary.js +0 -43
- package/dist/components/data-summary/DataSummary.module.css +0 -51
- package/dist/components/filter-field/FilterField.cjs +0 -174
- package/dist/components/headline/Headline.cjs +0 -47
- package/dist/components/icon/Icon.cjs +0 -27
- package/dist/components/input/Input.cjs +0 -48
- package/dist/components/input/Input.d.ts +0 -13
- package/dist/components/input/Input.js +0 -42
- package/dist/components/input/Input.module.css +0 -112
- package/dist/components/menu/Menu.cjs +0 -96
- package/dist/components/multi-select/MultiSelect.cjs +0 -48
- package/dist/components/multi-select/MultiSelect.d.ts +0 -18
- package/dist/components/multi-select/MultiSelect.js +0 -46
- 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 -101
- package/dist/components/pagination/Pagination.cjs +0 -117
- package/dist/components/panel/Panel.cjs +0 -18
- package/dist/components/popover/Popover.cjs +0 -132
- package/dist/components/search-box/SearchBox.cjs +0 -162
- package/dist/components/segmented-progress-bar/SegmentedProgressBar.cjs +0 -97
- package/dist/components/select/Select.cjs +0 -52
- package/dist/components/select/Select.d.ts +0 -11
- package/dist/components/select/Select.js +0 -50
- package/dist/components/sidebar/Sidebar.cjs +0 -38
- package/dist/components/sidebar/Sidebar.module.css +0 -66
- package/dist/components/sidebar/components/SidebarItem.cjs +0 -16
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +0 -74
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.cjs +0 -27
- package/dist/components/sidebar/components/sidebar-items/SidebarItems.cjs +0 -28
- package/dist/components/sidebar/components/sidenav-filteirng/SidenavFiltering.cjs +0 -25
- package/dist/components/sidebar/providers/SidebarProvider.cjs +0 -81
- 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/table/Table.cjs +0 -181
- package/dist/components/table/components/column-resizer/ColumnResizer.cjs +0 -22
- package/dist/components/tabs/Tabs.cjs +0 -74
- 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/tooltip/Tooltip.cjs +0 -78
- package/dist/components/tooltip/Tooltip.d.ts +0 -11
- package/dist/components/tooltip/Tooltip.js +0 -72
- package/dist/components/tooltip/Tooltip.module.css +0 -84
- 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 -10
- package/dist/hooks/useTheme.cjs +0 -58
- package/dist/hooks/useViewportFill.cjs +0 -52
- package/dist/index.cjs +0 -264
- package/dist/styles/themes/types.cjs +0 -2
- package/dist/tanstack.cjs +0 -231
- package/dist/tanstack.d.ts +0 -25
- package/dist/tanstack.js +0 -206
- 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
|
@@ -1,167 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Check } from 'lucide-react';
|
|
4
|
-
import {
|
|
5
|
-
import { Input } from '
|
|
6
|
-
import {
|
|
7
|
-
import { MultiSelect } from '../multi-select/MultiSelect';
|
|
8
|
-
import { Select } from '../select/Select';
|
|
4
|
+
import { useMemo, useRef, useState, useEffect } from 'react';
|
|
5
|
+
import { Input } from '../../components/forms/input/Input';
|
|
6
|
+
import { MultiSelect } from '../../components/forms/multi-select/MultiSelect';
|
|
9
7
|
import styles from './FilterField.module.css';
|
|
10
|
-
|
|
8
|
+
import { Select } from '../forms/select/Select';
|
|
9
|
+
import { Menu } from '../menu/Menu';
|
|
10
|
+
import { Popover } from '../popover/Popover';
|
|
11
11
|
const LABELS = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
is: 'is',
|
|
13
|
+
isNot: 'not',
|
|
14
|
+
contains: 'contains',
|
|
15
|
+
notContains: 'not contain',
|
|
16
|
+
startsWith: 'starts with',
|
|
17
|
+
endsWith: 'ends with',
|
|
18
|
+
gt: '>',
|
|
19
|
+
lt: '<',
|
|
20
|
+
gte: '≥',
|
|
21
|
+
lte: '≤',
|
|
22
|
+
in: '',
|
|
23
|
+
notIn: 'not in',
|
|
24
|
+
isEmpty: 'empty',
|
|
25
|
+
isNotEmpty: 'not empty',
|
|
26
26
|
};
|
|
27
27
|
const DEFAULT_TEXT_OPERATORS = [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
'is',
|
|
29
|
+
'isNot',
|
|
30
|
+
'contains',
|
|
31
|
+
'notContains',
|
|
32
|
+
'startsWith',
|
|
33
|
+
'endsWith',
|
|
34
|
+
'isEmpty',
|
|
35
|
+
'isNotEmpty',
|
|
36
36
|
];
|
|
37
|
-
const NUMBER_OPERATORS = [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
export const NUMBER_OPERATORS = [
|
|
38
|
+
'is',
|
|
39
|
+
'isNot',
|
|
40
|
+
'gt',
|
|
41
|
+
'lt',
|
|
42
|
+
'gte',
|
|
43
|
+
'lte',
|
|
44
|
+
'isEmpty',
|
|
45
|
+
'isNotEmpty',
|
|
46
46
|
];
|
|
47
|
-
function OperatorDropdown({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
Popover,
|
|
64
|
-
{
|
|
65
|
-
ref: popRef,
|
|
66
|
-
minWidth: "220px",
|
|
67
|
-
trigger: (toggle, icon) => /* @__PURE__ */ jsxs(
|
|
68
|
-
"button",
|
|
69
|
-
{
|
|
70
|
-
type: "button",
|
|
71
|
-
onClick: toggle,
|
|
72
|
-
disabled,
|
|
73
|
-
"aria-label": "Change operator",
|
|
74
|
-
className: `${styles.operatorTrigger} ${styles[size]}`,
|
|
75
|
-
children: [
|
|
76
|
-
/* @__PURE__ */ jsx("span", { className: styles.operatorText, children: LABELS[value] }),
|
|
77
|
-
icon
|
|
78
|
-
]
|
|
79
|
-
}
|
|
80
|
-
),
|
|
81
|
-
children: /* @__PURE__ */ jsx(Menu, { children: operators.map((op) => {
|
|
82
|
-
const selected = op === value;
|
|
83
|
-
return /* @__PURE__ */ jsx(Menu.Item, { active: selected, children: /* @__PURE__ */ jsxs("button", { onClick: () => handleSelect(op), children: [
|
|
84
|
-
/* @__PURE__ */ jsx("span", { style: { width: 16, display: "inline-flex", justifyContent: "center" }, children: selected ? /* @__PURE__ */ jsx(Check, { size: 16 }) : null }),
|
|
85
|
-
LABELS[op]
|
|
86
|
-
] }) }, op);
|
|
87
|
-
}) })
|
|
88
|
-
}
|
|
89
|
-
);
|
|
47
|
+
function OperatorDropdown({ value, onChange, operators, size = 'sm', disabled, }) {
|
|
48
|
+
const popRef = useRef(null);
|
|
49
|
+
const [activeIndex, setActiveIndex] = useState(() => Math.max(0, operators.indexOf(value)));
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
setActiveIndex(Math.max(0, operators.indexOf(value)));
|
|
52
|
+
}, [operators, value]);
|
|
53
|
+
const handleSelect = (op) => {
|
|
54
|
+
var _a;
|
|
55
|
+
onChange(op);
|
|
56
|
+
setActiveIndex(operators.indexOf(op));
|
|
57
|
+
(_a = popRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
58
|
+
};
|
|
59
|
+
return (_jsx(Popover, { ref: popRef, minWidth: "220px", trigger: (toggle, icon) => (_jsxs("button", { type: "button", onClick: toggle, disabled: disabled, "aria-label": "Change operator", className: `${styles.operatorTrigger} ${styles[size]}`, children: [_jsx("span", { className: styles.operatorText, children: LABELS[value] }), icon] })), children: _jsx(Menu, { children: operators.map(op => {
|
|
60
|
+
const selected = op === value;
|
|
61
|
+
return (_jsx(Menu.Item, { active: selected, children: _jsxs("button", { type: "button", onClick: () => handleSelect(op), disabled: disabled, children: [_jsx("span", { style: { width: 16, display: 'inline-flex', justifyContent: 'center' }, children: selected ? _jsx(Check, { size: 16 }) : null }), LABELS[op]] }) }, op));
|
|
62
|
+
}) }) }));
|
|
90
63
|
}
|
|
91
|
-
function FilterField({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
value
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
64
|
+
export function FilterField({ field, control, operator, value, onChange, operators, options = [], single = true, size = 'md', label, placeholder = 'Type value…', disabled, 'data-cy': dataCy, ...inputProps }) {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
const [selectedOperator, setSelectedOperator] = useState(operator);
|
|
67
|
+
const ops = useMemo(() => operators !== null && operators !== void 0 ? operators : DEFAULT_TEXT_OPERATORS, [operators]);
|
|
68
|
+
// Local state ONLY for input control (to avoid URL->props lag)
|
|
69
|
+
const [localValue, setLocalValue] = useState((_a = value) !== null && _a !== void 0 ? _a : '');
|
|
70
|
+
const debounceRef = useRef(null);
|
|
71
|
+
const isTypingRef = useRef(false);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (ops.includes(operator)) {
|
|
74
|
+
setSelectedOperator(operator);
|
|
75
|
+
}
|
|
76
|
+
}, [operator, ops]);
|
|
77
|
+
const emit = (next) => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const nextOperator = (_a = next.operator) !== null && _a !== void 0 ? _a : selectedOperator;
|
|
80
|
+
const nextValue = (_b = next.value) !== null && _b !== void 0 ? _b : value;
|
|
81
|
+
if (next.operator)
|
|
82
|
+
setSelectedOperator(nextOperator);
|
|
83
|
+
onChange({
|
|
84
|
+
field,
|
|
85
|
+
operator: nextOperator,
|
|
86
|
+
value: nextValue,
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const scheduleEmitValue = (nextVal) => {
|
|
90
|
+
if (debounceRef.current)
|
|
91
|
+
clearTimeout(debounceRef.current);
|
|
92
|
+
debounceRef.current = setTimeout(() => {
|
|
93
|
+
isTypingRef.current = false;
|
|
94
|
+
emit({ value: nextVal });
|
|
95
|
+
}, 250); // tweak debounce as needed
|
|
96
|
+
};
|
|
97
|
+
// Sync internal value when parent value changes (e.g. URL updates)
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
var _a;
|
|
100
|
+
if (control !== 'input')
|
|
101
|
+
return;
|
|
102
|
+
const incoming = (_a = value) !== null && _a !== void 0 ? _a : '';
|
|
103
|
+
// don't fight the user mid-typing; once parent catches up, we allow sync again
|
|
104
|
+
if (!isTypingRef.current && incoming !== localValue) {
|
|
105
|
+
setLocalValue(incoming);
|
|
106
|
+
}
|
|
107
|
+
if (incoming === localValue) {
|
|
108
|
+
isTypingRef.current = false;
|
|
109
|
+
}
|
|
110
|
+
}, [value, control, localValue]);
|
|
111
|
+
// Cleanup debounce on unmount
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
return () => {
|
|
114
|
+
if (debounceRef.current)
|
|
115
|
+
clearTimeout(debounceRef.current);
|
|
116
|
+
};
|
|
117
|
+
}, []);
|
|
118
|
+
return (_jsxs("div", { ...(dataCy ? { 'data-cy': dataCy } : {}), className: ` ${styles.filterField} ${styles[size]} ${value ? styles.active : ''}`, children: [label ? _jsx("span", { className: `${styles.label} ${styles[size]}`, children: label }) : null, _jsx(OperatorDropdown, { value: selectedOperator, onChange: op => emit({ operator: op }), operators: ops, size: size, disabled: disabled }), _jsx("div", { className: `${control === 'input' ? 'dbc-flex' : styles.valueWrapper}`, children: control === 'input' ? (_jsx(Input, { ...inputProps, value: localValue, onChange: e => {
|
|
119
|
+
const next = e.currentTarget.value;
|
|
120
|
+
isTypingRef.current = true;
|
|
121
|
+
setLocalValue(next); // immediate UI update
|
|
122
|
+
scheduleEmitValue(next); // debounced parent update
|
|
123
|
+
}, inputSize: size, placeholder: placeholder, width: "160px", minWidth: "120px", disabled: disabled, onClear: () => {
|
|
124
|
+
isTypingRef.current = false;
|
|
125
|
+
if (debounceRef.current)
|
|
126
|
+
clearTimeout(debounceRef.current);
|
|
127
|
+
setLocalValue('');
|
|
128
|
+
emit({ value: '' }); // clear should be immediate
|
|
129
|
+
} })) : single ? (_jsx(Select, { options: options, selectedValue: (_b = value) !== null && _b !== void 0 ? _b : null, onChange: v => emit({ value: v }), placeholder: placeholder, size: size, variant: "inline", onClear: () => emit({ value: '' }) })) : (_jsx(MultiSelect, { options: options, size: size, variant: "inline", selectedValues: (Array.isArray(value) ? value : []), onChange: v => {
|
|
130
|
+
const current = new Set((Array.isArray(value) ? value : []));
|
|
131
|
+
if (current.has(v)) {
|
|
132
|
+
current.delete(v);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
current.add(v);
|
|
136
|
+
}
|
|
137
|
+
emit({ value: Array.from(current) });
|
|
138
|
+
}, onClear: () => emit({ value: [] }), children: placeholder })) })] }));
|
|
165
139
|
}
|
|
166
|
-
|
|
167
|
-
export { FilterField, NUMBER_OPERATORS };
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
gap: 0;
|
|
5
5
|
font-size: var(--font-size-sm);
|
|
6
6
|
font-family: var(--font-family);
|
|
7
|
-
background: var(--color-surface);
|
|
8
|
-
color: var(--color-
|
|
7
|
+
background: var(--color-bg-surface);
|
|
8
|
+
color: var(--color-fg-default);
|
|
9
9
|
|
|
10
|
-
border: var(--border-width-thin) solid var(--color-border);
|
|
10
|
+
border: var(--border-width-thin) solid var(--color-border-default);
|
|
11
11
|
border-radius: var(--border-radius-default);
|
|
12
12
|
|
|
13
13
|
transition:
|
|
@@ -16,27 +16,25 @@
|
|
|
16
16
|
background-color var(--transition-fast) var(--ease-standard);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
.filterField
|
|
19
|
+
/* .filterField.active {
|
|
20
20
|
border-color: var(--color-border-selected);
|
|
21
|
-
|
|
22
|
-
}
|
|
21
|
+
background: var(--color-bg-selected);
|
|
22
|
+
} */
|
|
23
23
|
|
|
24
24
|
.filterField.sm {
|
|
25
|
-
|
|
25
|
+
block-size: calc(var(--component-size-sm) + var(--density));
|
|
26
26
|
}
|
|
27
27
|
.filterField.md {
|
|
28
|
-
|
|
28
|
+
block-size: calc(var(--component-size-md) + var(--density));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
.filterField .label {
|
|
32
32
|
display: inline-flex;
|
|
33
33
|
align-items: center;
|
|
34
|
-
|
|
35
|
-
padding-
|
|
36
|
-
padding-inline: var(--spacing-sm); /* 12px */
|
|
37
|
-
|
|
34
|
+
padding-block: calc(var(--spacing-2xs) + var(--density));
|
|
35
|
+
padding-inline: var(--spacing-sm);
|
|
38
36
|
font-size: var(--font-size-sm);
|
|
39
|
-
color: var(--color-
|
|
37
|
+
color: var(--color-fg-muted);
|
|
40
38
|
white-space: nowrap;
|
|
41
39
|
user-select: none;
|
|
42
40
|
}
|
|
@@ -45,16 +43,14 @@
|
|
|
45
43
|
display: inline-flex;
|
|
46
44
|
align-items: center;
|
|
47
45
|
justify-content: center;
|
|
48
|
-
|
|
46
|
+
height: 100%;
|
|
49
47
|
padding-block: calc(var(--spacing-2xs) + var(--density));
|
|
50
48
|
padding-inline: var(--spacing-sm);
|
|
51
|
-
|
|
52
49
|
background: var(--opac-bg-default);
|
|
53
|
-
color: var(--color-
|
|
50
|
+
color: var(--color-fg-default);
|
|
54
51
|
border: 0;
|
|
55
52
|
border-radius: 0;
|
|
56
53
|
cursor: pointer;
|
|
57
|
-
|
|
58
54
|
transition:
|
|
59
55
|
background-color var(--transition-fast) var(--ease-standard),
|
|
60
56
|
color var(--transition-fast) var(--ease-standard);
|
|
@@ -69,7 +65,7 @@
|
|
|
69
65
|
.filterField .operatorTrigger:disabled,
|
|
70
66
|
.filterField .operatorTrigger[aria-disabled='true'] {
|
|
71
67
|
cursor: not-allowed;
|
|
72
|
-
color: var(--color-disabled-
|
|
68
|
+
color: var(--color-disabled-fg);
|
|
73
69
|
background: var(--color-disabled-bg);
|
|
74
70
|
}
|
|
75
71
|
|
|
@@ -80,9 +76,21 @@
|
|
|
80
76
|
.filterField .valueWrapper {
|
|
81
77
|
display: inline-flex;
|
|
82
78
|
align-items: center;
|
|
79
|
+
padding: 0;
|
|
80
|
+
height: 100%;
|
|
81
|
+
}
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
.valueWrapper > * {
|
|
84
|
+
height: 100%;
|
|
85
|
+
& > * {
|
|
86
|
+
height: 100% !important;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.valueWrapper button {
|
|
91
|
+
height: 100% !important;
|
|
92
|
+
border: 0 !important;
|
|
93
|
+
padding-inline: var(--spacing-sm) !important;
|
|
86
94
|
}
|
|
87
95
|
|
|
88
96
|
.filterField input {
|
|
@@ -90,20 +98,22 @@
|
|
|
90
98
|
border: 0;
|
|
91
99
|
outline: none;
|
|
92
100
|
background: transparent;
|
|
93
|
-
color: var(--color-
|
|
101
|
+
color: var(--color-fg-default);
|
|
94
102
|
font: inherit;
|
|
95
|
-
|
|
96
103
|
inline-size: auto;
|
|
97
104
|
min-inline-size: 10ch;
|
|
98
|
-
|
|
99
105
|
block-size: 100%;
|
|
100
106
|
}
|
|
101
107
|
|
|
108
|
+
.filterField button {
|
|
109
|
+
border-radius: 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
102
112
|
.filterField input::placeholder {
|
|
103
|
-
color: var(--color-
|
|
113
|
+
color: var(--color-fg-muted);
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
.filterField input:disabled {
|
|
107
|
-
color: var(--color-disabled-
|
|
117
|
+
color: var(--color-disabled-fg);
|
|
108
118
|
cursor: not-allowed;
|
|
109
119
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface ChipToggleOption {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
icon?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
interface ChipMultiToggleProps {
|
|
9
|
+
/** Optional group label (e.g. "Fejlede i") */
|
|
10
|
+
label?: string;
|
|
11
|
+
options: ChipToggleOption[];
|
|
12
|
+
selectedValues: string[];
|
|
13
|
+
onChange: (nextSelectedValues: string[]) => void;
|
|
14
|
+
onToggle?: (toggledValue: string, isSelected: boolean) => void;
|
|
15
|
+
size?: 'sm' | 'md' | 'lg';
|
|
16
|
+
selectedSeverity: 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
|
17
|
+
unselectedSeverity?: 'neutral' | 'info' | 'success' | 'warning' | 'danger' | null;
|
|
18
|
+
fullWidth?: boolean;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
showAllOption?: boolean;
|
|
21
|
+
allLabel?: string;
|
|
22
|
+
allIcon?: React.ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* ✅ If true, clicking "All" toggles between:
|
|
25
|
+
* - All (no filtering) => []
|
|
26
|
+
* - None (match nothing) => [noneValue]
|
|
27
|
+
*/
|
|
28
|
+
allTogglesNone?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Sentinel stored in selectedValues to represent "none selected".
|
|
31
|
+
* Must not collide with any real option.value.
|
|
32
|
+
*/
|
|
33
|
+
noneValue?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function ChipMultiToggle({ label, options, selectedValues, onChange, onToggle, size, selectedSeverity, unselectedSeverity, fullWidth, disabled, showAllOption, allLabel, allIcon, allTogglesNone, noneValue, }: ChipMultiToggleProps): JSX.Element;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Chip } from '../../../components/chip/Chip';
|
|
5
|
+
import styles from './ChipMultiToggle.module.css';
|
|
6
|
+
export function ChipMultiToggle({ label, options, selectedValues = [], onChange, onToggle, size = 'sm', selectedSeverity = 'info', unselectedSeverity = null, fullWidth = false, disabled = false, showAllOption = false, allLabel = 'Alle', allIcon, allTogglesNone = false, noneValue = '__none__', }) {
|
|
7
|
+
const selectedSet = React.useMemo(() => new Set(selectedValues), [selectedValues]);
|
|
8
|
+
const isNoneSelected = allTogglesNone && selectedSet.has(noneValue);
|
|
9
|
+
const isAllSelected = showAllOption && !isNoneSelected && selectedSet.size === 0;
|
|
10
|
+
const toggleValue = (value) => {
|
|
11
|
+
if (disabled)
|
|
12
|
+
return;
|
|
13
|
+
// If we're in "none" state, selecting any option should exit none state
|
|
14
|
+
const next = new Set(selectedSet);
|
|
15
|
+
if (isNoneSelected)
|
|
16
|
+
next.delete(noneValue);
|
|
17
|
+
const willSelect = !next.has(value);
|
|
18
|
+
if (willSelect)
|
|
19
|
+
next.add(value);
|
|
20
|
+
else
|
|
21
|
+
next.delete(value);
|
|
22
|
+
const nextArr = Array.from(next);
|
|
23
|
+
onChange(nextArr);
|
|
24
|
+
onToggle === null || onToggle === void 0 ? void 0 : onToggle(value, willSelect);
|
|
25
|
+
};
|
|
26
|
+
const toggleAll = () => {
|
|
27
|
+
if (disabled)
|
|
28
|
+
return;
|
|
29
|
+
if (!allTogglesNone) {
|
|
30
|
+
// Classic "All" = clear selection
|
|
31
|
+
onChange([]);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Toggle between All <-> None
|
|
35
|
+
if (isAllSelected) {
|
|
36
|
+
onChange([noneValue]);
|
|
37
|
+
onToggle === null || onToggle === void 0 ? void 0 : onToggle(noneValue, true);
|
|
38
|
+
}
|
|
39
|
+
else if (isNoneSelected) {
|
|
40
|
+
onChange([]);
|
|
41
|
+
onToggle === null || onToggle === void 0 ? void 0 : onToggle(noneValue, false);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// If some are selected, clicking All goes to All (clear)
|
|
45
|
+
onChange([]);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return (_jsxs("div", { className: `${styles.wrapper} ${fullWidth ? styles.fullWidth : ''}`, children: [label && _jsx("span", { className: styles.label, children: label }), _jsxs("div", { className: styles.container, children: [showAllOption && (_jsx("button", { type: "button", className: styles.chipButton, onClick: toggleAll, "aria-pressed": isAllSelected || isNoneSelected, disabled: disabled, children: _jsx(Chip, { size: size, severity: (isAllSelected || isNoneSelected ? selectedSeverity : unselectedSeverity), customIcon: allIcon, type: unselectedSeverity === null ? 'outlined' : 'rounded', children: isNoneSelected ? `${allLabel} (ingen)` : allLabel }) }, "__all__")), options.map(opt => {
|
|
49
|
+
// If none-state is active, everything else should look unselected
|
|
50
|
+
const isSelected = !isNoneSelected && selectedSet.has(opt.value);
|
|
51
|
+
return (_jsx("button", { type: "button", className: styles.chipButton, onClick: () => toggleValue(opt.value), "aria-pressed": isSelected, disabled: disabled, children: _jsx(Chip, { size: size, severity: (isSelected ? selectedSeverity : unselectedSeverity), customIcon: opt.icon, type: unselectedSeverity === null ? 'outlined' : 'rounded', children: opt.label }) }, opt.value));
|
|
52
|
+
})] })] }));
|
|
53
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* ChipMultiToggle.module.css */
|
|
2
|
+
|
|
3
|
+
.wrapper {
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
flex-wrap: wrap;
|
|
7
|
+
|
|
8
|
+
/* use theme spacing tokens */
|
|
9
|
+
gap: var(--spacing-xs);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.fullWidth {
|
|
13
|
+
width: 100%;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.label {
|
|
17
|
+
font-weight: var(--font-weight-medium);
|
|
18
|
+
|
|
19
|
+
/* theme uses --color-fg-muted / --color-fg-subtle (not --color-text-muted) */
|
|
20
|
+
color: var(--color-fg-muted);
|
|
21
|
+
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
line-height: var(--line-height-tight);
|
|
24
|
+
font-size: var(--font-size-sm);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.container {
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-wrap: wrap;
|
|
30
|
+
align-items: center;
|
|
31
|
+
|
|
32
|
+
/* use theme spacing token */
|
|
33
|
+
gap: var(--spacing-xxs);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.chipButton {
|
|
37
|
+
padding: 0;
|
|
38
|
+
border: 0;
|
|
39
|
+
background: transparent;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
|
|
42
|
+
/* avoid default button styles on some browsers */
|
|
43
|
+
font: inherit;
|
|
44
|
+
color: inherit;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.chipButton:disabled {
|
|
48
|
+
cursor: not-allowed;
|
|
49
|
+
|
|
50
|
+
/* align with theme disabled */
|
|
51
|
+
opacity: 1;
|
|
52
|
+
color: var(--color-disabled-fg);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* Focus ring should use theme focus tokens */
|
|
56
|
+
.chipButton:focus-visible {
|
|
57
|
+
outline: none;
|
|
58
|
+
box-shadow: var(--focus-ring);
|
|
59
|
+
border-radius: var(--border-radius-rounded);
|
|
60
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { JSX } from 'react';
|
|
3
|
+
type Variant = 'default' | 'primary' | 'outlined';
|
|
4
|
+
type Size = 'sm' | 'md' | 'lg';
|
|
5
|
+
interface CheckboxProps {
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
onChange?: (checked: boolean, event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
8
|
+
variant?: Variant;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Text shown next to the box (per-item label) */
|
|
11
|
+
label?: string;
|
|
12
|
+
size?: Size;
|
|
13
|
+
containerLabel?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
helpText?: string;
|
|
16
|
+
orientation?: 'vertical' | 'horizontal';
|
|
17
|
+
labelWidth?: string;
|
|
18
|
+
fullWidth?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* If true, do NOT wrap with InputContainer.
|
|
22
|
+
* Use this inside CheckboxGroup (so you don't get group-form layout per item).
|
|
23
|
+
*/
|
|
24
|
+
noContainer?: boolean;
|
|
25
|
+
/** Optional id for accessibility (label htmlFor) */
|
|
26
|
+
id?: string;
|
|
27
|
+
/** Data attributes pass-through */
|
|
28
|
+
'data-cy'?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function Checkbox({ checked: controlled, onChange, variant, disabled, label, size, containerLabel, error, helpText, orientation, labelWidth, fullWidth, required, noContainer, id, 'data-cy': dataCy, }: CheckboxProps): JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Check } from 'lucide-react';
|
|
4
|
+
import { useId, useState } from 'react';
|
|
5
|
+
import styles from './Checkbox.module.css';
|
|
6
|
+
import { InputContainer } from '../input-container/InputContainer';
|
|
7
|
+
export function Checkbox({ checked: controlled, onChange, variant = 'outlined', disabled, label, size = 'md', containerLabel, error, helpText, orientation = 'horizontal', labelWidth = '120px', fullWidth = false, required = false, noContainer = false, id, 'data-cy': dataCy, }) {
|
|
8
|
+
const [internal, setInternal] = useState(false);
|
|
9
|
+
const isChecked = controlled !== null && controlled !== void 0 ? controlled : internal;
|
|
10
|
+
const generatedId = useId();
|
|
11
|
+
const controlId = id !== null && id !== void 0 ? id : `checkbox-${generatedId}`;
|
|
12
|
+
const toggle = (e) => {
|
|
13
|
+
if (disabled)
|
|
14
|
+
return;
|
|
15
|
+
const value = !isChecked;
|
|
16
|
+
setInternal(value);
|
|
17
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(value, e);
|
|
18
|
+
};
|
|
19
|
+
const content = (_jsxs("span", { className: styles.container, "data-cy": dataCy, children: [_jsx("button", { id: controlId, disabled: disabled, type: "button", role: "checkbox", "aria-checked": isChecked, "aria-disabled": disabled || undefined, "aria-invalid": Boolean(error) || undefined, onClick: toggle, className: [styles.checkbox, isChecked ? styles.checked : '', styles[variant], styles[size]]
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.join(' '), children: isChecked && _jsx(Check, { className: styles.icon }) }), label && (_jsx("label", { className: styles.label, htmlFor: controlId, children: label }))] }));
|
|
22
|
+
// For CheckboxGroup use-case
|
|
23
|
+
if (noContainer || (!containerLabel && !error))
|
|
24
|
+
return content;
|
|
25
|
+
// Standalone form field use-case
|
|
26
|
+
return (_jsx(InputContainer, { label: containerLabel, htmlFor: controlId, error: error, helpText: helpText, orientation: orientation, labelWidth: labelWidth, fullWidth: fullWidth, required: required, children: content }));
|
|
27
|
+
}
|