@navikt/ds-react 0.16.12 → 0.16.13

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.
@@ -42,9 +42,9 @@ const CheckboxGroup = (0, react_1.forwardRef)((_a, ref) => {
42
42
  var _b, _c;
43
43
  var { value, defaultValue, onChange = () => { }, children, className } = _a, rest = __rest(_a, ["value", "defaultValue", "onChange", "children", "className"]);
44
44
  const fieldset = (0, react_1.useContext)(__1.FieldsetContext);
45
- const [state, setState] = (0, react_1.useState)([]);
46
- const handleChange = (v) => {
47
- const newValue = value ? value : state;
45
+ const [state, setState] = (0, react_1.useState)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : []);
46
+ const toggleValue = (v) => {
47
+ const newValue = value !== null && value !== void 0 ? value : state;
48
48
  const newState = newValue.includes(v)
49
49
  ? newValue.filter((x) => x !== v)
50
50
  : [...newValue, v];
@@ -55,7 +55,7 @@ const CheckboxGroup = (0, react_1.forwardRef)((_a, ref) => {
55
55
  react_1.default.createElement(exports.CheckboxGroupContext.Provider, { value: {
56
56
  value,
57
57
  defaultValue,
58
- toggleValue: (value) => handleChange(value),
58
+ toggleValue,
59
59
  } },
60
60
  react_1.default.createElement("div", { className: "navds-checkboxes" }, children))));
61
61
  });
@@ -30,13 +30,14 @@ const useCheckbox = (_a) => {
30
30
  console.warn("A <Checkbox> element within a <CheckboxGroup> requires a `value` property.");
31
31
  }
32
32
  }
33
+ const value = props.value;
33
34
  return Object.assign(Object.assign({}, rest), { inputProps: Object.assign(Object.assign({}, inputProps), { checked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.value)
34
- ? checkboxGroup.value.includes(props.value)
35
+ ? checkboxGroup.value.includes(value)
35
36
  : props.checked, defaultChecked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.defaultValue)
36
- ? checkboxGroup.defaultValue.includes(props.value)
37
+ ? checkboxGroup.defaultValue.includes(value)
37
38
  : props.defaultChecked, onChange: (e) => {
38
39
  props.onChange && props.onChange(e);
39
- checkboxGroup && checkboxGroup.toggleValue(props.value);
40
+ checkboxGroup && checkboxGroup.toggleValue(value);
40
41
  } }) });
41
42
  };
42
43
  exports.default = useCheckbox;
@@ -1,6 +1,6 @@
1
1
  import React, { InputHTMLAttributes } from "react";
2
2
  import { FormFieldProps } from "../useFormField";
3
- export interface CheckboxProps extends Omit<FormFieldProps, "errorId">, Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
3
+ export interface CheckboxProps extends Omit<FormFieldProps, "errorId">, Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "value"> {
4
4
  /**
5
5
  * Checkbox has error
6
6
  * @default false
@@ -17,7 +17,7 @@ export interface CheckboxProps extends Omit<FormFieldProps, "errorId">, Omit<Inp
17
17
  /**
18
18
  * The value of the HTML element.
19
19
  */
20
- value?: string;
20
+ value?: string | number | boolean;
21
21
  /**
22
22
  * Specify whether the Checkbox is in an indeterminate state
23
23
  * @default false
@@ -1,12 +1,12 @@
1
1
  import React from "react";
2
2
  import { FieldsetProps } from "..";
3
3
  export interface CheckboxGroupState {
4
- readonly defaultValue?: readonly string[];
5
- readonly value?: readonly string[];
6
- toggleValue(value: string): void;
4
+ readonly defaultValue?: ReadonlyArray<string | number | boolean>;
5
+ readonly value?: ReadonlyArray<string | number | boolean>;
6
+ toggleValue(value: string | number | boolean): void;
7
7
  }
8
8
  export declare const CheckboxGroupContext: React.Context<CheckboxGroupState | null>;
9
- export interface CheckboxGroupProps extends Omit<FieldsetProps, "onChange" | "errorPropagation"> {
9
+ export interface CheckboxGroupProps extends Omit<FieldsetProps, "onChange" | "errorPropagation" | "defaultValue"> {
10
10
  /**
11
11
  * Checkboxes
12
12
  */
@@ -14,15 +14,15 @@ export interface CheckboxGroupProps extends Omit<FieldsetProps, "onChange" | "er
14
14
  /**
15
15
  * Controlled state for group
16
16
  */
17
- value?: string[];
17
+ value?: Array<string | number | boolean>;
18
18
  /**
19
19
  * Default checked checkboxes on render
20
20
  */
21
- defaultValue?: string[];
21
+ defaultValue?: Array<string | number | boolean>;
22
22
  /**
23
23
  * Returns current checked checkboxes in group
24
24
  */
25
- onChange?: (value: string[]) => void;
25
+ onChange?: (value: Array<string | number | boolean>) => void;
26
26
  }
27
27
  declare const CheckboxGroup: React.ForwardRefExoticComponent<CheckboxGroupProps & React.RefAttributes<HTMLFieldSetElement>>;
28
28
  export default CheckboxGroup;
@@ -17,9 +17,9 @@ const CheckboxGroup = forwardRef((_a, ref) => {
17
17
  var _b, _c;
18
18
  var { value, defaultValue, onChange = () => { }, children, className } = _a, rest = __rest(_a, ["value", "defaultValue", "onChange", "children", "className"]);
19
19
  const fieldset = useContext(FieldsetContext);
20
- const [state, setState] = useState([]);
21
- const handleChange = (v) => {
22
- const newValue = value ? value : state;
20
+ const [state, setState] = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : []);
21
+ const toggleValue = (v) => {
22
+ const newValue = value !== null && value !== void 0 ? value : state;
23
23
  const newState = newValue.includes(v)
24
24
  ? newValue.filter((x) => x !== v)
25
25
  : [...newValue, v];
@@ -30,7 +30,7 @@ const CheckboxGroup = forwardRef((_a, ref) => {
30
30
  React.createElement(CheckboxGroupContext.Provider, { value: {
31
31
  value,
32
32
  defaultValue,
33
- toggleValue: (value) => handleChange(value),
33
+ toggleValue,
34
34
  } },
35
35
  React.createElement("div", { className: "navds-checkboxes" }, children))));
36
36
  });
@@ -1 +1 @@
1
- {"version":3,"file":"CheckboxGroup.js","sourceRoot":"","sources":["../../../src/form/checkbox/CheckboxGroup.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/E,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAiB,eAAe,EAAE,MAAM,IAAI,CAAC;AAQ9D,MAAM,CAAC,MAAM,oBAAoB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QAAQ,EAAE,CAAC,CAAC,CAAC;QAErB,KAAK,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC1C,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC,CAAC;IAEF,OAAO,CACL,oBAAC,QAAQ,oBACH,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,SAAS,EACT,sBAAsB,EACtB,yBAAyB,MAAA,MAAA,IAAI,CAAC,IAAI,mCAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,mCAAI,QAAQ,EAAE,CACnE;QAED,oBAAC,oBAAoB,CAAC,QAAQ,IAC5B,KAAK,EAAE;gBACL,KAAK;gBACL,YAAY;gBACZ,WAAW;aACZ;YAED,6BAAK,SAAS,EAAC,kBAAkB,IAAE,QAAQ,CAAO,CACpB,CACvB,CACZ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -28,13 +28,14 @@ const useCheckbox = (_a) => {
28
28
  console.warn("A <Checkbox> element within a <CheckboxGroup> requires a `value` property.");
29
29
  }
30
30
  }
31
+ const value = props.value;
31
32
  return Object.assign(Object.assign({}, rest), { inputProps: Object.assign(Object.assign({}, inputProps), { checked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.value)
32
- ? checkboxGroup.value.includes(props.value)
33
+ ? checkboxGroup.value.includes(value)
33
34
  : props.checked, defaultChecked: (checkboxGroup === null || checkboxGroup === void 0 ? void 0 : checkboxGroup.defaultValue)
34
- ? checkboxGroup.defaultValue.includes(props.value)
35
+ ? checkboxGroup.defaultValue.includes(value)
35
36
  : props.defaultChecked, onChange: (e) => {
36
37
  props.onChange && props.onChange(e);
37
- checkboxGroup && checkboxGroup.toggleValue(props.value);
38
+ checkboxGroup && checkboxGroup.toggleValue(value);
38
39
  } }) });
39
40
  };
40
41
  export default useCheckbox;
@@ -1 +1 @@
1
- {"version":3,"file":"useChe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AU,KACb,OAAO,EAAE,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,KAAK;gBAC3B,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;gBACrC,CAAC,CAAC,KAAK,CAAC,OAAO,EACjB,cAAc,EAAE,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,YAAY;gBACzC,CAAC,CAAC,aAAa,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC;gBAC5C,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,CAAC;YACpD,CAAC,OAEH;AACJ,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import React, { InputHTMLAttributes } from "react";
2
2
  import { FormFieldProps } from "../useFormField";
3
- export interface RadioProps extends Omit<FormFieldProps, "error" | "errorId">, Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
3
+ export interface RadioProps extends Omit<FormFieldProps, "error" | "errorId">, Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "value"> {
4
4
  /**
5
5
  * Label for radio
6
6
  */
@@ -8,7 +8,7 @@ export interface RadioProps extends Omit<FormFieldProps, "error" | "errorId">, O
8
8
  /**
9
9
  * The value of the HTML element
10
10
  */
11
- value: string;
11
+ value: string | number | boolean;
12
12
  }
13
13
  declare const Radio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLInputElement>>;
14
14
  export default Radio;
@@ -2,13 +2,13 @@ import React from "react";
2
2
  import { FieldsetProps } from "..";
3
3
  export interface RadioGroupContextProps {
4
4
  name: string;
5
- defaultValue?: string;
6
- value?: string;
7
- onChange: (value: string) => void;
5
+ defaultValue?: string | number | boolean;
6
+ value?: string | number | boolean;
7
+ onChange: (value: string | number | boolean) => void;
8
8
  required?: boolean;
9
9
  }
10
10
  export declare const RadioGroupContext: React.Context<RadioGroupContextProps | null>;
11
- export interface RadioGroupProps extends Omit<FieldsetProps, "onChange" | "errorPropagation"> {
11
+ export interface RadioGroupProps extends Omit<FieldsetProps, "onChange" | "errorPropagation" | "defaultValue"> {
12
12
  /**
13
13
  * Collection of <Radio>-elements
14
14
  */
@@ -20,15 +20,15 @@ export interface RadioGroupProps extends Omit<FieldsetProps, "onChange" | "error
20
20
  /**
21
21
  * Default checked radiobutton
22
22
  */
23
- defaultValue?: string;
23
+ defaultValue?: string | number | boolean;
24
24
  /**
25
25
  * Controlled state for Radiobutton
26
26
  */
27
- value?: string;
27
+ value?: string | number | boolean;
28
28
  /**
29
29
  * Returns current checked radiobutton in group
30
30
  */
31
- onChange?: (value: string) => void;
31
+ onChange?: (value: string | number | boolean) => void;
32
32
  /**
33
33
  * Tells Fieldset if group is required
34
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["../../../src/form/radio/RadioGroup.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAiB,MAAM,IAAI,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAU9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,aAAa,CAClD,IAAI,CACL,CAAC;AA8BF,MAAM,UAAU,GAAG,UAAU,CAC3B,CACE,EASC,EACD,GAAG,EACH,EAAE;;QAXF,EACE,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,QAAQ,GAAG,GAAG,EAAE,GAAE,CAAC,EACnB,QAAQ,OAET,EADI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AE,GAAE,CAAC,EACnB,QAAQ,OAET,EADI,IAAI,cART,kFASC,CADQ;IAIT,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE7C,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC;IAEvB,OAAO,CACL,oBAAC,QAAQ,oBACH,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,SAAS,EACT,mBAAmB,EACnB,sBAAsB,MAAA,MAAA,IAAI,CAAC,IAAI,mCAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,mCAAI,QAAQ,EAAE,CAChE;QAED,oBAAC,iBAAiB,CAAC,QAAQ,IACzB,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,kBAAkB,MAAM,EAAE;gBACxC,YAAY;gBACZ,KAAK;gBACL,QAAQ;gBACR,QAAQ;aACT;YAED,6BAAK,SAAS,EAAC,qBAAqB,IAAE,QAAQ,CAAO,CAC1B,CACpB,CACZ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.16.12",
3
+ "version": "0.16.13",
4
4
  "private": false,
5
5
  "description": "NAV designsystem react components",
6
6
  "author": "NAV Designsystem team",
@@ -65,5 +65,5 @@
65
65
  "@types/react": "^17.0.30",
66
66
  "react": "^17.0.0"
67
67
  },
68
- "gitHead": "8f99813590a93d55b4f06f6c1129da169a72fa58"
68
+ "gitHead": "537cdd3defb3a317fdaab250fa578272c6f2f58e"
69
69
  }
@@ -6,7 +6,7 @@ import { BodyShort, Detail, omit } from "../..";
6
6
 
7
7
  export interface CheckboxProps
8
8
  extends Omit<FormFieldProps, "errorId">,
9
- Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
9
+ Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "value"> {
10
10
  /**
11
11
  * Checkbox has error
12
12
  * @default false
@@ -23,7 +23,7 @@ export interface CheckboxProps
23
23
  /**
24
24
  * The value of the HTML element.
25
25
  */
26
- value?: string;
26
+ value?: string | number | boolean;
27
27
  /**
28
28
  * Specify whether the Checkbox is in an indeterminate state
29
29
  * @default false
@@ -3,9 +3,9 @@ import cl from "classnames";
3
3
  import { Fieldset, FieldsetProps, FieldsetContext } from "..";
4
4
 
5
5
  export interface CheckboxGroupState {
6
- readonly defaultValue?: readonly string[];
7
- readonly value?: readonly string[];
8
- toggleValue(value: string): void;
6
+ readonly defaultValue?: ReadonlyArray<string | number | boolean>;
7
+ readonly value?: ReadonlyArray<string | number | boolean>;
8
+ toggleValue(value: string | number | boolean): void;
9
9
  }
10
10
 
11
11
  export const CheckboxGroupContext = createContext<CheckboxGroupState | null>(
@@ -13,7 +13,10 @@ export const CheckboxGroupContext = createContext<CheckboxGroupState | null>(
13
13
  );
14
14
 
15
15
  export interface CheckboxGroupProps
16
- extends Omit<FieldsetProps, "onChange" | "errorPropagation"> {
16
+ extends Omit<
17
+ FieldsetProps,
18
+ "onChange" | "errorPropagation" | "defaultValue"
19
+ > {
17
20
  /**
18
21
  * Checkboxes
19
22
  */
@@ -21,15 +24,15 @@ export interface CheckboxGroupProps
21
24
  /**
22
25
  * Controlled state for group
23
26
  */
24
- value?: string[];
27
+ value?: Array<string | number | boolean>;
25
28
  /**
26
29
  * Default checked checkboxes on render
27
30
  */
28
- defaultValue?: string[];
31
+ defaultValue?: Array<string | number | boolean>;
29
32
  /**
30
33
  * Returns current checked checkboxes in group
31
34
  */
32
- onChange?: (value: string[]) => void;
35
+ onChange?: (value: Array<string | number | boolean>) => void;
33
36
  }
34
37
 
35
38
  const CheckboxGroup = forwardRef<HTMLFieldSetElement, CheckboxGroupProps>(
@@ -39,10 +42,12 @@ const CheckboxGroup = forwardRef<HTMLFieldSetElement, CheckboxGroupProps>(
39
42
  ) => {
40
43
  const fieldset = useContext(FieldsetContext);
41
44
 
42
- const [state, setState] = useState<string[]>([]);
45
+ const [state, setState] = useState<Array<string | number | boolean>>(
46
+ defaultValue ?? []
47
+ );
43
48
 
44
- const handleChange = (v: string) => {
45
- const newValue = value ? value : state;
49
+ const toggleValue = (v: string | number | boolean) => {
50
+ const newValue = value ?? state;
46
51
  const newState = newValue.includes(v)
47
52
  ? newValue.filter((x) => x !== v)
48
53
  : [...newValue, v];
@@ -65,7 +70,7 @@ const CheckboxGroup = forwardRef<HTMLFieldSetElement, CheckboxGroupProps>(
65
70
  value={{
66
71
  value,
67
72
  defaultValue,
68
- toggleValue: (value: string) => handleChange(value),
73
+ toggleValue,
69
74
  }}
70
75
  >
71
76
  <div className="navds-checkboxes">{children}</div>
@@ -1,6 +1,7 @@
1
1
  import React, { useState } from "react";
2
2
  import { Checkbox, CheckboxGroup } from "../../index";
3
3
  import { Meta } from "@storybook/react/types-6-0";
4
+ import { CheckboxGroupProps } from "..";
4
5
  export default {
5
6
  title: "ds-react/form/checkbox",
6
7
  component: Checkbox,
@@ -37,13 +38,15 @@ export const Indeterminate = () => {
37
38
  };
38
39
 
39
40
  export const All = () => {
40
- const Checkboxes = (props) => (
41
+ const Checkboxes = (
42
+ props: Omit<CheckboxGroupProps, "legend" | "description" | "children">
43
+ ) => (
41
44
  <CheckboxGroup
42
45
  legend="Mollit eiusmod"
43
46
  description="Exercitation do labore"
44
47
  {...props}
45
48
  >
46
- <Checkbox value="Apple">Apple</Checkbox>
49
+ <Checkbox value={1}>Apple</Checkbox>
47
50
  <Checkbox value="Orange" description="Laborum ad">
48
51
  Orange
49
52
  </Checkbox>
@@ -60,7 +63,7 @@ export const All = () => {
60
63
  <h2>Single checkbox</h2>
61
64
  <Checkbox value="Apple">Apple</Checkbox>
62
65
  <h3>Desription</h3>
63
- <Checkbox value="Apple" description="Laborum ad" defaultChecked>
66
+ <Checkbox value={1} description="Laborum ad" defaultChecked>
64
67
  Apple
65
68
  </Checkbox>
66
69
  <h3>Error</h3>
@@ -98,7 +101,7 @@ export const All = () => {
98
101
  <h3>Small + error</h3>
99
102
  <Checkboxes size="small" error="Dette er en feilmelding" />
100
103
  <h3>Default value</h3>
101
- <Checkboxes defaultValue={["Orange", "Melon"]} />
104
+ <Checkboxes defaultValue={[1, "Melon"]} />
102
105
  <h3>Disabled</h3>
103
106
  <Checkboxes disabled />
104
107
  </>
@@ -28,19 +28,21 @@ const useCheckbox = ({ children, ...props }: CheckboxProps) => {
28
28
  }
29
29
  }
30
30
 
31
+ const value = props.value as string | number | boolean;
32
+
31
33
  return {
32
34
  ...rest,
33
35
  inputProps: {
34
36
  ...inputProps,
35
37
  checked: checkboxGroup?.value
36
- ? checkboxGroup.value.includes(props.value as string)
38
+ ? checkboxGroup.value.includes(value)
37
39
  : props.checked,
38
40
  defaultChecked: checkboxGroup?.defaultValue
39
- ? checkboxGroup.defaultValue.includes(props.value as string)
41
+ ? checkboxGroup.defaultValue.includes(value)
40
42
  : props.defaultChecked,
41
43
  onChange: (e) => {
42
44
  props.onChange && props.onChange(e);
43
- checkboxGroup && checkboxGroup.toggleValue(props.value as string);
45
+ checkboxGroup && checkboxGroup.toggleValue(value);
44
46
  },
45
47
  },
46
48
  };
@@ -6,7 +6,7 @@ import { useRadio } from "./useRadio";
6
6
 
7
7
  export interface RadioProps
8
8
  extends Omit<FormFieldProps, "error" | "errorId">,
9
- Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
9
+ Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "value"> {
10
10
  /**
11
11
  * Label for radio
12
12
  */
@@ -14,7 +14,7 @@ export interface RadioProps
14
14
  /**
15
15
  * The value of the HTML element
16
16
  */
17
- value: string;
17
+ value: string | number | boolean;
18
18
  }
19
19
 
20
20
  const Radio = forwardRef<HTMLInputElement, RadioProps>((props, ref) => {
@@ -5,9 +5,9 @@ import { useId } from "../..";
5
5
 
6
6
  export interface RadioGroupContextProps {
7
7
  name: string;
8
- defaultValue?: string;
9
- value?: string;
10
- onChange: (value: string) => void;
8
+ defaultValue?: string | number | boolean;
9
+ value?: string | number | boolean;
10
+ onChange: (value: string | number | boolean) => void;
11
11
  required?: boolean;
12
12
  }
13
13
 
@@ -16,7 +16,10 @@ export const RadioGroupContext = React.createContext<RadioGroupContextProps | nu
16
16
  );
17
17
 
18
18
  export interface RadioGroupProps
19
- extends Omit<FieldsetProps, "onChange" | "errorPropagation"> {
19
+ extends Omit<
20
+ FieldsetProps,
21
+ "onChange" | "errorPropagation" | "defaultValue"
22
+ > {
20
23
  /**
21
24
  * Collection of <Radio>-elements
22
25
  */
@@ -28,15 +31,15 @@ export interface RadioGroupProps
28
31
  /**
29
32
  * Default checked radiobutton
30
33
  */
31
- defaultValue?: string;
34
+ defaultValue?: string | number | boolean;
32
35
  /**
33
36
  * Controlled state for Radiobutton
34
37
  */
35
- value?: string;
38
+ value?: string | number | boolean;
36
39
  /**
37
40
  * Returns current checked radiobutton in group
38
41
  */
39
- onChange?: (value: string) => void;
42
+ onChange?: (value: string | number | boolean) => void;
40
43
  /**
41
44
  * Tells Fieldset if group is required
42
45
  */
@@ -1,23 +1,21 @@
1
1
  import React from "react";
2
2
  import { Meta } from "@storybook/react/types-6-0";
3
3
  import { RadioGroup, Radio } from "../index";
4
+ import { RadioGroupProps } from "../RadioGroup";
4
5
  export default {
5
6
  title: "ds-react/form/radio",
6
7
  component: RadioGroup,
7
8
  } as Meta;
8
9
 
9
10
  export const All = () => {
10
- const Radios = (props) => (
11
+ const Radios = (props: Omit<RadioGroupProps, "legend" | "children">) => (
11
12
  <RadioGroup
12
13
  legend="Mollit eiusmod"
13
14
  description={<div>"Exercitation do labore"</div>}
14
15
  {...props}
15
16
  >
16
- <Radio value="Apple">Apple</Radio>
17
- <Radio value="Orange" description="Laborum ad">
18
- Orange
19
- </Radio>
20
- <Radio value="Orange" description={<div>Laborum ad</div>}>
17
+ <Radio value={1}>Apple</Radio>
18
+ <Radio value={false} description={<div>Laborum ad</div>}>
21
19
  Orange
22
20
  </Radio>
23
21
  <Radio value="Melon">Melon</Radio>
@@ -35,13 +33,13 @@ export const All = () => {
35
33
  <h2>Small + error</h2>
36
34
  <Radios size="small" error="Dette er en feilmelding" />
37
35
  <h2>Default value</h2>
38
- <Radios defaultValue="Orange" />
36
+ <Radios defaultValue={1} />
39
37
  <h2>Disabled</h2>
40
38
  <RadioGroup legend="Mollit eiusmod" description="Exercitation do labore">
41
39
  <Radio value="Apple" disabled>
42
40
  Apple
43
41
  </Radio>
44
- <Radio value="Orange" description="Laborum ad" disabled>
42
+ <Radio value={false} description="Laborum ad" disabled>
45
43
  Orange
46
44
  </Radio>
47
45
  <Radio value="Melon">Melon</Radio>