@navikt/ds-react 0.17.3 → 0.17.4

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;
@@ -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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AAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExC,OAAO,CACL,6BAAK,SAAS,EAAC,iBAAiB;QAC9B,gDACM,IAAI,IACR,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;gBACb,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAG,CAAC,CAAC,CAAC;YACf,CAAC,EACD,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,yBAAyB,CAAC,EACnD,IAAI,EAAC,QAAQ,mBACE,IAAI,EACnB,KAAK,EAAE,KAAK;YAEZ,oBAAC,YAAY,IAAC,SAAS,EAAC,uBAAuB,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.17.3",
3
+ "version": "0.17.4",
4
4
  "private": false,
5
5
  "description": "NAV designsystem react components",
6
6
  "author": "NAV Designsystem team",
@@ -66,5 +66,5 @@
66
66
  "@types/react": "^17.0.30",
67
67
  "react": "^17.0.0"
68
68
  },
69
- "gitHead": "4baebb43408f7f77334c3c31a23140e04eef9a52"
69
+ "gitHead": "ddc0db1905160264958fcff8d59420b74740a5ac"
70
70
  }
@@ -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
+ };
@@ -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
- };