@navikt/ds-react 0.15.0 → 0.15.1
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/checkbox/Checkbox.js +12 -1
- package/cjs/form/checkbox/useCheckbox.js +1 -1
- package/esm/form/checkbox/Checkbox.d.ts +5 -0
- package/esm/form/checkbox/Checkbox.js +12 -1
- package/esm/form/checkbox/Checkbox.js.map +1 -1
- package/esm/form/checkbox/useCheckbox.d.ts +0 -1
- package/esm/form/checkbox/useCheckbox.js +1 -1
- package/esm/form/checkbox/useCheckbox.js.map +1 -1
- package/package.json +2 -2
- package/src/form/checkbox/Checkbox.tsx +18 -1
- package/src/form/checkbox/stories/checkbox.stories.tsx +38 -1
- package/src/form/checkbox/useCheckbox.ts +0 -1
|
@@ -39,7 +39,18 @@ const Checkbox = (0, react_1.forwardRef)((props, ref) => {
|
|
|
39
39
|
"error",
|
|
40
40
|
"description",
|
|
41
41
|
"hideLabel",
|
|
42
|
-
]), inputProps, { className: "navds-checkbox__input",
|
|
42
|
+
]), inputProps, { type: "checkbox", className: "navds-checkbox__input", "aria-checked": props.indeterminate ? "mixed" : inputProps.checked, ref: (el) => {
|
|
43
|
+
var _a;
|
|
44
|
+
if (el) {
|
|
45
|
+
el.indeterminate = (_a = props.indeterminate) !== null && _a !== void 0 ? _a : false;
|
|
46
|
+
}
|
|
47
|
+
if (typeof ref === "function") {
|
|
48
|
+
ref(el);
|
|
49
|
+
}
|
|
50
|
+
else if (ref != null) {
|
|
51
|
+
ref.current = el;
|
|
52
|
+
}
|
|
53
|
+
} })),
|
|
43
54
|
react_1.default.createElement("label", { htmlFor: inputProps.id, className: "navds-checkbox__label" },
|
|
44
55
|
react_1.default.createElement("div", { className: (0, classnames_1.default)("navds-checkbox__content", {
|
|
45
56
|
"navds-sr-only": props.hideLabel,
|
|
@@ -30,7 +30,7 @@ const useCheckbox = (_a) => {
|
|
|
30
30
|
console.warn("A <Checkbox> element within a <CheckboxGroup> requires a `value` property.");
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
return Object.assign(Object.assign({}, rest), { inputProps: Object.assign(Object.assign({}, inputProps), {
|
|
33
|
+
return Object.assign(Object.assign({}, rest), { inputProps: Object.assign(Object.assign({}, inputProps), { checked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.value)
|
|
34
34
|
? checkboxGroup.value.includes(props.value)
|
|
35
35
|
: props.checked, defaultChecked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.defaultValue)
|
|
36
36
|
? checkboxGroup.defaultValue.includes(props.value)
|
|
@@ -18,6 +18,11 @@ export interface CheckboxProps extends Omit<FormFieldProps, "errorId">, Omit<Inp
|
|
|
18
18
|
* The value of the HTML element.
|
|
19
19
|
*/
|
|
20
20
|
value?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Specify whether the Checkbox is in an indeterminate state
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
indeterminate?: boolean;
|
|
21
26
|
}
|
|
22
27
|
declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
23
28
|
export default Checkbox;
|
|
@@ -15,7 +15,18 @@ const Checkbox = forwardRef((props, ref) => {
|
|
|
15
15
|
"error",
|
|
16
16
|
"description",
|
|
17
17
|
"hideLabel",
|
|
18
|
-
]), inputProps, { className: "navds-checkbox__input",
|
|
18
|
+
]), inputProps, { type: "checkbox", className: "navds-checkbox__input", "aria-checked": props.indeterminate ? "mixed" : inputProps.checked, ref: (el) => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (el) {
|
|
21
|
+
el.indeterminate = (_a = props.indeterminate) !== null && _a !== void 0 ? _a : false;
|
|
22
|
+
}
|
|
23
|
+
if (typeof ref === "function") {
|
|
24
|
+
ref(el);
|
|
25
|
+
}
|
|
26
|
+
else if (ref != null) {
|
|
27
|
+
ref.current = el;
|
|
28
|
+
}
|
|
29
|
+
} })),
|
|
19
30
|
React.createElement("label", { htmlFor: inputProps.id, className: "navds-checkbox__label" },
|
|
20
31
|
React.createElement("div", { className: cl("navds-checkbox__content", {
|
|
21
32
|
"navds-sr-only": props.hideLabel,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","sourceRoot":"","sources":["../../../src/form/checkbox/Checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAuB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Checkbox.js","sourceRoot":"","sources":["../../../src/form/checkbox/Checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAuB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AA6BhD,MAAM,QAAQ,GAAG,UAAU,CAAkC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAC1E,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAE1D,MAAM,WAAW,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;IAE3D,OAAO,CACL,6BACE,SAAS,EAAE,EAAE,CACX,KAAK,CAAC,SAAS,EACf,gBAAgB,EAChB,mBAAmB,IAAI,EAAE,EACzB;YACE,uBAAuB,EAAE,QAAQ;YACjC,0BAA0B,EAAE,UAAU,CAAC,QAAQ;SAChD,CACF;QAED,+CACM,IAAI,CAAC,KAAK,EAAE;YACd,UAAU;YACV,MAAM;YACN,OAAO;YACP,aAAa;YACb,WAAW;SACZ,CAAC,EACE,UAAU,IACd,IAAI,EAAC,UAAU,EACf,SAAS,EAAC,uBAAuB,kBACnB,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAChE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE;;gBACV,IAAI,EAAE,EAAE;oBACN,EAAE,CAAC,aAAa,GAAG,MAAA,KAAK,CAAC,aAAa,mCAAI,KAAK,CAAC;iBACjD;gBAED,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;oBAC7B,GAAG,CAAC,EAAE,CAAC,CAAC;iBACT;qBAAM,IAAI,GAAG,IAAI,IAAI,EAAE;oBACtB,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC;iBAClB;YACH,CAAC,IACD;QACF,+BAAO,OAAO,EAAE,UAAU,CAAC,EAAE,EAAE,SAAS,EAAC,uBAAuB;YAC9D,6BACE,SAAS,EAAE,EAAE,CAAC,yBAAyB,EAAE;oBACvC,eAAe,EAAE,KAAK,CAAC,SAAS;iBACjC,CAAC;gBAEF,oBAAC,SAAS,IAAC,EAAE,EAAC,KAAK,EAAC,IAAI,EAAE,IAAI,IAC3B,KAAK,CAAC,QAAQ,CACL;gBACX,KAAK,CAAC,WAAW,IAAI,CACpB,oBAAC,WAAW,IACV,EAAE,EAAC,KAAK,EACR,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,6BAA6B,IAEtC,KAAK,CAAC,WAAW,CACN,CACf,CACG,CACA,CACJ,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -28,7 +28,7 @@ const useCheckbox = (_a) => {
|
|
|
28
28
|
console.warn("A <Checkbox> element within a <CheckboxGroup> requires a `value` property.");
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
return Object.assign(Object.assign({}, rest), { inputProps: Object.assign(Object.assign({}, inputProps), {
|
|
31
|
+
return Object.assign(Object.assign({}, rest), { inputProps: Object.assign(Object.assign({}, inputProps), { checked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.value)
|
|
32
32
|
? checkboxGroup.value.includes(props.value)
|
|
33
33
|
: props.checked, defaultChecked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.defaultValue)
|
|
34
34
|
? checkboxGroup.defaultValue.includes(props.value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCheckbox.js","sourceRoot":"","sources":["../../../src/form/checkbox/useCheckbox.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,EAAqC,EAAE,EAAE;QAAzC,EAAE,QAAQ,OAA2B,EAAtB,KAAK,cAApB,YAAsB,CAAF;IACvC,MAAM,aAAa,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEvD,MAAM,KAA0B,YAAY,CAC1C,IAAI,CAAC,KAAK,EAAE,CAAC,aAAa,CAAC,CAAC,EAC5B,UAAU,CACX,EAHK,EAAE,UAAU,OAGjB,EAHsB,IAAI,cAArB,cAAuB,CAG5B,CAAC;IAEF,IAAI,aAAa,EAAE;QACjB,IAAI,KAAK,CAAC,OAAO,EAAE;YACjB,OAAO,CAAC,IAAI,CACV,8IAA8I,CAC/I,CAAC;SACH;QACD,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE;YAC7B,OAAO,CAAC,IAAI,CACV,4EAA4E,CAC7E,CAAC;SACH;KACF;IAED,uCACK,IAAI,KACP,UAAU,k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,CAAC,KAAK,CAAC,KAAe,CAAC;gBAC5D,CAAC,CAAC,KAAK,CAAC,cAAc,EACxB,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;gBACd,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBACpC,aAAa,IAAI,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,KAAe,CAAC,CAAC;YACpE,CAAC,OAEH;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "NAV designsystem react components",
|
|
6
6
|
"author": "NAV Designsystem team",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"@types/react": "^17.0.30",
|
|
65
65
|
"react": "^17.0.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "4ea5face0ca3eaf990d528e9c737595add9c7378"
|
|
68
68
|
}
|
|
@@ -24,6 +24,11 @@ export interface CheckboxProps
|
|
|
24
24
|
* The value of the HTML element.
|
|
25
25
|
*/
|
|
26
26
|
value?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Specify whether the Checkbox is in an indeterminate state
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
indeterminate?: boolean;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {
|
|
@@ -52,8 +57,20 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>((props, ref) => {
|
|
|
52
57
|
"hideLabel",
|
|
53
58
|
])}
|
|
54
59
|
{...inputProps}
|
|
60
|
+
type="checkbox"
|
|
55
61
|
className="navds-checkbox__input"
|
|
56
|
-
|
|
62
|
+
aria-checked={props.indeterminate ? "mixed" : inputProps.checked}
|
|
63
|
+
ref={(el) => {
|
|
64
|
+
if (el) {
|
|
65
|
+
el.indeterminate = props.indeterminate ?? false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof ref === "function") {
|
|
69
|
+
ref(el);
|
|
70
|
+
} else if (ref != null) {
|
|
71
|
+
ref.current = el;
|
|
72
|
+
}
|
|
73
|
+
}}
|
|
57
74
|
/>
|
|
58
75
|
<label htmlFor={inputProps.id} className="navds-checkbox__label">
|
|
59
76
|
<div
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
import { Checkbox, CheckboxGroup } from "../../index";
|
|
3
3
|
import { Meta } from "@storybook/react/types-6-0";
|
|
4
4
|
export default {
|
|
@@ -6,6 +6,36 @@ export default {
|
|
|
6
6
|
component: Checkbox,
|
|
7
7
|
} as Meta;
|
|
8
8
|
|
|
9
|
+
export const Indeterminate = () => {
|
|
10
|
+
const [checked, setChecked] = useState([true, false]);
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<>
|
|
14
|
+
<Checkbox
|
|
15
|
+
checked={checked[0] && checked[1]}
|
|
16
|
+
indeterminate={checked[0] !== checked[1]}
|
|
17
|
+
onChange={(e) => setChecked([e.target.checked, e.target.checked])}
|
|
18
|
+
>
|
|
19
|
+
Parent
|
|
20
|
+
</Checkbox>
|
|
21
|
+
<div style={{ paddingLeft: "2rem" }}>
|
|
22
|
+
<Checkbox
|
|
23
|
+
checked={checked[0]}
|
|
24
|
+
onChange={(e) => setChecked([e.target.checked, checked[1]])}
|
|
25
|
+
>
|
|
26
|
+
Child 1
|
|
27
|
+
</Checkbox>
|
|
28
|
+
<Checkbox
|
|
29
|
+
checked={checked[1]}
|
|
30
|
+
onChange={(e) => setChecked([checked[0], e.target.checked])}
|
|
31
|
+
>
|
|
32
|
+
Child 2
|
|
33
|
+
</Checkbox>
|
|
34
|
+
</div>
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
9
39
|
export const All = () => {
|
|
10
40
|
const Checkboxes = (props) => (
|
|
11
41
|
<CheckboxGroup
|
|
@@ -51,6 +81,13 @@ export const All = () => {
|
|
|
51
81
|
<Checkbox value="Orange" description="Laborum ad" disabled defaultChecked>
|
|
52
82
|
Orange
|
|
53
83
|
</Checkbox>
|
|
84
|
+
<h3>Indeterminate</h3>
|
|
85
|
+
<Checkbox value="Apple" indeterminate>
|
|
86
|
+
Apple
|
|
87
|
+
</Checkbox>
|
|
88
|
+
<Checkbox value="Orange" indeterminate size="small">
|
|
89
|
+
Orange
|
|
90
|
+
</Checkbox>
|
|
54
91
|
|
|
55
92
|
<h2>Checkbox group</h2>
|
|
56
93
|
<Checkboxes />
|