@navikt/ds-react 5.18.1 → 5.18.3

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 (53) hide show
  1. package/cjs/date/parts/DateWrapper.js +2 -2
  2. package/cjs/form/search/Search.js +1 -1
  3. package/cjs/modal/Modal.context.js +9 -0
  4. package/cjs/modal/Modal.js +3 -6
  5. package/cjs/modal/ModalHeader.js +2 -6
  6. package/cjs/popover/Popover.js +2 -2
  7. package/cjs/tooltip/Tooltip.js +3 -3
  8. package/cjs/util/create-context.js +9 -5
  9. package/esm/date/parts/DateWrapper.js +3 -3
  10. package/esm/date/parts/DateWrapper.js.map +1 -1
  11. package/esm/form/search/Search.js +1 -1
  12. package/esm/modal/Modal.context.d.ts +9 -0
  13. package/esm/modal/Modal.context.js +6 -0
  14. package/esm/modal/Modal.context.js.map +1 -0
  15. package/esm/modal/Modal.js +3 -6
  16. package/esm/modal/Modal.js.map +1 -1
  17. package/esm/modal/ModalHeader.js +3 -7
  18. package/esm/modal/ModalHeader.js.map +1 -1
  19. package/esm/popover/Popover.js +2 -2
  20. package/esm/popover/Popover.js.map +1 -1
  21. package/esm/tooltip/Tooltip.js +4 -4
  22. package/esm/tooltip/Tooltip.js.map +1 -1
  23. package/esm/util/create-context.d.ts +2 -5
  24. package/esm/util/create-context.js +10 -6
  25. package/esm/util/create-context.js.map +1 -1
  26. package/package.json +3 -3
  27. package/src/accordion/accordion.stories.tsx +121 -135
  28. package/src/chat/chat.stories.tsx +284 -206
  29. package/src/date/parts/DateWrapper.tsx +3 -3
  30. package/src/form/search/Search.tsx +3 -3
  31. package/src/modal/Modal.context.ts +13 -0
  32. package/src/modal/Modal.tsx +6 -8
  33. package/src/modal/ModalHeader.tsx +3 -7
  34. package/src/popover/Popover.tsx +2 -2
  35. package/src/table/stories/{table.stories.tsx → table-1.stories.tsx} +117 -94
  36. package/src/table/stories/{table-expandable.stories.tsx → table-2-expandable.stories.tsx} +6 -32
  37. package/src/table/stories/{table-async.stories.tsx → table-3-async.stories.tsx} +1 -1
  38. package/src/table/stories/tests/table.stories.tsx +3 -0
  39. package/src/tabs/Tabs.test.tsx +109 -0
  40. package/src/toggle-group/ToggleGroup.test.tsx +54 -0
  41. package/src/tooltip/Tooltip.tsx +4 -10
  42. package/src/typography/stories/bodylong.stories.tsx +47 -1
  43. package/src/typography/stories/bodyshort.stories.tsx +48 -2
  44. package/src/typography/stories/detail.stories.tsx +30 -1
  45. package/src/typography/stories/error-message.stories.tsx +32 -1
  46. package/src/typography/stories/heading.stories.tsx +30 -1
  47. package/src/typography/stories/label.stories.tsx +36 -1
  48. package/src/util/create-context.tsx +26 -15
  49. package/cjs/modal/ModalContext.js +0 -8
  50. package/esm/modal/ModalContext.d.ts +0 -7
  51. package/esm/modal/ModalContext.js +0 -3
  52. package/esm/modal/ModalContext.js.map +0 -1
  53. package/src/modal/ModalContext.ts +0 -7
@@ -1,6 +1,6 @@
1
- import { Meta } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react";
2
2
  import React from "react";
3
- import { Chat } from "../index";
3
+ import { Chat, VStack } from "../index";
4
4
  import { POSITIONS, SIZES } from "./Chat";
5
5
 
6
6
  export default {
@@ -30,9 +30,14 @@ export default {
30
30
  options: SIZES,
31
31
  },
32
32
  },
33
+ parameters: {
34
+ chromatic: { disable: true },
35
+ },
33
36
  } satisfies Meta<typeof Chat>;
34
37
 
35
- export const Default = {
38
+ type Story = StoryObj<typeof Chat>;
39
+
40
+ export const Controls: Story = {
36
41
  render: (props) => {
37
42
  return (
38
43
  <Chat {...props}>
@@ -55,219 +60,292 @@ export const Default = {
55
60
  },
56
61
  };
57
62
 
58
- export const Small = () => (
59
- <Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 14:00" size="small">
60
- <Chat.Bubble>
61
- Aute minim nisi sunt mollit duis sunt nulla minim non proident.
62
- </Chat.Bubble>
63
- <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
64
- <Chat.Bubble>
65
- Adipisicing laborum est eu laborum est sit in commodo enim sint laboris
66
- labore nisi ut.
67
- </Chat.Bubble>
68
- </Chat>
69
- );
63
+ export const Size: Story = {
64
+ render: () => (
65
+ <VStack gap="4">
66
+ <h3>Medium</h3>
67
+ <Chat
68
+ avatar="ON"
69
+ name="Ola Normann"
70
+ timestamp="01.01.21 14:00"
71
+ size="medium"
72
+ >
73
+ <Chat.Bubble>
74
+ Aute minim nisi sunt mollit duis sunt nulla minim non proident.
75
+ </Chat.Bubble>
76
+ <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
77
+ <Chat.Bubble>
78
+ Adipisicing laborum est eu laborum est sit in commodo enim sint
79
+ laboris labore nisi ut.
80
+ </Chat.Bubble>
81
+ </Chat>
82
+ <h3>Small</h3>
83
+ <Chat
84
+ avatar="ON"
85
+ name="Ola Normann"
86
+ timestamp="01.01.21 14:00"
87
+ size="small"
88
+ >
89
+ <Chat.Bubble>
90
+ Aute minim nisi sunt mollit duis sunt nulla minim non proident.
91
+ </Chat.Bubble>
92
+ <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
93
+ <Chat.Bubble>
94
+ Adipisicing laborum est eu laborum est sit in commodo enim sint
95
+ laboris labore nisi ut.
96
+ </Chat.Bubble>
97
+ </Chat>
98
+ </VStack>
99
+ ),
100
+ };
101
+
102
+ export const Variants: Story = {
103
+ render: () => (
104
+ <VStack gap="4">
105
+ <h3>Info</h3>
106
+ <Chat avatar="NAV" name="NAV" timestamp="01.01.21 14:00" variant="info">
107
+ <Chat.Bubble>
108
+ Aute minim nisi sunt mollit duis sunt nulla minim non proident.
109
+ </Chat.Bubble>
110
+ </Chat>
111
+ <h3>Neutral</h3>
112
+ <Chat
113
+ avatar="KN"
114
+ name="Kari Nordmann"
115
+ timestamp="01.01.21 14:03"
116
+ variant="neutral"
117
+ position="right"
118
+ >
119
+ <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
120
+ </Chat>
121
+ <h3>Subtle</h3>
122
+ <Chat
123
+ avatar="ON"
124
+ name="Ola Nordmann"
125
+ timestamp="01.01.21 14:07"
126
+ variant="subtle"
127
+ position="right"
128
+ >
129
+ <Chat.Bubble>
130
+ Adipisicing laborum est eu laborum est sit in commodo enim sint
131
+ laboris labore nisi ut.
132
+ </Chat.Bubble>
133
+ </Chat>
134
+ </VStack>
135
+ ),
136
+ };
70
137
 
71
- export const Colors = () => (
72
- <Chat
73
- avatar="NAV"
74
- name="NAV"
75
- timestamp="01.01.21 14:00"
76
- avatarBgColor="var(--a-surface-alt-1-subtle)"
77
- backgroundColor="var(--a-surface-warning-subtle)"
78
- >
79
- <Chat.Bubble>
80
- Aute minim nisi sunt mollit duis sunt nulla minim non proident.
81
- </Chat.Bubble>
82
- <Chat.Bubble backgroundColor="lightYellow">
83
- Tempor fugiat amet eu sint in in ullamco.
84
- </Chat.Bubble>
85
- <Chat.Bubble>
86
- Adipisicing laborum est eu laborum est sit in commodo enim sint laboris
87
- labore nisi ut.
88
- </Chat.Bubble>
89
- </Chat>
90
- );
138
+ export const Position: Story = {
139
+ render: () => (
140
+ <VStack gap="4">
141
+ <h3>Default</h3>
142
+ <Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 14:00">
143
+ <Chat.Bubble>
144
+ Adipisicing laborum est eu laborum est sit in commodo enim sint
145
+ laboris labore nisi ut.
146
+ </Chat.Bubble>
147
+ </Chat>
148
+ <h3>Right</h3>
149
+ <Chat
150
+ avatar="KH"
151
+ name="Kari Høyli"
152
+ timestamp="01.01.21 14:32"
153
+ position="right"
154
+ variant="info"
155
+ >
156
+ <Chat.Bubble>
157
+ Reprehenderit pariatur officia exercitation laboris.
158
+ </Chat.Bubble>
159
+ <Chat.Bubble>
160
+ Enim velit deserunt do quis. Eu fugiat magna esse dolore ad sunt sit
161
+ est dolore incididunt. Occaecat cupidatat magna.
162
+ </Chat.Bubble>
163
+ </Chat>
164
+ <h3>Left</h3>
165
+ <Chat
166
+ position="left"
167
+ avatar="ON"
168
+ name="Ola Normann"
169
+ timestamp="01.01.21 15:00"
170
+ >
171
+ <Chat.Bubble>
172
+ Exercitation irure Lorem cupidatat culpa anim cillum esse ullamco qui
173
+ dolore laborum et Lorem. Labore sunt duis id Lorem voluptate commodo
174
+ ea esse. Dolore esse aliqua proident ea ad commodo ut dolore voluptate
175
+ labore sunt aute.
176
+ </Chat.Bubble>
177
+ </Chat>
178
+ </VStack>
179
+ ),
180
+ };
91
181
 
92
- export const Variants = () => (
93
- <div className="colgap">
94
- <Chat avatar="NAV" name="NAV" timestamp="01.01.21 14:00" variant="info">
182
+ export const ToptextPosition: Story = {
183
+ render: () => (
184
+ <VStack gap="4">
185
+ <h3>Right</h3>
186
+ <Chat
187
+ avatar="ON"
188
+ name="Ola Normann"
189
+ timestamp="01.01.21 14:00"
190
+ toptextPosition="right"
191
+ >
192
+ <Chat.Bubble>
193
+ Adipisicing laborum est eu laborum est sit in commodo enim sint
194
+ laboris labore nisi ut.
195
+ </Chat.Bubble>
196
+ </Chat>
197
+ <h3>Left</h3>
198
+ <Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 15:00">
199
+ <Chat.Bubble toptextPosition="left">
200
+ Exercitation irure Lorem cupidatat culpa anim cillum esse ullamco qui
201
+ dolore laborum et Lorem. Labore sunt duis id Lorem voluptate commodo
202
+ ea esse. Dolore esse aliqua proident ea ad commodo ut dolore voluptate
203
+ labore sunt aute.
204
+ </Chat.Bubble>
205
+ </Chat>
206
+ <h3>Left</h3>
207
+ <Chat
208
+ name="Kari Høyli"
209
+ timestamp="01.01.21 14:32"
210
+ position="right"
211
+ toptextPosition="left"
212
+ >
213
+ <Chat.Bubble>
214
+ Reprehenderit pariatur officia exercitation laboris.
215
+ </Chat.Bubble>
216
+ <Chat.Bubble>
217
+ Enim velit deserunt do quis. Eu fugiat magna esse dolore ad sunt sit
218
+ est dolore incididunt. Occaecat cupidatat magna.
219
+ </Chat.Bubble>
220
+ </Chat>
221
+ <h3>Right</h3>
222
+ <Chat
223
+ name="Kari Høyli"
224
+ timestamp="01.01.21 14:32"
225
+ position="right"
226
+ toptextPosition="right"
227
+ >
228
+ <Chat.Bubble>
229
+ Reprehenderit pariatur officia exercitation laboris.
230
+ </Chat.Bubble>
231
+ <Chat.Bubble>
232
+ Enim velit deserunt do quis. Eu fugiat magna esse dolore ad sunt sit
233
+ est dolore incididunt. Occaecat cupidatat magna.
234
+ </Chat.Bubble>
235
+ </Chat>
236
+ </VStack>
237
+ ),
238
+ };
239
+
240
+ export const Avatar: Story = {
241
+ render: () => (
242
+ <Chat avatar={<Illustration />}>
95
243
  <Chat.Bubble>
96
244
  Aute minim nisi sunt mollit duis sunt nulla minim non proident.
97
245
  </Chat.Bubble>
98
- </Chat>
99
- <Chat
100
- avatar="KN"
101
- name="Kari Nordmann"
102
- timestamp="01.01.21 14:03"
103
- variant="neutral"
104
- position="right"
105
- >
106
246
  <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
107
- </Chat>
108
- <Chat
109
- avatar="ON"
110
- name="Ola Nordmann"
111
- timestamp="01.01.21 14:07"
112
- variant="subtle"
113
- position="right"
114
- >
115
- <Chat.Bubble>
116
- Adipisicing laborum est eu laborum est sit in commodo enim sint laboris
117
- labore nisi ut.
118
- </Chat.Bubble>
119
- </Chat>
120
- </div>
121
- );
122
-
123
- export const Position = () => (
124
- <div className="colgap">
125
- <Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 14:00">
126
247
  <Chat.Bubble>
127
248
  Adipisicing laborum est eu laborum est sit in commodo enim sint laboris
128
249
  labore nisi ut.
129
250
  </Chat.Bubble>
130
251
  </Chat>
131
- <Chat
132
- avatar="KH"
133
- name="Kari Høyli"
134
- timestamp="01.01.21 14:32"
135
- position="right"
136
- variant="info"
137
- >
138
- <Chat.Bubble>
139
- Reprehenderit pariatur officia exercitation laboris.
140
- </Chat.Bubble>
141
- <Chat.Bubble>
142
- Enim velit deserunt do quis. Eu fugiat magna esse dolore ad sunt sit est
143
- dolore incididunt. Occaecat cupidatat magna.
144
- </Chat.Bubble>
145
- </Chat>
146
- <Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 15:00">
147
- <Chat.Bubble>
148
- Exercitation irure Lorem cupidatat culpa anim cillum esse ullamco qui
149
- dolore laborum et Lorem. Labore sunt duis id Lorem voluptate commodo ea
150
- esse. Dolore esse aliqua proident ea ad commodo ut dolore voluptate
151
- labore sunt aute.
152
- </Chat.Bubble>
153
- </Chat>
154
- </div>
155
- );
156
-
157
- export const ToptextPosition = () => (
158
- <div className="colgap">
159
- <Chat
160
- avatar="ON"
161
- name="Ola Normann"
162
- timestamp="01.01.21 14:00"
163
- toptextPosition="right"
164
- >
165
- <Chat.Bubble>
166
- Adipisicing laborum est eu laborum est sit in commodo enim sint laboris
167
- labore nisi ut.
168
- </Chat.Bubble>
169
- </Chat>
170
- <Chat
171
- name="Kari Høyli"
172
- timestamp="01.01.21 14:32"
173
- position="right"
174
- variant="info"
175
- toptextPosition="left"
176
- >
177
- <Chat.Bubble>
178
- Reprehenderit pariatur officia exercitation laboris.
179
- </Chat.Bubble>
180
- <Chat.Bubble>
181
- Enim velit deserunt do quis. Eu fugiat magna esse dolore ad sunt sit est
182
- dolore incididunt. Occaecat cupidatat magna.
183
- </Chat.Bubble>
184
- </Chat>
185
- <Chat avatar="ON" name="Ola Normann" timestamp="01.01.21 15:00">
186
- <Chat.Bubble toptextPosition="right">
187
- Exercitation irure Lorem cupidatat culpa anim cillum esse ullamco qui
188
- dolore laborum et Lorem. Labore sunt duis id Lorem voluptate commodo ea
189
- esse. Dolore esse aliqua proident ea ad commodo ut dolore voluptate
190
- labore sunt aute.
191
- </Chat.Bubble>
192
- </Chat>
193
- </div>
194
- );
252
+ ),
253
+ };
195
254
 
196
- export const Avatar = () => (
197
- <Chat avatar={<Illustration />} timestamp="01.01.21 14:00">
198
- <Chat.Bubble>
199
- Aute minim nisi sunt mollit duis sunt nulla minim non proident.
200
- </Chat.Bubble>
201
- <Chat.Bubble>Tempor fugiat amet eu sint in in ullamco.</Chat.Bubble>
202
- <Chat.Bubble>
203
- Adipisicing laborum est eu laborum est sit in commodo enim sint laboris
204
- labore nisi ut.
205
- </Chat.Bubble>
206
- </Chat>
207
- );
255
+ function Illustration() {
256
+ return (
257
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 54 93">
258
+ <path
259
+ fill="#e7e5e2"
260
+ d="M14 50.7C15 52.3 17.9 81 26.5 81S39 51.8 39 50.3c-13.2-7.6-25 .4-25 .4z"
261
+ />
262
+ <path
263
+ fill="#5c4378"
264
+ d="M38.7 50.2c6 2.9 15.3 10.9 15.3 18.3V93H0V68.5c0-7.1 8.5-14.8 14.5-18-.3.2-.5.3-.5.3 1 1.7 3.8 9.2 12.4 9.2C35 60 39 51.9 39 50.4c-.1-.1-.2-.2-.3-.2z"
265
+ />
266
+ <path
267
+ fill="#d2242a"
268
+ d="M46.7 76H31.2c-.7 0-1.3-.6-1.2-1.3v-8.5c0-.7.6-1.3 1.3-1.3h15.5c.7 0 1.3.6 1.3 1.3v8.5c-.1.7-.7 1.3-1.4 1.3"
269
+ />
270
+ <path
271
+ fill="#fff"
272
+ d="M42.9 71c0 2.1-1.7 3.8-3.8 3.8-2.1 0-3.8-1.7-3.8-3.8s1.7-3.8 3.8-3.8c2.1 0 3.8 1.7 3.8 3.8m-8.7 1.7h-.7l.8-1.9h.7l-.8 1.9zm9.3 0H43l.8-1.9h.5l-.8 1.9zm1.2 0h-.2l.8-1.9h.2l-.8 1.9z"
273
+ />
274
+ <path
275
+ fill="#c52d35"
276
+ d="M36.2 72.7h.6s.1 0 .1-.1v-1.8s0-.1-.1-.1h-.6s-.1 0-.1.1l-.2.6v.1h.2l.1 1.2c0-.1 0 0 0 0"
277
+ />
278
+ <path
279
+ fill="#c52d35"
280
+ d="M37.5 72.7h.6s.1 0 .1-.1v-1.8s0-.1-.1-.1h-.9s-.1 0-.1.1l-.2.6-.1.1h.5c.1 0 .2.1.2.2v1c-.1-.1-.1 0 0 0m2.6-1.9h-.6s-.1 0-.1.1v1.8s0 .1.1.1h.6s.1 0 .1-.1l.2-.6V72h-.2l-.1-1.2"
281
+ />
282
+ <path
283
+ fill="#c52d35"
284
+ d="M37.7 72.7h.4s.1 0 .1-.1l.2-.6v-.1h-.2c0 .1-.5.8-.5.8zm3.9-1.9h.7s.1 0 0 .1l-.7 1.8H41l.6-1.9"
285
+ />
286
+ <path
287
+ fill="#c52d35"
288
+ d="M40.8 70.8h-1c-.1 0 .3.1.3.1l.7 1.7s0 .1.1.1h.6l-.7-1.9m-1.3.6v.4s-.1-.4-.3-.4c-.3 0-.3.2-.3.3 0 .1.1.3.2.3h.5l-.3.7H39c-.2 0-.9-.3-.9-.9 0-.6.5-1 .9-1 .2-.1.5.2.5.6 0-.1 0-.1 0 0z"
289
+ />
290
+ <path
291
+ fill="#5a1f57"
292
+ d="M39.9 66.7h-1.6c-.1 0-.2-.1-.2-.2v-.3c0-.1.1-.2.2-.2h1.6c.1 0 .2.1.2.2v.3c0 .2-.1.2-.2.2"
293
+ />
294
+ <path fill="#c2b5cf" d="M38.7 66.5h.9V64h-.9v2.5z" />
295
+ <path
296
+ fill="#e7e5e2"
297
+ d="M47.2 35.3C44.7 45.6 36.6 53.1 27 53.1S9.3 45.6 6.8 35.3c-.2.1-.5.1-.8.1-1.1 0-2-.8-2-1.7v-7c0-1 .9-1.7 2-1.7h.2C7.7 13.1 16.4 4 27 4c10.6 0 19.3 9.1 20.8 21h.2c1.1 0 2 .8 2 1.7v7c0 1-.9 1.7-2 1.7-.3 0-.5 0-.8-.1z"
298
+ />
299
+ <path
300
+ fill="#635e59"
301
+ d="M19 27.6c-1.4.1-1.9-2-1.4-3.4.1-.3.6-1.5 1.4-1.5.8 0 1.2.7 1.3.8.6 1.4.3 4-1.3 4.1m16.2 0c1.4.1 1.9-2 1.4-3.4-.1-.3-.6-1.5-1.4-1.5-.8 0-1.2.7-1.3.8-.6 1.4-.3 4 1.3 4.1"
302
+ />
303
+ <path
304
+ fill="#d1bfa3"
305
+ d="M26.8 34.6c-.4 0-.7-.1-1-.2-.3-.1-.4-.4-.3-.7.1-.3.4-.4.7-.3.5.2 1.5.1 2.2-.4.7-.4 1.1-1 1.2-1.5.1-.4-.1-.9-.4-1.3-.2-.2-.8-.2-1.6-.1-.3 0-.5-.1-.6-.4 0-.3.1-.5.4-.6 1.2-.2 2.1 0 2.6.6.5.7.8 1.4.6 2.1-.1.8-.7 1.6-1.7 2.2-.6.3-1.4.6-2.1.6z"
306
+ />
307
+ <path
308
+ fill="#593a32"
309
+ d="M27.1 42.1h-.3c-5.3-.2-7.3-4.1-7.4-4.3-.1-.3 0-.6.2-.7.2-.1.6 0 .7.2.1.1 1.9 3.6 6.6 3.8 4.7.2 6.4-3.7 6.4-3.7.1-.3.4-.4.7-.3.3.1.4.4.3.7-.1 0-2.1 4.3-7.2 4.3z"
310
+ />
311
+ <path
312
+ fill="#f6b873"
313
+ d="M6.6 30.7c.1-.1.1-.2.1-.3v-2c-.1-5.6 1.8-8.1 3.4-10.1 0 0-1 4.3-.3 3.4 3.8-5 21.4-1.6 25-8.1.5 3.6-4.1 4.6-4.1 4.6 3.7.7 6.9-.8 7.7-2.5.3 1.4-.6 2.4-1.9 3.4 4.5-.9 4.6-4 4.6-4 .6 4.1 5.3 2.5 5.3 9.3v6c0 .3.2.6.5.6h.5c.3 0 .5-.3.5-.6V26c.3-15.6-8.5-26-20.6-26C15.9 0 5 10.4 5 24.1v6.3c0 .4.2.6.5.6h.6c.2 0 .3-.1.5-.3"
314
+ />
315
+ <path
316
+ fill="#f6b873"
317
+ d="M25.9 43.4c-4.4 0-8-1.4-8-3.2s3.6-3.2 8-3.2 8 1.4 8 3.2c0 1.8-3.6 3.2-8 3.2m.8-9.4c-2.9 0-4.7.7-8.8 2.1-12.7 4.6-11.6-14-11.6-14C3.4 46 18.6 52 26.5 52c8.1 0 24.1-8.1 21-30 0 0 .4 17.1-12.9 13.8-3.7-.9-5-1.8-7.9-1.8z"
318
+ />
319
+ </svg>
320
+ );
321
+ }
208
322
 
209
- const Illustration = () => (
210
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 54 93">
211
- <path
212
- fill="#e7e5e2"
213
- d="M14 50.7C15 52.3 17.9 81 26.5 81S39 51.8 39 50.3c-13.2-7.6-25 .4-25 .4z"
214
- />
215
- <path
216
- fill="#5c4378"
217
- d="M38.7 50.2c6 2.9 15.3 10.9 15.3 18.3V93H0V68.5c0-7.1 8.5-14.8 14.5-18-.3.2-.5.3-.5.3 1 1.7 3.8 9.2 12.4 9.2C35 60 39 51.9 39 50.4c-.1-.1-.2-.2-.3-.2z"
218
- />
219
- <path
220
- fill="#d2242a"
221
- d="M46.7 76H31.2c-.7 0-1.3-.6-1.2-1.3v-8.5c0-.7.6-1.3 1.3-1.3h15.5c.7 0 1.3.6 1.3 1.3v8.5c-.1.7-.7 1.3-1.4 1.3"
222
- />
223
- <path
224
- fill="#fff"
225
- d="M42.9 71c0 2.1-1.7 3.8-3.8 3.8-2.1 0-3.8-1.7-3.8-3.8s1.7-3.8 3.8-3.8c2.1 0 3.8 1.7 3.8 3.8m-8.7 1.7h-.7l.8-1.9h.7l-.8 1.9zm9.3 0H43l.8-1.9h.5l-.8 1.9zm1.2 0h-.2l.8-1.9h.2l-.8 1.9z"
226
- />
227
- <path
228
- fill="#c52d35"
229
- d="M36.2 72.7h.6s.1 0 .1-.1v-1.8s0-.1-.1-.1h-.6s-.1 0-.1.1l-.2.6v.1h.2l.1 1.2c0-.1 0 0 0 0"
230
- />
231
- <path
232
- fill="#c52d35"
233
- d="M37.5 72.7h.6s.1 0 .1-.1v-1.8s0-.1-.1-.1h-.9s-.1 0-.1.1l-.2.6-.1.1h.5c.1 0 .2.1.2.2v1c-.1-.1-.1 0 0 0m2.6-1.9h-.6s-.1 0-.1.1v1.8s0 .1.1.1h.6s.1 0 .1-.1l.2-.6V72h-.2l-.1-1.2"
234
- />
235
- <path
236
- fill="#c52d35"
237
- d="M37.7 72.7h.4s.1 0 .1-.1l.2-.6v-.1h-.2c0 .1-.5.8-.5.8zm3.9-1.9h.7s.1 0 0 .1l-.7 1.8H41l.6-1.9"
238
- />
239
- <path
240
- fill="#c52d35"
241
- d="M40.8 70.8h-1c-.1 0 .3.1.3.1l.7 1.7s0 .1.1.1h.6l-.7-1.9m-1.3.6v.4s-.1-.4-.3-.4c-.3 0-.3.2-.3.3 0 .1.1.3.2.3h.5l-.3.7H39c-.2 0-.9-.3-.9-.9 0-.6.5-1 .9-1 .2-.1.5.2.5.6 0-.1 0-.1 0 0z"
242
- />
243
- <path
244
- fill="#5a1f57"
245
- d="M39.9 66.7h-1.6c-.1 0-.2-.1-.2-.2v-.3c0-.1.1-.2.2-.2h1.6c.1 0 .2.1.2.2v.3c0 .2-.1.2-.2.2"
246
- />
247
- <path fill="#c2b5cf" d="M38.7 66.5h.9V64h-.9v2.5z" />
248
- <path
249
- fill="#e7e5e2"
250
- d="M47.2 35.3C44.7 45.6 36.6 53.1 27 53.1S9.3 45.6 6.8 35.3c-.2.1-.5.1-.8.1-1.1 0-2-.8-2-1.7v-7c0-1 .9-1.7 2-1.7h.2C7.7 13.1 16.4 4 27 4c10.6 0 19.3 9.1 20.8 21h.2c1.1 0 2 .8 2 1.7v7c0 1-.9 1.7-2 1.7-.3 0-.5 0-.8-.1z"
251
- />
252
- <path
253
- fill="#635e59"
254
- d="M19 27.6c-1.4.1-1.9-2-1.4-3.4.1-.3.6-1.5 1.4-1.5.8 0 1.2.7 1.3.8.6 1.4.3 4-1.3 4.1m16.2 0c1.4.1 1.9-2 1.4-3.4-.1-.3-.6-1.5-1.4-1.5-.8 0-1.2.7-1.3.8-.6 1.4-.3 4 1.3 4.1"
255
- />
256
- <path
257
- fill="#d1bfa3"
258
- d="M26.8 34.6c-.4 0-.7-.1-1-.2-.3-.1-.4-.4-.3-.7.1-.3.4-.4.7-.3.5.2 1.5.1 2.2-.4.7-.4 1.1-1 1.2-1.5.1-.4-.1-.9-.4-1.3-.2-.2-.8-.2-1.6-.1-.3 0-.5-.1-.6-.4 0-.3.1-.5.4-.6 1.2-.2 2.1 0 2.6.6.5.7.8 1.4.6 2.1-.1.8-.7 1.6-1.7 2.2-.6.3-1.4.6-2.1.6z"
259
- />
260
- <path
261
- fill="#593a32"
262
- d="M27.1 42.1h-.3c-5.3-.2-7.3-4.1-7.4-4.3-.1-.3 0-.6.2-.7.2-.1.6 0 .7.2.1.1 1.9 3.6 6.6 3.8 4.7.2 6.4-3.7 6.4-3.7.1-.3.4-.4.7-.3.3.1.4.4.3.7-.1 0-2.1 4.3-7.2 4.3z"
263
- />
264
- <path
265
- fill="#f6b873"
266
- d="M6.6 30.7c.1-.1.1-.2.1-.3v-2c-.1-5.6 1.8-8.1 3.4-10.1 0 0-1 4.3-.3 3.4 3.8-5 21.4-1.6 25-8.1.5 3.6-4.1 4.6-4.1 4.6 3.7.7 6.9-.8 7.7-2.5.3 1.4-.6 2.4-1.9 3.4 4.5-.9 4.6-4 4.6-4 .6 4.1 5.3 2.5 5.3 9.3v6c0 .3.2.6.5.6h.5c.3 0 .5-.3.5-.6V26c.3-15.6-8.5-26-20.6-26C15.9 0 5 10.4 5 24.1v6.3c0 .4.2.6.5.6h.6c.2 0 .3-.1.5-.3"
267
- />
268
- <path
269
- fill="#f6b873"
270
- d="M25.9 43.4c-4.4 0-8-1.4-8-3.2s3.6-3.2 8-3.2 8 1.4 8 3.2c0 1.8-3.6 3.2-8 3.2m.8-9.4c-2.9 0-4.7.7-8.8 2.1-12.7 4.6-11.6-14-11.6-14C3.4 46 18.6 52 26.5 52c8.1 0 24.1-8.1 21-30 0 0 .4 17.1-12.9 13.8-3.7-.9-5-1.8-7.9-1.8z"
271
- />
272
- </svg>
273
- );
323
+ export const Chromatic: Story = {
324
+ render: (...props) => (
325
+ <div>
326
+ <div>
327
+ <h2>Size</h2>
328
+ {Size.render?.(...props)}
329
+ </div>
330
+ <div>
331
+ <h2>Variants</h2>
332
+ {Variants.render?.(...props)}
333
+ </div>
334
+ <div>
335
+ <h2>Position</h2>
336
+ {Position.render?.(...props)}
337
+ </div>
338
+ <div>
339
+ <h2>Toptext</h2>
340
+ {ToptextPosition.render?.(...props)}
341
+ </div>
342
+ <div>
343
+ <h2>Avatar</h2>
344
+ {Avatar.render?.(...props)}
345
+ </div>
346
+ </div>
347
+ ),
348
+ parameters: {
349
+ chromatic: { disable: false },
350
+ },
351
+ };
@@ -1,8 +1,8 @@
1
1
  import cl from "clsx";
2
- import React, { useContext, useRef } from "react";
2
+ import React, { useRef } from "react";
3
3
  import { Button } from "../../button";
4
4
  import { Modal } from "../../modal";
5
- import { ModalContext } from "../../modal/ModalContext";
5
+ import { useModalContext } from "../../modal/Modal.context";
6
6
  import { Popover } from "../../popover";
7
7
  import { useMedia } from "../../util/hooks";
8
8
  import { modalCloseButtonLabel, modalLabel } from "../utils/labels";
@@ -30,7 +30,7 @@ export const DateWrapper = ({
30
30
  popoverProps,
31
31
  }: DateWrapperProps) => {
32
32
  const modalRef = useRef<HTMLDialogElement>(null);
33
- const isInModal = useContext(ModalContext) !== null;
33
+ const isInModal = useModalContext(false) !== undefined;
34
34
  const hideModal =
35
35
  useMedia("screen and (min-width: 768px)", true) && !isInModal;
36
36
 
@@ -66,10 +66,10 @@ export interface SearchProps
66
66
  * Exposes the HTML size attribute
67
67
  */
68
68
  htmlSize?: number | string;
69
- /*
69
+ /*
70
70
  * Exposes role attribute
71
71
  */
72
- role?: string
72
+ role?: string;
73
73
  }
74
74
 
75
75
  interface SearchComponent
@@ -210,7 +210,7 @@ export const Search = forwardRef<HTMLInputElement, SearchProps>(
210
210
  value={value ?? internalValue}
211
211
  onChange={(e) => handleChange(e.target.value)}
212
212
  type="search"
213
- role={role ?? 'searchbox'}
213
+ role={role ?? "searchbox"}
214
214
  className={cl(
215
215
  className,
216
216
  "navds-search__input",
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import { createContext } from "../util/create-context";
3
+
4
+ interface ModalContextProps {
5
+ closeHandler?: React.MouseEventHandler<HTMLButtonElement>;
6
+ ref: React.RefObject<HTMLDialogElement>;
7
+ }
8
+
9
+ export const [ModalContextProvider, useModalContext] =
10
+ createContext<ModalContextProps>({
11
+ name: "ModalContext",
12
+ errorMessage: "<Modal.Header> must be used within a <Modal>",
13
+ });
@@ -8,8 +8,8 @@ import { Detail, Heading } from "../typography";
8
8
  import { composeEventHandlers } from "../util/composeEventHandlers";
9
9
  import { useId } from "../util/hooks";
10
10
  import { useMergeRefs } from "../util/hooks/useMergeRefs";
11
+ import { ModalContextProvider, useModalContext } from "./Modal.context";
11
12
  import ModalBody from "./ModalBody";
12
- import { ModalContext } from "./ModalContext";
13
13
  import ModalFooter from "./ModalFooter";
14
14
  import ModalHeader from "./ModalHeader";
15
15
  import { getCloseHandler, useBodyScrollLock } from "./ModalUtils";
@@ -98,7 +98,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
98
98
  const portalNode = useFloatingPortalNode({ root: rootElement });
99
99
 
100
100
  const dateContext = useContext(DateContext);
101
- const modalContext = useContext(ModalContext);
101
+ const modalContext = useModalContext(false);
102
102
  if (modalContext && !dateContext) {
103
103
  console.error("Modals should not be nested");
104
104
  }
@@ -185,11 +185,9 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
185
185
  onClick={composeEventHandlers(onClick, handleModalClick)}
186
186
  aria-labelledby={mergedAriaLabelledBy}
187
187
  >
188
- <ModalContext.Provider
189
- value={{
190
- closeHandler: getCloseHandler(modalRef, header, onBeforeClose),
191
- ref: modalRef,
192
- }}
188
+ <ModalContextProvider
189
+ closeHandler={getCloseHandler(modalRef, header, onBeforeClose)}
190
+ ref={modalRef}
193
191
  >
194
192
  {header && (
195
193
  <ModalHeader>
@@ -208,7 +206,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(
208
206
  )}
209
207
 
210
208
  {children}
211
- </ModalContext.Provider>
209
+ </ModalContextProvider>
212
210
  </dialog>
213
211
  );
214
212
 
@@ -1,8 +1,8 @@
1
1
  import cl from "clsx";
2
- import React, { forwardRef, useContext } from "react";
2
+ import React, { forwardRef } from "react";
3
3
  import { XMarkIcon } from "@navikt/aksel-icons";
4
4
  import { Button } from "../button";
5
- import { ModalContext } from "./ModalContext";
5
+ import { useModalContext } from "./Modal.context";
6
6
 
7
7
  export interface ModalHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
8
8
  children?: React.ReactNode;
@@ -15,11 +15,7 @@ export interface ModalHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
15
15
 
16
16
  const ModalHeader = forwardRef<HTMLDivElement, ModalHeaderProps>(
17
17
  ({ children, className, closeButton = true, ...rest }, ref) => {
18
- const context = useContext(ModalContext);
19
- if (context === null) {
20
- console.error("<Modal.Header> has to be used within a <Modal>");
21
- return null;
22
- }
18
+ const context = useModalContext();
23
19
 
24
20
  return (
25
21
  <div {...rest} ref={ref} className={cl("navds-modal__header", className)}>
@@ -18,7 +18,7 @@ import React, {
18
18
  useRef,
19
19
  } from "react";
20
20
  import { DateContext } from "../date/context";
21
- import { ModalContext } from "../modal/ModalContext";
21
+ import { useModalContext } from "../modal/Modal.context";
22
22
  import { useClientLayoutEffect, useEventListener } from "../util/hooks";
23
23
  import { useMergeRefs } from "../util/hooks/useMergeRefs";
24
24
  import PopoverContent, { PopoverContentType } from "./PopoverContent";
@@ -126,7 +126,7 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
126
126
  ref,
127
127
  ) => {
128
128
  const arrowRef = useRef<HTMLDivElement | null>(null);
129
- const isInModal = useContext(ModalContext) !== null;
129
+ const isInModal = useModalContext(false) !== undefined;
130
130
  const isInDatepicker = useContext(DateContext) !== null;
131
131
  const chosenStrategy = userStrategy ?? (isInModal ? "fixed" : "absolute");
132
132
  const chosenFlip = isInDatepicker ? false : _flip;