@navikt/ds-react 6.3.2 → 6.3.4

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.
@@ -1,5 +1,6 @@
1
- import { Meta } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react";
2
2
  import React from "react";
3
+ import { VStack } from "../../layout/stack";
3
4
  import { ErrorSummary } from "./ErrorSummary";
4
5
 
5
6
  export default {
@@ -18,9 +19,14 @@ export default {
18
19
  },
19
20
  },
20
21
  },
21
- } as Meta;
22
+ parameters: {
23
+ chromatic: { disable: true },
24
+ },
25
+ } satisfies Meta<typeof ErrorSummary>;
26
+
27
+ type Story = StoryObj<typeof ErrorSummary>;
22
28
 
23
- export const Default = {
29
+ export const Default: Story = {
24
30
  render: (props) => (
25
31
  <ErrorSummary
26
32
  heading="Feiloppsummering komponent"
@@ -35,11 +41,41 @@ export const Default = {
35
41
  ),
36
42
  };
37
43
 
38
- export const Small = () => (
39
- <ErrorSummary heading="Feiloppsummering komponent" size="small">
40
- <ErrorSummary.Item href="#1">Checkbox må fylles ut</ErrorSummary.Item>
41
- <ErrorSummary.Item href="#2">
42
- Tekstfeltet må ha en godkjent e-mail
43
- </ErrorSummary.Item>
44
- </ErrorSummary>
45
- );
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,5 +1,6 @@
1
- import { Meta } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react";
2
2
  import React from "react";
3
+ import { VStack } from "../../layout/stack";
3
4
  import TextField from "../textfield/TextField";
4
5
  import { Fieldset } from "./index";
5
6
 
@@ -26,7 +27,12 @@ export default {
26
27
  type: "boolean",
27
28
  },
28
29
  },
29
- } as Meta;
30
+ parameters: {
31
+ chromatic: { disable: true },
32
+ },
33
+ } satisfies Meta<typeof Fieldset>;
34
+
35
+ type Story = StoryObj<typeof Fieldset>;
30
36
 
31
37
  const content = (
32
38
  <>
@@ -35,88 +41,117 @@ const content = (
35
41
  </>
36
42
  );
37
43
 
38
- export const Default = {
39
- render: (props) => {
40
- return (
41
- <Fieldset legend="Mollit eiusmod" {...props}>
42
- {content}
43
- </Fieldset>
44
- );
45
- },
44
+ const contentWithError = (
45
+ <>
46
+ <TextField label="Textfield label" hideLabel error="Må være fylt ut" />
47
+ <TextField label="Textfield label" hideLabel />
48
+ </>
49
+ );
46
50
 
51
+ export const Default: Story = {
47
52
  args: {
53
+ legend: "Mollit eiusmod",
54
+ description:
55
+ "Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure.",
48
56
  errorPropagation: true,
57
+ children: content,
49
58
  },
50
59
  };
51
60
 
52
- export const Small = () => (
53
- <Fieldset
54
- size="small"
55
- legend="Mollit eiusmod"
56
- description="Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure."
57
- >
58
- {content}
59
- </Fieldset>
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
+ };
61
71
 
62
- export const Description = () => (
63
- <Fieldset
64
- legend="Mollit eiusmod"
65
- description="Esse cupidatat reprehenderit est culpa consectetur sit dolor esse."
66
- >
67
- <TextField
68
- label="Textfield label"
69
- description="Amet quis cillum incididunt "
70
- />
71
- <TextField
72
- label="Textfield label"
73
- description="Enim et occaecat voluptate labore sit do exercitation laborum non "
74
- />
75
- </Fieldset>
76
- );
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
+ };
77
81
 
78
- export const ErrorPropagation = () => (
79
- <Fieldset
80
- legend="Mollit eiusmod"
81
- error="Fieldsett error"
82
- errorPropagation={false}
83
- >
84
- <TextField label="Textfield label" hideLabel error="Må være fylt ut" />
85
- <TextField label="Textfield label" hideLabel />
86
- </Fieldset>
87
- );
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
+ };
88
91
 
89
- export const Error = () => (
90
- <div className="colgap">
91
- <Fieldset
92
- legend="Mollit eiusmod"
93
- error="Laborum officia nisi aliqua esse minim in amet."
94
- >
95
- {content}
96
- </Fieldset>
97
- <Fieldset
98
- size="small"
99
- legend="Mollit eiusmod"
100
- error="Laborum officia nisi aliqua esse minim in amet."
101
- >
102
- {content}
103
- </Fieldset>
104
- </div>
105
- );
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
+ };
106
101
 
107
- export const Disabled = () => (
108
- <div className="colgap">
109
- <Fieldset legend="Mollit eiusmod" disabled>
110
- {content}
111
- </Fieldset>
112
- <Fieldset size="small" legend="Mollit eiusmod" disabled>
113
- {content}
114
- </Fieldset>
115
- </div>
116
- );
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
+ };
117
111
 
118
- export const HideLegend = () => (
119
- <Fieldset legend="Mollit eiusmod" hideLegend>
120
- {content}
121
- </Fieldset>
122
- );
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
+ };
@@ -30,6 +30,7 @@ const Dropzone = forwardRef<HTMLInputElement, FileUploadDropzoneProps>(
30
30
  disabled,
31
31
  translations,
32
32
  onClick,
33
+ id: buttonId,
33
34
  ...rest
34
35
  } = props;
35
36
 
@@ -46,7 +47,10 @@ const Dropzone = forwardRef<HTMLInputElement, FileUploadDropzoneProps>(
46
47
  const _disabled = disabled ?? fileLimitReached;
47
48
 
48
49
  const { inputProps, errorId, showErrorMsg, hasError, inputDescriptionId } =
49
- useFormField({ ...props, disabled: _disabled }, "fileUpload");
50
+ useFormField(
51
+ { ...omit(props, ["id"]), disabled: _disabled },
52
+ "fileUpload",
53
+ );
50
54
  const {
51
55
  id: inputId,
52
56
  "aria-describedby": ariaDescribedby,
@@ -131,6 +135,7 @@ const Dropzone = forwardRef<HTMLInputElement, FileUploadDropzoneProps>(
131
135
  <Button
132
136
  {...omit(rest, ["errorId"])}
133
137
  {...inputPropsRest}
138
+ id={buttonId}
134
139
  aria-describedby={cl(labelId, ariaDescribedby)}
135
140
  className="navds-dropzone__area-button"
136
141
  type="button"
@@ -49,6 +49,7 @@ export const Default = (props) => {
49
49
  </RadioGroup>
50
50
  );
51
51
  };
52
+
52
53
  Default.args = {
53
54
  controlled: false,
54
55
  error: false,
@@ -85,7 +85,7 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
85
85
  ...rest
86
86
  } = props;
87
87
 
88
- const [checked, setChecked] = useState(
88
+ const [_checked, setChecked] = useState(
89
89
  defaultChecked ?? checkedProp ?? false,
90
90
  );
91
91
 
@@ -93,6 +93,8 @@ export const Switch = forwardRef<HTMLInputElement, SwitchProps>(
93
93
  checkedProp !== undefined && setChecked(checkedProp);
94
94
  }, [checkedProp]);
95
95
 
96
+ const checked = checkedProp ?? _checked;
97
+
96
98
  return (
97
99
  <div
98
100
  className={cl(
@@ -1,5 +1,6 @@
1
- import { Meta } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react";
2
2
  import React from "react";
3
+ import { VStack } from "../../layout/stack";
3
4
  import Switch from "./Switch";
4
5
 
5
6
  export default {
@@ -31,70 +32,59 @@ export default {
31
32
  type: "boolean",
32
33
  },
33
34
  },
34
- } as Meta;
35
-
36
- export const Default = {
37
- render: (props) => {
38
- return <Switch {...props}>Label text</Switch>;
35
+ parameters: {
36
+ chromatic: { disable: true },
39
37
  },
38
+ } satisfies Meta<typeof Switch>;
39
+
40
+ type Story = StoryObj<typeof Switch>;
40
41
 
42
+ export const Default: Story = {
41
43
  args: {
42
- position: "right",
44
+ children: "Label text",
43
45
  },
44
46
  };
45
47
 
46
- export const Small = () => {
47
- return (
48
- <div className="colgap">
49
- <Switch size="small">Label text</Switch>
50
- <Switch size="small" position="right">
51
- Label text
52
- </Switch>
53
- </div>
54
- );
48
+ export const Small: Story = {
49
+ args: {
50
+ children: "Label text",
51
+ size: "small",
52
+ },
55
53
  };
56
54
 
57
- export const Description = () => {
58
- return (
59
- <div className="colgap">
60
- <Switch size="small" description="Cillum sint exercitation ut cillum.">
61
- Label text
62
- </Switch>
63
- <Switch
64
- size="small"
65
- position="right"
66
- description="Cillum sint exercitation ut cillum."
67
- >
68
- Label text
69
- </Switch>
70
- </div>
71
- );
55
+ export const Description: Story = {
56
+ args: {
57
+ children: "Label text",
58
+ description: "Cillum sint exercitation ut cillum.",
59
+ },
72
60
  };
73
61
 
74
- export const Loading = () => {
75
- return (
76
- <div className="colgap">
62
+ export const Loading: Story = {
63
+ render: () => {
64
+ return (
77
65
  <div className="colgap">
78
- <Switch loading>Label text</Switch>
66
+ <div className="colgap">
67
+ <Switch loading>Label text</Switch>
79
68
 
80
- <Switch checked loading>
81
- Label text
82
- </Switch>
83
- </div>
84
- <div className="colgap">
85
- <Switch loading size="small">
86
- Label text
87
- </Switch>
88
- <Switch checked loading size="small">
89
- Label text
90
- </Switch>
69
+ <Switch checked loading>
70
+ Label text
71
+ </Switch>
72
+ </div>
73
+ <div className="colgap">
74
+ <Switch loading size="small">
75
+ Label text
76
+ </Switch>
77
+ <Switch checked loading size="small">
78
+ Label text
79
+ </Switch>
80
+ </div>
91
81
  </div>
92
- </div>
93
- );
82
+ );
83
+ },
94
84
  };
95
85
 
96
- export const Disabled = () => {
97
- return (
86
+ export const Disabled: Story = {
87
+ render: () => (
98
88
  <div className="colgap">
99
89
  <Switch disabled>Label text</Switch>
100
90
 
@@ -102,11 +92,11 @@ export const Disabled = () => {
102
92
  Label text
103
93
  </Switch>
104
94
  </div>
105
- );
95
+ ),
106
96
  };
107
97
 
108
- export const HideLabel = () => {
109
- return (
98
+ export const HideLabel: Story = {
99
+ render: () => (
110
100
  <div className="colgap">
111
101
  <Switch hideLabel>Label text</Switch>
112
102
 
@@ -114,11 +104,11 @@ export const HideLabel = () => {
114
104
  Label text
115
105
  </Switch>
116
106
  </div>
117
- );
107
+ ),
118
108
  };
119
109
 
120
- export const Readonly = () => {
121
- return (
110
+ export const Readonly: Story = {
111
+ render: () => (
122
112
  <div className="colgap">
123
113
  <Switch description="Slår av alle notifikasjoner" readOnly>
124
114
  Notifikasjoner
@@ -128,5 +118,54 @@ export const Readonly = () => {
128
118
  Notifikasjoner
129
119
  </Switch>
130
120
  </div>
131
- );
121
+ ),
122
+ };
123
+
124
+ export const Chromatic: Story = {
125
+ render: () => (
126
+ <VStack gap="4" align="start">
127
+ <div>
128
+ <h2>Default</h2>
129
+ {/* @ts-expect-error Args are Partial here */}
130
+ <Switch {...Default.args} />
131
+ </div>
132
+ <div>
133
+ <h2>Small</h2>
134
+ {/* @ts-expect-error Args are Partial here */}
135
+ <Switch {...Small.args} position="left" />
136
+ {/* @ts-expect-error Args are Partial here */}
137
+ <Switch {...Small.args} position="right" />
138
+ </div>
139
+ <div>
140
+ <h2>Description</h2>
141
+ {/* @ts-expect-error Args are Partial here */}
142
+ <Switch {...Description.args} position="left" />
143
+ {/* @ts-expect-error Args are Partial here */}
144
+ <Switch {...Description.args} position="right" />
145
+ </div>
146
+ <div>
147
+ <h2>Loading</h2>
148
+ {/* @ts-expect-error Args are Partial here */}
149
+ <Loading.render />
150
+ </div>
151
+ <div>
152
+ <h2>Disabled</h2>
153
+ {/* @ts-expect-error Args are Partial here */}
154
+ <Disabled.render />
155
+ </div>
156
+ <div>
157
+ <h2>HideLabel</h2>
158
+ {/* @ts-expect-error Args are Partial here */}
159
+ <HideLabel.render />
160
+ </div>
161
+ <div>
162
+ <h2>Readonly</h2>
163
+ {/* @ts-expect-error Args are Partial here */}
164
+ <Readonly.render />
165
+ </div>
166
+ </VStack>
167
+ ),
168
+ parameters: {
169
+ chromatic: { disable: false },
170
+ },
132
171
  };