@navikt/ds-react 0.16.9 → 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.
Files changed (43) hide show
  1. package/cjs/form/checkbox/CheckboxGroup.js +4 -4
  2. package/cjs/form/checkbox/useCheckbox.js +4 -3
  3. package/cjs/index.js +1 -0
  4. package/cjs/pagination/Pagination.js +71 -0
  5. package/cjs/pagination/index.js +19 -0
  6. package/cjs/pagination/package.json +6 -0
  7. package/cjs/toggle-group/ToggleGroup.js +4 -1
  8. package/esm/form/checkbox/Checkbox.d.ts +2 -2
  9. package/esm/form/checkbox/CheckboxGroup.d.ts +7 -7
  10. package/esm/form/checkbox/CheckboxGroup.js +4 -4
  11. package/esm/form/checkbox/CheckboxGroup.js.map +1 -1
  12. package/esm/form/checkbox/useCheckbox.js +4 -3
  13. package/esm/form/checkbox/useCheckbox.js.map +1 -1
  14. package/esm/form/radio/Radio.d.ts +2 -2
  15. package/esm/form/radio/RadioGroup.d.ts +7 -7
  16. package/esm/form/radio/RadioGroup.js.map +1 -1
  17. package/esm/index.d.ts +1 -0
  18. package/esm/index.js +1 -0
  19. package/esm/index.js.map +1 -1
  20. package/esm/modal/Modal.d.ts +1 -1
  21. package/esm/pagination/Pagination.d.ts +43 -0
  22. package/esm/pagination/Pagination.js +65 -0
  23. package/esm/pagination/Pagination.js.map +1 -0
  24. package/esm/pagination/index.d.ts +2 -0
  25. package/esm/pagination/index.js +3 -0
  26. package/esm/pagination/index.js.map +1 -0
  27. package/esm/toggle-group/ToggleGroup.js +4 -1
  28. package/esm/toggle-group/ToggleGroup.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/form/checkbox/Checkbox.tsx +2 -2
  31. package/src/form/checkbox/CheckboxGroup.tsx +16 -11
  32. package/src/form/checkbox/stories/checkbox.stories.tsx +7 -4
  33. package/src/form/checkbox/useCheckbox.ts +5 -3
  34. package/src/form/radio/Radio.tsx +2 -2
  35. package/src/form/radio/RadioGroup.tsx +10 -7
  36. package/src/form/radio/stories/radio.stories.tsx +6 -8
  37. package/src/index.ts +1 -0
  38. package/src/modal/Modal.tsx +1 -1
  39. package/src/pagination/Pagination.tsx +191 -0
  40. package/src/pagination/index.ts +2 -0
  41. package/src/pagination/pagination.stories.tsx +37 -0
  42. package/src/pagination/steps.test.ts +120 -0
  43. package/src/toggle-group/ToggleGroup.tsx +5 -0
@@ -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;
package/cjs/index.js CHANGED
@@ -22,6 +22,7 @@ __exportStar(require("./link-panel"), exports);
22
22
  __exportStar(require("./loader"), exports);
23
23
  __exportStar(require("./menu"), exports);
24
24
  __exportStar(require("./modal"), exports);
25
+ __exportStar(require("./pagination"), exports);
25
26
  __exportStar(require("./panel"), exports);
26
27
  __exportStar(require("./popover"), exports);
27
28
  __exportStar(require("./speech-bubble"), exports);
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSteps = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const classnames_1 = __importDefault(require("classnames"));
9
+ const ds_icons_1 = require("@navikt/ds-icons");
10
+ const __1 = require("..");
11
+ const getSteps = ({ page, count, boundaryCount = 1, siblingCount = 1, }) => {
12
+ var _a, _b;
13
+ const range = (start, end) => Array.from({ length: end - start + 1 }, (_, i) => start + i);
14
+ if (count <= (boundaryCount + siblingCount) * 2 + 3)
15
+ return range(1, count);
16
+ const startPages = range(1, boundaryCount);
17
+ const endPages = range(count - boundaryCount + 1, count);
18
+ const siblingsStart = Math.max(Math.min(page - siblingCount, count - boundaryCount - siblingCount * 2 - 1), boundaryCount + 2);
19
+ const siblingsEnd = siblingsStart + siblingCount * 2;
20
+ return [
21
+ ...startPages,
22
+ siblingsStart - ((_a = startPages[startPages.length - 1]) !== null && _a !== void 0 ? _a : 0) === 2
23
+ ? siblingsStart - 1
24
+ : "ellipsis",
25
+ ...range(siblingsStart, siblingsEnd),
26
+ ((_b = endPages[0]) !== null && _b !== void 0 ? _b : count + 1) - siblingsEnd === 2
27
+ ? siblingsEnd + 1
28
+ : "ellipsis",
29
+ ...endPages,
30
+ ];
31
+ };
32
+ exports.getSteps = getSteps;
33
+ const Pagination = ({ page, onPageChange, count, boundaryCount = 1, siblingCount = 1, className, size = "medium", prevNextTexts = false, }) => {
34
+ if (page < 1) {
35
+ console.error("page cannot be less than 1");
36
+ return null;
37
+ }
38
+ if (count < 1) {
39
+ console.error("count cannot be less than 1");
40
+ return null;
41
+ }
42
+ if (boundaryCount < 0) {
43
+ console.error("boundaryCount cannot be less than 0");
44
+ return null;
45
+ }
46
+ if (siblingCount < 0) {
47
+ console.error("siblingCount cannot be less than 0");
48
+ return null;
49
+ }
50
+ return (react_1.default.createElement("nav", { className: (0, classnames_1.default)("navds-pagination", `navds-pagination--${size}`, className) },
51
+ prevNextTexts && (react_1.default.createElement("button", { className: "navds-pagination__prev-next", disabled: page === 1, onClick: () => onPageChange(page - 1) },
52
+ react_1.default.createElement(ds_icons_1.Back, { className: "navds-pagination__prev-next-icon", role: "presentation" }),
53
+ react_1.default.createElement(__1.BodyShort, { size: size, className: "navds-pagination__prev-text" }, "Tilbake"))),
54
+ react_1.default.createElement("ul", { className: "navds-pagination__list" },
55
+ !prevNextTexts && (react_1.default.createElement("li", null,
56
+ react_1.default.createElement("button", { className: "navds-pagination__prev-next", disabled: page === 1, onClick: () => onPageChange(page - 1) },
57
+ react_1.default.createElement(ds_icons_1.Back, { className: "navds-pagination__prev-next-icon", title: "Tilbake" })))),
58
+ (0, exports.getSteps)({ page, count, siblingCount, boundaryCount }).map((step, i) => {
59
+ const n = Number(step);
60
+ return isNaN(n) ? (react_1.default.createElement("li", { className: "navds-pagination__ellipsis", key: `${step}${i}` },
61
+ react_1.default.createElement(__1.BodyShort, { size: size }, "..."))) : (react_1.default.createElement("li", { key: step },
62
+ react_1.default.createElement(__1.BodyShort, { size: size, as: "button", className: "navds-pagination__item", onClick: () => onPageChange(n), "aria-current": page === n ? true : undefined }, n)));
63
+ }),
64
+ !prevNextTexts && (react_1.default.createElement("li", null,
65
+ react_1.default.createElement("button", { className: "navds-pagination__prev-next", disabled: page === count, onClick: () => onPageChange(page + 1) },
66
+ react_1.default.createElement(ds_icons_1.Next, { className: "navds-pagination__prev-next-icon", title: "Neste" }))))),
67
+ prevNextTexts && (react_1.default.createElement("button", { className: "navds-pagination__prev-next", disabled: page === count, onClick: () => onPageChange(page + 1) },
68
+ react_1.default.createElement(__1.BodyShort, { size: size, className: "navds-pagination__next-text" }, "Neste"),
69
+ react_1.default.createElement(ds_icons_1.Next, { className: "navds-pagination__prev-next-icon", role: "presentation" })))));
70
+ };
71
+ exports.default = Pagination;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Pagination = void 0;
17
+ var Pagination_1 = require("./Pagination");
18
+ Object.defineProperty(exports, "Pagination", { enumerable: true, get: function () { return __importDefault(Pagination_1).default; } });
19
+ __exportStar(require("./Pagination"), exports);
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "main": "./index.js",
4
+ "module": "../../esm/pagination/index.js",
5
+ "types": "../../esm/pagination/index.d.ts"
6
+ }
@@ -57,12 +57,15 @@ const ToggleGroup = (0, react_1.forwardRef)((_a, ref) => {
57
57
  [desc !== null && desc !== void 0 ? desc : ""]: !!desc,
58
58
  [labelId]: !!label,
59
59
  });
60
+ if (!value && !defaultValue) {
61
+ console.error("ToggleGroup needs either a value or defaultValue");
62
+ }
60
63
  return (react_1.default.createElement(exports.ToggleGroupContext.Provider, { value: {
61
64
  size,
62
65
  } },
63
66
  react_1.default.createElement("div", null,
64
67
  label && (react_1.default.createElement(__1.Label, { size: size, className: "navds-toggle-group__label", id: labelId }, label)),
65
- react_1.default.createElement(RadixToggleGroup.Root, Object.assign({}, rest, { onValueChange: handleValueChange, value: value !== null && value !== void 0 ? value : groupValue, defaultValue: defaultValue, ref: ref, className: (0, classnames_1.default)("navds-toggle-group", className, `navds-toggle-group--${size}`) }, (describeBy && { "aria-describedby": describeBy }), { type: "single" }), children))));
68
+ react_1.default.createElement(RadixToggleGroup.Root, Object.assign({}, rest, { onValueChange: handleValueChange, value: value !== null && value !== void 0 ? value : groupValue, defaultValue: defaultValue, ref: ref, className: (0, classnames_1.default)("navds-toggle-group", className, `navds-toggle-group--${size}`) }, (describeBy && { "aria-describedby": describeBy }), { role: "toolbar", type: "single" }), children))));
66
69
  });
67
70
  ToggleGroup.Item = ToggleItem_1.default;
68
71
  exports.default = ToggleGroup;
@@ -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,GAAG,aAAa,CAC/C,IAAI,CACL,CAAC;AAsBF,MAAM,aAAa,GAAG,UAAU,CAC9B,CACE,EAA0E,EAC1E,GAAG,EACH,EAAE;;QAFF,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,GAAG,GAAG,EAAE,GAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,OAAW,EAAN,IAAI,cAAxE,8DAA0E,CAAF;IAGxE,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAC;IAEjD,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE;QACjC,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QACvC,MAAM,QAAQ,GAAG,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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":"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,UAA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ACJ,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,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;YA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AK;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/esm/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./link-panel";
10
10
  export * from "./loader";
11
11
  export * from "./menu";
12
12
  export * from "./modal";
13
+ export * from "./pagination";
13
14
  export * from "./panel";
14
15
  export * from "./popover";
15
16
  export * from "./speech-bubble";
package/esm/index.js CHANGED
@@ -10,6 +10,7 @@ export * from "./link-panel";
10
10
  export * from "./loader";
11
11
  export * from "./menu";
12
12
  export * from "./modal";
13
+ export * from "./pagination";
13
14
  export * from "./panel";
14
15
  export * from "./popover";
15
16
  export * from "./speech-bubble";
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AAEvB,6BAA6B;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AAEvB,6BAA6B;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import ReactModal from "react-modal";
3
3
  import { ModalContentType } from "./ModalContent";
4
- export interface ModalProps extends ReactModal {
4
+ export interface ModalProps {
5
5
  /**
6
6
  * Modal content
7
7
  */
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ interface PaginationProps extends React.HTMLAttributes<HTMLElement> {
3
+ /**
4
+ * Current page
5
+ */
6
+ page: number;
7
+ /**
8
+ * Number of always visible pages before and after the current page.
9
+ * @default 1
10
+ */
11
+ siblingCount?: number;
12
+ /**
13
+ * Number of always visible pages at the beginning and end.
14
+ * @default 1
15
+ */
16
+ boundaryCount?: number;
17
+ /**
18
+ * Callback when current page changes
19
+ */
20
+ onPageChange: (page: number) => void;
21
+ /**
22
+ * Total number of pages
23
+ */
24
+ count: number;
25
+ /**
26
+ * Changes padding, height and font-size
27
+ * @default "medium"
28
+ */
29
+ size?: "medium" | "small";
30
+ /**
31
+ * Display text alongside "previous" and "next" icons
32
+ * @default false
33
+ */
34
+ prevNextTexts?: boolean;
35
+ }
36
+ export declare const getSteps: ({ page, count, boundaryCount, siblingCount, }: {
37
+ page: any;
38
+ count: any;
39
+ boundaryCount?: number | undefined;
40
+ siblingCount?: number | undefined;
41
+ }) => (string | number)[];
42
+ declare const Pagination: ({ page, onPageChange, count, boundaryCount, siblingCount, className, size, prevNextTexts, }: PaginationProps) => JSX.Element | null;
43
+ export default Pagination;
@@ -0,0 +1,65 @@
1
+ import React from "react";
2
+ import cl from "classnames";
3
+ import { Back, Next } from "@navikt/ds-icons";
4
+ import { BodyShort } from "..";
5
+ export const getSteps = ({ page, count, boundaryCount = 1, siblingCount = 1, }) => {
6
+ var _a, _b;
7
+ const range = (start, end) => Array.from({ length: end - start + 1 }, (_, i) => start + i);
8
+ if (count <= (boundaryCount + siblingCount) * 2 + 3)
9
+ return range(1, count);
10
+ const startPages = range(1, boundaryCount);
11
+ const endPages = range(count - boundaryCount + 1, count);
12
+ const siblingsStart = Math.max(Math.min(page - siblingCount, count - boundaryCount - siblingCount * 2 - 1), boundaryCount + 2);
13
+ const siblingsEnd = siblingsStart + siblingCount * 2;
14
+ return [
15
+ ...startPages,
16
+ siblingsStart - ((_a = startPages[startPages.length - 1]) !== null && _a !== void 0 ? _a : 0) === 2
17
+ ? siblingsStart - 1
18
+ : "ellipsis",
19
+ ...range(siblingsStart, siblingsEnd),
20
+ ((_b = endPages[0]) !== null && _b !== void 0 ? _b : count + 1) - siblingsEnd === 2
21
+ ? siblingsEnd + 1
22
+ : "ellipsis",
23
+ ...endPages,
24
+ ];
25
+ };
26
+ const Pagination = ({ page, onPageChange, count, boundaryCount = 1, siblingCount = 1, className, size = "medium", prevNextTexts = false, }) => {
27
+ if (page < 1) {
28
+ console.error("page cannot be less than 1");
29
+ return null;
30
+ }
31
+ if (count < 1) {
32
+ console.error("count cannot be less than 1");
33
+ return null;
34
+ }
35
+ if (boundaryCount < 0) {
36
+ console.error("boundaryCount cannot be less than 0");
37
+ return null;
38
+ }
39
+ if (siblingCount < 0) {
40
+ console.error("siblingCount cannot be less than 0");
41
+ return null;
42
+ }
43
+ return (React.createElement("nav", { className: cl("navds-pagination", `navds-pagination--${size}`, className) },
44
+ prevNextTexts && (React.createElement("button", { className: "navds-pagination__prev-next", disabled: page === 1, onClick: () => onPageChange(page - 1) },
45
+ React.createElement(Back, { className: "navds-pagination__prev-next-icon", role: "presentation" }),
46
+ React.createElement(BodyShort, { size: size, className: "navds-pagination__prev-text" }, "Tilbake"))),
47
+ React.createElement("ul", { className: "navds-pagination__list" },
48
+ !prevNextTexts && (React.createElement("li", null,
49
+ React.createElement("button", { className: "navds-pagination__prev-next", disabled: page === 1, onClick: () => onPageChange(page - 1) },
50
+ React.createElement(Back, { className: "navds-pagination__prev-next-icon", title: "Tilbake" })))),
51
+ getSteps({ page, count, siblingCount, boundaryCount }).map((step, i) => {
52
+ const n = Number(step);
53
+ return isNaN(n) ? (React.createElement("li", { className: "navds-pagination__ellipsis", key: `${step}${i}` },
54
+ React.createElement(BodyShort, { size: size }, "..."))) : (React.createElement("li", { key: step },
55
+ React.createElement(BodyShort, { size: size, as: "button", className: "navds-pagination__item", onClick: () => onPageChange(n), "aria-current": page === n ? true : undefined }, n)));
56
+ }),
57
+ !prevNextTexts && (React.createElement("li", null,
58
+ React.createElement("button", { className: "navds-pagination__prev-next", disabled: page === count, onClick: () => onPageChange(page + 1) },
59
+ React.createElement(Next, { className: "navds-pagination__prev-next-icon", title: "Neste" }))))),
60
+ prevNextTexts && (React.createElement("button", { className: "navds-pagination__prev-next", disabled: page === count, onClick: () => onPageChange(page + 1) },
61
+ React.createElement(BodyShort, { size: size, className: "navds-pagination__next-text" }, "Neste"),
62
+ React.createElement(Next, { className: "navds-pagination__prev-next-icon", role: "presentation" })))));
63
+ };
64
+ export default Pagination;
65
+ //# sourceMappingURL=Pagination.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pagination.js","sourceRoot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ACE,gCACE,SAAS,EAAC,6BAA6B,EACvC,QAAQ,EAAE,IAAI,KAAK,KAAK,EACxB,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,CAAC;oBAErC,oBAAC,IAAI,IACH,SAAS,EAAC,kCAAkC,EAC5C,KAAK,EAAC,OAAO,GACb,CACK,CACN,CACN,CACE;QACJ,aAAa,IAAI,CAChB,gCACE,SAAS,EAAC,6BAA6B,EACvC,QAAQ,EAAE,IAAI,KAAK,KAAK,EACxB,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,CAAC;YAErC,oBAAC,SAAS,IAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAC,6BAA6B,YAElD;YACZ,oBAAC,IAAI,IACH,SAAS,EAAC,kCAAkC,EAC5C,IAAI,EAAC,cAAc,GACnB,CACK,CACV,CACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as Pagination } from "./Pagination";
2
+ export * from "./Pagination";
@@ -0,0 +1,3 @@
1
+ export { default as Pagination } from "./Pagination";
2
+ export * from "./Pagination";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pagination/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,cAAc,cAAc,CAAC"}
@@ -32,12 +32,15 @@ const ToggleGroup = forwardRef((_a, ref) => {
32
32
  [desc !== null && desc !== void 0 ? desc : ""]: !!desc,
33
33
  [labelId]: !!label,
34
34
  });
35
+ if (!value && !defaultValue) {
36
+ console.error("ToggleGroup needs either a value or defaultValue");
37
+ }
35
38
  return (React.createElement(ToggleGroupContext.Provider, { value: {
36
39
  size,
37
40
  } },
38
41
  React.createElement("div", null,
39
42
  label && (React.createElement(Label, { size: size, className: "navds-toggle-group__label", id: labelId }, label)),
40
- React.createElement(RadixToggleGroup.Root, Object.assign({}, rest, { onValueChange: handleValueChange, value: value !== null && value !== void 0 ? value : groupValue, defaultValue: defaultValue, ref: ref, className: cl("navds-toggle-group", className, `navds-toggle-group--${size}`) }, (describeBy && { "aria-describedby": describeBy }), { type: "single" }), children))));
43
+ React.createElement(RadixToggleGroup.Root, Object.assign({}, rest, { onValueChange: handleValueChange, value: value !== null && value !== void 0 ? value : groupValue, defaultValue: defaultValue, ref: ref, className: cl("navds-toggle-group", className, `navds-toggle-group--${size}`) }, (describeBy && { "aria-describedby": describeBy }), { role: "toolbar", type: "single" }), children))));
41
44
  });
42
45
  ToggleGroup.Item = ToggleItem;
43
46
  export default ToggleGroup;
@@ -1 +1 @@
1
- {"version":3,"file":"ToggleGroup.js","sourceRoot":"","sources":["../../src/toggle-group/ToggleGroup.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,UAAU,EAEV,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,UAA8B,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AA0ClC,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,IAAI,CACL,CAAC;AAEF,MAAM,WAAW,GAAG,UAAU,CAC5B,CACE,EAWC,EACD,GAAG,EACH,EAAE;QAbF,EACE,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,IAAI,GAAG,QAAQ,EACf,KAAK,EACL,KAAK,EACL,YAAY,EACZ,EAAE,EACF,kBAAkB,EAAE,IAAI,OAEzB,EADI,IAAI,cAVT,yGAWC,CADQ;IAIT,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC3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AAI,GAAI,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI;QACpB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK;KACnB,CAAC,CAAC;IAEH,IAAI,CAAC,KAAK,IAAI,CAAC,YAAY,EAAE;QAC3B,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;KACnE;IAED,OAAO,CACL,oBAAC,kBAAkB,CAAC,QAAQ,IAC1B,KAAK,EAAE;YACL,IAAI;SACL;QAED;YACG,KAAK,IAAI,CACR,oBAAC,KAAK,IACJ,IAAI,EAAE,IAAI,EACV,SAAS,EAAC,2BAA2B,EACrC,EAAE,EAAE,OAAO,IAEV,KAAK,CACA,CACT;YACD,oBAAC,gBAAgB,CAAC,IAAI,oBAChB,IAAI,IACR,aAAa,EAAE,iBAAiB,EAChC,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,UAAU,EAC1B,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CACX,oBAAoB,EACpB,SAAS,EACT,uBAAuB,IAAI,EAAE,CAC9B,IACG,CAAC,UAAU,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC,IACtD,IAAI,EAAC,SAAS,EACd,IAAI,EAAC,QAAQ,KAEZ,QAAQ,CACa,CACpB,CACsB,CAC/B,CAAC;AACJ,CAAC,CACsB,CAAC;AAE1B,WAAW,CAAC,IAAI,GAAG,UAAU,CAAC;AAE9B,eAAe,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.16.9",
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": "8a58d75efbbfd6ae78d9a352aeacefb10617cf70"
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>
package/src/index.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./link-panel";
10
10
  export * from "./loader";
11
11
  export * from "./menu";
12
12
  export * from "./modal";
13
+ export * from "./pagination";
13
14
  export * from "./panel";
14
15
  export * from "./popover";
15
16
  export * from "./speech-bubble";
@@ -6,7 +6,7 @@ import { Close } from "@navikt/ds-icons";
6
6
  import { Button } from "..";
7
7
  import ModalContent, { ModalContentType } from "./ModalContent";
8
8
 
9
- export interface ModalProps extends ReactModal {
9
+ export interface ModalProps {
10
10
  /**
11
11
  * Modal content
12
12
  */
@@ -0,0 +1,191 @@
1
+ import React from "react";
2
+ import cl from "classnames";
3
+ import { Back, Next } from "@navikt/ds-icons";
4
+ import { BodyShort } from "..";
5
+
6
+ interface PaginationProps extends React.HTMLAttributes<HTMLElement> {
7
+ /**
8
+ * Current page
9
+ */
10
+ page: number;
11
+ /**
12
+ * Number of always visible pages before and after the current page.
13
+ * @default 1
14
+ */
15
+ siblingCount?: number;
16
+ /**
17
+ * Number of always visible pages at the beginning and end.
18
+ * @default 1
19
+ */
20
+ boundaryCount?: number;
21
+ /**
22
+ * Callback when current page changes
23
+ */
24
+ onPageChange: (page: number) => void;
25
+ /**
26
+ * Total number of pages
27
+ */
28
+ count: number;
29
+ /**
30
+ * Changes padding, height and font-size
31
+ * @default "medium"
32
+ */
33
+ size?: "medium" | "small";
34
+ /**
35
+ * Display text alongside "previous" and "next" icons
36
+ * @default false
37
+ */
38
+ prevNextTexts?: boolean;
39
+ }
40
+
41
+ export const getSteps = ({
42
+ page,
43
+ count,
44
+ boundaryCount = 1,
45
+ siblingCount = 1,
46
+ }) => {
47
+ const range = (start: number, end: number) =>
48
+ Array.from({ length: end - start + 1 }, (_, i) => start + i);
49
+
50
+ if (count <= (boundaryCount + siblingCount) * 2 + 3) return range(1, count);
51
+
52
+ const startPages = range(1, boundaryCount);
53
+ const endPages = range(count - boundaryCount + 1, count);
54
+
55
+ const siblingsStart = Math.max(
56
+ Math.min(page - siblingCount, count - boundaryCount - siblingCount * 2 - 1),
57
+ boundaryCount + 2
58
+ );
59
+ const siblingsEnd = siblingsStart + siblingCount * 2;
60
+
61
+ return [
62
+ ...startPages,
63
+ siblingsStart - (startPages[startPages.length - 1] ?? 0) === 2
64
+ ? siblingsStart - 1
65
+ : "ellipsis",
66
+ ...range(siblingsStart, siblingsEnd),
67
+ (endPages[0] ?? count + 1) - siblingsEnd === 2
68
+ ? siblingsEnd + 1
69
+ : "ellipsis",
70
+ ...endPages,
71
+ ];
72
+ };
73
+
74
+ const Pagination = ({
75
+ page,
76
+ onPageChange,
77
+ count,
78
+ boundaryCount = 1,
79
+ siblingCount = 1,
80
+ className,
81
+ size = "medium",
82
+ prevNextTexts = false,
83
+ }: PaginationProps) => {
84
+ if (page < 1) {
85
+ console.error("page cannot be less than 1");
86
+ return null;
87
+ }
88
+ if (count < 1) {
89
+ console.error("count cannot be less than 1");
90
+ return null;
91
+ }
92
+ if (boundaryCount < 0) {
93
+ console.error("boundaryCount cannot be less than 0");
94
+ return null;
95
+ }
96
+ if (siblingCount < 0) {
97
+ console.error("siblingCount cannot be less than 0");
98
+ return null;
99
+ }
100
+
101
+ return (
102
+ <nav
103
+ className={cl("navds-pagination", `navds-pagination--${size}`, className)}
104
+ >
105
+ {prevNextTexts && (
106
+ <button
107
+ className="navds-pagination__prev-next"
108
+ disabled={page === 1}
109
+ onClick={() => onPageChange(page - 1)}
110
+ >
111
+ <Back
112
+ className="navds-pagination__prev-next-icon"
113
+ role="presentation"
114
+ />
115
+ <BodyShort size={size} className="navds-pagination__prev-text">
116
+ Tilbake
117
+ </BodyShort>
118
+ </button>
119
+ )}
120
+ <ul className="navds-pagination__list">
121
+ {!prevNextTexts && (
122
+ <li>
123
+ <button
124
+ className="navds-pagination__prev-next"
125
+ disabled={page === 1}
126
+ onClick={() => onPageChange(page - 1)}
127
+ >
128
+ <Back
129
+ className="navds-pagination__prev-next-icon"
130
+ title="Tilbake"
131
+ />
132
+ </button>
133
+ </li>
134
+ )}
135
+ {getSteps({ page, count, siblingCount, boundaryCount }).map(
136
+ (step, i) => {
137
+ const n = Number(step);
138
+ return isNaN(n) ? (
139
+ <li className="navds-pagination__ellipsis" key={`${step}${i}`}>
140
+ <BodyShort size={size}>...</BodyShort>
141
+ </li>
142
+ ) : (
143
+ <li key={step}>
144
+ <BodyShort
145
+ size={size}
146
+ as="button"
147
+ className="navds-pagination__item"
148
+ onClick={() => onPageChange(n)}
149
+ aria-current={page === n ? true : undefined}
150
+ >
151
+ {n}
152
+ </BodyShort>
153
+ </li>
154
+ );
155
+ }
156
+ )}
157
+ {!prevNextTexts && (
158
+ <li>
159
+ <button
160
+ className="navds-pagination__prev-next"
161
+ disabled={page === count}
162
+ onClick={() => onPageChange(page + 1)}
163
+ >
164
+ <Next
165
+ className="navds-pagination__prev-next-icon"
166
+ title="Neste"
167
+ />
168
+ </button>
169
+ </li>
170
+ )}
171
+ </ul>
172
+ {prevNextTexts && (
173
+ <button
174
+ className="navds-pagination__prev-next"
175
+ disabled={page === count}
176
+ onClick={() => onPageChange(page + 1)}
177
+ >
178
+ <BodyShort size={size} className="navds-pagination__next-text">
179
+ Neste
180
+ </BodyShort>
181
+ <Next
182
+ className="navds-pagination__prev-next-icon"
183
+ role="presentation"
184
+ />
185
+ </button>
186
+ )}
187
+ </nav>
188
+ );
189
+ };
190
+
191
+ export default Pagination;
@@ -0,0 +1,2 @@
1
+ export { default as Pagination } from "./Pagination";
2
+ export * from "./Pagination";
@@ -0,0 +1,37 @@
1
+ import React, { useState } from "react";
2
+ import Pagination from "./Pagination";
3
+
4
+ export default {
5
+ title: "ds-react/pagination",
6
+ component: Pagination,
7
+ };
8
+
9
+ export const All = (props) => {
10
+ const [page, setPage] = useState(props.page);
11
+ return (
12
+ <div>
13
+ <h2>Pagination</h2>
14
+ <Pagination {...props} page={page} onPageChange={setPage} />
15
+
16
+ <h2>Small</h2>
17
+ <Pagination size="small" {...props} page={page} onPageChange={setPage} />
18
+
19
+ <h2>prevNextTexts</h2>
20
+ <Pagination prevNextTexts {...props} page={page} onPageChange={setPage} />
21
+ <h3>prevNextTexts small</h3>
22
+ <Pagination
23
+ prevNextTexts
24
+ size="small"
25
+ {...props}
26
+ page={page}
27
+ onPageChange={setPage}
28
+ />
29
+ </div>
30
+ );
31
+ };
32
+ All.args = {
33
+ page: 1,
34
+ count: 8,
35
+ siblingCount: 1,
36
+ boundaryCount: 1,
37
+ };
@@ -0,0 +1,120 @@
1
+ import faker from "faker";
2
+ import { getSteps } from "./Pagination";
3
+
4
+ describe("getSteps", () => {
5
+ it("lists all pages when count is <= 7", () => {
6
+ const count = faker.datatype.number({ min: 1, max: 7 });
7
+ expect(getSteps({ page: 1, count })).toEqual(
8
+ Array.from({ length: count }, (_, i) => i + 1)
9
+ );
10
+ });
11
+
12
+ it("has an end ellipsis when count >= 8", () => {
13
+ const count = faker.datatype.number({ min: 8 });
14
+ const page = faker.datatype.number({ min: 1, max: 4 });
15
+ expect(
16
+ getSteps({
17
+ page,
18
+ count,
19
+ })
20
+ ).toEqual([1, 2, 3, 4, 5, "ellipsis", count]);
21
+ });
22
+
23
+ it("has a start ellipsis when count - page >= 3", () => {
24
+ const count = faker.datatype.number({ min: 8 });
25
+ const page = faker.datatype.number({ min: count - 3, max: count });
26
+ expect(
27
+ getSteps({
28
+ page,
29
+ count,
30
+ })
31
+ ).toEqual([
32
+ 1,
33
+ "ellipsis",
34
+ count - 4,
35
+ count - 3,
36
+ count - 2,
37
+ count - 1,
38
+ count,
39
+ ]);
40
+ });
41
+
42
+ it("has start & end ellipsis when count is high", () => {
43
+ const count = faker.datatype.number({ min: 9 });
44
+ const page = faker.datatype.number({ min: 5, max: count - 4 });
45
+ expect(
46
+ getSteps({
47
+ page,
48
+ count,
49
+ })
50
+ ).toEqual([1, "ellipsis", page - 1, page, page + 1, "ellipsis", count]);
51
+ });
52
+
53
+ it("can have a reduced siblingCount", () => {
54
+ const count = faker.datatype.number({ min: 7 });
55
+ const page = faker.datatype.number({ min: 4, max: count - 3 });
56
+ expect(
57
+ getSteps({
58
+ page,
59
+ count,
60
+ siblingCount: 0,
61
+ })
62
+ ).toEqual([1, "ellipsis", page, "ellipsis", count]);
63
+ });
64
+
65
+ it("can have an increased siblingCount", () => {
66
+ const count = faker.datatype.number({ min: 11 });
67
+ const page = faker.datatype.number({ min: 6, max: count - 5 });
68
+ expect(
69
+ getSteps({
70
+ page,
71
+ count,
72
+ siblingCount: 2,
73
+ })
74
+ ).toEqual([
75
+ 1,
76
+ "ellipsis",
77
+ page - 2,
78
+ page - 1,
79
+ page,
80
+ page + 1,
81
+ page + 2,
82
+ "ellipsis",
83
+ count,
84
+ ]);
85
+ });
86
+
87
+ it("can have an reduced boundaryCount", () => {
88
+ const count = faker.datatype.number({ min: 7 });
89
+ const page = faker.datatype.number({ min: 4, max: count - 3 });
90
+ expect(
91
+ getSteps({
92
+ page,
93
+ count,
94
+ boundaryCount: 0,
95
+ })
96
+ ).toEqual(["ellipsis", page - 1, page, page + 1, "ellipsis"]);
97
+ });
98
+
99
+ it("can have an increased boundaryCount", () => {
100
+ const count = faker.datatype.number({ min: 11 });
101
+ const page = faker.datatype.number({ min: 6, max: count - 5 });
102
+ expect(
103
+ getSteps({
104
+ page,
105
+ count,
106
+ boundaryCount: 2,
107
+ })
108
+ ).toEqual([
109
+ 1,
110
+ 2,
111
+ "ellipsis",
112
+ page - 1,
113
+ page,
114
+ page + 1,
115
+ "ellipsis",
116
+ count - 1,
117
+ count,
118
+ ]);
119
+ });
120
+ });
@@ -88,6 +88,10 @@ const ToggleGroup = forwardRef<HTMLDivElement, ToggleGroupProps>(
88
88
  [labelId]: !!label,
89
89
  });
90
90
 
91
+ if (!value && !defaultValue) {
92
+ console.error("ToggleGroup needs either a value or defaultValue");
93
+ }
94
+
91
95
  return (
92
96
  <ToggleGroupContext.Provider
93
97
  value={{
@@ -116,6 +120,7 @@ const ToggleGroup = forwardRef<HTMLDivElement, ToggleGroupProps>(
116
120
  `navds-toggle-group--${size}`
117
121
  )}
118
122
  {...(describeBy && { "aria-describedby": describeBy })}
123
+ role="toolbar"
119
124
  type="single"
120
125
  >
121
126
  {children}