@navikt/ds-react 0.19.0 → 0.19.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.
@@ -2,69 +2,113 @@ import React from "react";
2
2
  import { Select } from "../index";
3
3
  import { Meta } from "@storybook/react/types-6-0";
4
4
  export default {
5
- title: "ds-react/form/select",
5
+ title: "ds-react/form/Select",
6
6
  component: Select,
7
+ argTypes: {
8
+ size: {
9
+ control: {
10
+ type: "radio",
11
+ options: ["medium", "small"],
12
+ },
13
+ },
14
+ description: {
15
+ type: "string",
16
+ },
17
+ error: {
18
+ type: "string",
19
+ },
20
+ hideLabel: {
21
+ type: "boolean",
22
+ },
23
+ disabled: {
24
+ type: "boolean",
25
+ },
26
+ },
7
27
  } as Meta;
8
28
 
9
- export const All = () => {
29
+ const content = (
30
+ <>
31
+ <option value="">Velg land</option>
32
+ <option value="norge">Norge</option>
33
+ <option value="sverige">Sverige</option>
34
+ </>
35
+ );
36
+
37
+ export const Default = (props) => {
10
38
  return (
11
- <div>
12
- <h1>Select</h1>
39
+ <Select {...props} label="Ipsum enim quis culpa">
40
+ {content}
41
+ </Select>
42
+ );
43
+ };
13
44
 
14
- <Select label="Ipsum enim quis culpa">
15
- <option value="">Velg land</option>
16
- <option value="norge">Norge</option>
17
- <option value="sverige">Sverige</option>
18
- </Select>
45
+ Default.args = {};
19
46
 
20
- <h2>Description</h2>
47
+ export const Small = () => {
48
+ return (
49
+ <Select size="small" label="Ipsum enim quis culpa">
50
+ {content}
51
+ </Select>
52
+ );
53
+ };
21
54
 
22
- <Select label="Ipsum enim quis culpa" description={<div>Aute enim</div>}>
23
- <option value="">Velg land</option>
24
- <option value="norge">Norge</option>
25
- <option value="sverige">Sverige</option>
55
+ export const Description = () => {
56
+ return (
57
+ <div className="colgap">
58
+ <Select
59
+ label="Ipsum enim quis culpa"
60
+ description="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
61
+ >
62
+ {content}
26
63
  </Select>
27
-
28
- <h2>Errors</h2>
29
-
30
64
  <Select
31
65
  label="Ipsum enim quis culpa"
32
- description="Aute enim"
33
- error="Select error message"
66
+ description="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
67
+ size="small"
34
68
  >
35
- <option value="">Velg land</option>
36
- <option value="norge">Norge</option>
37
- <option value="sverige">Sverige</option>
69
+ {content}
38
70
  </Select>
71
+ </div>
72
+ );
73
+ };
39
74
 
40
- <h2>Sizing</h2>
41
-
75
+ export const Error = () => {
76
+ return (
77
+ <div className="colgap">
42
78
  <Select
43
79
  label="Ipsum enim quis culpa"
44
- description="Aute enim"
45
- error="Select error message"
80
+ error="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
81
+ >
82
+ {content}
83
+ </Select>
84
+ <Select
85
+ label="Ipsum enim quis culpa"
86
+ error="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
46
87
  size="small"
47
88
  >
48
- <option value="">Velg land</option>
49
- <option value="norge">Norge</option>
50
- <option value="sverige">Sverige</option>
89
+ {content}
51
90
  </Select>
91
+ </div>
92
+ );
93
+ };
52
94
 
53
- <h2>hideLabel</h2>
54
-
55
- <Select label="Ipsum enim quis culpa" description="Aute enim" hideLabel>
56
- <option value="">Velg land</option>
57
- <option value="norge">Norge</option>
58
- <option value="sverige">Sverige</option>
95
+ export const Disabled = () => {
96
+ return (
97
+ <div className="colgap">
98
+ <Select label="Ipsum enim quis culpa" disabled>
99
+ {content}
59
100
  </Select>
60
-
61
- <h2>Disabled</h2>
62
-
63
- <Select label="Ipsum enim quis culpa" description="Aute enim" disabled>
64
- <option value="">Velg land</option>
65
- <option value="norge">Norge</option>
66
- <option value="sverige">Sverige</option>
101
+ <Select label="Ipsum enim quis culpa" disabled size="small">
102
+ {content}
67
103
  </Select>
68
104
  </div>
69
105
  );
70
106
  };
107
+
108
+ export const HideLabel = () => {
109
+ return (
110
+ <Select label="Ipsum enim quis culpa" hideLabel>
111
+ {content}
112
+ </Select>
113
+ );
114
+ };
@@ -1,104 +1,117 @@
1
- import React, { useState } from "react";
2
- import { Switch } from "../index";
3
1
  import { Meta } from "@storybook/react/types-6-0";
4
- import { Fieldset } from "../..";
2
+ import React from "react";
3
+ import { Switch } from "../index";
4
+
5
5
  export default {
6
- title: "ds-react/form/switch",
6
+ title: "ds-react/form/Switch",
7
7
  component: Switch,
8
+ argTypes: {
9
+ size: {
10
+ control: {
11
+ type: "radio",
12
+ options: ["medium", "small"],
13
+ },
14
+ },
15
+ position: {
16
+ control: {
17
+ type: "radio",
18
+ options: ["right", "left"],
19
+ },
20
+ },
21
+ description: {
22
+ type: "string",
23
+ },
24
+ hideLabel: {
25
+ type: "boolean",
26
+ },
27
+ disabled: {
28
+ type: "boolean",
29
+ },
30
+ loading: {
31
+ type: "boolean",
32
+ },
33
+ },
8
34
  } as Meta;
9
35
 
10
- export const All = () => {
11
- const [checked, setChecked] = useState(false);
12
- const [loadingState, setLoadingState] = useState(false);
13
- return (
14
- <div style={{ width: "fit-content" }}>
15
- <h1>Switch</h1>
16
- <Switch>Label text</Switch>
17
- <Switch position="right">Label text</Switch>
18
-
19
- <h2>Switch w/Description</h2>
20
- <Switch>Label text</Switch>
21
- <Switch description="Switch description">Label text</Switch>
22
- <Switch>Label text</Switch>
23
-
24
- <Switch position="right">Label text</Switch>
25
- <Switch position="right" description="Switch description">
26
- Label text
27
- </Switch>
28
- <Switch position="right">Label text</Switch>
36
+ export const Default = (props) => {
37
+ return <Switch {...props}>Label text</Switch>;
38
+ };
29
39
 
30
- <h2>hidelabel</h2>
31
- <Switch description="Switch description" hideLabel>
32
- Label text
33
- </Switch>
34
- <Switch description="Switch description" hideLabel>
35
- Label text
36
- </Switch>
37
- <Switch hideLabel size="small">
38
- Label text small
39
- </Switch>
40
- <Switch position="right" description="Switch description" hideLabel>
41
- Label text
42
- </Switch>
43
- <Switch position="right" description="Switch description" hideLabel>
44
- Label text
45
- </Switch>
46
- <Switch position="right" hideLabel size="small">
47
- Label text small
48
- </Switch>
40
+ Default.args = {
41
+ checked: false,
42
+ position: "right",
43
+ };
49
44
 
50
- <h2>Switch small</h2>
45
+ export const Small = () => {
46
+ return (
47
+ <div className="colgap">
51
48
  <Switch size="small">Label text</Switch>
52
- <Switch description="Switch description" size="small">
49
+ <Switch size="small" position="right">
53
50
  Label text
54
51
  </Switch>
55
- <Switch size="small">Label text</Switch>
52
+ </div>
53
+ );
54
+ };
56
55
 
57
- <Switch position="right" size="small">
58
- Label text
59
- </Switch>
60
- <Switch position="right" description="Switch description" size="small">
56
+ export const Description = () => {
57
+ return (
58
+ <div className="colgap">
59
+ <Switch size="small" description="Cillum sint exercitation ut cillum.">
61
60
  Label text
62
61
  </Switch>
63
- <Switch position="right" size="small">
62
+ <Switch
63
+ size="small"
64
+ position="right"
65
+ description="Cillum sint exercitation ut cillum."
66
+ >
64
67
  Label text
65
68
  </Switch>
69
+ </div>
70
+ );
71
+ };
66
72
 
67
- <h2>Controlled</h2>
68
- <Switch checked={checked} onChange={() => setChecked(!checked)}>
69
- Label text
70
- </Switch>
73
+ export const Loading = () => {
74
+ return (
75
+ <div className="colgap">
76
+ <div className="colgap">
77
+ <Switch loading>Label text</Switch>
71
78
 
72
- <h2>Defaultchecked</h2>
73
- <Switch defaultChecked>Label text</Switch>
79
+ <Switch checked loading>
80
+ Label text
81
+ </Switch>
82
+ </div>
83
+ <div className="colgap">
84
+ <Switch loading size="small">
85
+ Label text
86
+ </Switch>
87
+ <Switch checked loading size="small">
88
+ Label text
89
+ </Switch>
90
+ </div>
91
+ </div>
92
+ );
93
+ };
74
94
 
75
- <h2>Disabled</h2>
95
+ export const Disabled = () => {
96
+ return (
97
+ <div className="colgap">
76
98
  <Switch disabled>Label text</Switch>
77
- <Switch disabled defaultChecked>
99
+
100
+ <Switch checked disabled>
78
101
  Label text
79
102
  </Switch>
103
+ </div>
104
+ );
105
+ };
80
106
 
81
- <h2>With fieldset error</h2>
82
- <Fieldset legend="Fieldset legend" error="Errormsg">
83
- <Switch defaultChecked>Label text</Switch>
84
- <Switch>Label text</Switch>
85
- </Fieldset>
107
+ export const HideLabel = () => {
108
+ return (
109
+ <div className="colgap">
110
+ <Switch hideLabel>Label text</Switch>
86
111
 
87
- <h2>loading prop</h2>
88
- <Switch loading>Label text</Switch>
89
- <Switch size="small" loading>
90
- Label text
91
- </Switch>
92
- <Switch disabled loading>
93
- Label text
94
- </Switch>
95
- <Switch checked loading>
112
+ <Switch checked hideLabel>
96
113
  Label text
97
114
  </Switch>
98
- <button onClick={() => setLoadingState(!loadingState)}>
99
- Toggle loading
100
- </button>
101
- <Switch loading={loadingState}>Label text</Switch>
102
115
  </div>
103
116
  );
104
117
  };
@@ -2,78 +2,82 @@ import React from "react";
2
2
  import { TextField } from "../index";
3
3
  import { Meta } from "@storybook/react/types-6-0";
4
4
  export default {
5
- title: "ds-react/form/text-field",
5
+ title: "ds-react/form/TextField",
6
6
  component: TextField,
7
+ argTypes: {
8
+ size: {
9
+ control: {
10
+ type: "radio",
11
+ options: ["medium", "small"],
12
+ },
13
+ },
14
+ description: {
15
+ type: "string",
16
+ },
17
+ error: {
18
+ type: "string",
19
+ },
20
+ hideLabel: {
21
+ type: "boolean",
22
+ },
23
+ disabled: {
24
+ type: "boolean",
25
+ },
26
+ },
7
27
  } as Meta;
8
28
 
9
- export const All = () => {
10
- return (
11
- <div style={{ maxWidth: 400 }}>
12
- <h1>TextField</h1>
13
-
14
- <TextField label="Laborum excepteur" />
15
-
16
- <h2>Description</h2>
17
-
18
- <TextField
19
- label="Laborum excepteur"
20
- description={<div>Cillum mollit</div>}
21
- />
29
+ export const Default = (props) => {
30
+ return <TextField {...props} label="Ipsum enim quis culpa" />;
31
+ };
22
32
 
23
- <h2>Passord-type</h2>
24
- <TextField label="Passord" type="password" />
33
+ Default.args = {};
25
34
 
26
- <h2>Errors</h2>
35
+ export const Small = () => {
36
+ return <TextField size="small" label="Ipsum enim quis culpa" />;
37
+ };
27
38
 
39
+ export const Description = () => {
40
+ return (
41
+ <div className="colgap">
28
42
  <TextField
29
- label="Laborum excepteur"
30
- description="Cillum mollit"
31
- error="TextField error"
43
+ label="Ipsum enim quis culpa"
44
+ description="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
32
45
  />
33
-
34
- <h2>Sizing</h2>
35
-
36
46
  <TextField
47
+ label="Ipsum enim quis culpa"
48
+ description="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
37
49
  size="small"
38
- label="Laborum excepteur"
39
- description="Cillum mollit"
40
- error="TextField error"
41
50
  />
51
+ </div>
52
+ );
53
+ };
42
54
 
43
- <h2>hideLabel</h2>
44
-
55
+ export const Error = () => {
56
+ return (
57
+ <div className="colgap">
45
58
  <TextField
46
- label="Laborum excepteur"
47
- description="Cillum mollit"
48
- hideLabel
59
+ label="Ipsum enim quis culpa"
60
+ error="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
49
61
  />
50
62
 
51
- <h2>Disabled</h2>
52
-
53
- <TextField
54
- label="Laborum excepteur"
55
- description="Cillum mollit"
56
- disabled
57
- />
58
63
  <TextField
64
+ label="Ipsum enim quis culpa"
65
+ error="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
59
66
  size="small"
60
- label="Laborum excepteur"
61
- description="Cillum mollit"
62
- disabled
63
67
  />
64
- <h2>Readonly</h2>
68
+ </div>
69
+ );
70
+ };
65
71
 
66
- <TextField
67
- label="Laborum excepteur"
68
- description="Cillum mollit"
69
- readOnly
70
- />
71
- <TextField
72
- label="Laborum excepteur"
73
- description="Cillum mollit"
74
- size="small"
75
- readOnly
76
- />
72
+ export const Disabled = () => {
73
+ return (
74
+ <div className="colgap">
75
+ <TextField label="Ipsum enim quis culpa" disabled />
76
+ <TextField label="Ipsum enim quis culpa" disabled size="small" />
77
77
  </div>
78
78
  );
79
79
  };
80
+
81
+ export const HideLabel = () => {
82
+ return <TextField label="Ipsum enim quis culpa" hideLabel />;
83
+ };
@@ -1,104 +1,111 @@
1
- import React, { useState } from "react";
2
- import { Textarea } from "../index";
3
1
  import { Meta } from "@storybook/react/types-6-0";
2
+ import React from "react";
3
+ import { Textarea } from "../index";
4
4
  export default {
5
- title: "ds-react/form/textarea",
5
+ title: "ds-react/form/Textarea",
6
6
  component: Textarea,
7
+ argTypes: {
8
+ size: {
9
+ control: {
10
+ type: "radio",
11
+ options: ["medium", "small"],
12
+ },
13
+ },
14
+ description: {
15
+ type: "string",
16
+ },
17
+ error: {
18
+ type: "string",
19
+ },
20
+ hideLabel: {
21
+ type: "boolean",
22
+ },
23
+ disabled: {
24
+ type: "boolean",
25
+ },
26
+ },
7
27
  } as Meta;
8
28
 
9
- export const All = () => {
10
- const [value, setValue] = useState("");
11
-
12
- const handleChange = (e) => {
13
- setValue(e.target.value);
14
- };
15
-
29
+ export const Default = (props) => {
16
30
  return (
17
- <div style={{ maxWidth: 400 }}>
18
- <h1>Textarea</h1>
19
-
20
- <Textarea label="In anim elit" value={value} onChange={handleChange} />
21
-
22
- <h2>Uncontrolled</h2>
23
-
24
- <Textarea label="In anim elit" />
25
-
26
- <h3>defaultValue</h3>
31
+ <Textarea
32
+ {...props}
33
+ maxLength={props?.maxLength ?? 100}
34
+ label="Ipsum enim quis culpa"
35
+ />
36
+ );
37
+ };
27
38
 
28
- <Textarea label="In anim elit" defaultValue="wat" />
39
+ Default.args = {
40
+ maxLength: 100,
41
+ };
29
42
 
30
- <h2>Description</h2>
43
+ export const Small = () => {
44
+ return <Textarea size="small" label="Ipsum enim quis culpa" />;
45
+ };
31
46
 
47
+ export const Description = () => {
48
+ return (
49
+ <div className="colgap">
32
50
  <Textarea
33
- label="In anim elit"
34
- description={<div>Reprehenderit esse proident</div>}
35
- value={value}
36
- onChange={handleChange}
51
+ label="Ipsum enim quis culpa"
52
+ description="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
37
53
  />
38
-
39
- <h2>maxLength</h2>
40
-
41
54
  <Textarea
42
- label="In anim elit"
43
- description="Reprehenderit esse proident"
44
- maxLength={400}
45
- value={value}
46
- onChange={handleChange}
55
+ label="Ipsum enim quis culpa"
56
+ description="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
57
+ size="small"
47
58
  />
59
+ </div>
60
+ );
61
+ };
48
62
 
49
- <h2>Errors</h2>
50
-
63
+ export const Error = () => {
64
+ return (
65
+ <div className="colgap">
51
66
  <Textarea
52
- label="In anim elit"
53
- description="Reprehenderit esse proident"
54
- error="Textarea error"
55
- maxLength={400}
56
- value={value}
57
- onChange={handleChange}
67
+ label="Ipsum enim quis culpa"
68
+ error="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
58
69
  />
59
70
 
60
- <h2>Sizing</h2>
61
-
62
71
  <Textarea
63
- label="In anim elit"
64
- description="Reprehenderit esse proident"
65
- maxLength={400}
72
+ label="Ipsum enim quis culpa"
73
+ error="Consectetur labore velit eiusmod Lorem ut nostrud mollit labore ullamco laboris laboris in."
66
74
  size="small"
67
- value={value}
68
- onChange={handleChange}
69
75
  />
76
+ </div>
77
+ );
78
+ };
70
79
 
71
- <h2>hideLabel</h2>
80
+ export const Disabled = () => {
81
+ return (
82
+ <div className="colgap">
83
+ <Textarea label="Ipsum enim quis culpa" disabled />
84
+ <Textarea label="Ipsum enim quis culpa" disabled size="small" />
85
+ </div>
86
+ );
87
+ };
72
88
 
73
- <Textarea
74
- label="In anim elit"
75
- description="Reprehenderit esse proident"
76
- maxLength={400}
77
- hideLabel
78
- value={value}
79
- onChange={handleChange}
80
- />
89
+ export const HideLabel = () => {
90
+ return <Textarea label="Ipsum enim quis culpa" hideLabel />;
91
+ };
81
92
 
82
- <h2>Disabled</h2>
93
+ export const MaxLength = () => {
94
+ return <Textarea maxLength={200} label="Ipsum enim quis culpa" />;
95
+ };
83
96
 
84
- <Textarea
85
- label="In anim elit"
86
- description="Reprehenderit esse proident"
87
- maxLength={400}
88
- disabled
89
- value="Consectetur commodo mollit voluptate esse minim elit deserunt fugiat consectetur laboris."
90
- onChange={handleChange}
91
- />
92
- <h2>Readonly</h2>
97
+ export const MinRows = () => {
98
+ return <Textarea minRows={5} label="Ipsum enim quis culpa" />;
99
+ };
93
100
 
94
- <Textarea
95
- label="In anim elit"
96
- description="Reprehenderit esse proident"
97
- maxLength={400}
98
- readOnly
99
- value="Consectetur commodo mollit voluptate esse minim elit deserunt fugiat consectetur laboris."
100
- onChange={handleChange}
101
- />
102
- </div>
101
+ export const MaxRows = () => {
102
+ return (
103
+ <Textarea
104
+ maxRows={3}
105
+ value={
106
+ "Aute fugiat ut culpa enim ad culpa proident adipisicing anim proident ipsum elit. Cillum Lorem magna nisi cupidatat consequat culpa. Veniam ex quis elit dolore ea cupidatat fugiat in. Sint proident magna duis consequat velit ea velit pariatur in dolore ad. Aliqua officia nostrud veniam pariatur eu sint elit qui amet."
107
+ }
108
+ label="Ipsum enim quis culpa"
109
+ />
103
110
  );
104
111
  };