@navikt/ds-react 6.5.0 → 6.6.1

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.
Files changed (200) hide show
  1. package/cjs/collapsible/Collapsible.context.d.ts +48 -0
  2. package/cjs/collapsible/Collapsible.context.js +10 -0
  3. package/cjs/collapsible/Collapsible.context.js.map +1 -0
  4. package/cjs/collapsible/Collapsible.d.ts +48 -0
  5. package/cjs/collapsible/Collapsible.js +91 -0
  6. package/cjs/collapsible/Collapsible.js.map +1 -0
  7. package/cjs/collapsible/Collapsible.types.d.ts +19 -0
  8. package/cjs/collapsible/Collapsible.types.js +3 -0
  9. package/cjs/collapsible/Collapsible.types.js.map +1 -0
  10. package/cjs/collapsible/index.d.ts +3 -0
  11. package/cjs/collapsible/index.js +14 -0
  12. package/cjs/collapsible/index.js.map +1 -0
  13. package/cjs/collapsible/parts/Collapsible.Content.d.ts +10 -0
  14. package/cjs/collapsible/parts/Collapsible.Content.js +48 -0
  15. package/cjs/collapsible/parts/Collapsible.Content.js.map +1 -0
  16. package/cjs/collapsible/parts/Collapsible.Trigger.d.ts +10 -0
  17. package/cjs/collapsible/parts/Collapsible.Trigger.js +49 -0
  18. package/cjs/collapsible/parts/Collapsible.Trigger.js.map +1 -0
  19. package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +2 -4
  20. package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
  21. package/cjs/form/combobox/Input/Input.js +6 -1
  22. package/cjs/form/combobox/Input/Input.js.map +1 -1
  23. package/cjs/form/form-summary/FormSummary.d.ts +82 -0
  24. package/cjs/form/form-summary/FormSummary.js +81 -0
  25. package/cjs/form/form-summary/FormSummary.js.map +1 -0
  26. package/cjs/form/form-summary/FormSummaryAnswer.d.ts +11 -0
  27. package/cjs/form/form-summary/FormSummaryAnswer.js +25 -0
  28. package/cjs/form/form-summary/FormSummaryAnswer.js.map +1 -0
  29. package/cjs/form/form-summary/FormSummaryAnswers.d.ts +9 -0
  30. package/cjs/form/form-summary/FormSummaryAnswers.js +48 -0
  31. package/cjs/form/form-summary/FormSummaryAnswers.js.map +1 -0
  32. package/cjs/form/form-summary/FormSummaryEditLink.d.ts +17 -0
  33. package/cjs/form/form-summary/FormSummaryEditLink.js +49 -0
  34. package/cjs/form/form-summary/FormSummaryEditLink.js.map +1 -0
  35. package/cjs/form/form-summary/FormSummaryHeader.d.ts +9 -0
  36. package/cjs/form/form-summary/FormSummaryHeader.js +48 -0
  37. package/cjs/form/form-summary/FormSummaryHeader.js.map +1 -0
  38. package/cjs/form/form-summary/FormSummaryHeading.d.ts +14 -0
  39. package/cjs/form/form-summary/FormSummaryHeading.js +31 -0
  40. package/cjs/form/form-summary/FormSummaryHeading.js.map +1 -0
  41. package/cjs/form/form-summary/FormSummaryLabel.d.ts +6 -0
  42. package/cjs/form/form-summary/FormSummaryLabel.js +45 -0
  43. package/cjs/form/form-summary/FormSummaryLabel.js.map +1 -0
  44. package/cjs/form/form-summary/FormSummaryValue.d.ts +6 -0
  45. package/cjs/form/form-summary/FormSummaryValue.js +49 -0
  46. package/cjs/form/form-summary/FormSummaryValue.js.map +1 -0
  47. package/cjs/form/form-summary/index.d.ts +8 -0
  48. package/cjs/form/form-summary/index.js +24 -0
  49. package/cjs/form/form-summary/index.js.map +1 -0
  50. package/cjs/index.d.ts +3 -2
  51. package/cjs/index.js +5 -3
  52. package/cjs/index.js.map +1 -1
  53. package/cjs/layout/stack/Spacer.js +1 -1
  54. package/cjs/layout/stack/Spacer.js.map +1 -1
  55. package/cjs/util/hooks/descendants/descendant.js +10 -1
  56. package/cjs/util/hooks/descendants/descendant.js.map +1 -1
  57. package/cjs/util/hooks/descendants/useDescendant.js +0 -5
  58. package/cjs/util/hooks/descendants/useDescendant.js.map +1 -1
  59. package/esm/collapsible/Collapsible.context.d.ts +48 -0
  60. package/esm/collapsible/Collapsible.context.js +6 -0
  61. package/esm/collapsible/Collapsible.context.js.map +1 -0
  62. package/esm/collapsible/Collapsible.d.ts +48 -0
  63. package/esm/collapsible/Collapsible.js +62 -0
  64. package/esm/collapsible/Collapsible.js.map +1 -0
  65. package/esm/collapsible/Collapsible.types.d.ts +19 -0
  66. package/esm/collapsible/Collapsible.types.js +2 -0
  67. package/esm/collapsible/Collapsible.types.js.map +1 -0
  68. package/esm/collapsible/index.d.ts +3 -0
  69. package/esm/collapsible/index.js +5 -0
  70. package/esm/collapsible/index.js.map +1 -0
  71. package/esm/collapsible/parts/Collapsible.Content.d.ts +10 -0
  72. package/esm/collapsible/parts/Collapsible.Content.js +22 -0
  73. package/esm/collapsible/parts/Collapsible.Content.js.map +1 -0
  74. package/esm/collapsible/parts/Collapsible.Trigger.d.ts +10 -0
  75. package/esm/collapsible/parts/Collapsible.Trigger.js +23 -0
  76. package/esm/collapsible/parts/Collapsible.Trigger.js.map +1 -0
  77. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +2 -4
  78. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
  79. package/esm/form/combobox/Input/Input.js +6 -1
  80. package/esm/form/combobox/Input/Input.js.map +1 -1
  81. package/esm/form/form-summary/FormSummary.d.ts +82 -0
  82. package/esm/form/form-summary/FormSummary.js +52 -0
  83. package/esm/form/form-summary/FormSummary.js.map +1 -0
  84. package/esm/form/form-summary/FormSummaryAnswer.d.ts +11 -0
  85. package/esm/form/form-summary/FormSummaryAnswer.js +19 -0
  86. package/esm/form/form-summary/FormSummaryAnswer.js.map +1 -0
  87. package/esm/form/form-summary/FormSummaryAnswers.d.ts +9 -0
  88. package/esm/form/form-summary/FormSummaryAnswers.js +19 -0
  89. package/esm/form/form-summary/FormSummaryAnswers.js.map +1 -0
  90. package/esm/form/form-summary/FormSummaryEditLink.d.ts +17 -0
  91. package/esm/form/form-summary/FormSummaryEditLink.js +20 -0
  92. package/esm/form/form-summary/FormSummaryEditLink.js.map +1 -0
  93. package/esm/form/form-summary/FormSummaryHeader.d.ts +9 -0
  94. package/esm/form/form-summary/FormSummaryHeader.js +19 -0
  95. package/esm/form/form-summary/FormSummaryHeader.js.map +1 -0
  96. package/esm/form/form-summary/FormSummaryHeading.d.ts +14 -0
  97. package/esm/form/form-summary/FormSummaryHeading.js +5 -0
  98. package/esm/form/form-summary/FormSummaryHeading.js.map +1 -0
  99. package/esm/form/form-summary/FormSummaryLabel.d.ts +6 -0
  100. package/esm/form/form-summary/FormSummaryLabel.js +19 -0
  101. package/esm/form/form-summary/FormSummaryLabel.js.map +1 -0
  102. package/esm/form/form-summary/FormSummaryValue.d.ts +6 -0
  103. package/esm/form/form-summary/FormSummaryValue.js +20 -0
  104. package/esm/form/form-summary/FormSummaryValue.js.map +1 -0
  105. package/esm/form/form-summary/index.d.ts +8 -0
  106. package/esm/form/form-summary/index.js +10 -0
  107. package/esm/form/form-summary/index.js.map +1 -0
  108. package/esm/index.d.ts +3 -2
  109. package/esm/index.js +2 -1
  110. package/esm/index.js.map +1 -1
  111. package/esm/layout/stack/Spacer.js +1 -1
  112. package/esm/layout/stack/Spacer.js.map +1 -1
  113. package/esm/util/hooks/descendants/descendant.js +10 -1
  114. package/esm/util/hooks/descendants/descendant.js.map +1 -1
  115. package/esm/util/hooks/descendants/useDescendant.js +0 -5
  116. package/esm/util/hooks/descendants/useDescendant.js.map +1 -1
  117. package/package.json +15 -4
  118. package/src/collapsible/Collapsible.context.tsx +32 -0
  119. package/src/collapsible/Collapsible.tsx +100 -0
  120. package/src/collapsible/Collapsible.types.ts +19 -0
  121. package/src/collapsible/index.ts +10 -0
  122. package/src/collapsible/parts/Collapsible.Content.tsx +39 -0
  123. package/src/collapsible/parts/Collapsible.Trigger.tsx +42 -0
  124. package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +9 -1
  125. package/src/form/combobox/Input/Input.tsx +5 -0
  126. package/src/form/form-summary/FormSummary.tsx +106 -0
  127. package/src/form/form-summary/FormSummaryAnswer.tsx +27 -0
  128. package/src/form/form-summary/FormSummaryAnswers.tsx +25 -0
  129. package/src/form/form-summary/FormSummaryEditLink.tsx +35 -0
  130. package/src/form/form-summary/FormSummaryHeader.tsx +25 -0
  131. package/src/form/form-summary/FormSummaryHeading.tsx +23 -0
  132. package/src/form/form-summary/FormSummaryLabel.tsx +17 -0
  133. package/src/form/form-summary/FormSummaryValue.tsx +24 -0
  134. package/src/form/form-summary/index.ts +30 -0
  135. package/src/index.ts +16 -15
  136. package/src/layout/stack/Spacer.tsx +1 -1
  137. package/src/util/hooks/descendants/descendant.ts +15 -1
  138. package/src/util/hooks/descendants/useDescendant.tsx +0 -5
  139. package/src/accordion/accordion.stories.tsx +0 -286
  140. package/src/alert/alert.stories.tsx +0 -306
  141. package/src/button/button.stories.tsx +0 -185
  142. package/src/chat/chat.stories.tsx +0 -341
  143. package/src/chips/chips.stories.tsx +0 -260
  144. package/src/copybutton/copy-button.stories.tsx +0 -261
  145. package/src/date/datepicker/datepicker.stories.tsx +0 -614
  146. package/src/date/monthpicker/monthpicker.stories.tsx +0 -221
  147. package/src/dropdown/dropdown.stories.tsx +0 -124
  148. package/src/expansion-card/expansion-card.stories.tsx +0 -282
  149. package/src/form/checkbox/checkbox.stories.tsx +0 -281
  150. package/src/form/combobox/combobox.stories.tsx +0 -626
  151. package/src/form/confirmation-panel/confirmation-panel.stories.tsx +0 -128
  152. package/src/form/error-summary/error-summary.stories.tsx +0 -81
  153. package/src/form/fieldset/fieldset.stories.tsx +0 -157
  154. package/src/form/file-upload/file-upload-dropzone.stories.tsx +0 -123
  155. package/src/form/file-upload/file-upload-item.stories.tsx +0 -148
  156. package/src/form/file-upload/file-upload.stories.tsx +0 -248
  157. package/src/form/radio/radio.stories.tsx +0 -230
  158. package/src/form/search/search.stories.tsx +0 -238
  159. package/src/form/select/select.stories.tsx +0 -172
  160. package/src/form/switch/switch.stories.tsx +0 -171
  161. package/src/form/textarea/textarea.stories.tsx +0 -254
  162. package/src/form/textfield/text-field.stories.tsx +0 -143
  163. package/src/guide-panel/guidepanel.stories.tsx +0 -90
  164. package/src/help-text/help-text.stories.tsx +0 -91
  165. package/src/internal-header/header.stories.tsx +0 -229
  166. package/src/layout/bleed/Bleed.stories.tsx +0 -395
  167. package/src/layout/box/Box.stories.tsx +0 -380
  168. package/src/layout/grid/h-grid.stories.tsx +0 -122
  169. package/src/layout/page/Page.stories.tsx +0 -271
  170. package/src/layout/responsive/hide.stories.tsx +0 -80
  171. package/src/layout/responsive/show.stories.tsx +0 -80
  172. package/src/layout/sidemal-test/navno-sidemal.stories.tsx +0 -69
  173. package/src/layout/stack/stack.stories.tsx +0 -183
  174. package/src/link/stories/link.stories.tsx +0 -304
  175. package/src/link-panel/link-panel.stories.tsx +0 -59
  176. package/src/list/list.stories.tsx +0 -280
  177. package/src/loader/loader.stories.tsx +0 -82
  178. package/src/modal/modal.stories.tsx +0 -391
  179. package/src/pagination/pagination.stories.tsx +0 -110
  180. package/src/popover/popover.stories.tsx +0 -113
  181. package/src/portal/Portal.stories.tsx +0 -102
  182. package/src/read-more/readmore.stories.tsx +0 -91
  183. package/src/skeleton/skeleton.stories.tsx +0 -130
  184. package/src/stepper/stepper.stories.tsx +0 -200
  185. package/src/table/stories/table-1.stories.tsx +0 -292
  186. package/src/table/stories/table-2-expandable.stories.tsx +0 -298
  187. package/src/table/stories/table-3-async.stories.tsx +0 -179
  188. package/src/table/stories/tests/table.stories.tsx +0 -102
  189. package/src/tabs/Tabs.stories.tsx +0 -311
  190. package/src/tag/tag.stories.tsx +0 -126
  191. package/src/timeline/timeline.stories.tsx +0 -445
  192. package/src/toggle-group/ToggleGroup.stories.tsx +0 -198
  193. package/src/tooltip/tooltip.stories.tsx +0 -101
  194. package/src/typography/stories/bodylong.stories.tsx +0 -209
  195. package/src/typography/stories/bodyshort.stories.tsx +0 -208
  196. package/src/typography/stories/detail.stories.tsx +0 -115
  197. package/src/typography/stories/error-message.stories.tsx +0 -122
  198. package/src/typography/stories/heading.stories.tsx +0 -169
  199. package/src/typography/stories/label.stories.tsx +0 -131
  200. package/src/util/hooks/descendants/descendant.stories.tsx +0 -147
@@ -0,0 +1,39 @@
1
+ import React, { forwardRef } from "react";
2
+ import { Slot } from "../../util/Slot";
3
+ import { useCollapsibleContext } from "../Collapsible.context";
4
+
5
+ export interface CollapsibleContentProps
6
+ extends Omit<
7
+ React.HTMLAttributes<HTMLDivElement>,
8
+ "hidden" | "aria-controls" | "id"
9
+ > {
10
+ /**
11
+ * When true, will render element as its child. This merges classes, styles and event handlers.
12
+ * @default false
13
+ */
14
+ asChild?: boolean;
15
+ }
16
+
17
+ export const CollapsibleContent = forwardRef<
18
+ HTMLDivElement,
19
+ CollapsibleContentProps
20
+ >(({ children, asChild, ...rest }, ref) => {
21
+ const ctx = useCollapsibleContext();
22
+
23
+ const Comp = asChild ? Slot : "div";
24
+
25
+ return (
26
+ <Comp
27
+ ref={ref}
28
+ {...rest}
29
+ data-state={ctx.state}
30
+ hidden={!ctx.open}
31
+ aria-controls={ctx.open ? ctx.triggerId : undefined}
32
+ id={ctx.contentId}
33
+ >
34
+ {ctx.lazy || ctx.open ? children : null}
35
+ </Comp>
36
+ );
37
+ });
38
+
39
+ export default CollapsibleContent;
@@ -0,0 +1,42 @@
1
+ import React, { forwardRef } from "react";
2
+ import { Slot } from "../../util/Slot";
3
+ import { composeEventHandlers } from "../../util/composeEventHandlers";
4
+ import { useCollapsibleContext } from "../Collapsible.context";
5
+
6
+ export interface CollapsibleTriggerProps
7
+ extends Omit<
8
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
9
+ "id" | "aria-controls" | "aria-expanded"
10
+ > {
11
+ /**
12
+ * When true, will render element as its child. This merges classes, styles and event handlers.
13
+ * @default false
14
+ */
15
+ asChild?: boolean;
16
+ }
17
+
18
+ export const CollapsibleTrigger = forwardRef<
19
+ HTMLButtonElement,
20
+ CollapsibleTriggerProps
21
+ >(({ children, asChild, onClick, ...rest }, ref) => {
22
+ const ctx = useCollapsibleContext();
23
+
24
+ const Comp = asChild ? Slot : "button";
25
+
26
+ return (
27
+ <Comp
28
+ ref={ref}
29
+ type="button"
30
+ data-state={ctx.state}
31
+ onClick={composeEventHandlers(onClick, ctx.onOpenToggle)}
32
+ {...rest}
33
+ id={ctx.triggerId}
34
+ aria-controls={ctx.open ? ctx.contentId : undefined}
35
+ aria-expanded={ctx.open}
36
+ >
37
+ {children}
38
+ </Comp>
39
+ );
40
+ });
41
+
42
+ export default CollapsibleTrigger;
@@ -97,9 +97,17 @@ export const FilteredOptionsProvider = ({
97
97
  [filteredOptionsUtils.getAddNewOptionId(id)]: allowNewValues
98
98
  ? toComboboxOption(value)
99
99
  : undefined,
100
+ ...customOptions.reduce(
101
+ (acc, customOption) => ({
102
+ ...acc,
103
+ [filteredOptionsUtils.getOptionId(id, customOption.label)]:
104
+ customOption,
105
+ }),
106
+ {},
107
+ ),
100
108
  },
101
109
  ),
102
- [allowNewValues, id, options, value],
110
+ [allowNewValues, customOptions, id, options, value],
103
111
  );
104
112
 
105
113
  useClientLayoutEffect(() => {
@@ -128,6 +128,10 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
128
128
  removeSelectedOption(lastSelectedOption);
129
129
  }
130
130
  }
131
+ } else if (e.key === "Enter" || e.key === "Accept") {
132
+ if (activeDecendantId || value) {
133
+ e.preventDefault();
134
+ }
131
135
  } else if (e.key === "ArrowDown") {
132
136
  // Check that cursor position is at the end of the input field,
133
137
  // so we don't interfere with text editing
@@ -182,6 +186,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
182
186
  {...omit(inputProps, ["aria-invalid"])}
183
187
  ref={ref}
184
188
  value={value}
189
+ onBlur={() => virtualFocus.moveFocusToTop()}
185
190
  onChange={onChangeHandler}
186
191
  type="text"
187
192
  role="combobox"
@@ -0,0 +1,106 @@
1
+ import cl from "clsx";
2
+ import React, { HTMLAttributes, forwardRef } from "react";
3
+ import FormSummaryAnswer from "./FormSummaryAnswer";
4
+ import FormSummaryAnswers from "./FormSummaryAnswers";
5
+ import FormSummaryEditLink from "./FormSummaryEditLink";
6
+ import FormSummaryHeader from "./FormSummaryHeader";
7
+ import FormSummaryHeading from "./FormSummaryHeading";
8
+ import FormSummaryLabel from "./FormSummaryLabel";
9
+ import FormSummaryValue from "./FormSummaryValue";
10
+
11
+ interface FormSummaryComponent
12
+ extends React.ForwardRefExoticComponent<
13
+ FormSummaryProps & React.RefAttributes<HTMLDivElement>
14
+ > {
15
+ /**
16
+ * Must include `<FormSummary.Heading>` and optionally `<FormSummary.EditLink>`.
17
+ */
18
+ Header: typeof FormSummaryHeader;
19
+ /**
20
+ * Typographic Heading to use in the `FormSummary.Header` component.
21
+ */
22
+ Heading: typeof FormSummaryHeading;
23
+ /**
24
+ * Link to edit the answers to use in the `FormSummary.Header` component. Should link to the relevant part of the form.
25
+ */
26
+ EditLink: typeof FormSummaryEditLink;
27
+ /**
28
+ * Wrapper component for the answers.
29
+ */
30
+ Answers: typeof FormSummaryAnswers;
31
+ /**
32
+ * Wrapper component for each answer. To be used in the `FormSummary.Answers` component.
33
+ */
34
+ Answer: typeof FormSummaryAnswer;
35
+ /**
36
+ * Corresponds to the question in the form. To be used in the `FormSummary.Answer` component.
37
+ */
38
+ Label: typeof FormSummaryLabel;
39
+ /**
40
+ * Corresponds to the answer in the form. To be used in the `FormSummary.Answer` component.
41
+ */
42
+ Value: typeof FormSummaryValue;
43
+ }
44
+
45
+ export interface FormSummaryProps extends HTMLAttributes<HTMLDivElement> {
46
+ /**
47
+ * Must include:
48
+ *
49
+ * - `<FormSummary.Header>`
50
+ * - `<FormSummary.Answers>`
51
+ *
52
+ * @example
53
+ * <FormSummary>
54
+ * <FormSummary.Header>
55
+ * <FormSummary.Heading level="2">HeadingTekst</FormSummary.Heading>
56
+ * <FormSummary.EditLink href="#" />
57
+ * </FormSummary.Header>
58
+ * <FormSummary.Answers>
59
+ * <FormSummary.Answer>
60
+ * <FormSummary.Label>Navn</FormSummary.Label>
61
+ * <FormSummary.Value>Ola Nordmann</FormSummary.Value>
62
+ * </FormSummary.Answer>
63
+ * </FormSummary.Answers>
64
+ * </FormSummary>
65
+ */
66
+ children: React.ReactNode;
67
+ }
68
+
69
+ /**
70
+ * A summary of a previously answered form.
71
+ *
72
+ * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/formsummary)
73
+ *
74
+ * @example
75
+ * <FormSummary>
76
+ * <FormSummary.Header>
77
+ * <FormSummary.Heading level="2">HeadingTekst</FormSummary.Heading>
78
+ * <FormSummary.EditLink href="#" />
79
+ * </FormSummary.Header>
80
+ * <FormSummary.Answers>
81
+ * <FormSummary.Answer>
82
+ * <FormSummary.Label>Navn</FormSummary.Label>
83
+ * <FormSummary.Value>Ola Nordmann</FormSummary.Value>
84
+ * </FormSummary.Answer>
85
+ * </FormSummary.Answers>
86
+ * </FormSummary>
87
+ */
88
+ export const FormSummary = forwardRef<HTMLDivElement, FormSummaryProps>(
89
+ ({ children, className, ...rest }, ref) => {
90
+ return (
91
+ <div ref={ref} {...rest} className={cl("navds-form-summary", className)}>
92
+ {children}
93
+ </div>
94
+ );
95
+ },
96
+ ) as FormSummaryComponent;
97
+
98
+ FormSummary.Header = FormSummaryHeader;
99
+ FormSummary.Heading = FormSummaryHeading;
100
+ FormSummary.EditLink = FormSummaryEditLink;
101
+ FormSummary.Answers = FormSummaryAnswers;
102
+ FormSummary.Answer = FormSummaryAnswer;
103
+ FormSummary.Label = FormSummaryLabel;
104
+ FormSummary.Value = FormSummaryValue;
105
+
106
+ export default FormSummary;
@@ -0,0 +1,27 @@
1
+ import cl from "clsx";
2
+ import React from "react";
3
+
4
+ export interface FormSummaryAnswerProps
5
+ extends React.HTMLAttributes<HTMLDivElement> {
6
+ /**
7
+ * Must include:
8
+ * - `<FormSummary.Label>`
9
+ * - `<FormSummary.Value>`
10
+ */
11
+ children: React.ReactNode;
12
+ }
13
+
14
+ export const FormSummaryAnswer = React.forwardRef<
15
+ HTMLDivElement,
16
+ FormSummaryAnswerProps
17
+ >(({ children, className, ...rest }, ref) => (
18
+ <div
19
+ ref={ref}
20
+ {...rest}
21
+ className={cl("navds-form-summary__answer", className)}
22
+ >
23
+ {children}
24
+ </div>
25
+ ));
26
+
27
+ export default FormSummaryAnswer;
@@ -0,0 +1,25 @@
1
+ import cl from "clsx";
2
+ import React, { forwardRef } from "react";
3
+
4
+ export interface FormSummaryAnswersProps
5
+ extends React.HTMLAttributes<HTMLDListElement> {
6
+ /**
7
+ * Must include one or more of `<FormSummary.Answer>`.
8
+ */
9
+ children: React.ReactNode;
10
+ }
11
+
12
+ export const FormSummaryAnswers = forwardRef<
13
+ HTMLDListElement,
14
+ FormSummaryAnswersProps
15
+ >(({ children, className, ...rest }: FormSummaryAnswersProps, ref) => (
16
+ <dl
17
+ ref={ref}
18
+ {...rest}
19
+ className={cl("navds-form-summary__answers", className)}
20
+ >
21
+ {children}
22
+ </dl>
23
+ ));
24
+
25
+ export default FormSummaryAnswers;
@@ -0,0 +1,35 @@
1
+ import cl from "clsx";
2
+ import React, { forwardRef } from "react";
3
+ import { Link } from "../../link";
4
+ import { OverridableComponent } from "../../util/types";
5
+
6
+ // export type FormSummaryEditProps = Partial<LinkProps>;
7
+ export interface FormSummaryEditProps
8
+ extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
9
+ /**
10
+ * URL to the relevant part of the form, where the answers can be edited.
11
+ */
12
+ href?: string;
13
+ /**
14
+ * Link text.
15
+ *
16
+ * [How to write good links](https://aksel.nav.no/god-praksis/artikler/lenker).
17
+ * @default "Endre svar"
18
+ */
19
+ children?: React.ReactNode;
20
+ }
21
+
22
+ export const FormSummaryEditLink: OverridableComponent<
23
+ FormSummaryEditProps,
24
+ HTMLAnchorElement
25
+ > = forwardRef(({ children = "Endre svar", className, ...rest }, ref) => (
26
+ <Link
27
+ ref={ref}
28
+ {...rest}
29
+ className={cl("navds-form-summary__edit", className)}
30
+ >
31
+ {children}
32
+ </Link>
33
+ ));
34
+
35
+ export default FormSummaryEditLink;
@@ -0,0 +1,25 @@
1
+ import cl from "clsx";
2
+ import React, { forwardRef } from "react";
3
+
4
+ export interface FormSummaryHeaderProps
5
+ extends React.HTMLAttributes<HTMLDivElement> {
6
+ /**
7
+ * Must include `<FormSummary.Heading>` and optionally `<FormSummary.EditLink>`.
8
+ */
9
+ children: React.ReactNode;
10
+ }
11
+
12
+ export const FormSummaryHeader = forwardRef<
13
+ HTMLDivElement,
14
+ FormSummaryHeaderProps
15
+ >(({ children, className, ...rest }, ref) => (
16
+ <header
17
+ ref={ref}
18
+ {...rest}
19
+ className={cl("navds-form-summary__header", className)}
20
+ >
21
+ {children}
22
+ </header>
23
+ ));
24
+
25
+ export default FormSummaryHeader;
@@ -0,0 +1,23 @@
1
+ import React, { forwardRef } from "react";
2
+ import { Heading, HeadingProps } from "../../typography";
3
+
4
+ export interface FormSummaryHeadingProps
5
+ extends React.HTMLAttributes<HTMLHeadingElement> {
6
+ /**
7
+ * Heading text.
8
+ */
9
+ children: React.ReactNode;
10
+ /**
11
+ * The heading level.
12
+ */
13
+ level: Exclude<HeadingProps["level"], "1">;
14
+ }
15
+
16
+ export const FormSummaryHeading = forwardRef<
17
+ HTMLHeadingElement,
18
+ FormSummaryHeadingProps
19
+ >((props: FormSummaryHeadingProps, ref) => (
20
+ <Heading ref={ref} {...props} size="medium" />
21
+ ));
22
+
23
+ export default FormSummaryHeading;
@@ -0,0 +1,17 @@
1
+ import React, { forwardRef } from "react";
2
+ import { Label } from "../../typography";
3
+
4
+ export interface FormSummaryLabelProps
5
+ extends React.HTMLAttributes<HTMLElement> {
6
+ children: React.ReactNode;
7
+ }
8
+
9
+ export const FormSummaryLabel = forwardRef<HTMLElement, FormSummaryLabelProps>(
10
+ ({ children, ...rest }, ref) => (
11
+ <Label ref={ref} {...rest} as="dt">
12
+ {children}
13
+ </Label>
14
+ ),
15
+ );
16
+
17
+ export default FormSummaryLabel;
@@ -0,0 +1,24 @@
1
+ import cl from "clsx";
2
+ import React, { forwardRef } from "react";
3
+ import { BodyLong } from "../../typography";
4
+
5
+ export interface FormSummaryValueProps
6
+ extends React.HTMLAttributes<HTMLDivElement> {
7
+ children: React.ReactNode;
8
+ }
9
+
10
+ export const FormSummaryValue = forwardRef<
11
+ HTMLDivElement,
12
+ FormSummaryValueProps
13
+ >(({ children, className, ...rest }, ref) => (
14
+ <BodyLong
15
+ ref={ref}
16
+ {...rest}
17
+ as="dd"
18
+ className={cl("navds-form-summary__value", className)}
19
+ >
20
+ {children}
21
+ </BodyLong>
22
+ ));
23
+
24
+ export default FormSummaryValue;
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ export { default as FormSummary, type FormSummaryProps } from "./FormSummary";
3
+ export {
4
+ default as FormSummaryAnswer,
5
+ type FormSummaryAnswerProps,
6
+ } from "./FormSummaryAnswer";
7
+ export {
8
+ default as FormSummaryAnswers,
9
+ type FormSummaryAnswersProps,
10
+ } from "./FormSummaryAnswers";
11
+ export {
12
+ default as FormSummaryEditLink,
13
+ type FormSummaryEditProps,
14
+ } from "./FormSummaryEditLink";
15
+ export {
16
+ default as FormSummaryHeader,
17
+ type FormSummaryHeaderProps,
18
+ } from "./FormSummaryHeader";
19
+ export {
20
+ default as FormSummaryHeading,
21
+ type FormSummaryHeadingProps,
22
+ } from "./FormSummaryHeading";
23
+ export {
24
+ default as FormSummaryLabel,
25
+ type FormSummaryLabelProps,
26
+ } from "./FormSummaryLabel";
27
+ export {
28
+ default as FormSummaryValue,
29
+ type FormSummaryValueProps,
30
+ } from "./FormSummaryValue";
package/src/index.ts CHANGED
@@ -26,8 +26,8 @@ export { Dropdown, type DropdownProps } from "./dropdown";
26
26
  export { ExpansionCard, type ExpansionCardProps } from "./expansion-card";
27
27
  export {
28
28
  GuidePanel,
29
- type GuidePanelProps,
30
29
  GuidePanelDefaultIllustration,
30
+ type GuidePanelProps,
31
31
  } from "./guide-panel";
32
32
  export { HelpText, type HelpTextProps } from "./help-text";
33
33
  export {
@@ -125,6 +125,21 @@ export {
125
125
  } from "./form/confirmation-panel";
126
126
  export { ErrorSummary, type ErrorSummaryProps } from "./form/error-summary";
127
127
  export { Fieldset, type FieldsetProps } from "./form/fieldset";
128
+ export {
129
+ UNSAFE_FileUpload,
130
+ type FileAccepted,
131
+ type FileItem,
132
+ type FileMetadata,
133
+ type FileObject,
134
+ type FileRejected,
135
+ type FileRejectedPartitioned,
136
+ type FileRejectionReason,
137
+ type FileUploadDropzoneProps,
138
+ type FileUploadItemProps,
139
+ type FileUploadTriggerProps,
140
+ type FilesPartitioned,
141
+ } from "./form/file-upload";
142
+ export { FormSummary, type FormSummaryProps } from "./form/form-summary";
128
143
  export {
129
144
  Radio,
130
145
  RadioGroup,
@@ -136,20 +151,6 @@ export { Select, type SelectProps } from "./form/select";
136
151
  export { Switch, type SwitchProps } from "./form/switch";
137
152
  export { Textarea, type TextareaProps } from "./form/textarea";
138
153
  export { TextField, type TextFieldProps } from "./form/textfield";
139
- export {
140
- UNSAFE_FileUpload,
141
- type FileUploadDropzoneProps,
142
- type FileUploadTriggerProps,
143
- type FileObject,
144
- type FileRejected,
145
- type FileAccepted,
146
- type FileRejectedPartitioned,
147
- type FilesPartitioned,
148
- type FileRejectionReason,
149
- type FileUploadItemProps,
150
- type FileItem,
151
- type FileMetadata,
152
- } from "./form/file-upload";
153
154
 
154
155
  /**
155
156
  * @deprecated
@@ -12,6 +12,6 @@ import React from "react";
12
12
  * <MyComponent />
13
13
  * </HStack>
14
14
  */
15
- export const Spacer = () => <div className="navds-stack__spacer" />;
15
+ export const Spacer = () => <span className="navds-stack__spacer" />;
16
16
 
17
17
  export default Spacer;
@@ -143,7 +143,21 @@ export class DescendantsManager<
143
143
  };
144
144
 
145
145
  private registerNode = (node: T | null, options?: DescendantOptions<K>) => {
146
- if (!node || this.descendants.has(node)) return;
146
+ if (!node) return;
147
+
148
+ /**
149
+ * While the node is registered, we have to make sure to sync options
150
+ * This is useful when ex. a node is disabled after it has been registered
151
+ */
152
+ const mapNode = this.descendants.get(node);
153
+ if (mapNode) {
154
+ this.descendants.set(node, {
155
+ index: mapNode.index,
156
+ node,
157
+ ...options,
158
+ } as Descendant<T, K>);
159
+ return;
160
+ }
147
161
 
148
162
  const keys = Array.from(this.descendants.keys()).concat(node);
149
163
  const sorted = sortNodes(keys);
@@ -17,11 +17,6 @@ function useDescendants<
17
17
  K extends Record<string, any> = object,
18
18
  >() {
19
19
  const descendants = useRef(new DescendantsManager<T, K>()).current;
20
- useClientLayoutEffect(() => {
21
- return () => {
22
- descendants.destroy();
23
- };
24
- });
25
20
 
26
21
  return descendants;
27
22
  }