@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,19 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useId } from 'react';
|
|
4
|
-
import { RadioButton } from './RadioButton';
|
|
5
|
-
import { InputContainer } from '../input-container/InputContainer';
|
|
6
|
-
export function RadioButtonGroup({ name, value, onChange, options, disabled = false, label, error, helpText, required = false, orientation = 'horizontal', labelWidth = '160px', fullWidth = false, modified = false, direction = 'column', 'data-cy': dataCy, }) {
|
|
7
|
-
const generated = useId();
|
|
8
|
-
const groupName = name !== null && name !== void 0 ? name : `radio-group-${generated}`;
|
|
9
|
-
const content = (_jsx("div", { role: "radiogroup", "aria-invalid": Boolean(error) || undefined, "data-cy": dataCy, style: {
|
|
10
|
-
display: 'flex',
|
|
11
|
-
flexDirection: direction,
|
|
12
|
-
gap: '8px',
|
|
13
|
-
}, children: options.map(opt => (_jsx(RadioButton, { noContainer: true, name: groupName, value: String(opt.value), selectedValue: value !== null && value !== void 0 ? value : undefined, disabled: disabled || opt.disabled, label: opt.label, required: required, onChange: v => onChange(v), "data-cy": dataCy ? `${dataCy}-option-${String(opt.value)}` : undefined }, String(opt.value)))) }));
|
|
14
|
-
// If no InputContainer props were provided, just return group content
|
|
15
|
-
if (!label && !error)
|
|
16
|
-
return content;
|
|
17
|
-
// Wrap once as a proper field
|
|
18
|
-
return (_jsx(InputContainer, { label: label, htmlFor: undefined, error: error, helpText: helpText, orientation: orientation, labelWidth: labelWidth, fullWidth: fullWidth, required: required, modified: modified, children: content }));
|
|
19
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
.container {
|
|
2
|
-
display: inline-flex;
|
|
3
|
-
align-items: center;
|
|
4
|
-
gap: 8px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.controlWrap {
|
|
8
|
-
position: relative;
|
|
9
|
-
display: inline-flex;
|
|
10
|
-
align-items: center;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/* Real input stays for a11y, but visually hidden */
|
|
14
|
-
.input {
|
|
15
|
-
position: absolute;
|
|
16
|
-
inset: 0;
|
|
17
|
-
width: var(--component-size-xs);
|
|
18
|
-
height: var(--component-size-xs);
|
|
19
|
-
margin: 0;
|
|
20
|
-
opacity: 0;
|
|
21
|
-
cursor: pointer;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/* The visible radio */
|
|
25
|
-
.radio {
|
|
26
|
-
width: var(--component-size-xs);
|
|
27
|
-
height: var(--component-size-xs);
|
|
28
|
-
border-radius: 999px;
|
|
29
|
-
display: inline-flex;
|
|
30
|
-
align-items: center;
|
|
31
|
-
justify-content: center;
|
|
32
|
-
|
|
33
|
-
background: var(--color-bg-surface);
|
|
34
|
-
border: 2px solid var(--color-border-default);
|
|
35
|
-
|
|
36
|
-
transition:
|
|
37
|
-
border-color 120ms ease,
|
|
38
|
-
box-shadow 120ms ease,
|
|
39
|
-
background-color 120ms ease;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.dot {
|
|
43
|
-
width: 10px;
|
|
44
|
-
height: 10px;
|
|
45
|
-
border-radius: 999px;
|
|
46
|
-
transform: scale(0);
|
|
47
|
-
transition: transform 120ms ease;
|
|
48
|
-
background: var(--color-brand);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/* checked state */
|
|
52
|
-
.checked {
|
|
53
|
-
border-color: var(--color-brand);
|
|
54
|
-
}
|
|
55
|
-
.checked .dot {
|
|
56
|
-
transform: scale(1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/* hover (only when not disabled) */
|
|
60
|
-
.input:not(:disabled):hover + .radio {
|
|
61
|
-
border-color: var(--color-brand-hover);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/* focus ring */
|
|
65
|
-
.input:focus-visible + .radio {
|
|
66
|
-
box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand) 30%, transparent);
|
|
67
|
-
border-color: var(--color-brand-strong);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/* disabled */
|
|
71
|
-
.disabled {
|
|
72
|
-
opacity: 0.5;
|
|
73
|
-
}
|
|
74
|
-
.input:disabled {
|
|
75
|
-
cursor: not-allowed;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.label {
|
|
79
|
-
cursor: pointer;
|
|
80
|
-
user-select: none;
|
|
81
|
-
flex: 1;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.primary.checked {
|
|
85
|
-
background: color-mix(in srgb, var(--color-brand) 10%, var(--color-bg-surface));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
.default {
|
|
89
|
-
border-color: var(--color-border-strong);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/* Sizes */
|
|
93
|
-
.sm {
|
|
94
|
-
width: 16px;
|
|
95
|
-
height: 16px;
|
|
96
|
-
}
|
|
97
|
-
.sm .dot {
|
|
98
|
-
width: 8px;
|
|
99
|
-
height: 8px;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.md {
|
|
103
|
-
width: 20px;
|
|
104
|
-
height: 20px;
|
|
105
|
-
}
|
|
106
|
-
.md .dot {
|
|
107
|
-
width: 10px;
|
|
108
|
-
height: 10px;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.lg {
|
|
112
|
-
width: 24px;
|
|
113
|
-
height: 24px;
|
|
114
|
-
}
|
|
115
|
-
.lg .dot {
|
|
116
|
-
width: 12px;
|
|
117
|
-
height: 12px;
|
|
118
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Check } from 'lucide-react';
|
|
4
|
-
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import { useTooltipTrigger } from '../../../components/overlay/tooltip/useTooltipTrigger';
|
|
6
|
-
import styles from './Select.module.css';
|
|
7
|
-
import { Button } from '../../button/Button';
|
|
8
|
-
import { ClearButton } from '../../clear-button/ClearButton';
|
|
9
|
-
import { Menu } from '../../menu/Menu';
|
|
10
|
-
import { Popover } from '../../popover/Popover';
|
|
11
|
-
import { InputContainer } from '../input-container/InputContainer';
|
|
12
|
-
export function Select({ label, error, helpText, orientation = 'vertical', labelWidth = '160px', fullWidth = true, required, tooltip, tooltipPlacement = 'right', modified = false, id, options, selectedValue, onChange, placeholder = 'Vælg', size, variant = 'outlined', onClear, datakey, dataCy, disabled, minWidth, }) {
|
|
13
|
-
const generatedId = useId();
|
|
14
|
-
const controlId = id !== null && id !== void 0 ? id : `select-${generatedId}`;
|
|
15
|
-
const describedById = `${controlId}-desc`;
|
|
16
|
-
const listboxId = `${controlId}-listbox`;
|
|
17
|
-
const popoverRef = useRef(null);
|
|
18
|
-
const optionRefs = useRef([]);
|
|
19
|
-
const typeaheadRef = useRef('');
|
|
20
|
-
const typeaheadTimeoutRef = useRef(null);
|
|
21
|
-
const selectedIndex = useMemo(() => options.findIndex(o => o.value === selectedValue), [options, selectedValue]);
|
|
22
|
-
const [activeIndex, setActiveIndex] = useState(selectedIndex >= 0 ? selectedIndex : 0);
|
|
23
|
-
const [open, setOpen] = useState(false);
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
return () => {
|
|
26
|
-
if (typeaheadTimeoutRef.current)
|
|
27
|
-
clearTimeout(typeaheadTimeoutRef.current);
|
|
28
|
-
};
|
|
29
|
-
}, []);
|
|
30
|
-
// Only move focus when open
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
var _a;
|
|
33
|
-
if (!open)
|
|
34
|
-
return;
|
|
35
|
-
(_a = optionRefs.current[activeIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
36
|
-
}, [activeIndex, open]);
|
|
37
|
-
// keep activeIndex aligned when opening
|
|
38
|
-
const resetActiveToSelected = () => setActiveIndex(selectedIndex >= 0 ? selectedIndex : 0);
|
|
39
|
-
const findTypeaheadMatch = (query, startIndex) => {
|
|
40
|
-
var _a, _b;
|
|
41
|
-
if (!query || options.length === 0)
|
|
42
|
-
return -1;
|
|
43
|
-
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
44
|
-
if (!normalizedQuery)
|
|
45
|
-
return -1;
|
|
46
|
-
for (let step = 1; step <= options.length; step += 1) {
|
|
47
|
-
const index = (startIndex + step + options.length) % options.length;
|
|
48
|
-
const label = (_b = (_a = options[index]) === null || _a === void 0 ? void 0 : _a.label) === null || _b === void 0 ? void 0 : _b.trim().toLocaleLowerCase();
|
|
49
|
-
if (label === null || label === void 0 ? void 0 : label.startsWith(normalizedQuery))
|
|
50
|
-
return index;
|
|
51
|
-
}
|
|
52
|
-
return -1;
|
|
53
|
-
};
|
|
54
|
-
const handleTypeahead = (key) => {
|
|
55
|
-
const startIndex = open ? activeIndex : selectedIndex;
|
|
56
|
-
const nextBuffer = `${typeaheadRef.current}${key.toLocaleLowerCase()}`;
|
|
57
|
-
const repeatedChar = new Set(nextBuffer).size === 1;
|
|
58
|
-
let nextIndex = findTypeaheadMatch(nextBuffer, startIndex);
|
|
59
|
-
let appliedBuffer = nextBuffer;
|
|
60
|
-
if (nextIndex < 0 && repeatedChar) {
|
|
61
|
-
appliedBuffer = key.toLocaleLowerCase();
|
|
62
|
-
nextIndex = findTypeaheadMatch(appliedBuffer, startIndex);
|
|
63
|
-
}
|
|
64
|
-
if (typeaheadTimeoutRef.current)
|
|
65
|
-
clearTimeout(typeaheadTimeoutRef.current);
|
|
66
|
-
typeaheadRef.current = appliedBuffer;
|
|
67
|
-
typeaheadTimeoutRef.current = setTimeout(() => {
|
|
68
|
-
typeaheadRef.current = '';
|
|
69
|
-
typeaheadTimeoutRef.current = null;
|
|
70
|
-
}, 500);
|
|
71
|
-
if (nextIndex < 0)
|
|
72
|
-
return;
|
|
73
|
-
setActiveIndex(nextIndex);
|
|
74
|
-
if (!open)
|
|
75
|
-
setOpen(true);
|
|
76
|
-
};
|
|
77
|
-
const handleKeyDown = (e) => {
|
|
78
|
-
var _a, _b;
|
|
79
|
-
if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey && !/\s/.test(e.key)) {
|
|
80
|
-
e.preventDefault();
|
|
81
|
-
handleTypeahead(e.key);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
switch (e.key) {
|
|
85
|
-
case 'ArrowDown': {
|
|
86
|
-
e.preventDefault();
|
|
87
|
-
if (!open) {
|
|
88
|
-
setOpen(true);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
setActiveIndex(i => Math.min(i + 1, options.length - 1));
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
case 'ArrowUp': {
|
|
95
|
-
e.preventDefault();
|
|
96
|
-
if (!open) {
|
|
97
|
-
setOpen(true);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
setActiveIndex(i => Math.max(i - 1, 0));
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
case 'Enter':
|
|
104
|
-
case ' ': {
|
|
105
|
-
// Space on a button should open/select depending on state
|
|
106
|
-
e.preventDefault();
|
|
107
|
-
typeaheadRef.current = '';
|
|
108
|
-
if (typeaheadTimeoutRef.current) {
|
|
109
|
-
clearTimeout(typeaheadTimeoutRef.current);
|
|
110
|
-
typeaheadTimeoutRef.current = null;
|
|
111
|
-
}
|
|
112
|
-
if (!open) {
|
|
113
|
-
setOpen(true);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const opt = options[activeIndex];
|
|
117
|
-
if (opt) {
|
|
118
|
-
onChange(opt.value);
|
|
119
|
-
(_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
case 'Escape': {
|
|
124
|
-
if (!open)
|
|
125
|
-
return;
|
|
126
|
-
e.preventDefault();
|
|
127
|
-
(_b = popoverRef.current) === null || _b === void 0 ? void 0 : _b.close();
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
case 'Home': {
|
|
131
|
-
if (!open)
|
|
132
|
-
return;
|
|
133
|
-
e.preventDefault();
|
|
134
|
-
setActiveIndex(0);
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
case 'End': {
|
|
138
|
-
if (!open)
|
|
139
|
-
return;
|
|
140
|
-
e.preventDefault();
|
|
141
|
-
setActiveIndex(options.length - 1);
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
const selected = options.find(o => o.value === selectedValue);
|
|
147
|
-
const tooltipEnabled = Boolean(tooltip);
|
|
148
|
-
const { triggerProps, id: tooltipId } = useTooltipTrigger({
|
|
149
|
-
content: tooltipEnabled ? tooltip : null,
|
|
150
|
-
placement: tooltipPlacement,
|
|
151
|
-
offset: 8,
|
|
152
|
-
});
|
|
153
|
-
const describedBy = (() => {
|
|
154
|
-
const ids = [];
|
|
155
|
-
if (error || helpText)
|
|
156
|
-
ids.push(describedById);
|
|
157
|
-
if (tooltipEnabled)
|
|
158
|
-
ids.push(tooltipId);
|
|
159
|
-
return ids.length ? ids.join(' ') : undefined;
|
|
160
|
-
})();
|
|
161
|
-
return (_jsxs(InputContainer, { label: label, htmlFor: controlId, fullWidth: fullWidth, error: error, helpText: helpText, orientation: orientation, labelWidth: labelWidth, required: required, modified: modified, children: [_jsx(Popover, { ref: popoverRef, open: open, fullWidth: fullWidth, onOpenChange: next => {
|
|
162
|
-
setOpen(next);
|
|
163
|
-
if (next)
|
|
164
|
-
resetActiveToSelected();
|
|
165
|
-
}, contentId: listboxId,
|
|
166
|
-
// Select manages roving focus; don't auto-focus content wrapper
|
|
167
|
-
autoFocusContent: false,
|
|
168
|
-
// keep focus on trigger until you move it yourself (your ArrowDown opens then focuses option)
|
|
169
|
-
returnFocus: true, trigger: (toggle, icon, isOpen) => (_jsx(Button, { disabled: disabled, ...(tooltipEnabled ? triggerProps : {}), id: controlId, "data-cy": dataCy !== null && dataCy !== void 0 ? dataCy : 'select-button', onKeyDown: handleKeyDown, fullWidth: fullWidth, variant: variant, onClick: e => {
|
|
170
|
-
resetActiveToSelected();
|
|
171
|
-
toggle(e);
|
|
172
|
-
}, size: size, style: minWidth != null ? { minWidth } : undefined, type: "button", "data-forminput": true, "aria-haspopup": "listbox", "aria-expanded": !!isOpen, "aria-controls": listboxId, "aria-invalid": Boolean(error) || undefined, "aria-describedby": describedBy, className: modified ? styles.triggerModified : undefined, children: _jsxs("span", { className: "dbc-flex dbc-justify-between dbc-items-center dbc-gap-xxs", style: { width: '100%' }, children: [_jsx("span", { children: selected ? selected.label : _jsx("span", { className: "dbc-muted-text", children: placeholder }) }), _jsxs("span", { className: "dbc-flex dbc-items-center dbc-gap-xxs", children: [onClear && selected && _jsx(ClearButton, { onClick: onClear }), _jsx("span", { style: { color: 'var(--color-fg-subtle)', display: 'inline-flex' }, children: icon })] })] }) })), children: _jsx(Menu, { onKeyDown: handleKeyDown, role: "listbox", children: options.map((opt, index) => {
|
|
173
|
-
const isSelected = typeof opt.value === 'object' && typeof selectedValue === 'object' && datakey
|
|
174
|
-
? (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue[datakey]) === opt.value[datakey]
|
|
175
|
-
: opt.value === selectedValue;
|
|
176
|
-
const isActive = index === activeIndex;
|
|
177
|
-
return (_jsx(Menu.Item, { active: isActive, itemRole: "option", "aria-selected": isSelected, children: _jsxs("button", { ref: el => {
|
|
178
|
-
optionRefs.current[index] = el;
|
|
179
|
-
}, type: "button", tabIndex: isActive ? 0 : -1, onClick: () => {
|
|
180
|
-
var _a;
|
|
181
|
-
onChange(opt.value);
|
|
182
|
-
(_a = popoverRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
183
|
-
}, onFocus: () => setActiveIndex(index), style: { display: 'flex', alignItems: 'center', width: '100%' }, children: [_jsx("span", { style: { width: 16, display: 'inline-flex', justifyContent: 'center' }, children: isSelected ? _jsx(Check, {}) : null }), opt.label] }) }, String(opt.value)));
|
|
184
|
-
}) }) }), (error || helpText) && (_jsx("span", { id: describedById, style: { display: 'none' }, children: error !== null && error !== void 0 ? error : helpText }))] }));
|
|
185
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
.triggerModified {
|
|
2
|
-
background-color: color-mix(in srgb, var(--color-status-warning-bg) 22%, var(--color-bg-surface));
|
|
3
|
-
border-color: color-mix(
|
|
4
|
-
in srgb,
|
|
5
|
-
var(--color-status-warning-border) 45%,
|
|
6
|
-
var(--color-border-default)
|
|
7
|
-
);
|
|
8
|
-
border-left-color: var(--color-status-warning-border);
|
|
9
|
-
border-left-width: 4px;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.triggerModified:hover:not([disabled]) {
|
|
13
|
-
background-color: color-mix(in srgb, var(--color-status-warning-bg) 28%, var(--color-bg-surface));
|
|
14
|
-
border-color: color-mix(
|
|
15
|
-
in srgb,
|
|
16
|
-
var(--color-status-warning-border) 60%,
|
|
17
|
-
var(--color-border-default)
|
|
18
|
-
);
|
|
19
|
-
border-left-color: var(--color-status-warning-border);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.triggerModified:focus-visible {
|
|
23
|
-
background-color: color-mix(in srgb, var(--color-status-warning-bg) 28%, var(--color-bg-surface));
|
|
24
|
-
border-color: color-mix(
|
|
25
|
-
in srgb,
|
|
26
|
-
var(--color-status-warning-border) 75%,
|
|
27
|
-
var(--color-border-default)
|
|
28
|
-
);
|
|
29
|
-
border-left-color: var(--color-status-warning-border);
|
|
30
|
-
box-shadow: inset 0 0 0 1px
|
|
31
|
-
color-mix(in srgb, var(--color-status-warning-border) 55%, var(--color-border-default));
|
|
32
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useId, useLayoutEffect, useMemo, useRef } from 'react';
|
|
4
|
-
import { useTooltipTrigger } from '../../../components/overlay/tooltip/useTooltipTrigger';
|
|
5
|
-
import styles from './Textarea.module.css';
|
|
6
|
-
import { InputContainer } from '../input-container/InputContainer';
|
|
7
|
-
export const Textarea = function Textarea({ value, inputChanged, disabled, rows = 3, showCount, tooltip, tooltipPlacement = 'right', showTooltip, placeholder, adjustHeight, id, modified = false,
|
|
8
|
-
// InputContainer props
|
|
9
|
-
label, error, helpText, orientation = 'horizontal', labelWidth = '160px', fullWidth = false, required,
|
|
10
|
-
// Native textarea props
|
|
11
|
-
className, ...rest }) {
|
|
12
|
-
const HEIGHT_BUFFER_PX = 2;
|
|
13
|
-
const generatedId = useId();
|
|
14
|
-
const textareaId = id !== null && id !== void 0 ? id : `textarea-${generatedId}`;
|
|
15
|
-
const textareaRef = useRef(null);
|
|
16
|
-
const syncHeight = useCallback((textarea) => {
|
|
17
|
-
if (!adjustHeight)
|
|
18
|
-
return;
|
|
19
|
-
textarea.style.height = 'auto';
|
|
20
|
-
textarea.style.height = `${textarea.scrollHeight + HEIGHT_BUFFER_PX}px`;
|
|
21
|
-
}, [adjustHeight]);
|
|
22
|
-
useLayoutEffect(() => {
|
|
23
|
-
const textarea = textareaRef.current;
|
|
24
|
-
if (!textarea)
|
|
25
|
-
return;
|
|
26
|
-
syncHeight(textarea);
|
|
27
|
-
}, [syncHeight, value, rows]);
|
|
28
|
-
const onInput = useCallback((e) => {
|
|
29
|
-
const textarea = e.currentTarget;
|
|
30
|
-
syncHeight(textarea);
|
|
31
|
-
inputChanged(e);
|
|
32
|
-
}, [inputChanged, syncHeight]);
|
|
33
|
-
const inputField = useMemo(() => (_jsx("textarea", { ...rest, ref: textareaRef, id: textareaId, className: [styles.textarea, className].filter(Boolean).join(' '), placeholder: placeholder, rows: rows, value: value, onChange: onInput, disabled: disabled, "aria-invalid": Boolean(error) || undefined })), [rest, textareaId, className, placeholder, rows, value, onInput, disabled, error]);
|
|
34
|
-
// Enable tooltip if tooltip exists, and if showTooltip is either true or undefined.
|
|
35
|
-
// (So you can deprecate showTooltip later without breaking callers.)
|
|
36
|
-
const tooltipEnabled = Boolean(tooltip) && (showTooltip !== null && showTooltip !== void 0 ? showTooltip : true);
|
|
37
|
-
const { triggerProps } = useTooltipTrigger({
|
|
38
|
-
content: tooltipEnabled ? tooltip : null,
|
|
39
|
-
placement: tooltipPlacement,
|
|
40
|
-
offset: 8,
|
|
41
|
-
delayOpenMs: 0,
|
|
42
|
-
focusOpenMode: 'any',
|
|
43
|
-
closeOnPointerDown: false,
|
|
44
|
-
});
|
|
45
|
-
return (_jsx(InputContainer, { modified: modified, label: label, htmlFor: textareaId, error: error, helpText: helpText, helpTextAddition: showCount ? `${value === null || value === void 0 ? void 0 : value.length} tegn i denne boks` : undefined, orientation: orientation, labelWidth: labelWidth, fullWidth: fullWidth, required: required, children: _jsx("div", { className: [styles.container, modified ? styles.modified : ''].filter(Boolean).join(' '), children: _jsx("div", { ...(tooltipEnabled ? triggerProps : {}), children: inputField }) }) }));
|
|
46
|
-
};
|
|
47
|
-
Textarea.displayName = 'Textarea';
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
.container {
|
|
2
|
-
flex-grow: 1;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.container.modified textarea {
|
|
6
|
-
background-color: color-mix(in srgb, var(--color-status-warning-bg) 22%, var(--color-bg-surface));
|
|
7
|
-
border-color: color-mix(
|
|
8
|
-
in srgb,
|
|
9
|
-
var(--color-status-warning-border) 45%,
|
|
10
|
-
var(--color-border-default)
|
|
11
|
-
);
|
|
12
|
-
border-left-color: var(--color-status-warning-border);
|
|
13
|
-
border-left-width: 4px;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.container.modified textarea:hover {
|
|
17
|
-
background-color: color-mix(in srgb, var(--color-status-warning-bg) 28%, var(--color-bg-surface));
|
|
18
|
-
border-color: color-mix(
|
|
19
|
-
in srgb,
|
|
20
|
-
var(--color-status-warning-border) 60%,
|
|
21
|
-
var(--color-border-default)
|
|
22
|
-
);
|
|
23
|
-
border-left-color: var(--color-status-warning-border);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.container.modified textarea:focus-visible {
|
|
27
|
-
background-color: color-mix(in srgb, var(--color-status-warning-bg) 28%, var(--color-bg-surface));
|
|
28
|
-
border-color: color-mix(
|
|
29
|
-
in srgb,
|
|
30
|
-
var(--color-status-warning-border) 75%,
|
|
31
|
-
var(--color-border-default)
|
|
32
|
-
);
|
|
33
|
-
border-left-color: var(--color-status-warning-border);
|
|
34
|
-
box-shadow: inset 0 0 0 1px
|
|
35
|
-
color-mix(in srgb, var(--color-status-warning-border) 55%, var(--color-border-default));
|
|
36
|
-
}
|
|
37
|
-
.container textarea {
|
|
38
|
-
width: 100%;
|
|
39
|
-
padding: var(--spacing-xs);
|
|
40
|
-
border: var(--border-width-thin) solid var(--color-border-default);
|
|
41
|
-
border-radius: var(--border-radius-default);
|
|
42
|
-
font-family: var(--font-family);
|
|
43
|
-
font-size: var(--font-size-sm);
|
|
44
|
-
line-height: var(--line-height-normal);
|
|
45
|
-
background-color: var(--color-bg-surface);
|
|
46
|
-
color: var(--color-fg-default);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.container textarea:disabled {
|
|
50
|
-
background-color: var(--color-disabled-bg);
|
|
51
|
-
border: 0;
|
|
52
|
-
color: var(--color-disabled-fg);
|
|
53
|
-
cursor: not-allowed;
|
|
54
|
-
opacity: 0.5;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.internalCount {
|
|
58
|
-
text-align: right;
|
|
59
|
-
font-size: var(--font-size-sm);
|
|
60
|
-
color: var(--color-fg-subtle);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.container textarea:hover {
|
|
64
|
-
border-color: var(--color-border-strong);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.container textarea:focus-visible {
|
|
68
|
-
outline: none;
|
|
69
|
-
border-color: var(--color-border-selected);
|
|
70
|
-
}
|