@navikt/ds-react 0.18.4 → 0.18.7

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/_docs.json CHANGED
@@ -707,44 +707,61 @@
707
707
  "name": "ReactNode"
708
708
  }
709
709
  },
710
- "className": {
710
+ "error": {
711
711
  "defaultValue": null,
712
- "description": "",
713
- "name": "className",
712
+ "description": "Error message for element",
713
+ "name": "error",
714
714
  "parent": {
715
- "fileName": "nav-frontend-moduler/node_modules/@types/react/index.d.ts",
716
- "name": "HTMLAttributes"
715
+ "fileName": "src/form/ConfirmationPanel.tsx",
716
+ "name": "ConfirmationPanelProps"
717
717
  },
718
718
  "declarations": [
719
719
  {
720
- "fileName": "nav-frontend-moduler/node_modules/@types/react/index.d.ts",
721
- "name": "HTMLAttributes"
720
+ "fileName": "src/form/ConfirmationPanel.tsx",
721
+ "name": "ConfirmationPanelProps"
722
722
  }
723
723
  ],
724
724
  "required": false,
725
725
  "type": {
726
- "name": "string"
726
+ "name": "ReactNode"
727
727
  }
728
728
  },
729
- "error": {
730
- "defaultValue": {
731
- "value": "false"
729
+ "errorId": {
730
+ "defaultValue": null,
731
+ "description": "Override internal errorId",
732
+ "name": "errorId",
733
+ "parent": {
734
+ "fileName": "src/form/ConfirmationPanel.tsx",
735
+ "name": "ConfirmationPanelProps"
732
736
  },
733
- "description": "Adds error indication on checkbox",
734
- "name": "error",
737
+ "declarations": [
738
+ {
739
+ "fileName": "src/form/ConfirmationPanel.tsx",
740
+ "name": "ConfirmationPanelProps"
741
+ }
742
+ ],
743
+ "required": false,
744
+ "type": {
745
+ "name": "string"
746
+ }
747
+ },
748
+ "className": {
749
+ "defaultValue": null,
750
+ "description": "",
751
+ "name": "className",
735
752
  "parent": {
736
- "fileName": "react/src/form/checkbox/Checkbox.tsx",
737
- "name": "CheckboxProps"
753
+ "fileName": "nav-frontend-moduler/node_modules/@types/react/index.d.ts",
754
+ "name": "HTMLAttributes"
738
755
  },
739
756
  "declarations": [
740
757
  {
741
- "fileName": "react/src/form/checkbox/Checkbox.tsx",
742
- "name": "CheckboxProps"
758
+ "fileName": "nav-frontend-moduler/node_modules/@types/react/index.d.ts",
759
+ "name": "HTMLAttributes"
743
760
  }
744
761
  ],
745
762
  "required": false,
746
763
  "type": {
747
- "name": "boolean"
764
+ "name": "string"
748
765
  }
749
766
  },
750
767
  "size": {
@@ -41,14 +41,19 @@ exports.ConfirmationPanel = void 0;
41
41
  const react_1 = __importStar(require("react"));
42
42
  const classnames_1 = __importDefault(require("classnames"));
43
43
  const __1 = require("..");
44
+ const ErrorMessage_1 = __importDefault(require("./ErrorMessage"));
45
+ const useFormField_1 = require("./useFormField");
44
46
  exports.ConfirmationPanel = (0, react_1.forwardRef)((_a, ref) => {
45
47
  var { className, children, label } = _a, props = __rest(_a, ["className", "children", "label"]);
46
- return (react_1.default.createElement("div", { ref: ref, className: (0, classnames_1.default)("navds-confirmation-panel", className, {
47
- "navds-confirmation-panel--small": props.size === "small",
48
- "navds-confirmation-panel--error": !!props.error,
48
+ const { errorId, showErrorMsg, hasError, size, inputProps } = (0, useFormField_1.useFormField)(props, "confirmationPanel");
49
+ return (react_1.default.createElement("div", { ref: ref, className: (0, classnames_1.default)("navds-confirmation-panel", "navds-form-field", className, {
50
+ "navds-confirmation-panel--small": size === "small",
51
+ "navds-confirmation-panel--error": hasError,
49
52
  "navds-confirmation-panel--checked": !!props.checked,
50
53
  }) },
51
- children && (react_1.default.createElement(__1.BodyLong, { size: props.size, className: "navds-confirmation-panel__content" }, children)),
52
- react_1.default.createElement(__1.Checkbox, Object.assign({}, props), label)));
54
+ react_1.default.createElement("div", { className: "navds-confirmation-panel__inner" },
55
+ children && (react_1.default.createElement(__1.BodyLong, { size: props.size, className: "navds-confirmation-panel__content" }, children)),
56
+ react_1.default.createElement(__1.Checkbox, Object.assign({}, props, inputProps, { error: hasError, size: size }), label)),
57
+ react_1.default.createElement("div", { id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && react_1.default.createElement(ErrorMessage_1.default, { size: size }, props.error))));
53
58
  });
54
59
  exports.default = exports.ConfirmationPanel;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { CheckboxProps } from "..";
3
- export interface ConfirmationPanelProps extends Omit<CheckboxProps, "children" | "indeterminate" | "hideLabel"> {
3
+ export interface ConfirmationPanelProps extends Omit<CheckboxProps, "children" | "indeterminate" | "hideLabel" | "error"> {
4
4
  /**
5
5
  * Additional information on panel
6
6
  */
@@ -9,6 +9,14 @@ export interface ConfirmationPanelProps extends Omit<CheckboxProps, "children" |
9
9
  * Checkbox label
10
10
  */
11
11
  label: React.ReactNode;
12
+ /**
13
+ * Error message for element
14
+ */
15
+ error?: React.ReactNode;
16
+ /**
17
+ * Override internal errorId
18
+ */
19
+ errorId?: string;
12
20
  }
13
21
  export declare const ConfirmationPanel: React.ForwardRefExoticComponent<ConfirmationPanelProps & React.RefAttributes<HTMLDivElement>>;
14
22
  export default ConfirmationPanel;
@@ -12,15 +12,20 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import React, { forwardRef } from "react";
13
13
  import cl from "classnames";
14
14
  import { BodyLong, Checkbox } from "..";
15
+ import ErrorMessage from "./ErrorMessage";
16
+ import { useFormField } from "./useFormField";
15
17
  export const ConfirmationPanel = forwardRef((_a, ref) => {
16
18
  var { className, children, label } = _a, props = __rest(_a, ["className", "children", "label"]);
17
- return (React.createElement("div", { ref: ref, className: cl("navds-confirmation-panel", className, {
18
- "navds-confirmation-panel--small": props.size === "small",
19
- "navds-confirmation-panel--error": !!props.error,
19
+ const { errorId, showErrorMsg, hasError, size, inputProps } = useFormField(props, "confirmationPanel");
20
+ return (React.createElement("div", { ref: ref, className: cl("navds-confirmation-panel", "navds-form-field", className, {
21
+ "navds-confirmation-panel--small": size === "small",
22
+ "navds-confirmation-panel--error": hasError,
20
23
  "navds-confirmation-panel--checked": !!props.checked,
21
24
  }) },
22
- children && (React.createElement(BodyLong, { size: props.size, className: "navds-confirmation-panel__content" }, children)),
23
- React.createElement(Checkbox, Object.assign({}, props), label)));
25
+ React.createElement("div", { className: "navds-confirmation-panel__inner" },
26
+ children && (React.createElement(BodyLong, { size: props.size, className: "navds-confirmation-panel__content" }, children)),
27
+ React.createElement(Checkbox, Object.assign({}, props, inputProps, { error: hasError, size: size }), label)),
28
+ React.createElement("div", { id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && React.createElement(ErrorMessage, { size: size }, props.error))));
24
29
  });
25
30
  export default ConfirmationPanel;
26
31
  //# sourceMappingURL=ConfirmationPanel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConfirmationPanel.js","sourceRoot":"","sources":["../../src/form/ConfirmationPanel.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAiB,MAAM,IAAI,CAAC;AAcvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAGzC,CAAC,EAAwC,EAAE,GAAG,EAAE,EAAE;QAAjD,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,OAAY,EAAP,KAAK,cAAtC,kCAAwC,CAAF;IACvC,OAAO,CACL,6BACE,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,0BAA0B,EAAE,SAAS,EAAE;YACnD,iCAAiC,EAAE,KAAK,CAAC,IAAI,KAAK,OAAO;YACzD,iCAAiC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK;YAChD,mCAAmC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO;SACrD,CAAC;QAED,QAAQ,IAAI,CACX,oBAAC,QAAQ,IACP,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,SAAS,EAAC,mCAAmC,IAE5C,QAAQ,CACA,CACZ;QACD,oBAAC,QAAQ,oB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AI,EAAE,IAAI,KAC7D,KAAK,CACG,CACP;QACN,6BAAK,EAAE,EAAE,OAAO,mBAAgB,oBAAoB,eAAW,QAAQ,IACpE,YAAY,IAAI,oBAAC,YAAY,IAAC,IAAI,EAAE,IAAI,IAAG,KAAK,CAAC,KAAK,CAAgB,CACnE,CACF,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.18.4",
3
+ "version": "0.18.7",
4
4
  "private": false,
5
5
  "description": "NAV designsystem react components",
6
6
  "author": "NAV Designsystem team",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@floating-ui/react-dom": "0.6.0",
40
40
  "@material-ui/core": "^4.12.3",
41
- "@navikt/ds-icons": "^0.8.11",
41
+ "@navikt/ds-icons": "^0.8.13",
42
42
  "@popperjs/core": "^2.10.1",
43
43
  "@radix-ui/react-tabs": "0.1.5",
44
44
  "@radix-ui/react-toggle-group": "0.1.5",
@@ -74,5 +74,5 @@
74
74
  "@types/react": "^17.0.30 || ^18.0.0",
75
75
  "react": "^17.0.0 || ^18.0.0"
76
76
  },
77
- "gitHead": "ce0e15166d8523300a5a2a99eabb04c748078893"
77
+ "gitHead": "46b1186bb8614fd065e87c09b139a095b8993778"
78
78
  }
@@ -1,9 +1,14 @@
1
1
  import React, { forwardRef } from "react";
2
2
  import cl from "classnames";
3
3
  import { BodyLong, Checkbox, CheckboxProps } from "..";
4
+ import ErrorMessage from "./ErrorMessage";
5
+ import { useFormField } from "./useFormField";
4
6
 
5
7
  export interface ConfirmationPanelProps
6
- extends Omit<CheckboxProps, "children" | "indeterminate" | "hideLabel"> {
8
+ extends Omit<
9
+ CheckboxProps,
10
+ "children" | "indeterminate" | "hideLabel" | "error"
11
+ > {
7
12
  /**
8
13
  * Additional information on panel
9
14
  */
@@ -12,30 +17,50 @@ export interface ConfirmationPanelProps
12
17
  * Checkbox label
13
18
  */
14
19
  label: React.ReactNode;
20
+ /**
21
+ * Error message for element
22
+ */
23
+ error?: React.ReactNode;
24
+ /**
25
+ * Override internal errorId
26
+ */
27
+ errorId?: string;
15
28
  }
16
29
 
17
30
  export const ConfirmationPanel = forwardRef<
18
31
  HTMLDivElement,
19
32
  ConfirmationPanelProps
20
33
  >(({ className, children, label, ...props }, ref) => {
34
+ const { errorId, showErrorMsg, hasError, size, inputProps } = useFormField(
35
+ props,
36
+ "confirmationPanel"
37
+ );
38
+
21
39
  return (
22
40
  <div
23
41
  ref={ref}
24
- className={cl("navds-confirmation-panel", className, {
25
- "navds-confirmation-panel--small": props.size === "small",
26
- "navds-confirmation-panel--error": !!props.error,
42
+ className={cl("navds-confirmation-panel", "navds-form-field", className, {
43
+ "navds-confirmation-panel--small": size === "small",
44
+ "navds-confirmation-panel--error": hasError,
27
45
  "navds-confirmation-panel--checked": !!props.checked,
28
46
  })}
29
47
  >
30
- {children && (
31
- <BodyLong
32
- size={props.size}
33
- className="navds-confirmation-panel__content"
34
- >
35
- {children}
36
- </BodyLong>
37
- )}
38
- <Checkbox {...props}>{label}</Checkbox>
48
+ <div className="navds-confirmation-panel__inner">
49
+ {children && (
50
+ <BodyLong
51
+ size={props.size}
52
+ className="navds-confirmation-panel__content"
53
+ >
54
+ {children}
55
+ </BodyLong>
56
+ )}
57
+ <Checkbox {...props} {...inputProps} error={hasError} size={size}>
58
+ {label}
59
+ </Checkbox>
60
+ </div>
61
+ <div id={errorId} aria-relevant="additions removals" aria-live="polite">
62
+ {showErrorMsg && <ErrorMessage size={size}>{props.error}</ErrorMessage>}
63
+ </div>
39
64
  </div>
40
65
  );
41
66
  });
@@ -1,5 +1,4 @@
1
1
  import React, { useState } from "react";
2
- import { rest } from "msw";
3
2
  import useSWR from "swr";
4
3
  import people from "./people.json";
5
4
  import { Table } from "../index";
@@ -21,6 +20,42 @@ const queryString = (obj) =>
21
20
  .map((key) => key + "=" + obj[key])
22
21
  .join("&");
23
22
 
23
+ const updateData = async (url: string) => {
24
+ const newUrl = new URL(`https://www.example.com/${url}`);
25
+ const comparator = (a, b, orderBy) => {
26
+ if (b[orderBy] < a[orderBy]) {
27
+ return -1;
28
+ }
29
+ if (b[orderBy] > a[orderBy]) {
30
+ return 1;
31
+ }
32
+ return 0;
33
+ };
34
+
35
+ const page = Number(newUrl.searchParams.get("page"));
36
+ const sort = newUrl.searchParams.get("sort");
37
+
38
+ await new Promise((resolve) =>
39
+ setTimeout(resolve, Math.round(Math.random() * (1000 - 200) + 200))
40
+ );
41
+
42
+ return {
43
+ count: people.length,
44
+ results: people
45
+ .slice()
46
+ .sort((a, b) => {
47
+ if (sort) {
48
+ const [orderBy, direction] = sort.split(":");
49
+ return direction === "ascending"
50
+ ? comparator(b, a, orderBy)
51
+ : comparator(a, b, orderBy);
52
+ }
53
+ return 1;
54
+ })
55
+ .slice((page - 1) * rowsPerPage, page * rowsPerPage),
56
+ };
57
+ };
58
+
24
59
  export const Async = () => {
25
60
  const [page, setPage] = useState(1);
26
61
  const [sort, setSort] = useState<SortState>();
@@ -30,7 +65,7 @@ export const Async = () => {
30
65
  page,
31
66
  sort: sort ? `${sort.orderBy}:${sort.direction}` : undefined,
32
67
  })}`,
33
- (url) => fetch(url).then((res) => res.json())
68
+ (url) => updateData(url)
34
69
  );
35
70
 
36
71
  if (!data) {
@@ -128,42 +163,3 @@ export const Async = () => {
128
163
  </div>
129
164
  );
130
165
  };
131
-
132
- Async.parameters = {
133
- msw: {
134
- handlers: [
135
- rest.get("/people", (req, res, ctx) => {
136
- const comparator = (a, b, orderBy) => {
137
- if (b[orderBy] < a[orderBy]) {
138
- return -1;
139
- }
140
- if (b[orderBy] > a[orderBy]) {
141
- return 1;
142
- }
143
- return 0;
144
- };
145
-
146
- const page = Number(req.url.searchParams.get("page"));
147
- const sort = req.url.searchParams.get("sort");
148
- return res(
149
- //ctx.delay(),
150
- ctx.json({
151
- count: people.length,
152
- results: people
153
- .slice()
154
- .sort((a, b) => {
155
- if (sort) {
156
- const [orderBy, direction] = sort.split(":");
157
- return direction === "ascending"
158
- ? comparator(b, a, orderBy)
159
- : comparator(a, b, orderBy);
160
- }
161
- return 1;
162
- })
163
- .slice((page - 1) * rowsPerPage, page * rowsPerPage),
164
- })
165
- );
166
- }),
167
- ],
168
- },
169
- };