@navikt/ds-react 0.19.0 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,7 @@ const AccordionContent = (0, react_1.forwardRef)((_a, ref) => {
51
51
  const CollapseComponent = context.renderContentWhenClosed
52
52
  ? react_collapse_1.Collapse
53
53
  : react_collapse_1.UnmountClosed;
54
- return (react_1.default.createElement("div", Object.assign({ ref: ref, role: "region", "aria-labelledby": context.buttonId }, rest),
54
+ return (react_1.default.createElement("div", Object.assign({ ref: ref, "aria-labelledby": context.buttonId }, rest),
55
55
  react_1.default.createElement(CollapseComponent, { isOpened: context.open },
56
56
  react_1.default.createElement("div", { className: (0, classnames_1.default)("navds-accordion__content", className) }, children))));
57
57
  });
@@ -46,11 +46,12 @@ const ErrorMessage_1 = __importDefault(require("./ErrorMessage"));
46
46
  const useFormField_1 = require("./useFormField");
47
47
  const __2 = require("..");
48
48
  exports.Textarea = (0, react_1.forwardRef)((props, ref) => {
49
- var _a;
49
+ var _a, _b, _c;
50
50
  const { inputProps, errorId, showErrorMsg, hasError, size, inputDescriptionId, } = (0, useFormField_1.useFormField)(props, "textarea");
51
51
  const { label, className, description, maxLength, hideLabel = false } = props, rest = __rest(props, ["label", "className", "description", "maxLength", "hideLabel"]);
52
52
  const maxLengthId = `TextareaMaxLength-${(0, __2.useId)()}`;
53
53
  const hasMaxLength = maxLength !== undefined && maxLength > 0;
54
+ const [controlledValue, setControlledValue] = (0, react_1.useState)((_a = props === null || props === void 0 ? void 0 : props.defaultValue) !== null && _a !== void 0 ? _a : "");
54
55
  return (react_1.default.createElement("div", { className: (0, classnames_1.default)(className, "navds-form-field", `navds-form-field--${size}`, {
55
56
  "navds-textarea--error": hasError,
56
57
  "navds-textarea--disabled": !!inputProps.disabled,
@@ -62,7 +63,9 @@ exports.Textarea = (0, react_1.forwardRef)((props, ref) => {
62
63
  "navds-sr-only": hideLabel,
63
64
  }), id: inputDescriptionId, size: size }, description)),
64
65
  react_1.default.createElement("div", { className: "navds-textarea__wrapper" },
65
- react_1.default.createElement(TextareaAutosize_1.default, Object.assign({}, (0, __1.omit)(rest, ["error", "errorId", "size"]), inputProps, { ref: ref, className: (0, classnames_1.default)("navds-textarea__input", "navds-body-short", `navds-body-${size !== null && size !== void 0 ? size : "medium"}`, {
66
+ react_1.default.createElement(TextareaAutosize_1.default, Object.assign({}, (0, __1.omit)(rest, ["error", "errorId", "size"]), inputProps, { onChange: (e) => props.onChange
67
+ ? props.onChange(e)
68
+ : setControlledValue(e.target.value), ref: ref, className: (0, classnames_1.default)("navds-textarea__input", "navds-body-short", `navds-body-${size !== null && size !== void 0 ? size : "medium"}`, {
66
69
  "navds-textarea--counter": hasMaxLength,
67
70
  }), "aria-describedby": (0, classnames_1.default)(inputProps["aria-describedby"], {
68
71
  [maxLengthId]: hasMaxLength,
@@ -75,7 +78,7 @@ exports.Textarea = (0, react_1.forwardRef)((props, ref) => {
75
78
  " ",
76
79
  maxLength,
77
80
  " signs."),
78
- react_1.default.createElement(exports.Counter, { maxLength: maxLength, currentLength: (_a = props.value) === null || _a === void 0 ? void 0 : _a.length, size: size })))),
81
+ react_1.default.createElement(exports.Counter, { maxLength: maxLength, currentLength: (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : controlledValue === null || controlledValue === void 0 ? void 0 : controlledValue.length, size: size })))),
79
82
  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)))));
80
83
  });
81
84
  const Counter = ({ maxLength, currentLength, size }) => {
@@ -23,7 +23,7 @@ const AccordionContent = forwardRef((_a, ref) => {
23
23
  const CollapseComponent = context.renderContentWhenClosed
24
24
  ? Collapse
25
25
  : UnmountClosed;
26
- return (React.createElement("div", Object.assign({ ref: ref, role: "region", "aria-labelledby": context.buttonId }, rest),
26
+ return (React.createElement("div", Object.assign({ ref: ref, "aria-labelledby": context.buttonId }, rest),
27
27
  React.createElement(CollapseComponent, { isOpened: context.open },
28
28
  React.createElement("div", { className: cl("navds-accordion__content", className) }, children))));
29
29
  });
@@ -1 +1 @@
1
- {"version":3,"file":"AccordionContent.js","sourceRoot":"","sources":["../../src/accordion/AccordionContent.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAgBvD,MAAM,gBAAgB,GAAyB,UAAU,CACvD,CAAC,EAAoC,EAAE,GAAG,EAAE,EAAE;QAA7C,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAW,EAAN,IAAI,cAAlC,+BAAoC,CAAF;IACjC,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEjD,IAAI,OAAO,KAAK,IAAI,EAAE;QACpB,OAAO,CAAC,KAAK,CACX,+DAA+D,CAChE,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,uBAAuB;QACvD,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,aAAa,CAAC;IAElB,OAAO,CACL,2CAAK,GAAG,EAAE,GAAG,EAAE,IAAI,EAAC,QAAQ,qBAAkB,OAAO,CAAC,QAAQ,IAAM,IAAI;QACtE,oBAAC,iBAAiB,IAAC,QAAQ,EAAE,OAAO,CAAC,IAAI;YACvC,6BAAK,SAAS,EAAE,EAAE,CAAC,0BAA0B,EAAE,SAAS,CAAC,IACtD,QAAQ,CACL,CACY,CAChB,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"AccordionContent.js","sourceRoot":"","sources":["../../src/accordion/AccordionContent.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAgBvD,MAAM,gBAAgB,GAAyB,UAAU,CACvD,CAAC,EAAoC,EAAE,GAAG,EAAE,EAAE;QAA7C,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAW,EAAN,IAAI,cAAlC,+BAAoC,CAAF;IACjC,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAEjD,IAAI,OAAO,KAAK,IAAI,EAAE;QACpB,OAAO,CAAC,KAAK,CACX,+DAA+D,CAChE,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IAED,MAAM,iBAAiB,GAAG,OAAO,CAAC,uBAAuB;QACvD,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,aAAa,CAAC;IAElB,OAAO,CACL,2CAAK,GAAG,EAAE,GAAG,qBAAmB,OAAO,CAAC,QAAQ,IAAM,IAAI;QACxD,oBAAC,iBAAiB,IAAC,QAAQ,EAAE,OAAO,CAAC,IAAI;YACvC,6BAAK,SAAS,EAAE,EAAE,CAAC,0BAA0B,EAAE,SAAS,CAAC,IACtD,QAAQ,CACL,CACY,CAChB,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -9,7 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import React, { forwardRef } from "react";
12
+ import React, { forwardRef, useState } from "react";
13
13
  import cl from "classnames";
14
14
  import TextareaAutosize from "@material-ui/core/TextareaAutosize";
15
15
  import { BodyShort, Label, omit } from "..";
@@ -17,11 +17,12 @@ import ErrorMessage from "./ErrorMessage";
17
17
  import { useFormField } from "./useFormField";
18
18
  import { useId } from "..";
19
19
  export const Textarea = forwardRef((props, ref) => {
20
- var _a;
20
+ var _a, _b, _c;
21
21
  const { inputProps, errorId, showErrorMsg, hasError, size, inputDescriptionId, } = useFormField(props, "textarea");
22
22
  const { label, className, description, maxLength, hideLabel = false } = props, rest = __rest(props, ["label", "className", "description", "maxLength", "hideLabel"]);
23
23
  const maxLengthId = `TextareaMaxLength-${useId()}`;
24
24
  const hasMaxLength = maxLength !== undefined && maxLength > 0;
25
+ const [controlledValue, setControlledValue] = useState((_a = props === null || props === void 0 ? void 0 : props.defaultValue) !== null && _a !== void 0 ? _a : "");
25
26
  return (React.createElement("div", { className: cl(className, "navds-form-field", `navds-form-field--${size}`, {
26
27
  "navds-textarea--error": hasError,
27
28
  "navds-textarea--disabled": !!inputProps.disabled,
@@ -33,7 +34,9 @@ export const Textarea = forwardRef((props, ref) => {
33
34
  "navds-sr-only": hideLabel,
34
35
  }), id: inputDescriptionId, size: size }, description)),
35
36
  React.createElement("div", { className: "navds-textarea__wrapper" },
36
- React.createElement(TextareaAutosize, Object.assign({}, omit(rest, ["error", "errorId", "size"]), inputProps, { ref: ref, className: cl("navds-textarea__input", "navds-body-short", `navds-body-${size !== null && size !== void 0 ? size : "medium"}`, {
37
+ React.createElement(TextareaAutosize, Object.assign({}, omit(rest, ["error", "errorId", "size"]), inputProps, { onChange: (e) => props.onChange
38
+ ? props.onChange(e)
39
+ : setControlledValue(e.target.value), ref: ref, className: cl("navds-textarea__input", "navds-body-short", `navds-body-${size !== null && size !== void 0 ? size : "medium"}`, {
37
40
  "navds-textarea--counter": hasMaxLength,
38
41
  }), "aria-describedby": cl(inputProps["aria-describedby"], {
39
42
  [maxLengthId]: hasMaxLength,
@@ -46,7 +49,7 @@ export const Textarea = forwardRef((props, ref) => {
46
49
  " ",
47
50
  maxLength,
48
51
  " signs."),
49
- React.createElement(Counter, { maxLength: maxLength, currentLength: (_a = props.value) === null || _a === void 0 ? void 0 : _a.length, size: size })))),
52
+ React.createElement(Counter, { maxLength: maxLength, currentLength: (_c = (_b = props.value) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : controlledValue === null || controlledValue === void 0 ? void 0 : controlledValue.length, size: size })))),
50
53
  React.createElement("div", { id: errorId, "aria-relevant": "additions removals", "aria-live": "polite" }, showErrorMsg && (React.createElement(ErrorMessage, { size: size }, props.error)))));
51
54
  });
52
55
  export const Counter = ({ maxLength, currentLength, size }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Textarea.js","sourceRoot":"","sources":["../../src/form/Textarea.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,gBAAgB,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAkB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAwC3B,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAChC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;;IACb,MAAM,EACJ,UAAU,EACV,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,IAAI,EACJ,kBAAkB,GACnB,GAAG,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAEpC,MAAM,EACJ,KAAK,EACL,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,GAAG,KAAK,KAEf,KAAK,EADJ,IAAI,UACL,KAAK,EAPH,+DAOL,CAAQ,CAAC;IAEV,MAAM,WAAW,GAAG,qBAAqB,KAAK,EAAE,EAAE,CAAC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K,CAAC,KAAK,CAAgB,CACvD,CACG,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE;IAC5D,MAAM,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;IAE7C,OAAO,CACL,oBAAC,SAAS,IACR,SAAS,EAAE,EAAE,CAAC,yBAAyB,EAAE;YACvC,gCAAgC,EAAE,UAAU,GAAG,CAAC;SACjD,CAAC,eACS,UAAU,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,EAC7C,IAAI,EAAE,IAAI,IAET,UAAU,GAAG,CAAC;QACb,CAAC,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,eAAe;QAC/C,CAAC,CAAC,UAAU,UAAU,aAAa,CAC3B,CACb,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.19.0",
4
- "private": false,
3
+ "version": "0.19.3",
5
4
  "description": "NAV designsystem react components",
6
5
  "author": "NAV Designsystem team",
7
6
  "license": "MIT",
@@ -31,14 +30,14 @@
31
30
  "docgen": "yarn ts-node ../../../scripts/docgen.ts",
32
31
  "create-package-json-pointers-to-esm": "node ../../../scripts/createPackageJsonsWithESMPointers.js",
33
32
  "clean": "rimraf cjs esm",
34
- "build": "yarn run clean && tsc && tsc -p tsconfig.esm.json && yarn create-package-json-pointers-to-esm && yarn docgen",
33
+ "build": "yarn run clean && concurrently \"tsc\" \"tsc -p tsconfig.esm.json\" && yarn create-package-json-pointers-to-esm",
35
34
  "watch": "tsc --watch -p tsconfig.esm.json",
36
35
  "test": "jest"
37
36
  },
38
37
  "dependencies": {
39
38
  "@floating-ui/react-dom": "0.6.0",
40
39
  "@material-ui/core": "^4.12.3",
41
- "@navikt/ds-icons": "^0.8.13",
40
+ "@navikt/ds-icons": "^0.8.15",
42
41
  "@popperjs/core": "^2.10.1",
43
42
  "@radix-ui/react-tabs": "0.1.5",
44
43
  "@radix-ui/react-toggle-group": "0.1.5",
@@ -50,29 +49,32 @@
50
49
  "uuid": "^8.3.2"
51
50
  },
52
51
  "devDependencies": {
52
+ "@testing-library/dom": "8.13.0",
53
53
  "@testing-library/jest-dom": "^5.16.0",
54
54
  "@testing-library/react": "^13.0.0",
55
55
  "@testing-library/user-event": "^14.0.0",
56
56
  "@types/faker": "5.5.8",
57
57
  "@types/jest": "^27.0.1",
58
+ "@types/node": "^17.0.35",
58
59
  "@types/react-collapse": "^5.0.1",
59
60
  "@types/react-modal": "^3.13.1",
60
- "@types/styled-components": "^5.1.14",
61
+ "concurrently": "7.2.1",
61
62
  "copyfiles": "^2.4.1",
62
63
  "faker": "5.5.3",
63
64
  "fast-glob": "3.2.11",
64
65
  "jest": "^27.5.0",
65
66
  "react-docgen-typescript": "2.2.2",
67
+ "react-dom": "^18.0.0",
66
68
  "react-router-dom": "^6.3.0",
67
69
  "rimraf": "3.0.2",
68
- "styled-components": "^5.3.1",
69
70
  "swr": "^1.1.2",
70
71
  "ts-jest": "^27.1.0",
71
- "ts-node": "10.7.0"
72
+ "ts-node": "10.7.0",
73
+ "typescript": "^4.7.2"
72
74
  },
73
75
  "peerDependencies": {
74
76
  "@types/react": "^17.0.30 || ^18.0.0",
75
77
  "react": "^17.0.0 || ^18.0.0"
76
78
  },
77
- "gitHead": "17f35836538a5956def85cefe08ba956c71ba3b2"
79
+ "gitHead": "035f4e937ada8a9f8ed9836116024596a271ab4f"
78
80
  }
@@ -33,7 +33,7 @@ const AccordionContent: AccordionContentType = forwardRef(
33
33
  : UnmountClosed;
34
34
 
35
35
  return (
36
- <div ref={ref} role="region" aria-labelledby={context.buttonId} {...rest}>
36
+ <div ref={ref} aria-labelledby={context.buttonId} {...rest}>
37
37
  <CollapseComponent isOpened={context.open}>
38
38
  <div className={cl("navds-accordion__content", className)}>
39
39
  {children}
@@ -52,11 +52,13 @@ export const Default = (props) => {
52
52
  </Accordion.Item>
53
53
  );
54
54
  return (
55
- <Accordion>
56
- {[...Array(props.nItems ? props.nItems : 2)].map((_, y) => (
57
- <Item key={y} />
58
- ))}
59
- </Accordion>
55
+ <div style={{ width: 500 }}>
56
+ <Accordion>
57
+ {[...Array(props.nItems ? props.nItems : 2)].map((_, y) => (
58
+ <Item key={y} />
59
+ ))}
60
+ </Accordion>
61
+ </div>
60
62
  );
61
63
  };
62
64
 
@@ -71,32 +73,36 @@ export const Controlled = () => {
71
73
  const [open2, setOpen2] = useState(false);
72
74
 
73
75
  return (
76
+ <div style={{ width: 500 }}>
77
+ <Accordion>
78
+ <Accordion.Item open={open}>
79
+ <Accordion.Header onClick={() => setOpen(!open)}>
80
+ Accordion header text
81
+ </Accordion.Header>
82
+ <Content />
83
+ </Accordion.Item>
84
+ <Accordion.Item open={open2}>
85
+ <Accordion.Header onClick={() => setOpen2(!open2)}>
86
+ Accordion header text
87
+ </Accordion.Header>
88
+ <Content />
89
+ </Accordion.Item>
90
+ </Accordion>
91
+ </div>
92
+ );
93
+ };
94
+
95
+ export const Uncontrolled = () => (
96
+ <div style={{ width: 500 }}>
74
97
  <Accordion>
75
- <Accordion.Item open={open}>
76
- <Accordion.Header onClick={() => setOpen(!open)}>
77
- Accordion header text
78
- </Accordion.Header>
98
+ <Accordion.Item>
99
+ <Accordion.Header>Accordion header text</Accordion.Header>
79
100
  <Content />
80
101
  </Accordion.Item>
81
- <Accordion.Item open={open2}>
82
- <Accordion.Header onClick={() => setOpen2(!open2)}>
83
- Accordion header text
84
- </Accordion.Header>
102
+ <Accordion.Item>
103
+ <Accordion.Header>Accordion header text</Accordion.Header>
85
104
  <Content />
86
105
  </Accordion.Item>
87
106
  </Accordion>
88
- );
89
- };
90
-
91
- export const Uncontrolled = () => (
92
- <Accordion>
93
- <Accordion.Item>
94
- <Accordion.Header>Accordion header text</Accordion.Header>
95
- <Content />
96
- </Accordion.Item>
97
- <Accordion.Item>
98
- <Accordion.Header>Accordion header text</Accordion.Header>
99
- <Content />
100
- </Accordion.Item>
101
- </Accordion>
107
+ </div>
102
108
  );
@@ -1,4 +1,4 @@
1
- import React, { forwardRef } from "react";
1
+ import React, { forwardRef, useState } from "react";
2
2
  import cl from "classnames";
3
3
  import TextareaAutosize from "@material-ui/core/TextareaAutosize";
4
4
  import { BodyShort, Label, omit } from "..";
@@ -67,6 +67,10 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
67
67
  const maxLengthId = `TextareaMaxLength-${useId()}`;
68
68
  const hasMaxLength = maxLength !== undefined && maxLength > 0;
69
69
 
70
+ const [controlledValue, setControlledValue] = useState<string>(
71
+ props?.defaultValue ?? ""
72
+ );
73
+
70
74
  return (
71
75
  <div
72
76
  className={cl(
@@ -105,6 +109,11 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
105
109
  <TextareaAutosize
106
110
  {...omit(rest, ["error", "errorId", "size"])}
107
111
  {...inputProps}
112
+ onChange={(e) =>
113
+ props.onChange
114
+ ? props.onChange(e)
115
+ : setControlledValue(e.target.value)
116
+ }
108
117
  ref={ref}
109
118
  className={cl(
110
119
  "navds-textarea__input",
@@ -126,7 +135,7 @@ export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
126
135
  </span>
127
136
  <Counter
128
137
  maxLength={maxLength}
129
- currentLength={props.value?.length}
138
+ currentLength={props.value?.length ?? controlledValue?.length}
130
139
  size={size}
131
140
  />
132
141
  </>
@@ -3,67 +3,92 @@ import { ConfirmationPanel } from "../index";
3
3
  import { Meta } from "@storybook/react/types-6-0";
4
4
  import { Link } from "../..";
5
5
  export default {
6
- title: "ds-react/form/confirmation-panel",
6
+ title: "ds-react/form/ConfirmationPanel",
7
7
  component: ConfirmationPanel,
8
+ argTypes: {
9
+ size: {
10
+ control: {
11
+ type: "radio",
12
+ options: ["medium", "small"],
13
+ },
14
+ },
15
+ error: {
16
+ type: "string",
17
+ },
18
+ },
8
19
  } as Meta;
9
20
 
10
- export const All = () => {
21
+ const content = (
22
+ <>
23
+ Ipsum voluptate pariatur <Link href="#123">testlink</Link> anim officia
24
+ minim ut mollit voluptate exercitation nulla mollit.
25
+ </>
26
+ );
27
+
28
+ export const Default = (props) => {
29
+ return (
30
+ <ConfirmationPanel
31
+ error={props?.error}
32
+ size={props?.size}
33
+ checked={props?.checked ?? undefined}
34
+ label={props?.label ?? "Checkbox label text"}
35
+ >
36
+ {content}
37
+ </ConfirmationPanel>
38
+ );
39
+ };
40
+
41
+ Default.args = {
42
+ label: "Checkbox label text",
43
+ checked: false,
44
+ };
45
+
46
+ export const Small = () => {
11
47
  const [checked, setChecked] = useState(false);
12
48
  return (
13
- <div>
14
- <h1>ConfirmationPanel</h1>
15
- <ConfirmationPanel
16
- checked={checked}
17
- onChange={() => setChecked(!checked)}
18
- label="Checkbox label text"
19
- >
20
- Ipsum voluptate pariatur <Link href="#123">testlink</Link> anim officia
21
- minim ut mollit voluptate exercitation nulla mollit.
22
- </ConfirmationPanel>
23
- <h2>size small</h2>
24
- <ConfirmationPanel
25
- checked={checked}
26
- onChange={() => setChecked(!checked)}
27
- label="Checkbox label text"
28
- size="small"
29
- >
30
- Ipsum voluptate pariatur <Link href="#123">testlink</Link> anim officia
31
- minim ut mollit voluptate exercitation nulla mollit.
32
- </ConfirmationPanel>
33
- <h3>error</h3>
49
+ <ConfirmationPanel
50
+ checked={checked}
51
+ onChange={() => setChecked(!checked)}
52
+ label="Checkbox label text"
53
+ size="small"
54
+ >
55
+ {content}
56
+ </ConfirmationPanel>
57
+ );
58
+ };
59
+
60
+ export const NoContent = () => {
61
+ const [checked, setChecked] = useState(false);
62
+ return (
63
+ <ConfirmationPanel
64
+ checked={checked}
65
+ onChange={() => setChecked(!checked)}
66
+ label="Checkbox label text"
67
+ />
68
+ );
69
+ };
70
+
71
+ export const Error = () => {
72
+ const [checked, setChecked] = useState(false);
73
+ return (
74
+ <div className="colgap">
34
75
  <ConfirmationPanel
35
76
  checked={checked}
36
77
  onChange={() => setChecked(!checked)}
37
78
  label="Checkbox label text"
38
- error="Ex cupidatat do do do"
79
+ error="Adipisicing sint aute quis veniam incididunt duis est sint aute cillum."
39
80
  >
40
- Ipsum voluptate pariatur <Link href="#123">testlink</Link> anim officia
41
- minim ut mollit voluptate exercitation nulla mollit.
81
+ {content}
42
82
  </ConfirmationPanel>
43
- <h3>error small</h3>
44
83
  <ConfirmationPanel
45
84
  checked={checked}
46
85
  onChange={() => setChecked(!checked)}
47
86
  label="Checkbox label text"
48
- error="Ex cupidatat do do do"
87
+ error="Adipisicing sint aute quis veniam incididunt duis est sint aute cillum."
49
88
  size="small"
50
89
  >
51
- Ipsum voluptate pariatur <Link href="#123">testlink</Link> anim officia
52
- minim ut mollit voluptate exercitation nulla mollit.
90
+ {content}
53
91
  </ConfirmationPanel>
54
- <h2>Empty</h2>
55
- <ConfirmationPanel
56
- checked={checked}
57
- onChange={() => setChecked(!checked)}
58
- label="Checkbox label text"
59
- ></ConfirmationPanel>
60
- <h2>Uncontrolled</h2>
61
- <ConfirmationPanel label="Checkbox label text"></ConfirmationPanel>
62
- <h3>defaultChecked</h3>
63
- <ConfirmationPanel
64
- defaultChecked
65
- label="Checkbox label text"
66
- ></ConfirmationPanel>
67
92
  </div>
68
93
  );
69
94
  };
@@ -3,72 +3,111 @@ import { Fieldset } from "../index";
3
3
  import { Meta } from "@storybook/react/types-6-0";
4
4
  import { TextField } from "../../index";
5
5
  export default {
6
- title: "ds-react/form/fieldset",
6
+ title: "ds-react/form/Fieldset",
7
7
  component: Fieldset,
8
+ argTypes: {
9
+ size: {
10
+ control: {
11
+ type: "radio",
12
+ options: ["medium", "small"],
13
+ },
14
+ },
15
+ description: {
16
+ type: "string",
17
+ },
18
+ error: {
19
+ type: "string",
20
+ },
21
+ hideLegend: {
22
+ type: "boolean",
23
+ },
24
+ disabled: {
25
+ type: "boolean",
26
+ },
27
+ },
8
28
  } as Meta;
9
29
 
10
- export const All = () => {
11
- return (
12
- <div>
13
- <h1>Fieldset</h1>
14
-
15
- <Fieldset legend="Mollit eiusmod">
16
- <TextField label="Textfield label" hideLabel />
17
- <TextField label="Textfield label" hideLabel />
18
- </Fieldset>
19
-
20
- <h2>Description</h2>
21
-
22
- <Fieldset
23
- legend="Mollit eiusmod"
24
- description={<div>Quis reprehenderit esse cillum</div>}
25
- >
26
- <TextField
27
- label="Textfield label"
28
- hideLabel
29
- description={<div>Quis reprehenderit esse cillum</div>}
30
- />
31
- <TextField label="Textfield label" hideLabel />
32
- </Fieldset>
33
-
34
- <h2>Errors</h2>
35
-
36
- <Fieldset legend="Mollit eiusmod" error="Fieldsett error">
37
- <TextField label="Textfield label" hideLabel />
38
- <TextField label="Textfield label" hideLabel />
39
- </Fieldset>
30
+ const content = (
31
+ <>
32
+ <TextField label="Textfield label" hideLabel />
33
+ <TextField label="Textfield label" hideLabel />
34
+ </>
35
+ );
40
36
 
41
- <h2>Errors uten errorPropagation</h2>
37
+ export const Default = (props) => {
38
+ return (
39
+ <Fieldset legend="Mollit eiusmod" {...props}>
40
+ {content}
41
+ </Fieldset>
42
+ );
43
+ };
42
44
 
43
- <Fieldset
44
- legend="Mollit eiusmod"
45
- error="Fieldsett error"
46
- errorPropagation={false}
47
- >
48
- <TextField label="Textfield label" hideLabel error="Må være fylt ut" />
49
- <TextField label="Textfield label" hideLabel />
50
- </Fieldset>
45
+ Default.args = {
46
+ errorPropagation: true,
47
+ };
51
48
 
52
- <h2>Sizing</h2>
49
+ export const Small = () => (
50
+ <Fieldset
51
+ size="small"
52
+ legend="Mollit eiusmod"
53
+ description="Do ullamco amet mollit labore tempor minim cupidatat dolore voluptate velit irure."
54
+ >
55
+ {content}
56
+ </Fieldset>
57
+ );
53
58
 
54
- <Fieldset size="small" legend="Mollit eiusmod" description="Dolore minim">
55
- <TextField label="Textfield label" hideLabel />
56
- <TextField label="Textfield label" hideLabel />
57
- </Fieldset>
59
+ export const Description = () => (
60
+ <Fieldset
61
+ legend="Mollit eiusmod"
62
+ description="Esse cupidatat reprehenderit est culpa consectetur sit dolor esse."
63
+ >
64
+ <TextField label="Textfield label" hideLabel />
65
+ <TextField label="Textfield label" hideLabel />
66
+ </Fieldset>
67
+ );
58
68
 
59
- <h2>hideLegend</h2>
69
+ export const ErrorPropagation = () => (
70
+ <Fieldset
71
+ legend="Mollit eiusmod"
72
+ error="Fieldsett error"
73
+ errorPropagation={false}
74
+ >
75
+ <TextField label="Textfield label" hideLabel error="Må være fylt ut" />
76
+ <TextField label="Textfield label" hideLabel />
77
+ </Fieldset>
78
+ );
60
79
 
61
- <Fieldset legend="Mollit eiusmod" description="Dolore minim" hideLegend>
62
- <TextField label="Textfield label" hideLabel />
63
- <TextField label="Textfield label" hideLabel />
64
- </Fieldset>
80
+ export const Error = () => (
81
+ <div className="colgap">
82
+ <Fieldset
83
+ legend="Mollit eiusmod"
84
+ error="Laborum officia nisi aliqua esse minim in amet."
85
+ >
86
+ {content}
87
+ </Fieldset>
88
+ <Fieldset
89
+ size="small"
90
+ legend="Mollit eiusmod"
91
+ error="Laborum officia nisi aliqua esse minim in amet."
92
+ >
93
+ {content}
94
+ </Fieldset>
95
+ </div>
96
+ );
65
97
 
66
- <h2>Disabled</h2>
98
+ export const Disabled = () => (
99
+ <div className="colgap">
100
+ <Fieldset legend="Mollit eiusmod" disabled>
101
+ {content}
102
+ </Fieldset>
103
+ <Fieldset size="small" legend="Mollit eiusmod" disabled>
104
+ {content}
105
+ </Fieldset>
106
+ </div>
107
+ );
67
108
 
68
- <Fieldset legend="Mollit eiusmod" description="Dolore minim" disabled>
69
- <TextField label="Textfield label" hideLabel />
70
- <TextField label="Textfield label" hideLabel />
71
- </Fieldset>
72
- </div>
73
- );
74
- };
109
+ export const hideLegend = () => (
110
+ <Fieldset legend="Mollit eiusmod" hideLegend>
111
+ {content}
112
+ </Fieldset>
113
+ );