@helsenorge/designsystem-react 6.4.0 → 6.5.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## [6.4.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv6.3.0&targetVersion=GTv6.4.0) (2024-02-29)
2
+
3
+ ### Features
4
+
5
+ - slider har fatt value prop og fiks til selected state
6
+ ([645ca82](https://github.com/helsenorge/designsystem/commit/645ca8291d85705f7e9cf3a372376cb4e53dc4cd)), closes
7
+ [#321070](https://github.com/helsenorge/designsystem/issues/321070)
8
+ - table-komponenter støtter alle vanlige html-attributter
9
+ ([0810650](https://github.com/helsenorge/designsystem/commit/08106504e1441a9c8916c41fbca31accf0beade2)), closes
10
+ [#321166](https://github.com/helsenorge/designsystem/issues/321166)
11
+
12
+ ### Bug Fixes
13
+
14
+ - slider value prop oppdaterer og selectedstate
15
+ ([e510bd7](https://github.com/helsenorge/designsystem/commit/e510bd7a1ef3fe89eaa4cbd6af614291d055cbb8))
16
+
1
17
  ## [6.3.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv6.2.0&targetVersion=GTv6.3.0) (2024-02-22)
2
18
 
3
19
  ### Features
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../../../src/components/Dropdown/Dropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAsBhD,oBAAY,YAAY;IACtB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,wBAAwB;IACx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ACf,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,OAAO,YAAY,CAAC;IACjC,uCAAuC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uCAAuC;IACvC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA0JrC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -1,20 +1,21 @@
1
- import t, { useRef as g, useState as V } from "react";
1
+ import r, { useRef as g, useState as W } from "react";
2
2
  import k from "classnames";
3
3
  import { theme as C } from "../../theme/index.js";
4
4
  import "../../hooks/useBreakpoint.js";
5
- import { useHover as W } from "../../hooks/useHover.js";
6
- import { useSize as X } from "../../hooks/useSize.js";
7
- import { useToggle as j } from "../../hooks/useToggle.js";
8
- import { useKeyboardEvent as q } from "../../hooks/useKeyboardEvent.js";
9
- import { useOutsideEvent as F } from "../../hooks/useOutsideEvent.js";
5
+ import { useHover as X } from "../../hooks/useHover.js";
6
+ import { useSize as j } from "../../hooks/useSize.js";
7
+ import { useToggle as q } from "../../hooks/useToggle.js";
8
+ import { useKeyboardEvent as F } from "../../hooks/useKeyboardEvent.js";
9
+ import { useOutsideEvent as G } from "../../hooks/useOutsideEvent.js";
10
10
  import { useUuid as _ } from "../../hooks/useUuid.js";
11
- import { KeyboardEventKey as r, AnalyticsId as G, IconSize as J } from "../../constants.js";
12
- import Q from "../Button/Button.js";
13
- import { Icon as Y } from "../Icon/Icon.js";
14
- import Z from "../Icons/PlusSmall.js";
15
- import e from "./styles.module.scss";
16
- var M = /* @__PURE__ */ ((s) => (s.onwhite = "onwhite", s.ongrey = "ongrey", s.onblueberry = "onblueberry", s.oncherry = "oncherry", s))(M || {});
17
- const ee = (s) => {
11
+ import { KeyboardEventKey as n, AnalyticsId as J, IconSize as Q } from "../../constants.js";
12
+ import { mergeRefs as Y } from "../../utils/refs.js";
13
+ import Z from "../Button/Button.js";
14
+ import { Icon as M } from "../Icon/Icon.js";
15
+ import ee from "../Icons/PlusSmall.js";
16
+ import o from "./styles.module.scss";
17
+ var oe = /* @__PURE__ */ ((d) => (d.onwhite = "onwhite", d.ongrey = "ongrey", d.onblueberry = "onblueberry", d.oncherry = "oncherry", d))(oe || {});
18
+ const re = (d) => {
18
19
  const {
19
20
  label: R,
20
21
  placeholder: $,
@@ -28,19 +29,19 @@ const ee = (s) => {
28
29
  fluid: b = !1,
29
30
  testId: z,
30
31
  disabled: i
31
- } = s, p = g(null), w = g(null), { hoverRef: u, isHovered: D } = W(), { value: a, toggleValue: h } = j(!i && S, K), d = g(t.Children.map(y, () => t.createRef())), [m, L] = V(), { width: T } = X(u) || {}, E = _(), I = _(), x = _(), N = () => {
32
- var o;
33
- h(), (o = w.current) == null || o.focus();
32
+ } = d, p = g(null), w = g(null), { hoverRef: m, isHovered: D } = X(), { value: l, toggleValue: h } = q(!i && S, K), a = g(r.Children.map(y, () => r.createRef())), [u, L] = W(), { width: T } = j(m) || {}, E = _(), I = _(), x = _(), N = () => {
33
+ var e;
34
+ h(), (e = w.current) == null || e.focus();
34
35
  }, f = () => {
35
- var o;
36
- h(), (o = u.current) == null || o.focus();
36
+ var e;
37
+ h(), (e = m.current) == null || e.focus();
37
38
  };
38
- q(p, (o) => {
39
+ F(p, (e) => {
39
40
  var v;
40
- if (o.preventDefault(), !d.current)
41
+ if (e.preventDefault(), !a.current)
41
42
  return;
42
- if (a) {
43
- if (o.key === r.Escape && a) {
43
+ if (l) {
44
+ if (e.key === n.Escape && l) {
44
45
  f();
45
46
  return;
46
47
  }
@@ -48,72 +49,69 @@ const ee = (s) => {
48
49
  N();
49
50
  return;
50
51
  }
51
- const n = d.current.findIndex((P) => P.current === o.target);
52
- let l = n;
53
- o.key === r.Home ? l = 0 : o.key === r.End ? l = d.current.length - 1 : o.key === r.ArrowDown && n < d.current.length - 1 ? l = n + 1 : o.key === r.ArrowUp && n > 0 ? l = n - 1 : o.key === r.Enter && n !== -1 && (l = n), l !== -1 && ((v = d.current[l].current) == null || v.focus(), L(l));
52
+ const t = a.current.findIndex((V) => V.current === e.target);
53
+ let s = t;
54
+ e.key === n.Home ? s = 0 : e.key === n.End ? s = a.current.length - 1 : e.key === n.ArrowDown && t < a.current.length - 1 ? s = t + 1 : e.key === n.ArrowUp && t > 0 ? s = t - 1 : e.key === n.Enter && t !== -1 && (s = t), s !== -1 && ((v = a.current[s].current) == null || v.focus(), L(s));
54
55
  }, [
55
- r.ArrowDown,
56
- r.ArrowUp,
57
- r.End,
58
- r.Enter,
59
- r.Escape,
60
- r.Home
61
- ]), F(p, () => a && f());
56
+ n.ArrowDown,
57
+ n.ArrowUp,
58
+ n.End,
59
+ n.Enter,
60
+ n.Escape,
61
+ n.Home
62
+ ]), G(p, () => l && f());
62
63
  const U = k(
63
- e.dropdown__toggle,
64
+ o.dropdown__toggle,
64
65
  !i && {
65
- [e["dropdown__toggle--on-white"]]: c === "onwhite",
66
- [e["dropdown__toggle--on-grey"]]: c === "ongrey",
67
- [e["dropdown__toggle--on-blueberry"]]: c === "onblueberry",
68
- [e["dropdown__toggle--on-cherry"]]: c === "oncherry",
69
- [e["dropdown__toggle--transparent"]]: O,
70
- [e["dropdown__toggle--fluid"]]: b,
71
- [e["dropdown__toggle--open"]]: a
66
+ [o["dropdown__toggle--on-white"]]: c === "onwhite",
67
+ [o["dropdown__toggle--on-grey"]]: c === "ongrey",
68
+ [o["dropdown__toggle--on-blueberry"]]: c === "onblueberry",
69
+ [o["dropdown__toggle--on-cherry"]]: c === "oncherry",
70
+ [o["dropdown__toggle--transparent"]]: O,
71
+ [o["dropdown__toggle--fluid"]]: b,
72
+ [o["dropdown__toggle--open"]]: l
72
73
  }
73
- ), B = k(e.dropdown__content, a && e["dropdown__content--open"]);
74
- return /* @__PURE__ */ t.createElement("div", { className: e.dropdown, ref: p }, /* @__PURE__ */ t.createElement("span", { id: E, className: e.dropdown__label }, R), /* @__PURE__ */ t.createElement(
74
+ ), B = k(o.dropdown__content, l && o["dropdown__content--open"]), P = r.Children.map(y, (e, t) => /* @__PURE__ */ r.createElement("li", { className: o.dropdown__input, role: "option", id: `${x}-${t}`, "aria-selected": t === u }, r.isValidElement(e) && a.current && a.current[t] ? r.cloneElement(e, { ref: Y([e.props.ref, a.current[t]]) }) : e));
75
+ return /* @__PURE__ */ r.createElement("div", { className: o.dropdown, ref: p }, /* @__PURE__ */ r.createElement("span", { id: E, className: o.dropdown__label }, R), /* @__PURE__ */ r.createElement(
75
76
  "button",
76
77
  {
77
78
  type: "button",
78
- onClick: () => !a && N(),
79
+ onClick: () => !l && N(),
79
80
  className: U,
80
- ref: u,
81
+ ref: m,
81
82
  "data-testid": z,
82
- "data-analyticsid": G.Dropdown,
83
+ "data-analyticsid": J.Dropdown,
83
84
  disabled: i,
84
85
  "aria-labelledby": I,
85
86
  "aria-haspopup": "listbox",
86
- "aria-expanded": a
87
+ "aria-expanded": l
87
88
  },
88
- /* @__PURE__ */ t.createElement("span", { id: I, className: e.dropdown__toggle__label }, $),
89
- /* @__PURE__ */ t.createElement(
90
- Y,
89
+ /* @__PURE__ */ r.createElement("span", { id: I, className: o.dropdown__toggle__label }, $),
90
+ /* @__PURE__ */ r.createElement(
91
+ M,
91
92
  {
92
93
  color: i ? C.palette.neutral700 : C.palette.blueberry600,
93
- svgIcon: Z,
94
- className: e.dropdown__icon,
94
+ svgIcon: ee,
95
+ className: o.dropdown__icon,
95
96
  isHovered: !i && D,
96
- size: J.XSmall
97
+ size: Q.XSmall
97
98
  }
98
99
  )
99
- ), /* @__PURE__ */ t.createElement("div", { className: B, style: { width: b ? "100%" : `${T}px` } }, /* @__PURE__ */ t.createElement(
100
+ ), /* @__PURE__ */ r.createElement("div", { className: B, style: { width: b ? "100%" : `${T}px` } }, /* @__PURE__ */ r.createElement(
100
101
  "ul",
101
102
  {
102
- className: e.dropdown__options,
103
+ className: o.dropdown__options,
103
104
  role: "listbox",
104
105
  "aria-labelledby": E,
105
106
  tabIndex: -1,
106
- "aria-activedescendant": typeof m < "u" ? `${x}-${m}` : void 0,
107
+ "aria-activedescendant": typeof u < "u" ? `${x}-${u}` : void 0,
107
108
  ref: w
108
109
  },
109
- t.Children.map(y, (o, n) => {
110
- var l;
111
- return /* @__PURE__ */ t.createElement("li", { className: e.dropdown__input, role: "option", id: `${x}-${n}`, "aria-selected": n === m }, t.cloneElement(o, { ref: (l = d.current) == null ? void 0 : l[n] }));
112
- })
113
- ), !H && /* @__PURE__ */ t.createElement("div", { className: e.dropdown__close }, /* @__PURE__ */ t.createElement(Q, { onClick: f, fluid: !0, "aria-expanded": a }, A))));
114
- }, ye = ee;
110
+ P
111
+ ), !H && /* @__PURE__ */ r.createElement("div", { className: o.dropdown__close }, /* @__PURE__ */ r.createElement(Z, { onClick: f, fluid: !0, "aria-expanded": l }, A))));
112
+ }, he = re;
115
113
  export {
116
- M as DropdownMode,
117
- ye as default
114
+ oe as DropdownMode,
115
+ he as default
118
116
  };
119
117
  //# sourceMappingURL=Dropdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.js","sources":["../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport {\n AnalyticsId,\n IconSize,\n KeyboardEventKey,\n theme,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\n useSize,\n useToggle,\n useUuid,\n} from '../..';\nimport Button from '../Button';\nimport Icon from '../Icon';\nimport PlusSmall from '../Icons/PlusSmall';\n\nimport styles from './styles.module.scss';\n\nexport enum DropdownMode {\n onwhite = 'onwhite',\n ongrey = 'ongrey',\n onblueberry = 'onblueberry',\n oncherry = 'oncherry',\n}\n\nexport interface DropdownProps {\n /** Label for dropdown. Synlig for skjermlesere. */\n label: string;\n /** Tekst på knappen som åpner dropdownen */\n placeholder: string;\n /** Sets the dropdown content */\n children: React.ReactNode;\n /** Close button text */\n closeText?: string;\n /** No close button */\n noCloseButton?: boolean;\n /** Called when dropdown is open/closed. */\n onToggle?: (isOpen: boolean) => void;\n /** Om dropdown er åpen */\n open?: boolean;\n /** Changes the visuals of the dropdown */\n mode?: keyof typeof DropdownMode;\n /** Makes the background transparent */\n transparent?: boolean;\n /** Makes the background transparent */\n fluid?: boolean;\n /** Makes the dropdown disabled */\n disabled?: boolean;\n /** Sets the data-testid attribute on the dropdown button. */\n testId?: string;\n}\n\nconst Dropdown: React.FC<DropdownProps> = props => {\n const {\n label,\n placeholder,\n closeText = 'Lukk',\n noCloseButton = false,\n onToggle,\n open = false,\n children,\n mode = DropdownMode.onwhite,\n transparent = false,\n fluid = false,\n testId,\n disabled,\n } = props;\n const dropdownRef = useRef<HTMLDivElement>(null);\n const optionsRef = useRef<HTMLUListElement>(null);\n const { hoverRef: buttonRef, isHovered } = useHover<HTMLButtonElement>();\n const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);\n const inputRefList = useRef(React.Children.map(children, () => React.createRef<HTMLElement>()));\n const [currentIndex, setCurrentIndex] = useState<number>();\n const { width: buttonWidth } = useSize(buttonRef) || {};\n const labelId = useUuid();\n const toggleLabelId = useUuid();\n const optionIdPrefix = useUuid();\n\n const handleOpen = (): void => {\n toggleIsOpen();\n optionsRef.current?.focus();\n };\n\n const handleClose = (): void => {\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n event.preventDefault();\n\n if (!inputRefList.current) {\n return;\n }\n\n if (!isOpen) {\n handleOpen();\n return;\n } else if (event.key === KeyboardEventKey.Escape && isOpen) {\n handleClose();\n return;\n }\n\n const index = inputRefList.current.findIndex(x => x.current === event.target);\n let nextIndex = index;\n\n if (event.key === KeyboardEventKey.Home) {\n nextIndex = 0;\n } else if (event.key === KeyboardEventKey.End) {\n nextIndex = inputRefList.current.length - 1;\n } else if (event.key === KeyboardEventKey.ArrowDown && index < inputRefList.current.length - 1) {\n nextIndex = index + 1;\n } else if (event.key === KeyboardEventKey.ArrowUp && index > 0) {\n nextIndex = index - 1;\n } else if (event.key === KeyboardEventKey.Enter && index !== -1) {\n nextIndex = index;\n }\n if (nextIndex !== -1) {\n inputRefList.current[nextIndex].current?.focus();\n setCurrentIndex(nextIndex);\n }\n };\n\n useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [\n KeyboardEventKey.ArrowDown,\n KeyboardEventKey.ArrowUp,\n KeyboardEventKey.End,\n KeyboardEventKey.Enter,\n KeyboardEventKey.Escape,\n KeyboardEventKey.Home,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const toggleClasses = classNames(\n styles.dropdown__toggle,\n !disabled && {\n [styles['dropdown__toggle--on-white']]: mode === DropdownMode.onwhite,\n [styles['dropdown__toggle--on-grey']]: mode === DropdownMode.ongrey,\n [styles['dropdown__toggle--on-blueberry']]: mode === DropdownMode.onblueberry,\n [styles['dropdown__toggle--on-cherry']]: mode === DropdownMode.oncherry,\n [styles['dropdown__toggle--transparent']]: transparent,\n [styles['dropdown__toggle--fluid']]: fluid,\n [styles['dropdown__toggle--open']]: isOpen,\n }\n );\n\n const contentClasses = classNames(styles.dropdown__content, isOpen && styles['dropdown__content--open']);\n\n return (\n <div className={styles.dropdown} ref={dropdownRef}>\n <span id={labelId} className={styles.dropdown__label}>\n {label}\n </span>\n <button\n type=\"button\"\n onClick={() => !isOpen && handleOpen()}\n className={toggleClasses}\n ref={buttonRef}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Dropdown}\n disabled={disabled}\n aria-labelledby={toggleLabelId}\n aria-haspopup=\"listbox\"\n aria-expanded={isOpen}\n >\n <span id={toggleLabelId} className={styles.dropdown__toggle__label}>\n {placeholder}\n </span>\n <Icon\n color={disabled ? theme.palette.neutral700 : theme.palette.blueberry600}\n svgIcon={PlusSmall}\n className={styles.dropdown__icon}\n isHovered={!disabled && isHovered}\n size={IconSize.XSmall}\n />\n </button>\n <div className={contentClasses} style={{ width: fluid ? '100%' : `${buttonWidth}px` }}>\n <ul\n className={styles.dropdown__options}\n role=\"listbox\"\n aria-labelledby={labelId}\n tabIndex={-1}\n aria-activedescendant={typeof currentIndex !== 'undefined' ? `${optionIdPrefix}-${currentIndex}` : undefined}\n ref={optionsRef}\n >\n {React.Children.map(children, (child, index) => (\n <li className={styles.dropdown__input} role=\"option\" id={`${optionIdPrefix}-${index}`} aria-selected={index === currentIndex}>\n {React.cloneElement(child as React.ReactElement, { ref: inputRefList.current?.[index] })}\n </li>\n ))}\n </ul>\n {!noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose} fluid aria-expanded={isOpen}>\n {closeText}\n </Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"names":["DropdownMode","Dropdown","props","label","placeholder","closeText","noCloseButton","onToggle","open","children","mode","transparent","fluid","testId","disabled","dropdownRef","useRef","optionsRef","buttonRef","isHovered","useHover","isOpen","toggleIsOpen","useToggle","inputRefList","React","currentIndex","setCurrentIndex","useState","buttonWidth","useSize","labelId","useUuid","toggleLabelId","optionIdPrefix","handleOpen","_a","handleClose","useKeyboardEvent","event","KeyboardEventKey","index","x","nextIndex","useOutsideEvent","toggleClasses","classNames","styles","contentClasses","AnalyticsId","Icon","theme","PlusSmall","IconSize","child","Button","Dropdown$1"],"mappings":";;;;;;;;;;;;;;;AAsBY,IAAAA,sBAAAA,OACVA,EAAA,UAAU,WACVA,EAAA,SAAS,UACTA,EAAA,cAAc,eACdA,EAAA,WAAW,YAJDA,IAAAA,KAAA,CAAA,CAAA;AAkCZ,MAAMC,KAAoC,CAASC,MAAA;AAC3C,QAAA;AAAA,IACJ,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,eAAAC,IAAgB;AAAA,IAChB,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,UAAAC;AAAA,IAC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AA,cAAC8B,KAAO,SAASlB,GAAa,OAAK,IAAC,iBAAehB,KAChDhB,CACH,CACF,CAEJ,CACF;AAEJ,GAEAmD,KAAevD;"}
1
+ {"version":3,"file":"Dropdown.js","sources":["../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport {\n AnalyticsId,\n IconSize,\n KeyboardEventKey,\n theme,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\n useSize,\n useToggle,\n useUuid,\n} from '../..';\nimport { mergeRefs } from '../../utils/refs';\nimport Button from '../Button';\nimport Icon from '../Icon';\nimport PlusSmall from '../Icons/PlusSmall';\n\nimport styles from './styles.module.scss';\n\nexport enum DropdownMode {\n onwhite = 'onwhite',\n ongrey = 'ongrey',\n onblueberry = 'onblueberry',\n oncherry = 'oncherry',\n}\n\nexport interface DropdownProps {\n /** Label for dropdown. Synlig for skjermlesere. */\n label: string;\n /** Tekst på knappen som åpner dropdownen */\n placeholder: string;\n /** Sets the dropdown content */\n children: React.ReactNode;\n /** Close button text */\n closeText?: string;\n /** No close button */\n noCloseButton?: boolean;\n /** Called when dropdown is open/closed. */\n onToggle?: (isOpen: boolean) => void;\n /** Om dropdown er åpen */\n open?: boolean;\n /** Changes the visuals of the dropdown */\n mode?: keyof typeof DropdownMode;\n /** Makes the background transparent */\n transparent?: boolean;\n /** Makes the background transparent */\n fluid?: boolean;\n /** Makes the dropdown disabled */\n disabled?: boolean;\n /** Sets the data-testid attribute on the dropdown button. */\n testId?: string;\n}\n\nconst Dropdown: React.FC<DropdownProps> = props => {\n const {\n label,\n placeholder,\n closeText = 'Lukk',\n noCloseButton = false,\n onToggle,\n open = false,\n children,\n mode = DropdownMode.onwhite,\n transparent = false,\n fluid = false,\n testId,\n disabled,\n } = props;\n const dropdownRef = useRef<HTMLDivElement>(null);\n const optionsRef = useRef<HTMLUListElement>(null);\n const { hoverRef: buttonRef, isHovered } = useHover<HTMLButtonElement>();\n const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);\n const inputRefList = useRef(React.Children.map(children, () => React.createRef<HTMLElement>()));\n const [currentIndex, setCurrentIndex] = useState<number>();\n const { width: buttonWidth } = useSize(buttonRef) || {};\n const labelId = useUuid();\n const toggleLabelId = useUuid();\n const optionIdPrefix = useUuid();\n\n const handleOpen = (): void => {\n toggleIsOpen();\n optionsRef.current?.focus();\n };\n\n const handleClose = (): void => {\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n event.preventDefault();\n\n if (!inputRefList.current) {\n return;\n }\n\n if (!isOpen) {\n handleOpen();\n return;\n } else if (event.key === KeyboardEventKey.Escape && isOpen) {\n handleClose();\n return;\n }\n\n const index = inputRefList.current.findIndex(x => x.current === event.target);\n let nextIndex = index;\n\n if (event.key === KeyboardEventKey.Home) {\n nextIndex = 0;\n } else if (event.key === KeyboardEventKey.End) {\n nextIndex = inputRefList.current.length - 1;\n } else if (event.key === KeyboardEventKey.ArrowDown && index < inputRefList.current.length - 1) {\n nextIndex = index + 1;\n } else if (event.key === KeyboardEventKey.ArrowUp && index > 0) {\n nextIndex = index - 1;\n } else if (event.key === KeyboardEventKey.Enter && index !== -1) {\n nextIndex = index;\n }\n if (nextIndex !== -1) {\n inputRefList.current[nextIndex].current?.focus();\n setCurrentIndex(nextIndex);\n }\n };\n\n useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [\n KeyboardEventKey.ArrowDown,\n KeyboardEventKey.ArrowUp,\n KeyboardEventKey.End,\n KeyboardEventKey.Enter,\n KeyboardEventKey.Escape,\n KeyboardEventKey.Home,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const toggleClasses = classNames(\n styles.dropdown__toggle,\n !disabled && {\n [styles['dropdown__toggle--on-white']]: mode === DropdownMode.onwhite,\n [styles['dropdown__toggle--on-grey']]: mode === DropdownMode.ongrey,\n [styles['dropdown__toggle--on-blueberry']]: mode === DropdownMode.onblueberry,\n [styles['dropdown__toggle--on-cherry']]: mode === DropdownMode.oncherry,\n [styles['dropdown__toggle--transparent']]: transparent,\n [styles['dropdown__toggle--fluid']]: fluid,\n [styles['dropdown__toggle--open']]: isOpen,\n }\n );\n\n const contentClasses = classNames(styles.dropdown__content, isOpen && styles['dropdown__content--open']);\n\n const renderChildren = React.Children.map(children, (child, index) => (\n <li className={styles.dropdown__input} role=\"option\" id={`${optionIdPrefix}-${index}`} aria-selected={index === currentIndex}>\n {React.isValidElement(child) && inputRefList.current && inputRefList.current[index]\n ? React.cloneElement(child as React.ReactElement, { ref: mergeRefs([child.props.ref, inputRefList.current[index]]) })\n : child}\n </li>\n ));\n\n return (\n <div className={styles.dropdown} ref={dropdownRef}>\n <span id={labelId} className={styles.dropdown__label}>\n {label}\n </span>\n <button\n type=\"button\"\n onClick={() => !isOpen && handleOpen()}\n className={toggleClasses}\n ref={buttonRef}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Dropdown}\n disabled={disabled}\n aria-labelledby={toggleLabelId}\n aria-haspopup=\"listbox\"\n aria-expanded={isOpen}\n >\n <span id={toggleLabelId} className={styles.dropdown__toggle__label}>\n {placeholder}\n </span>\n <Icon\n color={disabled ? theme.palette.neutral700 : theme.palette.blueberry600}\n svgIcon={PlusSmall}\n className={styles.dropdown__icon}\n isHovered={!disabled && isHovered}\n size={IconSize.XSmall}\n />\n </button>\n <div className={contentClasses} style={{ width: fluid ? '100%' : `${buttonWidth}px` }}>\n <ul\n className={styles.dropdown__options}\n role=\"listbox\"\n aria-labelledby={labelId}\n tabIndex={-1}\n aria-activedescendant={typeof currentIndex !== 'undefined' ? `${optionIdPrefix}-${currentIndex}` : undefined}\n ref={optionsRef}\n >\n {renderChildren}\n </ul>\n {!noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose} fluid aria-expanded={isOpen}>\n {closeText}\n </Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"names":["DropdownMode","Dropdown","props","label","placeholder","closeText","noCloseButton","onToggle","open","children","mode","transparent","fluid","testId","disabled","dropdownRef","useRef","optionsRef","buttonRef","isHovered","useHover","isOpen","toggleIsOpen","useToggle","inputRefList","React","currentIndex","setCurrentIndex","useState","buttonWidth","useSize","labelId","useUuid","toggleLabelId","optionIdPrefix","handleOpen","_a","handleClose","useKeyboardEvent","event","KeyboardEventKey","index","x","nextIndex","useOutsideEvent","toggleClasses","classNames","styles","contentClasses","renderChildren","child","mergeRefs","AnalyticsId","Icon","theme","PlusSmall","IconSize","Button","Dropdown$1"],"mappings":";;;;;;;;;;;;;;;;AAuBY,IAAAA,uBAAAA,OACVA,EAAA,UAAU,WACVA,EAAA,SAAS,UACTA,EAAA,cAAc,eACdA,EAAA,WAAW,YAJDA,IAAAA,MAAA,CAAA,CAAA;AAkCZ,MAAMC,KAAoC,CAASC,MAAA;AAC3C,QAAA;AAAA,IACJ,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,eAAAC,IAAgB;AAAA,IAChB,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,aAAAC,IAAc;AAAA,IACd,OAAAC,IAAQ;AAAA,IACR,QAAAC;AAAA,IACA,UAAAC;AAAA,EACE,IAAAZ,GACEa,IAAcC,EAAuB,IAAI,GACzCC,IAAaD,EAAyB,IAAI,GAC1C,EAAE,UAAUE,GAAW,WAAAC,MAAcC,EAA4B,GACjE,EAAE,OAAOC,GAAQ,aAAaC,EAAA,IAAiBC,EAAU,CAACT,KAAYN,GAAMD,CAAQ,GACpFiB,IAAeR,EAAOS,EAAM,SAAS,IAAIhB,GAAU,MAAMgB,EAAM,UAAwB,CAAA,CAAC,GACxF,CAACC,GAAcC,CAAe,IAAIC,EAAiB,GACnD,EAAE,OAAOC,EAAA,IAAgBC,EAAQZ,CAAS,KAAK,IAC/Ca,IAAUC,KAC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AAA,MACA,mBAAiBmB;AAAA,MACjB,iBAAc;AAAA,MACd,iBAAeZ;AAAA,IAAA;AAAA,oCAEd,QAAK,EAAA,IAAIY,GAAe,WAAWc,EAAO,2BACxC3C,CACH;AAAA,IACAqB,gBAAAA,EAAA;AAAA,MAAC4B;AAAA,MAAA;AAAA,QACC,OAAOvC,IAAWwC,EAAM,QAAQ,aAAaA,EAAM,QAAQ;AAAA,QAC3D,SAASC;AAAA,QACT,WAAWR,EAAO;AAAA,QAClB,WAAW,CAACjC,KAAYK;AAAA,QACxB,MAAMqC,EAAS;AAAA,MAAA;AAAA,IACjB;AAAA,EAAA,GAEF/B,gBAAAA,EAAA,cAAC,OAAI,EAAA,WAAWuB,GAAgB,OAAO,EAAE,OAAOpC,IAAQ,SAAS,GAAGiB,CAAW,KAC7E,EAAA,GAAAJ,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWsB,EAAO;AAAA,MAClB,MAAK;AAAA,MACL,mBAAiBhB;AAAA,MACjB,UAAU;AAAA,MACV,yBAAuB,OAAOL,IAAiB,MAAc,GAAGQ,CAAc,IAAIR,CAAY,KAAK;AAAA,MACnG,KAAKT;AAAA,IAAA;AAAA,IAEJgC;AAAA,EAAA,GAEF,CAAC3C,qCACC,OAAI,EAAA,WAAWyC,EAAO,gBACrB,GAAAtB,gBAAAA,EAAA,cAACgC,KAAO,SAASpB,GAAa,OAAK,IAAC,iBAAehB,KAChDhB,CACH,CACF,CAEJ,CACF;AAEJ,GAEAqD,KAAezD;"}
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "git+https://github.com/helsenorge/designsystem.git"
8
8
  },
9
9
  "homepage": "https://helsenorge.design",
10
- "version": "6.4.0",
10
+ "version": "6.5.0",
11
11
  "author": "Helsenorge",
12
12
  "license": "MIT",
13
13
  "peerDependencies": {