@helsenorge/designsystem-react 12.7.0 → 12.8.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.
Files changed (67) hide show
  1. package/AsChildSlot.js +74 -0
  2. package/AsChildSlot.js.map +1 -0
  3. package/CHANGELOG.md +37 -5
  4. package/Drawer.js +58 -4
  5. package/Drawer.js.map +1 -1
  6. package/HN.Designsystem.Dropdown.nb-NO.js +13 -0
  7. package/HN.Designsystem.Dropdown.nb-NO.js.map +1 -0
  8. package/HelpDetails.js +1 -1
  9. package/LinkList.js +1 -0
  10. package/LinkList.js.map +1 -1
  11. package/SingleSelectItem.js +96 -0
  12. package/SingleSelectItem.js.map +1 -0
  13. package/clamp.js +11 -0
  14. package/clamp.js.map +1 -0
  15. package/components/ArticleTeaser/styles.module.scss +3 -5
  16. package/components/AsChildSlot/AsChildSlot.d.ts +23 -0
  17. package/components/AsChildSlot/AsChildSlot.test.d.ts +1 -0
  18. package/components/AsChildSlot/index.d.ts +3 -0
  19. package/components/AsChildSlot/index.js +6 -0
  20. package/components/AsChildSlot/index.js.map +1 -0
  21. package/components/AsChildSlot/styles.module.scss +13 -0
  22. package/components/AsChildSlot/styles.module.scss.d.ts +9 -0
  23. package/components/Drawer/styles.module.scss +45 -26
  24. package/components/Drawer/styles.module.scss.d.ts +5 -0
  25. package/components/Dropdown/Dropdown.d.ts +19 -21
  26. package/components/Dropdown/Dropdown.test.d.ts +1 -0
  27. package/components/Dropdown/SingleSelect/SingleSelect.d.ts +18 -0
  28. package/components/Dropdown/SingleSelect/SingleSelect.test.d.ts +1 -0
  29. package/components/Dropdown/SingleSelect/SingleSelectItem.d.ts +21 -0
  30. package/components/Dropdown/SingleSelect/index.d.ts +3 -0
  31. package/components/Dropdown/SingleSelect/index.js +6 -0
  32. package/components/Dropdown/SingleSelect/index.js.map +1 -0
  33. package/components/Dropdown/SingleSelect/styles.module.scss +54 -0
  34. package/components/Dropdown/SingleSelect/styles.module.scss.d.ts +14 -0
  35. package/components/Dropdown/index.js +140 -76
  36. package/components/Dropdown/index.js.map +1 -1
  37. package/components/Dropdown/styles.module.scss +90 -136
  38. package/components/Dropdown/styles.module.scss.d.ts +8 -9
  39. package/components/DropdownOld/DropdownOld.d.ts +42 -0
  40. package/components/DropdownOld/index.d.ts +3 -0
  41. package/components/DropdownOld/index.js +194 -0
  42. package/components/DropdownOld/index.js.map +1 -0
  43. package/components/DropdownOld/resourceHelper.d.ts +3 -0
  44. package/components/DropdownOld/styles.module.scss +230 -0
  45. package/components/DropdownOld/styles.module.scss.d.ts +25 -0
  46. package/components/Icons/EmoticonAnnoyed.js +8 -11
  47. package/components/Icons/EmoticonAnnoyed.js.map +1 -1
  48. package/components/Icons/EmoticonDelighted.js +8 -4
  49. package/components/Icons/EmoticonDelighted.js.map +1 -1
  50. package/components/Icons/EmoticonDisappointed.js +8 -4
  51. package/components/Icons/EmoticonDisappointed.js.map +1 -1
  52. package/components/Icons/EmoticonHappy.js +8 -4
  53. package/components/Icons/EmoticonHappy.js.map +1 -1
  54. package/components/Icons/EmoticonMeh.js +8 -4
  55. package/components/Icons/EmoticonMeh.js.map +1 -1
  56. package/components/LinkList/styles.module.scss +47 -61
  57. package/components/LinkList/styles.module.scss.d.ts +1 -0
  58. package/components/ListEditMode/styles.module.scss +1 -0
  59. package/components/NotificationPanel/index.js +3 -1
  60. package/components/NotificationPanel/index.js.map +1 -1
  61. package/components/NotificationPanel/styles.module.scss +10 -5
  62. package/designsystem-react.css +10 -0
  63. package/package.json +1 -1
  64. package/scss/supernova/styles/colors.css +10 -0
  65. package/use-animate.js +1 -7
  66. package/use-animate.js.map +1 -1
  67. /package/{resources/index.d.ts → components/DropdownOld/DropdownOld.test.d.ts} +0 -0
@@ -1,27 +1,30 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import React__default, { useRef, useId, useEffect } from "react";
3
+ import { u as useFloating, f as autoUpdate, o as offset, s as shift, j as size } from "../../floating-ui.react.js";
3
4
  import classNames from "classnames";
4
- import { theme } from "../../theme/index.js";
5
+ import "../../theme/grid.js";
5
6
  import "../../hooks/useBreakpoint.js";
6
7
  import { useHover } from "../../hooks/useHover.js";
7
8
  import { useToggle } from "../../hooks/useToggle.js";
8
9
  import { useKeyboardEvent } from "../../hooks/useKeyboardEvent.js";
9
10
  import { useOutsideEvent } from "../../hooks/useOutsideEvent.js";
10
- import { LanguageLocales, ZIndex, KeyboardEventKey, AnalyticsId, IconSize } from "../../constants.js";
11
+ import { LanguageLocales, ZIndex, IconSize, KeyboardEventKey, AnalyticsId } from "../../constants.js";
12
+ import { n as nbNO, e as enGB } from "../../HN.Designsystem.Dropdown.nb-NO.js";
13
+ import { a as SingleSelect, S as SingleSelectItem } from "../../SingleSelectItem.js";
14
+ import { useIsMobileBreakpoint } from "../../hooks/useIsMobileBreakpoint.js";
15
+ import { isComponent } from "../../utils/component.js";
11
16
  import { useLanguage } from "../../utils/language.js";
12
17
  import { mergeRefs } from "../../utils/refs.js";
13
18
  import { B as Button } from "../../Button.js";
19
+ import { C as Checkbox } from "../../Checkbox.js";
14
20
  import { I as Icon } from "../../Icon.js";
21
+ import ChevronDown from "../Icons/ChevronDown.js";
22
+ import ChevronUp from "../Icons/ChevronUp.js";
15
23
  import PlusSmall from "../Icons/PlusSmall.js";
24
+ import { L as Label } from "../../Label.js";
25
+ import { L as LazyIcon } from "../../LazyIcon.js";
16
26
  import styles from "./styles.module.scss";
17
- const closeText$1 = "Close";
18
- const enGB = {
19
- closeText: closeText$1
20
- };
21
- const closeText = "Lukk";
22
- const nbNO = {
23
- closeText
24
- };
27
+ import { c as clamp } from "../../clamp.js";
25
28
  const getResources = (language) => {
26
29
  switch (language) {
27
30
  case LanguageLocales.ENGLISH:
@@ -31,47 +34,82 @@ const getResources = (language) => {
31
34
  return nbNO;
32
35
  }
33
36
  };
34
- var DropdownOnColor = /* @__PURE__ */ ((DropdownOnColor2) => {
35
- DropdownOnColor2["onwhite"] = "onwhite";
36
- DropdownOnColor2["ongrey"] = "ongrey";
37
- DropdownOnColor2["onblueberry"] = "onblueberry";
38
- DropdownOnColor2["oncherry"] = "oncherry";
39
- return DropdownOnColor2;
40
- })(DropdownOnColor || {});
41
- const Dropdown = (props) => {
37
+ const DropdownBase = (props) => {
42
38
  const {
43
- label,
44
- placeholder,
39
+ triggerText,
45
40
  noCloseButton = false,
46
41
  onToggle,
47
42
  dropdownMinWidth,
43
+ triggerMinWidth,
48
44
  open = false,
49
45
  children,
50
- onColor = "onwhite",
51
- transparent = false,
52
- fluid = false,
53
46
  testId,
54
47
  disabled,
55
48
  zIndex = ZIndex.PopOver,
56
- resources
49
+ resources,
50
+ svgIcon,
51
+ variant = "fill"
57
52
  } = props;
58
53
  const dropdownRef = useRef(null);
59
54
  const optionsRef = useRef(null);
55
+ const childrenRefList = useRef(React__default.Children.map(children, () => React__default.createRef()));
60
56
  const { hoverRef: buttonRef, isHovered } = useHover();
61
57
  const openedByKeyboard = useRef(false);
62
58
  const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);
63
- const inputRefList = useRef(React__default.Children.map(children, () => React__default.createRef()));
64
- const labelId = useId();
65
- const toggleLabelId = useId();
59
+ const isMobile = useIsMobileBreakpoint();
60
+ const triggerActualMinWidth = variant !== "borderless" && typeof triggerMinWidth != "undefined" ? `${triggerMinWidth}px` : "auto";
61
+ const triggerMinWidthLimit = isMobile ? 96 : 112;
62
+ const maxWidth = isMobile ? 384 : 400;
63
+ const toggleTextId = useId();
66
64
  const optionIdPrefix = useId();
67
65
  const contentId = useId();
66
+ const leftIconProps = {
67
+ className: styles["dropdown__left-icon"],
68
+ size: IconSize.XSmall,
69
+ isHovered: !disabled && isHovered
70
+ };
71
+ const isSingleSelect = React__default.Children.toArray(children).every(
72
+ (child) => React__default.isValidElement(child) && isComponent(child, SingleSelectItem)
73
+ );
74
+ const isMultiSelect = React__default.Children.toArray(children).every(
75
+ (child) => React__default.isValidElement(child) && isComponent(child, Checkbox)
76
+ );
68
77
  const { language } = useLanguage(LanguageLocales.NORWEGIAN);
69
78
  const defaultResources = getResources(language);
70
79
  const mergedResources = {
71
80
  ...defaultResources,
72
- ...resources,
73
- closeText: props.closeText ?? (resources == null ? void 0 : resources.closeText) ?? defaultResources.closeText
81
+ ...resources
74
82
  };
83
+ const toggleClasses = classNames(styles.dropdown__toggle, {
84
+ [styles["dropdown__toggle--open"]]: isOpen && !disabled,
85
+ [styles["dropdown__toggle--with-icon"]]: typeof svgIcon !== "undefined",
86
+ [styles["dropdown__toggle--transparent"]]: variant === "transparent",
87
+ [styles["dropdown__toggle--borderless"]]: variant === "borderless"
88
+ });
89
+ const contentClasses = classNames(styles.dropdown__content, isOpen && styles["dropdown__content--open"]);
90
+ const listItemClasses = classNames(styles["dropdown__list-item"], { [styles["dropdown__list-item--single-select"]]: isSingleSelect });
91
+ const { refs, floatingStyles } = useFloating({
92
+ placement: "bottom",
93
+ middleware: [
94
+ offset(8),
95
+ shift({ padding: 8 }),
96
+ size({
97
+ apply({ availableWidth, availableHeight, elements, rects }) {
98
+ const triggerW = rects.reference.width;
99
+ const minProp = typeof dropdownMinWidth !== "undefined" ? clamp(0, maxWidth, dropdownMinWidth) : 0;
100
+ const targetW = Math.max(triggerW, minProp);
101
+ const finalW = Math.min(availableWidth, targetW);
102
+ Object.assign(elements.floating.style, {
103
+ width: `${finalW}px`,
104
+ maxHeight: `${availableHeight}px`,
105
+ overflowY: "auto",
106
+ overflowX: "hidden"
107
+ });
108
+ }
109
+ })
110
+ ],
111
+ whileElementsMounted: autoUpdate
112
+ });
75
113
  const handleOpen = (isKeyboard) => {
76
114
  openedByKeyboard.current = isKeyboard;
77
115
  toggleIsOpen();
@@ -84,41 +122,50 @@ const Dropdown = (props) => {
84
122
  useEffect(() => {
85
123
  var _a, _b;
86
124
  if (isOpen && openedByKeyboard.current) {
87
- const firstEnabled = (_a = inputRefList.current) == null ? void 0 : _a.find((r) => r.current && !r.current.hasAttribute("disabled"));
125
+ const firstEnabled = (_a = childrenRefList.current) == null ? void 0 : _a.find((r) => r.current && !r.current.hasAttribute("disabled"));
88
126
  (_b = firstEnabled == null ? void 0 : firstEnabled.current) == null ? void 0 : _b.focus();
89
127
  openedByKeyboard.current = false;
90
128
  }
91
129
  }, [isOpen]);
130
+ const focusByIndex = (nextIndex) => {
131
+ var _a, _b, _c;
132
+ (_c = (_b = (_a = childrenRefList.current) == null ? void 0 : _a[nextIndex]) == null ? void 0 : _b.current) == null ? void 0 : _c.focus();
133
+ };
134
+ const isListNavKey = (key) => key === KeyboardEventKey.ArrowDown || key === KeyboardEventKey.ArrowUp || key === KeyboardEventKey.Home || key === KeyboardEventKey.End;
92
135
  const handleKeyboardNavigation = (event) => {
93
- var _a;
94
- if (!inputRefList.current) {
136
+ if (!childrenRefList.current) return;
137
+ const key = event.key;
138
+ if (key === KeyboardEventKey.Escape) {
139
+ if (isOpen) {
140
+ event.preventDefault();
141
+ handleClose();
142
+ }
95
143
  return;
96
144
  }
97
- if (event.key === KeyboardEventKey.Escape) {
98
- if (isOpen) handleClose();
145
+ if (!isOpen) {
146
+ if (isListNavKey(key)) {
147
+ event.preventDefault();
148
+ handleOpen(true);
149
+ }
99
150
  return;
100
151
  }
101
- if (!isOpen) {
102
- handleOpen(true);
103
- event.preventDefault();
152
+ if (!isListNavKey(key)) {
104
153
  return;
105
154
  }
106
- const index = inputRefList.current.findIndex((x) => x.current === event.target);
155
+ const index = childrenRefList.current.findIndex((x) => x.current === event.target);
107
156
  let nextIndex = index;
108
- if (event.key === KeyboardEventKey.Home) {
157
+ if (key === KeyboardEventKey.Home) {
109
158
  nextIndex = 0;
110
- } else if (event.key === KeyboardEventKey.End) {
111
- nextIndex = inputRefList.current.length - 1;
112
- } else if (event.key === KeyboardEventKey.ArrowDown && index < inputRefList.current.length - 1) {
159
+ } else if (key === KeyboardEventKey.End) {
160
+ nextIndex = childrenRefList.current.length - 1;
161
+ } else if (key === KeyboardEventKey.ArrowDown && index < childrenRefList.current.length - 1) {
113
162
  nextIndex = index + 1;
114
- } else if (event.key === KeyboardEventKey.ArrowUp && index > 0) {
163
+ } else if (key === KeyboardEventKey.ArrowUp && index > 0) {
115
164
  nextIndex = index - 1;
116
- } else if (event.key === KeyboardEventKey.Enter && index !== -1) {
117
- nextIndex = index;
118
165
  }
119
- if (nextIndex !== -1 && event.key !== KeyboardEventKey.Space) {
166
+ if (nextIndex !== -1) {
120
167
  event.preventDefault();
121
- (_a = inputRefList.current[nextIndex].current) == null ? void 0 : _a.focus();
168
+ focusByIndex(nextIndex);
122
169
  }
123
170
  };
124
171
  useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [
@@ -131,48 +178,54 @@ const Dropdown = (props) => {
131
178
  KeyboardEventKey.Space
132
179
  ]);
133
180
  useOutsideEvent(dropdownRef, () => isOpen && handleClose());
134
- const toggleClasses = classNames(
135
- styles.dropdown__toggle,
136
- !disabled && {
137
- [styles["dropdown__toggle--on-white"]]: onColor === "onwhite",
138
- [styles["dropdown__toggle--on-grey"]]: onColor === "ongrey",
139
- [styles["dropdown__toggle--on-blueberry"]]: onColor === "onblueberry",
140
- [styles["dropdown__toggle--on-cherry"]]: onColor === "oncherry",
141
- [styles["dropdown__toggle--transparent"]]: transparent,
142
- [styles["dropdown__toggle--fluid"]]: fluid,
143
- [styles["dropdown__toggle--open"]]: isOpen
144
- }
145
- );
146
- const contentClasses = classNames(styles.dropdown__content, isOpen && styles["dropdown__content--open"]);
147
181
  const renderChildren = React__default.Children.map(children, (child, index) => {
148
- return /* @__PURE__ */ jsx("li", { className: styles.dropdown__input, id: `${optionIdPrefix}-${index}`, children: React__default.isValidElement(child) && inputRefList.current && inputRefList.current[index] ? React__default.cloneElement(child, {
149
- ref: mergeRefs([child.props.ref, inputRefList.current[index]])
150
- }) : child });
182
+ return /* @__PURE__ */ jsx("li", { className: listItemClasses, id: `${optionIdPrefix}-${index}`, children: React__default.isValidElement(child) && childrenRefList.current && childrenRefList.current[index] ? (() => {
183
+ var _a;
184
+ const baseProps = {
185
+ ref: mergeRefs([child.props.ref, childrenRefList.current[index]])
186
+ };
187
+ if (isMultiSelect) {
188
+ const label = child.props.label;
189
+ if (React__default.isValidElement(label) && isComponent(label, Label)) {
190
+ return React__default.cloneElement(child, {
191
+ ...baseProps,
192
+ label: React__default.cloneElement(label, {
193
+ labelClassName: classNames((_a = label.props) == null ? void 0 : _a.labelClassName, styles["dropdown__multiselect-item"])
194
+ })
195
+ });
196
+ }
197
+ }
198
+ return React__default.cloneElement(child, baseProps);
199
+ })() : child });
151
200
  });
152
201
  return /* @__PURE__ */ jsxs("div", { className: styles.dropdown, ref: dropdownRef, children: [
153
- /* @__PURE__ */ jsx("span", { id: labelId, className: styles.dropdown__label, children: label }),
154
202
  /* @__PURE__ */ jsxs(
155
203
  "button",
156
204
  {
157
205
  type: "button",
158
206
  onClick: () => handleOpen(false),
159
207
  className: toggleClasses,
160
- ref: buttonRef,
208
+ ref: mergeRefs([buttonRef, refs.setReference]),
161
209
  "data-testid": testId,
162
210
  "data-analyticsid": AnalyticsId.Dropdown,
163
211
  disabled,
164
- "aria-labelledby": toggleLabelId,
212
+ "aria-labelledby": toggleTextId,
165
213
  "aria-haspopup": true,
166
214
  "aria-controls": contentId,
167
215
  "aria-expanded": isOpen,
216
+ style: {
217
+ width: triggerActualMinWidth,
218
+ maxWidth: "100%",
219
+ minWidth: `${triggerMinWidthLimit}px`
220
+ },
168
221
  children: [
169
- /* @__PURE__ */ jsx("span", { id: toggleLabelId, className: styles.dropdown__toggle__label, children: placeholder }),
222
+ svgIcon && /* @__PURE__ */ jsx(Fragment, { children: typeof svgIcon === "string" ? /* @__PURE__ */ jsx(LazyIcon, { ...leftIconProps, iconName: svgIcon }) : /* @__PURE__ */ jsx(Icon, { ...leftIconProps, svgIcon }) }),
223
+ /* @__PURE__ */ jsx("span", { id: toggleTextId, className: styles.dropdown__toggle__text, children: triggerText }),
170
224
  /* @__PURE__ */ jsx(
171
225
  Icon,
172
226
  {
173
- color: disabled ? theme.palette.neutral700 : theme.palette.blueberry600,
174
- svgIcon: PlusSmall,
175
- className: styles.dropdown__icon,
227
+ svgIcon: !isSingleSelect ? PlusSmall : isOpen ? ChevronUp : ChevronDown,
228
+ className: styles["dropdown__right-icon"],
176
229
  isHovered: !disabled && isHovered,
177
230
  size: IconSize.XSmall
178
231
  }
@@ -185,17 +238,28 @@ const Dropdown = (props) => {
185
238
  {
186
239
  id: contentId,
187
240
  className: contentClasses,
188
- style: { width: fluid ? "100%" : `auto`, minWidth: dropdownMinWidth ?? "auto", zIndex },
241
+ ref: refs.setFloating,
242
+ style: {
243
+ ...floatingStyles,
244
+ zIndex
245
+ },
189
246
  children: [
190
- /* @__PURE__ */ jsx("ul", { className: styles.dropdown__options, role: "group", "aria-labelledby": labelId, tabIndex: -1, ref: optionsRef, children: renderChildren }),
191
- !noCloseButton && /* @__PURE__ */ jsx("div", { className: styles.dropdown__close, children: /* @__PURE__ */ jsx(Button, { onClick: handleClose, children: mergedResources.closeText }) })
247
+ /* @__PURE__ */ jsxs("ul", { className: styles.dropdown__options, role: "group", "aria-labelledby": toggleTextId, tabIndex: -1, ref: optionsRef, children: [
248
+ isSingleSelect && /* @__PURE__ */ jsx(SingleSelect, { onValueChange: () => handleClose(), children: renderChildren }),
249
+ isMultiSelect && renderChildren
250
+ ] }),
251
+ !isSingleSelect && !noCloseButton && /* @__PURE__ */ jsx("div", { className: styles.dropdown__close, children: /* @__PURE__ */ jsx(Button, { onClick: handleClose, children: mergedResources.closeText }) })
192
252
  ]
193
- }
253
+ },
254
+ dropdownMinWidth ?? "auto"
194
255
  )
195
256
  ] });
196
257
  };
258
+ const Dropdown = DropdownBase;
259
+ Dropdown.SingleSelectItem = SingleSelectItem;
260
+ DropdownBase.displayName = "Dropdown";
197
261
  export {
198
- DropdownOnColor,
262
+ DropdownBase,
199
263
  Dropdown as default
200
264
  };
201
265
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/Dropdown/resourceHelper.ts","../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import { LanguageLocales } from '../../constants';\nimport enGB from '../../resources/HN.Designsystem.Dropdown.en-GB.json';\nimport nbNO from '../../resources/HN.Designsystem.Dropdown.nb-NO.json';\nimport { HNDesignsystemDropdown } from '../../resources/Resources';\n\nexport const getResources = (language: LanguageLocales): HNDesignsystemDropdown => {\n switch (language) {\n case LanguageLocales.ENGLISH:\n return enGB;\n case LanguageLocales.NORWEGIAN:\n default:\n return nbNO;\n }\n};\n","import React, { useEffect, useRef, useId } from 'react';\n\nimport classNames from 'classnames';\n\nimport {\n AnalyticsId,\n IconSize,\n KeyboardEventKey,\n LanguageLocales,\n ZIndex,\n theme,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\n useToggle,\n} from '../..';\nimport { getResources } from './resourceHelper';\nimport { HNDesignsystemDropdown } from '../../resources/Resources';\nimport { useLanguage } from '../../utils/language';\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 DropdownOnColor {\n onwhite = 'onwhite',\n ongrey = 'ongrey',\n onblueberry = 'onblueberry',\n oncherry = 'oncherry',\n}\n\nexport interface DropdownProps {\n /** Label for dropdown. Visible for screen readers */\n label: string;\n /** Text on the trigger button that opens the dropdown */\n placeholder: string;\n /** Sets the dropdown content */\n children: React.ReactNode;\n /** @deprecated Close button text */\n closeText?: string;\n /** Minimum width for the dropdown in pixels. Does not affect trigger button */\n dropdownMinWidth?: number;\n /** No close button */\n noCloseButton?: boolean;\n /** Called when dropdown is open/closed */\n onToggle?: (isOpen: boolean) => void;\n /** Whether the dropdown is open or not */\n open?: boolean;\n /** Changes the visuals of the dropdown */\n onColor?: keyof typeof DropdownOnColor;\n /** Makes the background of the trigger transparent */\n transparent?: boolean;\n /** Makes the width of the full component adjust to its parent */\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 /** Overrides the default z-index of the DropDownContent */\n zIndex?: number;\n /** Resources for component */\n resources?: Partial<HNDesignsystemDropdown>;\n}\n\nconst Dropdown: React.FC<DropdownProps> = props => {\n const {\n label,\n placeholder,\n noCloseButton = false,\n onToggle,\n dropdownMinWidth,\n open = false,\n children,\n onColor = DropdownOnColor.onwhite,\n transparent = false,\n fluid = false,\n testId,\n disabled,\n zIndex = ZIndex.PopOver,\n resources,\n } = props;\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const optionsRef = useRef<HTMLUListElement>(null);\n const { hoverRef: buttonRef, isHovered } = useHover<HTMLButtonElement>();\n const openedByKeyboard = useRef<boolean>(false);\n const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);\n const inputRefList = useRef(React.Children.map(children, () => React.createRef<HTMLElement>()));\n const labelId = useId();\n const toggleLabelId = useId();\n const optionIdPrefix = useId();\n const contentId = useId();\n const { language } = useLanguage<LanguageLocales>(LanguageLocales.NORWEGIAN);\n const defaultResources = getResources(language);\n\n const mergedResources: HNDesignsystemDropdown = {\n ...defaultResources,\n ...resources,\n closeText: props.closeText ?? resources?.closeText ?? defaultResources.closeText,\n };\n\n const handleOpen = (isKeyboard: boolean): void => {\n openedByKeyboard.current = isKeyboard;\n toggleIsOpen();\n };\n\n const handleClose = (): void => {\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n useEffect(() => {\n if (isOpen && openedByKeyboard.current) {\n const firstEnabled = inputRefList.current?.find(r => r.current && !r.current.hasAttribute('disabled'));\n firstEnabled?.current?.focus();\n openedByKeyboard.current = false;\n }\n }, [isOpen]);\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n if (!inputRefList.current) {\n return;\n }\n\n if (event.key === KeyboardEventKey.Escape) {\n if (isOpen) handleClose();\n return;\n }\n\n if (!isOpen) {\n handleOpen(true);\n event.preventDefault();\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\n if (nextIndex !== -1 && event.key !== KeyboardEventKey.Space) {\n event.preventDefault();\n\n inputRefList.current[nextIndex].current?.focus();\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 KeyboardEventKey.Space,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const toggleClasses = classNames(\n styles.dropdown__toggle,\n !disabled && {\n [styles['dropdown__toggle--on-white']]: onColor === DropdownOnColor.onwhite,\n [styles['dropdown__toggle--on-grey']]: onColor === DropdownOnColor.ongrey,\n [styles['dropdown__toggle--on-blueberry']]: onColor === DropdownOnColor.onblueberry,\n [styles['dropdown__toggle--on-cherry']]: onColor === DropdownOnColor.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 return (\n <li className={styles.dropdown__input} id={`${optionIdPrefix}-${index}`}>\n {React.isValidElement(child) && inputRefList.current && inputRefList.current[index]\n ? React.cloneElement(child as React.ReactElement, {\n ref: mergeRefs([child.props.ref, inputRefList.current[index]]),\n })\n : child}\n </li>\n );\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={(): false | void => handleOpen(false)}\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={true}\n aria-controls={contentId}\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\n id={contentId}\n className={contentClasses}\n style={{ width: fluid ? '100%' : `auto`, minWidth: dropdownMinWidth ?? 'auto', zIndex: zIndex }}\n >\n <ul className={styles.dropdown__options} role=\"group\" aria-labelledby={labelId} tabIndex={-1} ref={optionsRef}>\n {renderChildren}\n </ul>\n {!noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose}>{mergedResources.closeText}</Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"names":["DropdownOnColor","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAM,eAAe,CAAC,aAAsD;AACjF,UAAQ,UAAA;AAAA,IACN,KAAK,gBAAgB;AACnB,aAAO;AAAA,IACT,KAAK,gBAAgB;AAAA,IACrB;AACE,aAAO;AAAA,EAAA;AAEb;ACaO,IAAK,oCAAAA,qBAAL;AACLA,mBAAA,SAAA,IAAU;AACVA,mBAAA,QAAA,IAAS;AACTA,mBAAA,aAAA,IAAc;AACdA,mBAAA,UAAA,IAAW;AAJD,SAAAA;AAAA,GAAA,mBAAA,CAAA,CAAA;AAwCZ,MAAM,WAAoC,CAAA,UAAS;AACjD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,g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AQ,aAAa,MAAM,QAAQ;AAAA,cAC3D,SAAS;AAAA,cACT,WAAW,OAAO;AAAA,cAClB,WAAW,CAAC,YAAY;AAAA,cACxB,MAAM,SAAS;AAAA,YAAA;AAAA,UAAA;AAAA,QACjB;AAAA,MAAA;AAAA,IAAA;AAAA,IAEF;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,IAAI;AAAA,QACJ,WAAW;AAAA,QACX,OAAO,EAAE,OAAO,QAAQ,SAAS,QAAQ,UAAU,oBAAoB,QAAQ,OAAA;AAAA,QAE/E,UAAA;AAAA,UAAA,oBAAC,MAAA,EAAG,WAAW,OAAO,mBAAmB,MAAK,SAAQ,mBAAiB,SAAS,UAAU,IAAI,KAAK,YAChG,UAAA,gBACH;AAAA,UACC,CAAC,iBACA,oBAAC,OAAA,EAAI,WAAW,OAAO,iBACrB,UAAA,oBAAC,QAAA,EAAO,SAAS,aAAc,UAAA,gBAAgB,WAAU,EAAA,CAC3D;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAEJ,GACF;AAEJ;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/Dropdown/resourceHelper.ts","../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import { LanguageLocales } from '../../constants';\nimport enGB from '../../resources/HN.Designsystem.Dropdown.en-GB.json';\nimport nbNO from '../../resources/HN.Designsystem.Dropdown.nb-NO.json';\nimport { HNDesignsystemDropdown } from '../../resources/Resources';\n\nexport const getResources = (language: LanguageLocales): HNDesignsystemDropdown => {\n switch (language) {\n case LanguageLocales.ENGLISH:\n return enGB;\n case LanguageLocales.NORWEGIAN:\n default:\n return nbNO;\n }\n};\n","import React, { useEffect, useRef, useId, ComponentType } from 'react';\n\nimport { autoUpdate, offset, shift, size, useFloating } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { clamp } from 'motion/react';\n\nimport {\n AnalyticsId,\n IconSize,\n KeyboardEventKey,\n LanguageLocales,\n ZIndex,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\n useToggle,\n} from '../..';\nimport { getResources } from './resourceHelper';\nimport { SingleSelectItem, SingleSelectItemProps } from './SingleSelect/SingleSelectItem';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { HNDesignsystemDropdown } from '../../resources/Resources';\nimport { isComponent } from '../../utils/component';\nimport { useLanguage } from '../../utils/language';\nimport { mergeRefs } from '../../utils/refs';\nimport Button from '../Button';\nimport Checkbox, { CheckboxProps } from '../Checkbox';\nimport Icon, { SvgIcon } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { IconName } from '../Icons/IconNames';\nimport PlusSmall from '../Icons/PlusSmall';\nimport Label, { LabelProps } from '../Label';\nimport LazyIcon from '../LazyIcon';\nimport { SingleSelect } from './SingleSelect/SingleSelect';\n\nimport styles from './styles.module.scss';\n\ntype DropdownVariants = 'fill' | 'transparent' | 'borderless';\n\nexport interface DropdownProps {\n /** Text on the trigger button that opens the dropdown */\n triggerText: string;\n /** Sets the dropdown content */\n children: React.ReactNode;\n /** Minimum width for the dropdown in pixels. Does not affect trigger button. */\n dropdownMinWidth?: number;\n /** Minimum width for the trigger in pixels. Does not apply for borderless variant */\n triggerMinWidth?: number;\n /** Disables rendring of the close button in the list */\n noCloseButton?: boolean;\n /** Called when dropdown is open/closed */\n onToggle?: (isOpen: boolean) => void;\n /** Whether the dropdown is open or not */\n open?: boolean;\n /** Makes the dropdown disabled */\n disabled?: boolean;\n /** Sets the data-testid attribute on the dropdown button */\n testId?: string;\n /** Overrides the default z-index of the DropDownContent */\n zIndex?: number;\n /** Resources for component */\n resources?: Partial<HNDesignsystemDropdown>;\n /** Adds an icon to the trigger */\n svgIcon?: SvgIcon | IconName;\n /** Sets the visual variant of the Dropdown */\n variant?: DropdownVariants;\n}\n\nexport const DropdownBase: React.FC<DropdownProps> = props => {\n const {\n triggerText,\n noCloseButton = false,\n onToggle,\n dropdownMinWidth,\n triggerMinWidth,\n open = false,\n children,\n testId,\n disabled,\n zIndex = ZIndex.PopOver,\n resources,\n svgIcon,\n variant = 'fill',\n } = props;\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const optionsRef = useRef<HTMLUListElement>(null);\n const childrenRefList = useRef(React.Children.map(children, () => React.createRef<HTMLElement>()));\n const { hoverRef: buttonRef, isHovered } = useHover<HTMLButtonElement>();\n const openedByKeyboard = useRef<boolean>(false);\n const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);\n const isMobile = useIsMobileBreakpoint();\n const triggerActualMinWidth = variant !== 'borderless' && typeof triggerMinWidth != 'undefined' ? `${triggerMinWidth}px` : 'auto';\n const triggerMinWidthLimit = isMobile ? 96 : 112;\n const maxWidth = isMobile ? 384 : 400;\n const toggleTextId = useId();\n const optionIdPrefix = useId();\n const contentId = useId();\n const leftIconProps = {\n className: styles['dropdown__left-icon'],\n size: IconSize.XSmall,\n isHovered: !disabled && isHovered,\n };\n\n const isSingleSelect = React.Children.toArray(children).every(\n child => React.isValidElement(child) && isComponent<SingleSelectItemProps>(child, SingleSelectItem)\n );\n const isMultiSelect = React.Children.toArray(children).every(\n child => React.isValidElement(child) && isComponent<CheckboxProps>(child, Checkbox)\n );\n\n const { language } = useLanguage<LanguageLocales>(LanguageLocales.NORWEGIAN);\n const defaultResources = getResources(language);\n const mergedResources: HNDesignsystemDropdown = {\n ...defaultResources,\n ...resources,\n };\n\n const toggleClasses = classNames(styles.dropdown__toggle, {\n [styles['dropdown__toggle--open']]: isOpen && !disabled,\n [styles['dropdown__toggle--with-icon']]: typeof svgIcon !== 'undefined',\n [styles['dropdown__toggle--transparent']]: variant === 'transparent',\n [styles['dropdown__toggle--borderless']]: variant === 'borderless',\n });\n const contentClasses = classNames(styles.dropdown__content, isOpen && styles['dropdown__content--open']);\n const listItemClasses = classNames(styles['dropdown__list-item'], { [styles['dropdown__list-item--single-select']]: isSingleSelect });\n\n const { refs, floatingStyles } = useFloating({\n placement: 'bottom',\n middleware: [\n offset(8),\n shift({ padding: 8 }),\n size({\n apply({ availableWidth, availableHeight, elements, rects }) {\n const triggerW = rects.reference.width;\n const minProp = typeof dropdownMinWidth !== 'undefined' ? clamp(0, maxWidth, dropdownMinWidth) : 0;\n const targetW = Math.max(triggerW, minProp);\n const finalW = Math.min(availableWidth, targetW);\n\n Object.assign(elements.floating.style, {\n width: `${finalW}px`,\n maxHeight: `${availableHeight}px`,\n overflowY: 'auto',\n overflowX: 'hidden',\n });\n },\n }),\n ],\n whileElementsMounted: autoUpdate,\n });\n\n const handleOpen = (isKeyboard: boolean): void => {\n openedByKeyboard.current = isKeyboard;\n toggleIsOpen();\n };\n\n const handleClose = (): void => {\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n useEffect(() => {\n if (isOpen && openedByKeyboard.current) {\n const firstEnabled = childrenRefList.current?.find(r => r.current && !r.current.hasAttribute('disabled'));\n firstEnabled?.current?.focus();\n openedByKeyboard.current = false;\n }\n }, [isOpen]);\n\n const focusByIndex = (nextIndex: number): void => {\n childrenRefList.current?.[nextIndex]?.current?.focus();\n };\n\n const isListNavKey = (key: string): boolean =>\n key === KeyboardEventKey.ArrowDown || key === KeyboardEventKey.ArrowUp || key === KeyboardEventKey.Home || key === KeyboardEventKey.End;\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n if (!childrenRefList.current) return;\n\n const key = event.key as KeyboardEventKey;\n\n if (key === KeyboardEventKey.Escape) {\n if (isOpen) {\n event.preventDefault();\n handleClose();\n }\n return;\n }\n\n if (!isOpen) {\n if (isListNavKey(key)) {\n event.preventDefault();\n handleOpen(true);\n }\n return;\n }\n\n if (!isListNavKey(key)) {\n return;\n }\n\n const index = childrenRefList.current.findIndex(x => x.current === (event.target as HTMLElement));\n let nextIndex = index;\n\n if (key === KeyboardEventKey.Home) {\n nextIndex = 0;\n } else if (key === KeyboardEventKey.End) {\n nextIndex = childrenRefList.current.length - 1;\n } else if (key === KeyboardEventKey.ArrowDown && index < childrenRefList.current.length - 1) {\n nextIndex = index + 1;\n } else if (key === KeyboardEventKey.ArrowUp && index > 0) {\n nextIndex = index - 1;\n }\n\n if (nextIndex !== -1) {\n event.preventDefault();\n focusByIndex(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 KeyboardEventKey.Space,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const renderChildren = React.Children.map(children, (child, index) => {\n return (\n <li className={listItemClasses} id={`${optionIdPrefix}-${index}`}>\n {React.isValidElement(child) && childrenRefList.current && childrenRefList.current[index]\n ? ((): React.ReactElement => {\n const baseProps: { ref: React.Ref<HTMLElement> } = {\n ref: mergeRefs([child.props.ref, childrenRefList.current[index]]),\n };\n\n if (isMultiSelect) {\n const label = (child.props as CheckboxProps).label as React.ReactNode;\n if (React.isValidElement(label) && isComponent<LabelProps>(label, Label)) {\n return React.cloneElement(child as React.ReactElement<CheckboxProps>, {\n ...baseProps,\n label: React.cloneElement(label, {\n labelClassName: classNames((label.props as LabelProps)?.labelClassName, styles['dropdown__multiselect-item']),\n }),\n });\n }\n }\n\n return React.cloneElement(child as React.ReactElement<Record<string, unknown>>, baseProps);\n })()\n : child}\n </li>\n );\n });\n\n return (\n <div className={styles.dropdown} ref={dropdownRef}>\n <button\n type=\"button\"\n onClick={(): false | void => handleOpen(false)}\n className={toggleClasses}\n ref={mergeRefs([buttonRef, refs.setReference])}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Dropdown}\n disabled={disabled}\n aria-labelledby={toggleTextId}\n aria-haspopup={true}\n aria-controls={contentId}\n aria-expanded={isOpen}\n style={{\n width: triggerActualMinWidth,\n maxWidth: '100%',\n minWidth: `${triggerMinWidthLimit}px`,\n }}\n >\n {svgIcon && (\n <>\n {typeof svgIcon === 'string' ? (\n <LazyIcon {...leftIconProps} iconName={svgIcon} />\n ) : (\n <Icon {...leftIconProps} svgIcon={svgIcon} />\n )}\n </>\n )}\n <span id={toggleTextId} className={styles.dropdown__toggle__text}>\n {triggerText}\n </span>\n <Icon\n svgIcon={!isSingleSelect ? PlusSmall : isOpen ? ChevronUp : ChevronDown}\n className={styles['dropdown__right-icon']}\n isHovered={!disabled && isHovered}\n size={IconSize.XSmall}\n />\n </button>\n <div\n key={dropdownMinWidth ?? 'auto'}\n id={contentId}\n className={contentClasses}\n ref={refs.setFloating}\n style={{\n ...floatingStyles,\n zIndex: zIndex,\n }}\n >\n <ul className={styles.dropdown__options} role=\"group\" aria-labelledby={toggleTextId} tabIndex={-1} ref={optionsRef}>\n {isSingleSelect && <SingleSelect onValueChange={() => handleClose()}>{renderChildren}</SingleSelect>}\n {isMultiSelect && renderChildren}\n </ul>\n {!isSingleSelect && !noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose}>{mergedResources.closeText}</Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport interface DropdownCompound extends React.FC<DropdownProps> {\n SingleSelectItem: ComponentType<SingleSelectItemProps>;\n}\nconst Dropdown = DropdownBase as DropdownCompound;\nDropdown.SingleSelectItem = SingleSelectItem;\nDropdownBase.displayName = 'Dropdown';\n\nexport default Dropdown;\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAM,eAAe,CAAC,aAAsD;AACjF,UAAQ,UAAA;AAAA,IACN,KAAK,gBAAgB;AACnB,aAAO;AAAA,IACT,KAAK,gBAAgB;AAAA,IACrB;AACE,aAAO;AAAA,EAAA;AAEb;ACuDO,MAAM,eAAwC,CAAA,UAAS;AAC5D,QAAM;AAAA,IACJ;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,OAAO;AAAA,I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