@navikt/ds-react 6.5.0 → 6.6.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.
Files changed (153) hide show
  1. package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +2 -4
  2. package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
  3. package/cjs/form/combobox/Input/Input.js +6 -1
  4. package/cjs/form/combobox/Input/Input.js.map +1 -1
  5. package/cjs/form/form-summary/FormSummary.d.ts +82 -0
  6. package/cjs/form/form-summary/FormSummary.js +81 -0
  7. package/cjs/form/form-summary/FormSummary.js.map +1 -0
  8. package/cjs/form/form-summary/FormSummaryAnswer.d.ts +11 -0
  9. package/cjs/form/form-summary/FormSummaryAnswer.js +25 -0
  10. package/cjs/form/form-summary/FormSummaryAnswer.js.map +1 -0
  11. package/cjs/form/form-summary/FormSummaryAnswers.d.ts +9 -0
  12. package/cjs/form/form-summary/FormSummaryAnswers.js +48 -0
  13. package/cjs/form/form-summary/FormSummaryAnswers.js.map +1 -0
  14. package/cjs/form/form-summary/FormSummaryEditLink.d.ts +17 -0
  15. package/cjs/form/form-summary/FormSummaryEditLink.js +49 -0
  16. package/cjs/form/form-summary/FormSummaryEditLink.js.map +1 -0
  17. package/cjs/form/form-summary/FormSummaryHeader.d.ts +9 -0
  18. package/cjs/form/form-summary/FormSummaryHeader.js +48 -0
  19. package/cjs/form/form-summary/FormSummaryHeader.js.map +1 -0
  20. package/cjs/form/form-summary/FormSummaryHeading.d.ts +14 -0
  21. package/cjs/form/form-summary/FormSummaryHeading.js +31 -0
  22. package/cjs/form/form-summary/FormSummaryHeading.js.map +1 -0
  23. package/cjs/form/form-summary/FormSummaryLabel.d.ts +6 -0
  24. package/cjs/form/form-summary/FormSummaryLabel.js +45 -0
  25. package/cjs/form/form-summary/FormSummaryLabel.js.map +1 -0
  26. package/cjs/form/form-summary/FormSummaryValue.d.ts +6 -0
  27. package/cjs/form/form-summary/FormSummaryValue.js +49 -0
  28. package/cjs/form/form-summary/FormSummaryValue.js.map +1 -0
  29. package/cjs/form/form-summary/index.d.ts +8 -0
  30. package/cjs/form/form-summary/index.js +24 -0
  31. package/cjs/form/form-summary/index.js.map +1 -0
  32. package/cjs/index.d.ts +3 -2
  33. package/cjs/index.js +5 -3
  34. package/cjs/index.js.map +1 -1
  35. package/cjs/util/hooks/descendants/descendant.js +10 -1
  36. package/cjs/util/hooks/descendants/descendant.js.map +1 -1
  37. package/cjs/util/hooks/descendants/useDescendant.js +0 -5
  38. package/cjs/util/hooks/descendants/useDescendant.js.map +1 -1
  39. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +2 -4
  40. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
  41. package/esm/form/combobox/Input/Input.js +6 -1
  42. package/esm/form/combobox/Input/Input.js.map +1 -1
  43. package/esm/form/form-summary/FormSummary.d.ts +82 -0
  44. package/esm/form/form-summary/FormSummary.js +52 -0
  45. package/esm/form/form-summary/FormSummary.js.map +1 -0
  46. package/esm/form/form-summary/FormSummaryAnswer.d.ts +11 -0
  47. package/esm/form/form-summary/FormSummaryAnswer.js +19 -0
  48. package/esm/form/form-summary/FormSummaryAnswer.js.map +1 -0
  49. package/esm/form/form-summary/FormSummaryAnswers.d.ts +9 -0
  50. package/esm/form/form-summary/FormSummaryAnswers.js +19 -0
  51. package/esm/form/form-summary/FormSummaryAnswers.js.map +1 -0
  52. package/esm/form/form-summary/FormSummaryEditLink.d.ts +17 -0
  53. package/esm/form/form-summary/FormSummaryEditLink.js +20 -0
  54. package/esm/form/form-summary/FormSummaryEditLink.js.map +1 -0
  55. package/esm/form/form-summary/FormSummaryHeader.d.ts +9 -0
  56. package/esm/form/form-summary/FormSummaryHeader.js +19 -0
  57. package/esm/form/form-summary/FormSummaryHeader.js.map +1 -0
  58. package/esm/form/form-summary/FormSummaryHeading.d.ts +14 -0
  59. package/esm/form/form-summary/FormSummaryHeading.js +5 -0
  60. package/esm/form/form-summary/FormSummaryHeading.js.map +1 -0
  61. package/esm/form/form-summary/FormSummaryLabel.d.ts +6 -0
  62. package/esm/form/form-summary/FormSummaryLabel.js +19 -0
  63. package/esm/form/form-summary/FormSummaryLabel.js.map +1 -0
  64. package/esm/form/form-summary/FormSummaryValue.d.ts +6 -0
  65. package/esm/form/form-summary/FormSummaryValue.js +20 -0
  66. package/esm/form/form-summary/FormSummaryValue.js.map +1 -0
  67. package/esm/form/form-summary/index.d.ts +8 -0
  68. package/esm/form/form-summary/index.js +10 -0
  69. package/esm/form/form-summary/index.js.map +1 -0
  70. package/esm/index.d.ts +3 -2
  71. package/esm/index.js +2 -1
  72. package/esm/index.js.map +1 -1
  73. package/esm/util/hooks/descendants/descendant.js +10 -1
  74. package/esm/util/hooks/descendants/descendant.js.map +1 -1
  75. package/esm/util/hooks/descendants/useDescendant.js +0 -5
  76. package/esm/util/hooks/descendants/useDescendant.js.map +1 -1
  77. package/package.json +15 -4
  78. package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +9 -1
  79. package/src/form/combobox/Input/Input.tsx +5 -0
  80. package/src/form/form-summary/FormSummary.tsx +106 -0
  81. package/src/form/form-summary/FormSummaryAnswer.tsx +27 -0
  82. package/src/form/form-summary/FormSummaryAnswers.tsx +25 -0
  83. package/src/form/form-summary/FormSummaryEditLink.tsx +35 -0
  84. package/src/form/form-summary/FormSummaryHeader.tsx +25 -0
  85. package/src/form/form-summary/FormSummaryHeading.tsx +23 -0
  86. package/src/form/form-summary/FormSummaryLabel.tsx +17 -0
  87. package/src/form/form-summary/FormSummaryValue.tsx +24 -0
  88. package/src/form/form-summary/index.ts +30 -0
  89. package/src/index.ts +16 -15
  90. package/src/util/hooks/descendants/descendant.ts +15 -1
  91. package/src/util/hooks/descendants/useDescendant.tsx +0 -5
  92. package/src/accordion/accordion.stories.tsx +0 -286
  93. package/src/alert/alert.stories.tsx +0 -306
  94. package/src/button/button.stories.tsx +0 -185
  95. package/src/chat/chat.stories.tsx +0 -341
  96. package/src/chips/chips.stories.tsx +0 -260
  97. package/src/copybutton/copy-button.stories.tsx +0 -261
  98. package/src/date/datepicker/datepicker.stories.tsx +0 -614
  99. package/src/date/monthpicker/monthpicker.stories.tsx +0 -221
  100. package/src/dropdown/dropdown.stories.tsx +0 -124
  101. package/src/expansion-card/expansion-card.stories.tsx +0 -282
  102. package/src/form/checkbox/checkbox.stories.tsx +0 -281
  103. package/src/form/combobox/combobox.stories.tsx +0 -626
  104. package/src/form/confirmation-panel/confirmation-panel.stories.tsx +0 -128
  105. package/src/form/error-summary/error-summary.stories.tsx +0 -81
  106. package/src/form/fieldset/fieldset.stories.tsx +0 -157
  107. package/src/form/file-upload/file-upload-dropzone.stories.tsx +0 -123
  108. package/src/form/file-upload/file-upload-item.stories.tsx +0 -148
  109. package/src/form/file-upload/file-upload.stories.tsx +0 -248
  110. package/src/form/radio/radio.stories.tsx +0 -230
  111. package/src/form/search/search.stories.tsx +0 -238
  112. package/src/form/select/select.stories.tsx +0 -172
  113. package/src/form/switch/switch.stories.tsx +0 -171
  114. package/src/form/textarea/textarea.stories.tsx +0 -254
  115. package/src/form/textfield/text-field.stories.tsx +0 -143
  116. package/src/guide-panel/guidepanel.stories.tsx +0 -90
  117. package/src/help-text/help-text.stories.tsx +0 -91
  118. package/src/internal-header/header.stories.tsx +0 -229
  119. package/src/layout/bleed/Bleed.stories.tsx +0 -395
  120. package/src/layout/box/Box.stories.tsx +0 -380
  121. package/src/layout/grid/h-grid.stories.tsx +0 -122
  122. package/src/layout/page/Page.stories.tsx +0 -271
  123. package/src/layout/responsive/hide.stories.tsx +0 -80
  124. package/src/layout/responsive/show.stories.tsx +0 -80
  125. package/src/layout/sidemal-test/navno-sidemal.stories.tsx +0 -69
  126. package/src/layout/stack/stack.stories.tsx +0 -183
  127. package/src/link/stories/link.stories.tsx +0 -304
  128. package/src/link-panel/link-panel.stories.tsx +0 -59
  129. package/src/list/list.stories.tsx +0 -280
  130. package/src/loader/loader.stories.tsx +0 -82
  131. package/src/modal/modal.stories.tsx +0 -391
  132. package/src/pagination/pagination.stories.tsx +0 -110
  133. package/src/popover/popover.stories.tsx +0 -113
  134. package/src/portal/Portal.stories.tsx +0 -102
  135. package/src/read-more/readmore.stories.tsx +0 -91
  136. package/src/skeleton/skeleton.stories.tsx +0 -130
  137. package/src/stepper/stepper.stories.tsx +0 -200
  138. package/src/table/stories/table-1.stories.tsx +0 -292
  139. package/src/table/stories/table-2-expandable.stories.tsx +0 -298
  140. package/src/table/stories/table-3-async.stories.tsx +0 -179
  141. package/src/table/stories/tests/table.stories.tsx +0 -102
  142. package/src/tabs/Tabs.stories.tsx +0 -311
  143. package/src/tag/tag.stories.tsx +0 -126
  144. package/src/timeline/timeline.stories.tsx +0 -445
  145. package/src/toggle-group/ToggleGroup.stories.tsx +0 -198
  146. package/src/tooltip/tooltip.stories.tsx +0 -101
  147. package/src/typography/stories/bodylong.stories.tsx +0 -209
  148. package/src/typography/stories/bodyshort.stories.tsx +0 -208
  149. package/src/typography/stories/detail.stories.tsx +0 -115
  150. package/src/typography/stories/error-message.stories.tsx +0 -122
  151. package/src/typography/stories/heading.stories.tsx +0 -169
  152. package/src/typography/stories/label.stories.tsx +0 -131
  153. package/src/util/hooks/descendants/descendant.stories.tsx +0 -147
@@ -1,128 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
- import React, { useState } from "react";
3
- import { Link } from "../../link";
4
- import { ConfirmationPanel } from "./index";
5
-
6
- export default {
7
- title: "ds-react/ConfirmationPanel",
8
- component: ConfirmationPanel,
9
- argTypes: {
10
- size: {
11
- control: {
12
- type: "radio",
13
- options: ["medium", "small"],
14
- },
15
- },
16
- error: {
17
- type: "string",
18
- },
19
- },
20
- parameters: {
21
- chromatic: { disable: true },
22
- },
23
- } as Meta;
24
-
25
- type Story = StoryObj<typeof ConfirmationPanel>;
26
-
27
- const content = (
28
- <>
29
- Ipsum voluptate pariatur <Link href="#123">testlink</Link> anim officia
30
- minim ut mollit voluptate exercitation nulla mollit.
31
- </>
32
- );
33
-
34
- export const Default = {
35
- render: (props) => {
36
- return (
37
- <ConfirmationPanel
38
- error={props?.error}
39
- size={props?.size}
40
- checked={props?.checked ?? undefined}
41
- label={props?.label ?? "Checkbox label text"}
42
- >
43
- {content}
44
- </ConfirmationPanel>
45
- );
46
- },
47
-
48
- args: {
49
- label: "Checkbox label text",
50
- checked: false,
51
- },
52
- };
53
-
54
- export const Small = () => {
55
- const [checked, setChecked] = useState(false);
56
- return (
57
- <ConfirmationPanel
58
- checked={checked}
59
- onChange={() => setChecked(!checked)}
60
- label="Checkbox label text"
61
- size="small"
62
- >
63
- {content}
64
- </ConfirmationPanel>
65
- );
66
- };
67
-
68
- export const NoContent = () => {
69
- const [checked, setChecked] = useState(false);
70
- return (
71
- <ConfirmationPanel
72
- checked={checked}
73
- onChange={() => setChecked(!checked)}
74
- label="Checkbox label text"
75
- />
76
- );
77
- };
78
-
79
- export const Error = () => {
80
- const [checked, setChecked] = useState(false);
81
- return (
82
- <div className="colgap">
83
- <ConfirmationPanel
84
- checked={checked}
85
- onChange={() => setChecked(!checked)}
86
- label="Checkbox label text"
87
- error="Adipisicing sint aute quis veniam incididunt duis est sint aute cillum."
88
- >
89
- {content}
90
- </ConfirmationPanel>
91
- <ConfirmationPanel
92
- checked={checked}
93
- onChange={() => setChecked(!checked)}
94
- label="Checkbox label text"
95
- error="Adipisicing sint aute quis veniam incididunt duis est sint aute cillum."
96
- size="small"
97
- >
98
- {content}
99
- </ConfirmationPanel>
100
- </div>
101
- );
102
- };
103
-
104
- export const Chromatic: Story = {
105
- render: (...props) => (
106
- <div>
107
- <div>
108
- <h2>Default</h2>
109
- {Default.render?.(props)}
110
- </div>
111
- <div>
112
- <h2>Small</h2>
113
- <Small />
114
- </div>
115
- <div>
116
- <h2>No content</h2>
117
- <NoContent />
118
- </div>
119
- <div>
120
- <h2>Error</h2>
121
- <Error />
122
- </div>
123
- </div>
124
- ),
125
- parameters: {
126
- chromatic: { disable: false },
127
- },
128
- };
@@ -1,81 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
- import React from "react";
3
- import { VStack } from "../../layout/stack";
4
- import { ErrorSummary } from "./ErrorSummary";
5
-
6
- export default {
7
- title: "ds-react/Errorsummary",
8
- component: ErrorSummary,
9
- argTypes: {
10
- headingTag: {
11
- control: {
12
- type: "text",
13
- },
14
- },
15
- size: {
16
- control: {
17
- type: "radio",
18
- options: ["medium", "small"],
19
- },
20
- },
21
- },
22
- parameters: {
23
- chromatic: { disable: true },
24
- },
25
- } satisfies Meta<typeof ErrorSummary>;
26
-
27
- type Story = StoryObj<typeof ErrorSummary>;
28
-
29
- export const Default: Story = {
30
- render: (props) => (
31
- <ErrorSummary
32
- heading="Feiloppsummering komponent"
33
- headingTag={props.headingTag || "h2"}
34
- size={props.size ?? undefined}
35
- >
36
- <ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
37
- <ErrorSummary.Item href="#2">
38
- Tekstfeltet må ha en godkjent e-mail
39
- </ErrorSummary.Item>
40
- </ErrorSummary>
41
- ),
42
- };
43
-
44
- export const Small: Story = {
45
- render: () => (
46
- <ErrorSummary heading="Feiloppsummering komponent" size="small">
47
- <ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
48
- <ErrorSummary.Item href="#2">
49
- Tekstfeltet må ha en godkjent e-mail
50
- </ErrorSummary.Item>
51
- </ErrorSummary>
52
- ),
53
- };
54
-
55
- export const Chromatic: Story = {
56
- render: () => (
57
- <VStack gap="4">
58
- <div>
59
- <h2>Default</h2>
60
- <ErrorSummary heading="Feiloppsummering komponent">
61
- <ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
62
- <ErrorSummary.Item href="#2">
63
- Tekstfeltet må ha en godkjent e-mail
64
- </ErrorSummary.Item>
65
- </ErrorSummary>
66
- </div>
67
- <div>
68
- <h2>Small</h2>
69
- <ErrorSummary heading="Feiloppsummering komponent" size="small">
70
- <ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
71
- <ErrorSummary.Item href="#2">
72
- Tekstfeltet må ha en godkjent e-mail
73
- </ErrorSummary.Item>
74
- </ErrorSummary>
75
- </div>
76
- </VStack>
77
- ),
78
- parameters: {
79
- chromatic: { disable: false },
80
- },
81
- };
@@ -1,157 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
- import React from "react";
3
- import { VStack } from "../../layout/stack";
4
- import TextField from "../textfield/TextField";
5
- import { Fieldset } from "./index";
6
-
7
- export default {
8
- title: "ds-react/Fieldset",
9
- component: Fieldset,
10
- argTypes: {
11
- size: {
12
- control: {
13
- type: "radio",
14
- options: ["medium", "small"],
15
- },
16
- },
17
- description: {
18
- type: "string",
19
- },
20
- error: {
21
- type: "string",
22
- },
23
- hideLegend: {
24
- type: "boolean",
25
- },
26
- disabled: {
27
- type: "boolean",
28
- },
29
- },
30
- parameters: {
31
- chromatic: { disable: true },
32
- },
33
- } satisfies Meta<typeof Fieldset>;
34
-
35
- type Story = StoryObj<typeof Fieldset>;
36
-
37
- const content = (
38
- <>
39
- <TextField label="Textfield label" hideLabel />
40
- <TextField label="Textfield label" hideLabel />
41
- </>
42
- );
43
-
44
- const contentWithError = (
45
- <>
46
- <TextField label="Textfield label" hideLabel error="Må være fylt ut" />
47
- <TextField label="Textfield label" hideLabel />
48
- </>
49
- );
50
-
51
- export const Default: Story = {
52
- args: {
53
- legend: "Mollit eiusmod",
54
- description:
55
- "Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
56
- errorPropagation: true,
57
- children: content,
58
- },
59
- };
60
-
61
- export const Small: Story = {
62
- args: {
63
- legend: "Mollit eiusmod",
64
- description:
65
- "Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
66
- errorPropagation: true,
67
- children: content,
68
- size: "small",
69
- },
70
- };
71
-
72
- export const ErrorPropagation: Story = {
73
- args: {
74
- legend: "Mollit eiusmod",
75
- description:
76
- "Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
77
- errorPropagation: false,
78
- children: contentWithError,
79
- },
80
- };
81
-
82
- export const Error: Story = {
83
- args: {
84
- legend: "Mollit eiusmod",
85
- description:
86
- "Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
87
- children: content,
88
- error: "Laborum officia nisi aliqua esse minim in amet.",
89
- },
90
- };
91
-
92
- export const Disabled: Story = {
93
- args: {
94
- legend: "Mollit eiusmod",
95
- description:
96
- "Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
97
- children: content,
98
- disabled: true,
99
- },
100
- };
101
-
102
- export const HideLegend: Story = {
103
- args: {
104
- legend: "Mollit eiusmod",
105
- description:
106
- "Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
107
- children: content,
108
- hideLegend: true,
109
- },
110
- };
111
-
112
- export const Chromatic: Story = {
113
- render: () => {
114
- return (
115
- <VStack gap="4">
116
- <div>
117
- <h2>Default</h2>
118
- {/* @ts-expect-error Args are Partial here */}
119
- <Fieldset {...Default.args} />
120
- </div>
121
- <div>
122
- <h2>Small</h2>
123
- {/* @ts-expect-error Args are Partial here */}
124
- <Fieldset {...Small.args} />
125
- </div>
126
- <div>
127
- <h2>ErrorPropagation</h2>
128
- {/* @ts-expect-error Args are Partial here */}
129
- <Fieldset {...ErrorPropagation.args} />
130
- </div>
131
- <div>
132
- <h2>Error</h2>
133
- {/* @ts-expect-error Args are Partial here */}
134
- <Fieldset {...Error.args} />
135
- </div>
136
- <div>
137
- <h2>Error small</h2>
138
- {/* @ts-expect-error Args are Partial here */}
139
- <Fieldset {...Error.args} size="small" />
140
- </div>
141
- <div>
142
- <h2>Disabled</h2>
143
- {/* @ts-expect-error Args are Partial here */}
144
- <Fieldset {...Disabled.args} />
145
- </div>
146
- <div>
147
- <h2>HideLegend</h2>
148
- {/* @ts-expect-error Args are Partial here */}
149
- <Fieldset {...HideLegend.args} />
150
- </div>
151
- </VStack>
152
- );
153
- },
154
- parameters: {
155
- chromatic: { disable: false },
156
- },
157
- };
@@ -1,123 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
- import { fireEvent, within } from "@storybook/test";
3
- import React from "react";
4
- import { ImageIcon } from "@navikt/aksel-icons";
5
- import {
6
- type FileObject,
7
- UNSAFE_FileUpload as FileUpload,
8
- type FilesPartitioned,
9
- } from ".";
10
-
11
- const meta: Meta<typeof FileUpload.Dropzone> = {
12
- title: "ds-react/FileUpload/Dropzone",
13
- component: FileUpload.Dropzone,
14
- decorators: [
15
- (Story) => (
16
- <div style={{ width: 500, maxWidth: "100%" }}>
17
- <Story />
18
- </div>
19
- ),
20
- ],
21
- };
22
-
23
- export default meta;
24
-
25
- const onSelect = (
26
- allFiles: FileObject[],
27
- { accepted, rejected }: FilesPartitioned,
28
- ) => {
29
- alert(
30
- `Lastet opp ${allFiles.length} filer. Accepted: ${accepted.length}. Rejected: ${rejected.length}`,
31
- );
32
- };
33
-
34
- export const Default: StoryObj<typeof FileUpload.Dropzone> = {
35
- render: (props) => <FileUpload.Dropzone {...props} onSelect={console.log} />,
36
- args: {
37
- label: "Last opp filer",
38
- description: "",
39
- error: "",
40
- multiple: true,
41
- accept: "",
42
- maxSizeInBytes: 0,
43
- fileLimit: { max: 2, current: 1 },
44
- },
45
- argTypes: {
46
- disabled: { control: { type: "boolean" } },
47
- },
48
- parameters: { chromatic: { disable: true } },
49
- };
50
-
51
- export const States: StoryObj = {
52
- render: () => (
53
- <div>
54
- <h2>Disabled</h2>
55
- <FileUpload.Dropzone
56
- label="Disabled prop"
57
- onSelect={console.log}
58
- disabled
59
- />
60
- <FileUpload.Dropzone
61
- label="FileLimit disabled"
62
- onSelect={console.log}
63
- fileLimit={{ max: 1, current: 2 }}
64
- />
65
-
66
- <h2>Error</h2>
67
- <FileUpload.Dropzone
68
- label="Last opp filer"
69
- onSelect={onSelect}
70
- error="Du må laste opp en fil"
71
- description="Bruk filtype DOC, PPT eller PDF. Maks filstørrelse 10 MB."
72
- />
73
-
74
- <h2>Dragging</h2>
75
- <FileUpload.Dropzone
76
- label="Drag over test"
77
- multiple={false}
78
- onSelect={onSelect}
79
- />
80
- </div>
81
- ),
82
- };
83
- States.play = async ({ canvasElement }) => {
84
- const canvas = within(canvasElement);
85
- const button = canvas.getByText("Velg fil");
86
- fireEvent.dragEnter(button);
87
- };
88
-
89
- export const Translation: StoryObj = {
90
- render: () => (
91
- <div>
92
- <h2>Single file</h2>
93
- <FileUpload.Dropzone
94
- label="Last opp fil"
95
- multiple={false}
96
- onSelect={onSelect}
97
- />
98
-
99
- <h2>Custom texts</h2>
100
- <FileUpload.Dropzone
101
- translations={{
102
- dragAndDropMultiple: "Dra og slipp bilder i format .png",
103
- buttonMultiple: "Velg bilder",
104
- disabled: "Du kan ikke laste opp flere bilder",
105
- }}
106
- label="Last opp bilder"
107
- onSelect={console.log}
108
- icon={ImageIcon}
109
- />
110
-
111
- <h3>Disabled</h3>
112
- <FileUpload.Dropzone
113
- translations={{
114
- disabled: "Du kan ikke laste opp flere bilder",
115
- }}
116
- label="Last opp bilder"
117
- onSelect={console.log}
118
- icon={ImageIcon}
119
- disabled
120
- />
121
- </div>
122
- ),
123
- };
@@ -1,148 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
- import React from "react";
3
- import { FileItem, UNSAFE_FileUpload as FileUpload } from ".";
4
- import { VStack } from "../../layout/stack";
5
-
6
- const meta: Meta<typeof FileUpload.Item> = {
7
- title: "ds-react/FileUpload/Item",
8
- component: FileUpload.Item,
9
- decorators: [
10
- (Story) => (
11
- <div style={{ width: 400, maxWidth: "100%" }}>
12
- <Story />
13
- </div>
14
- ),
15
- ],
16
- };
17
-
18
- export default meta;
19
-
20
- const onDelete = (file: FileItem) => alert(`Delete ${file.name}`);
21
- const onRetry = (file: FileItem) => alert(`Retry ${file.name}`);
22
- const fileTxt = new File(["abc".repeat(10000)], "file.txt");
23
- const filePng = new File(["abc".repeat(10000)], "file.png");
24
- const filePdf = new File(["abc".repeat(100000)], "file.pdf");
25
- const fileXlsx = new File(["abc"], "file.xlsx");
26
- const fileCsv = new File(["abc"], "file.csv");
27
- const filePptx = new File(["abc"], "file.pptx");
28
- const fileWebp = new File(["abc"], "file.webp");
29
- const fileDocx = new File(["abc"], "file.docx");
30
-
31
- export const Icons: StoryObj<typeof FileUpload.Item> = {
32
- render: () => (
33
- <FileUpload>
34
- <VStack gap="5" as="ul">
35
- <FileUpload.Item file={fileTxt} as="li" />
36
- <FileUpload.Item file={filePng} as="li" />
37
- <FileUpload.Item file={fileWebp} as="li" />
38
- <FileUpload.Item file={filePdf} as="li" />
39
- <FileUpload.Item file={fileDocx} as="li" />
40
- <FileUpload.Item file={fileDocx} as="li" status="uploading" />
41
- <FileUpload.Item file={fileDocx} as="li" status="downloading" />
42
- <FileUpload.Item file={fileXlsx} as="li" />
43
- <FileUpload.Item file={fileCsv} as="li" />
44
- <FileUpload.Item file={filePptx} as="li" />
45
- </VStack>
46
- </FileUpload>
47
- ),
48
- };
49
-
50
- export const States: StoryObj<typeof FileUpload.Item> = {
51
- render: () => (
52
- <div>
53
- <h2>Error</h2>
54
- <FileUpload.Item file={fileTxt} error="Plain error" />
55
- <h3>error + status</h3>
56
- <FileUpload.Item
57
- file={fileTxt}
58
- error="Error og uploading"
59
- status="uploading"
60
- button={{
61
- onClick: () => onDelete(fileTxt),
62
- action: "delete",
63
- }}
64
- />
65
- <h2>Item Actions</h2>
66
- <h3>status + delete</h3>
67
- <FileUpload.Item
68
- file={fileDocx}
69
- status="uploading"
70
- button={{
71
- onClick: () => onDelete(fileDocx),
72
- action: "delete",
73
- }}
74
- />
75
- <h3>status + retry</h3>
76
- <FileUpload.Item
77
- file={fileDocx}
78
- status="downloading"
79
- button={{
80
- onClick: () => onRetry(fileDocx),
81
- action: "retry",
82
- }}
83
- />
84
- <h3>retry</h3>
85
- <FileUpload.Item
86
- file={fileCsv}
87
- button={{
88
- onClick: () => onRetry(fileCsv),
89
- action: "retry",
90
- }}
91
- />
92
- <h3>delete</h3>
93
- <FileUpload.Item
94
- file={filePptx}
95
- button={{
96
- onClick: () => onDelete(filePptx),
97
- action: "delete",
98
- }}
99
- />
100
- <h3>retry + error</h3>
101
- <FileUpload.Item
102
- file={fileCsv}
103
- error="Error og onRetry"
104
- button={{
105
- onClick: () => onRetry(fileCsv),
106
- action: "retry",
107
- }}
108
- />
109
- <h3>delete + error</h3>
110
- <FileUpload.Item
111
- file={filePptx}
112
- error="Error og onDelete"
113
- button={{
114
- onClick: () => onDelete(filePptx),
115
- action: "delete",
116
- }}
117
- />
118
- </div>
119
- ),
120
- };
121
-
122
- export const Download: StoryObj = {
123
- render: () => (
124
- <VStack gap="5">
125
- <FileUpload.Item
126
- file={{
127
- name: "with onClick.txt",
128
- size: 1_048_576,
129
- }}
130
- onFileClick={() => alert("onFileClick")}
131
- />
132
- <FileUpload.Item
133
- file={{
134
- name: "with href.txt",
135
- size: 1,
136
- }}
137
- href="https://www.nav.no"
138
- />
139
- <FileUpload.Item
140
- file={{
141
- name: "without href/onFileClick.txt",
142
- size: 2_000_000,
143
- }}
144
- />
145
- <FileUpload.Item file={fileTxt} />
146
- </VStack>
147
- ),
148
- };