@helsenorge/designsystem-react 14.0.0-beta.9 → 14.0.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/CHANGELOG.md +331 -12
- package/lib/DoctorSmall.js +22 -34
- package/lib/DoctorSmall.js.map +1 -1
- package/lib/Drawer.js +2 -1
- package/lib/Drawer.js.map +1 -1
- package/lib/HelpTriggerIcon.js +10 -6
- package/lib/HelpTriggerIcon.js.map +1 -1
- package/lib/IllustrationNames.js +6 -2
- package/lib/IllustrationNames.js.map +1 -1
- package/lib/Input.js +5 -3
- package/lib/Input.js.map +1 -1
- package/lib/LazyIcon.js +2 -0
- package/lib/LazyIcon.js.map +1 -1
- package/lib/LazyIllustration.js +5 -1
- package/lib/LazyIllustration.js.map +1 -1
- package/lib/Slider.js +14 -6
- package/lib/Slider.js.map +1 -1
- package/lib/StorkMedium.js +96 -0
- package/lib/StorkMedium.js.map +1 -0
- 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 +6 -6
- package/lib/TableHead.js.map +1 -1
- package/lib/TableHeadCell.js +5 -5
- package/lib/TableHeadCell.js.map +1 -1
- package/lib/TableRow.js +5 -5
- package/lib/TableRow.js.map +1 -1
- package/lib/Textarea.js +13 -12
- package/lib/Textarea.js.map +1 -1
- package/lib/ThinkingMedium.js +98 -0
- package/lib/ThinkingMedium.js.map +1 -0
- package/lib/components/Button/styles.module.scss +1 -3
- package/lib/components/Drawer/styles.module.scss +4 -21
- package/lib/components/Drawer/styles.module.scss.d.ts +1 -1
- package/lib/components/ExpanderHierarchy/Expander.d.ts +1 -1
- package/lib/components/ExpanderHierarchy/index.js.map +1 -1
- package/lib/components/ExpanderList/index.js +13 -4
- package/lib/components/ExpanderList/index.js.map +1 -1
- package/lib/components/HelpTriggerIcon/HelpSign.d.ts +0 -1
- package/lib/components/HelpTriggerInline/styles.module.scss +1 -0
- package/lib/components/Icons/AdditionalIconInformation.d.ts +8 -0
- package/lib/components/Icons/AdditionalIconInformation.js +8 -0
- 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/StarFill.d.ts +4 -0
- package/lib/components/Icons/StarFill.js +16 -0
- package/lib/components/Icons/StarFill.js.map +1 -0
- package/lib/components/Icons/StarStroke.d.ts +4 -0
- package/lib/components/Icons/StarStroke.js +16 -0
- package/lib/components/Icons/StarStroke.js.map +1 -0
- package/lib/components/Illustrations/IllustrationNames.d.ts +1 -1
- package/lib/components/Illustrations/Stork.d.ts +11 -0
- package/lib/components/Illustrations/Stork.js +16 -0
- package/lib/components/Illustrations/Stork.js.map +1 -0
- package/lib/components/Illustrations/StorkMedium.d.ts +4 -0
- package/lib/components/Illustrations/StorkMedium.js +2 -0
- package/lib/components/Illustrations/Thinking.d.ts +9 -0
- package/lib/components/Illustrations/Thinking.js +16 -0
- package/lib/components/Illustrations/Thinking.js.map +1 -0
- package/lib/components/Illustrations/ThinkingMedium.d.ts +4 -0
- package/lib/components/Illustrations/ThinkingMedium.js +2 -0
- package/lib/components/Loader/index.js +15 -13
- package/lib/components/Loader/index.js.map +1 -1
- package/lib/components/ServiceMessage/ServiceMessage.d.ts +3 -0
- package/lib/components/ServiceMessage/index.js +2 -2
- package/lib/components/ServiceMessage/index.js.map +1 -1
- package/lib/components/StickyNote/index.js +8 -5
- 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/floating-ui.react.js +126 -129
- package/lib/floating-ui.react.js.map +1 -1
- package/lib/hooks/useIsServerSide.d.ts +1 -1
- package/lib/useBreakpoint.js +15 -24
- package/lib/useBreakpoint.js.map +1 -1
- package/lib/useExpand.js +5 -3
- package/lib/useExpand.js.map +1 -1
- package/lib/useIsServerSide.js +5 -6
- package/lib/useIsServerSide.js.map +1 -1
- package/lib/useToggle.js +5 -3
- package/lib/useToggle.js.map +1 -1
- package/lib/utils6.js +2 -2
- package/lib/utils6.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { SvgIllustrationProps } from '../Illustration';
|
|
3
|
+
export interface Palette {
|
|
4
|
+
lines: string;
|
|
5
|
+
shapes1: string;
|
|
6
|
+
shapes2: string;
|
|
7
|
+
}
|
|
8
|
+
declare const Thinking: React.FC<SvgIllustrationProps>;
|
|
9
|
+
export default Thinking;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { n as getIllustration } from "../../utils4.js";
|
|
2
|
+
import { t as ThinkingMedium_default } from "../../ThinkingMedium.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var Thinking = ({ size = 512, color, ...rest }) => {
|
|
5
|
+
return getIllustration({
|
|
6
|
+
size,
|
|
7
|
+
medium: /* @__PURE__ */ jsx(ThinkingMedium_default, {
|
|
8
|
+
color,
|
|
9
|
+
...rest
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var Thinking_default = Thinking;
|
|
14
|
+
export { Thinking_default as default };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=Thinking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Thinking.js","names":["Thinking: React.FC<SvgIllustrationProps>"],"sources":["../../../src/components/Illustrations/Thinking.tsx"],"sourcesContent":["import type React from 'react';\n\nimport type { SvgIllustrationProps } from '../Illustration';\n\nimport ThinkingMedium from './ThinkingMedium';\nimport { getIllustration } from '../Illustration/utils';\n\nexport interface Palette {\n lines: string;\n shapes1: string;\n shapes2: string;\n}\n\nconst Thinking: React.FC<SvgIllustrationProps> = ({ size = 512, color, ...rest }) => {\n const medium = <ThinkingMedium color={color} {...rest} />;\n\n return getIllustration({ size, medium });\n};\n\nexport default Thinking;\n"],"mappings":";;;AAaA,IAAMA,YAA4C,EAAE,OAAO,KAAK,OAAO,GAAG,WAAW;AAGnF,QAAO,gBAAgB;EAAE;EAAM,QAFhB,oBAAC,wBAAA;GAAsB;GAAO,GAAI;IAAQ;EAElB,CAAC;;AAG1C,IAAA,mBAAe"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as uuid } from "../../uuid.js";
|
|
2
2
|
import { c as ZIndex, n as AnalyticsId } from "../../constants2.js";
|
|
3
3
|
import classNames from "classnames";
|
|
4
|
-
import {
|
|
4
|
+
import { useCallback, useRef, useState } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import loaderStyles from "./styles.module.scss";
|
|
7
7
|
let Overlay = /* @__PURE__ */ function(Overlay$1) {
|
|
@@ -17,6 +17,7 @@ var Loader = (props) => {
|
|
|
17
17
|
return true;
|
|
18
18
|
};
|
|
19
19
|
const [display, setDisplay] = useState(showLoader());
|
|
20
|
+
const hasInitializedRef = useRef(false);
|
|
20
21
|
const isSmall = size === "small";
|
|
21
22
|
const isMedium = size === "medium";
|
|
22
23
|
const isLarge = size === "large";
|
|
@@ -44,20 +45,21 @@ var Loader = (props) => {
|
|
|
44
45
|
[loaderStyles["loader__dot--black"]]: color === "black",
|
|
45
46
|
[loaderStyles["loader__dot--white"]]: color === "white"
|
|
46
47
|
});
|
|
47
|
-
const wrapperRef = useRef(null);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (overlay === Overlay.parent && wrapperRef.current?.parentElement?.style) {
|
|
50
|
-
wrapperRef.current.parentElement.style.position = "relative";
|
|
51
|
-
setDisplay(true);
|
|
52
|
-
}
|
|
53
|
-
if (inline && wrapperRef.current?.parentElement?.style) {
|
|
54
|
-
wrapperRef.current.parentElement.style.display = "flex";
|
|
55
|
-
setDisplay(true);
|
|
56
|
-
}
|
|
57
|
-
}, []);
|
|
58
48
|
return /* @__PURE__ */ jsx("div", {
|
|
59
49
|
className: loaderWrapperClasses,
|
|
60
|
-
ref:
|
|
50
|
+
ref: useCallback((node) => {
|
|
51
|
+
if (node && !hasInitializedRef.current) {
|
|
52
|
+
hasInitializedRef.current = true;
|
|
53
|
+
if (overlay === Overlay.parent && node.parentElement?.style) {
|
|
54
|
+
node.parentElement.style.position = "relative";
|
|
55
|
+
setDisplay(true);
|
|
56
|
+
}
|
|
57
|
+
if (inline && node.parentElement?.style) {
|
|
58
|
+
node.parentElement.style.display = "flex";
|
|
59
|
+
setDisplay(true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, [overlay, inline]),
|
|
61
63
|
style: overlay === Overlay.screen ? { zIndex: ZIndex.OverlayScreen } : {},
|
|
62
64
|
children: display && /* @__PURE__ */ jsxs("div", {
|
|
63
65
|
"data-testid": testId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Loader: React.FC<LoaderProps>"],"sources":["../../../src/components/Loader/constants.ts","../../../src/components/Loader/Loader.tsx","../../../src/components/Loader/index.ts"],"sourcesContent":["export enum Overlay {\n screen = 'screen',\n parent = 'parent',\n}\n","import {
|
|
1
|
+
{"version":3,"file":"index.js","names":["Loader: React.FC<LoaderProps>"],"sources":["../../../src/components/Loader/constants.ts","../../../src/components/Loader/Loader.tsx","../../../src/components/Loader/index.ts"],"sourcesContent":["export enum Overlay {\n screen = 'screen',\n parent = 'parent',\n}\n","import { useCallback, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport type { PaletteNames } from '../../theme/palette';\n\nimport { Overlay } from './constants';\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { uuid } from '../../utils/uuid';\n\nimport loaderStyles from './styles.module.scss';\n\nexport type LoaderColors = PaletteNames;\nexport type LoaderSizes = 'tiny' | 'small' | 'medium' | 'large';\n\nexport interface LoaderProps {\n /** Sets the color of the loader. If overlay is used, the color will always be white. */\n color?: LoaderColors;\n /**\tAdds custom classes to the element. */\n className?: string;\n /** Changes the size of the loader. */\n size?: LoaderSizes;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** id of the label */\n labelId?: string;\n /** Centers the loader in a container */\n center?: boolean;\n /** Inline the loader so it can be used in a span or paragraph */\n inline?: boolean;\n /** Loader is displayed with grey background covering the entire screen */\n overlay?: keyof typeof Overlay;\n /** Individual id for loading icon (aria-labelledby). */\n ariaLabelledById?: string;\n /** String that labels the current loading element */\n ariaLabel?: string;\n}\n\nconst Loader: React.FC<LoaderProps> = props => {\n const {\n overlay,\n size = 'small',\n className = '',\n labelId = uuid(),\n testId,\n center,\n inline,\n ariaLabelledById,\n ariaLabel = 'Laster inn',\n } = props;\n const color = props.overlay ? 'white' : props.color || 'neutral';\n\n const showLoader = (): boolean => {\n if (overlay === Overlay.parent || inline) {\n return false;\n }\n\n return true;\n };\n\n const [display, setDisplay] = useState(showLoader());\n const hasInitializedRef = useRef(false);\n\n const isSmall = size === 'small';\n const isMedium = size === 'medium';\n const isLarge = size === 'large';\n\n const loaderWrapperClasses = classNames({\n [loaderStyles['loader-wrapper--center']]: center,\n [loaderStyles['loader-wrapper--overlay']]: overlay,\n [loaderStyles['loader-wrapper--overlay-screen']]: overlay === Overlay.screen,\n [loaderStyles['loader-wrapper--overlay-parent']]: overlay === Overlay.parent && display,\n [loaderStyles['loader-wrapper--inline']]: inline && display,\n });\n const loaderClasses = classNames(\n loaderStyles.loader,\n {\n [loaderStyles['loader--small']]: isSmall,\n [loaderStyles['loader--medium']]: isMedium,\n [loaderStyles['loader--large']]: isLarge,\n },\n className\n );\n const loaderDotClasses = classNames(loaderStyles.loader__dot, {\n [loaderStyles['loader__dot--small']]: isSmall,\n [loaderStyles['loader__dot--medium']]: isMedium,\n [loaderStyles['loader__dot--large']]: isLarge,\n [loaderStyles['loader__dot--banana']]: color === 'banana',\n [loaderStyles['loader__dot--cherry']]: color === 'cherry',\n [loaderStyles['loader__dot--kiwi']]: color === 'kiwi',\n [loaderStyles['loader__dot--neutral']]: color === 'neutral',\n [loaderStyles['loader__dot--plum']]: color === 'plum',\n [loaderStyles['loader__dot--black']]: color === 'black',\n [loaderStyles['loader__dot--white']]: color === 'white',\n });\n\n const wrapperRef = useCallback(\n (node: HTMLDivElement | null) => {\n if (node && !hasInitializedRef.current) {\n hasInitializedRef.current = true;\n if (overlay === Overlay.parent && node.parentElement?.style) {\n node.parentElement.style.position = 'relative';\n setDisplay(true);\n }\n if (inline && node.parentElement?.style) {\n node.parentElement.style.display = 'flex';\n setDisplay(true);\n }\n }\n },\n [overlay, inline]\n );\n\n return (\n <div className={loaderWrapperClasses} ref={wrapperRef} style={overlay === Overlay.screen ? { zIndex: ZIndex.OverlayScreen } : {}}>\n {display && (\n <div\n data-testid={testId}\n data-analyticsid={AnalyticsId.Loader}\n role=\"progressbar\"\n aria-labelledby={ariaLabelledById || labelId}\n className={loaderClasses}\n >\n <div className={loaderDotClasses} />\n <div className={loaderDotClasses} />\n <div className={loaderDotClasses} />\n <div className={loaderDotClasses} />\n {!ariaLabelledById && (\n <span id={labelId} className={loaderStyles['loader__hidden-text']}>\n {ariaLabel}\n </span>\n )}\n </div>\n )}\n </div>\n );\n};\n\nexport default Loader;\n","import Loader from './Loader';\nexport { Overlay } from './constants';\nexport * from './Loader';\nexport default Loader;\n"],"mappings":";;;;;;AAAA,IAAY,UAAA,yBAAA,WAAL;AACL,WAAA,YAAA;AACA,WAAA,YAAA;;;ACoCF,IAAMA,UAAgC,UAAS;CAC7C,MAAM,EACJ,SACA,OAAO,SACP,YAAY,IACZ,UAAU,MAAM,EAChB,QACA,QACA,QACA,kBACA,YAAY,iBACV;CACJ,MAAM,QAAQ,MAAM,UAAU,UAAU,MAAM,SAAS;CAEvD,MAAM,mBAA4B;AAChC,MAAI,YAAY,QAAQ,UAAU,O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,oBAAkB,YAAY;GAC9B,MAAK;GACL,mBAAiB,oBAAoB;GACrC,WAAW;;IAEX,oBAAC,OAAA,EAAI,WAAW,kBAAA,CAAoB;IACpC,oBAAC,OAAA,EAAI,WAAW,kBAAA,CAAoB;IACpC,oBAAC,OAAA,EAAI,WAAW,kBAAA,CAAoB;IACpC,oBAAC,OAAA,EAAI,WAAW,kBAAA,CAAoB;IACnC,CAAC,oBACA,oBAAC,QAAA;KAAK,IAAI;KAAS,WAAW,aAAa;eACxC;MACI;;IAEL;GAEJ;;ACnIV,IAAA,iBDuIe"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AnchorLinkTargets } from '../AnchorLink';
|
|
2
2
|
import { NotificationPanelVariants } from '../NotificationPanel';
|
|
3
|
+
export type ServiceMessageRoles = 'alert' | 'region' | 'auto' | 'none';
|
|
3
4
|
export interface ServiceMessageProps {
|
|
4
5
|
/** Sets a label for the notification panel. */
|
|
5
6
|
label: string;
|
|
@@ -23,6 +24,8 @@ export interface ServiceMessageProps {
|
|
|
23
24
|
closeBtnText?: string;
|
|
24
25
|
/** Changes the visual representation. */
|
|
25
26
|
variant?: NotificationPanelVariants;
|
|
27
|
+
/** Sets the role of the service message - default: auto, will decide based on variant */
|
|
28
|
+
messageRole?: ServiceMessageRoles;
|
|
26
29
|
/** Sets the data-testid attribute. */
|
|
27
30
|
testId?: string;
|
|
28
31
|
}
|
|
@@ -123,11 +123,11 @@ var Content = ({ info, extraInfo, urlTitle, url, target, dismissable, closeBtnTe
|
|
|
123
123
|
})
|
|
124
124
|
});
|
|
125
125
|
};
|
|
126
|
-
var ServiceMessage = ({ label, dismissable = true, onDismiss, info, extraInfo, urlTitle, url, target = "_self", closeBtnText = "fjern melding", expanderOpenFromStart = false, variant = "error", testId }) => {
|
|
126
|
+
var ServiceMessage = ({ label, dismissable = true, onDismiss, info, extraInfo, urlTitle, url, target = "_self", closeBtnText = "fjern melding", expanderOpenFromStart = false, variant = "error", messageRole = "auto", testId }) => {
|
|
127
127
|
const [isExpanded, setIsExpanded] = useState(expanderOpenFromStart);
|
|
128
128
|
const labelId = useId();
|
|
129
129
|
const hasExpander = !!info || !!extraInfo;
|
|
130
|
-
const ariaRole = variant === "error" ? "alert" : "region";
|
|
130
|
+
const ariaRole = messageRole === "auto" ? variant === "error" ? "alert" : "region" : messageRole === "none" ? void 0 : messageRole;
|
|
131
131
|
const ariaLabelAttributes = getAriaLabelAttributes({
|
|
132
132
|
label,
|
|
133
133
|
id: labelId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Label: React.FC<LabelProps>","Content: React.FC<ContentProps>","ServiceMessage: React.FC<ServiceMessageProps>"],"sources":["../../../src/components/ServiceMessage/ServiceMessage.tsx","../../../src/components/ServiceMessage/index.ts"],"sourcesContent":["import { useId, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport type { AnchorLinkTargets } from '../AnchorLink';\nimport type { NotificationPanelVariants } from '../NotificationPanel';\n\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { getColor } from '../../theme/currys';\nimport { breakpoints } from '../../theme/grid';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport NotificationBadge from '../Badge/NotificationBadge';\nimport Close from '../Close';\nimport { renderElementHeader } from '../ElementHeader/utils';\nimport Icon, { IconSize } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport Forward from '../Icons/Forward';\nimport X from '../Icons/X';\n\nimport styles from './styles.module.scss';\n\ninterface LabelProps {\n label: string;\n variant: NotificationPanelVariants;\n id: string;\n hasExpander: boolean;\n isExpanded: boolean;\n dismissable: boolean;\n onExpand: () => void;\n onDismiss?: () => void;\n closeBtnText?: string;\n}\n\nconst Label: React.FC<LabelProps> = ({ label, variant, id, hasExpander, isExpanded, dismissable, onExpand, onDismiss, closeBtnText }) => {\n const breakpoint = useBreakpoint();\n const { isHovered, refObject } = usePseudoClasses<HTMLDivElement>();\n\n const iconSize = breakpoint < breakpoints.lg ? IconSize.XSmall : IconSize.Small;\n const labelContainerClasses = classNames(\n styles['service-message__label-container'],\n styles[`service-message__label-container--${variant}`],\n hasExpander && styles[`service-message__label-container--has-expander`]\n );\n\n const elementHeader = renderElementHeader(label, {\n titleHtmlMarkup: 'span',\n isHovered,\n size: 'compact',\n parentType: 'expanderlist',\n chevronIcon: hasExpander ? (isExpanded ? ChevronUp : ChevronDown) : undefined,\n icon: <NotificationBadge variant={variant} size={iconSize} isHovered={hasExpander && isHovered} />,\n closeButton:\n !hasExpander && dismissable ? (\n <Close onClick={onDismiss} ariaLabel={closeBtnText} className={styles['service-message__close']} />\n ) : undefined,\n });\n\n return (\n <div className={labelContainerClasses} ref={refObject}>\n <div className={styles['service-message__container']}>\n <div className={styles['service-message__row']}>\n <div className={styles['service-message__col']}>\n <div className={styles['service-message__label']}>\n {hasExpander ? (\n <h1 className={styles['service-message__title']} id={id}>\n <button type=\"button\" className={styles['service-message__toggle']} onClick={onExpand} aria-expanded={isExpanded}>\n {elementHeader}\n </button>\n </h1>\n ) : (\n <h1 className={styles['service-message__title']} id={id}>\n {elementHeader}\n </h1>\n )}\n </div>\n </div>\n </div>\n </div>\n </div>\n );\n};\n\ninterface ContentProps {\n info?: string;\n extraInfo?: string;\n urlTitle?: string;\n url?: string;\n target?: AnchorLinkTargets;\n dismissable: boolean;\n onDismiss?: () => void;\n closeBtnText?: string;\n}\n\nconst Content: React.FC<ContentProps> = ({ info, extraInfo, urlTitle, url, target, dismissable, closeBtnText, onDismiss }) => {\n const { refObject: readMoreRef, isHovered: readMoreHoverRefIsHovered } = usePseudoClasses<HTMLAnchorElement>();\n const { refObject: closeButtonRef, isHovered: closeButtonIsHovered } = usePseudoClasses<HTMLButtonElement>();\n\n const hasUrl = url && urlTitle;\n\n return (\n <div className={styles['service-message__container']}>\n <div className={styles['service-message__row']}>\n <div className={styles['service-message__col']}>\n <div className={styles['service-message__content']}>\n {info && <p className={styles['service-message__info']}>{info}</p>}\n {extraInfo && (\n <p className={classNames(styles['service-message__info'], styles['service-message__info--extra'])}>{extraInfo}</p>\n )}\n <div className={styles['service-message__actions']}>\n {hasUrl && (\n <a className={styles['service-message__action']} href={url} ref={readMoreRef} target={target}>\n {urlTitle}\n <Icon size={IconSize.XSmall} svgIcon={Forward} color={getColor('blueberry', 700)} isHovered={readMoreHoverRefIsHovered} />\n </a>\n )}\n\n {dismissable && (\n <button\n ref={closeButtonRef}\n className={classNames(styles['service-message__action'], styles['service-message__action--close'])}\n aria-label={closeBtnText}\n onClick={onDismiss}\n >\n {closeBtnText}\n <Icon size={IconSize.XSmall} svgIcon={X} color={getColor('blueberry', 700)} isHovered={closeButtonIsHovered} />\n </button>\n )}\n </div>\n </div>\n </div>\n </div>\n </div>\n );\n};\n\nexport interface ServiceMessageProps {\n /** Sets a label for the notification panel. */\n label: string;\n /** String displayed in service-message when expanded */\n info?: string;\n /** String displayed in service-message when expanded, with a smaller font */\n extraInfo?: string;\n /** function that runs on dismiss */\n onDismiss?: () => void;\n /** Allows for dismiss to be an option, also for ServiceMessage with only label as content */\n dismissable?: boolean;\n /** Makes expander be open from start. */\n expanderOpenFromStart?: boolean;\n /** Name that describes a url-link for the user*/\n urlTitle?: string;\n /** Url for further information*/\n url?: string;\n /** Sets target for the anchorlink to the url*/\n target?: AnchorLinkTargets;\n /** Text on close-button in service messages. */\n closeBtnText?: string;\n /** Changes the visual representation. */\n variant?: NotificationPanelVariants;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst ServiceMessage: React.FC<ServiceMessageProps> = ({\n label,\n dismissable = true,\n onDismiss,\n info,\n extraInfo,\n urlTitle,\n url,\n target = '_self',\n closeBtnText = 'fjern melding',\n expanderOpenFromStart = false,\n variant = 'error',\n testId,\n}) => {\n const [isExpanded, setIsExpanded] = useState<boolean>(expanderOpenFromStart);\n\n const labelId = useId();\n const hasExpander = !!info || !!extraInfo;\n\n const ariaRole = variant === 'error' ? 'alert' : 'region';\n const ariaLabelAttributes = getAriaLabelAttributes({ label, id: labelId });\n\n const handleClick = (): void => {\n if (hasExpander) setIsExpanded(!isExpanded);\n };\n\n const classes = classNames(styles['service-message'], styles[`service-message--${variant}`]);\n\n return (\n <div className={classes} role={ariaRole} {...ariaLabelAttributes} data-testid={testId}>\n <Label\n label={label}\n variant={variant}\n id={labelId}\n hasExpander={hasExpander}\n isExpanded={isExpanded}\n dismissable={dismissable}\n onExpand={handleClick}\n onDismiss={onDismiss}\n closeBtnText={closeBtnText}\n />\n {hasExpander && isExpanded && (\n <Content\n info={info}\n extraInfo={extraInfo}\n urlTitle={urlTitle}\n url={url}\n target={target}\n dismissable={dismissable}\n onDismiss={onDismiss}\n closeBtnText={closeBtnText}\n />\n )}\n </div>\n );\n};\n\nexport default ServiceMessage;\n","import ServiceMessage from './ServiceMessage';\nexport * from './ServiceMessage';\nexport default ServiceMessage;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,IAAMA,SAA+B,EAAE,OAAO,SAAS,IAAI,aAAa,YAAY,aAAa,UAAU,WAAW,mBAAmB;CACvI,MAAM,aAAa,eAAe;CAClC,MAAM,EAAE,WAAW,cAAc,kBAAkC;CAEnE,MAAM,WAAW,aAAa,YAAY,KAAK,SAAS,SAAS,SAAS;CAC1E,MAAM,wBAAwB,WAC5B,OAAO,qCACP,OAAO,qCAAqC,YAC5C,eAAe,OAAO,kDACvB;CAED,MAAM,gBAAgB,oBAAoB,OAAO;EAC/C,iBAAiB;EACjB;EACA,MAAM;EACN,YAAY;EACZ,aAAa,cAAe,aAAa,oBAAY,sBAAe,KAAA;EACpE,MAAM,oBAAC,2BAAA;GAA2B;GAAS,MAAM;GAAU,WAAW,eAAe;IAAa;EAClG,aACE,CAAC,eAAe,cACd,oBAAC,eAAA;GAAM,SAAS;GAAW,WAAW;GAAc,WAAW,OAAO;IAA6B,GACjG,KAAA;EACP,CAAC;AAEF,QACE,oBAAC,OAAA;EA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,cAAY;QACZ,SAAS;mBAER,cACD,oBAAC,cAAA;SAAK,MAAM,SAAS;SAAQ,SAAS;SAAG,OAAO,SAAS,aAAa,IAAI;SAAE,WAAW;UAAwB,CAAA;SACxG,CAAA;QAEP;;MACF;KACF;IACF;GACF;;AA+BV,IAAMC,kBAAiD,EACrD,OACA,cAAc,MACd,WACA,MACA,WACA,UACA,KACA,SAAS,SACT,eAAe,iBACf,wBAAwB,OACxB,UAAU,SACV,aACI;CACJ,MAAM,CAAC,YAAY,iBAAiB,SAAkB,sBAAsB;CAE5E,MAAM,UAAU,OAAO;CACvB,MAAM,cAAc,CAAC,CAAC,QAAQ,CAAC,CAAC;CAEhC,MAAM,WAAW,YAAY,UAAU,UAAU;CACjD,MAAM,sBAAsB,uBAAuB;EAAE;EAAO,IAAI;EAAS,CAAC;CAE1E,MAAM,oBAA0B;AAC9B,MAAI,YAAa,eAAc,CAAC,WAAW;;AAK7C,QACE,qBAAC,OAAA;EAAI,WAHS,WAAW,OAAO,oBAAoB,OAAO,oBAAoB,WAAW;EAGjE,MAAM;EAAU,GAAI;EAAqB,eAAa;aAC7E,oBAAC,OAAA;GACQ;GACE;GACT,IAAI;GACS;GACD;GACC;GACb,UAAU;GACC;GACG;IACd,EACD,eAAe,cACd,oBAAC,SAAA;GACO;GACK;GACD;GACL;GACG;GACK;GACF;GACG;IACd,CAAA;GAEA;;ACvNV,IAAA,yBD2Ne"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Label: React.FC<LabelProps>","Content: React.FC<ContentProps>","ServiceMessage: React.FC<ServiceMessageProps>"],"sources":["../../../src/components/ServiceMessage/ServiceMessage.tsx","../../../src/components/ServiceMessage/index.ts"],"sourcesContent":["import { useId, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport type { AnchorLinkTargets } from '../AnchorLink';\nimport type { NotificationPanelVariants } from '../NotificationPanel';\n\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { getColor } from '../../theme/currys';\nimport { breakpoints } from '../../theme/grid';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport NotificationBadge from '../Badge/NotificationBadge';\nimport Close from '../Close';\nimport { renderElementHeader } from '../ElementHeader/utils';\nimport Icon, { IconSize } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport Forward from '../Icons/Forward';\nimport X from '../Icons/X';\n\nimport styles from './styles.module.scss';\n\ninterface LabelProps {\n label: string;\n variant: NotificationPanelVariants;\n id: string;\n hasExpander: boolean;\n isExpanded: boolean;\n dismissable: boolean;\n onExpand: () => void;\n onDismiss?: () => void;\n closeBtnText?: string;\n}\n\nconst Label: React.FC<LabelProps> = ({ label, variant, id, hasExpander, isExpanded, dismissable, onExpand, onDismiss, closeBtnText }) => {\n const breakpoint = useBreakpoint();\n const { isHovered, refObject } = usePseudoClasses<HTMLDivElement>();\n\n const iconSize = breakpoint < breakpoints.lg ? IconSize.XSmall : IconSize.Small;\n const labelContainerClasses = classNames(\n styles['service-message__label-container'],\n styles[`service-message__label-container--${variant}`],\n hasExpander && styles[`service-message__label-container--has-expander`]\n );\n\n const elementHeader = renderElementHeader(label, {\n titleHtmlMarkup: 'span',\n isHovered,\n size: 'compact',\n parentType: 'expanderlist',\n chevronIcon: hasExpander ? (isExpanded ? ChevronUp : ChevronDown) : undefined,\n icon: <NotificationBadge variant={variant} size={iconSize} isHovered={hasExpander && isHovered} />,\n closeButton:\n !hasExpander && dismissable ? (\n <Close onClick={onDismiss} ariaLabel={closeBtnText} className={styles['service-message__close']} />\n ) : undefined,\n });\n\n return (\n <div className={labelContainerClasses} ref={refObject}>\n <div className={styles['service-message__container']}>\n <div className={styles['service-message__row']}>\n <div className={styles['service-message__col']}>\n <div className={styles['service-message__label']}>\n {hasExpander ? (\n <h1 className={styles['service-message__title']} id={id}>\n <button type=\"button\" className={styles['service-message__toggle']} onClick={onExpand} aria-expanded={isExpanded}>\n {elementHeader}\n </button>\n </h1>\n ) : (\n <h1 className={styles['service-message__title']} id={id}>\n {elementHeader}\n </h1>\n )}\n </div>\n </div>\n </div>\n </div>\n </div>\n );\n};\n\ninterface ContentProps {\n info?: string;\n extraInfo?: string;\n urlTitle?: string;\n url?: string;\n target?: AnchorLinkTargets;\n dismissable: boolean;\n onDismiss?: () => void;\n closeBtnText?: string;\n}\n\nconst Content: React.FC<ContentProps> = ({ info, extraInfo, urlTitle, url, target, dismissable, closeBtnText, onDismiss }) => {\n const { refObject: readMoreRef, isHovered: readMoreHoverRefIsHovered } = usePseudoClasses<HTMLAnchorElement>();\n const { refObject: closeButtonRef, isHovered: closeButtonIsHovered } = usePseudoClasses<HTMLButtonElement>();\n\n const hasUrl = url && urlTitle;\n\n return (\n <div className={styles['service-message__container']}>\n <div className={styles['service-message__row']}>\n <div className={styles['service-message__col']}>\n <div className={styles['service-message__content']}>\n {info && <p className={styles['service-message__info']}>{info}</p>}\n {extraInfo && (\n <p className={classNames(styles['service-message__info'], styles['service-message__info--extra'])}>{extraInfo}</p>\n )}\n <div className={styles['service-message__actions']}>\n {hasUrl && (\n <a className={styles['service-message__action']} href={url} ref={readMoreRef} target={target}>\n {urlTitle}\n <Icon size={IconSize.XSmall} svgIcon={Forward} color={getColor('blueberry', 700)} isHovered={readMoreHoverRefIsHovered} />\n </a>\n )}\n\n {dismissable && (\n <button\n ref={closeButtonRef}\n className={classNames(styles['service-message__action'], styles['service-message__action--close'])}\n aria-label={closeBtnText}\n onClick={onDismiss}\n >\n {closeBtnText}\n <Icon size={IconSize.XSmall} svgIcon={X} color={getColor('blueberry', 700)} isHovered={closeButtonIsHovered} />\n </button>\n )}\n </div>\n </div>\n </div>\n </div>\n </div>\n );\n};\n\nexport type ServiceMessageRoles = 'alert' | 'region' | 'auto' | 'none';\n\nexport interface ServiceMessageProps {\n /** Sets a label for the notification panel. */\n label: string;\n /** String displayed in service-message when expanded */\n info?: string;\n /** String displayed in service-message when expanded, with a smaller font */\n extraInfo?: string;\n /** function that runs on dismiss */\n onDismiss?: () => void;\n /** Allows for dismiss to be an option, also for ServiceMessage with only label as content */\n dismissable?: boolean;\n /** Makes expander be open from start. */\n expanderOpenFromStart?: boolean;\n /** Name that describes a url-link for the user*/\n urlTitle?: string;\n /** Url for further information*/\n url?: string;\n /** Sets target for the anchorlink to the url*/\n target?: AnchorLinkTargets;\n /** Text on close-button in service messages. */\n closeBtnText?: string;\n /** Changes the visual representation. */\n variant?: NotificationPanelVariants;\n /** Sets the role of the service message - default: auto, will decide based on variant */\n messageRole?: ServiceMessageRoles;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst ServiceMessage: React.FC<ServiceMessageProps> = ({\n label,\n dismissable = true,\n onDismiss,\n info,\n extraInfo,\n urlTitle,\n url,\n target = '_self',\n closeBtnText = 'fjern melding',\n expanderOpenFromStart = false,\n variant = 'error',\n messageRole = 'auto',\n testId,\n}) => {\n const [isExpanded, setIsExpanded] = useState<boolean>(expanderOpenFromStart);\n\n const labelId = useId();\n const hasExpander = !!info || !!extraInfo;\n\n const autoRole = variant === 'error' ? 'alert' : 'region';\n const ariaRole = messageRole === 'auto' ? autoRole : messageRole === 'none' ? undefined : messageRole;\n const ariaLabelAttributes = getAriaLabelAttributes({ label, id: labelId });\n\n const handleClick = (): void => {\n if (hasExpander) setIsExpanded(!isExpanded);\n };\n\n const classes = classNames(styles['service-message'], styles[`service-message--${variant}`]);\n\n return (\n <div className={classes} role={ariaRole} {...ariaLabelAttributes} data-testid={testId}>\n <Label\n label={label}\n variant={variant}\n id={labelId}\n hasExpander={hasExpander}\n isExpanded={isExpanded}\n dismissable={dismissable}\n onExpand={handleClick}\n onDismiss={onDismiss}\n closeBtnText={closeBtnText}\n />\n {hasExpander && isExpanded && (\n <Content\n info={info}\n extraInfo={extraInfo}\n urlTitle={urlTitle}\n url={url}\n target={target}\n dismissable={dismissable}\n onDismiss={onDismiss}\n closeBtnText={closeBtnText}\n />\n )}\n </div>\n );\n};\n\nexport default ServiceMessage;\n","import ServiceMessage from './ServiceMessage';\nexport * from './ServiceMessage';\nexport default ServiceMessage;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmCA,IAAMA,SAA+B,EAAE,OAAO,SAAS,IAAI,aAAa,YAAY,aAAa,UAAU,WAAW,mBAAmB;CACvI,MAAM,aAAa,eAAe;CAClC,MAAM,EAAE,WAAW,cAAc,kBAAkC;CAEnE,MAAM,WAAW,aAAa,YAAY,KAAK,SAAS,SAAS,SAAS;CAC1E,MAAM,wBAAwB,WAC5B,OAAO,qCACP,OAAO,qCAAqC,YAC5C,eAAe,OAAO,kDACvB;CAED,MAAM,gBAAgB,oBAAoB,OAAO;EAC/C,iBAAiB;EACjB;EACA,MAAM;EACN,YAAY;EACZ,aAAa,cAAe,aAAa,oBAAY,sBAAe,KAAA;EACpE,MAAM,oBAAC,2BAAA;GAA2B;GAAS,MAAM;GAAU,WAAW,eAAe;IAAa;EAClG,aACE,CAAC,eAAe,cACd,oBAAC,eAAA;GAAM,SAAS;GAAW,WAAW;GAAc,WAAW,OAAO;IAA6B,GACjG,KAAA;EACP,CAAC;AAEF,QACE,oBAAC,OAAA;EAAI,WAAW;EAAuB,KAAK;YAC1C,oBAAC,OAAA;GAAI,WAAW,OAAO;aACrB,oBAAC,OAAA;IAAI,WAAW,OAAO;cACrB,oBAAC,OAAA;KAAI,WAAW,OAAO;eACrB,oBAAC,OAAA;MAAI,WAAW,OAAO;gBACpB,cACC,oBAAC,MAAA;OAAG,WAAW,OAAO;OAA+B;iBACnD,oBAAC,UAAA;QAAO,MAAK;QAAS,WAAW,OAAO;QAA4B,SAAS;QAAU,iBAAe;kBACnG;SACM;QACN,GAEL,oBAAC,MAAA;OAAG,WAAW,OAAO;OAA+B;iBAClD;QACE;OAEH;MACF;KACF;IACF;GACF;;AAeV,IAAMC,WAAmC,EAAE,MAAM,WAAW,UAAU,KAAK,QAAQ,aAAa,cAAc,gBAAgB;CAC5H,MAAM,EAAE,WAAW,aAAa,WAA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,MAAM,sBAAsB,uBAAuB;EAAE;EAAO,IAAI;EAAS,CAAC;CAE1E,MAAM,oBAA0B;AAC9B,MAAI,YAAa,eAAc,CAAC,WAAW;;AAK7C,QACE,qBAAC,OAAA;EAAI,WAHS,WAAW,OAAO,oBAAoB,OAAO,oBAAoB,WAAW;EAGjE,MAAM;EAAU,GAAI;EAAqB,eAAa;aAC7E,oBAAC,OAAA;GACQ;GACE;GACT,IAAI;GACS;GACD;GACC;GACb,UAAU;GACC;GACG;IACd,EACD,eAAe,cACd,oBAAC,SAAA;GACO;GACK;GACD;GACL;GACG;GACK;GACF;GACG;IACd,CAAA;GAEA;;AC7NV,IAAA,yBDiOe"}
|
|
@@ -6,7 +6,7 @@ import { t as useIdWithFallback } from "../../useIdWithFallback.js";
|
|
|
6
6
|
import { t as getAriaDescribedBy } from "../../accessibility.js";
|
|
7
7
|
import { t as X_default } from "../../X.js";
|
|
8
8
|
import classNames from "classnames";
|
|
9
|
-
import { useLayoutEffect, useRef } from "react";
|
|
9
|
+
import { useId, useLayoutEffect, useRef } from "react";
|
|
10
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import styles from "./styles.module.scss";
|
|
12
12
|
var Close = (props) => {
|
|
@@ -34,6 +34,9 @@ var Close = (props) => {
|
|
|
34
34
|
};
|
|
35
35
|
var Close_default = Close;
|
|
36
36
|
var Triangle = ({ isHover, isFocus, isActive, isError }) => {
|
|
37
|
+
const uniqueId = useId();
|
|
38
|
+
const maskIdFocus = `${uniqueId}-mask-focus`;
|
|
39
|
+
const maskIdNormal = `${uniqueId}-mask-normal`;
|
|
37
40
|
const palette = (() => {
|
|
38
41
|
const colors = {
|
|
39
42
|
border: "var(--component-stickynote-border-normal)",
|
|
@@ -67,7 +70,7 @@ var Triangle = ({ isHover, isFocus, isActive, isError }) => {
|
|
|
67
70
|
xmlns: "http://www.w3.org/2000/svg",
|
|
68
71
|
children: [
|
|
69
72
|
/* @__PURE__ */ jsx("mask", {
|
|
70
|
-
id:
|
|
73
|
+
id: maskIdFocus,
|
|
71
74
|
fill: "white",
|
|
72
75
|
children: /* @__PURE__ */ jsx("path", { d: "M0.493163 20.9211L0.276366 20.9211L0.276367 0.921142L20.2764 0.921143L20.2764 1.13794L0.493163 20.9211Z" })
|
|
73
76
|
}),
|
|
@@ -78,7 +81,7 @@ var Triangle = ({ isHover, isFocus, isActive, isError }) => {
|
|
|
78
81
|
/* @__PURE__ */ jsx("path", {
|
|
79
82
|
d: "M0.493163 20.9211L0.493163 22.9211L1.32159 22.9211L1.90738 22.3354L0.493163 20.9211ZM0.276366 20.9211L-1.72363 20.9211L-1.72363 22.9211L0.276366 22.9211L0.276366 20.9211ZM0.276367 0.921142L0.276367 -1.07886L-1.72363 -1.07886L-1.72363 0.921142L0.276367 0.921142ZM20.2764 0.921143L22.2764 0.921143L22.2764 -1.07886L20.2764 -1.07886L20.2764 0.921143ZM20.2764 1.13794L21.6906 2.55215L22.2764 1.96637L22.2764 1.13794L20.2764 1.13794ZM0.493163 20.9211L0.493163 18.9211L0.276366 18.9211L0.276366 20.9211L0.276366 22.9211L0.493163 22.9211L0.493163 20.9211ZM0.276366 20.9211L2.27637 20.9211L2.27637 0.921142L0.276367 0.921142L-1.72363 0.921142L-1.72363 20.9211L0.276366 20.9211ZM0.276367 0.921142L0.276367 2.92114L20.2764 2.92114L20.2764 0.921143L20.2764 -1.07886L0.276367 -1.07886L0.276367 0.921142ZM20.2764 0.921143L18.2764 0.921142L18.2764 1.13794L20.2764 1.13794L22.2764 1.13794L22.2764 0.921143L20.2764 0.921143ZM20.2764 1.13794L18.8622 -0.276274L-0.92105 19.5069L0.493163 20.9211L1.90738 22.3354L21.6906 2.55215L20.2764 1.13794Z",
|
|
80
83
|
fill: palette.border,
|
|
81
|
-
mask:
|
|
84
|
+
mask: `url(#${maskIdFocus})`
|
|
82
85
|
})
|
|
83
86
|
]
|
|
84
87
|
});
|
|
@@ -90,7 +93,7 @@ var Triangle = ({ isHover, isFocus, isActive, isError }) => {
|
|
|
90
93
|
xmlns: "http://www.w3.org/2000/svg",
|
|
91
94
|
children: [
|
|
92
95
|
/* @__PURE__ */ jsx("mask", {
|
|
93
|
-
id:
|
|
96
|
+
id: maskIdNormal,
|
|
94
97
|
fill: "white",
|
|
95
98
|
children: /* @__PURE__ */ jsx("path", { d: "M0.923827 20.9211L0.70703 20.9211L0.707031 0.921142L20.707 0.921143L20.707 1.13794L0.923827 20.9211Z" })
|
|
96
99
|
}),
|
|
@@ -101,7 +104,7 @@ var Triangle = ({ isHover, isFocus, isActive, isError }) => {
|
|
|
101
104
|
/* @__PURE__ */ jsx("path", {
|
|
102
105
|
d: "M0.923827 20.9211L0.923827 21.9211L1.33804 21.9211L1.63093 21.6282L0.923827 20.9211ZM0.70703 20.9211L-0.29297 20.9211L-0.29297 21.9211L0.70703 21.9211L0.70703 20.9211ZM0.707031 0.921142L0.707031 -0.0788582L-0.292969 -0.0788583L-0.292969 0.921142L0.707031 0.921142ZM20.707 0.921143L21.707 0.921143L21.707 -0.0788574L20.707 -0.0788574L20.707 0.921143ZM20.707 1.13794L21.4141 1.84505L21.707 1.55215L21.707 1.13794L20.707 1.13794ZM0.923827 20.9211L0.923827 19.9211L0.70703 19.9211L0.70703 20.9211L0.70703 21.9211L0.923827 21.9211L0.923827 20.9211ZM0.70703 20.9211L1.70703 20.9211L1.70703 0.921142L0.707031 0.921142L-0.292969 0.921142L-0.29297 20.9211L0.70703 20.9211ZM0.707031 0.921142L0.707031 1.92114L20.707 1.92114L20.707 0.921143L20.707 -0.0788574L0.707031 -0.0788582L0.707031 0.921142ZM20.707 0.921143L19.707 0.921143L19.707 1.13794L20.707 1.13794L21.707 1.13794L21.707 0.921143L20.707 0.921143ZM20.707 1.13794L19.9999 0.430833L0.21672 20.214L0.923827 20.9211L1.63093 21.6282L21.4141 1.84505L20.707 1.13794Z",
|
|
103
106
|
fill: palette.border,
|
|
104
|
-
mask:
|
|
107
|
+
mask: `url(#${maskIdNormal})`
|
|
105
108
|
})
|
|
106
109
|
]
|
|
107
110
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Close: React.FC<CloseProps>","Triangle: React.FC<TriangleProps>","colors: Palette","svg: React.ReactNode","StickyNote: React.FC<StickyNoteProps>"],"sources":["../../../src/components/StickyNote/Close.tsx","../../../src/components/StickyNote/Triangle.tsx","../../../src/components/StickyNote/StickyNote.tsx","../../../src/components/StickyNote/index.ts"],"sourcesContent":["import classNames from 'classnames';\n\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { mergeRefs } from '../../utils/refs';\nimport Icon from '../Icon';\nimport X from '../Icons/X';\n\nimport styles from './styles.module.scss';\n\nexport interface CloseProps {\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 /** Sets the data-testid attribute. */\n testId?: string;\n /** Ref passed to the button element */\n ref?: React.Ref<HTMLButtonElement | null>;\n}\n\n/*\n Denne er kopiert fra Close-komponent. \n Det er for å kunne ha en egen lokal variant for StickyNote. \n Likt som i Figma.\n */\n\nconst Close: React.FC<CloseProps> = (props: CloseProps) => {\n const { testId, ariaLabel = 'Lukk', onClick, ref } = props;\n const { refObject, isHovered } = usePseudoClasses();\n\n const iconSize = useIsMobileBreakpoint() ? 38 : 48;\n\n const closeClasses = classNames(styles.close);\n\n return (\n <button\n ref={mergeRefs([ref, refObject])}\n data-testid={testId}\n className={closeClasses}\n aria-label={ariaLabel}\n onClick={onClick}\n type=\"button\"\n >\n <span className={classNames(styles['close__inner-container'])}>\n <Icon svgIcon={X} color=\"black\" size={iconSize} isHovered={isHovered} />\n </span>\n </button>\n );\n};\n\nexport default Close;\n","interface TriangleProps {\n isHover: boolean;\n isFocus: boolean;\n isActive: boolean;\n isError: boolean;\n}\n\nexport interface Palette {\n border: string;\n background: string;\n}\n\nconst Triangle: React.FC<TriangleProps> = ({ isHover, isFocus, isActive, isError }) => {\n const palette = ((): Palette => {\n const colors: Palette = {\n border: 'var(--component-stickynote-border-normal)',\n background: 'var(--component-stickynote-background-fold-normal-light)',\n };\n\n if (!isError) {\n if (isHover) {\n colors.background = 'var(--component-stickynote-background-fold-normal-medium)';\n }\n if (isFocus) {\n colors.border = 'var(--color-action-border-onlight-focus)';\n colors.background = 'var(--component-stickynote-background-fold-normal-medium)';\n }\n if (isActive) {\n colors.background = 'var(--component-stickynote-background-fold-normal-dark)';\n }\n } else {\n colors.border = 'var(--component-stickynote-border-error)';\n colors.background = 'var(--component-stickynote-background-fold-error-light)';\n if (isHover) {\n colors.background = 'var(--component-stickynote-background-fold-error-medium)';\n }\n if (isFocus) {\n colors.border = 'var(--color-action-border-onlight-focus)';\n colors.background = 'var(--component-stickynote-background-fold-error-medium)';\n }\n if (isActive) {\n colors.background = 'var(--component-stickynote-background-fold-error-dark)';\n }\n }\n return colors;\n })();\n\n let svg: React.ReactNode;\n\n if (isFocus) {\n svg = (\n <svg width=\"21\" height=\"21\" viewBox=\"0 0 21 21\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <mask id=\"path-1-inside-1_7753_1401\" fill=\"white\">\n <path d=\"M0.493163 20.9211L0.276366 20.9211L0.276367 0.921142L20.2764 0.921143L20.2764 1.13794L0.493163 20.9211Z\" />\n </mask>\n <path\n d=\"M0.493163 20.9211L0.276366 20.9211L0.276367 0.921142L20.2764 0.921143L20.2764 1.13794L0.493163 20.9211Z\"\n fill={palette.background}\n />\n <path\n d=\"M0.493163 20.9211L0.493163 22.9211L1.32159 22.9211L1.90738 22.3354L0.493163 20.9211ZM0.276366 20.9211L-1.72363 20.9211L-1.72363 22.9211L0.276366 22.9211L0.276366 20.9211ZM0.276367 0.921142L0.276367 -1.07886L-1.72363 -1.07886L-1.72363 0.921142L0.276367 0.921142ZM20.2764 0.921143L22.2764 0.921143L22.2764 -1.07886L20.2764 -1.07886L20.2764 0.921143ZM20.2764 1.13794L21.6906 2.55215L22.2764 1.96637L22.2764 1.13794L20.2764 1.13794ZM0.493163 20.9211L0.493163 18.9211L0.276366 18.9211L0.276366 20.9211L0.276366 22.9211L0.493163 22.9211L0.493163 20.9211ZM0.276366 20.9211L2.27637 20.9211L2.27637 0.921142L0.276367 0.921142L-1.72363 0.921142L-1.72363 20.9211L0.276366 20.9211ZM0.276367 0.921142L0.276367 2.92114L20.2764 2.92114L20.2764 0.921143L20.2764 -1.07886L0.276367 -1.07886L0.276367 0.921142ZM20.2764 0.921143L18.2764 0.921142L18.2764 1.13794L20.2764 1.13794L22.2764 1.13794L22.2764 0.921143L20.2764 0.921143ZM20.2764 1.13794L18.8622 -0.276274L-0.92105 19.5069L0.493163 20.9211L1.90738 22.3354L21.6906 2.55215L20.2764 1.13794Z\"\n fill={palette.border}\n mask=\"url(#path-1-inside-1_7753_1401)\"\n />\n </svg>\n );\n } else {\n svg = (\n <svg width=\"21\" height=\"21\" viewBox=\"0 0 21 21\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <mask id=\"path-1-inside-1_7717_293537\" fill=\"white\">\n <path d=\"M0.923827 20.9211L0.70703 20.9211L0.707031 0.921142L20.707 0.921143L20.707 1.13794L0.923827 20.9211Z\" />\n </mask>\n <path\n d=\"M0.923827 20.9211L0.70703 20.9211L0.707031 0.921142L20.707 0.921143L20.707 1.13794L0.923827 20.9211Z\"\n fill={palette.background}\n />\n <path\n d=\"M0.923827 20.9211L0.923827 21.9211L1.33804 21.9211L1.63093 21.6282L0.923827 20.9211ZM0.70703 20.9211L-0.29297 20.9211L-0.29297 21.9211L0.70703 21.9211L0.70703 20.9211ZM0.707031 0.921142L0.707031 -0.0788582L-0.292969 -0.0788583L-0.292969 0.921142L0.707031 0.921142ZM20.707 0.921143L21.707 0.921143L21.707 -0.0788574L20.707 -0.0788574L20.707 0.921143ZM20.707 1.13794L21.4141 1.84505L21.707 1.55215L21.707 1.13794L20.707 1.13794ZM0.923827 20.9211L0.923827 19.9211L0.70703 19.9211L0.70703 20.9211L0.70703 21.9211L0.923827 21.9211L0.923827 20.9211ZM0.70703 20.9211L1.70703 20.9211L1.70703 0.921142L0.707031 0.921142L-0.292969 0.921142L-0.29297 20.9211L0.70703 20.9211ZM0.707031 0.921142L0.707031 1.92114L20.707 1.92114L20.707 0.921143L20.707 -0.0788574L0.707031 -0.0788582L0.707031 0.921142ZM20.707 0.921143L19.707 0.921143L19.707 1.13794L20.707 1.13794L21.707 1.13794L21.707 0.921143L20.707 0.921143ZM20.707 1.13794L19.9999 0.430833L0.21672 20.214L0.923827 20.9211L1.63093 21.6282L21.4141 1.84505L20.707 1.13794Z\"\n fill={palette.border}\n mask=\"url(#path-1-inside-1_7717_293537)\"\n />\n </svg>\n );\n }\n\n return <>{svg}</>;\n};\n\nexport default Triangle;\n","import { useLayoutEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport Close from './Close';\nimport Triangle from './Triangle';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\n\nimport styles from './styles.module.scss';\n\nexport interface StickyNoteProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {\n /** Aria label for the delete/close button */\n arialabelXButton: string;\n /** Activates the error styling */\n error?: boolean;\n /** Error text to show below the note */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Text shown under the textarea */\n footerText?: string;\n /** Function run when clicking the delete/close button */\n onXButtonClick?: () => void;\n /** Function run if user clicks the component while it is disabled */\n onClickWhileDisabled?: () => void;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Timestamp shown over the textarea */\n timestamp: string;\n /** Classname for the outer wrapper */\n wrapperClassName?: string;\n}\n\nconst StickyNote: React.FC<StickyNoteProps> = (props: StickyNoteProps) => {\n const {\n wrapperClassName,\n timestamp,\n onXButtonClick,\n arialabelXButton,\n footerText,\n error,\n errorText,\n errorTextId: errorTextIdProp,\n onClickWhileDisabled,\n testId,\n ...textareaProps\n } = props;\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const stickynoteRef = useRef<HTMLDivElement>(null);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const { isFocused: isTextareaFocused } = usePseudoClasses<HTMLTextAreaElement | null>(textareaRef);\n const { isHovered, isActive } = usePseudoClasses<HTMLDivElement | null>(stickynoteRef);\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>): void => {\n if ((event.target as HTMLElement).closest('button')) {\n return;\n }\n if (textareaProps.disabled) {\n if (onClickWhileDisabled) onClickWhileDisabled();\n return;\n }\n textareaRef.current?.focus();\n };\n\n const resizeTextarea = (): void => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n resizeTarget(textarea);\n };\n\n const resizeTarget = (target: HTMLTextAreaElement): void => {\n // Reset field height\n target.style.height = 'inherit';\n // Set new height\n target.style.height = `${target.scrollHeight}px`;\n };\n\n useLayoutEffect(() => {\n resizeTextarea();\n // Must run after the shadow DOM has been set up to work on microweb\n setTimeout(() => resizeTextarea(), 1000);\n }, []);\n\n const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {\n const textarea = e.target as HTMLTextAreaElement;\n resizeTarget(textarea);\n if (textareaProps.onChange) textareaProps.onChange(e);\n };\n\n return (\n <div>\n <div\n data-testid={testId}\n ref={stickynoteRef}\n className={classNames(styles['sticky-note'], wrapperClassName, {\n [styles['sticky-note--focused']]: isTextareaFocused,\n [styles['sticky-note--active']]: isActive,\n [styles['sticky-note--hovered']]: isHovered && !isTextareaFocused && !textareaProps.disabled,\n [styles['sticky-note--error']]: error,\n })}\n onClick={handleWrapperClick}\n role=\"textbox\"\n tabIndex={-1}\n onKeyDown={e => {\n if (e.key === 'Enter' || e.key === ' ') {\n handleWrapperClick(e as React.KeyboardEvent<HTMLDivElement>);\n }\n }}\n >\n <div className={classNames(styles['sticky-note__header'])}>\n {timestamp && <span className={styles['sticky-note__header__timestamp']}>{timestamp}</span>}\n </div>\n <textarea\n ref={textareaRef}\n data-testid={`${testId}-textarea`}\n className={classNames(styles['sticky-note__textarea'], textareaProps.className)}\n {...textareaProps}\n onChange={handleChange}\n aria-describedby={getAriaDescribedBy(props, errorTextId)}\n />\n <Close onClick={onXButtonClick} ariaLabel={arialabelXButton} testId=\"closeButton\" />\n <div className={classNames(styles['sticky-note__footer'])}>{footerText && <span>{footerText}</span>}</div>\n <div className={classNames(styles['sticky-note__triangle'])}>\n <Triangle isHover={isHovered} isActive={isActive} isFocus={isTextareaFocused} isError={!!error} />\n </div>\n </div>\n {error && (\n <p className={styles['sticky-note__error-text']} id={errorTextId}>\n {errorText}\n </p>\n )}\n </div>\n );\n};\n\nexport default StickyNote;\n","import StickyNote from './StickyNote';\nexport * from './StickyNote';\nexport default StickyNote;\n"],"mappings":";;;;;;;;;;;AA2BA,IAAMA,SAA+B,UAAsB;CACzD,MAAM,EAAE,QAAQ,YAAY,QAAQ,SAAS,QAAQ;CACrD,MAAM,EAAE,WAAW,cAAc,kBAAkB;CAEnD,MAAM,WAAW,uBAAuB,GAAG,KAAK;CAEhD,MAAM,eAAe,WAAW,OAAO,MAAM;AAE7C,QACE,oBAAC,UAAA;EACC,KAAK,UAAU,CAAC,KAAK,UAAU,CAAC;EAChC,eAAa;EACb,WAAW;EACX,cAAY;EACH;EACT,MAAK;YAEL,oBAAC,QAAA;GAAK,WAAW,WAAW,OAAO,0BAA0B;aAC3D,oBAAC,cAAA;IAAK,SAAS;IAAG,OAAM;IAAQ,MAAM;IAAqB;KAAa;IACnE;GACA;;AAIb,IAAA,gBAAe;ACvCf,IAAMC,YAAqC,EAAE,SAAS,SAAS,UAAU,cAAc;CACrF,MAAM,iBAA0B;EAC9B,MAAMC,SAAkB;GACtB,QAAQ;GACR,YAAY;GACb;AAED,MAAI,CAAC,SAAS;AACZ,OAAI,QACF,QAAO,aAAa;AAEtB,OAAI,SAAS;A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M,SAAS;IAAgB,WAAW;IAAkB,QAAO;KAAgB;GACpF,oBAAC,OAAA;IAAI,WAAW,WAAW,OAAO,uBAAuB;cAAG,cAAc,oBAAC,QAAA,EAAA,UAAM,YAAA,CAAkB;KAAO;GAC1G,oBAAC,OAAA;IAAI,WAAW,WAAW,OAAO,yBAAyB;cACzD,oBAAC,kBAAA;KAAS,SAAS;KAAqB;KAAU,SAAS;KAAmB,SAAS,CAAC,CAAC;MAAS;KAC9F;;GACF,EACL,SACC,oBAAC,KAAA;EAAE,WAAW,OAAO;EAA4B,IAAI;YAClD;GACC,CAAA,EAAA,CAEF;;ACnIV,IAAA,qBDuIe"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Close: React.FC<CloseProps>","Triangle: React.FC<TriangleProps>","colors: Palette","svg: React.ReactNode","StickyNote: React.FC<StickyNoteProps>"],"sources":["../../../src/components/StickyNote/Close.tsx","../../../src/components/StickyNote/Triangle.tsx","../../../src/components/StickyNote/StickyNote.tsx","../../../src/components/StickyNote/index.ts"],"sourcesContent":["import classNames from 'classnames';\n\nimport { useIsMobileBreakpoint } from '../../hooks/useIsMobileBreakpoint';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { mergeRefs } from '../../utils/refs';\nimport Icon from '../Icon';\nimport X from '../Icons/X';\n\nimport styles from './styles.module.scss';\n\nexport interface CloseProps {\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 /** Sets the data-testid attribute. */\n testId?: string;\n /** Ref passed to the button element */\n ref?: React.Ref<HTMLButtonElement | null>;\n}\n\n/*\n Denne er kopiert fra Close-komponent. \n Det er for å kunne ha en egen lokal variant for StickyNote. \n Likt som i Figma.\n */\n\nconst Close: React.FC<CloseProps> = (props: CloseProps) => {\n const { testId, ariaLabel = 'Lukk', onClick, ref } = props;\n const { refObject, isHovered } = usePseudoClasses();\n\n const iconSize = useIsMobileBreakpoint() ? 38 : 48;\n\n const closeClasses = classNames(styles.close);\n\n return (\n <button\n ref={mergeRefs([ref, refObject])}\n data-testid={testId}\n className={closeClasses}\n aria-label={ariaLabel}\n onClick={onClick}\n type=\"button\"\n >\n <span className={classNames(styles['close__inner-container'])}>\n <Icon svgIcon={X} color=\"black\" size={iconSize} isHovered={isHovered} />\n </span>\n </button>\n );\n};\n\nexport default Close;\n","import { useId } from 'react';\n\ninterface TriangleProps {\n isHover: boolean;\n isFocus: boolean;\n isActive: boolean;\n isError: boolean;\n}\n\nexport interface Palette {\n border: string;\n background: string;\n}\n\nconst Triangle: React.FC<TriangleProps> = ({ isHover, isFocus, isActive, isError }) => {\n const uniqueId = useId();\n const maskIdFocus = `${uniqueId}-mask-focus`;\n const maskIdNormal = `${uniqueId}-mask-normal`;\n const palette = ((): Palette => {\n const colors: Palette = {\n border: 'var(--component-stickynote-border-normal)',\n background: 'var(--component-stickynote-background-fold-normal-light)',\n };\n\n if (!isError) {\n if (isHover) {\n colors.background = 'var(--component-stickynote-background-fold-normal-medium)';\n }\n if (isFocus) {\n colors.border = 'var(--color-action-border-onlight-focus)';\n colors.background = 'var(--component-stickynote-background-fold-normal-medium)';\n }\n if (isActive) {\n colors.background = 'var(--component-stickynote-background-fold-normal-dark)';\n }\n } else {\n colors.border = 'var(--component-stickynote-border-error)';\n colors.background = 'var(--component-stickynote-background-fold-error-light)';\n if (isHover) {\n colors.background = 'var(--component-stickynote-background-fold-error-medium)';\n }\n if (isFocus) {\n colors.border = 'var(--color-action-border-onlight-focus)';\n colors.background = 'var(--component-stickynote-background-fold-error-medium)';\n }\n if (isActive) {\n colors.background = 'var(--component-stickynote-background-fold-error-dark)';\n }\n }\n return colors;\n })();\n\n let svg: React.ReactNode;\n\n if (isFocus) {\n svg = (\n <svg width=\"21\" height=\"21\" viewBox=\"0 0 21 21\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <mask id={maskIdFocus} fill=\"white\">\n <path d=\"M0.493163 20.9211L0.276366 20.9211L0.276367 0.921142L20.2764 0.921143L20.2764 1.13794L0.493163 20.9211Z\" />\n </mask>\n <path\n d=\"M0.493163 20.9211L0.276366 20.9211L0.276367 0.921142L20.2764 0.921143L20.2764 1.13794L0.493163 20.9211Z\"\n fill={palette.background}\n />\n <path\n d=\"M0.493163 20.9211L0.493163 22.9211L1.32159 22.9211L1.90738 22.3354L0.493163 20.9211ZM0.276366 20.9211L-1.72363 20.9211L-1.72363 22.9211L0.276366 22.9211L0.276366 20.9211ZM0.276367 0.921142L0.276367 -1.07886L-1.72363 -1.07886L-1.72363 0.921142L0.276367 0.921142ZM20.2764 0.921143L22.2764 0.921143L22.2764 -1.07886L20.2764 -1.07886L20.2764 0.921143ZM20.2764 1.13794L21.6906 2.55215L22.2764 1.96637L22.2764 1.13794L20.2764 1.13794ZM0.493163 20.9211L0.493163 18.9211L0.276366 18.9211L0.276366 20.9211L0.276366 22.9211L0.493163 22.9211L0.493163 20.9211ZM0.276366 20.9211L2.27637 20.9211L2.27637 0.921142L0.276367 0.921142L-1.72363 0.921142L-1.72363 20.9211L0.276366 20.9211ZM0.276367 0.921142L0.276367 2.92114L20.2764 2.92114L20.2764 0.921143L20.2764 -1.07886L0.276367 -1.07886L0.276367 0.921142ZM20.2764 0.921143L18.2764 0.921142L18.2764 1.13794L20.2764 1.13794L22.2764 1.13794L22.2764 0.921143L20.2764 0.921143ZM20.2764 1.13794L18.8622 -0.276274L-0.92105 19.5069L0.493163 20.9211L1.90738 22.3354L21.6906 2.55215L20.2764 1.13794Z\"\n fill={palette.border}\n mask={`url(#${maskIdFocus})`}\n />\n </svg>\n );\n } else {\n svg = (\n <svg width=\"21\" height=\"21\" viewBox=\"0 0 21 21\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <mask id={maskIdNormal} fill=\"white\">\n <path d=\"M0.923827 20.9211L0.70703 20.9211L0.707031 0.921142L20.707 0.921143L20.707 1.13794L0.923827 20.9211Z\" />\n </mask>\n <path\n d=\"M0.923827 20.9211L0.70703 20.9211L0.707031 0.921142L20.707 0.921143L20.707 1.13794L0.923827 20.9211Z\"\n fill={palette.background}\n />\n <path\n d=\"M0.923827 20.9211L0.923827 21.9211L1.33804 21.9211L1.63093 21.6282L0.923827 20.9211ZM0.70703 20.9211L-0.29297 20.9211L-0.29297 21.9211L0.70703 21.9211L0.70703 20.9211ZM0.707031 0.921142L0.707031 -0.0788582L-0.292969 -0.0788583L-0.292969 0.921142L0.707031 0.921142ZM20.707 0.921143L21.707 0.921143L21.707 -0.0788574L20.707 -0.0788574L20.707 0.921143ZM20.707 1.13794L21.4141 1.84505L21.707 1.55215L21.707 1.13794L20.707 1.13794ZM0.923827 20.9211L0.923827 19.9211L0.70703 19.9211L0.70703 20.9211L0.70703 21.9211L0.923827 21.9211L0.923827 20.9211ZM0.70703 20.9211L1.70703 20.9211L1.70703 0.921142L0.707031 0.921142L-0.292969 0.921142L-0.29297 20.9211L0.70703 20.9211ZM0.707031 0.921142L0.707031 1.92114L20.707 1.92114L20.707 0.921143L20.707 -0.0788574L0.707031 -0.0788582L0.707031 0.921142ZM20.707 0.921143L19.707 0.921143L19.707 1.13794L20.707 1.13794L21.707 1.13794L21.707 0.921143L20.707 0.921143ZM20.707 1.13794L19.9999 0.430833L0.21672 20.214L0.923827 20.9211L1.63093 21.6282L21.4141 1.84505L20.707 1.13794Z\"\n fill={palette.border}\n mask={`url(#${maskIdNormal})`}\n />\n </svg>\n );\n }\n\n return <>{svg}</>;\n};\n\nexport default Triangle;\n","import { useLayoutEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport Close from './Close';\nimport Triangle from './Triangle';\nimport { useIdWithFallback } from '../../hooks/useIdWithFallback';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\n\nimport styles from './styles.module.scss';\n\nexport interface StickyNoteProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {\n /** Aria label for the delete/close button */\n arialabelXButton: string;\n /** Activates the error styling */\n error?: boolean;\n /** Error text to show below the note */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Text shown under the textarea */\n footerText?: string;\n /** Function run when clicking the delete/close button */\n onXButtonClick?: () => void;\n /** Function run if user clicks the component while it is disabled */\n onClickWhileDisabled?: () => void;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Timestamp shown over the textarea */\n timestamp: string;\n /** Classname for the outer wrapper */\n wrapperClassName?: string;\n}\n\nconst StickyNote: React.FC<StickyNoteProps> = (props: StickyNoteProps) => {\n const {\n wrapperClassName,\n timestamp,\n onXButtonClick,\n arialabelXButton,\n footerText,\n error,\n errorText,\n errorTextId: errorTextIdProp,\n onClickWhileDisabled,\n testId,\n ...textareaProps\n } = props;\n const errorTextId = useIdWithFallback(errorTextIdProp);\n const stickynoteRef = useRef<HTMLDivElement>(null);\n const textareaRef = useRef<HTMLTextAreaElement>(null);\n const { isFocused: isTextareaFocused } = usePseudoClasses<HTMLTextAreaElement | null>(textareaRef);\n const { isHovered, isActive } = usePseudoClasses<HTMLDivElement | null>(stickynoteRef);\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>): void => {\n if ((event.target as HTMLElement).closest('button')) {\n return;\n }\n if (textareaProps.disabled) {\n if (onClickWhileDisabled) onClickWhileDisabled();\n return;\n }\n textareaRef.current?.focus();\n };\n\n const resizeTextarea = (): void => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n resizeTarget(textarea);\n };\n\n const resizeTarget = (target: HTMLTextAreaElement): void => {\n // Reset field height\n target.style.height = 'inherit';\n // Set new height\n target.style.height = `${target.scrollHeight}px`;\n };\n\n useLayoutEffect(() => {\n resizeTextarea();\n // Must run after the shadow DOM has been set up to work on microweb\n setTimeout(() => resizeTextarea(), 1000);\n }, []);\n\n const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>): void => {\n const textarea = e.target as HTMLTextAreaElement;\n resizeTarget(textarea);\n if (textareaProps.onChange) textareaProps.onChange(e);\n };\n\n return (\n <div>\n <div\n data-testid={testId}\n ref={stickynoteRef}\n className={classNames(styles['sticky-note'], wrapperClassName, {\n [styles['sticky-note--focused']]: isTextareaFocused,\n [styles['sticky-note--active']]: isActive,\n [styles['sticky-note--hovered']]: isHovered && !isTextareaFocused && !textareaProps.disabled,\n [styles['sticky-note--error']]: error,\n })}\n onClick={handleWrapperClick}\n role=\"textbox\"\n tabIndex={-1}\n onKeyDown={e => {\n if (e.key === 'Enter' || e.key === ' ') {\n handleWrapperClick(e as React.KeyboardEvent<HTMLDivElement>);\n }\n }}\n >\n <div className={classNames(styles['sticky-note__header'])}>\n {timestamp && <span className={styles['sticky-note__header__timestamp']}>{timestamp}</span>}\n </div>\n <textarea\n ref={textareaRef}\n data-testid={`${testId}-textarea`}\n className={classNames(styles['sticky-note__textarea'], textareaProps.className)}\n {...textareaProps}\n onChange={handleChange}\n aria-describedby={getAriaDescribedBy(props, errorTextId)}\n />\n <Close onClick={onXButtonClick} ariaLabel={arialabelXButton} testId=\"closeButton\" />\n <div className={classNames(styles['sticky-note__footer'])}>{footerText && <span>{footerText}</span>}</div>\n <div className={classNames(styles['sticky-note__triangle'])}>\n <Triangle isHover={isHovered} isActive={isActive} isFocus={isTextareaFocused} isError={!!error} />\n </div>\n </div>\n {error && (\n <p className={styles['sticky-note__error-text']} id={errorTextId}>\n {errorText}\n </p>\n )}\n </div>\n );\n};\n\nexport default StickyNote;\n","import StickyNote from './StickyNote';\nexport * from './StickyNote';\nexport default StickyNote;\n"],"mappings":";;;;;;;;;;;AA2BA,IAAMA,SAA+B,UAAsB;CACzD,MAAM,EAAE,QAAQ,YAAY,QAAQ,SAAS,QAAQ;CACrD,MAAM,EAAE,WAAW,cAAc,kBAAkB;CAEnD,MAAM,WAAW,uBAAuB,GAAG,KAAK;CAEhD,MAAM,eAAe,WAAW,OAAO,MAAM;AAE7C,QACE,oBAAC,UAAA;EACC,KAAK,UAAU,CAAC,KAAK,UAAU,C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,OAAO,yBAAyB;IAChC,OAAO,0BAA0B,aAAa,CAAC,qBAAqB,CAAC,cAAc;IACnF,OAAO,wBAAwB;GACjC,CAAC;EACF,SAAS;EACT,MAAK;EACL,UAAU;EACV,YAAW,MAAK;AACd,OAAI,EAAE,QAAQ,WAAW,EAAE,QAAQ,IACjC,oBAAmB,EAAyC;;;GAIhE,oBAAC,OAAA;IAAI,WAAW,WAAW,OAAO,uBAAuB;cACtD,aAAa,oBAAC,QAAA;KAAK,WAAW,OAAO;eAAoC;MAAiB;KACvF;GACN,oBAAC,YAAA;IACC,KAAK;IACL,eAAa,GAAG,OAAO;IACvB,WAAW,WAAW,OAAO,0BAA0B,cAAc,UAAU;IAC/E,GAAI;IACJ,UAAU;IACV,oBAAkB,mBAAmB,OAAO,YAAY;KACxD;GACF,oBAAC,eAAA;IAAM,SAAS;IAAgB,WAAW;IAAkB,QAAO;KAAgB;GACpF,oBAAC,OAAA;IAAI,WAAW,WAAW,OAAO,uBAAuB;cAAG,cAAc,oBAAC,QAAA,EAAA,UAAM,YAAA,CAAkB;KAAO;GAC1G,oBAAC,OAAA;IAAI,WAAW,WAAW,OAAO,yBAAyB;cACzD,oBAAC,kBAAA;KAAS,SAAS;KAAqB;KAAU,SAAS;KAAmB,SAAS,CAAC,CAAC;MAAS;KAC9F;;GACF,EACL,SACC,oBAAC,KAAA;EAAE,WAAW,OAAO;EAA4B,IAAI;YAClD;GACC,CAAA,EAAA,CAEF;;ACnIV,IAAA,qBDuIe"}
|
|
@@ -16,7 +16,7 @@ import { n as TableRow } from "../../TableRow.js";
|
|
|
16
16
|
import classNames from "classnames";
|
|
17
17
|
import { useEffect, useRef, useState } from "react";
|
|
18
18
|
import { jsx } from "react/jsx-runtime";
|
|
19
|
-
import
|
|
19
|
+
import tableStyles from "./styles.module.scss";
|
|
20
20
|
const Table = ({ id, testId, className, children, breakpointConfig = defaultConfig, mode = ModeType.normal, scrollAriaLabel, scrollAriaLabelledById, ...rest }) => {
|
|
21
21
|
const [currentConfig, setCurrentConfig] = useState();
|
|
22
22
|
const [tableWidth, setTableWidth] = useState(0);
|
|
@@ -43,7 +43,7 @@ const Table = ({ id, testId, className, children, breakpointConfig = defaultConf
|
|
|
43
43
|
}, [tableWidth, tableIsVisible]);
|
|
44
44
|
const tableStyle = currentConfig?.variant === ResponsiveTableVariant.centeredoverflow ? getCenteredOverflowTableStyle(parentWidth, tableWidth) : void 0;
|
|
45
45
|
const breakpointClass = getBreakpointClass(currentConfig);
|
|
46
|
-
const tableClass = classNames(
|
|
46
|
+
const tableClass = classNames(tableStyles.table, breakpointClass, className);
|
|
47
47
|
const domRest = omitProps(rest, [
|
|
48
48
|
"breakpoint",
|
|
49
49
|
"variant",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Table: React.FC<Props>"],"sources":["../../../src/components/Table/Table.tsx","../../../src/components/Table/index.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport type { Breakpoint } from '../../hooks/useBreakpoint';\n\nimport { defaultConfig, ModeType, ResponsiveTableVariant } from './constants';\nimport { getCurrentConfig, getBreakpointClass, getCenteredOverflowTableStyle, mapChildrenWithMode, omitProps } from './utils';\nimport { AnalyticsId } from '../../constants';\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useLayoutEvent } from '../../hooks/useLayoutEvent';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport HorizontalScroll from '../HorizontalScroll';\n\nimport styles from './styles.module.scss';\n\nexport interface BreakpointConfig {\n /** Breakpoint at which responsive behaviour will be applied. The table component uses a \"desktop first\" approach. */\n breakpoint: keyof typeof Breakpoint;\n /** Desired behaviour on this breakpoint and all smaller screens. */\n variant: keyof typeof ResponsiveTableVariant;\n /** If variant is horizontallscroll, use a fallback instead of device is not a touch device. */\n fallbackVariant?: keyof typeof ResponsiveTableVariant;\n}\n\nexport interface Props extends Omit<React.ComponentPropsWithoutRef<'table'>, 'style'> {\n /** Unique ID */\n id?: string;\n /** Id used for testing */\n testId?: string;\n /** Customize how the table behaves on various screen widths */\n breakpointConfig?: BreakpointConfig | BreakpointConfig[];\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the content of the table. Use TableHead and TableBody */\n children: React.ReactNode;\n /** For display with less space. Discouraged to use together with interactive elements. */\n mode?: ModeType;\n /** Sets aria-label of the horizontal scroll container. scrollAriaLabel or scrollAriaLabelledById MUST be set if horizontal scrolling is enabled! */\n scrollAriaLabel?: string;\n /** Sets aria-labelledby of the horizontal scroll container. scrollAriaLabel or scrollAriaLabelledById MUST be set if horizontal scrolling is enabled! */\n scrollAriaLabelledById?: string;\n}\n\nexport const Table: React.FC<Props> = ({\n id,\n testId,\n className,\n children,\n breakpointConfig = defaultConfig,\n mode = ModeType.normal,\n scrollAriaLabel,\n scrollAriaLabelledById,\n ...rest\n}) => {\n const [currentConfig, setCurrentConfig] = useState<BreakpointConfig>();\n const [tableWidth, setTableWidth] = useState<number>(0);\n const [parentWidth, setParentWidth] = useState<number>(0);\n const [windowWidth, setWindowWidth] = useState(window.innerWidth);\n const tableRef = useRef<HTMLTableElement>(null);\n const tableIsVisible = useIsVisible(tableRef, 0);\n const breakpoint = useBreakpoint();\n\n useEffect(() => {\n setCurrentConfig(getCurrentConfig(breakpointConfig, breakpoint, tableWidth, windowWidth));\n }, [breakpointConfig, breakpoint, tableWidth, windowWidth]);\n\n useEffect(() => {\n if (\n currentConfig?.variant === ResponsiveTableVariant.centeredoverflow ||\n currentConfig?.variant === ResponsiveTableVariant.horizontalscroll\n ) {\n setTableWidth(tableRef.current?.getBoundingClientRect().width ?? 0);\n }\n if (currentConfig?.variant === ResponsiveTableVariant.centeredoverflow) {\n setParentWidth(tableRef.current?.parentElement?.getBoundingClientRect().width ?? 0);\n }\n }, [currentConfig, breakpoint]);\n\n useLayoutEvent(() => setWindowWidth(window.innerWidth), ['resize'], 100);\n\n useEffect(() => {\n if (tableWidth === 0 && tableIsVisible) {\n setTableWidth(tableRef.current?.getBoundingClientRect().width ?? 0);\n }\n }, [tableWidth, tableIsVisible]);\n\n const tableStyle =\n currentConfig?.variant === ResponsiveTableVariant.centeredoverflow ? getCenteredOverflowTableStyle(parentWidth, tableWidth) : undefined;\n\n const breakpointClass = getBreakpointClass(currentConfig);\n const tableClass = classNames(styles.table, breakpointClass, className);\n const domRest = omitProps(rest as Record<string, unknown>, ['breakpoint', 'variant', 'fallbackVariant', 'headerCategory']);\n\n const table = (\n <table\n className={tableClass}\n id={id}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Table}\n ref={tableRef}\n style={tableStyle}\n {...(domRest as React.ComponentPropsWithoutRef<'table'>)}\n >\n {mapChildrenWithMode(children, mode)}\n </table>\n );\n\n const ariaLabelAttributes = getAriaLabelAttributes({ label: scrollAriaLabel, id: scrollAriaLabelledById });\n\n if (currentConfig?.variant === ResponsiveTableVariant.horizontalscroll) {\n return (\n <HorizontalScroll childWidth={tableWidth} testId=\"horizontal-scroll\" {...ariaLabelAttributes}>\n {table}\n </HorizontalScroll>\n );\n }\n\n return table;\n};\n\nexport default Table;\n","import { Table } from './Table';\n\nexport { TableBody } from './TableBody';\nexport { TableCell } from './TableCell';\nexport { TableExpandedRow } from './TableExpandedRow';\nexport { TableExpanderCell } from './TableExpanderCell';\nexport { TableHead } from './TableHead';\nexport { TableHeadCell } from './TableHeadCell';\nexport { TableRow } from './TableRow';\nexport { SortDirection, HeaderCategory, TextAlign, ResponsiveTableVariant, ModeType, defaultConfig, simpleConfig } from './constants';\n\nexport * from './Table';\nexport * from './utils';\n\nexport default Table;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6CA,MAAaA,SAA0B,EACrC,IACA,QACA,WACA,UACA,mBAAmB,eACnB,OAAO,SAAS,QAChB,iBACA,wBACA,GAAG,WACC;CACJ,MAAM,CAAC,eAAe,oBAAoB,UAA4B;CACtE,MAAM,CAAC,YAAY,iBAAiB,SAAiB,EAAE;CACvD,MAAM,CAAC,aAAa,kBAAkB,SAAiB,EAAE;CACzD,MAAM,CAAC,aAAa,kBAAkB,SAAS,OAAO,WAAW;CACjE,MAAM,WAAW,OAAyB,KAAK;CAC/C,MAAM,iBAAiB,aAAa,UAAU,EAAE;CAChD,MAAM,aAAa,eAAe;AAElC,iBAAgB;AACd,mBAAiB,iBAAiB,kBAAkB,YAAY,YAAY,YAAY,CAAC;IACxF;EAAC;EAAkB;EAAY;EAAY;EAAY,CAAC;AAE3D,iBAAgB;AACd,MACE,eAAe,YAAY,uBAAuB,oBAClD,eAAe,YAAY,uBAAuB,iBAElD,eAAc,SAAS,SAAS,uBAAuB,CAAC,SAAS,EAAE;AAErE,MAAI,eAAe,YAAY,uBAAuB,iBACpD,gBAAe,SAAS,SAAS,eAAe,uBAAuB,CAAC,SAAS,EAAE;IAEpF,CAAC,eAAe,WAAW,CAAC;AAE/B,sBAAqB,eAAe,OAAO,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI;AAExE,iBAAgB;AACd,MAAI,eAAe,KAAK,eACtB,eAAc,SAAS,SAAS,uBAAuB,CAAC,SAAS,EAAE;IAEpE,CAAC,YAAY,eAAe,CAAC;CAEhC,MAAM,aACJ,eAAe,YAAY,uBAAuB,mBAAmB,8BAA8B,aAAa,WAAW,GAAG,KAAA;CAEhI,MAAM,kBAAkB,mBAAmB,cAAc;CACzD,MAAM,aAAa,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","names":["Table: React.FC<Props>"],"sources":["../../../src/components/Table/Table.tsx","../../../src/components/Table/index.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport type { Breakpoint } from '../../hooks/useBreakpoint';\n\nimport { defaultConfig, ModeType, ResponsiveTableVariant } from './constants';\nimport { getCurrentConfig, getBreakpointClass, getCenteredOverflowTableStyle, mapChildrenWithMode, omitProps } from './utils';\nimport { AnalyticsId } from '../../constants';\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useLayoutEvent } from '../../hooks/useLayoutEvent';\nimport { getAriaLabelAttributes } from '../../utils/accessibility';\nimport HorizontalScroll from '../HorizontalScroll';\n\nimport styles from './styles.module.scss';\n\nexport interface BreakpointConfig {\n /** Breakpoint at which responsive behaviour will be applied. The table component uses a \"desktop first\" approach. */\n breakpoint: keyof typeof Breakpoint;\n /** Desired behaviour on this breakpoint and all smaller screens. */\n variant: keyof typeof ResponsiveTableVariant;\n /** If variant is horizontallscroll, use a fallback instead of device is not a touch device. */\n fallbackVariant?: keyof typeof ResponsiveTableVariant;\n}\n\nexport interface Props extends Omit<React.ComponentPropsWithoutRef<'table'>, 'style'> {\n /** Unique ID */\n id?: string;\n /** Id used for testing */\n testId?: string;\n /** Customize how the table behaves on various screen widths */\n breakpointConfig?: BreakpointConfig | BreakpointConfig[];\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the content of the table. Use TableHead and TableBody */\n children: React.ReactNode;\n /** For display with less space. Discouraged to use together with interactive elements. */\n mode?: ModeType;\n /** Sets aria-label of the horizontal scroll container. scrollAriaLabel or scrollAriaLabelledById MUST be set if horizontal scrolling is enabled! */\n scrollAriaLabel?: string;\n /** Sets aria-labelledby of the horizontal scroll container. scrollAriaLabel or scrollAriaLabelledById MUST be set if horizontal scrolling is enabled! */\n scrollAriaLabelledById?: string;\n}\n\nexport const Table: React.FC<Props> = ({\n id,\n testId,\n className,\n children,\n breakpointConfig = defaultConfig,\n mode = ModeType.normal,\n scrollAriaLabel,\n scrollAriaLabelledById,\n ...rest\n}) => {\n const [currentConfig, setCurrentConfig] = useState<BreakpointConfig>();\n const [tableWidth, setTableWidth] = useState<number>(0);\n const [parentWidth, setParentWidth] = useState<number>(0);\n const [windowWidth, setWindowWidth] = useState(window.innerWidth);\n const tableRef = useRef<HTMLTableElement>(null);\n const tableIsVisible = useIsVisible(tableRef, 0);\n const breakpoint = useBreakpoint();\n\n useEffect(() => {\n setCurrentConfig(getCurrentConfig(breakpointConfig, breakpoint, tableWidth, windowWidth));\n }, [breakpointConfig, breakpoint, tableWidth, windowWidth]);\n\n useEffect(() => {\n if (\n currentConfig?.variant === ResponsiveTableVariant.centeredoverflow ||\n currentConfig?.variant === ResponsiveTableVariant.horizontalscroll\n ) {\n setTableWidth(tableRef.current?.getBoundingClientRect().width ?? 0);\n }\n if (currentConfig?.variant === ResponsiveTableVariant.centeredoverflow) {\n setParentWidth(tableRef.current?.parentElement?.getBoundingClientRect().width ?? 0);\n }\n }, [currentConfig, breakpoint]);\n\n useLayoutEvent(() => setWindowWidth(window.innerWidth), ['resize'], 100);\n\n useEffect(() => {\n if (tableWidth === 0 && tableIsVisible) {\n setTableWidth(tableRef.current?.getBoundingClientRect().width ?? 0);\n }\n }, [tableWidth, tableIsVisible]);\n\n const tableStyle =\n currentConfig?.variant === ResponsiveTableVariant.centeredoverflow ? getCenteredOverflowTableStyle(parentWidth, tableWidth) : undefined;\n\n const breakpointClass = getBreakpointClass(currentConfig);\n const tableClass = classNames(styles.table, breakpointClass, className);\n const domRest = omitProps(rest as Record<string, unknown>, ['breakpoint', 'variant', 'fallbackVariant', 'headerCategory']);\n\n const table = (\n <table\n className={tableClass}\n id={id}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Table}\n ref={tableRef}\n style={tableStyle}\n {...(domRest as React.ComponentPropsWithoutRef<'table'>)}\n >\n {mapChildrenWithMode(children, mode)}\n </table>\n );\n\n const ariaLabelAttributes = getAriaLabelAttributes({ label: scrollAriaLabel, id: scrollAriaLabelledById });\n\n if (currentConfig?.variant === ResponsiveTableVariant.horizontalscroll) {\n return (\n <HorizontalScroll childWidth={tableWidth} testId=\"horizontal-scroll\" {...ariaLabelAttributes}>\n {table}\n </HorizontalScroll>\n );\n }\n\n return table;\n};\n\nexport default Table;\n","import { Table } from './Table';\n\nexport { TableBody } from './TableBody';\nexport { TableCell } from './TableCell';\nexport { TableExpandedRow } from './TableExpandedRow';\nexport { TableExpanderCell } from './TableExpanderCell';\nexport { TableHead } from './TableHead';\nexport { TableHeadCell } from './TableHeadCell';\nexport { TableRow } from './TableRow';\nexport { SortDirection, HeaderCategory, TextAlign, ResponsiveTableVariant, ModeType, defaultConfig, simpleConfig } from './constants';\n\nexport * from './Table';\nexport * from './utils';\n\nexport default Table;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6CA,MAAaA,SAA0B,EACrC,IACA,QACA,WACA,UACA,mBAAmB,eACnB,OAAO,SAAS,QAChB,iBACA,wBACA,GAAG,WACC;CACJ,MAAM,CAAC,eAAe,oBAAoB,UAA4B;CACtE,MAAM,CAAC,YAAY,iBAAiB,SAAiB,EAAE;CACvD,MAAM,CAAC,aAAa,kBAAkB,SAAiB,EAAE;CACzD,MAAM,CAAC,aAAa,kBAAkB,SAAS,OAAO,WAAW;CACjE,MAAM,WAAW,OAAyB,KAAK;CAC/C,MAAM,iBAAiB,aAAa,UAAU,EAAE;CAChD,MAAM,aAAa,eAAe;AAElC,iBAAgB;AACd,mBAAiB,iBAAiB,kBAAkB,YAAY,YAAY,YAAY,CAAC;IACxF;EAAC;EAAkB;EAAY;EAAY;EAAY,CAAC;AAE3D,iBAAgB;AACd,MACE,eAAe,YAAY,uBAAuB,oBAClD,eAAe,YAAY,uBAAuB,iBAElD,eAAc,SAAS,SAAS,uBAAuB,CAAC,SAAS,EAAE;AAErE,MAAI,eAAe,YAAY,uBAAuB,iBACpD,gBAAe,SAAS,SAAS,eAAe,uBAAuB,CAAC,SAAS,EAAE;IAEpF,CAAC,eAAe,WAAW,CAAC;AAE/B,sBAAqB,eAAe,OAAO,WAAW,EAAE,CAAC,SAAS,EAAE,IAAI;AAExE,iBAAgB;AACd,MAAI,eAAe,KAAK,eACtB,eAAc,SAAS,SAAS,uBAAuB,CAAC,SAAS,EAAE;IAEpE,CAAC,YAAY,eAAe,CAAC;CAEhC,MAAM,aACJ,eAAe,YAAY,uBAAuB,mBAAmB,8BAA8B,aAAa,WAAW,GAAG,KAAA;CA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