@helsenorge/designsystem-react 15.2.0 → 15.4.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/lib/AnchorLink.js +2 -2
- package/lib/AnchorLink.js.map +1 -1
- package/lib/Avatar.js +2 -2
- package/lib/Avatar.js.map +1 -1
- package/lib/Badge.js +2 -2
- package/lib/Badge.js.map +1 -1
- package/lib/Button.js +7 -7
- package/lib/Button.js.map +1 -1
- package/lib/CHANGELOG.md +23 -0
- package/lib/Checkbox.js +5 -5
- package/lib/Checkbox.js.map +1 -1
- package/lib/Checkbox2.js +2 -2
- package/lib/Checkbox2.js.map +1 -1
- package/lib/CheckboxMarker.js +2 -2
- package/lib/CheckboxMarker.js.map +1 -1
- package/lib/Chip.js +4 -4
- package/lib/Chip.js.map +1 -1
- package/lib/Close.js +3 -3
- package/lib/Close.js.map +1 -1
- package/lib/DictionaryTrigger.js +2 -2
- package/lib/DictionaryTrigger.js.map +1 -1
- package/lib/Drawer.js +56 -39
- package/lib/Drawer.js.map +1 -1
- package/lib/DrawerNavigation.js +107 -8
- package/lib/DrawerNavigation.js.map +1 -1
- package/lib/Duolist.js +5 -5
- package/lib/Duolist.js.map +1 -1
- package/lib/ElementHeader.js +9 -9
- package/lib/ElementHeader.js.map +1 -1
- package/lib/ElementHeaderText.js +4 -4
- package/lib/ElementHeaderText.js.map +1 -1
- package/lib/ErrorWrapper.js +2 -2
- package/lib/ErrorWrapper.js.map +1 -1
- package/lib/Expander.js +8 -8
- package/lib/Expander.js.map +1 -1
- package/lib/FilterButton.js +2 -2
- package/lib/FilterButton.js.map +1 -1
- package/lib/FilterButtonAndChipsWrapper.js +2 -2
- package/lib/FilterButtonAndChipsWrapper.js.map +1 -1
- package/lib/FilterDrawer.js +0 -2
- package/lib/FilterDrawer.js.map +1 -1
- package/lib/FilterLinkList.js +4 -4
- package/lib/FilterLinkList.js.map +1 -1
- package/lib/FilterOverviewSearch.js +2 -2
- package/lib/FilterOverviewSearch.js.map +1 -1
- package/lib/FilterSearch.js +6 -6
- package/lib/FilterSearch.js.map +1 -1
- package/lib/FormFieldTag.js +2 -2
- package/lib/FormFieldTag.js.map +1 -1
- package/lib/FormGroup.js +5 -5
- package/lib/FormGroup.js.map +1 -1
- package/lib/FormLayout.js +3 -3
- package/lib/FormLayout.js.map +1 -1
- package/lib/HelpDetails.js +3 -3
- package/lib/HelpDetails.js.map +1 -1
- package/lib/HelpTriggerIcon.js +2 -2
- package/lib/HelpTriggerIcon.js.map +1 -1
- package/lib/HelpTriggerStandalone.js +2 -2
- package/lib/HelpTriggerStandalone.js.map +1 -1
- package/lib/HighlightPanel.js +3 -3
- package/lib/HighlightPanel.js.map +1 -1
- package/lib/HorizontalScroll.js +4 -4
- package/lib/HorizontalScroll.js.map +1 -1
- package/lib/Icon.js +2 -2
- package/lib/Icon.js.map +1 -1
- package/lib/InfoTeaser.js +12 -11
- package/lib/InfoTeaser.js.map +1 -1
- package/lib/Input.js +4 -4
- package/lib/Input.js.map +1 -1
- package/lib/LazyIcon.js +2 -0
- package/lib/LazyIcon.js.map +1 -1
- package/lib/LinkList.js +5 -5
- package/lib/LinkList.js.map +1 -1
- package/lib/List.js +2 -2
- package/lib/List.js.map +1 -1
- package/lib/ListEditMode.js +4 -4
- package/lib/ListEditMode.js.map +1 -1
- package/lib/MaxCharacters.js +2 -2
- package/lib/MaxCharacters.js.map +1 -1
- package/lib/PanelTitle.js +2 -2
- package/lib/PanelTitle.js.map +1 -1
- package/lib/PopOver.js +2 -2
- package/lib/PopOver.js.map +1 -1
- package/lib/Radio.js +2 -2
- package/lib/Radio.js.map +1 -1
- package/lib/RadioButton.js +4 -4
- package/lib/RadioButton.js.map +1 -1
- package/lib/RadioMarker.js +2 -2
- package/lib/RadioMarker.js.map +1 -1
- package/lib/Select.js +4 -4
- package/lib/Select.js.map +1 -1
- package/lib/SingleSelectItem.js +3 -3
- package/lib/SingleSelectItem.js.map +1 -1
- package/lib/Slider.js +4 -4
- package/lib/Slider.js.map +1 -1
- package/lib/Spacer.js +2 -2
- package/lib/Spacer.js.map +1 -1
- package/lib/StatusDot.js +4 -4
- package/lib/StatusDot.js.map +1 -1
- package/lib/StatusDotList.js +2 -2
- package/lib/StatusDotList.js.map +1 -1
- package/lib/StepButtons.js +5 -5
- package/lib/StepButtons.js.map +1 -1
- package/lib/TabList.js +8 -8
- package/lib/TabList.js.map +1 -1
- package/lib/TabPanel.js +2 -2
- package/lib/TabPanel.js.map +1 -1
- package/lib/TableBody.js +2 -2
- package/lib/TableBody.js.map +1 -1
- package/lib/TableCell.js +2 -2
- package/lib/TableCell.js.map +1 -1
- package/lib/TableExpandedRow.js +4 -4
- package/lib/TableExpandedRow.js.map +1 -1
- package/lib/TableExpanderCell.js +2 -2
- package/lib/TableExpanderCell.js.map +1 -1
- package/lib/TableHead.js +2 -2
- package/lib/TableHead.js.map +1 -1
- package/lib/TableHeadCell.js +3 -3
- package/lib/TableHeadCell.js.map +1 -1
- package/lib/TableRow.js +3 -3
- package/lib/TableRow.js.map +1 -1
- package/lib/Textarea.js +4 -4
- package/lib/Textarea.js.map +1 -1
- package/lib/Title.js +2 -2
- package/lib/Title.js.map +1 -1
- package/lib/Toast.js +3 -3
- package/lib/Toast.js.map +1 -1
- package/lib/VisualCheckbox.js +3 -3
- package/lib/VisualCheckbox.js.map +1 -1
- package/lib/VisualRadio.js +3 -3
- package/lib/VisualRadio.js.map +1 -1
- package/lib/components/ArticleTeaser/index.js +4 -4
- package/lib/components/ArticleTeaser/index.js.map +1 -1
- package/lib/components/Drawer/Drawer.d.ts +6 -1
- package/lib/components/Drawer/DrawerHeaderContent.d.ts +22 -0
- package/lib/components/Drawer/DrawerHeaderContent.module.scss +51 -0
- package/lib/components/Drawer/DrawerHeaderContent.module.scss.d.ts +12 -0
- package/lib/components/Drawer/styles.module.scss +20 -10
- package/lib/components/Drawer/styles.module.scss.d.ts +3 -2
- package/lib/components/Dropdown/index.js +5 -5
- package/lib/components/Dropdown/index.js.map +1 -1
- package/lib/components/DropdownOld/index.js +3 -3
- package/lib/components/DropdownOld/index.js.map +1 -1
- package/lib/components/EmptyState/index.js +2 -2
- package/lib/components/EmptyState/index.js.map +1 -1
- package/lib/components/ExpanderHierarchy/index.js +7 -7
- package/lib/components/ExpanderHierarchy/index.js.map +1 -1
- package/lib/components/ExpanderList/index.js +6 -6
- package/lib/components/ExpanderList/index.js.map +1 -1
- package/lib/components/FavoriteButton/index.js +2 -2
- package/lib/components/FavoriteButton/index.js.map +1 -1
- package/lib/components/Filter/DrawerNavigation/styles.module.scss +15 -0
- package/lib/components/Filter/DrawerNavigation/styles.module.scss.d.ts +11 -0
- package/lib/components/Filter/FilterDrawer/styles.module.scss +0 -11
- package/lib/components/Filter/FilterDrawer/styles.module.scss.d.ts +0 -1
- package/lib/components/HelpBubble/index.js +3 -3
- package/lib/components/HelpBubble/index.js.map +1 -1
- package/lib/components/HelpDrawer/HelpDrawer.d.ts +1 -1
- package/lib/components/HelpDrawer/index.js +2 -1
- package/lib/components/HelpDrawer/index.js.map +1 -1
- package/lib/components/HelpPanel/index.js +2 -2
- package/lib/components/HelpPanel/index.js.map +1 -1
- package/lib/components/HelpTriggerInline/index.js +2 -2
- package/lib/components/HelpTriggerInline/index.js.map +1 -1
- package/lib/components/Highlighter/styles.module.scss +1 -1
- package/lib/components/Icons/AdditionalIconInformation.d.ts +12 -0
- package/lib/components/Icons/AdditionalIconInformation.js +13 -1
- package/lib/components/Icons/AdditionalIconInformation.js.map +1 -1
- package/lib/components/Icons/IconNames.d.ts +1 -1
- package/lib/components/Icons/IconNames.js +2 -0
- package/lib/components/Icons/IconNames.js.map +1 -1
- package/lib/components/Icons/ThumbsDown.d.ts +4 -0
- package/lib/components/Icons/ThumbsDown.js +15 -0
- package/lib/components/Icons/ThumbsDown.js.map +1 -0
- package/lib/components/Icons/ThumbsUp.d.ts +4 -0
- package/lib/components/Icons/ThumbsUp.js +15 -0
- package/lib/components/Icons/ThumbsUp.js.map +1 -0
- package/lib/components/InfoTeaser/InfoTeaser.d.ts +4 -0
- package/lib/components/Loader/index.js +4 -4
- package/lib/components/Loader/index.js.map +1 -1
- package/lib/components/Modal/index.js +9 -9
- package/lib/components/Modal/index.js.map +1 -1
- package/lib/components/NotificationPanel/index.js +6 -6
- package/lib/components/NotificationPanel/index.js.map +1 -1
- package/lib/components/Panel/index.js +12 -12
- package/lib/components/Panel/index.js.map +1 -1
- package/lib/components/PanelList/index.js +3 -3
- package/lib/components/PanelList/index.js.map +1 -1
- package/lib/components/PopMenu/index.js +3 -3
- package/lib/components/PopMenu/index.js.map +1 -1
- package/lib/components/Progressbar/index.js +2 -2
- package/lib/components/Progressbar/index.js.map +1 -1
- package/lib/components/PromoPanel/index.js +2 -2
- package/lib/components/PromoPanel/index.js.map +1 -1
- package/lib/components/ServiceMessage/index.js +5 -5
- package/lib/components/ServiceMessage/index.js.map +1 -1
- package/lib/components/SharingStatus/index.js +4 -4
- package/lib/components/SharingStatus/index.js.map +1 -1
- package/lib/components/Step/index.js +2 -2
- package/lib/components/Step/index.js.map +1 -1
- package/lib/components/Stepper/index.js +2 -2
- package/lib/components/Stepper/index.js.map +1 -1
- package/lib/components/StickyNote/index.js +8 -8
- package/lib/components/StickyNote/index.js.map +1 -1
- package/lib/components/Table/index.js +2 -2
- package/lib/components/Table/index.js.map +1 -1
- package/lib/components/Tabs/index.js +4 -4
- package/lib/components/Tabs/index.js.map +1 -1
- package/lib/components/Tag/constants.d.ts +2 -1
- package/lib/components/Tag/index.js +3 -2
- package/lib/components/Tag/index.js.map +1 -1
- package/lib/components/Tag/styles.module.scss +5 -0
- package/lib/components/Tag/styles.module.scss.d.ts +1 -0
- package/lib/components/Tile/index.js +4 -4
- package/lib/components/Tile/index.js.map +1 -1
- package/lib/components/Toggle/index.js +7 -7
- package/lib/components/Toggle/index.js.map +1 -1
- package/lib/components/Validation/index.js +2 -2
- package/lib/components/Validation/index.js.map +1 -1
- package/lib/components/VisualCheckboxCloud/index.js +2 -2
- package/lib/components/VisualCheckboxCloud/index.js.map +1 -1
- package/lib/components/VisualCheckboxGroup/index.js +3 -3
- package/lib/components/VisualCheckboxGroup/index.js.map +1 -1
- package/lib/components/VisualContentgroupWithImage/index.js +2 -2
- package/lib/components/VisualContentgroupWithImage/index.js.map +1 -1
- package/lib/components/VisualRadioCloud/index.js +2 -2
- package/lib/components/VisualRadioCloud/index.js.map +1 -1
- package/lib/components/VisualRadioGroup/index.js +3 -3
- package/lib/components/VisualRadioGroup/index.js.map +1 -1
- package/lib/hooks/useFocusTrap.js +4 -2
- package/lib/hooks/useFocusTrap.js.map +1 -1
- package/lib/utils2.js +7 -7
- package/lib/utils2.js.map +1 -1
- package/package.json +1 -1
package/lib/Drawer.js
CHANGED
|
@@ -13,14 +13,15 @@ import { useOutsideEvent } from "./hooks/useOutsideEvent.js";
|
|
|
13
13
|
import { t as Close_default } from "./Close.js";
|
|
14
14
|
import { useReturnFocusOnUnmount } from "./hooks/useReturnFocusOnUnmount.js";
|
|
15
15
|
import { disableBodyScroll, enableBodyScroll } from "./utils/scroll.js";
|
|
16
|
-
import Title_default from "./components/Title/index.js";
|
|
17
16
|
import ChevronLeft from "./components/Icons/ChevronLeft.js";
|
|
18
|
-
import
|
|
17
|
+
import Title_default from "./components/Title/index.js";
|
|
18
|
+
import cn from "classnames";
|
|
19
19
|
import React, { useEffect, useRef } from "react";
|
|
20
20
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
21
|
import { AnimatePresence, useAnimate, usePresence } from "motion/react";
|
|
22
22
|
import styles from "./components/Drawer/DrawerBackButton.module.scss";
|
|
23
|
-
import styles$1 from "./components/Drawer/
|
|
23
|
+
import styles$1 from "./components/Drawer/DrawerHeaderContent.module.scss";
|
|
24
|
+
import styles$2 from "./components/Drawer/styles.module.scss";
|
|
24
25
|
var HN_Designsystem_Drawer_en_GB_default = {
|
|
25
26
|
ariaLabelCloseBtn: "Close",
|
|
26
27
|
ariaLabelBackButton: "Go back"
|
|
@@ -56,12 +57,12 @@ var DrawerBackButton = (props) => {
|
|
|
56
57
|
const iconSize = useIsMobileBreakpoint() ? 38 : 48;
|
|
57
58
|
return /* @__PURE__ */ jsx("button", {
|
|
58
59
|
ref: refObject,
|
|
59
|
-
className:
|
|
60
|
+
className: cn(styles["back-button"], className),
|
|
60
61
|
"aria-label": ariaLabel,
|
|
61
62
|
onClick,
|
|
62
63
|
type: "button",
|
|
63
64
|
children: /* @__PURE__ */ jsx("span", {
|
|
64
|
-
className:
|
|
65
|
+
className: cn(styles["back-button__inner-container"]),
|
|
65
66
|
children: /* @__PURE__ */ jsx(Icon_default, {
|
|
66
67
|
svgIcon: ChevronLeft,
|
|
67
68
|
color: "var(--color-action-graphics-onlight",
|
|
@@ -72,6 +73,29 @@ var DrawerBackButton = (props) => {
|
|
|
72
73
|
});
|
|
73
74
|
};
|
|
74
75
|
//#endregion
|
|
76
|
+
//#region src/components/Drawer/DrawerHeaderContent.tsx
|
|
77
|
+
var DrawerHeaderContent = (props) => {
|
|
78
|
+
const { title, titleId, titleRef, titleHtmlMarkup = "h3", withBackButton, onRequestBack, backButtonAriaLabel, className } = props;
|
|
79
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
80
|
+
className: cn(styles$1["header-content"], className),
|
|
81
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
82
|
+
className: cn(styles$1["header-content__title"], { [styles$1["header-content__title--centered"]]: withBackButton }),
|
|
83
|
+
children: /* @__PURE__ */ jsx(Title_default, {
|
|
84
|
+
id: titleId,
|
|
85
|
+
ref: titleRef,
|
|
86
|
+
tabIndex: -1,
|
|
87
|
+
htmlMarkup: titleHtmlMarkup,
|
|
88
|
+
appearance: "title3",
|
|
89
|
+
children: title
|
|
90
|
+
})
|
|
91
|
+
}), withBackButton && /* @__PURE__ */ jsx(DrawerBackButton, {
|
|
92
|
+
ariaLabel: backButtonAriaLabel,
|
|
93
|
+
onClick: onRequestBack,
|
|
94
|
+
className: styles$1["header-content__back-button"]
|
|
95
|
+
})]
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
75
99
|
//#region src/components/Drawer/Drawer.tsx
|
|
76
100
|
var Drawer = (props) => {
|
|
77
101
|
const { isOpen, ...rest } = props;
|
|
@@ -82,7 +106,7 @@ var Drawer = (props) => {
|
|
|
82
106
|
}) });
|
|
83
107
|
};
|
|
84
108
|
var InnerDrawer = (props) => {
|
|
85
|
-
const { ariaLabel, ariaLabelledBy, children, closeColor = "blueberry", desktopDirection = "left", footerContent, headerClasses, noCloseButton = false, onPrimaryAction, onRequestClose, onSecondaryAction, primaryActionText, secondaryActionText, title, titleHtmlMarkup = "h3", titleId = uuid(), zIndex = ZIndex.OverlayScreen, resources, isMobile, withBackButton, onRequestBack, contentClassName } = props;
|
|
109
|
+
const { ariaLabel, ariaLabelledBy, children, closeColor = "blueberry", desktopDirection = "left", footerContent, headerClasses, headerContent, noCloseButton = false, onPrimaryAction, onRequestClose, onSecondaryAction, primaryActionText, secondaryActionText, title, titleHtmlMarkup = "h3", titleId = uuid(), zIndex = ZIndex.OverlayScreen, resources, isMobile, withBackButton, onRequestBack, contentClassName, paddingSize = "normal" } = props;
|
|
86
110
|
const ariaLabelAttributes = getAriaLabelAttributes({
|
|
87
111
|
label: ariaLabel,
|
|
88
112
|
id: ariaLabelledBy,
|
|
@@ -108,7 +132,7 @@ var InnerDrawer = (props) => {
|
|
|
108
132
|
...resources
|
|
109
133
|
};
|
|
110
134
|
const contentIsScrollable = contentRef.current && contentRef.current.scrollHeight > contentRef.current.clientHeight;
|
|
111
|
-
const headerStyling =
|
|
135
|
+
const headerStyling = cn(styles$2.drawer__header, { [styles$2["drawer__header--padding-extra"]]: paddingSize === "extra" }, headerClasses);
|
|
112
136
|
const hasFooterContent = typeof footerContent !== "undefined" && footerContent || onPrimaryAction || onSecondaryAction;
|
|
113
137
|
useFocusTrap(containerRef, true);
|
|
114
138
|
useReturnFocusOnUnmount(containerRef);
|
|
@@ -188,60 +212,53 @@ var InnerDrawer = (props) => {
|
|
|
188
212
|
useEffect(() => {
|
|
189
213
|
titleRef.current?.focus();
|
|
190
214
|
}, [title]);
|
|
215
|
+
const headerMain = /* @__PURE__ */ jsx(DrawerHeaderContent, {
|
|
216
|
+
title,
|
|
217
|
+
titleId: ariaLabelAttributes?.["aria-labelledby"],
|
|
218
|
+
titleRef,
|
|
219
|
+
titleHtmlMarkup,
|
|
220
|
+
withBackButton: withBackButton && onRequestBack !== void 0,
|
|
221
|
+
onRequestBack,
|
|
222
|
+
backButtonAriaLabel: mergedResources.ariaLabelBackButton
|
|
223
|
+
});
|
|
191
224
|
return /* @__PURE__ */ jsxs("div", {
|
|
192
|
-
className: styles$
|
|
225
|
+
className: styles$2.drawer,
|
|
193
226
|
ref: scope,
|
|
194
227
|
style: { zIndex },
|
|
195
228
|
"data-analyticsid": AnalyticsId.Drawer,
|
|
196
229
|
children: [/* @__PURE__ */ jsx("div", {
|
|
197
|
-
className: styles$
|
|
230
|
+
className: styles$2.drawer__overlay,
|
|
198
231
|
ref: overlayRef,
|
|
199
232
|
"aria-hidden": "true"
|
|
200
233
|
}), /* @__PURE__ */ jsxs("div", {
|
|
201
|
-
className:
|
|
234
|
+
className: cn(styles$2.drawer__container, { [styles$2["drawer__container--right"]]: desktopDirection === "right" }),
|
|
202
235
|
ref: containerRef,
|
|
203
236
|
role: "dialog",
|
|
204
237
|
"aria-modal": "true",
|
|
205
238
|
tabIndex: -1,
|
|
206
239
|
...ariaLabelAttributes,
|
|
207
240
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
208
|
-
className: styles$
|
|
241
|
+
className: styles$2.drawer__container__inner,
|
|
209
242
|
children: [
|
|
210
243
|
/* @__PURE__ */ jsxs("div", {
|
|
211
244
|
className: headerStyling,
|
|
212
245
|
ref: headerRef,
|
|
213
|
-
children: [
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
ref: titleRef,
|
|
220
|
-
tabIndex: -1,
|
|
221
|
-
children: title
|
|
222
|
-
}),
|
|
223
|
-
withBackButton && onRequestBack !== void 0 && /* @__PURE__ */ jsx(DrawerBackButton, {
|
|
224
|
-
ariaLabel: mergedResources.ariaLabelBackButton,
|
|
225
|
-
onClick: onRequestBack,
|
|
226
|
-
className: styles$1["drawer__header__back-button"]
|
|
227
|
-
}),
|
|
228
|
-
!noCloseButton && onRequestClose != void 0 && /* @__PURE__ */ jsx(Close_default, {
|
|
229
|
-
ariaLabel: mergedResources.ariaLabelCloseBtn,
|
|
230
|
-
color: closeColor,
|
|
231
|
-
onClick: onRequestClose,
|
|
232
|
-
className: styles$1["drawer__header__close-button"]
|
|
233
|
-
})
|
|
234
|
-
]
|
|
246
|
+
children: [headerContent ?? headerMain, !noCloseButton && onRequestClose != void 0 && /* @__PURE__ */ jsx(Close_default, {
|
|
247
|
+
ariaLabel: mergedResources.ariaLabelCloseBtn,
|
|
248
|
+
color: closeColor,
|
|
249
|
+
onClick: onRequestClose,
|
|
250
|
+
className: styles$2["drawer__header__close-button"]
|
|
251
|
+
})]
|
|
235
252
|
}),
|
|
236
253
|
/* @__PURE__ */ jsx("div", {
|
|
237
|
-
className:
|
|
254
|
+
className: cn(styles$2["drawer__content__shadow"], styles$2["drawer__content__shadow--top"]),
|
|
238
255
|
style: {
|
|
239
256
|
opacity: !topContentVisible && contentIsScrollable ? 1 : 0,
|
|
240
257
|
top: headerHeight
|
|
241
258
|
}
|
|
242
259
|
}),
|
|
243
260
|
/* @__PURE__ */ jsxs("div", {
|
|
244
|
-
className:
|
|
261
|
+
className: cn(styles$2.drawer__content, contentClassName),
|
|
245
262
|
tabIndex: contentIsScrollable ? 0 : void 0,
|
|
246
263
|
role: contentIsScrollable ? "region" : void 0,
|
|
247
264
|
...contentIsScrollable ? ariaLabelAttributes : {},
|
|
@@ -249,7 +266,7 @@ var InnerDrawer = (props) => {
|
|
|
249
266
|
children: [
|
|
250
267
|
/* @__PURE__ */ jsx("div", { ref: topContent }),
|
|
251
268
|
/* @__PURE__ */ jsx("div", {
|
|
252
|
-
className: styles$
|
|
269
|
+
className: cn(styles$2["drawer__content__children"], { [styles$2["drawer__content__children--padding-extra"]]: paddingSize === "extra" }),
|
|
253
270
|
children
|
|
254
271
|
}),
|
|
255
272
|
/* @__PURE__ */ jsx("div", {
|
|
@@ -259,7 +276,7 @@ var InnerDrawer = (props) => {
|
|
|
259
276
|
]
|
|
260
277
|
}),
|
|
261
278
|
/* @__PURE__ */ jsx("div", {
|
|
262
|
-
className:
|
|
279
|
+
className: cn(styles$2["drawer__content__shadow"], styles$2["drawer__content__shadow--bottom"]),
|
|
263
280
|
style: {
|
|
264
281
|
opacity: !bottomContentVisible && contentIsScrollable ? 1 : 0,
|
|
265
282
|
bottom: hasFooterContent ? footerHeight : 0
|
|
@@ -267,7 +284,7 @@ var InnerDrawer = (props) => {
|
|
|
267
284
|
})
|
|
268
285
|
]
|
|
269
286
|
}), hasFooterContent && /* @__PURE__ */ jsx("div", {
|
|
270
|
-
className: styles$
|
|
287
|
+
className: cn(styles$2.drawer__footer, { [styles$2["drawer__footer--padding-extra"]]: paddingSize === "extra" }),
|
|
271
288
|
ref: footerRef,
|
|
272
289
|
children: footerContent ? footerContent : /* @__PURE__ */ jsxs(Fragment, { children: [onPrimaryAction && /* @__PURE__ */ jsx(Button_default, {
|
|
273
290
|
onClick: () => handleCTA(onPrimaryAction),
|
|
@@ -285,6 +302,6 @@ var InnerDrawer = (props) => {
|
|
|
285
302
|
//#region src/components/Drawer/index.ts
|
|
286
303
|
var Drawer_default = Drawer;
|
|
287
304
|
//#endregion
|
|
288
|
-
export { Drawer_default as t };
|
|
305
|
+
export { DrawerHeaderContent as n, Drawer_default as t };
|
|
289
306
|
|
|
290
307
|
//# sourceMappingURL=Drawer.js.map
|
package/lib/Drawer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer.js","names":[],"sources":["../src/resources/HN.Designsystem.Drawer.en-GB.json","../src/resources/HN.Designsystem.Drawer.nb-NO.json","../src/resources/HN.Designsystem.Drawer.nn-NO.json","../src/resources/HN.Designsystem.Drawer.se-NO.json","../src/components/Drawer/resourceHelper.ts","../src/components/Drawer/DrawerBackButton.tsx","../src/components/Drawer/Drawer.tsx","../src/components/Drawer/index.ts"],"sourcesContent":["{\n \"ariaLabelCloseBtn\": \"Close\",\n \"ariaLabelBackButton\": \"Go back\"\n}\n","{\n \"ariaLabelBackButton\": \"Gå tilbake\",\n \"ariaLabelCloseBtn\": \"Lukk\"\n}\n","{\n \"ariaLabelCloseBtn\": \"Lukk\",\n \"ariaLabelBackButton\": \"Gå tilbake\"\n}\n","{\n \"ariaLabelCloseBtn\": \"Gidde\",\n \"ariaLabelBackButton\": \"Mana ruovttoluotta\"\n}\n","import type { HNDesignsystemDrawer } from '../../resources/Resources';\n\nimport { LanguageLocales } from '../../constants';\nimport enGB from '../../resources/HN.Designsystem.Drawer.en-GB.json';\nimport nbNO from '../../resources/HN.Designsystem.Drawer.nb-NO.json';\nimport nnNO from '../../resources/HN.Designsystem.Drawer.nn-NO.json';\nimport seNO from '../../resources/HN.Designsystem.Drawer.se-NO.json';\n\nexport const getResources = (language: LanguageLocales): HNDesignsystemDrawer => {\n switch (language) {\n case LanguageLocales.ENGLISH:\n return enGB;\n case LanguageLocales.NORWEGIAN_NYNORSK:\n return nnNO;\n case LanguageLocales.SAMI_NORTHERN:\n return seNO;\n case LanguageLocales.NORWEGIAN:\n default:\n return nbNO;\n }\n};\n","import classNames from 'classnames';\n\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport Icon from '../Icon';\nimport ChevronLeft from '../Icons/ChevronLeft';\n\nimport styles from './DrawerBackButton.module.scss';\n\nexport interface DrawerBackButtonProps {\n /** Function is called when user clicks the button */\n onClick?: (e?: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Sets the aria-label of the button */\n ariaLabel?: string;\n /** Adds custom classes to the element. */\n className?: string;\n}\n\nconst DrawerBackButton: React.FC<DrawerBackButtonProps> = props => {\n const { ariaLabel = 'Tilbake', onClick, className } = props;\n const { refObject, isHovered } = usePseudoClasses<HTMLButtonElement>();\n\n const iconSize = useIsMobileBreakpoint() ? 38 : 48;\n\n return (\n <button ref={refObject} className={classNames(styles['back-button'], className)} aria-label={ariaLabel} onClick={onClick} type=\"button\">\n <span className={classNames(styles['back-button__inner-container'])}>\n <Icon svgIcon={ChevronLeft} color={'var(--color-action-graphics-onlight'} size={iconSize} isHovered={isHovered} />\n </span>\n </button>\n );\n};\n\nexport default DrawerBackButton;\n","import React, { useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\nimport { AnimatePresence, useAnimate, usePresence } from 'motion/react';\n\nimport type { HNDesignsystemDrawer } from '../../resources/Resources';\nimport type { TitleTags } from '../Title';\n\nimport { getResources } from './resourceHelper';\nimport { AnalyticsId, KeyboardEventKey, LanguageLocales, ZIndex } from '../../constants';\nimport useFocusTrap from '../../hooks/useFocusTrap';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useKeyboardEvent } from '../../hooks/useKeyboardEvent';\nimport { useLanguage } from '../../hooks/useLanguage';\nimport { useOutsideEvent } from '../../hooks/useOutsideEvent';\nimport { useReturnFocusOnUnmount } from '../../hooks/useReturnFocusOnUnmount';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport { disableBodyScroll, enableBodyScroll } from '../../utils/scroll';\nimport uuid from '../../utils/uuid';\nimport Button from '../Button';\nimport Close from '../Close';\nimport Title from '../Title';\nimport DrawerBackButton from './DrawerBackButton';\n\nimport styles from './styles.module.scss';\n\ntype DesktopDirections = 'left' | 'right';\n\nexport interface DrawerProps extends InnerDrawerProps {\n /** Opens and closes the drawer */\n isOpen: boolean;\n}\n\nexport interface InnerDrawerProps {\n /** Sets the aria-label of the drawer */\n ariaLabel?: string;\n /** Sets the aria-labelledby of the drawer */\n ariaLabelledBy?: string;\n /** Sets the style of the Drawer Close button. Meant for use by HelpDrawer */\n closeColor?: 'blueberry' | 'plum';\n /** Direction of the drawer on desktop. Default: left */\n desktopDirection?: DesktopDirections;\n /** Sets the style of the Drawer header */\n headerClasses?: string;\n /** Title to display in the header of the drawer */\n title: string;\n /** id of the drawer title */\n titleId?: string;\n /** Changes the underlying element of the title. Default: h3 */\n titleHtmlMarkup?: TitleTags;\n /** Callback that triggers when clicking on close button or outside the drawer, update isOpen state when this triggers */\n onRequestClose?: () => void;\n /** Optional footer content that can be rendered instead of default CTA(s) */\n footerContent?: React.ReactNode;\n /** Main content of the drawer */\n children?: React.ReactNode;\n /** Hides the close button */\n noCloseButton?: boolean;\n /** Primary CTA callback */\n onPrimaryAction?: () => void;\n /** Text for primary CTA button if you want a default CTA button rendered (instead of `footerContent`) */\n primaryActionText?: string;\n /** Text for secondary CTA button if you want a default CTA button rendered (instead of `footerContent`) */\n secondaryActionText?: string;\n /** Secondary CTA callback */\n onSecondaryAction?: () => void;\n /** Customize the z-index of the drawer */\n zIndex?: number;\n /** Resources for component */\n resources?: Partial<HNDesignsystemDrawer>;\n /** Sets mobile styling and animation from outer level Drawer */\n isMobile?: boolean;\n /** Shows a back button to the left of title */\n withBackButton?: boolean;\n /** Callback for the back button */\n onRequestBack?: () => void;\n /** Sets classname for content part in Drawer */\n contentClassName?: string;\n}\n\nconst Drawer: React.FC<DrawerProps> = props => {\n const { isOpen, ...rest } = props;\n const isMobile = useIsMobileBreakpoint();\n\n return <AnimatePresence>{isOpen && <InnerDrawer {...rest} isMobile={isMobile} />}</AnimatePresence>;\n};\n\nconst InnerDrawer: React.FC<InnerDrawerProps> = props => {\n const {\n ariaLabel,\n ariaLabelledBy,\n children,\n closeColor = 'blueberry',\n desktopDirection = 'left',\n footerContent,\n headerClasses,\n noCloseButton = false,\n onPrimaryAction,\n onRequestClose,\n onSecondaryAction,\n primaryActionText,\n secondaryActionText,\n title,\n titleHtmlMarkup = 'h3',\n titleId = uuid(),\n zIndex = ZIndex.OverlayScreen,\n resources,\n isMobile,\n withBackButton,\n onRequestBack,\n contentClassName,\n } = props;\n\n const ariaLabelAttributes = getAriaLabelAttributes({ label: ariaLabel, id: ariaLabelledBy, fallbackId: titleId });\n const overlayRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n // topContent and bottomContent are used to detect scroll position for shadow effects\n const topContent = useRef<HTMLDivElement>(null);\n const bottomContent = useRef<HTMLDivElement>(null);\n const headerRef = useRef<HTMLDivElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n const titleRef = useRef<HTMLHeadingElement>(null);\n const [scope, animate] = useAnimate();\n const [isPresent, safeToRemove] = usePresence();\n const [headerHeight, setHeaderHeight] = React.useState(0);\n const [footerHeight, setFooterHeight] = React.useState(0);\n const topContentVisible = useIsVisible(topContent);\n const bottomContentVisible = useIsVisible(bottomContent, 0);\n const { language } = useLanguage<LanguageLocales>(LanguageLocales.NORWEGIAN);\n const defaultResources = getResources(language);\n\n const mergedResources: HNDesignsystemDrawer = {\n ...defaultResources,\n ...resources,\n };\n\n // eslint-disable-next-line react-hooks/refs\n const contentIsScrollable = contentRef.current && contentRef.current.scrollHeight > contentRef.current.clientHeight;\n const headerStyling = classNames(styles.drawer__header, headerClasses);\n const hasFooterContent = (typeof footerContent !== 'undefined' && footerContent) || onPrimaryAction || onSecondaryAction;\n\n useFocusTrap(containerRef, true);\n useReturnFocusOnUnmount(containerRef);\n useOutsideEvent(containerRef, () => {\n if (onRequestClose) onRequestClose();\n });\n useKeyboardEvent(containerRef, () => onRequestClose && onRequestClose(), [KeyboardEventKey.Escape]);\n\n // Close animasjon, vi kaller `onClose()` til slutt\n const closeDrawer = (): void => {\n if (!overlayRef.current || !containerRef.current) return;\n\n animate(overlayRef.current, { opacity: 0, pointerEvents: 'none' }, { duration: 0.3, ease: 'easeInOut' });\n\n if (isMobile) {\n animate(\n containerRef.current,\n { y: '100%' },\n {\n duration: 0.3,\n ease: 'easeInOut',\n onComplete: () => {\n if (safeToRemove) safeToRemove();\n },\n }\n );\n } else {\n animate(\n containerRef.current,\n { x: desktopDirection === 'left' ? '-100%' : '100%' },\n {\n duration: 0.3,\n ease: 'easeInOut',\n onComplete: () => {\n if (safeToRemove) safeToRemove();\n },\n }\n );\n }\n };\n\n useEffect(() => {\n containerRef.current?.focus();\n disableBodyScroll();\n\n return (): void => {\n enableBodyScroll();\n };\n }, []);\n\n // Measure header and footer heights\n useEffect(() => {\n const updateHeights = (): void => {\n if (headerRef.current) {\n setHeaderHeight(headerRef.current.offsetHeight);\n }\n if (footerRef.current) {\n setFooterHeight(footerRef.current.offsetHeight);\n }\n };\n\n updateHeights();\n\n // Update heights when content changes\n const resizeObserver = new ResizeObserver(updateHeights);\n if (headerRef.current) {\n resizeObserver.observe(headerRef.current);\n }\n if (footerRef.current) {\n resizeObserver.observe(footerRef.current);\n }\n\n return (): void => {\n resizeObserver.disconnect();\n };\n }, [hasFooterContent]);\n\n // Open animation.\n useEffect(() => {\n if (!overlayRef.current || !containerRef.current) return;\n\n if (!isPresent) {\n closeDrawer();\n return;\n }\n\n if (isMobile) {\n animate(containerRef.current, { y: '0' }, { duration: 0.3, ease: 'easeInOut' });\n } else {\n animate(containerRef.current, { x: '0' }, { duration: 0.3, ease: 'easeInOut' });\n }\n\n animate(overlayRef.current, { opacity: 1, pointerEvents: 'auto' }, { duration: 0.3, ease: 'easeInOut' });\n }, [isPresent]);\n\n const handleCTA = (callback?: () => void): void => {\n if (callback) {\n callback();\n }\n };\n\n useEffect(() => {\n titleRef.current?.focus();\n }, [title]);\n\n return (\n <div className={styles.drawer} ref={scope} style={{ zIndex }} data-analyticsid={AnalyticsId.Drawer}>\n <div className={styles.drawer__overlay} ref={overlayRef} aria-hidden=\"true\" />\n <div\n className={classNames(styles.drawer__container, {\n [styles['drawer__container--right']]: desktopDirection === 'right',\n })}\n ref={containerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n {...ariaLabelAttributes}\n >\n <div className={styles.drawer__container__inner}>\n <div className={headerStyling} ref={headerRef}>\n <Title\n id={ariaLabelAttributes?.['aria-labelledby']}\n className={styles['drawer__header__title']}\n htmlMarkup={titleHtmlMarkup}\n appearance=\"title3\"\n ref={titleRef}\n tabIndex={-1}\n >\n {title}\n </Title>\n {withBackButton && onRequestBack !== undefined && (\n <DrawerBackButton\n ariaLabel={mergedResources.ariaLabelBackButton}\n onClick={onRequestBack}\n className={styles['drawer__header__back-button']}\n />\n )}\n {!noCloseButton && onRequestClose != undefined && (\n <Close\n ariaLabel={mergedResources.ariaLabelCloseBtn}\n color={closeColor}\n onClick={onRequestClose}\n className={styles['drawer__header__close-button']}\n />\n )}\n </div>\n <div\n className={classNames(styles['drawer__content__shadow'], styles['drawer__content__shadow--top'])}\n style={{\n opacity: !topContentVisible && contentIsScrollable ? 1 : 0,\n top: headerHeight,\n }}\n />\n <div\n className={classNames(styles.drawer__content, contentClassName)}\n tabIndex={contentIsScrollable ? 0 : undefined}\n role={contentIsScrollable ? 'region' : undefined}\n {...(contentIsScrollable ? ariaLabelAttributes : {})}\n ref={contentRef}\n >\n <div ref={topContent} />\n <div className={styles['drawer__content__children']}>{children}</div>\n <div ref={bottomContent} style={{ height: '1px' }} />\n </div>\n <div\n className={classNames(styles['drawer__content__shadow'], styles['drawer__content__shadow--bottom'])}\n style={{\n opacity: !bottomContentVisible && contentIsScrollable ? 1 : 0,\n bottom: hasFooterContent ? footerHeight : 0,\n }}\n />\n </div>\n {hasFooterContent && (\n <div className={styles.drawer__footer} ref={footerRef}>\n {footerContent ? (\n footerContent\n ) : (\n <>\n {onPrimaryAction && <Button onClick={() => handleCTA(onPrimaryAction)}>{primaryActionText}</Button>}\n {onSecondaryAction && (\n <Button variant=\"borderless\" onClick={() => handleCTA(onSecondaryAction)}>\n {secondaryActionText}\n </Button>\n )}\n </>\n )}\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Drawer;\n","import Drawer from './Drawer';\nexport * from './Drawer';\nexport default Drawer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AIQA,IAAa,gBAAgB,aAAoD;CAC/E,QAAQ,UAAR;EACE,KAAK,gBAAgB,SACnB,OAAO;EACT,KAAK,gBAAgB,mBACnB,OAAO;EACT,KAAK,gBAAgB,eACnB,OAAO;EACT,KAAK,gBAAgB;EACrB,SACE,OAAO;CACX;AACF;;;ACFA,IAAM,oBAAoD,UAAS;CACjE,MAAM,EAAE,YAAY,WAAW,SAAS,cAAc;CACtD,MAAM,EAAE,WAAW,cAAc,iBAAoC;CAErE,MAAM,WAAW,sBAAsB,IAAI,KAAK;CAEhD,OACE,oBAAC,UAAD;EAAQ,KAAK;EAAW,WAAW,WAAW,OAAO,gBAAgB,SAAS;EAAG,cAAY;EAAoB;EAAS,MAAK;YAC7H,oBAAC,QAAD;GAAM,WAAW,WAAW,OAAO,+BAA+B;aAChE,oBAAC,cAAD;IAAM,SAAS;IAAa,OAAO;IAAuC,MAAM;IAAqB;GAAY,CAAA;EAC7G,CAAA;CACA,CAAA;AAEZ;;;ACkDA,IAAM,UAAgC,UAAS;CAC7C,MAAM,EAAE,QAAQ,GAAG,SAAS;CAC5B,MAAM,WAAW,sBAAsB;CAEvC,OAAO,oBAAC,iBAAD,EAAA,UAAkB,UAAU,oBAAC,aAAD;EAAa,GAAI;EAAgB;CAAW,CAAA,EAAmB,CAAA;AACpG;AAEA,IAAM,eAA0C,UAAS;CACvD,MAAM,EACJ,WACA,gBACA,UACA,aAAa,aACb,mBAAmB,QACnB,eACA,eACA,gBAAgB,OAChB,iBACA,gBACA,mBACA,mBACA,qBACA,OACA,kBAAkB,MAClB,UAAU,KAAK,GACf,SAAS,OAAO,eAChB,WACA,UACA,gBACA,eACA,qBACE;CAEJ,MAAM,sBAAsB,uBAAuB;EAAE,OAAO;EAAW,IAAI;EAAgB,YAAY;CAA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,EAAE,QAAQ,MAAM;OAAI,CAAA;MACjD;;KACL,oBAAC,OAAD;MACE,WAAW,WAAW,SAAO,4BAA4B,SAAO,kCAAkC;MAClG,OAAO;OACL,SAAS,CAAC,wBAAwB,sBAAsB,IAAI;OAC5D,QAAQ,mBAAmB,eAAe;MAC5C;KACD,CAAA;IACE;OACJ,oBACC,oBAAC,OAAD;IAAK,WAAW,SAAO;IAAgB,KAAK;cACzC,gBACC,gBAEA,qBAAA,UAAA,EAAA,UAAA,CACG,mBAAmB,oBAAC,gBAAD;KAAQ,eAAe,UAAU,eAAe;eAAI;IAA0B,CAAA,GACjG,qBACC,oBAAC,gBAAD;KAAQ,SAAQ;KAAa,eAAe,UAAU,iBAAiB;eACpE;IACK,CAAA,CAEV,EAAA,CAAA;GAED,CAAA,CAEJ;IACF;;AAET;;;AC3UA,IAAA,iBAAe"}
|
|
1
|
+
{"version":3,"file":"Drawer.js","names":[],"sources":["../src/resources/HN.Designsystem.Drawer.en-GB.json","../src/resources/HN.Designsystem.Drawer.nb-NO.json","../src/resources/HN.Designsystem.Drawer.nn-NO.json","../src/resources/HN.Designsystem.Drawer.se-NO.json","../src/components/Drawer/resourceHelper.ts","../src/components/Drawer/DrawerBackButton.tsx","../src/components/Drawer/DrawerHeaderContent.tsx","../src/components/Drawer/Drawer.tsx","../src/components/Drawer/index.ts"],"sourcesContent":["{\n \"ariaLabelCloseBtn\": \"Close\",\n \"ariaLabelBackButton\": \"Go back\"\n}\n","{\n \"ariaLabelBackButton\": \"Gå tilbake\",\n \"ariaLabelCloseBtn\": \"Lukk\"\n}\n","{\n \"ariaLabelCloseBtn\": \"Lukk\",\n \"ariaLabelBackButton\": \"Gå tilbake\"\n}\n","{\n \"ariaLabelCloseBtn\": \"Gidde\",\n \"ariaLabelBackButton\": \"Mana ruovttoluotta\"\n}\n","import type { HNDesignsystemDrawer } from '../../resources/Resources';\n\nimport { LanguageLocales } from '../../constants';\nimport enGB from '../../resources/HN.Designsystem.Drawer.en-GB.json';\nimport nbNO from '../../resources/HN.Designsystem.Drawer.nb-NO.json';\nimport nnNO from '../../resources/HN.Designsystem.Drawer.nn-NO.json';\nimport seNO from '../../resources/HN.Designsystem.Drawer.se-NO.json';\n\nexport const getResources = (language: LanguageLocales): HNDesignsystemDrawer => {\n switch (language) {\n case LanguageLocales.ENGLISH:\n return enGB;\n case LanguageLocales.NORWEGIAN_NYNORSK:\n return nnNO;\n case LanguageLocales.SAMI_NORTHERN:\n return seNO;\n case LanguageLocales.NORWEGIAN:\n default:\n return nbNO;\n }\n};\n","import classNames from 'classnames';\n\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport Icon from '../Icon';\nimport ChevronLeft from '../Icons/ChevronLeft';\n\nimport styles from './DrawerBackButton.module.scss';\n\nexport interface DrawerBackButtonProps {\n /** Function is called when user clicks the button */\n onClick?: (e?: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Sets the aria-label of the button */\n ariaLabel?: string;\n /** Adds custom classes to the element. */\n className?: string;\n}\n\nconst DrawerBackButton: React.FC<DrawerBackButtonProps> = props => {\n const { ariaLabel = 'Tilbake', onClick, className } = props;\n const { refObject, isHovered } = usePseudoClasses<HTMLButtonElement>();\n\n const iconSize = useIsMobileBreakpoint() ? 38 : 48;\n\n return (\n <button ref={refObject} className={classNames(styles['back-button'], className)} aria-label={ariaLabel} onClick={onClick} type=\"button\">\n <span className={classNames(styles['back-button__inner-container'])}>\n <Icon svgIcon={ChevronLeft} color={'var(--color-action-graphics-onlight'} size={iconSize} isHovered={isHovered} />\n </span>\n </button>\n );\n};\n\nexport default DrawerBackButton;\n","import type React from 'react';\n\nimport classNames from 'classnames';\n\nimport type { TitleTags } from '../Title';\n\nimport DrawerBackButton from './DrawerBackButton';\nimport Title from '../Title';\n\nimport styles from './DrawerHeaderContent.module.scss';\n\nexport interface DrawerHeaderContentProps {\n /** Title shown in the header */\n title?: React.ReactNode;\n /** id of the title element */\n titleId?: string;\n /** Ref passed to the title heading element */\n titleRef?: React.Ref<HTMLHeadingElement | null>;\n /** Changes the underlying element of the title. Default: h3 */\n titleHtmlMarkup?: TitleTags;\n /** Shows a back button before the title. When present the title is centered. */\n withBackButton?: boolean;\n /** Callback for the back button */\n onRequestBack?: () => void;\n /** Sets the aria-label of the back button */\n backButtonAriaLabel?: string;\n /** Adds custom classes to the root element. */\n className?: string;\n}\n\nconst DrawerHeaderContent: React.FC<DrawerHeaderContentProps> = props => {\n const { title, titleId, titleRef, titleHtmlMarkup = 'h3', withBackButton, onRequestBack, backButtonAriaLabel, className } = props;\n\n return (\n <div className={classNames(styles['header-content'], className)}>\n <span\n className={classNames(styles['header-content__title'], {\n [styles['header-content__title--centered']]: withBackButton,\n })}\n >\n <Title id={titleId} ref={titleRef} tabIndex={-1} htmlMarkup={titleHtmlMarkup} appearance=\"title3\">\n {title}\n </Title>\n </span>\n {withBackButton && (\n <DrawerBackButton ariaLabel={backButtonAriaLabel} onClick={onRequestBack} className={styles['header-content__back-button']} />\n )}\n </div>\n );\n};\n\nexport default DrawerHeaderContent;\n","import React, { useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\nimport { AnimatePresence, useAnimate, usePresence } from 'motion/react';\n\nimport type { HNDesignsystemDrawer } from '../../resources/Resources';\nimport type { TitleTags } from '../Title';\n\nimport { getResources } from './resourceHelper';\nimport { AnalyticsId, KeyboardEventKey, LanguageLocales, ZIndex } from '../../constants';\nimport useFocusTrap from '../../hooks/useFocusTrap';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useKeyboardEvent } from '../../hooks/useKeyboardEvent';\nimport { useLanguage } from '../../hooks/useLanguage';\nimport { useOutsideEvent } from '../../hooks/useOutsideEvent';\nimport { useReturnFocusOnUnmount } from '../../hooks/useReturnFocusOnUnmount';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport { disableBodyScroll, enableBodyScroll } from '../../utils/scroll';\nimport uuid from '../../utils/uuid';\nimport Button from '../Button';\nimport Close from '../Close';\nimport DrawerHeaderContent from './DrawerHeaderContent';\n\nimport styles from './styles.module.scss';\n\ntype DesktopDirections = 'left' | 'right';\ntype PaddingSizes = 'normal' | 'extra';\n\nexport interface DrawerProps extends InnerDrawerProps {\n /** Opens and closes the drawer */\n isOpen: boolean;\n}\n\nexport interface InnerDrawerProps {\n /** Sets the aria-label of the drawer */\n ariaLabel?: string;\n /** Sets the aria-labelledby of the drawer */\n ariaLabelledBy?: string;\n /** Sets the style of the Drawer Close button. Meant for use by HelpDrawer */\n closeColor?: 'blueberry' | 'plum';\n /** Direction of the drawer on desktop. Default: left */\n desktopDirection?: DesktopDirections;\n /** Sets the style of the Drawer header */\n headerClasses?: string;\n /** Optional content that replaces the default title (and back button) in the header. The close button is still rendered. */\n headerContent?: React.ReactNode;\n /** Title to display in the header of the drawer */\n title?: string;\n /** id of the drawer title */\n titleId?: string;\n /** Changes the underlying element of the title. Default: h3 */\n titleHtmlMarkup?: TitleTags;\n /** Callback that triggers when clicking on close button or outside the drawer, update isOpen state when this triggers */\n onRequestClose?: () => void;\n /** Optional footer content that can be rendered instead of default CTA(s) */\n footerContent?: React.ReactNode;\n /** Main content of the drawer */\n children?: React.ReactNode;\n /** Hides the close button */\n noCloseButton?: boolean;\n /** Primary CTA callback */\n onPrimaryAction?: () => void;\n /** Text for primary CTA button if you want a default CTA button rendered (instead of `footerContent`) */\n primaryActionText?: string;\n /** Text for secondary CTA button if you want a default CTA button rendered (instead of `footerContent`) */\n secondaryActionText?: string;\n /** Secondary CTA callback */\n onSecondaryAction?: () => void;\n /** Customize the z-index of the drawer */\n zIndex?: number;\n /** Resources for component */\n resources?: Partial<HNDesignsystemDrawer>;\n /** Sets mobile styling and animation from outer level Drawer */\n isMobile?: boolean;\n /** Shows a back button to the left of title */\n withBackButton?: boolean;\n /** Callback for the back button */\n onRequestBack?: () => void;\n /** Sets classname for content part in Drawer */\n contentClassName?: string;\n /** Sets the content padding of the Drawer */\n paddingSize?: PaddingSizes;\n}\n\nconst Drawer: React.FC<DrawerProps> = props => {\n const { isOpen, ...rest } = props;\n const isMobile = useIsMobileBreakpoint();\n\n return <AnimatePresence>{isOpen && <InnerDrawer {...rest} isMobile={isMobile} />}</AnimatePresence>;\n};\n\nconst InnerDrawer: React.FC<InnerDrawerProps> = props => {\n const {\n ariaLabel,\n ariaLabelledBy,\n children,\n closeColor = 'blueberry',\n desktopDirection = 'left',\n footerContent,\n headerClasses,\n headerContent,\n noCloseButton = false,\n onPrimaryAction,\n onRequestClose,\n onSecondaryAction,\n primaryActionText,\n secondaryActionText,\n title,\n titleHtmlMarkup = 'h3',\n titleId = uuid(),\n zIndex = ZIndex.OverlayScreen,\n resources,\n isMobile,\n withBackButton,\n onRequestBack,\n contentClassName,\n paddingSize = 'normal',\n } = props;\n\n const ariaLabelAttributes = getAriaLabelAttributes({ label: ariaLabel, id: ariaLabelledBy, fallbackId: titleId });\n const overlayRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n // topContent and bottomContent are used to detect scroll position for shadow effects\n const topContent = useRef<HTMLDivElement>(null);\n const bottomContent = useRef<HTMLDivElement>(null);\n const headerRef = useRef<HTMLDivElement>(null);\n const footerRef = useRef<HTMLDivElement>(null);\n const titleRef = useRef<HTMLHeadingElement>(null);\n const [scope, animate] = useAnimate();\n const [isPresent, safeToRemove] = usePresence();\n const [headerHeight, setHeaderHeight] = React.useState(0);\n const [footerHeight, setFooterHeight] = React.useState(0);\n const topContentVisible = useIsVisible(topContent);\n const bottomContentVisible = useIsVisible(bottomContent, 0);\n const { language } = useLanguage<LanguageLocales>(LanguageLocales.NORWEGIAN);\n const defaultResources = getResources(language);\n\n const mergedResources: HNDesignsystemDrawer = {\n ...defaultResources,\n ...resources,\n };\n\n // eslint-disable-next-line react-hooks/refs\n const contentIsScrollable = contentRef.current && contentRef.current.scrollHeight > contentRef.current.clientHeight;\n const headerStyling = classNames(\n styles.drawer__header,\n { [styles['drawer__header--padding-extra']]: paddingSize === 'extra' },\n headerClasses\n );\n const hasFooterContent = (typeof footerContent !== 'undefined' && footerContent) || onPrimaryAction || onSecondaryAction;\n\n useFocusTrap(containerRef, true);\n useReturnFocusOnUnmount(containerRef);\n useOutsideEvent(containerRef, () => {\n if (onRequestClose) onRequestClose();\n });\n useKeyboardEvent(containerRef, () => onRequestClose && onRequestClose(), [KeyboardEventKey.Escape]);\n\n // Close animasjon, vi kaller `onClose()` til slutt\n const closeDrawer = (): void => {\n if (!overlayRef.current || !containerRef.current) return;\n\n animate(overlayRef.current, { opacity: 0, pointerEvents: 'none' }, { duration: 0.3, ease: 'easeInOut' });\n\n if (isMobile) {\n animate(\n containerRef.current,\n { y: '100%' },\n {\n duration: 0.3,\n ease: 'easeInOut',\n onComplete: () => {\n if (safeToRemove) safeToRemove();\n },\n }\n );\n } else {\n animate(\n containerRef.current,\n { x: desktopDirection === 'left' ? '-100%' : '100%' },\n {\n duration: 0.3,\n ease: 'easeInOut',\n onComplete: () => {\n if (safeToRemove) safeToRemove();\n },\n }\n );\n }\n };\n\n useEffect(() => {\n containerRef.current?.focus();\n disableBodyScroll();\n\n return (): void => {\n enableBodyScroll();\n };\n }, []);\n\n // Measure header and footer heights\n useEffect(() => {\n const updateHeights = (): void => {\n if (headerRef.current) {\n setHeaderHeight(headerRef.current.offsetHeight);\n }\n if (footerRef.current) {\n setFooterHeight(footerRef.current.offsetHeight);\n }\n };\n\n updateHeights();\n\n // Update heights when content changes\n const resizeObserver = new ResizeObserver(updateHeights);\n if (headerRef.current) {\n resizeObserver.observe(headerRef.current);\n }\n if (footerRef.current) {\n resizeObserver.observe(footerRef.current);\n }\n\n return (): void => {\n resizeObserver.disconnect();\n };\n }, [hasFooterContent]);\n\n // Open animation.\n useEffect(() => {\n if (!overlayRef.current || !containerRef.current) return;\n\n if (!isPresent) {\n closeDrawer();\n return;\n }\n\n if (isMobile) {\n animate(containerRef.current, { y: '0' }, { duration: 0.3, ease: 'easeInOut' });\n } else {\n animate(containerRef.current, { x: '0' }, { duration: 0.3, ease: 'easeInOut' });\n }\n\n animate(overlayRef.current, { opacity: 1, pointerEvents: 'auto' }, { duration: 0.3, ease: 'easeInOut' });\n }, [isPresent]);\n\n const handleCTA = (callback?: () => void): void => {\n if (callback) {\n callback();\n }\n };\n\n useEffect(() => {\n titleRef.current?.focus();\n }, [title]);\n\n const headerMain = (\n <DrawerHeaderContent\n title={title}\n titleId={ariaLabelAttributes?.['aria-labelledby']}\n titleRef={titleRef}\n titleHtmlMarkup={titleHtmlMarkup}\n withBackButton={withBackButton && onRequestBack !== undefined}\n onRequestBack={onRequestBack}\n backButtonAriaLabel={mergedResources.ariaLabelBackButton}\n />\n );\n\n return (\n <div className={styles.drawer} ref={scope} style={{ zIndex }} data-analyticsid={AnalyticsId.Drawer}>\n <div className={styles.drawer__overlay} ref={overlayRef} aria-hidden=\"true\" />\n <div\n className={classNames(styles.drawer__container, {\n [styles['drawer__container--right']]: desktopDirection === 'right',\n })}\n ref={containerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n tabIndex={-1}\n {...ariaLabelAttributes}\n >\n <div className={styles.drawer__container__inner}>\n <div className={headerStyling} ref={headerRef}>\n {headerContent ?? headerMain}\n {!noCloseButton && onRequestClose != undefined && (\n <Close\n ariaLabel={mergedResources.ariaLabelCloseBtn}\n color={closeColor}\n onClick={onRequestClose}\n className={styles['drawer__header__close-button']}\n />\n )}\n </div>\n <div\n className={classNames(styles['drawer__content__shadow'], styles['drawer__content__shadow--top'])}\n style={{\n opacity: !topContentVisible && contentIsScrollable ? 1 : 0,\n top: headerHeight,\n }}\n />\n <div\n className={classNames(styles.drawer__content, contentClassName)}\n tabIndex={contentIsScrollable ? 0 : undefined}\n role={contentIsScrollable ? 'region' : undefined}\n {...(contentIsScrollable ? ariaLabelAttributes : {})}\n ref={contentRef}\n >\n <div ref={topContent} />\n <div\n className={classNames(styles['drawer__content__children'], {\n [styles['drawer__content__children--padding-extra']]: paddingSize === 'extra',\n })}\n >\n {children}\n </div>\n <div ref={bottomContent} style={{ height: '1px' }} />\n </div>\n <div\n className={classNames(styles['drawer__content__shadow'], styles['drawer__content__shadow--bottom'])}\n style={{\n opacity: !bottomContentVisible && contentIsScrollable ? 1 : 0,\n bottom: hasFooterContent ? footerHeight : 0,\n }}\n />\n </div>\n {hasFooterContent && (\n <div\n className={classNames(styles.drawer__footer, { [styles['drawer__footer--padding-extra']]: paddingSize === 'extra' })}\n ref={footerRef}\n >\n {footerContent ? (\n footerContent\n ) : (\n <>\n {onPrimaryAction && <Button onClick={() => handleCTA(onPrimaryAction)}>{primaryActionText}</Button>}\n {onSecondaryAction && (\n <Button variant=\"borderless\" onClick={() => handleCTA(onSecondaryAction)}>\n {secondaryActionText}\n </Button>\n )}\n </>\n )}\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Drawer;\n","import Drawer from './Drawer';\nexport * from './Drawer';\nexport default Drawer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AIQA,IAAa,gBAAgB,aAAoD;CAC/E,QAAQ,UAAR;EACE,KAAK,gBAAgB,SACnB,OAAO;EACT,KAAK,gBAAgB,mBACnB,OAAO;EACT,KAAK,gBAAgB,eACnB,OAAO;EACT,KAAK,gBAAgB;EACrB,SACE,OAAO;CACX;AACF;;;ACFA,IAAM,oBAAoD,UAAS;CACjE,MAAM,EAAE,YAAY,WAAW,SAAS,cAAc;CACtD,MAAM,EAAE,WAAW,cAAc,iBAAoC;CAErE,MAAM,WAAW,sBAAsB,IAAI,KAAK;CAEhD,OACE,oBAAC,UAAD;EAAQ,KAAK;EAAW,WAAW,GAAW,OAAO,gBAAgB,SAAS;EAAG,cAAY;EAAoB;EAAS,MAAK;YAC7H,oBAAC,QAAD;GAAM,WAAW,GAAW,OAAO,+BAA+B;aAChE,oBAAC,cAAD;IAAM,SA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C5D,QAAQ,mBAAmB,eAAe;MAC5C;KACD,CAAA;IACE;OACJ,oBACC,oBAAC,OAAD;IACE,WAAW,GAAW,SAAO,gBAAgB,GAAG,SAAO,mCAAmC,gBAAgB,QAAQ,CAAC;IACnH,KAAK;cAEJ,gBACC,gBAEA,qBAAA,UAAA,EAAA,UAAA,CACG,mBAAmB,oBAAC,gBAAD;KAAQ,eAAe,UAAU,eAAe;eAAI;IAA0B,CAAA,GACjG,qBACC,oBAAC,gBAAD;KAAQ,SAAQ;KAAa,eAAe,UAAU,iBAAiB;eACpE;IACK,CAAA,CAEV,EAAA,CAAA;GAED,CAAA,CAEJ;IACF;;AAET;;;AC1VA,IAAA,iBAAe"}
|
package/lib/DrawerNavigation.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
1
|
+
import { t as uuid } from "./uuid.js";
|
|
2
|
+
import { n as DrawerHeaderContent, t as Drawer_default } from "./Drawer.js";
|
|
3
|
+
import { Children, createContext, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { animate, useReducedMotion } from "motion/react";
|
|
6
|
+
import styles from "./components/Filter/DrawerNavigation/styles.module.scss";
|
|
4
7
|
//#region src/components/Filter/DrawerNavigation/useDrawerNavigation.ts
|
|
5
8
|
var DrawerNavigationContext = createContext(null);
|
|
6
9
|
function useDrawerNavigation() {
|
|
@@ -37,8 +40,20 @@ function parseChildren(children) {
|
|
|
37
40
|
}
|
|
38
41
|
function DrawerNavigation({ children, isOpen, initialView, onCloseButton, footer }) {
|
|
39
42
|
const { views, other } = useMemo(() => parseChildren(children), [children]);
|
|
43
|
+
const incomingContentRef = useRef(null);
|
|
44
|
+
const outgoingContentRef = useRef(null);
|
|
45
|
+
const incomingHeaderRef = useRef(null);
|
|
46
|
+
const outgoingHeaderRef = useRef(null);
|
|
47
|
+
const titleRef = useRef(null);
|
|
48
|
+
const titleId = useMemo(() => uuid(), []);
|
|
40
49
|
const homeView = views.find((v) => v.home) ?? views[0];
|
|
41
50
|
const [viewStack, setViewStack] = useState([homeView?.id]);
|
|
51
|
+
const prevStackLength = useRef(viewStack.length);
|
|
52
|
+
const prevView = useRef(void 0);
|
|
53
|
+
const reducedMotion = useReducedMotion();
|
|
54
|
+
const currentViewId = viewStack[viewStack.length - 1];
|
|
55
|
+
const currentView = views.find((v) => v.id === currentViewId);
|
|
56
|
+
const [outgoing, setOutgoing] = useState(null);
|
|
42
57
|
const goToView = useCallback((id) => {
|
|
43
58
|
if (views.some((v) => v.id === id)) setViewStack((stack) => [...stack, id]);
|
|
44
59
|
}, [views]);
|
|
@@ -48,8 +63,48 @@ function DrawerNavigation({ children, isOpen, initialView, onCloseButton, footer
|
|
|
48
63
|
const goToViewAndClearStack = useCallback((id) => {
|
|
49
64
|
if (views.some((v) => v.id === id)) setViewStack(id === homeView?.id ? [homeView.id] : [homeView?.id, id]);
|
|
50
65
|
}, [views, homeView]);
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!isOpen) {
|
|
68
|
+
prevView.current = void 0;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const previous = prevView.current;
|
|
72
|
+
prevView.current = currentView;
|
|
73
|
+
const previousStackLength = prevStackLength.current;
|
|
74
|
+
const dir = viewStack.length >= previousStackLength ? "left" : "right";
|
|
75
|
+
prevStackLength.current = viewStack.length;
|
|
76
|
+
if (isOpen && !reducedMotion && previous && currentView && previous.id !== currentView.id) setOutgoing({
|
|
77
|
+
view: previous,
|
|
78
|
+
dir,
|
|
79
|
+
withBackButton: previousStackLength > 1
|
|
80
|
+
});
|
|
81
|
+
}, [
|
|
82
|
+
viewStack,
|
|
83
|
+
currentView,
|
|
84
|
+
isOpen
|
|
85
|
+
]);
|
|
86
|
+
useLayoutEffect(() => {
|
|
87
|
+
if (!outgoing || !incomingContentRef.current || !outgoingContentRef.current) return;
|
|
88
|
+
const incomingFrom = outgoing.dir === "left" ? "100%" : "-100%";
|
|
89
|
+
const outgoingTo = outgoing.dir === "left" ? "-100%" : "100%";
|
|
90
|
+
const options = {
|
|
91
|
+
duration: .3,
|
|
92
|
+
ease: "easeInOut"
|
|
93
|
+
};
|
|
94
|
+
animate(incomingContentRef.current, { x: [incomingFrom, "0%"] }, options);
|
|
95
|
+
if (incomingHeaderRef.current) animate(incomingHeaderRef.current, { x: [incomingFrom, "0%"] }, options);
|
|
96
|
+
if (outgoingHeaderRef.current) animate(outgoingHeaderRef.current, { x: ["0%", outgoingTo] }, options);
|
|
97
|
+
const leaving = animate(outgoingContentRef.current, { x: ["0%", outgoingTo] }, {
|
|
98
|
+
...options,
|
|
99
|
+
onComplete: () => setOutgoing(null)
|
|
100
|
+
});
|
|
101
|
+
return () => {
|
|
102
|
+
leaving.stop();
|
|
103
|
+
};
|
|
104
|
+
}, [outgoing]);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (isOpen) titleRef.current?.focus();
|
|
107
|
+
}, [currentViewId, isOpen]);
|
|
53
108
|
const navigate = useMemo(() => ({
|
|
54
109
|
goBack,
|
|
55
110
|
goToView,
|
|
@@ -65,17 +120,61 @@ function DrawerNavigation({ children, isOpen, initialView, onCloseButton, footer
|
|
|
65
120
|
if (!isOpen) setViewStack([homeView?.id]);
|
|
66
121
|
else if (initialView && views.some((v) => v.id === initialView)) setViewStack(initialView === homeView?.id ? [homeView.id] : [homeView?.id, initialView]);
|
|
67
122
|
}
|
|
123
|
+
const headerContent = /* @__PURE__ */ jsxs("div", {
|
|
124
|
+
className: styles.header,
|
|
125
|
+
style: { overflow: outgoing ? "hidden" : "visible" },
|
|
126
|
+
children: [outgoing && /* @__PURE__ */ jsx("div", {
|
|
127
|
+
ref: outgoingHeaderRef,
|
|
128
|
+
"aria-hidden": true,
|
|
129
|
+
inert: true,
|
|
130
|
+
className: styles["header__layer"],
|
|
131
|
+
style: {
|
|
132
|
+
position: "absolute",
|
|
133
|
+
inset: 0
|
|
134
|
+
},
|
|
135
|
+
children: /* @__PURE__ */ jsx(DrawerHeaderContent, {
|
|
136
|
+
title: outgoing.view.title,
|
|
137
|
+
withBackButton: outgoing.withBackButton,
|
|
138
|
+
onRequestBack: () => void 0
|
|
139
|
+
})
|
|
140
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
141
|
+
ref: incomingHeaderRef,
|
|
142
|
+
className: styles["header__layer"],
|
|
143
|
+
children: /* @__PURE__ */ jsx(DrawerHeaderContent, {
|
|
144
|
+
title: currentView?.title,
|
|
145
|
+
titleId,
|
|
146
|
+
titleRef,
|
|
147
|
+
withBackButton: viewStack.length > 1,
|
|
148
|
+
onRequestBack: goBack
|
|
149
|
+
})
|
|
150
|
+
})]
|
|
151
|
+
});
|
|
68
152
|
return /* @__PURE__ */ jsxs(DrawerNavigationContext.Provider, {
|
|
69
153
|
value: navigate,
|
|
70
154
|
children: [/* @__PURE__ */ jsx(Drawer_default, {
|
|
71
155
|
isOpen,
|
|
72
|
-
title: currentView?.title ?? "Filter",
|
|
73
|
-
withBackButton: viewStack.length > 1,
|
|
74
|
-
onRequestBack: goBack,
|
|
75
156
|
onRequestClose: currentView?.onCloseButton ?? onCloseButton,
|
|
76
157
|
footerContent: currentView?.footer ?? footer,
|
|
77
158
|
contentClassName: currentView?.drawerContentClassname,
|
|
78
|
-
|
|
159
|
+
paddingSize: "extra",
|
|
160
|
+
headerContent,
|
|
161
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
162
|
+
className: styles["content"],
|
|
163
|
+
style: { overflow: outgoing ? "hidden" : "visible" },
|
|
164
|
+
children: [outgoing && /* @__PURE__ */ jsx("div", {
|
|
165
|
+
ref: outgoingContentRef,
|
|
166
|
+
"aria-hidden": true,
|
|
167
|
+
inert: true,
|
|
168
|
+
style: {
|
|
169
|
+
position: "absolute",
|
|
170
|
+
width: "100%"
|
|
171
|
+
},
|
|
172
|
+
children: outgoing.view.children
|
|
173
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
174
|
+
ref: incomingContentRef,
|
|
175
|
+
children: currentView?.children
|
|
176
|
+
})]
|
|
177
|
+
})
|
|
79
178
|
}), other]
|
|
80
179
|
});
|
|
81
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DrawerNavigation.js","names":[],"sources":["../src/components/Filter/DrawerNavigation/useDrawerNavigation.ts","../src/components/Filter/DrawerNavigation/DrawerNavigation.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nexport interface NavigateProps<ViewId extends string = string> {\n goToView: (id: ViewId) => void;\n goBack: () => void;\n goToViewAndClearStack: (id: ViewId) => void;\n}\n\nexport const DrawerNavigationContext = createContext<NavigateProps | null>(null);\n\nexport function useDrawerNavigation<ViewId extends string = string>(): NavigateProps<ViewId> {\n const context = useContext(DrawerNavigationContext);\n if (!context) {\n throw new Error('useDrawerNavigation must be used inside a <DrawerNavigation> component');\n }\n return context as NavigateProps<ViewId>;\n}\n","import type React from 'react';\nimport { Children, isValidElement, useCallback, useMemo, useState } from 'react';\n\nimport { type NavigateProps, DrawerNavigationContext } from './useDrawerNavigation';\nimport Drawer from '../../Drawer';\n\nexport interface DrawerViewProps<ViewId extends string = string> {\n /** Id for the view. Important for navigation */\n id: ViewId;\n /** Title used for Drawer in current view */\n title: string;\n /** Mark this view as the home/default view */\n home?: boolean;\n /** Content inside the drawer for this view */\n children: React.ReactNode;\n /** Default onClose callback for drawer. Will override onCloseButton on parent */\n onCloseButton?: () => void;\n /** Content sent to footer section of Drawer. Will override footer on parent */\n footer?: React.ReactNode;\n /** Classname set on the content inside Drawer */\n drawerContentClassname?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction DrawerView<ViewId extends string>(_props: DrawerViewProps<ViewId>): React.ReactNode {\n // DrawerView is never rendered directly — DrawerNavigation reads its props\n return null;\n}\n\nexport interface DrawerNavigationProps {\n /** Views and other children components inside the Drawer navigation. Views are put in stack */\n children: React.ReactNode;\n /** Is drawer open or closed */\n isOpen: boolean;\n /** Navigate to this view when the drawer opens. Defaults to home view. */\n initialView?: string;\n /** Default onClose callback for drawer. View onCloseButton callback will override this. */\n onCloseButton?: () => void;\n /** Content sent to footer section of Drawer. View footer will override this */\n footer?: React.ReactNode;\n}\n\nfunction parseChildren(children: React.ReactNode): { views: DrawerViewProps[]; other: React.ReactNode[] } {\n const views: DrawerViewProps[] = [];\n const other: React.ReactNode[] = [];\n Children.forEach(children, child => {\n if (isValidElement<DrawerViewProps>(child) && child.type === DrawerView) {\n views.push({\n id: child.props.id,\n title: child.props.title,\n home: child.props.home,\n children: child.props.children,\n onCloseButton: child.props.onCloseButton,\n footer: child.props.footer,\n drawerContentClassname: child.props.drawerContentClassname,\n });\n } else {\n /** Added possibility of other children to support Modals that need navigation context */\n other.push(child);\n }\n });\n return { views, other };\n}\n\nfunction DrawerNavigation({ children, isOpen, initialView, onCloseButton, footer }: DrawerNavigationProps): React.ReactNode {\n const { views, other } = useMemo(() => parseChildren(children), [children]);\n\n const homeView = views.find(v => v.home) ?? views[0];\n const [viewStack, setViewStack] = useState<string[]>([homeView?.id]);\n\n const goToView = useCallback(\n (id: string): void => {\n if (views.some(v => v.id === id)) {\n setViewStack(stack => [...stack, id]);\n }\n },\n [views]\n );\n\n const goBack = useCallback((): void => {\n setViewStack(stack => (stack.length > 1 ? stack.slice(0, -1) : stack));\n }, []);\n\n const goToViewAndClearStack = useCallback(\n (id: string): void => {\n if (views.some(v => v.id === id)) {\n setViewStack(id === homeView?.id ? [homeView.id] : [homeView?.id, id]);\n }\n },\n [views, homeView]\n );\n\n const currentViewId = viewStack[viewStack.length - 1];\n const currentView = views.find(v => v.id === currentViewId);\n\n const navigate = useMemo<NavigateProps>(() => ({ goBack, goToView, goToViewAndClearStack }), [goBack, goToView, goToViewAndClearStack]);\n\n const [prevIsOpen, setPrevIsOpen] = useState(isOpen);\n if (prevIsOpen !== isOpen) {\n setPrevIsOpen(isOpen);\n if (!isOpen) {\n setViewStack([homeView?.id]);\n } else if (initialView && views.some(v => v.id === initialView)) {\n setViewStack(initialView === homeView?.id ? [homeView.id] : [homeView?.id, initialView]);\n }\n }\n\n return (\n <DrawerNavigationContext.Provider value={navigate}>\n <Drawer\n isOpen={isOpen}\n title={currentView?.title ?? 'Filter'}\n withBackButton={viewStack.length > 1}\n onRequestBack={goBack}\n onRequestClose={currentView?.onCloseButton ?? onCloseButton}\n footerContent={currentView?.footer ?? footer}\n contentClassName={currentView?.drawerContentClassname}\n >\n {currentView?.children}\n </Drawer>\n {other}\n </DrawerNavigationContext.Provider>\n );\n}\n\nDrawerNavigation.View = DrawerView;\n\nexport default DrawerNavigation;\n"],"mappings":";;;;AAQA,IAAa,0BAA0B,cAAoC,IAAI;AAE/E,SAAgB,sBAA6E;CAC3F,MAAM,UAAU,WAAW,uBAAuB;CAClD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,wEAAwE;CAE1F,OAAO;AACT;;;ACQA,SAAS,WAAkC,QAAkD;CAE3F,OAAO;AACT;AAeA,SAAS,cAAc,UAAmF;CACxG,MAAM,QAA2B,CAAC;CAClC,MAAM,QAA2B,CAAC;CAClC,SAAS,QAAQ,WAAU,UAAS;EAClC,IAAI,eAAgC,KAAK,KAAK,MAAM,SAAS,YAC3D,MAAM,KAAK;GACT,IAAI,MAAM,MAAM;GAChB,OAAO,MAAM,MAAM;GACnB,MAAM,MAAM,MAAM;GAClB,UAAU,MAAM,MAAM;GACtB,eAAe,MAAM,MAAM;GAC3B,QAAQ,MAAM,MAAM;GACpB,wBAAwB,MAAM,MAAM;EACtC,CAAC;;;EAGD,MAAM,KAAK,KAAK;CAEpB,CAAC;CACD,OAAO;EAAE;EAAO;CAAM;AACxB;AAEA,SAAS,iBAAiB,EAAE,UAAU,QAAQ,aAAa,eAAe,UAAkD;CAC1H,MAAM,EAAE,OAAO,UAAU,cAAc,cAAc,QAAQ,GAAG,CAAC,QAAQ,CAAC;CAE1E,MAAM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,iBAAiB;GAC9C,eAAe,aAAa,UAAU;GACtC,kBAAkB,aAAa;aAE9B,aAAa;EACR,CAAA,GACP,KAC+B;;AAEtC;AAEA,iBAAiB,OAAO"}
|
|
1
|
+
{"version":3,"file":"DrawerNavigation.js","names":[],"sources":["../src/components/Filter/DrawerNavigation/useDrawerNavigation.ts","../src/components/Filter/DrawerNavigation/DrawerNavigation.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nexport interface NavigateProps<ViewId extends string = string> {\n goToView: (id: ViewId) => void;\n goBack: () => void;\n goToViewAndClearStack: (id: ViewId) => void;\n}\n\nexport const DrawerNavigationContext = createContext<NavigateProps | null>(null);\n\nexport function useDrawerNavigation<ViewId extends string = string>(): NavigateProps<ViewId> {\n const context = useContext(DrawerNavigationContext);\n if (!context) {\n throw new Error('useDrawerNavigation must be used inside a <DrawerNavigation> component');\n }\n return context as NavigateProps<ViewId>;\n}\n","import type React from 'react';\nimport { Children, isValidElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\n\nimport { animate, useReducedMotion } from 'motion/react';\n\nimport { type NavigateProps, DrawerNavigationContext } from './useDrawerNavigation';\nimport uuid from '../../../utils/uuid';\nimport Drawer from '../../Drawer';\nimport DrawerHeaderContent from '../../Drawer/DrawerHeaderContent';\n\nimport styles from './styles.module.scss';\n\nexport interface DrawerViewProps<ViewId extends string = string> {\n /** Id for the view. Important for navigation */\n id: ViewId;\n /** Title used for Drawer in current view */\n title: string;\n /** Mark this view as the home/default view */\n home?: boolean;\n /** Content inside the drawer for this view */\n children: React.ReactNode;\n /** Default onClose callback for drawer. Will override onCloseButton on parent */\n onCloseButton?: () => void;\n /** Content sent to footer section of Drawer. Will override footer on parent */\n footer?: React.ReactNode;\n /** Classname set on the content inside Drawer */\n drawerContentClassname?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction DrawerView<ViewId extends string>(_props: DrawerViewProps<ViewId>): React.ReactNode {\n // DrawerView is never rendered directly — DrawerNavigation reads its props\n return null;\n}\n\nexport interface DrawerNavigationProps {\n /** Views and other children components inside the Drawer navigation. Views are put in stack */\n children: React.ReactNode;\n /** Is drawer open or closed */\n isOpen: boolean;\n /** Navigate to this view when the drawer opens. Defaults to home view. */\n initialView?: string;\n /** Default onClose callback for drawer. View onCloseButton callback will override this. */\n onCloseButton?: () => void;\n /** Content sent to footer section of Drawer. View footer will override this */\n footer?: React.ReactNode;\n}\n\nfunction parseChildren(children: React.ReactNode): { views: DrawerViewProps[]; other: React.ReactNode[] } {\n const views: DrawerViewProps[] = [];\n const other: React.ReactNode[] = [];\n Children.forEach(children, child => {\n if (isValidElement<DrawerViewProps>(child) && child.type === DrawerView) {\n views.push({\n id: child.props.id,\n title: child.props.title,\n home: child.props.home,\n children: child.props.children,\n onCloseButton: child.props.onCloseButton,\n footer: child.props.footer,\n drawerContentClassname: child.props.drawerContentClassname,\n });\n } else {\n /** Added possibility of other children to support Modals that need navigation context */\n other.push(child);\n }\n });\n return { views, other };\n}\n\nfunction DrawerNavigation({ children, isOpen, initialView, onCloseButton, footer }: DrawerNavigationProps): React.ReactNode {\n const { views, other } = useMemo(() => parseChildren(children), [children]);\n\n const incomingContentRef = useRef<HTMLDivElement>(null);\n const outgoingContentRef = useRef<HTMLDivElement>(null);\n const incomingHeaderRef = useRef<HTMLDivElement>(null);\n const outgoingHeaderRef = useRef<HTMLDivElement>(null);\n const titleRef = useRef<HTMLHeadingElement>(null);\n const titleId = useMemo(() => uuid(), []);\n const homeView = views.find(v => v.home) ?? views[0];\n const [viewStack, setViewStack] = useState<string[]>([homeView?.id]);\n const prevStackLength = useRef<number>(viewStack.length);\n const prevView = useRef<DrawerViewProps | undefined>(undefined);\n const reducedMotion = useReducedMotion();\n\n const currentViewId = viewStack[viewStack.length - 1];\n const currentView = views.find(v => v.id === currentViewId);\n\n // The previous view, kept mounted as an overlay while it slides out during a navigation transition\n const [outgoing, setOutgoing] = useState<{ view: DrawerViewProps; dir: 'left' | 'right'; withBackButton: boolean } | null>(null);\n\n const goToView = useCallback(\n (id: string): void => {\n if (views.some(v => v.id === id)) {\n setViewStack(stack => [...stack, id]);\n }\n },\n [views]\n );\n\n const goBack = useCallback((): void => {\n setViewStack(stack => (stack.length > 1 ? stack.slice(0, -1) : stack));\n }, []);\n\n const goToViewAndClearStack = useCallback(\n (id: string): void => {\n if (views.some(v => v.id === id)) {\n setViewStack(id === homeView?.id ? [homeView.id] : [homeView?.id, id]);\n }\n },\n [views, homeView]\n );\n\n // Detect a navigation and capture the outgoing view + direction\n useEffect(() => {\n if (!isOpen) {\n prevView.current = undefined;\n return;\n }\n\n const previous = prevView.current;\n prevView.current = currentView;\n\n const previousStackLength = prevStackLength.current;\n const dir: 'left' | 'right' = viewStack.length >= previousStackLength ? 'left' : 'right';\n prevStackLength.current = viewStack.length;\n\n if (isOpen && !reducedMotion && previous && currentView && previous.id !== currentView.id) {\n setOutgoing({ view: previous, dir, withBackButton: previousStackLength > 1 });\n }\n }, [viewStack, currentView, isOpen]);\n\n // Animates the incoming and outgoing views\n useLayoutEffect(() => {\n if (!outgoing || !incomingContentRef.current || !outgoingContentRef.current) {\n return;\n }\n\n const incomingFrom = outgoing.dir === 'left' ? '100%' : '-100%';\n const outgoingTo = outgoing.dir === 'left' ? '-100%' : '100%';\n const options = { duration: 0.3, ease: 'easeInOut' } as const;\n\n animate(incomingContentRef.current, { x: [incomingFrom, '0%'] }, options);\n if (incomingHeaderRef.current) {\n animate(incomingHeaderRef.current, { x: [incomingFrom, '0%'] }, options);\n }\n if (outgoingHeaderRef.current) {\n animate(outgoingHeaderRef.current, { x: ['0%', outgoingTo] }, options);\n }\n const leaving = animate(outgoingContentRef.current, { x: ['0%', outgoingTo] }, { ...options, onComplete: () => setOutgoing(null) });\n\n return (): void => {\n leaving.stop();\n };\n }, [outgoing]);\n\n // Moves focus between incoming and outgoing view\n useEffect(() => {\n if (isOpen) {\n titleRef.current?.focus();\n }\n }, [currentViewId, isOpen]);\n\n const navigate = useMemo<NavigateProps>(() => ({ goBack, goToView, goToViewAndClearStack }), [goBack, goToView, goToViewAndClearStack]);\n\n const [prevIsOpen, setPrevIsOpen] = useState(isOpen);\n if (prevIsOpen !== isOpen) {\n setPrevIsOpen(isOpen);\n if (!isOpen) {\n setViewStack([homeView?.id]);\n } else if (initialView && views.some(v => v.id === initialView)) {\n setViewStack(initialView === homeView?.id ? [homeView.id] : [homeView?.id, initialView]);\n }\n }\n\n const headerContent = (\n <div className={styles.header} style={{ overflow: outgoing ? 'hidden' : 'visible' }}>\n {outgoing && (\n <div ref={outgoingHeaderRef} aria-hidden inert className={styles['header__layer']} style={{ position: 'absolute', inset: 0 }}>\n <DrawerHeaderContent title={outgoing.view.title} withBackButton={outgoing.withBackButton} onRequestBack={() => undefined} />\n </div>\n )}\n <div ref={incomingHeaderRef} className={styles['header__layer']}>\n <DrawerHeaderContent\n title={currentView?.title}\n titleId={titleId}\n titleRef={titleRef}\n withBackButton={viewStack.length > 1}\n onRequestBack={goBack}\n />\n </div>\n </div>\n );\n\n return (\n <DrawerNavigationContext.Provider value={navigate}>\n <Drawer\n isOpen={isOpen}\n onRequestClose={currentView?.onCloseButton ?? onCloseButton}\n footerContent={currentView?.footer ?? footer}\n contentClassName={currentView?.drawerContentClassname}\n paddingSize={'extra'}\n headerContent={headerContent}\n >\n <div className={styles['content']} style={{ overflow: outgoing ? 'hidden' : 'visible' }}>\n {outgoing && (\n <div ref={outgoingContentRef} aria-hidden inert style={{ position: 'absolute', width: '100%' }}>\n {outgoing.view.children}\n </div>\n )}\n <div ref={incomingContentRef}>{currentView?.children}</div>\n </div>\n </Drawer>\n {other}\n </DrawerNavigationContext.Provider>\n );\n}\n\nDrawerNavigation.View = DrawerView;\n\nexport default DrawerNavigation;\n"],"mappings":";;;;;;;AAQA,IAAa,0BAA0B,cAAoC,IAAI;AAE/E,SAAgB,sBAA6E;CAC3F,MAAM,UAAU,WAAW,uBAAuB;CAClD,IAAI,CAAC,SACH,MAAM,IAAI,MA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AgB,UAAU,SAAS;IACnC,eAAe;GAChB,CAAA;EACE,CAAA,CACF;;CAGP,OACE,qBAAC,wBAAwB,UAAzB;EAAkC,OAAO;YAAzC,CACE,oBAAC,gBAAD;GACU;GACR,gBAAgB,aAAa,iBAAiB;GAC9C,eAAe,aAAa,UAAU;GACtC,kBAAkB,aAAa;GAC/B,aAAa;GACE;aAEf,qBAAC,OAAD;IAAK,WAAW,OAAO;IAAY,OAAO,EAAE,UAAU,WAAW,WAAW,UAAU;cAAtF,CACG,YACC,oBAAC,OAAD;KAAK,KAAK;KAAoB,eAAA;KAAY,OAAA;KAAM,OAAO;MAAE,UAAU;MAAY,OAAO;KAAO;eAC1F,SAAS,KAAK;IACZ,CAAA,GAEP,oBAAC,OAAD;KAAK,KAAK;eAAqB,aAAa;IAAc,CAAA,CACvD;;EACC,CAAA,GACP,KAC+B;;AAEtC;AAEA,iBAAiB,OAAO"}
|
package/lib/Duolist.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnalyticsId } from "./constants.js";
|
|
2
2
|
import { Breakpoint, useBreakpoint } from "./hooks/useBreakpoint.js";
|
|
3
3
|
import { t as Spacer_default } from "./Spacer.js";
|
|
4
|
-
import
|
|
4
|
+
import cn from "classnames";
|
|
5
5
|
import React from "react";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import duolistStyles from "./components/Duolist/styles.module.scss";
|
|
@@ -11,11 +11,11 @@ var DuolistGroup = (props) => {
|
|
|
11
11
|
const firstBold = boldColumn === "first";
|
|
12
12
|
const secondBold = boldColumn === "second";
|
|
13
13
|
const nonFormatted = format === "non-formatted";
|
|
14
|
-
const dtClassNames =
|
|
14
|
+
const dtClassNames = cn(duolistStyles["duolist__dt"], {
|
|
15
15
|
[duolistStyles["duolist__dt--bold"]]: firstBold,
|
|
16
16
|
[duolistStyles["duolist__dt--non-formatted"]]: nonFormatted
|
|
17
17
|
});
|
|
18
|
-
const ddClassNames =
|
|
18
|
+
const ddClassNames = cn(duolistStyles["duolist__dd"], {
|
|
19
19
|
[duolistStyles["duolist__dd--bold"]]: secondBold,
|
|
20
20
|
[duolistStyles["duolist__dd--non-formatted"]]: nonFormatted
|
|
21
21
|
});
|
|
@@ -41,11 +41,11 @@ var Duolist = (props) => {
|
|
|
41
41
|
const nonFormatted = format === "non-formatted";
|
|
42
42
|
const breakpoint = useBreakpoint();
|
|
43
43
|
const useCollapsedMode = useCollapsedFromAndBelowBreakpoint && breakpoint <= Breakpoint[useCollapsedFromAndBelowBreakpoint];
|
|
44
|
-
const duolistWrapperClasses =
|
|
44
|
+
const duolistWrapperClasses = cn({
|
|
45
45
|
[duolistStyles["duolist-wrapper--border"]]: hasBorder,
|
|
46
46
|
[duolistStyles["duolist-wrapper--extra-padding-top"]]: extraPaddingTop
|
|
47
47
|
}, className);
|
|
48
|
-
const duolistClasses =
|
|
48
|
+
const duolistClasses = cn(duolistStyles.duolist, {
|
|
49
49
|
[duolistStyles["duolist--line"]]: hasLines,
|
|
50
50
|
[duolistStyles["duolist--non-formatted"]]: nonFormatted,
|
|
51
51
|
[duolistStyles["duolist--collapsed"]]: useCollapsedMode,
|
package/lib/Duolist.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Duolist.js","names":[],"sources":["../src/components/Duolist/Duolist.tsx","../src/components/Duolist/index.ts"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport type { TitleProps } from '../Title';\n\nimport { AnalyticsId } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport Spacer from '../Spacer';\n\nimport duolistStyles from './styles.module.scss';\n\nexport type DuolistVariants = 'normal' | 'line';\nexport type BoldColumn = 'first' | 'second' | 'none';\nexport type Border = 'no-border' | 'border';\nexport type Formats = 'formatted' | 'non-formatted';\n\nexport interface DuolistProps {\n /** Determines which column is bold */\n boldColumn?: BoldColumn;\n /** Label of the Duolist */\n border?: Border;\n /** Label of the Duolist */\n label?: React.ReactElement<TitleProps>;\n /** Formatted or non-formatted visual variants */\n format?: Formats;\n /** Character separator for non-formatted format */\n separator?: string;\n /** Sets the visual variant of the Duolist. */\n variant?: DuolistVariants;\n /** Sets the content of the Duolist. */\n children: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Width of the description column in percentage */\n descriptionWidth?: number;\n /** Use collapsed mode on columns from chosen breakpoint and below. */\n useCollapsedFromAndBelowBreakpoint?: keyof typeof Breakpoint;\n}\n\nexport interface DuolistGroupProps {\n /** Determines which column is bold */\n boldColumn?: BoldColumn;\n /** Sets content of the <dd> tag. */\n description: React.ReactNode;\n /** Formatted or non-formatted visual variants */\n format?: Formats;\n /** Character separator for non-formatted format */\n separator?: string;\n /** Sets content of the <dt> tag. */\n term: React.ReactNode;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const DuolistGroup: React.FC<DuolistGroupProps> = props => {\n const { format = 'formatted', boldColumn = format === 'non-formatted' ? 'none' : 'first', description, separator = ': ', term } = props;\n\n const firstBold = boldColumn === 'first';\n const secondBold = boldColumn === 'second';\n const nonFormatted = format === 'non-formatted';\n\n const dtClassNames = classNames(duolistStyles['duolist__dt'], {\n [duolistStyles['duolist__dt--bold']]: firstBold,\n [duolistStyles['duolist__dt--non-formatted']]: nonFormatted,\n });\n const ddClassNames = classNames(duolistStyles['duolist__dd'], {\n [duolistStyles['duolist__dd--bold']]: secondBold,\n [duolistStyles['duolist__dd--non-formatted']]: nonFormatted,\n });\n\n const renderContent = () => {\n return (\n <>\n <dt\n data-separator={nonFormatted ? separator : undefined}\n className={dtClassNames}\n data-testid={props.testId && `${props.testId}-term`}\n >\n {term}\n </dt>\n <dd className={ddClassNames} data-testid={props.testId && `${props.testId}-description`}>\n {description}\n </dd>\n </>\n );\n };\n\n return nonFormatted ? <div>{renderContent()}</div> : <>{renderContent()}</>;\n};\n\nexport const Duolist: React.FC<DuolistProps> = props => {\n const {\n boldColumn,\n border = 'no-border',\n descriptionWidth,\n label,\n format = 'formatted',\n separator,\n variant = 'normal',\n children,\n className,\n testId,\n useCollapsedFromAndBelowBreakpoint,\n } = props;\n\n const hasBorder = border === 'border';\n const hasLines = variant === 'line';\n const extraPaddingTop = hasBorder && (label || hasLines);\n const nonFormatted = format === 'non-formatted';\n const breakpoint = useBreakpoint();\n const useCollapsedMode = useCollapsedFromAndBelowBreakpoint && breakpoint <= Breakpoint[useCollapsedFromAndBelowBreakpoint];\n\n const duolistWrapperClasses = classNames(\n {\n [duolistStyles['duolist-wrapper--border']]: hasBorder,\n [duolistStyles['duolist-wrapper--extra-padding-top']]: extraPaddingTop,\n },\n className\n );\n\n const duolistClasses = classNames(duolistStyles.duolist, {\n [duolistStyles['duolist--line']]: hasLines,\n [duolistStyles['duolist--non-formatted']]: nonFormatted,\n [duolistStyles['duolist--collapsed']]: useCollapsedMode,\n [duolistStyles['duolist--not-collapsed']]: !useCollapsedMode,\n });\n\n const duolistColumnStyle = descriptionWidth ? descriptionWidth + '%' : 'minmax(60%, 1fr)';\n\n return (\n <div className={duolistWrapperClasses} data-testid={testId} data-analyticsid={AnalyticsId.Duolist}>\n {label && (\n <>\n {label}\n <Spacer />\n </>\n )}\n <dl\n style={!nonFormatted ? { gridTemplateColumns: useCollapsedMode ? `1fr` : `auto ${duolistColumnStyle}` } : undefined}\n className={duolistClasses}\n >\n {React.Children.map(children, (child: React.ReactNode | React.ReactElement<DuolistGroupProps>) => {\n if (child === null || typeof child === 'undefined') return;\n const duolistGroup = child as React.ReactElement<DuolistGroupProps>;\n if (duolistGroup.type === DuolistGroup) {\n return React.cloneElement(child as React.ReactElement<DuolistGroupProps>, {\n ...duolistGroup.props,\n boldColumn: duolistGroup.props.boldColumn ?? boldColumn,\n format: duolistGroup.props.format ?? format,\n separator: duolistGroup.props.separator ?? separator,\n });\n }\n })}\n </dl>\n </div>\n );\n};\n\nexport default Duolist;\n","import Duolist from './Duolist';\nexport * from './Duolist';\nexport default Duolist;\n"],"mappings":";;;;;;;;AAyDA,IAAa,gBAA4C,UAAS;CAChE,MAAM,EAAE,SAAS,aAAa,aAAa,WAAW,kBAAkB,SAAS,SAAS,aAAa,YAAY,MAAM,SAAS;CAElI,MAAM,YAAY,eAAe;CACjC,MAAM,aAAa,eAAe;CAClC,MAAM,eAAe,WAAW;CAEhC,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"Duolist.js","names":[],"sources":["../src/components/Duolist/Duolist.tsx","../src/components/Duolist/index.ts"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport type { TitleProps } from '../Title';\n\nimport { AnalyticsId } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport Spacer from '../Spacer';\n\nimport duolistStyles from './styles.module.scss';\n\nexport type DuolistVariants = 'normal' | 'line';\nexport type BoldColumn = 'first' | 'second' | 'none';\nexport type Border = 'no-border' | 'border';\nexport type Formats = 'formatted' | 'non-formatted';\n\nexport interface DuolistProps {\n /** Determines which column is bold */\n boldColumn?: BoldColumn;\n /** Label of the Duolist */\n border?: Border;\n /** Label of the Duolist */\n label?: React.ReactElement<TitleProps>;\n /** Formatted or non-formatted visual variants */\n format?: Formats;\n /** Character separator for non-formatted format */\n separator?: string;\n /** Sets the visual variant of the Duolist. */\n variant?: DuolistVariants;\n /** Sets the content of the Duolist. */\n children: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Width of the description column in percentage */\n descriptionWidth?: number;\n /** Use collapsed mode on columns from chosen breakpoint and below. */\n useCollapsedFromAndBelowBreakpoint?: keyof typeof Breakpoint;\n}\n\nexport interface DuolistGroupProps {\n /** Determines which column is bold */\n boldColumn?: BoldColumn;\n /** Sets content of the <dd> tag. */\n description: React.ReactNode;\n /** Formatted or non-formatted visual variants */\n format?: Formats;\n /** Character separator for non-formatted format */\n separator?: string;\n /** Sets content of the <dt> tag. */\n term: React.ReactNode;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const DuolistGroup: React.FC<DuolistGroupProps> = props => {\n const { format = 'formatted', boldColumn = format === 'non-formatted' ? 'none' : 'first', description, separator = ': ', term } = props;\n\n const firstBold = boldColumn === 'first';\n const secondBold = boldColumn === 'second';\n const nonFormatted = format === 'non-formatted';\n\n const dtClassNames = classNames(duolistStyles['duolist__dt'], {\n [duolistStyles['duolist__dt--bold']]: firstBold,\n [duolistStyles['duolist__dt--non-formatted']]: nonFormatted,\n });\n const ddClassNames = classNames(duolistStyles['duolist__dd'], {\n [duolistStyles['duolist__dd--bold']]: secondBold,\n [duolistStyles['duolist__dd--non-formatted']]: nonFormatted,\n });\n\n const renderContent = () => {\n return (\n <>\n <dt\n data-separator={nonFormatted ? separator : undefined}\n className={dtClassNames}\n data-testid={props.testId && `${props.testId}-term`}\n >\n {term}\n </dt>\n <dd className={ddClassNames} data-testid={props.testId && `${props.testId}-description`}>\n {description}\n </dd>\n </>\n );\n };\n\n return nonFormatted ? <div>{renderContent()}</div> : <>{renderContent()}</>;\n};\n\nexport const Duolist: React.FC<DuolistProps> = props => {\n const {\n boldColumn,\n border = 'no-border',\n descriptionWidth,\n label,\n format = 'formatted',\n separator,\n variant = 'normal',\n children,\n className,\n testId,\n useCollapsedFromAndBelowBreakpoint,\n } = props;\n\n const hasBorder = border === 'border';\n const hasLines = variant === 'line';\n const extraPaddingTop = hasBorder && (label || hasLines);\n const nonFormatted = format === 'non-formatted';\n const breakpoint = useBreakpoint();\n const useCollapsedMode = useCollapsedFromAndBelowBreakpoint && breakpoint <= Breakpoint[useCollapsedFromAndBelowBreakpoint];\n\n const duolistWrapperClasses = classNames(\n {\n [duolistStyles['duolist-wrapper--border']]: hasBorder,\n [duolistStyles['duolist-wrapper--extra-padding-top']]: extraPaddingTop,\n },\n className\n );\n\n const duolistClasses = classNames(duolistStyles.duolist, {\n [duolistStyles['duolist--line']]: hasLines,\n [duolistStyles['duolist--non-formatted']]: nonFormatted,\n [duolistStyles['duolist--collapsed']]: useCollapsedMode,\n [duolistStyles['duolist--not-collapsed']]: !useCollapsedMode,\n });\n\n const duolistColumnStyle = descriptionWidth ? descriptionWidth + '%' : 'minmax(60%, 1fr)';\n\n return (\n <div className={duolistWrapperClasses} data-testid={testId} data-analyticsid={AnalyticsId.Duolist}>\n {label && (\n <>\n {label}\n <Spacer />\n </>\n )}\n <dl\n style={!nonFormatted ? { gridTemplateColumns: useCollapsedMode ? `1fr` : `auto ${duolistColumnStyle}` } : undefined}\n className={duolistClasses}\n >\n {React.Children.map(children, (child: React.ReactNode | React.ReactElement<DuolistGroupProps>) => {\n if (child === null || typeof child === 'undefined') return;\n const duolistGroup = child as React.ReactElement<DuolistGroupProps>;\n if (duolistGroup.type === DuolistGroup) {\n return React.cloneElement(child as React.ReactElement<DuolistGroupProps>, {\n ...duolistGroup.props,\n boldColumn: duolistGroup.props.boldColumn ?? boldColumn,\n format: duolistGroup.props.format ?? format,\n separator: duolistGroup.props.separator ?? separator,\n });\n }\n })}\n </dl>\n </div>\n );\n};\n\nexport default Duolist;\n","import Duolist from './Duolist';\nexport * from './Duolist';\nexport default Duolist;\n"],"mappings":";;;;;;;;AAyDA,IAAa,gBAA4C,UAAS;CAChE,MAAM,EAAE,SAAS,aAAa,aAAa,WAAW,kBAAkB,SAAS,SAAS,aAAa,YAAY,MAAM,SAAS;CAElI,MAAM,YAAY,eAAe;CACjC,MAAM,aAAa,eAAe;CAClC,MAAM,eAAe,WAAW;CAEhC,MAAM,eAAe,GAAW,cAAc,gBAAgB;GAC3D,cAAc,uBAAuB;GACrC,cAAc,gCAAgC;CACjD,CAAC;CACD,MAAM,eAAe,GAAW,cAAc,gBAAgB;GAC3D,cAAc,uBAAuB;GACrC,cAAc,gCAAgC;CACjD,CAAC;CAED,MAAM,sBAAsB;EAC1B,OACE,qBAAA,UAAA,EAAA,UAAA,CACE,oBAAC,MAAD;GACE,kBAAgB,eAAe,YAAY,KAAA;GAC3C,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Ae;IACrB,IAAI,aAAa,SAAS,cACxB,OAAO,MAAM,aAAa,OAAgD;KACxE,GAAG,aAAa;KAChB,YAAY,aAAa,MAAM,cAAc;KAC7C,QAAQ,aAAa,MAAM,UAAU;KACrC,WAAW,aAAa,MAAM,aAAa;IAC7C,CAAC;GAEL,CAAC;EACC,CAAA,CACD;;AAET;;;AC7JA,IAAA,kBAAe"}
|
package/lib/ElementHeader.js
CHANGED
|
@@ -9,7 +9,7 @@ import { t as StatusDot_default } from "./StatusDot.js";
|
|
|
9
9
|
import { t as Highlighter_default } from "./Highlighter.js";
|
|
10
10
|
import { n as ElementHeaderText } from "./ElementHeaderText.js";
|
|
11
11
|
import { n as StatusDotList, t as StatusDotList_default } from "./StatusDotList.js";
|
|
12
|
-
import
|
|
12
|
+
import cn from "classnames";
|
|
13
13
|
import React from "react";
|
|
14
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
15
|
import styles from "./components/ElementHeader/styles.module.scss";
|
|
@@ -77,17 +77,17 @@ var ElementHeaderRoot = (props) => {
|
|
|
77
77
|
const contentIsString = typeof children === "string";
|
|
78
78
|
const mappedChildren = mapChildren(children);
|
|
79
79
|
const hasStatusDots = !!mappedChildren?.statusDotChildren?.length || !!mappedChildren?.statusDotMCChild;
|
|
80
|
-
const listLabelClasses =
|
|
81
|
-
const badgeContainerClasses =
|
|
82
|
-
const badgeClasses =
|
|
83
|
-
const statusdotContainerClasses =
|
|
84
|
-
const chevronClasses =
|
|
85
|
-
const contentClasses =
|
|
80
|
+
const listLabelClasses = cn(styles["element-header"], { [styles["element-header--compact"]]: size === "compact" }, className);
|
|
81
|
+
const badgeContainerClasses = cn(styles["element-header__badge-container"]);
|
|
82
|
+
const badgeClasses = cn(styles["element-header__badge"]);
|
|
83
|
+
const statusdotContainerClasses = cn(styles["element-header__statusdot-container"]);
|
|
84
|
+
const chevronClasses = cn(styles["element-header__chevron"]);
|
|
85
|
+
const contentClasses = cn(styles["element-header__content"], {
|
|
86
86
|
[styles["element-header__content--element"]]: !contentIsString,
|
|
87
87
|
[styles["element-header__content--compact"]]: size === "compact"
|
|
88
88
|
});
|
|
89
|
-
const iconClasses =
|
|
90
|
-
const avatarClasses =
|
|
89
|
+
const iconClasses = cn(styles["element-header__icon"], { [styles["element-header__icon--with-statusdot"]]: hasStatusDots });
|
|
90
|
+
const avatarClasses = cn(styles["element-header__avatar"], {});
|
|
91
91
|
const CustomTag = titleHtmlMarkup;
|
|
92
92
|
const iconPropIsIconComponent = isComponent(icon, Icon_default);
|
|
93
93
|
const iconPropIsLazyIconComponent = !iconPropIsIconComponent && isComponent(icon, LazyIcon_default);
|