@navikt/ds-react 0.13.2 → 0.13.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.
- package/cjs/form/Fieldset/Fieldset.js +6 -3
- package/cjs/form/Select.js +4 -1
- package/cjs/form/TextField.js +8 -3
- package/cjs/form/Textarea.js +4 -1
- package/cjs/form/checkbox/Checkbox.js +9 -8
- package/cjs/form/checkbox/useCheckbox.js +2 -1
- package/cjs/form/radio/Radio.js +8 -14
- package/cjs/form/radio/useRadio.js +2 -1
- package/cjs/form/search-field/SearchField.js +4 -1
- package/esm/form/Fieldset/Fieldset.js +7 -4
- package/esm/form/Fieldset/Fieldset.js.map +1 -1
- package/esm/form/Select.js +4 -1
- package/esm/form/Select.js.map +1 -1
- package/esm/form/TextField.js +9 -4
- package/esm/form/TextField.js.map +1 -1
- package/esm/form/Textarea.js +4 -1
- package/esm/form/Textarea.js.map +1 -1
- package/esm/form/checkbox/Checkbox.d.ts +6 -1
- package/esm/form/checkbox/Checkbox.js +10 -9
- package/esm/form/checkbox/Checkbox.js.map +1 -1
- package/esm/form/checkbox/CheckboxGroup.d.ts +1 -1
- package/esm/form/checkbox/CheckboxGroup.js.map +1 -1
- package/esm/form/checkbox/useCheckbox.js +2 -1
- package/esm/form/checkbox/useCheckbox.js.map +1 -1
- package/esm/form/radio/Radio.d.ts +4 -1
- package/esm/form/radio/Radio.js +9 -15
- package/esm/form/radio/Radio.js.map +1 -1
- package/esm/form/radio/RadioGroup.d.ts +1 -1
- package/esm/form/radio/RadioGroup.js.map +1 -1
- package/esm/form/radio/useRadio.js +2 -1
- package/esm/form/radio/useRadio.js.map +1 -1
- package/esm/form/search-field/SearchField.js +4 -1
- package/esm/form/search-field/SearchField.js.map +1 -1
- package/package.json +2 -2
- package/src/form/Fieldset/Fieldset.tsx +25 -13
- package/src/form/Select.tsx +4 -1
- package/src/form/TextField.tsx +30 -12
- package/src/form/Textarea.tsx +4 -1
- package/src/form/checkbox/Checkbox.tsx +30 -38
- package/src/form/checkbox/CheckboxGroup.tsx +2 -1
- package/src/form/checkbox/stories/checkbox.stories.mdx +17 -45
- package/src/form/checkbox/stories/checkbox.stories.tsx +55 -82
- package/src/form/checkbox/useCheckbox.ts +5 -1
- package/src/form/radio/Radio.tsx +26 -41
- package/src/form/radio/RadioGroup.tsx +2 -1
- package/src/form/radio/stories/radio.stories.mdx +3 -29
- package/src/form/radio/stories/radio.stories.tsx +33 -64
- package/src/form/radio/useRadio.ts +5 -1
- package/src/form/search-field/SearchField.tsx +4 -1
- package/src/form/search-field/stories/search-field.stories.tsx +24 -0
- package/src/form/stories/text-field.stories.tsx +19 -0
- package/src/form/stories/textarea.stories.tsx +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NAV designsystem react components",
|
|
6
6
|
"author": "NAV Designsystem team",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"react": "^16.8.0 || ^17.0.0"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "f6c4f853afefa13244fe3f9bd55126d7caaa0b70"
|
|
67
67
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cl from "classnames";
|
|
2
2
|
import React, { FieldsetHTMLAttributes, forwardRef, useContext } from "react";
|
|
3
|
-
import { BodyShort, Label, omit } from "../..";
|
|
3
|
+
import { BodyShort, Detail, Label, omit } from "../..";
|
|
4
4
|
import ErrorMessage from "../ErrorMessage";
|
|
5
5
|
import { FormFieldProps } from "../useFormField";
|
|
6
6
|
import { useFieldset } from "./useFieldset";
|
|
@@ -101,18 +101,30 @@ const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
|
|
101
101
|
>
|
|
102
102
|
{legend}
|
|
103
103
|
</Label>
|
|
104
|
-
{!!description &&
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
{!!description &&
|
|
105
|
+
(size === "medium" ? (
|
|
106
|
+
<BodyShort
|
|
107
|
+
className={cl("navds-fieldset__description", {
|
|
108
|
+
"sr-only": !!hideLegend,
|
|
109
|
+
})}
|
|
110
|
+
id={inputDescriptionId}
|
|
111
|
+
size="small"
|
|
112
|
+
as="div"
|
|
113
|
+
>
|
|
114
|
+
{props.description}
|
|
115
|
+
</BodyShort>
|
|
116
|
+
) : (
|
|
117
|
+
<Detail
|
|
118
|
+
className={cl("navds-fieldset__description", {
|
|
119
|
+
"sr-only": !!hideLegend,
|
|
120
|
+
})}
|
|
121
|
+
id={inputDescriptionId}
|
|
122
|
+
size="small"
|
|
123
|
+
as="div"
|
|
124
|
+
>
|
|
125
|
+
{props.description}
|
|
126
|
+
</Detail>
|
|
127
|
+
))}
|
|
116
128
|
{children}
|
|
117
129
|
<div
|
|
118
130
|
id={errorId}
|
package/src/form/Select.tsx
CHANGED
|
@@ -52,7 +52,10 @@ const Select = forwardRef<HTMLSelectElement, SelectProps>((props, ref) => {
|
|
|
52
52
|
className,
|
|
53
53
|
"navds-form-field",
|
|
54
54
|
`navds-form-field--${size}`,
|
|
55
|
-
{
|
|
55
|
+
{
|
|
56
|
+
"navds-select--error": hasError,
|
|
57
|
+
"navds-select--disabled": !!inputProps.disabled,
|
|
58
|
+
}
|
|
56
59
|
)}
|
|
57
60
|
>
|
|
58
61
|
<Label
|
package/src/form/TextField.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { forwardRef, InputHTMLAttributes } from "react";
|
|
2
2
|
import cl from "classnames";
|
|
3
|
-
import { BodyShort, Label, omit } from "..";
|
|
3
|
+
import { BodyShort, Detail, Label, omit } from "..";
|
|
4
4
|
import ErrorMessage from "./ErrorMessage";
|
|
5
5
|
import { FormFieldProps, useFormField } from "./useFormField";
|
|
6
6
|
|
|
@@ -52,7 +52,10 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {
|
|
|
52
52
|
className,
|
|
53
53
|
"navds-form-field",
|
|
54
54
|
`navds-form-field--${size}`,
|
|
55
|
-
{
|
|
55
|
+
{
|
|
56
|
+
"navds-text-field--error": hasError,
|
|
57
|
+
"navds-text-field--disabled": !!inputProps.disabled,
|
|
58
|
+
}
|
|
56
59
|
)}
|
|
57
60
|
>
|
|
58
61
|
<Label
|
|
@@ -65,16 +68,31 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {
|
|
|
65
68
|
</Label>
|
|
66
69
|
|
|
67
70
|
{!!description && (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
<>
|
|
72
|
+
{size === "medium" ? (
|
|
73
|
+
<BodyShort
|
|
74
|
+
className={cl("navds-text-field__description", {
|
|
75
|
+
"sr-only": hideLabel,
|
|
76
|
+
})}
|
|
77
|
+
id={inputDescriptionId}
|
|
78
|
+
size="small"
|
|
79
|
+
as="div"
|
|
80
|
+
>
|
|
81
|
+
{description}
|
|
82
|
+
</BodyShort>
|
|
83
|
+
) : (
|
|
84
|
+
<Detail
|
|
85
|
+
className={cl("navds-text-field__description", {
|
|
86
|
+
"sr-only": hideLabel,
|
|
87
|
+
})}
|
|
88
|
+
id={inputDescriptionId}
|
|
89
|
+
size="small"
|
|
90
|
+
as="div"
|
|
91
|
+
>
|
|
92
|
+
{description}
|
|
93
|
+
</Detail>
|
|
94
|
+
)}
|
|
95
|
+
</>
|
|
78
96
|
)}
|
|
79
97
|
<input
|
|
80
98
|
{...omit(rest, ["error", "errorId", "size"])}
|
package/src/form/Textarea.tsx
CHANGED
|
@@ -66,7 +66,10 @@ const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
|
66
66
|
className,
|
|
67
67
|
"navds-form-field",
|
|
68
68
|
`navds-form-field--${size}`,
|
|
69
|
-
{
|
|
69
|
+
{
|
|
70
|
+
"navds-textarea--error": hasError,
|
|
71
|
+
"navds-textarea--disabled": !!inputProps.disabled,
|
|
72
|
+
}
|
|
70
73
|
)}
|
|
71
74
|
>
|
|
72
75
|
<Label
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import React, { forwardRef, InputHTMLAttributes } from "react";
|
|
2
2
|
import cl from "classnames";
|
|
3
3
|
import useCheckbox from "./useCheckbox";
|
|
4
|
-
import ErrorMessage from "../ErrorMessage";
|
|
5
4
|
import { FormFieldProps } from "../useFormField";
|
|
6
|
-
import { BodyShort, omit } from "../..";
|
|
5
|
+
import { BodyShort, Detail, omit } from "../..";
|
|
7
6
|
|
|
8
7
|
export interface CheckboxProps
|
|
9
|
-
extends FormFieldProps,
|
|
8
|
+
extends Omit<FormFieldProps, "errorId">,
|
|
10
9
|
Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
10
|
+
/**
|
|
11
|
+
* Checkbox has error
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
error?: boolean;
|
|
11
15
|
/**
|
|
12
16
|
* Label for checkbox
|
|
13
17
|
*/
|
|
@@ -23,14 +27,9 @@ export interface CheckboxProps
|
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
showErrorMsg,
|
|
30
|
-
hasError,
|
|
31
|
-
size,
|
|
32
|
-
inputDescriptionId,
|
|
33
|
-
} = useCheckbox(props);
|
|
30
|
+
const { inputProps, hasError, size } = useCheckbox(props);
|
|
31
|
+
|
|
32
|
+
const Description = size === "medium" ? BodyShort : Detail;
|
|
34
33
|
|
|
35
34
|
return (
|
|
36
35
|
<div
|
|
@@ -40,8 +39,7 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {
|
|
|
40
39
|
`navds-checkbox--${size}`,
|
|
41
40
|
{
|
|
42
41
|
"navds-checkbox--error": hasError,
|
|
43
|
-
"navds-checkbox--
|
|
44
|
-
"navds-checkbox--with-description": !!props.description,
|
|
42
|
+
"navds-checkbox--disabled": inputProps.disabled,
|
|
45
43
|
}
|
|
46
44
|
)}
|
|
47
45
|
>
|
|
@@ -50,7 +48,6 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {
|
|
|
50
48
|
"children",
|
|
51
49
|
"size",
|
|
52
50
|
"error",
|
|
53
|
-
"errorId",
|
|
54
51
|
"description",
|
|
55
52
|
"hideLabel",
|
|
56
53
|
])}
|
|
@@ -58,31 +55,26 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {
|
|
|
58
55
|
className="navds-checkbox__input"
|
|
59
56
|
ref={ref}
|
|
60
57
|
/>
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
>
|
|
67
|
-
{props.hideLabel ? (
|
|
68
|
-
<span className="sr-only">{props.children}</span>
|
|
69
|
-
) : (
|
|
70
|
-
props.children
|
|
71
|
-
)}
|
|
72
|
-
</BodyShort>
|
|
73
|
-
{props.description && (
|
|
74
|
-
<BodyShort
|
|
75
|
-
as="div"
|
|
76
|
-
size={size}
|
|
77
|
-
id={inputDescriptionId}
|
|
78
|
-
className="navds-checkbox__description"
|
|
58
|
+
<label htmlFor={inputProps.id} className="navds-checkbox__label">
|
|
59
|
+
<div
|
|
60
|
+
className={cl("navds-checkbox__content", {
|
|
61
|
+
"sr-only": props.hideLabel,
|
|
62
|
+
})}
|
|
79
63
|
>
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
64
|
+
<BodyShort as="div" size={size}>
|
|
65
|
+
{props.children}
|
|
66
|
+
</BodyShort>
|
|
67
|
+
{props.description && (
|
|
68
|
+
<Description
|
|
69
|
+
as="div"
|
|
70
|
+
size="small"
|
|
71
|
+
className="navds-checkbox__description"
|
|
72
|
+
>
|
|
73
|
+
{props.description}
|
|
74
|
+
</Description>
|
|
75
|
+
)}
|
|
76
|
+
</div>
|
|
77
|
+
</label>
|
|
86
78
|
</div>
|
|
87
79
|
);
|
|
88
80
|
});
|
|
@@ -12,7 +12,8 @@ export const CheckboxGroupContext = createContext<CheckboxGroupState | null>(
|
|
|
12
12
|
null
|
|
13
13
|
);
|
|
14
14
|
|
|
15
|
-
export interface CheckboxGroupProps
|
|
15
|
+
export interface CheckboxGroupProps
|
|
16
|
+
extends Omit<FieldsetProps, "onChange" | "errorPropagation"> {
|
|
16
17
|
/**
|
|
17
18
|
* Checkboxes
|
|
18
19
|
*/
|
|
@@ -49,6 +49,8 @@ Man kan både sette en description på CheckboxGroup og selve checkbox
|
|
|
49
49
|
|
|
50
50
|
## Errors
|
|
51
51
|
|
|
52
|
+
Feilmeldinger kan bare settes på gruppa
|
|
53
|
+
|
|
52
54
|
```jsx
|
|
53
55
|
<CheckboxGroup legend="Mollit eiusmod" error="Boks nr 2 må være valgt">
|
|
54
56
|
<Checkbox value="Apple">Apple</Checkbox>
|
|
@@ -65,37 +67,23 @@ Man kan både sette en description på CheckboxGroup og selve checkbox
|
|
|
65
67
|
</CheckboxGroup>
|
|
66
68
|
</Canvas>
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
Enkelt-checkboxer tar en `boolean` error prop
|
|
69
71
|
|
|
70
72
|
```jsx
|
|
71
|
-
<
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
error="Boks nr 2 må være valgt"
|
|
75
|
-
>
|
|
76
|
-
<Checkbox value="Apple">Apple</Checkbox>
|
|
77
|
-
<Checkbox value="Orange">Orange</Checkbox>
|
|
78
|
-
<Checkbox value="Melon">Melon</Checkbox>
|
|
79
|
-
</CheckboxGroup>
|
|
73
|
+
<Checkbox value="Apple" error>
|
|
74
|
+
Apple
|
|
75
|
+
</Checkbox>
|
|
80
76
|
```
|
|
81
77
|
|
|
82
78
|
<Canvas>
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
error="Boks nr 2 må være valgt"
|
|
87
|
-
>
|
|
88
|
-
<Checkbox value="Apple">Apple</Checkbox>
|
|
89
|
-
<Checkbox value="Orange" error="Boksen må være valgt">
|
|
90
|
-
Orange
|
|
91
|
-
</Checkbox>
|
|
92
|
-
<Checkbox value="Melon">Melon</Checkbox>
|
|
93
|
-
</CheckboxGroup>
|
|
79
|
+
<Checkbox value="Apple" error>
|
|
80
|
+
Apple
|
|
81
|
+
</Checkbox>
|
|
94
82
|
</Canvas>
|
|
95
83
|
|
|
96
84
|
## Sizing
|
|
97
85
|
|
|
98
|
-
Checkboxer har default
|
|
86
|
+
Checkboxer har default 48px høy klikkflate. Med size="small" blir klikkflaten 32px
|
|
99
87
|
|
|
100
88
|
```jsx
|
|
101
89
|
<CheckboxGroup
|
|
@@ -166,31 +154,15 @@ Ved bruk av `hideLegend` på CheckboxGroup kan man gjøre slik at legend/descrip
|
|
|
166
154
|
Ved bruk av `hideLabel` kan man lettere ta i bruk checkbox internt i eks tabeller.
|
|
167
155
|
|
|
168
156
|
```jsx
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
</Checkbox>
|
|
173
|
-
<Checkbox value="Orange" hideLabel>
|
|
174
|
-
Orange
|
|
175
|
-
</Checkbox>
|
|
176
|
-
<Checkbox value="Melon" hideLabel>
|
|
177
|
-
Melon
|
|
178
|
-
</Checkbox>
|
|
179
|
-
</CheckboxGroup>
|
|
157
|
+
<Checkbox value="Orange" hideLabel>
|
|
158
|
+
Orange
|
|
159
|
+
</Checkbox>
|
|
180
160
|
```
|
|
181
161
|
|
|
182
162
|
<Canvas>
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
</Checkbox>
|
|
187
|
-
<Checkbox value="Orange" hideLabel>
|
|
188
|
-
Orange
|
|
189
|
-
</Checkbox>
|
|
190
|
-
<Checkbox value="Melon" hideLabel>
|
|
191
|
-
Melon
|
|
192
|
-
</Checkbox>
|
|
193
|
-
</CheckboxGroup>
|
|
163
|
+
<Checkbox value="Orange" hideLabel>
|
|
164
|
+
Orange
|
|
165
|
+
</Checkbox>
|
|
194
166
|
</Canvas>
|
|
195
167
|
|
|
196
168
|
## Disabled
|
|
@@ -206,7 +178,7 @@ NOTE: Husk at disabled bør unngås!
|
|
|
206
178
|
<Checkbox value="Melon">Melon</Checkbox>
|
|
207
179
|
</CheckboxGroup>
|
|
208
180
|
|
|
209
|
-
<CheckboxGroup legend="Mollit eiusmod"
|
|
181
|
+
<CheckboxGroup legend="Mollit eiusmod">
|
|
210
182
|
<Checkbox value="Apple" disabled>Apple</Checkbox>
|
|
211
183
|
<Checkbox value="Orange">Orange</Checkbox>
|
|
212
184
|
<Checkbox value="Melon">Melon</Checkbox>
|
|
@@ -7,90 +7,63 @@ export default {
|
|
|
7
7
|
} as Meta;
|
|
8
8
|
|
|
9
9
|
export const All = () => {
|
|
10
|
+
const Checkboxes = (props) => (
|
|
11
|
+
<CheckboxGroup
|
|
12
|
+
legend="Mollit eiusmod"
|
|
13
|
+
description="Exercitation do labore"
|
|
14
|
+
{...props}
|
|
15
|
+
>
|
|
16
|
+
<Checkbox value="Apple">Apple</Checkbox>
|
|
17
|
+
<Checkbox value="Orange" description="Laborum ad">
|
|
18
|
+
Orange
|
|
19
|
+
</Checkbox>
|
|
20
|
+
<Checkbox value="Banana" description={<div>Laborum ad</div>}>
|
|
21
|
+
Banana
|
|
22
|
+
</Checkbox>
|
|
23
|
+
<Checkbox value="Melon">Melon</Checkbox>
|
|
24
|
+
</CheckboxGroup>
|
|
25
|
+
);
|
|
26
|
+
|
|
10
27
|
return (
|
|
11
28
|
<>
|
|
12
|
-
<h1>
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
error="Boks nr 2 må være valgt"
|
|
51
|
-
size="small"
|
|
52
|
-
>
|
|
53
|
-
<Checkbox value="Apple">Apple</Checkbox>
|
|
54
|
-
<Checkbox value="Orange">Orange</Checkbox>
|
|
55
|
-
<Checkbox value="Melon">Melon</Checkbox>
|
|
56
|
-
</CheckboxGroup>
|
|
57
|
-
<h2>defaultValue</h2>
|
|
58
|
-
<CheckboxGroup legend="Mollit eiusmod" defaultValue={["Orange", "Melon"]}>
|
|
59
|
-
<Checkbox value="Apple">Apple</Checkbox>
|
|
60
|
-
<Checkbox value="Orange">Orange</Checkbox>
|
|
61
|
-
<Checkbox value="Melon">Melon</Checkbox>
|
|
62
|
-
</CheckboxGroup>
|
|
63
|
-
<h2>hideLenged</h2>
|
|
64
|
-
<CheckboxGroup legend="Mollit eiusmod" hideLegend>
|
|
65
|
-
<Checkbox value="Apple">Apple</Checkbox>
|
|
66
|
-
<Checkbox value="Orange">Orange</Checkbox>
|
|
67
|
-
<Checkbox value="Melon">Melon</Checkbox>
|
|
68
|
-
</CheckboxGroup>
|
|
69
|
-
<h2>hideLabel</h2>
|
|
70
|
-
<CheckboxGroup legend="Mollit eiusmod">
|
|
71
|
-
<Checkbox value="Apple" hideLabel>
|
|
72
|
-
Apple
|
|
73
|
-
</Checkbox>
|
|
74
|
-
<Checkbox value="Orange" hideLabel>
|
|
75
|
-
Orange
|
|
76
|
-
</Checkbox>
|
|
77
|
-
<Checkbox value="Melon" hideLabel>
|
|
78
|
-
Melon
|
|
79
|
-
</Checkbox>
|
|
80
|
-
</CheckboxGroup>
|
|
81
|
-
<h2>Disabled</h2>
|
|
82
|
-
<CheckboxGroup legend="Mollit eiusmod" disabled>
|
|
83
|
-
<Checkbox value="Apple">Apple</Checkbox>
|
|
84
|
-
<Checkbox value="Orange">Orange</Checkbox>
|
|
85
|
-
<Checkbox value="Melon">Melon</Checkbox>
|
|
86
|
-
</CheckboxGroup>
|
|
87
|
-
<CheckboxGroup legend="Mollit eiusmod">
|
|
88
|
-
<Checkbox value="Apple" disabled>
|
|
89
|
-
Apple
|
|
90
|
-
</Checkbox>
|
|
91
|
-
<Checkbox value="Orange">Orange</Checkbox>
|
|
92
|
-
<Checkbox value="Melon">Melon</Checkbox>
|
|
93
|
-
</CheckboxGroup>
|
|
29
|
+
<h1>Checkbox</h1>
|
|
30
|
+
<h2>Single checkbox</h2>
|
|
31
|
+
<Checkbox value="Apple">Apple</Checkbox>
|
|
32
|
+
<h3>Desription</h3>
|
|
33
|
+
<Checkbox value="Apple" description="Laborum ad" defaultChecked>
|
|
34
|
+
Apple
|
|
35
|
+
</Checkbox>
|
|
36
|
+
<h3>Error</h3>
|
|
37
|
+
<Checkbox value="Apple" error>
|
|
38
|
+
Apple
|
|
39
|
+
</Checkbox>
|
|
40
|
+
<Checkbox value="Apple" error defaultChecked>
|
|
41
|
+
Orange
|
|
42
|
+
</Checkbox>
|
|
43
|
+
<h3>Hide label</h3>
|
|
44
|
+
<Checkbox value="Apple" hideLabel description="Laborum ad">
|
|
45
|
+
Apple
|
|
46
|
+
</Checkbox>
|
|
47
|
+
<h3>Disabled</h3>
|
|
48
|
+
<Checkbox value="Apple" disabled>
|
|
49
|
+
Apple
|
|
50
|
+
</Checkbox>
|
|
51
|
+
<Checkbox value="Orange" description="Laborum ad" disabled defaultChecked>
|
|
52
|
+
Orange
|
|
53
|
+
</Checkbox>
|
|
54
|
+
|
|
55
|
+
<h2>Checkbox group</h2>
|
|
56
|
+
<Checkboxes />
|
|
57
|
+
<h3>Error</h3>
|
|
58
|
+
<Checkboxes error="Dette er en feilmelding" />
|
|
59
|
+
<h3>Small</h3>
|
|
60
|
+
<Checkboxes size="small" />
|
|
61
|
+
<h3>Small + error</h3>
|
|
62
|
+
<Checkboxes size="small" error="Dette er en feilmelding" />
|
|
63
|
+
<h3>Default value</h3>
|
|
64
|
+
<Checkboxes defaultValue={["Orange", "Melon"]} />
|
|
65
|
+
<h3>Disabled</h3>
|
|
66
|
+
<Checkboxes disabled />
|
|
94
67
|
</>
|
|
95
68
|
);
|
|
96
69
|
};
|
|
@@ -2,6 +2,7 @@ import { useContext } from "react";
|
|
|
2
2
|
import { CheckboxProps } from "../..";
|
|
3
3
|
import { useFormField } from "../useFormField";
|
|
4
4
|
import { CheckboxGroupContext } from "./CheckboxGroup";
|
|
5
|
+
import { omit } from "../..";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Handles props for Checkboxes in context with Fieldset and CheckboxGroup
|
|
@@ -9,7 +10,10 @@ import { CheckboxGroupContext } from "./CheckboxGroup";
|
|
|
9
10
|
const useCheckbox = ({ children, ...props }: CheckboxProps) => {
|
|
10
11
|
const checkboxGroup = useContext(CheckboxGroupContext);
|
|
11
12
|
|
|
12
|
-
const { inputProps, ...rest } = useFormField(
|
|
13
|
+
const { inputProps, ...rest } = useFormField(
|
|
14
|
+
omit(props, ["description"]),
|
|
15
|
+
"checkbox"
|
|
16
|
+
);
|
|
13
17
|
|
|
14
18
|
if (checkboxGroup) {
|
|
15
19
|
if (props.checked) {
|
package/src/form/radio/Radio.tsx
CHANGED
|
@@ -1,71 +1,56 @@
|
|
|
1
1
|
import React, { forwardRef, InputHTMLAttributes } from "react";
|
|
2
2
|
import cl from "classnames";
|
|
3
|
-
import { BodyShort, omit } from "../..";
|
|
4
|
-
import ErrorMessage from "../ErrorMessage";
|
|
3
|
+
import { BodyShort, Detail, omit } from "../..";
|
|
5
4
|
import { FormFieldProps } from "../useFormField";
|
|
6
5
|
import { useRadio } from "./useRadio";
|
|
7
6
|
|
|
8
7
|
export interface RadioProps
|
|
9
|
-
extends FormFieldProps,
|
|
8
|
+
extends Omit<FormFieldProps, "error" | "errorId">,
|
|
10
9
|
Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
11
10
|
/**
|
|
12
11
|
* Label for radio
|
|
13
12
|
*/
|
|
14
13
|
children: React.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* The value of the HTML element
|
|
16
|
+
*/
|
|
15
17
|
value: string;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
const Radio = forwardRef<HTMLInputElement, RadioProps>((props, ref) => {
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
showErrorMsg,
|
|
23
|
-
size,
|
|
24
|
-
hasError,
|
|
25
|
-
inputDescriptionId,
|
|
26
|
-
} = useRadio(props);
|
|
21
|
+
const { inputProps, size, hasError } = useRadio(props);
|
|
22
|
+
|
|
23
|
+
const Description = size === "medium" ? BodyShort : Detail;
|
|
27
24
|
|
|
28
25
|
return (
|
|
29
26
|
<div
|
|
30
27
|
className={cl(props.className, "navds-radio", `navds-radio--${size}`, {
|
|
31
28
|
"navds-radio--error": hasError,
|
|
32
|
-
"navds-radio--
|
|
33
|
-
"navds-radio--with-description": !!props.description,
|
|
29
|
+
"navds-radio--disabled": inputProps.disabled,
|
|
34
30
|
})}
|
|
35
31
|
>
|
|
36
32
|
<input
|
|
37
|
-
{...omit(props, [
|
|
38
|
-
"children",
|
|
39
|
-
"size",
|
|
40
|
-
"error",
|
|
41
|
-
"errorId",
|
|
42
|
-
"description",
|
|
43
|
-
])}
|
|
33
|
+
{...omit(props, ["children", "size", "description"])}
|
|
44
34
|
{...inputProps}
|
|
45
35
|
className="navds-radio__input"
|
|
46
36
|
ref={ref}
|
|
47
37
|
/>
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
>
|
|
63
|
-
|
|
64
|
-
</BodyShort>
|
|
65
|
-
)}
|
|
66
|
-
<div id={errorId} aria-relevant="additions removals" aria-live="polite">
|
|
67
|
-
{showErrorMsg && <ErrorMessage size={size}>{props.error}</ErrorMessage>}
|
|
68
|
-
</div>
|
|
38
|
+
<label htmlFor={inputProps.id} className="navds-radio__label">
|
|
39
|
+
<div className="navds-radio__content">
|
|
40
|
+
<BodyShort as="div" size={size}>
|
|
41
|
+
{props.children}
|
|
42
|
+
</BodyShort>
|
|
43
|
+
{props.description && (
|
|
44
|
+
<Description
|
|
45
|
+
as="div"
|
|
46
|
+
size="small"
|
|
47
|
+
className="navds-radio__description"
|
|
48
|
+
>
|
|
49
|
+
{props.description}
|
|
50
|
+
</Description>
|
|
51
|
+
)}
|
|
52
|
+
</div>
|
|
53
|
+
</label>
|
|
69
54
|
</div>
|
|
70
55
|
);
|
|
71
56
|
});
|
|
@@ -15,7 +15,8 @@ export const RadioGroupContext = React.createContext<RadioGroupContextProps | nu
|
|
|
15
15
|
null
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
export interface RadioGroupProps
|
|
18
|
+
export interface RadioGroupProps
|
|
19
|
+
extends Omit<FieldsetProps, "onChange" | "errorPropagation"> {
|
|
19
20
|
/**
|
|
20
21
|
* Collection of <Radio>-elements
|
|
21
22
|
*/
|