@navikt/ds-react 5.5.0-beta.0 → 5.6.0-beta.0
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/cjs/accordion/AccordionItem.js +3 -2
- package/cjs/date/datepicker/DatePickerStandalone.js +2 -2
- package/cjs/date/hooks/useDatepicker.js +2 -2
- package/cjs/date/hooks/useMonthPicker.js +2 -2
- package/cjs/date/hooks/useRangeDatepicker.js +3 -3
- package/cjs/date/monthpicker/MonthButton.js +6 -5
- package/cjs/date/monthpicker/MonthSelector.js +1 -1
- package/cjs/dropdown/Toggle.js +2 -2
- package/cjs/dropdown/index.js +0 -15
- package/cjs/form/Select.js +1 -1
- package/cjs/form/checkbox/useCheckbox.js +3 -4
- package/cjs/form/combobox/Combobox.js +1 -1
- package/cjs/form/combobox/Input/Input.js +1 -1
- package/cjs/form/search/Search.js +3 -1
- package/cjs/layout/bleed/Bleed.js +49 -0
- package/cjs/layout/bleed/index.js +8 -0
- package/cjs/layout/bleed/package.json +6 -0
- package/cjs/layout/content-box/ContentBox.js +56 -0
- package/cjs/layout/content-box/index.js +8 -0
- package/cjs/layout/content-box/package.json +6 -0
- package/cjs/layout/page-demo/AvatarPanel.js +18 -0
- package/cjs/layout/page-demo/Filter.js +21 -0
- package/cjs/layout/page-demo/Header.js +48 -0
- package/cjs/layout/page-demo/Intro.js +36 -0
- package/cjs/layout/page-demo/Sidebar.js +49 -0
- package/cjs/layout/sidemal-test/AvatarPanel.js +18 -0
- package/cjs/layout/sidemal-test/Content.js +66 -0
- package/cjs/layout/sidemal-test/Filter.js +48 -0
- package/cjs/layout/sidemal-test/Header.js +48 -0
- package/cjs/layout/sidemal-test/Intro.js +36 -0
- package/cjs/layout/sidemal-test/Sidebar.js +49 -0
- package/cjs/layout/sidemal-test/content-box/ContentBox.js +65 -0
- package/cjs/layout/sidemal-test/content-box/index.js +8 -0
- package/cjs/layout/sidemal-test/content-box/package.json +6 -0
- package/cjs/layout/stack/Stack.js +2 -2
- package/cjs/layout/stack/index.js +3 -1
- package/cjs/loader/Loader.js +2 -2
- package/cjs/modal/dialog-polyfill.js +2 -0
- package/cjs/popover/Popover.js +3 -2
- package/cjs/skeleton/Skeleton.js +1 -0
- package/cjs/tabs/TabList.js +6 -7
- package/cjs/timeline/Pin.js +20 -20
- package/cjs/timeline/Timeline.js +4 -4
- package/cjs/timeline/period/ClickablePeriod.js +19 -19
- package/cjs/timeline/period/index.js +1 -1
- package/cjs/timeline/utils/timeline.js +3 -3
- package/cjs/toggle-group/ToggleGroup.js +1 -1
- package/cjs/tooltip/Tooltip.js +1 -1
- package/cjs/typography/Heading.js +1 -1
- package/cjs/util/RandomIcon.js +1 -0
- package/cjs/util/Slot.js +88 -0
- package/cjs/util/useId.js +2 -4
- package/esm/accordion/AccordionItem.js +3 -2
- package/esm/accordion/AccordionItem.js.map +1 -1
- package/esm/date/datepicker/DatePickerStandalone.js +2 -2
- package/esm/date/datepicker/DatePickerStandalone.js.map +1 -1
- package/esm/date/hooks/useDatepicker.js +2 -2
- package/esm/date/hooks/useDatepicker.js.map +1 -1
- package/esm/date/hooks/useMonthPicker.js +2 -2
- package/esm/date/hooks/useMonthPicker.js.map +1 -1
- package/esm/date/hooks/useRangeDatepicker.js +3 -3
- package/esm/date/hooks/useRangeDatepicker.js.map +1 -1
- package/esm/date/monthpicker/MonthButton.d.ts +2 -2
- package/esm/date/monthpicker/MonthButton.js +6 -5
- package/esm/date/monthpicker/MonthButton.js.map +1 -1
- package/esm/date/monthpicker/MonthPicker.d.ts +1 -1
- package/esm/date/monthpicker/MonthSelector.js +1 -1
- package/esm/date/monthpicker/MonthSelector.js.map +1 -1
- package/esm/date/utils/navigation.d.ts +1 -1
- package/esm/date/utils/navigation.js.map +1 -1
- package/esm/dropdown/Toggle.js +1 -1
- package/esm/dropdown/Toggle.js.map +1 -1
- package/esm/dropdown/index.d.ts +1 -2
- package/esm/dropdown/index.js +0 -1
- package/esm/dropdown/index.js.map +1 -1
- package/esm/form/Fieldset/useFieldset.d.ts +1 -1
- package/esm/form/Select.js +1 -1
- package/esm/form/Select.js.map +1 -1
- package/esm/form/checkbox/useCheckbox.d.ts +2 -2
- package/esm/form/checkbox/useCheckbox.js +3 -4
- package/esm/form/checkbox/useCheckbox.js.map +1 -1
- package/esm/form/combobox/Combobox.d.ts +1 -1
- package/esm/form/combobox/Combobox.js +1 -1
- package/esm/form/combobox/Combobox.js.map +1 -1
- package/esm/form/combobox/Input/Input.d.ts +0 -2
- package/esm/form/combobox/Input/Input.js +1 -1
- package/esm/form/combobox/Input/Input.js.map +1 -1
- package/esm/form/radio/useRadio.d.ts +1 -1
- package/esm/form/search/Search.js +3 -1
- package/esm/form/search/Search.js.map +1 -1
- package/esm/layout/bleed/Bleed.d.ts +8 -0
- package/esm/layout/bleed/Bleed.js +21 -0
- package/esm/layout/bleed/Bleed.js.map +1 -0
- package/esm/layout/bleed/index.d.ts +1 -0
- package/esm/layout/bleed/index.js +2 -0
- package/esm/layout/bleed/index.js.map +1 -0
- package/esm/layout/box/Box.d.ts +1 -2
- package/esm/layout/box/Box.js.map +1 -1
- package/esm/layout/content-box/ContentBox.d.ts +8 -0
- package/esm/layout/content-box/ContentBox.js +28 -0
- package/esm/layout/content-box/ContentBox.js.map +1 -0
- package/esm/layout/content-box/index.d.ts +1 -0
- package/esm/layout/content-box/index.js +2 -0
- package/esm/layout/content-box/index.js.map +1 -0
- package/esm/layout/page-demo/AvatarPanel.d.ts +4 -0
- package/esm/layout/page-demo/AvatarPanel.js +12 -0
- package/esm/layout/page-demo/AvatarPanel.js.map +1 -0
- package/esm/layout/page-demo/Filter.d.ts +2 -0
- package/esm/layout/page-demo/Filter.js +15 -0
- package/esm/layout/page-demo/Filter.js.map +1 -0
- package/esm/layout/page-demo/Header.d.ts +2 -0
- package/esm/layout/page-demo/Header.js +42 -0
- package/esm/layout/page-demo/Header.js.map +1 -0
- package/esm/layout/page-demo/Intro.d.ts +2 -0
- package/esm/layout/page-demo/Intro.js +30 -0
- package/esm/layout/page-demo/Intro.js.map +1 -0
- package/esm/layout/page-demo/Sidebar.d.ts +4 -0
- package/esm/layout/page-demo/Sidebar.js +41 -0
- package/esm/layout/page-demo/Sidebar.js.map +1 -0
- package/esm/layout/sidemal-test/AvatarPanel.d.ts +4 -0
- package/esm/layout/sidemal-test/AvatarPanel.js +12 -0
- package/esm/layout/sidemal-test/AvatarPanel.js.map +1 -0
- package/esm/layout/sidemal-test/Content.d.ts +2 -0
- package/esm/layout/sidemal-test/Content.js +60 -0
- package/esm/layout/sidemal-test/Content.js.map +1 -0
- package/esm/layout/sidemal-test/Filter.d.ts +2 -0
- package/esm/layout/sidemal-test/Filter.js +22 -0
- package/esm/layout/sidemal-test/Filter.js.map +1 -0
- package/esm/layout/sidemal-test/Header.d.ts +2 -0
- package/esm/layout/sidemal-test/Header.js +42 -0
- package/esm/layout/sidemal-test/Header.js.map +1 -0
- package/esm/layout/sidemal-test/Intro.d.ts +2 -0
- package/esm/layout/sidemal-test/Intro.js +30 -0
- package/esm/layout/sidemal-test/Intro.js.map +1 -0
- package/esm/layout/sidemal-test/Sidebar.d.ts +4 -0
- package/esm/layout/sidemal-test/Sidebar.js +41 -0
- package/esm/layout/sidemal-test/Sidebar.js.map +1 -0
- package/esm/layout/sidemal-test/content-box/ContentBox.d.ts +8 -0
- package/esm/layout/sidemal-test/content-box/ContentBox.js +37 -0
- package/esm/layout/sidemal-test/content-box/ContentBox.js.map +1 -0
- package/esm/layout/sidemal-test/content-box/index.d.ts +1 -0
- package/esm/layout/sidemal-test/content-box/index.js +2 -0
- package/esm/layout/sidemal-test/content-box/index.js.map +1 -0
- package/esm/layout/stack/Stack.d.ts +7 -3
- package/esm/layout/stack/Stack.js +3 -3
- package/esm/layout/stack/Stack.js.map +1 -1
- package/esm/layout/stack/index.d.ts +1 -0
- package/esm/layout/stack/index.js +1 -0
- package/esm/layout/stack/index.js.map +1 -1
- package/esm/layout/utilities/css.js.map +1 -1
- package/esm/loader/Loader.js +3 -3
- package/esm/loader/Loader.js.map +1 -1
- package/esm/modal/dialog-polyfill.js +2 -0
- package/esm/modal/dialog-polyfill.js.map +1 -1
- package/esm/popover/Popover.js +3 -2
- package/esm/popover/Popover.js.map +1 -1
- package/esm/skeleton/Skeleton.js +1 -0
- package/esm/skeleton/Skeleton.js.map +1 -1
- package/esm/tabs/TabList.js +6 -7
- package/esm/tabs/TabList.js.map +1 -1
- package/esm/timeline/Pin.js +21 -21
- package/esm/timeline/Pin.js.map +1 -1
- package/esm/timeline/Timeline.js +4 -4
- package/esm/timeline/Timeline.js.map +1 -1
- package/esm/timeline/TimelineRow.js.map +1 -1
- package/esm/timeline/hooks/usePeriodContext.d.ts +1 -1
- package/esm/timeline/period/ClickablePeriod.js +20 -20
- package/esm/timeline/period/ClickablePeriod.js.map +1 -1
- package/esm/timeline/period/index.d.ts +2 -2
- package/esm/timeline/period/index.js +1 -1
- package/esm/timeline/period/index.js.map +1 -1
- package/esm/timeline/utils/timeline.js +3 -3
- package/esm/timeline/utils/timeline.js.map +1 -1
- package/esm/toggle-group/ToggleGroup.js +1 -1
- package/esm/toggle-group/ToggleGroup.js.map +1 -1
- package/esm/tooltip/Tooltip.js +1 -1
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/typography/Heading.js +1 -1
- package/esm/typography/Heading.js.map +1 -1
- package/esm/util/RandomIcon.js +1 -0
- package/esm/util/RandomIcon.js.map +1 -1
- package/esm/util/Slot.d.ts +6 -0
- package/esm/util/Slot.js +60 -0
- package/esm/util/Slot.js.map +1 -0
- package/esm/util/mergeRefs.d.ts +1 -1
- package/esm/util/useId.js +2 -4
- package/esm/util/useId.js.map +1 -1
- package/package.json +4 -3
- package/src/accordion/AccordionItem.tsx +3 -5
- package/src/accordion/accordion.stories.tsx +21 -34
- package/src/alert/alert.stories.tsx +2 -2
- package/src/chips/chips.stories.tsx +29 -32
- package/src/date/datepicker/DatePickerStandalone.tsx +1 -3
- package/src/date/datepicker/datepicker.stories.tsx +1 -1
- package/src/date/datepicker/datepicker.test.tsx +5 -4
- package/src/date/hooks/useDatepicker.tsx +2 -2
- package/src/date/hooks/useMonthPicker.tsx +2 -2
- package/src/date/hooks/useRangeDatepicker.test.tsx +11 -11
- package/src/date/hooks/useRangeDatepicker.tsx +3 -3
- package/src/date/monthpicker/MonthButton.tsx +8 -7
- package/src/date/monthpicker/MonthPicker.tsx +1 -1
- package/src/date/monthpicker/MonthSelector.tsx +3 -3
- package/src/date/monthpicker/monthpicker.stories.tsx +2 -2
- package/src/date/utils/__tests__/get-initial-year.test.ts +0 -12
- package/src/date/utils/__tests__/is-match.test.ts +3 -3
- package/src/date/utils/__tests__/parse-dates.test.ts +4 -2
- package/src/date/utils/navigation.ts +3 -3
- package/src/dropdown/Toggle.tsx +1 -1
- package/src/dropdown/dropdown.stories.tsx +25 -28
- package/src/dropdown/index.ts +1 -2
- package/src/expansion-card/expansion-card.stories.tsx +143 -161
- package/src/form/ConfirmationPanel.test.tsx +5 -5
- package/src/form/Select.tsx +1 -1
- package/src/form/checkbox/Checkbox.test.tsx +14 -26
- package/src/form/checkbox/checkbox.stories.tsx +66 -71
- package/src/form/checkbox/useCheckbox.ts +3 -4
- package/src/form/combobox/Combobox.tsx +2 -3
- package/src/form/combobox/Input/Input.tsx +1 -3
- package/src/form/combobox/combobox.stories.tsx +20 -23
- package/src/form/combobox/combobox.test.tsx +22 -20
- package/src/form/radio/radio.stories.tsx +39 -44
- package/src/form/search/Search.tsx +1 -0
- package/src/form/search/search.stories.tsx +22 -26
- package/src/form/stories/fieldset.stories.tsx +1 -1
- package/src/layout/box/Box.stories.tsx +251 -256
- package/src/layout/box/Box.tsx +1 -1
- package/src/layout/sidemal-test/AvatarPanel.tsx +27 -0
- package/src/layout/sidemal-test/Content.tsx +129 -0
- package/src/layout/sidemal-test/Filter.tsx +46 -0
- package/src/layout/sidemal-test/Header.tsx +96 -0
- package/src/layout/sidemal-test/Intro.tsx +91 -0
- package/src/layout/sidemal-test/Sidebar.tsx +77 -0
- package/src/layout/sidemal-test/content-box/ContentBox.tsx +46 -0
- package/src/layout/sidemal-test/content-box/index.ts +1 -0
- package/src/layout/sidemal-test/navno-sidemal.stories.mdx +29 -0
- package/src/layout/sidemal-test/navno-sidemal.stories.tsx +65 -0
- package/src/layout/sidemal-test/styling.css +43 -0
- package/src/layout/stack/Stack.tsx +14 -8
- package/src/layout/stack/index.ts +1 -0
- package/src/layout/stack/stack.stories.tsx +23 -1
- package/src/layout/utilities/css.ts +0 -1
- package/src/loader/Loader.tsx +2 -3
- package/src/modal/dialog-polyfill.ts +2 -0
- package/src/pagination/pagination.stories.tsx +35 -42
- package/src/popover/Popover.test.tsx +21 -35
- package/src/popover/Popover.tsx +2 -2
- package/src/popover/popover.stories.tsx +25 -41
- package/src/react-css.d.ts +0 -1
- package/src/read-more/readmore.stories.tsx +35 -36
- package/src/skeleton/Skeleton.tsx +1 -0
- package/src/skeleton/skeleton.stories.tsx +4 -3
- package/src/stepper/stepper.stories.tsx +45 -52
- package/src/table/stories/table-expandable.stories.tsx +59 -63
- package/src/tabs/TabList.tsx +4 -6
- package/src/tabs/Tabs.stories.tsx +3 -3
- package/src/tag/tag.stories.tsx +4 -4
- package/src/timeline/Pin.tsx +44 -39
- package/src/timeline/Timeline.tsx +6 -6
- package/src/timeline/TimelineRow.tsx +1 -0
- package/src/timeline/hooks/usePeriodContext.tsx +1 -1
- package/src/timeline/period/ClickablePeriod.tsx +42 -38
- package/src/timeline/period/index.tsx +5 -4
- package/src/timeline/timeline.stories.tsx +11 -10
- package/src/timeline/utils/timeline.ts +3 -3
- package/src/toggle-group/ToggleGroup.stories.tsx +25 -29
- package/src/toggle-group/ToggleGroup.tsx +0 -1
- package/src/tooltip/Tooltip.test.tsx +40 -54
- package/src/tooltip/Tooltip.tsx +1 -1
- package/src/typography/Heading.tsx +1 -1
- package/src/util/RandomIcon.tsx +1 -0
- package/src/util/Slot.tsx +69 -0
- package/src/util/__tests__/Slot.test.tsx +98 -0
- package/src/util/mergeRefs.tsx +1 -1
- package/src/util/useId.ts +1 -3
|
@@ -50,8 +50,8 @@ export interface PeriodProps {
|
|
|
50
50
|
status: string;
|
|
51
51
|
cropped: string;
|
|
52
52
|
direction: string;
|
|
53
|
-
width:
|
|
54
|
-
left:
|
|
53
|
+
width: number;
|
|
54
|
+
left: number;
|
|
55
55
|
icon?: React.ReactNode;
|
|
56
56
|
children?: React.ReactNode;
|
|
57
57
|
statusLabel?: string;
|
|
@@ -102,11 +102,12 @@ export const Period = forwardRef<HTMLDivElement, TimelinePeriodProps>(
|
|
|
102
102
|
width={width}
|
|
103
103
|
left={horizontalPosition}
|
|
104
104
|
icon={icon}
|
|
105
|
-
children={children}
|
|
106
105
|
isActive={isActive}
|
|
107
106
|
statusLabel={statusLabel}
|
|
108
107
|
restProps={restProps}
|
|
109
|
-
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
</ClickablePeriod>
|
|
110
111
|
) : (
|
|
111
112
|
<NonClickablePeriod
|
|
112
113
|
periodRef={ref}
|
|
@@ -110,7 +110,7 @@ export const Default = () => {
|
|
|
110
110
|
label="Row 1"
|
|
111
111
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
112
112
|
>
|
|
113
|
-
{row1.map((p: any
|
|
113
|
+
{row1.map((p: any) => {
|
|
114
114
|
return (
|
|
115
115
|
<Timeline.Period
|
|
116
116
|
key={p.id}
|
|
@@ -126,7 +126,7 @@ export const Default = () => {
|
|
|
126
126
|
label="Row 2"
|
|
127
127
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
128
128
|
>
|
|
129
|
-
{row2.map((p: any
|
|
129
|
+
{row2.map((p: any) => {
|
|
130
130
|
return (
|
|
131
131
|
<Timeline.Period
|
|
132
132
|
key={p.id}
|
|
@@ -154,7 +154,7 @@ export const WithPins = () => {
|
|
|
154
154
|
label="Row 1"
|
|
155
155
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
156
156
|
>
|
|
157
|
-
{row1.map((p: any
|
|
157
|
+
{row1.map((p: any) => {
|
|
158
158
|
return (
|
|
159
159
|
<Timeline.Period
|
|
160
160
|
key={p.id}
|
|
@@ -170,7 +170,7 @@ export const WithPins = () => {
|
|
|
170
170
|
label="Row 2"
|
|
171
171
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
172
172
|
>
|
|
173
|
-
{row2.map((p: any
|
|
173
|
+
{row2.map((p: any) => {
|
|
174
174
|
return (
|
|
175
175
|
<Timeline.Period
|
|
176
176
|
key={p.id}
|
|
@@ -195,7 +195,7 @@ export const WithZoom = () => {
|
|
|
195
195
|
label="Row 1"
|
|
196
196
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
197
197
|
>
|
|
198
|
-
{row1.map((p: any
|
|
198
|
+
{row1.map((p: any) => {
|
|
199
199
|
return (
|
|
200
200
|
<Timeline.Period
|
|
201
201
|
key={p.id}
|
|
@@ -211,7 +211,7 @@ export const WithZoom = () => {
|
|
|
211
211
|
label="Row 2"
|
|
212
212
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
213
213
|
>
|
|
214
|
-
{row2.map((p: any
|
|
214
|
+
{row2.map((p: any) => {
|
|
215
215
|
return (
|
|
216
216
|
<Timeline.Period
|
|
217
217
|
key={p.id}
|
|
@@ -246,7 +246,7 @@ export const ActivePeriod = () => {
|
|
|
246
246
|
label="Rad 1"
|
|
247
247
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
248
248
|
>
|
|
249
|
-
{row1.map((p: any
|
|
249
|
+
{row1.map((p: any) => {
|
|
250
250
|
return (
|
|
251
251
|
<Timeline.Period
|
|
252
252
|
key={p.id}
|
|
@@ -268,7 +268,7 @@ export const ActivePeriod = () => {
|
|
|
268
268
|
})}
|
|
269
269
|
</Timeline.Row>
|
|
270
270
|
<Timeline.Row label="Rad 2">
|
|
271
|
-
{row2.map((p: any
|
|
271
|
+
{row2.map((p: any) => {
|
|
272
272
|
return (
|
|
273
273
|
<Timeline.Period
|
|
274
274
|
key={p.id}
|
|
@@ -368,13 +368,14 @@ export const ContentDemo = () => {
|
|
|
368
368
|
<Timeline.Pin date={new Date("Apr 15 2022")}>Pin 1</Timeline.Pin>
|
|
369
369
|
<Timeline.Pin date={new Date("Jun 12 2022")}>
|
|
370
370
|
Pin 2 <button>test</button>
|
|
371
|
+
<a href="/123">test123123</a>
|
|
371
372
|
</Timeline.Pin>
|
|
372
373
|
<Timeline.Pin date={new Date("Jul 28 2022")}>Pin 3</Timeline.Pin>
|
|
373
374
|
<Timeline.Row
|
|
374
375
|
label="Rad 1"
|
|
375
376
|
icon={<CheckmarkCircleFillIcon aria-hidden />}
|
|
376
377
|
>
|
|
377
|
-
{row1.map((p: any
|
|
378
|
+
{row1.map((p: any) => {
|
|
378
379
|
return (
|
|
379
380
|
<Timeline.Period
|
|
380
381
|
key={p.id}
|
|
@@ -400,7 +401,7 @@ export const ContentDemo = () => {
|
|
|
400
401
|
})}
|
|
401
402
|
</Timeline.Row>
|
|
402
403
|
<Timeline.Row label="Rad 2">
|
|
403
|
-
{row2.map((p: any
|
|
404
|
+
{row2.map((p: any) => {
|
|
404
405
|
return (
|
|
405
406
|
<Timeline.Period
|
|
406
407
|
key={p.id}
|
|
@@ -12,9 +12,9 @@ type ParsedChild = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const parseRows = (rowChildren: ReactNode[]) => {
|
|
15
|
-
|
|
15
|
+
const parsedChildren: ParsedChild[] = [];
|
|
16
16
|
rowChildren?.forEach((r: React.ReactNode) => {
|
|
17
|
-
|
|
17
|
+
const periods: ParsedChild["periods"] = [];
|
|
18
18
|
if (React.isValidElement(r) && r?.props?.children) {
|
|
19
19
|
if (Array.isArray(r.props.children)) {
|
|
20
20
|
for (let i = 0; i < r.props.children.length; i++) {
|
|
@@ -72,7 +72,7 @@ export const parseRows = (rowChildren: ReactNode[]) => {
|
|
|
72
72
|
label: r.props.label,
|
|
73
73
|
icon: r.props.icon,
|
|
74
74
|
headingTag: r.props.headingTag,
|
|
75
|
-
periods
|
|
75
|
+
periods,
|
|
76
76
|
restProps: omit(r.props, ["label", "icon", "headingTag"]),
|
|
77
77
|
ref: (r as any)?.ref,
|
|
78
78
|
});
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
EnvelopeClosedIcon,
|
|
5
3
|
EnvelopeOpenIcon,
|
|
@@ -8,24 +6,24 @@ import {
|
|
|
8
6
|
import { Meta } from "@storybook/react";
|
|
9
7
|
import React, { useState } from "react";
|
|
10
8
|
import { ToggleGroup } from "../index";
|
|
11
|
-
|
|
9
|
+
|
|
10
|
+
const meta: Meta<typeof ToggleGroup> = {
|
|
12
11
|
title: "ds-react/ToggleGroup",
|
|
13
12
|
component: ToggleGroup,
|
|
14
13
|
argTypes: {
|
|
15
14
|
size: {
|
|
15
|
+
options: ["medium", "small"],
|
|
16
16
|
control: {
|
|
17
17
|
type: "radio",
|
|
18
|
-
options: ["medium", "small"],
|
|
19
18
|
},
|
|
20
19
|
},
|
|
21
20
|
variant: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
options: ["action", "neutral"],
|
|
25
|
-
},
|
|
21
|
+
options: ["action", "neutral"],
|
|
22
|
+
control: { type: "radio" },
|
|
26
23
|
},
|
|
27
24
|
},
|
|
28
|
-
}
|
|
25
|
+
};
|
|
26
|
+
export default meta;
|
|
29
27
|
|
|
30
28
|
const Items = (icon?: boolean, both?: boolean) => (
|
|
31
29
|
<>
|
|
@@ -59,26 +57,24 @@ const Items = (icon?: boolean, both?: boolean) => (
|
|
|
59
57
|
</>
|
|
60
58
|
);
|
|
61
59
|
|
|
62
|
-
export const Default = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
label: false,
|
|
81
|
-
},
|
|
60
|
+
export const Default = (props) => {
|
|
61
|
+
const [activeValue, setActiveValue] = useState("ulest");
|
|
62
|
+
return (
|
|
63
|
+
<ToggleGroup
|
|
64
|
+
size={props.size}
|
|
65
|
+
variant={props.variant}
|
|
66
|
+
value={activeValue}
|
|
67
|
+
onChange={setActiveValue}
|
|
68
|
+
label={props.label ? "Proident minim dolor pariatur." : undefined}
|
|
69
|
+
>
|
|
70
|
+
{Items(props.icon, props.text && props.icon)}
|
|
71
|
+
</ToggleGroup>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
Default.args = {
|
|
75
|
+
icon: true,
|
|
76
|
+
text: true,
|
|
77
|
+
label: false,
|
|
82
78
|
};
|
|
83
79
|
|
|
84
80
|
export const Compositions = () => {
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { act,
|
|
1
|
+
import { act, fireEvent, screen } from "@testing-library/react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
focusVisible,
|
|
5
|
+
simulatePointerDown,
|
|
6
|
+
renderWithStyles as render,
|
|
7
|
+
} from "../../tests/utils";
|
|
4
8
|
import userEvent from "@testing-library/user-event";
|
|
5
9
|
import Tooltip from "./Tooltip";
|
|
6
|
-
import { renderWithStyles as render } from "../../tests/utils";
|
|
7
10
|
|
|
8
11
|
describe("Tooltip", () => {
|
|
9
12
|
test("controlled open", () => {
|
|
10
|
-
|
|
13
|
+
render(
|
|
11
14
|
<Tooltip content="Hello World" open>
|
|
12
15
|
<button id="testChild" type="submit">
|
|
13
16
|
Hello World
|
|
@@ -15,12 +18,11 @@ describe("Tooltip", () => {
|
|
|
15
18
|
</Tooltip>
|
|
16
19
|
);
|
|
17
20
|
|
|
18
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
19
|
-
cleanup();
|
|
21
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
test("default open", () => {
|
|
23
|
-
|
|
25
|
+
render(
|
|
24
26
|
<Tooltip content="Hello World" defaultOpen>
|
|
25
27
|
<button id="testChild" type="submit">
|
|
26
28
|
Hello World
|
|
@@ -28,12 +30,11 @@ describe("Tooltip", () => {
|
|
|
28
30
|
</Tooltip>
|
|
29
31
|
);
|
|
30
32
|
|
|
31
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
32
|
-
cleanup();
|
|
33
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
test("Focus", async () => {
|
|
36
|
-
|
|
37
|
+
render(
|
|
37
38
|
<Tooltip content="Hello World">
|
|
38
39
|
<button id="testChild" type="submit">
|
|
39
40
|
Hello World
|
|
@@ -42,14 +43,12 @@ describe("Tooltip", () => {
|
|
|
42
43
|
);
|
|
43
44
|
simulatePointerDown();
|
|
44
45
|
|
|
45
|
-
focusVisible(getByRole("button"));
|
|
46
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
47
|
-
|
|
48
|
-
cleanup();
|
|
46
|
+
focusVisible(screen.getByRole("button"));
|
|
47
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
49
48
|
});
|
|
50
49
|
|
|
51
50
|
test("Escape", async () => {
|
|
52
|
-
|
|
51
|
+
render(
|
|
53
52
|
<Tooltip content="Hello World">
|
|
54
53
|
<button id="testChild" type="submit">
|
|
55
54
|
Hello World
|
|
@@ -58,21 +57,17 @@ describe("Tooltip", () => {
|
|
|
58
57
|
);
|
|
59
58
|
simulatePointerDown();
|
|
60
59
|
|
|
61
|
-
focusVisible(getByRole("button"));
|
|
62
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
63
|
-
|
|
64
|
-
act(() => {
|
|
65
|
-
fireEvent.keyDown(document, { key: "Escape" });
|
|
66
|
-
});
|
|
67
|
-
expect(queryByRole("tooltip")).toBeNull();
|
|
60
|
+
focusVisible(screen.getByRole("button"));
|
|
61
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
68
62
|
|
|
69
|
-
|
|
63
|
+
fireEvent.keyDown(document, { key: "Escape" });
|
|
64
|
+
expect(screen.queryByRole("tooltip")).toBeNull();
|
|
70
65
|
});
|
|
71
66
|
|
|
72
67
|
it("delay", async () => {
|
|
73
68
|
const user = userEvent.setup();
|
|
74
69
|
|
|
75
|
-
|
|
70
|
+
render(
|
|
76
71
|
<Tooltip content="Hello World" delay={300}>
|
|
77
72
|
<button id="testChild" type="submit">
|
|
78
73
|
Hello World
|
|
@@ -81,18 +76,17 @@ describe("Tooltip", () => {
|
|
|
81
76
|
);
|
|
82
77
|
|
|
83
78
|
await act(async () => {
|
|
84
|
-
await user.hover(getByRole("button"));
|
|
79
|
+
await user.hover(screen.getByRole("button"));
|
|
85
80
|
await new Promise((r) => setTimeout(r, 250));
|
|
86
|
-
expect(queryByRole("tooltip")).toBeNull();
|
|
81
|
+
expect(screen.queryByRole("tooltip")).toBeNull();
|
|
87
82
|
await new Promise((r) => setTimeout(r, 600));
|
|
88
83
|
});
|
|
89
84
|
|
|
90
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
91
|
-
cleanup();
|
|
85
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
92
86
|
});
|
|
93
87
|
|
|
94
88
|
it("outsideClick", async () => {
|
|
95
|
-
|
|
89
|
+
render(
|
|
96
90
|
<div>
|
|
97
91
|
<Tooltip content="Hello World">
|
|
98
92
|
<button id="testChild" type="submit">
|
|
@@ -103,21 +97,19 @@ describe("Tooltip", () => {
|
|
|
103
97
|
</div>
|
|
104
98
|
);
|
|
105
99
|
|
|
106
|
-
simulatePointerDown(getByRole("button"));
|
|
107
|
-
focusVisible(getByRole("button"));
|
|
100
|
+
simulatePointerDown(screen.getByRole("button"));
|
|
101
|
+
focusVisible(screen.getByRole("button"));
|
|
108
102
|
|
|
109
103
|
await act(async () => {
|
|
110
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
111
|
-
getByRole("link").focus();
|
|
104
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
105
|
+
screen.getByRole("link").focus();
|
|
112
106
|
});
|
|
113
107
|
|
|
114
|
-
expect(queryByRole("tooltip")).toBeNull();
|
|
115
|
-
|
|
116
|
-
cleanup();
|
|
108
|
+
expect(screen.queryByRole("tooltip")).toBeNull();
|
|
117
109
|
});
|
|
118
110
|
|
|
119
111
|
it("keep open on tooltip-click", async () => {
|
|
120
|
-
|
|
112
|
+
render(
|
|
121
113
|
<div>
|
|
122
114
|
<Tooltip content="Hello World">
|
|
123
115
|
<button id="testChild" type="submit">
|
|
@@ -127,21 +119,17 @@ describe("Tooltip", () => {
|
|
|
127
119
|
</div>
|
|
128
120
|
);
|
|
129
121
|
|
|
130
|
-
simulatePointerDown(getByRole("button"));
|
|
131
|
-
focusVisible(getByRole("button"));
|
|
122
|
+
simulatePointerDown(screen.getByRole("button"));
|
|
123
|
+
focusVisible(screen.getByRole("button"));
|
|
132
124
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
fireEvent.click(getByRole("tooltip"));
|
|
136
|
-
});
|
|
125
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
126
|
+
fireEvent.click(screen.getByRole("tooltip"));
|
|
137
127
|
|
|
138
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
139
|
-
|
|
140
|
-
cleanup();
|
|
128
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
141
129
|
});
|
|
142
130
|
|
|
143
131
|
it("close on focus-loss", async () => {
|
|
144
|
-
|
|
132
|
+
render(
|
|
145
133
|
<div>
|
|
146
134
|
<Tooltip content="Hello World">
|
|
147
135
|
<button id="testChild" type="submit">
|
|
@@ -152,16 +140,14 @@ describe("Tooltip", () => {
|
|
|
152
140
|
</div>
|
|
153
141
|
);
|
|
154
142
|
|
|
155
|
-
simulatePointerDown(getByRole("button"));
|
|
156
|
-
focusVisible(getByRole("button"));
|
|
143
|
+
simulatePointerDown(screen.getByRole("button"));
|
|
144
|
+
focusVisible(screen.getByRole("button"));
|
|
157
145
|
|
|
158
146
|
await act(async () => {
|
|
159
|
-
expect(getByRole("tooltip")).toBeVisible();
|
|
160
|
-
getByRole("link").focus();
|
|
147
|
+
expect(screen.getByRole("tooltip")).toBeVisible();
|
|
148
|
+
screen.getByRole("link").focus();
|
|
161
149
|
});
|
|
162
150
|
|
|
163
|
-
expect(queryByRole("tooltip")).toBeNull();
|
|
164
|
-
|
|
165
|
-
cleanup();
|
|
151
|
+
expect(screen.queryByRole("tooltip")).toBeNull();
|
|
166
152
|
});
|
|
167
153
|
});
|
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -125,7 +125,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
125
125
|
} = useFloating({
|
|
126
126
|
placement: _placement,
|
|
127
127
|
open: userOpen ?? open,
|
|
128
|
-
onOpenChange: setOpen,
|
|
128
|
+
onOpenChange: (_open) => setOpen(_open),
|
|
129
129
|
middleware: [
|
|
130
130
|
offset(_offset ? _offset : _arrow ? 10 : 2),
|
|
131
131
|
shift(),
|
package/src/util/RandomIcon.tsx
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// https://github.com/radix-ui/primitives/blob/main/packages/react/slot/src/Slot.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import mergeRefs from "./mergeRefs";
|
|
4
|
+
|
|
5
|
+
interface SlotProps extends React.HTMLAttributes<HTMLElement> {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const Slot = React.forwardRef<HTMLElement, SlotProps>(
|
|
10
|
+
(props, forwardedRef) => {
|
|
11
|
+
const { children, ...slotProps } = props;
|
|
12
|
+
|
|
13
|
+
if (React.isValidElement(children)) {
|
|
14
|
+
return React.cloneElement<any>(children, {
|
|
15
|
+
...mergeProps(slotProps, children.props),
|
|
16
|
+
ref: forwardedRef
|
|
17
|
+
? mergeRefs([forwardedRef, (children as any).ref])
|
|
18
|
+
: (children as any).ref,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (React.Children.count(children) > 1) {
|
|
23
|
+
console.error(
|
|
24
|
+
"Aksel: Components using 'asChild' expects to recieve a single React element child."
|
|
25
|
+
);
|
|
26
|
+
return React.Children.only(null);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
function mergeProps(
|
|
34
|
+
slotProps: Record<string, any>,
|
|
35
|
+
childProps: Record<string, any>
|
|
36
|
+
) {
|
|
37
|
+
// all child props should override
|
|
38
|
+
const overrideProps = { ...childProps };
|
|
39
|
+
|
|
40
|
+
for (const propName in childProps) {
|
|
41
|
+
const slotPropValue = slotProps[propName];
|
|
42
|
+
const childPropValue = childProps[propName];
|
|
43
|
+
|
|
44
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
45
|
+
if (isHandler) {
|
|
46
|
+
// if the handler exists on both, we compose them
|
|
47
|
+
if (slotPropValue && childPropValue) {
|
|
48
|
+
overrideProps[propName] = (...args: unknown[]) => {
|
|
49
|
+
childPropValue(...args);
|
|
50
|
+
slotPropValue(...args);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// but if it exists only on the slot, we use only this one
|
|
54
|
+
else if (slotPropValue) {
|
|
55
|
+
overrideProps[propName] = slotPropValue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// if it's `style`, we merge them
|
|
59
|
+
else if (propName === "style") {
|
|
60
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
61
|
+
} else if (propName === "className") {
|
|
62
|
+
overrideProps[propName] = [slotPropValue, childPropValue]
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.join(" ");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { ...slotProps, ...overrideProps };
|
|
69
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Button } from "../../button";
|
|
4
|
+
import { Slot } from "../Slot";
|
|
5
|
+
|
|
6
|
+
describe("Slot", () => {
|
|
7
|
+
describe("should handle forwarning events", () => {
|
|
8
|
+
test("Should call onClick when event is on Slot", async () => {
|
|
9
|
+
const handleClick = jest.fn();
|
|
10
|
+
render(
|
|
11
|
+
<Slot onClick={handleClick}>
|
|
12
|
+
<Button>Button</Button>
|
|
13
|
+
</Slot>
|
|
14
|
+
);
|
|
15
|
+
fireEvent.click(screen.getByRole("button"));
|
|
16
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("Should call onClick when event is on Child", async () => {
|
|
20
|
+
const handleClick = jest.fn();
|
|
21
|
+
render(
|
|
22
|
+
<Slot>
|
|
23
|
+
<Button onClick={handleClick}>Button</Button>
|
|
24
|
+
</Slot>
|
|
25
|
+
);
|
|
26
|
+
fireEvent.click(screen.getByRole("button"));
|
|
27
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("Should call onClick when event is on Child and Slot", async () => {
|
|
31
|
+
const handleClickSlot = jest.fn();
|
|
32
|
+
const handleClick = jest.fn();
|
|
33
|
+
render(
|
|
34
|
+
<Slot onClick={handleClickSlot}>
|
|
35
|
+
<Button onClick={handleClick}>Button</Button>
|
|
36
|
+
</Slot>
|
|
37
|
+
);
|
|
38
|
+
fireEvent.click(screen.getByRole("button"));
|
|
39
|
+
expect(handleClickSlot).toHaveBeenCalledTimes(1);
|
|
40
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("Should call onClick when event is on Child and undefined on Slot", async () => {
|
|
44
|
+
const handleClick = jest.fn();
|
|
45
|
+
render(
|
|
46
|
+
<Slot onClick={undefined}>
|
|
47
|
+
<Button onClick={handleClick}>Button</Button>
|
|
48
|
+
</Slot>
|
|
49
|
+
);
|
|
50
|
+
fireEvent.click(screen.getByRole("button"));
|
|
51
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("Should call onClick when event is on Slot and undefined on Child", async () => {
|
|
55
|
+
const handleClick = jest.fn();
|
|
56
|
+
render(
|
|
57
|
+
<Slot onClick={handleClick}>
|
|
58
|
+
<Button onClick={undefined}>Button</Button>
|
|
59
|
+
</Slot>
|
|
60
|
+
);
|
|
61
|
+
fireEvent.click(screen.getByRole("button"));
|
|
62
|
+
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("should handle className", () => {
|
|
67
|
+
test("Should merge className correctly when Child and Slot has className", async () => {
|
|
68
|
+
render(
|
|
69
|
+
<Slot className="class1">
|
|
70
|
+
<button className="class2 class2--inline">Button</button>
|
|
71
|
+
</Slot>
|
|
72
|
+
);
|
|
73
|
+
expect(screen.getByRole("button").className).toEqual(
|
|
74
|
+
"class1 class2 class2--inline"
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("Should merge className correctly when Child has className and Slot has undefined className", async () => {
|
|
79
|
+
render(
|
|
80
|
+
<Slot className={undefined}>
|
|
81
|
+
<button className="class2 class2--inline">Button</button>
|
|
82
|
+
</Slot>
|
|
83
|
+
);
|
|
84
|
+
expect(screen.getByRole("button").className).toEqual(
|
|
85
|
+
"class2 class2--inline"
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("Should merge className correctly when Slot has className and Child has undefined className", async () => {
|
|
90
|
+
render(
|
|
91
|
+
<Slot className="class1">
|
|
92
|
+
<button className={undefined}>Button</button>
|
|
93
|
+
</Slot>
|
|
94
|
+
);
|
|
95
|
+
expect(screen.getByRole("button").className).toEqual("class1");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
package/src/util/mergeRefs.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
// https://github.com/gregberge/react-merge-refs
|
|
3
|
-
export default function mergeRefs<T
|
|
3
|
+
export default function mergeRefs<T>(
|
|
4
4
|
refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>
|
|
5
5
|
): React.RefCallback<T> {
|
|
6
6
|
return (value) => {
|
package/src/util/useId.ts
CHANGED
|
@@ -18,10 +18,8 @@ function useGlobalId(idOverride?: string): string | undefined {
|
|
|
18
18
|
return id;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
|
|
22
21
|
const maybeReactUseId: undefined | (() => string) = (React as any)[
|
|
23
|
-
//
|
|
24
|
-
"useId" + ""
|
|
22
|
+
"useId" + "" // Workaround for https://github.com/webpack/webpack/issues/14814
|
|
25
23
|
];
|
|
26
24
|
/**
|
|
27
25
|
*
|