@helsenorge/designsystem-react 12.8.0 → 12.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/Drawer.js +4 -204
- package/Drawer.js.map +1 -1
- package/Panel.js +0 -1
- package/Panel.js.map +1 -1
- package/SVGVisualElement.js +3759 -0
- package/SVGVisualElement.js.map +1 -0
- package/Toast.js +24 -0
- package/Toast.js.map +1 -0
- package/components/Drawer/styles.module.scss +19 -18
- package/components/Dropdown/index.js +4 -2
- package/components/Dropdown/index.js.map +1 -1
- package/components/Dropdown/styles.module.scss +1 -0
- package/components/Panel/Panel.d.ts +1 -1
- package/components/Toast/Toast.d.ts +13 -0
- package/components/Toast/Toast.test.d.ts +1 -0
- package/components/Toast/index.d.ts +3 -0
- package/components/Toast/index.js +5 -0
- package/components/Toast/index.js.map +1 -0
- package/components/Toast/styles.module.scss +50 -0
- package/components/ToastList/ToastList.d.ts +14 -0
- package/components/ToastList/ToastList.test.d.ts +1 -0
- package/components/ToastList/index.d.ts +3 -0
- package/components/ToastList/index.js +3531 -0
- package/components/ToastList/index.js.map +1 -0
- package/components/ToastList/styles.module.scss +12 -0
- package/components/ToastList/styles.module.scss.d.ts +9 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/index2.js +213 -0
- package/index2.js.map +1 -0
- package/package.json +1 -1
- package/use-animate.js +50 -3614
- package/use-animate.js.map +1 -1
package/Toast.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { C as Close } from "./Close.js";
|
|
3
|
+
import { I as Icon } from "./Icon.js";
|
|
4
|
+
import CheckFill from "./components/Icons/CheckFill.js";
|
|
5
|
+
import styles from "./components/Toast/styles.module.scss";
|
|
6
|
+
const Toast = ({ testId, title, message, onClose }) => {
|
|
7
|
+
const handleClose = () => {
|
|
8
|
+
if (onClose) {
|
|
9
|
+
onClose();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
return /* @__PURE__ */ jsxs("output", { className: styles["toast"], "data-testid": testId, children: [
|
|
13
|
+
/* @__PURE__ */ jsx(Icon, { svgIcon: CheckFill, className: styles["toast__icon"] }),
|
|
14
|
+
/* @__PURE__ */ jsxs("div", { className: styles["toast__text-container"], children: [
|
|
15
|
+
/* @__PURE__ */ jsx("span", { className: styles["toast__title"], children: title }),
|
|
16
|
+
message && /* @__PURE__ */ jsx("span", { className: styles["toast__description"], children: message })
|
|
17
|
+
] }),
|
|
18
|
+
/* @__PURE__ */ jsx(Close, { onClick: handleClose, color: "black", className: styles["toast__icon"], testId: `${testId}-close` })
|
|
19
|
+
] });
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
Toast as T
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=Toast.js.map
|
package/Toast.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Toast.js","sources":["../src/components/Toast/Toast.tsx"],"sourcesContent":["import React from 'react';\n\nimport Close from '../Close';\nimport Icon from '../Icon';\nimport CheckFill from '../Icons/CheckFill';\n\nimport styles from './styles.module.scss';\n\nexport interface ToastProps {\n /** Sets the data-testid attribute. */\n testId?: string;\n /** The title to display in the toast */\n title: string;\n /** The message to display in the toast */\n message?: string;\n /** Callback when toast is closed */\n onClose?: () => void;\n}\n\nconst Toast: React.FC<ToastProps> = ({ testId, title, message, onClose }) => {\n const handleClose = (): void => {\n if (onClose) {\n onClose();\n }\n };\n\n return (\n <output className={styles['toast']} data-testid={testId}>\n <Icon svgIcon={CheckFill} className={styles['toast__icon']} />\n <div className={styles['toast__text-container']}>\n <span className={styles['toast__title']}>{title}</span>\n {message && <span className={styles['toast__description']}>{message}</span>}\n </div>\n <Close onClick={handleClose} color=\"black\" className={styles['toast__icon']} testId={`${testId}-close`} />\n </output>\n );\n};\n\nexport default Toast;\n"],"names":[],"mappings":";;;;;AAmBA,MAAM,QAA8B,CAAC,EAAE,QAAQ,OAAO,SAAS,cAAc;AAC3E,QAAM,cAAc,MAAY;AAC9B,QAAI,SAAS;AACX,cAAA;AAAA,IACF;AAAA,EACF;AAEA,8BACG,UAAA,EAAO,WAAW,OAAO,OAAO,GAAG,eAAa,QAC/C,UAAA;AAAA,IAAA,oBAAC,QAAK,SAAS,WAAW,WAAW,OAAO,aAAa,GAAG;AAAA,IAC5D,qBAAC,OAAA,EAAI,WAAW,OAAO,uBAAuB,GAC5C,UAAA;AAAA,MAAA,oBAAC,QAAA,EAAK,WAAW,OAAO,cAAc,GAAI,UAAA,OAAM;AAAA,MAC/C,WAAW,oBAAC,QAAA,EAAK,WAAW,OAAO,oBAAoB,GAAI,UAAA,QAAA,CAAQ;AAAA,IAAA,GACtE;AAAA,IACA,oBAAC,OAAA,EAAM,SAAS,aAAa,OAAM,SAAQ,WAAW,OAAO,aAAa,GAAG,QAAQ,GAAG,MAAM,SAAA,CAAU;AAAA,EAAA,GAC1G;AAEJ;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
@use 'sass:map';
|
|
2
|
-
@use '../../scss/spacers' as spacers;
|
|
3
2
|
@use '../../scss/palette' as palette;
|
|
4
3
|
@use '../../scss/font-settings' as font-settings;
|
|
5
4
|
@use '../../scss/breakpoints' as breakpoints;
|
|
6
5
|
@import '../../scss/supernova/styles/colors.css';
|
|
6
|
+
@import '../../scss/supernova/styles/spacers.css';
|
|
7
7
|
|
|
8
8
|
.drawer {
|
|
9
9
|
position: fixed;
|
|
@@ -77,23 +77,23 @@
|
|
|
77
77
|
justify-content: space-between;
|
|
78
78
|
|
|
79
79
|
// legg til padding for å gi plass til close button
|
|
80
|
-
padding:
|
|
80
|
+
padding: var(--core-space-xs) 2.75rem var(--core-space-xs) var(--core-space-2xs);
|
|
81
81
|
|
|
82
82
|
@media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
|
|
83
|
-
padding:
|
|
83
|
+
padding: var(--core-space-xs) 2.75rem var(--core-space-xs) var(--core-space-xs);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
@include breakpoints.tiny-screens-media-query {
|
|
87
|
-
padding:
|
|
87
|
+
padding: var(--core-space-4xs) 0;
|
|
88
88
|
flex-direction: column-reverse;
|
|
89
89
|
align-items: flex-start;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
&--no-close-button {
|
|
93
|
-
padding:
|
|
93
|
+
padding: var(--core-space-xs) var(--core-space-2xs);
|
|
94
94
|
|
|
95
95
|
@media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
|
|
96
|
-
padding:
|
|
96
|
+
padding: var(--core-space-xs);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
&__children {
|
|
124
|
-
padding:
|
|
124
|
+
padding: var(--core-space-xs) var(--core-space-2xs);
|
|
125
125
|
|
|
126
126
|
@media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
|
|
127
|
-
padding:
|
|
127
|
+
padding: var(--core-space-s) var(--core-space-xs);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -143,21 +143,21 @@
|
|
|
143
143
|
|
|
144
144
|
&--top {
|
|
145
145
|
top: 0;
|
|
146
|
-
margin-bottom: calc(0rem -
|
|
146
|
+
margin-bottom: calc(0rem - var(--core-space-xs));
|
|
147
147
|
background: linear-gradient(0deg, rgb(0 0 0 / 0%) 0%, rgb(0 0 0 / 45.7%) 100%);
|
|
148
148
|
|
|
149
149
|
@media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
|
|
150
|
-
margin-bottom: calc(0rem -
|
|
150
|
+
margin-bottom: calc(0rem - var(--core-space-s));
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
&--bottom {
|
|
155
155
|
bottom: 0;
|
|
156
156
|
background: linear-gradient(180deg, rgb(0 0 0 / 0%) 0%, rgb(0 0 0 / 45.7%) 100%);
|
|
157
|
-
margin-top: calc(0rem -
|
|
157
|
+
margin-top: calc(0rem - var(--core-space-xs));
|
|
158
158
|
|
|
159
159
|
@media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
|
|
160
|
-
margin-top: calc(0rem -
|
|
160
|
+
margin-top: calc(0rem - var(--core-space-s));
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
@@ -169,17 +169,18 @@
|
|
|
169
169
|
|
|
170
170
|
&__footer {
|
|
171
171
|
display: flex;
|
|
172
|
-
gap:
|
|
173
|
-
padding:
|
|
172
|
+
gap: var(--core-space-2xs) var(--core-space-m);
|
|
173
|
+
padding: var(--core-space-s) var(--core-space-2xs);
|
|
174
|
+
flex-wrap: wrap;
|
|
174
175
|
|
|
175
176
|
@media (min-width: map.get(breakpoints.$grid-breakpoints, md)) {
|
|
176
|
-
|
|
177
|
+
row-gap: var(--core-space-s);
|
|
178
|
+
padding: var(--core-space-m) var(--core-space-xs);
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
@include breakpoints.tiny-screens-media-query {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
padding: spacers.getSpacer(2xs) 0;
|
|
182
|
+
column-gap: var(--core-space-2xs) 0;
|
|
183
|
+
padding: var(--core-space-2xs) 0;
|
|
183
184
|
}
|
|
184
185
|
}
|
|
185
186
|
}
|
|
@@ -4,7 +4,7 @@ import { u as useFloating, f as autoUpdate, o as offset, s as shift, j as size }
|
|
|
4
4
|
import classNames from "classnames";
|
|
5
5
|
import "../../theme/grid.js";
|
|
6
6
|
import "../../hooks/useBreakpoint.js";
|
|
7
|
-
import {
|
|
7
|
+
import { usePseudoClasses } from "../../hooks/usePseudoClasses.js";
|
|
8
8
|
import { useToggle } from "../../hooks/useToggle.js";
|
|
9
9
|
import { useKeyboardEvent } from "../../hooks/useKeyboardEvent.js";
|
|
10
10
|
import { useOutsideEvent } from "../../hooks/useOutsideEvent.js";
|
|
@@ -53,7 +53,8 @@ const DropdownBase = (props) => {
|
|
|
53
53
|
const dropdownRef = useRef(null);
|
|
54
54
|
const optionsRef = useRef(null);
|
|
55
55
|
const childrenRefList = useRef(React__default.Children.map(children, () => React__default.createRef()));
|
|
56
|
-
const
|
|
56
|
+
const buttonRef = React__default.useRef(null);
|
|
57
|
+
const { isHovered } = usePseudoClasses(buttonRef);
|
|
57
58
|
const openedByKeyboard = useRef(false);
|
|
58
59
|
const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);
|
|
59
60
|
const isMobile = useIsMobileBreakpoint();
|
|
@@ -116,6 +117,7 @@ const DropdownBase = (props) => {
|
|
|
116
117
|
};
|
|
117
118
|
const handleClose = () => {
|
|
118
119
|
var _a;
|
|
120
|
+
if (!isOpen) return;
|
|
119
121
|
toggleIsOpen();
|
|
120
122
|
(_a = buttonRef.current) == null ? void 0 : _a.focus();
|
|
121
123
|
};
|
|
@@ -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, ComponentType } from 'react';\n\nimport { autoUpdate, offset, shift, size, useFloating } from '@floating-ui/react';\nimport classNames from 'classnames';\nimport { clamp } from 'motion/react';\n\nimport {\n AnalyticsId,\n IconSize,\n KeyboardEventKey,\n LanguageLocales,\n ZIndex,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\n useToggle,\n} from '../..';\nimport { getResources } from './resourceHelper';\nimport { SingleSelectItem, SingleSelectItemProps } from './SingleSelect/SingleSelectItem';\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { HNDesignsystemDropdown } from '../../resources/Resources';\nimport { isComponent } from '../../utils/component';\nimport { useLanguage } from '../../utils/language';\nimport { mergeRefs } from '../../utils/refs';\nimport Button from '../Button';\nimport Checkbox, { CheckboxProps } from '../Checkbox';\nimport Icon, { SvgIcon } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { IconName } from '../Icons/IconNames';\nimport PlusSmall from '../Icons/PlusSmall';\nimport Label, { LabelProps } from '../Label';\nimport LazyIcon from '../LazyIcon';\nimport { SingleSelect } from './SingleSelect/SingleSelect';\n\nimport styles from './styles.module.scss';\n\ntype DropdownVariants = 'fill' | 'transparent' | 'borderless';\n\nexport interface DropdownProps {\n /** Text on the trigger button that opens the dropdown */\n triggerText: string;\n /** Sets the dropdown content */\n children: React.ReactNode;\n /** Minimum width for the dropdown in pixels. Does not affect trigger button. */\n dropdownMinWidth?: number;\n /** Minimum width for the trigger in pixels. Does not apply for borderless variant */\n triggerMinWidth?: number;\n /** Disables rendring of the close button in the list */\n noCloseButton?: boolean;\n /** Called when dropdown is open/closed */\n onToggle?: (isOpen: boolean) => void;\n /** Whether the dropdown is open or not */\n open?: boolean;\n /** Makes the dropdown disabled */\n disabled?: boolean;\n /** Sets the data-testid attribute on the dropdown button */\n testId?: string;\n /** Overrides the default z-index of the DropDownContent */\n zIndex?: number;\n /** Resources for component */\n resources?: Partial<HNDesignsystemDropdown>;\n /** Adds an icon to the trigger */\n svgIcon?: SvgIcon | IconName;\n /** Sets the visual variant of the Dropdown */\n variant?: DropdownVariants;\n}\n\nexport const DropdownBase: React.FC<DropdownProps> = props => {\n const {\n triggerText,\n noCloseButton = false,\n onToggle,\n dropdownMinWidth,\n triggerMinWidth,\n open = false,\n children,\n testId,\n disabled,\n zIndex = ZIndex.PopOver,\n resources,\n svgIcon,\n variant = 'fill',\n } = props;\n\n const dropdownRef = useRef<HTMLDivElement>(null);\n const optionsRef = useRef<HTMLUListElement>(null);\n const childrenRefList = useRef(React.Children.map(children, () => React.createRef<HTMLElement>()));\n const { hoverRef: buttonRef, isHovered } = useHover<HTMLButtonElement>();\n const openedByKeyboard = useRef<boolean>(false);\n const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);\n const isMobile = useIsMobileBreakpoint();\n const triggerActualMinWidth = variant !== 'borderless' && typeof triggerMinWidth != 'undefined' ? `${triggerMinWidth}px` : 'auto';\n const triggerMinWidthLimit = isMobile ? 96 : 112;\n const maxWidth = isMobile ? 384 : 400;\n const toggleTextId = useId();\n const optionIdPrefix = useId();\n const contentId = useId();\n const leftIconProps = {\n className: styles['dropdown__left-icon'],\n size: IconSize.XSmall,\n isHovered: !disabled && isHovered,\n };\n\n const isSingleSelect = React.Children.toArray(children).every(\n child => React.isValidElement(child) && isComponent<SingleSelectItemProps>(child, SingleSelectItem)\n );\n const isMultiSelect = React.Children.toArray(children).every(\n child => React.isValidElement(child) && isComponent<CheckboxProps>(child, Checkbox)\n );\n\n const { language } = useLanguage<LanguageLocales>(LanguageLocales.NORWEGIAN);\n const defaultResources = getResources(language);\n const mergedResources: HNDesignsystemDropdown = {\n ...defaultResources,\n ...resources,\n };\n\n const toggleClasses = classNames(styles.dropdown__toggle, {\n [styles['dropdown__toggle--open']]: isOpen && !disabled,\n [styles['dropdown__toggle--with-icon']]: typeof svgIcon !== 'undefined',\n [styles['dropdown__toggle--transparent']]: variant === 'transparent',\n [styles['dropdown__toggle--borderless']]: variant === 'borderless',\n });\n const contentClasses = classNames(styles.dropdown__content, isOpen && styles['dropdown__content--open']);\n const listItemClasses = classNames(styles['dropdown__list-item'], { [styles['dropdown__list-item--single-select']]: isSingleSelect });\n\n const { refs, floatingStyles } = useFloating({\n placement: 'bottom',\n middleware: [\n offset(8),\n shift({ padding: 8 }),\n size({\n apply({ availableWidth, availableHeight, elements, rects }) {\n const triggerW = rects.reference.width;\n const minProp = typeof dropdownMinWidth !== 'undefined' ? clamp(0, maxWidth, dropdownMinWidth) : 0;\n const targetW = Math.max(triggerW, minProp);\n const finalW = Math.min(availableWidth, targetW);\n\n Object.assign(elements.floating.style, {\n width: `${finalW}px`,\n maxHeight: `${availableHeight}px`,\n overflowY: 'auto',\n overflowX: 'hidden',\n });\n },\n }),\n ],\n whileElementsMounted: autoUpdate,\n });\n\n const handleOpen = (isKeyboard: boolean): void => {\n openedByKeyboard.current = isKeyboard;\n toggleIsOpen();\n };\n\n const handleClose = (): void => {\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n useEffect(() => {\n if (isOpen && openedByKeyboard.current) {\n const firstEnabled = childrenRefList.current?.find(r => r.current && !r.current.hasAttribute('disabled'));\n firstEnabled?.current?.focus();\n openedByKeyboard.current = false;\n }\n }, [isOpen]);\n\n const focusByIndex = (nextIndex: number): void => {\n childrenRefList.current?.[nextIndex]?.current?.focus();\n };\n\n const isListNavKey = (key: string): boolean =>\n key === KeyboardEventKey.ArrowDown || key === KeyboardEventKey.ArrowUp || key === KeyboardEventKey.Home || key === KeyboardEventKey.End;\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n if (!childrenRefList.current) return;\n\n const key = event.key as KeyboardEventKey;\n\n if (key === KeyboardEventKey.Escape) {\n if (isOpen) {\n event.preventDefault();\n handleClose();\n }\n return;\n }\n\n if (!isOpen) {\n if (isListNavKey(key)) {\n event.preventDefault();\n handleOpen(true);\n }\n return;\n }\n\n if (!isListNavKey(key)) {\n return;\n }\n\n const index = childrenRefList.current.findIndex(x => x.current === (event.target as HTMLElement));\n let nextIndex = index;\n\n if (key === KeyboardEventKey.Home) {\n nextIndex = 0;\n } else if (key === KeyboardEventKey.End) {\n nextIndex = childrenRefList.current.length - 1;\n } else if (key === KeyboardEventKey.ArrowDown && index < childrenRefList.current.length - 1) {\n nextIndex = index + 1;\n } else if (key === KeyboardEventKey.ArrowUp && index > 0) {\n nextIndex = index - 1;\n }\n\n if (nextIndex !== -1) {\n event.preventDefault();\n focusByIndex(nextIndex);\n }\n };\n\n useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [\n KeyboardEventKey.ArrowDown,\n KeyboardEventKey.ArrowUp,\n KeyboardEventKey.End,\n KeyboardEventKey.Enter,\n KeyboardEventKey.Escape,\n KeyboardEventKey.Home,\n KeyboardEventKey.Space,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const renderChildren = React.Children.map(children, (child, index) => {\n return (\n <li className={listItemClasses} id={`${optionIdPrefix}-${index}`}>\n {React.isValidElement(child) && childrenRefList.current && childrenRefList.current[index]\n ? ((): React.ReactElement => {\n const baseProps: { ref: React.Ref<HTMLElement> } = {\n ref: mergeRefs([child.props.ref, childrenRefList.current[index]]),\n };\n\n if (isMultiSelect) {\n const label = (child.props as CheckboxProps).label as React.ReactNode;\n if (React.isValidElement(label) && isComponent<LabelProps>(label, Label)) {\n return React.cloneElement(child as React.ReactElement<CheckboxProps>, {\n ...baseProps,\n label: React.cloneElement(label, {\n labelClassName: classNames((label.props as LabelProps)?.labelClassName, styles['dropdown__multiselect-item']),\n }),\n });\n }\n }\n\n return React.cloneElement(child as React.ReactElement<Record<string, unknown>>, baseProps);\n })()\n : child}\n </li>\n );\n });\n\n return (\n <div className={styles.dropdown} ref={dropdownRef}>\n <button\n type=\"button\"\n onClick={(): false | void => handleOpen(false)}\n className={toggleClasses}\n ref={mergeRefs([buttonRef, refs.setReference])}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Dropdown}\n disabled={disabled}\n aria-labelledby={toggleTextId}\n aria-haspopup={true}\n aria-controls={contentId}\n aria-expanded={isOpen}\n style={{\n width: triggerActualMinWidth,\n maxWidth: '100%',\n minWidth: `${triggerMinWidthLimit}px`,\n }}\n >\n {svgIcon && (\n <>\n {typeof svgIcon === 'string' ? (\n <LazyIcon {...leftIconProps} iconName={svgIcon} />\n ) : (\n <Icon {...leftIconProps} svgIcon={svgIcon} />\n )}\n </>\n )}\n <span id={toggleTextId} className={styles.dropdown__toggle__text}>\n {triggerText}\n </span>\n <Icon\n svgIcon={!isSingleSelect ? PlusSmall : isOpen ? ChevronUp : ChevronDown}\n className={styles['dropdown__right-icon']}\n isHovered={!disabled && isHovered}\n size={IconSize.XSmall}\n />\n </button>\n <div\n key={dropdownMinWidth ?? 'auto'}\n id={contentId}\n className={contentClasses}\n ref={refs.setFloating}\n style={{\n ...floatingStyles,\n zIndex: zIndex,\n }}\n >\n <ul className={styles.dropdown__options} role=\"group\" aria-labelledby={toggleTextId} tabIndex={-1} ref={optionsRef}>\n {isSingleSelect && <SingleSelect onValueChange={() => handleClose()}>{renderChildren}</SingleSelect>}\n {isMultiSelect && renderChildren}\n </ul>\n {!isSingleSelect && !noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose}>{mergedResources.closeText}</Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport interface DropdownCompound extends React.FC<DropdownProps> {\n SingleSelectItem: ComponentType<SingleSelectItemProps>;\n}\nconst Dropdown = DropdownBase as DropdownCompound;\nDropdown.SingleSelectItem = SingleSelectItem;\nDropdownBase.displayName = 'Dropdown';\n\nexport default Dropdown;\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAM,eAAe,CAAC,aAAsD;AACjF,UAAQ,UAAA;AAAA,IACN,KAAK,gBAAgB;AACnB,aAAO;AAAA,IACT,KAAK,gBAAgB;AAAA,IACrB;AACE,aAAO;AAAA,EAAA;AAEb;ACuDO,MAAM,eAAwC,CAAA,UAAS;AAC5D,QAAM;AAAA,IACJ;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,OAAO;AAAA,IAChB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,E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S,mBAAmB;AAC5B,aAAa,cAAc;"}
|
|
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 if (!isOpen) return;\n\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n useEffect(() => {\n if (isOpen && openedByKeyboard.current) {\n const firstEnabled = childrenRefList.current?.find(r => r.current && !r.current.hasAttribute('disabled'));\n firstEnabled?.current?.focus();\n openedByKeyboard.current = false;\n }\n }, [isOpen]);\n\n const focusByIndex = (nextIndex: number): void => {\n childrenRefList.current?.[nextIndex]?.current?.focus();\n };\n\n const isListNavKey = (key: string): boolean =>\n key === KeyboardEventKey.ArrowDown || key === KeyboardEventKey.ArrowUp || key === KeyboardEventKey.Home || key === KeyboardEventKey.End;\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n if (!childrenRefList.current) return;\n\n const key = event.key as KeyboardEventKey;\n\n if (key === KeyboardEventKey.Escape) {\n if (isOpen) {\n event.preventDefault();\n handleClose();\n }\n return;\n }\n\n if (!isOpen) {\n if (isListNavKey(key)) {\n event.preventDefault();\n handleOpen(true);\n }\n return;\n }\n\n if (!isListNavKey(key)) {\n return;\n }\n\n const index = childrenRefList.current.findIndex(x => x.current === (event.target as HTMLElement));\n let nextIndex = index;\n\n if (key === KeyboardEventKey.Home) {\n nextIndex = 0;\n } else if (key === KeyboardEventKey.End) {\n nextIndex = childrenRefList.current.length - 1;\n } else if (key === KeyboardEventKey.ArrowDown && index < childrenRefList.current.length - 1) {\n nextIndex = index + 1;\n } else if (key === KeyboardEventKey.ArrowUp && index > 0) {\n nextIndex = index - 1;\n }\n\n if (nextIndex !== -1) {\n event.preventDefault();\n focusByIndex(nextIndex);\n }\n };\n\n useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [\n KeyboardEventKey.ArrowDown,\n KeyboardEventKey.ArrowUp,\n KeyboardEventKey.End,\n KeyboardEventKey.Enter,\n KeyboardEventKey.Escape,\n KeyboardEventKey.Home,\n KeyboardEventKey.Space,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const renderChildren = React.Children.map(children, (child, index) => {\n return (\n <li className={listItemClasses} id={`${optionIdPrefix}-${index}`}>\n {React.isValidElement(child) && childrenRefList.current && childrenRefList.current[index]\n ? ((): React.ReactElement => {\n const baseProps: { ref: React.Ref<HTMLElement> } = {\n ref: mergeRefs([child.props.ref, childrenRefList.current[index]]),\n };\n\n if (isMultiSelect) {\n const label = (child.props as CheckboxProps).label as React.ReactNode;\n if (React.isValidElement(label) && isComponent<LabelProps>(label, Label)) {\n return React.cloneElement(child as React.ReactElement<CheckboxProps>, {\n ...baseProps,\n label: React.cloneElement(label, {\n labelClassName: classNames((label.props as LabelProps)?.labelClassName, styles['dropdown__multiselect-item']),\n }),\n });\n }\n }\n\n return React.cloneElement(child as React.ReactElement<Record<string, unknown>>, baseProps);\n })()\n : child}\n </li>\n );\n });\n\n return (\n <div className={styles.dropdown} ref={dropdownRef}>\n <button\n type=\"button\"\n onClick={(): false | void => handleOpen(false)}\n className={toggleClasses}\n ref={mergeRefs([buttonRef, refs.setReference])}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Dropdown}\n disabled={disabled}\n aria-labelledby={toggleTextId}\n aria-haspopup={true}\n aria-controls={contentId}\n aria-expanded={isOpen}\n style={{\n width: triggerActualMinWidth,\n maxWidth: '100%',\n minWidth: `${triggerMinWidthLimit}px`,\n }}\n >\n {svgIcon && (\n <>\n {typeof svgIcon === 'string' ? (\n <LazyIcon {...leftIconProps} iconName={svgIcon} />\n ) : (\n <Icon {...leftIconProps} svgIcon={svgIcon} />\n )}\n </>\n )}\n <span id={toggleTextId} className={styles.dropdown__toggle__text}>\n {triggerText}\n </span>\n <Icon\n svgIcon={!isSingleSelect ? PlusSmall : isOpen ? ChevronUp : ChevronDown}\n className={styles['dropdown__right-icon']}\n isHovered={!disabled && isHovered}\n size={IconSize.XSmall}\n />\n </button>\n <div\n key={dropdownMinWidth ?? 'auto'}\n id={contentId}\n className={contentClasses}\n ref={refs.setFloating}\n style={{\n ...floatingStyles,\n zIndex: zIndex,\n }}\n >\n <ul className={styles.dropdown__options} role=\"group\" aria-labelledby={toggleTextId} tabIndex={-1} ref={optionsRef}>\n {isSingleSelect && <SingleSelect onValueChange={() => handleClose()}>{renderChildren}</SingleSelect>}\n {isMultiSelect && renderChildren}\n </ul>\n {!isSingleSelect && !noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose}>{mergedResources.closeText}</Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport interface DropdownCompound extends React.FC<DropdownProps> {\n SingleSelectItem: ComponentType<SingleSelectItemProps>;\n}\nconst Dropdown = DropdownBase as DropdownCompound;\nDropdown.SingleSelectItem = SingleSelectItem;\nDropdownBase.displayName = 'Dropdown';\n\nexport default Dropdown;\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAM,eAAe,CAAC,aAAsD;AACjF,UAAQ,UAAA;AAAA,IACN,KAAK,gBAAgB;AACnB,aAAO;AAAA,IACT,KAAK,gBAAgB;AAAA,IACrB;AACE,aAAO;AAAA,EAAA;AAEb;ACuDO,MAAM,eAAwC,CAAA,UAAS;AAC5D,QAAM;AAAA,IACJ;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,OAAO;AAAA,IAChB;AAAA,IACA;AAAA,IACA,UAAU;AAAA,EAAA,IACR;AAEJ,QAAM,cAAc,OAAuB,IAAI;AAC/C,QAAM,aAAa,OAAyB,IAAI;AAChD,QAAM,kBAAkB,OAAOA,eAAM,SAAS,IAAI,UAAU,MAAMA,eAAM,UAAA,CAAwB,CAAC;AACjG,QAAM,YAAYA,eAAM,OAA0B,IAAI;AACtD,QAAM,EAAE,UAAA,IAAc,iBAAoC,SAAS;AACnE,QAAM,mBAAmB,OAAgB,KAAK;AAC9C,QAAM,EAAE,OAAO,QAAQ,aAAa,iBAAiB,UAAU,CAAC,YAAY,MAAM,QAAQ;AAC1F,QAAM,WAAW,sBAAA;AACjB,QAAM,wBAAwB,YAAY,gBAAgB,OAAO,mBAAmB,cAAc,GAAG,eAAe,OAAO;AAC3H,QAAM,uBAAuB,WAAW,KAAK;AAC7C,QAAM,WAAW,WAAW,MAAM;AAClC,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W,OAAO,sBAAsB;AAAA,cACxC,WAAW,CAAC,YAAY;AAAA,cACxB,MAAM,SAAS;AAAA,YAAA;AAAA,UAAA;AAAA,QACjB;AAAA,MAAA;AAAA,IAAA;AAAA,IAEF;AAAA,MAAC;AAAA,MAAA;AAAA,QAEC,IAAI;AAAA,QACJ,WAAW;AAAA,QACX,KAAK,KAAK;AAAA,QACV,OAAO;AAAA,UACL,GAAG;AAAA,UACH;AAAA,QAAA;AAAA,QAGF,UAAA;AAAA,UAAA,qBAAC,MAAA,EAAG,WAAW,OAAO,mBAAmB,MAAK,SAAQ,mBAAiB,cAAc,UAAU,IAAI,KAAK,YACrG,UAAA;AAAA,YAAA,sCAAmB,cAAA,EAAa,eAAe,MAAM,YAAA,GAAgB,UAAA,gBAAe;AAAA,YACpF,iBAAiB;AAAA,UAAA,GACpB;AAAA,UACC,CAAC,kBAAkB,CAAC,qCAClB,OAAA,EAAI,WAAW,OAAO,iBACrB,8BAAC,QAAA,EAAO,SAAS,aAAc,UAAA,gBAAgB,WAAU,EAAA,CAC3D;AAAA,QAAA;AAAA,MAAA;AAAA,MAhBG,oBAAoB;AAAA,IAAA;AAAA,EAkB3B,GACF;AAEJ;AAKA,MAAM,WAAW;AACjB,SAAS,mBAAmB;AAC5B,aAAa,cAAc;"}
|
|
@@ -42,7 +42,7 @@ export interface PanelProps {
|
|
|
42
42
|
/** Sets classes on the outermost container of the panel */
|
|
43
43
|
className?: string;
|
|
44
44
|
/** Action called when toggling expansion of ExpandedContent */
|
|
45
|
-
onExpand?: () => void;
|
|
45
|
+
onExpand?: (isExpanded?: boolean) => void;
|
|
46
46
|
/** Sets the stacking order of the content boxes */
|
|
47
47
|
stacking?: PanelStacking;
|
|
48
48
|
/** Sets the data-testid attribute. */
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface ToastProps {
|
|
3
|
+
/** Sets the data-testid attribute. */
|
|
4
|
+
testId?: string;
|
|
5
|
+
/** The title to display in the toast */
|
|
6
|
+
title: string;
|
|
7
|
+
/** The message to display in the toast */
|
|
8
|
+
message?: string;
|
|
9
|
+
/** Callback when toast is closed */
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare const Toast: React.FC<ToastProps>;
|
|
13
|
+
export default Toast;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
@use '../../scss/font-mixins' as fonts;
|
|
2
|
+
@use 'sass:map';
|
|
3
|
+
@use '@helsenorge/designsystem-react/scss/breakpoints' as breakpoints;
|
|
4
|
+
@import '../../scss/supernova/styles/colors.css';
|
|
5
|
+
|
|
6
|
+
.toast {
|
|
7
|
+
max-width: 40rem;
|
|
8
|
+
width: fit-content;
|
|
9
|
+
margin: 0 auto;
|
|
10
|
+
padding: 0.5rem;
|
|
11
|
+
border-radius: 0.25rem;
|
|
12
|
+
background-color: var(--core-color-kiwi-50);
|
|
13
|
+
border: 2px solid var(--core-color-kiwi-900);
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: row;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: 0.25rem;
|
|
18
|
+
pointer-events: auto;
|
|
19
|
+
|
|
20
|
+
&__icon {
|
|
21
|
+
align-self: flex-start;
|
|
22
|
+
fill: var(--core-color-kiwi-900);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&__text-container {
|
|
26
|
+
--margin-top: 0;
|
|
27
|
+
|
|
28
|
+
flex-grow: 1;
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: 0.25rem;
|
|
32
|
+
margin-top: var(--margin-top);
|
|
33
|
+
|
|
34
|
+
&:has(.toast__description) {
|
|
35
|
+
--margin-top: 0.5rem;
|
|
36
|
+
|
|
37
|
+
@media (min-width: map.get(breakpoints.$grid-breakpoints, sm)) {
|
|
38
|
+
--margin-top: 0.625rem;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&__title {
|
|
44
|
+
@include fonts.title6;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&__description {
|
|
48
|
+
@include fonts.compact-data;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface ToastData {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ToastListProps {
|
|
8
|
+
/** Sets the data-testid attribute. */
|
|
9
|
+
testId?: string;
|
|
10
|
+
/** Array of toast data to display */
|
|
11
|
+
toasts?: ToastData[];
|
|
12
|
+
}
|
|
13
|
+
declare const ToastList: React.ForwardRefExoticComponent<ToastListProps & React.RefAttributes<HTMLElement>>;
|
|
14
|
+
export default ToastList;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|