@helsenorge/designsystem-react 12.7.0 → 12.9.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/AsChildSlot.js +74 -0
- package/AsChildSlot.js.map +1 -0
- package/CHANGELOG.md +48 -5
- package/Drawer.js +58 -4
- package/Drawer.js.map +1 -1
- package/HN.Designsystem.Dropdown.nb-NO.js +13 -0
- package/HN.Designsystem.Dropdown.nb-NO.js.map +1 -0
- package/HelpDetails.js +1 -1
- package/LinkList.js +1 -0
- package/LinkList.js.map +1 -1
- package/Panel.js +0 -1
- package/Panel.js.map +1 -1
- package/SingleSelectItem.js +96 -0
- package/SingleSelectItem.js.map +1 -0
- package/clamp.js +11 -0
- package/clamp.js.map +1 -0
- package/components/ArticleTeaser/styles.module.scss +3 -5
- package/components/AsChildSlot/AsChildSlot.d.ts +23 -0
- package/components/AsChildSlot/AsChildSlot.test.d.ts +1 -0
- package/components/AsChildSlot/index.d.ts +3 -0
- package/components/AsChildSlot/index.js +6 -0
- package/components/AsChildSlot/index.js.map +1 -0
- package/components/AsChildSlot/styles.module.scss +13 -0
- package/components/AsChildSlot/styles.module.scss.d.ts +9 -0
- package/components/Drawer/styles.module.scss +45 -26
- package/components/Drawer/styles.module.scss.d.ts +5 -0
- package/components/Dropdown/Dropdown.d.ts +19 -21
- package/components/Dropdown/Dropdown.test.d.ts +1 -0
- package/components/Dropdown/SingleSelect/SingleSelect.d.ts +18 -0
- package/components/Dropdown/SingleSelect/SingleSelect.test.d.ts +1 -0
- package/components/Dropdown/SingleSelect/SingleSelectItem.d.ts +21 -0
- package/components/Dropdown/SingleSelect/index.d.ts +3 -0
- package/components/Dropdown/SingleSelect/index.js +6 -0
- package/components/Dropdown/SingleSelect/index.js.map +1 -0
- package/components/Dropdown/SingleSelect/styles.module.scss +54 -0
- package/components/Dropdown/SingleSelect/styles.module.scss.d.ts +14 -0
- package/components/Dropdown/index.js +143 -78
- package/components/Dropdown/index.js.map +1 -1
- package/components/Dropdown/styles.module.scss +90 -136
- package/components/Dropdown/styles.module.scss.d.ts +8 -9
- package/components/DropdownOld/DropdownOld.d.ts +42 -0
- package/components/DropdownOld/index.d.ts +3 -0
- package/components/DropdownOld/index.js +194 -0
- package/components/DropdownOld/index.js.map +1 -0
- package/components/DropdownOld/resourceHelper.d.ts +3 -0
- package/components/DropdownOld/styles.module.scss +230 -0
- package/components/DropdownOld/styles.module.scss.d.ts +25 -0
- package/components/Icons/EmoticonAnnoyed.js +8 -11
- package/components/Icons/EmoticonAnnoyed.js.map +1 -1
- package/components/Icons/EmoticonDelighted.js +8 -4
- package/components/Icons/EmoticonDelighted.js.map +1 -1
- package/components/Icons/EmoticonDisappointed.js +8 -4
- package/components/Icons/EmoticonDisappointed.js.map +1 -1
- package/components/Icons/EmoticonHappy.js +8 -4
- package/components/Icons/EmoticonHappy.js.map +1 -1
- package/components/Icons/EmoticonMeh.js +8 -4
- package/components/Icons/EmoticonMeh.js.map +1 -1
- package/components/LinkList/styles.module.scss +47 -61
- package/components/LinkList/styles.module.scss.d.ts +1 -0
- package/components/ListEditMode/styles.module.scss +1 -0
- package/components/NotificationPanel/index.js +3 -1
- package/components/NotificationPanel/index.js.map +1 -1
- package/components/NotificationPanel/styles.module.scss +10 -5
- package/components/Panel/Panel.d.ts +1 -1
- package/designsystem-react.css +10 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/scss/supernova/styles/colors.css +10 -0
- package/use-animate.js +1 -7
- package/use-animate.js.map +1 -1
- /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
|
|
5
|
+
import "../../theme/grid.js";
|
|
5
6
|
import "../../hooks/useBreakpoint.js";
|
|
6
|
-
import {
|
|
7
|
+
import { usePseudoClasses } from "../../hooks/usePseudoClasses.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
|
|
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
|
-
|
|
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,83 @@ const getResources = (language) => {
|
|
|
31
34
|
return nbNO;
|
|
32
35
|
}
|
|
33
36
|
};
|
|
34
|
-
|
|
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
|
-
|
|
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);
|
|
60
|
-
const
|
|
55
|
+
const childrenRefList = useRef(React__default.Children.map(children, () => React__default.createRef()));
|
|
56
|
+
const buttonRef = React__default.useRef(null);
|
|
57
|
+
const { isHovered } = usePseudoClasses(buttonRef);
|
|
61
58
|
const openedByKeyboard = useRef(false);
|
|
62
59
|
const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
60
|
+
const isMobile = useIsMobileBreakpoint();
|
|
61
|
+
const triggerActualMinWidth = variant !== "borderless" && typeof triggerMinWidth != "undefined" ? `${triggerMinWidth}px` : "auto";
|
|
62
|
+
const triggerMinWidthLimit = isMobile ? 96 : 112;
|
|
63
|
+
const maxWidth = isMobile ? 384 : 400;
|
|
64
|
+
const toggleTextId = useId();
|
|
66
65
|
const optionIdPrefix = useId();
|
|
67
66
|
const contentId = useId();
|
|
67
|
+
const leftIconProps = {
|
|
68
|
+
className: styles["dropdown__left-icon"],
|
|
69
|
+
size: IconSize.XSmall,
|
|
70
|
+
isHovered: !disabled && isHovered
|
|
71
|
+
};
|
|
72
|
+
const isSingleSelect = React__default.Children.toArray(children).every(
|
|
73
|
+
(child) => React__default.isValidElement(child) && isComponent(child, SingleSelectItem)
|
|
74
|
+
);
|
|
75
|
+
const isMultiSelect = React__default.Children.toArray(children).every(
|
|
76
|
+
(child) => React__default.isValidElement(child) && isComponent(child, Checkbox)
|
|
77
|
+
);
|
|
68
78
|
const { language } = useLanguage(LanguageLocales.NORWEGIAN);
|
|
69
79
|
const defaultResources = getResources(language);
|
|
70
80
|
const mergedResources = {
|
|
71
81
|
...defaultResources,
|
|
72
|
-
...resources
|
|
73
|
-
closeText: props.closeText ?? (resources == null ? void 0 : resources.closeText) ?? defaultResources.closeText
|
|
82
|
+
...resources
|
|
74
83
|
};
|
|
84
|
+
const toggleClasses = classNames(styles.dropdown__toggle, {
|
|
85
|
+
[styles["dropdown__toggle--open"]]: isOpen && !disabled,
|
|
86
|
+
[styles["dropdown__toggle--with-icon"]]: typeof svgIcon !== "undefined",
|
|
87
|
+
[styles["dropdown__toggle--transparent"]]: variant === "transparent",
|
|
88
|
+
[styles["dropdown__toggle--borderless"]]: variant === "borderless"
|
|
89
|
+
});
|
|
90
|
+
const contentClasses = classNames(styles.dropdown__content, isOpen && styles["dropdown__content--open"]);
|
|
91
|
+
const listItemClasses = classNames(styles["dropdown__list-item"], { [styles["dropdown__list-item--single-select"]]: isSingleSelect });
|
|
92
|
+
const { refs, floatingStyles } = useFloating({
|
|
93
|
+
placement: "bottom",
|
|
94
|
+
middleware: [
|
|
95
|
+
offset(8),
|
|
96
|
+
shift({ padding: 8 }),
|
|
97
|
+
size({
|
|
98
|
+
apply({ availableWidth, availableHeight, elements, rects }) {
|
|
99
|
+
const triggerW = rects.reference.width;
|
|
100
|
+
const minProp = typeof dropdownMinWidth !== "undefined" ? clamp(0, maxWidth, dropdownMinWidth) : 0;
|
|
101
|
+
const targetW = Math.max(triggerW, minProp);
|
|
102
|
+
const finalW = Math.min(availableWidth, targetW);
|
|
103
|
+
Object.assign(elements.floating.style, {
|
|
104
|
+
width: `${finalW}px`,
|
|
105
|
+
maxHeight: `${availableHeight}px`,
|
|
106
|
+
overflowY: "auto",
|
|
107
|
+
overflowX: "hidden"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
],
|
|
112
|
+
whileElementsMounted: autoUpdate
|
|
113
|
+
});
|
|
75
114
|
const handleOpen = (isKeyboard) => {
|
|
76
115
|
openedByKeyboard.current = isKeyboard;
|
|
77
116
|
toggleIsOpen();
|
|
@@ -84,41 +123,50 @@ const Dropdown = (props) => {
|
|
|
84
123
|
useEffect(() => {
|
|
85
124
|
var _a, _b;
|
|
86
125
|
if (isOpen && openedByKeyboard.current) {
|
|
87
|
-
const firstEnabled = (_a =
|
|
126
|
+
const firstEnabled = (_a = childrenRefList.current) == null ? void 0 : _a.find((r) => r.current && !r.current.hasAttribute("disabled"));
|
|
88
127
|
(_b = firstEnabled == null ? void 0 : firstEnabled.current) == null ? void 0 : _b.focus();
|
|
89
128
|
openedByKeyboard.current = false;
|
|
90
129
|
}
|
|
91
130
|
}, [isOpen]);
|
|
131
|
+
const focusByIndex = (nextIndex) => {
|
|
132
|
+
var _a, _b, _c;
|
|
133
|
+
(_c = (_b = (_a = childrenRefList.current) == null ? void 0 : _a[nextIndex]) == null ? void 0 : _b.current) == null ? void 0 : _c.focus();
|
|
134
|
+
};
|
|
135
|
+
const isListNavKey = (key) => key === KeyboardEventKey.ArrowDown || key === KeyboardEventKey.ArrowUp || key === KeyboardEventKey.Home || key === KeyboardEventKey.End;
|
|
92
136
|
const handleKeyboardNavigation = (event) => {
|
|
93
|
-
|
|
94
|
-
|
|
137
|
+
if (!childrenRefList.current) return;
|
|
138
|
+
const key = event.key;
|
|
139
|
+
if (key === KeyboardEventKey.Escape) {
|
|
140
|
+
if (isOpen) {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
handleClose();
|
|
143
|
+
}
|
|
95
144
|
return;
|
|
96
145
|
}
|
|
97
|
-
if (
|
|
98
|
-
if (
|
|
146
|
+
if (!isOpen) {
|
|
147
|
+
if (isListNavKey(key)) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
handleOpen(true);
|
|
150
|
+
}
|
|
99
151
|
return;
|
|
100
152
|
}
|
|
101
|
-
if (!
|
|
102
|
-
handleOpen(true);
|
|
103
|
-
event.preventDefault();
|
|
153
|
+
if (!isListNavKey(key)) {
|
|
104
154
|
return;
|
|
105
155
|
}
|
|
106
|
-
const index =
|
|
156
|
+
const index = childrenRefList.current.findIndex((x) => x.current === event.target);
|
|
107
157
|
let nextIndex = index;
|
|
108
|
-
if (
|
|
158
|
+
if (key === KeyboardEventKey.Home) {
|
|
109
159
|
nextIndex = 0;
|
|
110
|
-
} else if (
|
|
111
|
-
nextIndex =
|
|
112
|
-
} else if (
|
|
160
|
+
} else if (key === KeyboardEventKey.End) {
|
|
161
|
+
nextIndex = childrenRefList.current.length - 1;
|
|
162
|
+
} else if (key === KeyboardEventKey.ArrowDown && index < childrenRefList.current.length - 1) {
|
|
113
163
|
nextIndex = index + 1;
|
|
114
|
-
} else if (
|
|
164
|
+
} else if (key === KeyboardEventKey.ArrowUp && index > 0) {
|
|
115
165
|
nextIndex = index - 1;
|
|
116
|
-
} else if (event.key === KeyboardEventKey.Enter && index !== -1) {
|
|
117
|
-
nextIndex = index;
|
|
118
166
|
}
|
|
119
|
-
if (nextIndex !== -1
|
|
167
|
+
if (nextIndex !== -1) {
|
|
120
168
|
event.preventDefault();
|
|
121
|
-
(
|
|
169
|
+
focusByIndex(nextIndex);
|
|
122
170
|
}
|
|
123
171
|
};
|
|
124
172
|
useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [
|
|
@@ -131,48 +179,54 @@ const Dropdown = (props) => {
|
|
|
131
179
|
KeyboardEventKey.Space
|
|
132
180
|
]);
|
|
133
181
|
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
182
|
const renderChildren = React__default.Children.map(children, (child, index) => {
|
|
148
|
-
return /* @__PURE__ */ jsx("li", { className:
|
|
149
|
-
|
|
150
|
-
|
|
183
|
+
return /* @__PURE__ */ jsx("li", { className: listItemClasses, id: `${optionIdPrefix}-${index}`, children: React__default.isValidElement(child) && childrenRefList.current && childrenRefList.current[index] ? (() => {
|
|
184
|
+
var _a;
|
|
185
|
+
const baseProps = {
|
|
186
|
+
ref: mergeRefs([child.props.ref, childrenRefList.current[index]])
|
|
187
|
+
};
|
|
188
|
+
if (isMultiSelect) {
|
|
189
|
+
const label = child.props.label;
|
|
190
|
+
if (React__default.isValidElement(label) && isComponent(label, Label)) {
|
|
191
|
+
return React__default.cloneElement(child, {
|
|
192
|
+
...baseProps,
|
|
193
|
+
label: React__default.cloneElement(label, {
|
|
194
|
+
labelClassName: classNames((_a = label.props) == null ? void 0 : _a.labelClassName, styles["dropdown__multiselect-item"])
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return React__default.cloneElement(child, baseProps);
|
|
200
|
+
})() : child });
|
|
151
201
|
});
|
|
152
202
|
return /* @__PURE__ */ jsxs("div", { className: styles.dropdown, ref: dropdownRef, children: [
|
|
153
|
-
/* @__PURE__ */ jsx("span", { id: labelId, className: styles.dropdown__label, children: label }),
|
|
154
203
|
/* @__PURE__ */ jsxs(
|
|
155
204
|
"button",
|
|
156
205
|
{
|
|
157
206
|
type: "button",
|
|
158
207
|
onClick: () => handleOpen(false),
|
|
159
208
|
className: toggleClasses,
|
|
160
|
-
ref: buttonRef,
|
|
209
|
+
ref: mergeRefs([buttonRef, refs.setReference]),
|
|
161
210
|
"data-testid": testId,
|
|
162
211
|
"data-analyticsid": AnalyticsId.Dropdown,
|
|
163
212
|
disabled,
|
|
164
|
-
"aria-labelledby":
|
|
213
|
+
"aria-labelledby": toggleTextId,
|
|
165
214
|
"aria-haspopup": true,
|
|
166
215
|
"aria-controls": contentId,
|
|
167
216
|
"aria-expanded": isOpen,
|
|
217
|
+
style: {
|
|
218
|
+
width: triggerActualMinWidth,
|
|
219
|
+
maxWidth: "100%",
|
|
220
|
+
minWidth: `${triggerMinWidthLimit}px`
|
|
221
|
+
},
|
|
168
222
|
children: [
|
|
169
|
-
/* @__PURE__ */ jsx("
|
|
223
|
+
svgIcon && /* @__PURE__ */ jsx(Fragment, { children: typeof svgIcon === "string" ? /* @__PURE__ */ jsx(LazyIcon, { ...leftIconProps, iconName: svgIcon }) : /* @__PURE__ */ jsx(Icon, { ...leftIconProps, svgIcon }) }),
|
|
224
|
+
/* @__PURE__ */ jsx("span", { id: toggleTextId, className: styles.dropdown__toggle__text, children: triggerText }),
|
|
170
225
|
/* @__PURE__ */ jsx(
|
|
171
226
|
Icon,
|
|
172
227
|
{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
className: styles.dropdown__icon,
|
|
228
|
+
svgIcon: !isSingleSelect ? PlusSmall : isOpen ? ChevronUp : ChevronDown,
|
|
229
|
+
className: styles["dropdown__right-icon"],
|
|
176
230
|
isHovered: !disabled && isHovered,
|
|
177
231
|
size: IconSize.XSmall
|
|
178
232
|
}
|
|
@@ -185,17 +239,28 @@ const Dropdown = (props) => {
|
|
|
185
239
|
{
|
|
186
240
|
id: contentId,
|
|
187
241
|
className: contentClasses,
|
|
188
|
-
|
|
242
|
+
ref: refs.setFloating,
|
|
243
|
+
style: {
|
|
244
|
+
...floatingStyles,
|
|
245
|
+
zIndex
|
|
246
|
+
},
|
|
189
247
|
children: [
|
|
190
|
-
/* @__PURE__ */
|
|
191
|
-
|
|
248
|
+
/* @__PURE__ */ jsxs("ul", { className: styles.dropdown__options, role: "group", "aria-labelledby": toggleTextId, tabIndex: -1, ref: optionsRef, children: [
|
|
249
|
+
isSingleSelect && /* @__PURE__ */ jsx(SingleSelect, { onValueChange: () => handleClose(), children: renderChildren }),
|
|
250
|
+
isMultiSelect && renderChildren
|
|
251
|
+
] }),
|
|
252
|
+
!isSingleSelect && !noCloseButton && /* @__PURE__ */ jsx("div", { className: styles.dropdown__close, children: /* @__PURE__ */ jsx(Button, { onClick: handleClose, children: mergedResources.closeText }) })
|
|
192
253
|
]
|
|
193
|
-
}
|
|
254
|
+
},
|
|
255
|
+
dropdownMinWidth ?? "auto"
|
|
194
256
|
)
|
|
195
257
|
] });
|
|
196
258
|
};
|
|
259
|
+
const Dropdown = DropdownBase;
|
|
260
|
+
Dropdown.SingleSelectItem = SingleSelectItem;
|
|
261
|
+
DropdownBase.displayName = "Dropdown";
|
|
197
262
|
export {
|
|
198
|
-
|
|
263
|
+
DropdownBase,
|
|
199
264
|
Dropdown as default
|
|
200
265
|
};
|
|
201
266
|
//# 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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AW,OAAO,yBACxC,UAAA,aACH;AAAA,UACA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,OAAO,WAAW,MAAM,QAAQ,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 usePseudoClasses,\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 buttonRef = React.useRef<HTMLButtonElement>(null);\n const { isHovered } = usePseudoClasses<HTMLButtonElement>(buttonRef);\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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