@navikt/ds-react 0.17.3 → 0.17.6

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.
@@ -43,25 +43,17 @@ const react_1 = __importStar(require("react"));
43
43
  const react_merge_refs_1 = __importDefault(require("react-merge-refs"));
44
44
  const __1 = require("..");
45
45
  const HelpText = (0, react_1.forwardRef)((_a, ref) => {
46
- var { className, children, placement = "top", strategy = "absolute", title = "hjelp" } = _a, rest = __rest(_a, ["className", "children", "placement", "strategy", "title"]);
46
+ var { className, children, placement = "top", strategy = "absolute", title = "hjelp", onClick } = _a, rest = __rest(_a, ["className", "children", "placement", "strategy", "title", "onClick"]);
47
47
  const buttonRef = (0, react_1.useRef)(null);
48
48
  const mergedRef = (0, react_merge_refs_1.default)([buttonRef, ref]);
49
- const [popoverRef, setPopoverRef] = (0, react_1.useState)(null);
50
- const wrapperRef = (0, react_1.useRef)(null);
51
49
  const [open, setOpen] = (0, react_1.useState)(false);
52
- (0, react_1.useEffect)(() => {
53
- var _a;
54
- open && ((_a = popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.focus) === null || _a === void 0 ? void 0 : _a.call(popoverRef));
55
- }, [open, popoverRef]);
56
- const handleClick = (e) => {
57
- setOpen((x) => !x);
58
- rest.onClick && rest.onClick(e);
59
- };
60
- return (react_1.default.createElement("div", { className: "navds-help-text", ref: wrapperRef },
61
- react_1.default.createElement("button", Object.assign({}, rest, { ref: mergedRef, onClick: (e) => handleClick(e), className: (0, classnames_1.default)(className, "navds-help-text__button"), type: "button", "aria-expanded": open, "aria-haspopup": "dialog", title: title }),
62
- react_1.default.createElement(ds_icons_1.Helptext, { className: "navds-help-text__icon" }),
63
- react_1.default.createElement("span", { className: "navds-sr-only" }, title)),
64
- react_1.default.createElement(__1.Popover, { ref: setPopoverRef, onClose: () => setOpen(false), className: "navds-help-text__popover", open: open, role: "tooltip", anchorEl: buttonRef.current, placement: placement, strategy: strategy },
65
- react_1.default.createElement(__1.Popover.Content, null, children))));
50
+ return (react_1.default.createElement("div", { className: "navds-help-text" },
51
+ react_1.default.createElement("button", Object.assign({}, rest, { ref: mergedRef, onClick: (e) => {
52
+ setOpen((x) => !x);
53
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
54
+ }, className: (0, classnames_1.default)(className, "navds-help-text__button"), type: "button", "aria-expanded": open, title: title }),
55
+ react_1.default.createElement(ds_icons_1.Helptext, { className: "navds-help-text__icon", "aria-hidden": true })),
56
+ react_1.default.createElement(__1.Popover, { onClose: () => setOpen(false), className: "navds-help-text__popover", open: open, anchorEl: buttonRef.current, placement: placement, strategy: strategy },
57
+ react_1.default.createElement(__1.Popover.Content, { className: "navds-body-short" }, children))));
66
58
  });
67
59
  exports.default = HelpText;
package/cjs/index.js CHANGED
@@ -29,6 +29,7 @@ __exportStar(require("./modal"), exports);
29
29
  __exportStar(require("./pagination"), exports);
30
30
  __exportStar(require("./panel"), exports);
31
31
  __exportStar(require("./popover"), exports);
32
+ __exportStar(require("./read-more"), exports);
32
33
  __exportStar(require("./speech-bubble"), exports);
33
34
  __exportStar(require("./step-indicator"), exports);
34
35
  __exportStar(require("./tag"), exports);
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ const react_1 = __importStar(require("react"));
41
+ const classnames_1 = __importDefault(require("classnames"));
42
+ const react_collapse_1 = require("react-collapse");
43
+ const ds_icons_1 = require("@navikt/ds-icons");
44
+ const typography_1 = require("../typography");
45
+ const ReadMore = (0, react_1.forwardRef)((_a, ref) => {
46
+ var { className, header, renderContentWhenClosed = false, children, open, defaultOpen = false, onClick } = _a, rest = __rest(_a, ["className", "header", "renderContentWhenClosed", "children", "open", "defaultOpen", "onClick"]);
47
+ const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
48
+ const CollapseComponent = renderContentWhenClosed
49
+ ? react_collapse_1.Collapse
50
+ : react_collapse_1.UnmountClosed;
51
+ const isOpened = open !== null && open !== void 0 ? open : internalOpen;
52
+ return (react_1.default.createElement(react_1.default.Fragment, null,
53
+ react_1.default.createElement("button", Object.assign({}, rest, { className: (0, classnames_1.default)("navds-read-more", "navds-body-short", "navds-body-short--small", className, {
54
+ "navds-read-more--open": isOpened,
55
+ }), onClick: (e) => {
56
+ if (open === undefined) {
57
+ setInternalOpen((isOpen) => !isOpen);
58
+ }
59
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
60
+ }, "aria-expanded": isOpened, ref: ref }),
61
+ react_1.default.createElement(ds_icons_1.Expand, { className: "navds-read-more__expand-icon", "aria-hidden": true }),
62
+ react_1.default.createElement("span", null, header)),
63
+ react_1.default.createElement(CollapseComponent, { isOpened: isOpened },
64
+ react_1.default.createElement("div", { className: "navds-read-more__content" },
65
+ react_1.default.createElement(typography_1.BodyLong, { size: "small" }, children)))));
66
+ });
67
+ exports.default = ReadMore;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.ReadMore = void 0;
21
+ var ReadMore_1 = require("./ReadMore");
22
+ Object.defineProperty(exports, "ReadMore", { enumerable: true, get: function () { return __importDefault(ReadMore_1).default; } });
23
+ __exportStar(require("./ReadMore"), exports);
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "main": "./index.js",
4
+ "module": "../../esm/read-more/index.js",
5
+ "types": "../../esm/read-more/index.d.ts"
6
+ }
@@ -11,30 +11,22 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { Helptext as HelpTextIcon } from "@navikt/ds-icons";
13
13
  import cl from "classnames";
14
- import React, { forwardRef, useEffect, useRef, useState } from "react";
14
+ import React, { forwardRef, useRef, useState } from "react";
15
15
  import mergeRefs from "react-merge-refs";
16
16
  import { Popover } from "..";
17
17
  const HelpText = forwardRef((_a, ref) => {
18
- var { className, children, placement = "top", strategy = "absolute", title = "hjelp" } = _a, rest = __rest(_a, ["className", "children", "placement", "strategy", "title"]);
18
+ var { className, children, placement = "top", strategy = "absolute", title = "hjelp", onClick } = _a, rest = __rest(_a, ["className", "children", "placement", "strategy", "title", "onClick"]);
19
19
  const buttonRef = useRef(null);
20
20
  const mergedRef = mergeRefs([buttonRef, ref]);
21
- const [popoverRef, setPopoverRef] = useState(null);
22
- const wrapperRef = useRef(null);
23
21
  const [open, setOpen] = useState(false);
24
- useEffect(() => {
25
- var _a;
26
- open && ((_a = popoverRef === null || popoverRef === void 0 ? void 0 : popoverRef.focus) === null || _a === void 0 ? void 0 : _a.call(popoverRef));
27
- }, [open, popoverRef]);
28
- const handleClick = (e) => {
29
- setOpen((x) => !x);
30
- rest.onClick && rest.onClick(e);
31
- };
32
- return (React.createElement("div", { className: "navds-help-text", ref: wrapperRef },
33
- React.createElement("button", Object.assign({}, rest, { ref: mergedRef, onClick: (e) => handleClick(e), className: cl(className, "navds-help-text__button"), type: "button", "aria-expanded": open, "aria-haspopup": "dialog", title: title }),
34
- React.createElement(HelpTextIcon, { className: "navds-help-text__icon" }),
35
- React.createElement("span", { className: "navds-sr-only" }, title)),
36
- React.createElement(Popover, { ref: setPopoverRef, onClose: () => setOpen(false), className: "navds-help-text__popover", open: open, role: "tooltip", anchorEl: buttonRef.current, placement: placement, strategy: strategy },
37
- React.createElement(Popover.Content, null, children))));
22
+ return (React.createElement("div", { className: "navds-help-text" },
23
+ React.createElement("button", Object.assign({}, rest, { ref: mergedRef, onClick: (e) => {
24
+ setOpen((x) => !x);
25
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
26
+ }, className: cl(className, "navds-help-text__button"), type: "button", "aria-expanded": open, title: title }),
27
+ React.createElement(HelpTextIcon, { className: "navds-help-text__icon", "aria-hidden": true })),
28
+ React.createElement(Popover, { onClose: () => setOpen(false), className: "navds-help-text__popover", open: open, anchorEl: buttonRef.current, placement: placement, strategy: strategy },
29
+ React.createElement(Popover.Content, { className: "navds-body-short" }, children))));
38
30
  });
39
31
  export default HelpText;
40
32
  //# sourceMappingURL=HelpText.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HelpText.js","sourceRoot":"","sources":["../../src/help-text/HelpText.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAgB,MAAM,IAAI,CAAC;AAW3C,MAAM,QAAQ,GAAG,UAAU,CACzB,CACE,EAOC,EACD,GAAG,EACH,EAAE;QATF,EACE,SAAS,EACT,QAAQ,EACR,SAAS,GAAG,KAAK,EACjB,QAAQ,GAAG,UAAU,EACrB,KAAK,GAAG,OAAO,OAEhB,EADI,IAAI,cANT,2DAOC,CADQ;IAIT,MAAM,SAAS,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAC;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IAEvD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GA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B,wBAAc,CACtD;QACT,oBAAC,OAAO,IACN,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAC7B,SAAS,EAAC,0BAA0B,EACpC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,SAAS,CAAC,OAAO,EAC3B,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ;YAElB,oBAAC,OAAO,CAAC,OAAO,IAAC,SAAS,EAAC,kBAAkB,IAC1C,QAAQ,CACO,CACV,CACN,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/esm/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./modal";
13
13
  export * from "./pagination";
14
14
  export * from "./panel";
15
15
  export * from "./popover";
16
+ export * from "./read-more";
16
17
  export * from "./speech-bubble";
17
18
  export * from "./step-indicator";
18
19
  export * from "./tag";
package/esm/index.js CHANGED
@@ -13,6 +13,7 @@ export * from "./modal";
13
13
  export * from "./pagination";
14
14
  export * from "./panel";
15
15
  export * from "./popover";
16
+ export * from "./read-more";
16
17
  export * from "./speech-bubble";
17
18
  export * from "./step-indicator";
18
19
  export * from "./tag";
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,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
+ {"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,aAAa,CAAC;AAC5B,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"}
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ export interface ReadMoreProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ /**
4
+ * Content inside read more
5
+ */
6
+ children: React.ReactNode;
7
+ /**
8
+ * Read more header content
9
+ */
10
+ header: React.ReactNode;
11
+ /**
12
+ * Opens component if 'true', closes if 'false'
13
+ * Using this props removes automatic control of open-state
14
+ */
15
+ open?: boolean;
16
+ /**
17
+ * Defaults the accordion to opened state
18
+ * @default false
19
+ */
20
+ defaultOpen?: boolean;
21
+ /**
22
+ * Removes content-element from dom when closed
23
+ * @default false
24
+ */
25
+ renderContentWhenClosed?: boolean;
26
+ }
27
+ declare const ReadMore: React.ForwardRefExoticComponent<ReadMoreProps & React.RefAttributes<HTMLButtonElement>>;
28
+ export default ReadMore;
@@ -0,0 +1,40 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React, { forwardRef, useState } from "react";
13
+ import cl from "classnames";
14
+ import { Collapse, UnmountClosed } from "react-collapse";
15
+ import { Expand } from "@navikt/ds-icons";
16
+ import { BodyLong } from "../typography";
17
+ const ReadMore = forwardRef((_a, ref) => {
18
+ var { className, header, renderContentWhenClosed = false, children, open, defaultOpen = false, onClick } = _a, rest = __rest(_a, ["className", "header", "renderContentWhenClosed", "children", "open", "defaultOpen", "onClick"]);
19
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
20
+ const CollapseComponent = renderContentWhenClosed
21
+ ? Collapse
22
+ : UnmountClosed;
23
+ const isOpened = open !== null && open !== void 0 ? open : internalOpen;
24
+ return (React.createElement(React.Fragment, null,
25
+ React.createElement("button", Object.assign({}, rest, { className: cl("navds-read-more", "navds-body-short", "navds-body-short--small", className, {
26
+ "navds-read-more--open": isOpened,
27
+ }), onClick: (e) => {
28
+ if (open === undefined) {
29
+ setInternalOpen((isOpen) => !isOpen);
30
+ }
31
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
32
+ }, "aria-expanded": isOpened, ref: ref }),
33
+ React.createElement(Expand, { className: "navds-read-more__expand-icon", "aria-hidden": true }),
34
+ React.createElement("span", null, header)),
35
+ React.createElement(CollapseComponent, { isOpened: isOpened },
36
+ React.createElement("div", { className: "navds-read-more__content" },
37
+ React.createElement(BodyLong, { size: "small" }, children)))));
38
+ });
39
+ export default ReadMore;
40
+ //# sourceMappingURL=ReadMore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReadMore.js","sourceRoot":"","sources":["../../src/read-more/ReadMore.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AA6BzC,MAAM,QAAQ,GAAG,UAAU,CACzB,CACE,EASC,EACD,GAAG,EACH,EAAE;QAXF,EACE,SAAS,EACT,MAAM,EACN,uBAAuB,GAAG,KAAK,EAC/B,QAAQ,EACR,IAAI,EACJ,WAAW,GAAG,KAAK,EACnB,OAAO,OAER,EADI,IAAI,cART,gGASC,CADQ;IAIT,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAU,WAAW,CAAC,CAAC;IACvE,MAAM,iBAAiB,GAAG,uBAAuB;QAC/C,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,aAAa,CAAC;IAElB,MAAM,QAAQ,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,YAAY,CAAC;IAEtC,OAAO,CACL;QACE,gDACM,IAAI,IACR,SAAS,EAAE,EAAE,CACX,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACT;gBACE,uBAAuB,EAAE,QAAQ;aAClC,CACF,EACD,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;gBACb,IAAI,IAAI,KAAK,SAAS,EAAE;oBACtB,eAAe,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;iBACtC;gBACD,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,CAAC,CAAC;YACf,CAAC,mBACc,QAAQ,EACvB,GAAG,EAAE,GAAG;YAER,oBAAC,MAAM,IAAC,SAAS,EAAC,8BAA8B,wBAAe;YAC/D,kCAAO,MAAM,CAAQ,CACd;QACT,oBAAC,iBAAiB,IAAC,QAAQ,EAAE,QAAQ;YACnC,6BAAK,SAAS,EAAC,0BAA0B;gBACvC,oBAAC,QAAQ,IAAC,IAAI,EAAC,OAAO,IAAE,QAAQ,CAAY,CACxC,CACY,CACnB,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as ReadMore } from "./ReadMore";
2
+ export * from "./ReadMore";
@@ -0,0 +1,3 @@
1
+ export { default as ReadMore } from "./ReadMore";
2
+ export * from "./ReadMore";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/read-more/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,cAAc,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.17.3",
3
+ "version": "0.17.6",
4
4
  "private": false,
5
5
  "description": "NAV designsystem react components",
6
6
  "author": "NAV Designsystem team",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@material-ui/core": "^4.12.3",
38
- "@navikt/ds-icons": "^0.8.4",
38
+ "@navikt/ds-icons": "^0.8.5",
39
39
  "@popperjs/core": "^2.10.1",
40
40
  "@radix-ui/react-toggle-group": "0.1.5",
41
41
  "classnames": "^2.2.6",
@@ -51,6 +51,7 @@
51
51
  "@testing-library/user-event": "^13.2.1",
52
52
  "@types/faker": "^5.5.8",
53
53
  "@types/jest": "^27.0.1",
54
+ "@types/react-collapse": "^5.0.1",
54
55
  "@types/react-modal": "^3.13.1",
55
56
  "@types/styled-components": "^5.1.14",
56
57
  "copyfiles": "^2.4.1",
@@ -66,5 +67,5 @@
66
67
  "@types/react": "^17.0.30",
67
68
  "react": "^17.0.0"
68
69
  },
69
- "gitHead": "4baebb43408f7f77334c3c31a23140e04eef9a52"
70
+ "gitHead": "f6042d01aad8740107376679bdd2917fa56dd3a0"
70
71
  }
@@ -10,20 +10,23 @@ export default {
10
10
  export const All = () => {
11
11
  const [value, setValue] = useState("");
12
12
  return (
13
- <div style={{ maxWidth: 300 }}>
13
+ <div
14
+ style={{
15
+ display: "flex",
16
+ alignItems: "center",
17
+ flexDirection: "column",
18
+ maxWidth: 400,
19
+ }}
20
+ >
14
21
  <h1>Search</h1>
15
- <div>
16
- <Search
17
- label="Søk alle sider om X og Y"
18
- onSearch={console.log}
19
- ></Search>
20
- <br />
21
- <Search
22
- label="Søk alle sider om X og Y"
23
- onSearch={console.log}
24
- variant="primary"
25
- ></Search>
26
- </div>
22
+
23
+ <Search label="Søk alle sider om X og Y" onSearch={console.log}></Search>
24
+ <h2>Primary search</h2>
25
+ <Search
26
+ label="Søk alle sider om X og Y"
27
+ onSearch={console.log}
28
+ variant="primary"
29
+ ></Search>
27
30
 
28
31
  <h2>Search small</h2>
29
32
  <Search
@@ -1,6 +1,6 @@
1
1
  import { Helptext as HelpTextIcon } from "@navikt/ds-icons";
2
2
  import cl from "classnames";
3
- import React, { forwardRef, useEffect, useRef, useState } from "react";
3
+ import React, { forwardRef, useRef, useState } from "react";
4
4
  import mergeRefs from "react-merge-refs";
5
5
  import { Popover, PopoverProps } from "..";
6
6
 
@@ -21,53 +21,42 @@ const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(
21
21
  placement = "top",
22
22
  strategy = "absolute",
23
23
  title = "hjelp",
24
+ onClick,
24
25
  ...rest
25
26
  },
26
27
  ref
27
28
  ) => {
28
29
  const buttonRef = useRef<HTMLButtonElement | null>(null);
29
30
  const mergedRef = mergeRefs([buttonRef, ref]);
30
- const [popoverRef, setPopoverRef] = useState<HTMLDivElement | null>(null);
31
- const wrapperRef = useRef<HTMLDivElement | null>(null);
32
-
33
31
  const [open, setOpen] = useState(false);
34
32
 
35
- useEffect(() => {
36
- open && popoverRef?.focus?.();
37
- }, [open, popoverRef]);
38
-
39
- const handleClick = (
40
- e: React.MouseEvent<HTMLButtonElement, MouseEvent>
41
- ) => {
42
- setOpen((x) => !x);
43
- rest.onClick && rest.onClick(e);
44
- };
45
33
  return (
46
- <div className="navds-help-text" ref={wrapperRef}>
34
+ <div className="navds-help-text">
47
35
  <button
48
36
  {...rest}
49
37
  ref={mergedRef}
50
- onClick={(e) => handleClick(e)}
38
+ onClick={(e) => {
39
+ setOpen((x) => !x);
40
+ onClick?.(e);
41
+ }}
51
42
  className={cl(className, "navds-help-text__button")}
52
43
  type="button"
53
44
  aria-expanded={open}
54
- aria-haspopup="dialog"
55
45
  title={title}
56
46
  >
57
- <HelpTextIcon className="navds-help-text__icon" />
58
- <span className="navds-sr-only">{title}</span>
47
+ <HelpTextIcon className="navds-help-text__icon" aria-hidden/>
59
48
  </button>
60
49
  <Popover
61
- ref={setPopoverRef}
62
50
  onClose={() => setOpen(false)}
63
51
  className="navds-help-text__popover"
64
52
  open={open}
65
- role="tooltip"
66
53
  anchorEl={buttonRef.current}
67
54
  placement={placement}
68
55
  strategy={strategy}
69
56
  >
70
- <Popover.Content>{children}</Popover.Content>
57
+ <Popover.Content className="navds-body-short">
58
+ {children}
59
+ </Popover.Content>
71
60
  </Popover>
72
61
  </div>
73
62
  );
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ import { TextField, HelpText } from "..";
3
+
4
+ export default {
5
+ title: "ds-react/help-text",
6
+ component: HelpText,
7
+ };
8
+
9
+ export const All = () => {
10
+ return (
11
+ <>
12
+ <h1>HelpText</h1>
13
+ <HelpText title="show tooltip">
14
+ Id ullamco excepteur elit fugiat labore.
15
+ </HelpText>
16
+ <TextField
17
+ label={
18
+ <div style={{ display: "flex", gap: 8 }}>
19
+ Text field label
20
+ <HelpText title="show tooltip">
21
+ Id ullamco excepteur elit fugiat labore.
22
+ </HelpText>
23
+ </div>
24
+ }
25
+ ></TextField>
26
+ </>
27
+ );
28
+ };
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./modal";
13
13
  export * from "./pagination";
14
14
  export * from "./panel";
15
15
  export * from "./popover";
16
+ export * from "./read-more";
16
17
  export * from "./speech-bubble";
17
18
  export * from "./step-indicator";
18
19
  export * from "./tag";
@@ -0,0 +1,90 @@
1
+ import React, { forwardRef, useState } from "react";
2
+ import cl from "classnames";
3
+ import { Collapse, UnmountClosed } from "react-collapse";
4
+ import { Expand } from "@navikt/ds-icons";
5
+ import { BodyLong } from "../typography";
6
+
7
+ export interface ReadMoreProps
8
+ extends React.ButtonHTMLAttributes<HTMLButtonElement> {
9
+ /**
10
+ * Content inside read more
11
+ */
12
+ children: React.ReactNode;
13
+ /**
14
+ * Read more header content
15
+ */
16
+ header: React.ReactNode;
17
+ /**
18
+ * Opens component if 'true', closes if 'false'
19
+ * Using this props removes automatic control of open-state
20
+ */
21
+ open?: boolean;
22
+ /**
23
+ * Defaults the accordion to opened state
24
+ * @default false
25
+ */
26
+ defaultOpen?: boolean;
27
+ /**
28
+ * Removes content-element from dom when closed
29
+ * @default false
30
+ */
31
+ renderContentWhenClosed?: boolean;
32
+ }
33
+
34
+ const ReadMore = forwardRef<HTMLButtonElement, ReadMoreProps>(
35
+ (
36
+ {
37
+ className,
38
+ header,
39
+ renderContentWhenClosed = false,
40
+ children,
41
+ open,
42
+ defaultOpen = false,
43
+ onClick,
44
+ ...rest
45
+ },
46
+ ref
47
+ ) => {
48
+ const [internalOpen, setInternalOpen] = useState<boolean>(defaultOpen);
49
+ const CollapseComponent = renderContentWhenClosed
50
+ ? Collapse
51
+ : UnmountClosed;
52
+
53
+ const isOpened = open ?? internalOpen;
54
+
55
+ return (
56
+ <>
57
+ <button
58
+ {...rest}
59
+ className={cl(
60
+ "navds-read-more",
61
+ "navds-body-short",
62
+ "navds-body-short--small",
63
+ className,
64
+ {
65
+ "navds-read-more--open": isOpened,
66
+ }
67
+ )}
68
+ onClick={(e) => {
69
+ if (open === undefined) {
70
+ setInternalOpen((isOpen) => !isOpen);
71
+ }
72
+ onClick?.(e);
73
+ }}
74
+ aria-expanded={isOpened}
75
+ ref={ref}
76
+ >
77
+ <Expand className="navds-read-more__expand-icon" aria-hidden />
78
+ <span>{header}</span>
79
+ </button>
80
+ <CollapseComponent isOpened={isOpened}>
81
+ <div className="navds-read-more__content">
82
+ <BodyLong size="small">{children}</BodyLong>
83
+ </div>
84
+ </CollapseComponent>
85
+ </>
86
+ );
87
+ }
88
+ );
89
+
90
+ export default ReadMore;
@@ -0,0 +1,2 @@
1
+ export { default as ReadMore } from "./ReadMore";
2
+ export * from "./ReadMore";
@@ -0,0 +1,60 @@
1
+ import React, { useState } from "react";
2
+ import { ReadMore } from ".";
3
+ import { Link } from "..";
4
+
5
+ export default {
6
+ title: "ds-react/read-more",
7
+ component: ReadMore,
8
+ };
9
+
10
+ export const All = () => {
11
+ const [open, setOpen] = useState(false);
12
+
13
+ return (
14
+ <>
15
+ <h1>Read more</h1>
16
+ <h2>Controlled</h2>
17
+ <ReadMore
18
+ open={open}
19
+ onClick={() => setOpen(!open)}
20
+ header="ReadMore header text"
21
+ >
22
+ Magna aliquip aliquip fugiat nostrud nostrud velit pariatur veniam
23
+ officia laboris voluptate officia pariatur.Lorem est ex anim velit
24
+ occaecat nisi qui nostrud sit consectetur consectetur officia nostrud
25
+ ullamco. Est ex duis proident nostrud elit qui laborum anim minim eu
26
+ eiusmod. Veniam in nostrud sunt tempor velit incididunt sint ex dolor
27
+ qui velit id eu.{" "}
28
+ <Link href="example.com">Deserunt magna sunt velit in</Link>. Est
29
+ exercitation id cillum qui do. Minim adipisicing nostrud commodo
30
+ proident occaecat aliquip nulla anim proident reprehenderit. Magna ipsum
31
+ officia veniam cupidatat duis veniam dolore reprehenderit mollit
32
+ velit.Ut consequat commodo minim occaecat id pariatur. Nisi enim tempor
33
+ laborum commodo. Tempor sit quis nostrud eu cupidatat sunt commodo
34
+ reprehenderit irure deserunt eiusmod ipsum. Exercitation quis commodo
35
+ cillum eiusmod eiusmod. Do laborum qui proident commodo adipisicing
36
+ eiusmod id.
37
+ </ReadMore>
38
+ <h2>Un-controlled</h2>
39
+ <ReadMore header="ReadMore header text">
40
+ Magna aliquip aliquip fugiat nostrud nostrud velit pariatur veniam
41
+ officia laboris voluptate officia pariatur.Lorem est ex anim velit
42
+ occaecat nisi qui nostrud sit consectetur consectetur officia nostrud
43
+ ullamco. Est ex duis proident nostrud elit qui laborum anim minim eu
44
+ eiusmod. Veniam in nostrud sunt tempor velit incididunt sint ex dolor
45
+ qui velit id eu. Deserunt magna sunt velit in. Est exercitation id
46
+ cillum qui do. Minim adipisicing nostrud commodo proident occaecat
47
+ aliquip nulla anim proident reprehenderit. Magna ipsum officia veniam
48
+ cupidatat duis veniam dolore reprehenderit mollit velit.Ut consequat
49
+ commodo minim occaecat id pariatur. Nisi enim tempor laborum commodo.
50
+ Tempor sit quis nostrud eu cupidatat sunt commodo reprehenderit irure
51
+ deserunt eiusmod ipsum. Exercitation quis commodo cillum eiusmod
52
+ eiusmod. Do laborum qui proident commodo adipisicing eiusmod id.
53
+ </ReadMore>
54
+ <h2>Default open</h2>
55
+ <ReadMore header="ReadMore header text" defaultOpen>
56
+ Body
57
+ </ReadMore>
58
+ </>
59
+ );
60
+ };
@@ -1,35 +0,0 @@
1
- import { Meta, Canvas } from "@storybook/addon-docs";
2
- import { HelpText } from "../../index";
3
- import { Success } from "@navikt/ds-react";
4
-
5
- <Meta title="ds-react/help-text/intro" />
6
-
7
- # Hvordan ta i bruk HelpText
8
-
9
- ```jsx
10
- <HelpText>Exercitation esse minim esse mollit ex magna.</HelpText>
11
- ```
12
-
13
- <Canvas>
14
- <div style={{ padding: "5rem" }}>
15
- <HelpText>Exercitation esse minim esse mollit ex magna.</HelpText>
16
- </div>
17
- </Canvas>
18
-
19
- # Egen title
20
-
21
- Husk å endre på "title" slik at skjermlesere får tydeligere informasjon
22
-
23
- ```jsx
24
- <HelpText title="vis hjelpetekst angående søknad">
25
- Exercitation esse minim esse mollit ex magna.
26
- </HelpText>
27
- ```
28
-
29
- <Canvas>
30
- <div style={{ padding: "5rem" }}>
31
- <HelpText title="vis hjelpetekst angående søknad">
32
- Exercitation esse minim esse mollit ex magna.
33
- </HelpText>
34
- </div>
35
- </Canvas>
@@ -1,32 +0,0 @@
1
- import React from "react";
2
- import { BodyLong } from "../../typography";
3
- import { HelpText } from "../index";
4
-
5
- export default {
6
- title: "ds-react/help-text",
7
- component: HelpText,
8
- };
9
-
10
- export const All = () => {
11
- return (
12
- <>
13
- <h1>HelpText</h1>
14
- <BodyLong style={{ display: "flex" }}>
15
- Quis tempor incididunt sint sit veniam ad dolore cillum ut.
16
- <HelpText title="show tooltip">
17
- Id ullamco excepteur elit fugiat labore.
18
- </HelpText>
19
- </BodyLong>
20
-
21
- <BodyLong>
22
- Incididunt pariatur laborum dolor sint qui eiusmod exercitation non
23
- cupidatat amet.
24
- </BodyLong>
25
-
26
- <h2>HelpText defaultOpen</h2>
27
- <HelpText title="show tooltip">
28
- Id ullamco excepteur elit fugiat labore.
29
- </HelpText>
30
- </>
31
- );
32
- };