@helsenorge/designsystem-react 9.4.3 → 9.5.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 +1245 -745
- package/HighlightPanel.js +5 -2
- package/HighlightPanel.js.map +1 -1
- package/Label.js +5 -2
- package/Label.js.map +1 -1
- package/PopOver.js +1 -1
- package/PopOver.js.map +1 -1
- package/TabList.js +3 -1
- package/TabList.js.map +1 -1
- package/components/Label/Label.d.ts +1 -1
- package/components/Label/SubLabel.d.ts +2 -0
- package/components/Tabs/TabList/TabItem.d.ts +1 -0
- package/components/Toggle/index.js +16 -16
- package/components/Toggle/index.js.map +1 -1
- package/package.json +2 -2
package/HighlightPanel.js
CHANGED
|
@@ -42,9 +42,9 @@ const HighlightPanel = (props) => {
|
|
|
42
42
|
className
|
|
43
43
|
);
|
|
44
44
|
const renderContent = () => {
|
|
45
|
+
const titleElement = title && /* @__PURE__ */ jsx(Title, { testId: "titleId", htmlMarkup: titleHtmlMarkup, appearance: "title4", children: title });
|
|
45
46
|
if (svgIcon) {
|
|
46
47
|
const iconSize = size === "large" && breakpoint && breakpoint >= Breakpoint.md ? IconSize.Medium : IconSize.Small;
|
|
47
|
-
const titleElement = /* @__PURE__ */ jsx(Title, { testId: "titleId", htmlMarkup: titleHtmlMarkup, appearance: "title4", children: title });
|
|
48
48
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
49
49
|
/* @__PURE__ */ jsxs("div", { className: styles.highlightpanel__icon, children: [
|
|
50
50
|
typeof svgIcon === "string" ? /* @__PURE__ */ jsx(LazyIcon, { iconName: svgIcon, size: iconSize }) : /* @__PURE__ */ jsx(Icon, { svgIcon, size: iconSize }),
|
|
@@ -56,7 +56,10 @@ const HighlightPanel = (props) => {
|
|
|
56
56
|
] })
|
|
57
57
|
] });
|
|
58
58
|
}
|
|
59
|
-
return children
|
|
59
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
60
|
+
title && /* @__PURE__ */ jsx("div", { className: styles.highlightpanel__content, children: /* @__PURE__ */ jsx("div", { children: titleElement }) }),
|
|
61
|
+
children
|
|
62
|
+
] });
|
|
60
63
|
};
|
|
61
64
|
const CustomTag = htmlMarkup;
|
|
62
65
|
const contentWrapperClasses = classNames(styles["highlightpanel__content-wrapper"], contentWrapperClassName);
|
package/HighlightPanel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HighlightPanel.js","sources":["../src/components/HighlightPanel/HighlightPanel.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { useBreakpoint, Breakpoint } from '../..';\nimport { AnalyticsId } from '../../constants';\nimport { PaletteNames } from '../../theme/palette';\nimport Icon, { SvgIcon, IconSize } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\nimport LazyIcon from '../LazyIcon';\nimport Title, { TitleTags } from '../Title';\n\nimport styles from './styles.module.scss';\n\nexport type HighlightPanelColors = Extract<PaletteNames, 'white' | 'neutral' | 'blueberry' | 'cherry'>;\n\nexport enum HighlightPanelSize {\n medium = 'medium',\n large = 'large',\n fluid = 'fluid',\n}\n\nexport type HighlightPanelTags = Exclude<\n keyof HTMLElementTagNameMap,\n 'dir' | 'font' | 'frame' | 'frameset' | 'marquee' | 'applet' | 'basefont' | 'search'\n>;\n\nexport interface HighlightPanelProps {\n /** What's in the box? */\n children: React.ReactNode;\n /** Changes the background color. Default: white */\n color?: HighlightPanelColors;\n /** Changes the size. Default: medium */\n size?: keyof typeof HighlightPanelSize;\n /** Adds an icon to the highlightpanel. */\n svgIcon?: SvgIcon | IconName;\n /** Changes the underlying element. Default: div */\n htmlMarkup?: HighlightPanelTags;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the content-wrapper. Not used for fluid size. */\n contentWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Element that is set after the icon-element in the DOM, often a title-element */\n title?: string;\n /** Markup props for title */\n titleHtmlMarkup?: TitleTags;\n}\n\ninterface WrapperProps {\n children?: React.ReactNode;\n className: string;\n size?: keyof typeof HighlightPanelSize;\n}\n\nconst Wrapper: React.FC<WrapperProps> = ({ className, size, children }) => (\n <div className={className} data-testid={'highlightpanel-wrapper'}>\n <div className={styles.highlightpanel__row}>\n <div className={classNames(styles.highlightpanel__col, size === HighlightPanelSize.medium && styles['highlightpanel__col--offset'])}>\n {children}\n </div>\n </div>\n </div>\n);\n\ninterface ContentWrapperProps {\n children: React.ReactNode;\n className?: string;\n}\n\nconst ContentWrapper: React.FC<ContentWrapperProps> = props => {\n const { children, className } = props;\n const contentWrapperClasses = classNames(styles['highlightpanel__content-wrapper'], className);\n\n return (\n <div className={contentWrapperClasses}>\n <div className={classNames(styles.highlightpanel__row)}>{children}</div>\n </div>\n );\n};\n\nconst HighlightPanel: React.FC<HighlightPanelProps> = props => {\n const {\n children,\n color = 'white',\n size = HighlightPanelSize.medium,\n testId,\n svgIcon,\n htmlMarkup = 'div',\n className,\n contentWrapperClassName,\n title,\n titleHtmlMarkup = 'h2',\n } = props;\n const breakpoint = useBreakpoint();\n\n const containerClassName = classNames(\n styles[`highlightpanel--${color}`],\n styles[`highlightpanel--${size}`],\n svgIcon && styles['highlightpanel--has-icon'],\n { container: size === 'medium' || size === 'large' },\n className\n );\n\n const renderContent = () => {\n if (svgIcon) {\n const iconSize = size === HighlightPanelSize.large && breakpoint && breakpoint >= Breakpoint.md ? IconSize.Medium : IconSize.Small;\n\n
|
|
1
|
+
{"version":3,"file":"HighlightPanel.js","sources":["../src/components/HighlightPanel/HighlightPanel.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { useBreakpoint, Breakpoint } from '../..';\nimport { AnalyticsId } from '../../constants';\nimport { PaletteNames } from '../../theme/palette';\nimport Icon, { SvgIcon, IconSize } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\nimport LazyIcon from '../LazyIcon';\nimport Title, { TitleTags } from '../Title';\n\nimport styles from './styles.module.scss';\n\nexport type HighlightPanelColors = Extract<PaletteNames, 'white' | 'neutral' | 'blueberry' | 'cherry'>;\n\nexport enum HighlightPanelSize {\n medium = 'medium',\n large = 'large',\n fluid = 'fluid',\n}\n\nexport type HighlightPanelTags = Exclude<\n keyof HTMLElementTagNameMap,\n 'dir' | 'font' | 'frame' | 'frameset' | 'marquee' | 'applet' | 'basefont' | 'search'\n>;\n\nexport interface HighlightPanelProps {\n /** What's in the box? */\n children: React.ReactNode;\n /** Changes the background color. Default: white */\n color?: HighlightPanelColors;\n /** Changes the size. Default: medium */\n size?: keyof typeof HighlightPanelSize;\n /** Adds an icon to the highlightpanel. */\n svgIcon?: SvgIcon | IconName;\n /** Changes the underlying element. Default: div */\n htmlMarkup?: HighlightPanelTags;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the content-wrapper. Not used for fluid size. */\n contentWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Element that is set after the icon-element in the DOM, often a title-element */\n title?: string;\n /** Markup props for title */\n titleHtmlMarkup?: TitleTags;\n}\n\ninterface WrapperProps {\n children?: React.ReactNode;\n className: string;\n size?: keyof typeof HighlightPanelSize;\n}\n\nconst Wrapper: React.FC<WrapperProps> = ({ className, size, children }) => (\n <div className={className} data-testid={'highlightpanel-wrapper'}>\n <div className={styles.highlightpanel__row}>\n <div className={classNames(styles.highlightpanel__col, size === HighlightPanelSize.medium && styles['highlightpanel__col--offset'])}>\n {children}\n </div>\n </div>\n </div>\n);\n\ninterface ContentWrapperProps {\n children: React.ReactNode;\n className?: string;\n}\n\nconst ContentWrapper: React.FC<ContentWrapperProps> = props => {\n const { children, className } = props;\n const contentWrapperClasses = classNames(styles['highlightpanel__content-wrapper'], className);\n\n return (\n <div className={contentWrapperClasses}>\n <div className={classNames(styles.highlightpanel__row)}>{children}</div>\n </div>\n );\n};\n\nconst HighlightPanel: React.FC<HighlightPanelProps> = props => {\n const {\n children,\n color = 'white',\n size = HighlightPanelSize.medium,\n testId,\n svgIcon,\n htmlMarkup = 'div',\n className,\n contentWrapperClassName,\n title,\n titleHtmlMarkup = 'h2',\n } = props;\n const breakpoint = useBreakpoint();\n\n const containerClassName = classNames(\n styles[`highlightpanel--${color}`],\n styles[`highlightpanel--${size}`],\n svgIcon && styles['highlightpanel--has-icon'],\n { container: size === 'medium' || size === 'large' },\n className\n );\n\n const renderContent = () => {\n const titleElement = title && (\n <Title testId=\"titleId\" htmlMarkup={titleHtmlMarkup} appearance=\"title4\">\n {title}\n </Title>\n );\n\n if (svgIcon) {\n const iconSize = size === HighlightPanelSize.large && breakpoint && breakpoint >= Breakpoint.md ? IconSize.Medium : IconSize.Small;\n\n return (\n <>\n <div className={styles.highlightpanel__icon}>\n {typeof svgIcon === 'string' ? <LazyIcon iconName={svgIcon} size={iconSize} /> : <Icon svgIcon={svgIcon} size={iconSize} />}\n {title && <div className={styles['mobile']}>{titleElement}</div>}\n </div>\n <div className={styles.highlightpanel__content}>\n {title && (\n <div className={styles['desktop']} aria-hidden=\"true\">\n {titleElement}\n </div>\n )}\n {children}\n </div>\n </>\n );\n }\n\n return (\n <>\n {title && (\n <div className={styles.highlightpanel__content}>\n <div>{titleElement}</div>\n </div>\n )}\n {children}\n </>\n );\n };\n\n const CustomTag = htmlMarkup;\n\n const contentWrapperClasses = classNames(styles['highlightpanel__content-wrapper'], contentWrapperClassName);\n\n if (size === HighlightPanelSize.medium) {\n return (\n <Wrapper className={containerClassName} size={size}>\n <CustomTag className={contentWrapperClasses} data-testid={testId} data-analyticsid={AnalyticsId.HighlightPanel}>\n {renderContent()}\n </CustomTag>\n </Wrapper>\n );\n }\n\n if (size === HighlightPanelSize.large && svgIcon) {\n return (\n <Wrapper className={containerClassName} size={size}>\n <ContentWrapper className={contentWrapperClasses}>\n <CustomTag\n className={classNames(styles.highlightpanel__col, styles['highlightpanel__col--large-with-icon'])}\n data-testid={testId}\n data-analyticsid={AnalyticsId.HighlightPanel}\n >\n {renderContent()}\n </CustomTag>\n </ContentWrapper>\n </Wrapper>\n );\n }\n\n if (size === HighlightPanelSize.large) {\n return (\n <Wrapper className={containerClassName} size={size}>\n <ContentWrapper className={contentWrapperClasses}>\n <CustomTag\n className={classNames(styles.highlightpanel__col, styles['highlightpanel__col--offset'])}\n data-testid={testId}\n data-analyticsid={AnalyticsId.HighlightPanel}\n >\n {renderContent()}\n </CustomTag>\n </ContentWrapper>\n </Wrapper>\n );\n }\n\n if (size === HighlightPanelSize.fluid) {\n return (\n <CustomTag className={containerClassName} data-testid={testId}>\n {renderContent()}\n </CustomTag>\n );\n }\n\n return null;\n};\n\nexport default HighlightPanel;\n"],"names":["HighlightPanelSize"],"mappings":";;;;;;;;;;AAgBY,IAAA,uCAAAA,wBAAL;AACLA,sBAAA,QAAS,IAAA;AACTA,sBAAA,OAAQ,IAAA;AACRA,sBAAA,OAAQ,IAAA;AAHEA,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAwCZ,MAAM,UAAkC,CAAC,EAAE,WAAW,MAAM,SAAA,MAC1D,oBAAC,OAAI,EAAA,WAAsB,eAAa,0BACtC,8BAAC,OAAI,EAAA,WAAW,OAAO,qBACrB,UAAC,oBAAA,OAAA,EAAI,WAAW,WAAW,OAAO,qBAAqB,SAAS,YAA6B,OAAO,6BAA6B,CAAC,GAC/H,SACH,CAAA,EACF,CAAA,GACF;AAQF,MAAM,iBAAgD,CAAS,UAAA;AACvD,QAAA,EAAE,UAAU,UAAA,IAAc;AAChC,QAAM,wBAAwB,WAAW,OAAO,iCAAiC,GAAG,SAAS;AAE7F,SACG,oBAAA,OAAA,EAAI,WAAW,uBACd,UAAC,oBAAA,OAAA,EAAI,WAAW,WAAW,OAAO,mBAAmB,GAAI,SAAS,CAAA,GACpE;AAEJ;AAEA,MAAM,iBAAgD,CAAS,UAAA;AACvD,QAAA;AAAA,IACJ;AAAA,IACA,QAAQ;AAAA,IACR,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb;AAAA,I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AW,OAAO,iCAAiC,GAAG,uBAAuB;AAE3G,MAAI,SAAS,UAA2B;AACtC,+BACG,SAAQ,EAAA,WAAW,oBAAoB,MACtC,8BAAC,WAAU,EAAA,WAAW,uBAAuB,eAAa,QAAQ,oBAAkB,YAAY,gBAC7F,UAAA,gBACH,CAAA,GACF;AAAA,EAAA;AAIA,MAAA,SAAS,WAA4B,SAAS;AAE9C,WAAA,oBAAC,WAAQ,WAAW,oBAAoB,MACtC,UAAC,oBAAA,gBAAA,EAAe,WAAW,uBACzB,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAW,WAAW,OAAO,qBAAqB,OAAO,sCAAsC,CAAC;AAAA,QAChG,eAAa;AAAA,QACb,oBAAkB,YAAY;AAAA,QAE7B,UAAc,cAAA;AAAA,MAAA;AAAA,OAEnB,EACF,CAAA;AAAA,EAAA;AAIJ,MAAI,SAAS,SAA0B;AAEnC,WAAA,oBAAC,WAAQ,WAAW,oBAAoB,MACtC,UAAC,oBAAA,gBAAA,EAAe,WAAW,uBACzB,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAW,WAAW,OAAO,qBAAqB,OAAO,6BAA6B,CAAC;AAAA,QACvF,eAAa;AAAA,QACb,oBAAkB,YAAY;AAAA,QAE7B,UAAc,cAAA;AAAA,MAAA;AAAA,OAEnB,EACF,CAAA;AAAA,EAAA;AAIJ,MAAI,SAAS,SAA0B;AACrC,+BACG,WAAU,EAAA,WAAW,oBAAoB,eAAa,QACpD,2BACH;AAAA,EAAA;AAIG,SAAA;AACT;"}
|
package/Label.js
CHANGED
|
@@ -6,7 +6,7 @@ import { S as Spacer } from "./Spacer.js";
|
|
|
6
6
|
import styles from "./components/Label/styles.module.scss";
|
|
7
7
|
import { isComponent } from "./utils/component.js";
|
|
8
8
|
import { S as StatusDot } from "./StatusDot.js";
|
|
9
|
-
const Sublabel = ({ className, id, onColor, sublabelTexts, testId }) => {
|
|
9
|
+
const Sublabel = ({ children, className, id, onColor, sublabelTexts, testId }) => {
|
|
10
10
|
const mapSublabels = (hideFromScreenReader) => {
|
|
11
11
|
return sublabelTexts && sublabelTexts.map((sublabelText, index) => {
|
|
12
12
|
const labelClasses = classNames(styles.label, styles["label--sublabel"], {
|
|
@@ -20,7 +20,10 @@ const Sublabel = ({ className, id, onColor, sublabelTexts, testId }) => {
|
|
|
20
20
|
const ariaHiddenSublabels = mapSublabels(true);
|
|
21
21
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
22
22
|
/* @__PURE__ */ jsx(Spacer, { size: "3xs" }),
|
|
23
|
-
subLabels && /* @__PURE__ */
|
|
23
|
+
(subLabels || children) && /* @__PURE__ */ jsxs("div", { className, id, "data-testid": testId, "data-analyticsid": AnalyticsId.Sublabel, children: [
|
|
24
|
+
children,
|
|
25
|
+
subLabels
|
|
26
|
+
] }),
|
|
24
27
|
ariaHiddenSublabels && /* @__PURE__ */ jsx("div", { className, "data-testid": testId, children: ariaHiddenSublabels })
|
|
25
28
|
] });
|
|
26
29
|
};
|
package/Label.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.js","sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { LabelText } from './Label';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: FormOnColor;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ className, id, onColor, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['label--sublabel'], {\n [styles['label--semibold']]: sublabelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {subLabels && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {subLabels}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import React, { FunctionComponent } from 'react';\n\nimport cn from 'classnames';\n\nimport { Sublabel, SublabelProps } from './SubLabel';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport Spacer from '../Spacer';\nimport StatusDot, { StatusDotProps } from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'semibold' | 'normal';\n};\n\nexport type LabelTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'span' | 'label' | 'p';\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n children?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Changes the underlying element of the label */\n htmlMarkup?: LabelTags;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: keyof typeof FormOnColor;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\nexport const renderLabel = (label: React.ReactNode, inputId: string, onColor: FormOnColor, markup?: LabelTags): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n htmlMarkup: markup || 'label',\n onColor,\n })\n : typeof label === 'string' && <Label labelTexts={[{ text: label, type: 'semibold' }]} htmlFor={inputId} onColor={onColor} />}\n </>\n );\n};\n\nexport const renderLabelAsParent = (\n label: React.ReactNode,\n children: React.ReactNode,\n inputId: string,\n onColor: FormOnColor,\n labelClassName?: string,\n labelTextClassName?: string,\n sublabelWrapperClassName?: string,\n large?: boolean,\n markup?: LabelTags\n): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n onColor,\n children: children,\n labelClassName: cn(labelClassName, label.props.labelClassName),\n labelTextClassName: labelTextClassName,\n htmlMarkup: markup || 'label',\n sublabelWrapperClassName: sublabelWrapperClassName,\n sublabel: large ? undefined : label.props.sublabel,\n statusDot: large ? undefined : label.props.statusDot,\n })\n : typeof label === 'string' && (\n <Label\n labelTexts={[{ text: label }]}\n htmlFor={inputId}\n onColor={onColor}\n htmlMarkup={markup || 'label'}\n labelClassName={labelClassName}\n labelTextClassName={labelTextClassName}\n sublabelWrapperClassName={sublabelWrapperClassName}\n >\n {children}\n </Label>\n )}\n </>\n );\n};\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n htmlFor,\n htmlMarkup = 'label',\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n onColor = FormOnColor.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(\n styles['label-wrapper'],\n { [styles['label-wrapper--no-bottom-margin']]: hasChildren, [styles['label-wrapper--after-label-children']]: afterLabelChildren },\n className\n );\n\n const mapLabels = (): React.ReactNode => {\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--semibold']]: labelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n const CustomTag = htmlMarkup;\n\n return (\n <div className={labelWrapperClasses}>\n <div>\n <CustomTag className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </CustomTag>\n <div className={sublabelWrapperClassName}>\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n onColor: onColor as FormOnColor,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n onColor: onColor === FormOnColor.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n </div>\n {afterLabelChildren && <div className={styles['after-label-children']}>{afterLabelChildren}</div>}\n </div>\n );\n};\n\nexport default Label;\n"],"names":["cn"],"mappings":";;;;;;;;AAuBa,MAAA,WAAoC,CAAC,EAAE,WAAW,IAAI,SAAS,eAAe,aAAa;AAChG,QAAA,eAAe,CAAC,yBAAoD;AACxE,WACE,iBACA,cAAc,IAAI,CAAC,cAAc,UAAU;AACzC,YAAM,eAA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AAA,QACtD;AAAA,QACA;AAAA,MACF;AAEE,aAAA,oBAAC,UAAK,eAAa,UAAU,sBAAsB,WAAW,cAC3D,UAAU,UAAA,KAAA,GADoE,KAEjF;AAAA,IAAA,CAEH;AAAA,EACH;AACA,QAAM,YAAY;AAGhB,SAAA,qBAAC,OAAI,EAAA,WAAW,qBACd,UAAA;AAAA,IAAA,qBAAC,OACC,EAAA,UAAA;AAAA,MAAA,oBAAC,aAAU,WAAW,gBAAgB,IAAI,SAAS,SAAkB,eAAa,QAAQ,oBAAkB,YAAY,OACtH,UAAC,qBAAA,QAAA,EAAK,WAAW,OAAO,uBAAuB,GAC5C,UAAA;AAAA,QAAA;AAAA,4BACA,QAAK,EAAA,WAAW,OAAO,cAAe,sBAAY,CAAA;AAAA,MAAA,EAAA,CACrD,EACF,CAAA;AAAA,MACA,qBAAC,OAAI,EAAA,WAAW,0BACb,UAAA;AAAA,QAAA,YACC,YAA2B,UAAU,QAAQ,KAC7C,MAAM,aAAa,UAAU;AAAA,UAC3B;AAAA,QAAA,CACD;AAAA,QACF,aAAa,YAA4B,WAAW,SAAS,KAE1D,qBAAA,UAAA,EAAA,UAAA;AAAA,UAAC,oBAAA,QAAA,EAAO,MAAM,MAAO,CAAA;AAAA,UACpB,MAAM,aAAa,WAAW;AAAA,YAC7B,SAAS,YAAY,YAAY,SAAS,WAAW;AAAA,UACtD,CAAA;AAAA,QAAA,EACH,CAAA;AAAA,MAAA,EAEJ,CAAA;AAAA,IAAA,GACF;AAAA,IACC,sBAAuB,oBAAA,OAAA,EAAI,WAAW,OAAO,sBAAsB,GAAI,UAAmB,mBAAA,CAAA;AAAA,EAAA,GAC7F;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Label.js","sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { LabelText } from './Label';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Sets the content of the Sublabel */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: FormOnColor;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ children, className, id, onColor, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['label--sublabel'], {\n [styles['label--semibold']]: sublabelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {(subLabels || children) && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {children}\n {subLabels}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import React, { FunctionComponent } from 'react';\n\nimport cn from 'classnames';\n\nimport { Sublabel, SublabelProps } from './SubLabel';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport Spacer from '../Spacer';\nimport StatusDot, { StatusDotProps } from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'semibold' | 'normal';\n};\n\nexport type LabelTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'span' | 'label' | 'p';\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Sets the content of the Label */\n children?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Changes the underlying element of the label */\n htmlMarkup?: LabelTags;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: keyof typeof FormOnColor;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\nexport const renderLabel = (label: React.ReactNode, inputId: string, onColor: FormOnColor, markup?: LabelTags): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n htmlMarkup: markup || 'label',\n onColor,\n })\n : typeof label === 'string' && <Label labelTexts={[{ text: label, type: 'semibold' }]} htmlFor={inputId} onColor={onColor} />}\n </>\n );\n};\n\nexport const renderLabelAsParent = (\n label: React.ReactNode,\n children: React.ReactNode,\n inputId: string,\n onColor: FormOnColor,\n labelClassName?: string,\n labelTextClassName?: string,\n sublabelWrapperClassName?: string,\n large?: boolean,\n markup?: LabelTags\n): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n onColor,\n children: children,\n labelClassName: cn(labelClassName, label.props.labelClassName),\n labelTextClassName: labelTextClassName,\n htmlMarkup: markup || 'label',\n sublabelWrapperClassName: sublabelWrapperClassName,\n sublabel: large ? undefined : label.props.sublabel,\n statusDot: large ? undefined : label.props.statusDot,\n })\n : typeof label === 'string' && (\n <Label\n labelTexts={[{ text: label }]}\n htmlFor={inputId}\n onColor={onColor}\n htmlMarkup={markup || 'label'}\n labelClassName={labelClassName}\n labelTextClassName={labelTextClassName}\n sublabelWrapperClassName={sublabelWrapperClassName}\n >\n {children}\n </Label>\n )}\n </>\n );\n};\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n htmlFor,\n htmlMarkup = 'label',\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n onColor = FormOnColor.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(\n styles['label-wrapper'],\n { [styles['label-wrapper--no-bottom-margin']]: hasChildren, [styles['label-wrapper--after-label-children']]: afterLabelChildren },\n className\n );\n\n const mapLabels = (): React.ReactNode => {\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--semibold']]: labelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n const CustomTag = htmlMarkup;\n\n return (\n <div className={labelWrapperClasses}>\n <div>\n <CustomTag className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </CustomTag>\n <div className={sublabelWrapperClassName}>\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n onColor: onColor as FormOnColor,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n onColor: onColor === FormOnColor.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n </div>\n {afterLabelChildren && <div className={styles['after-label-children']}>{afterLabelChildren}</div>}\n </div>\n );\n};\n\nexport default Label;\n"],"names":["cn"],"mappings":";;;;;;;;AAyBa,MAAA,WAAoC,CAAC,EAAE,UAAU,WAAW,IAAI,SAAS,eAAe,aAAa;AAC1G,QAAA,eAAe,CAAC,yBAAoD;AACxE,WACE,iBACA,cAAc,IAAI,CAAC,cAAc,UAAU;AACzC,YAAM,eAAeA,WAAG,OAAO,OAAO,OAAO,iBAAiB,GAAG;AAAA,QAC/D,CAAC,OAAO,iBAAiB,CAAC,GAAG,aAAa,SAAS;AAAA,QACnD,CAAC,OAAO,gBAAgB,CAAC,GAAG,YAAY,YAAY;AAAA,MAAA,CACrD;AAEC,aAAA,yBAAyB,aAAa,wBACpC,oBAAC,UAAK,WAAW,cACd,UAAa,aAAA,KAAA,GADoB,KAEpC;AAAA,IAAA,CAGL;AAAA,EAEL;AAEA,QAAM,YAAY,aAAa;AACzB,QAAA,sBAAsB,aAAa,IAAI;AAE7C,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAC,oBAAA,QAAA,EAAO,MAAM,MAAO,CAAA;AAAA,KACnB,aAAa,aACb,qBAAC,OAAI,EAAA,WAAsB,IAAQ,eAAa,QAAQ,oBAAkB,YAAY,UACnF,UAAA;AAAA,MAAA;AAAA,MACA;AAAA,IAAA,GACH;AAAA,IAED,uBACE,oBAAA,OAAA,EAAI,WAAsB,eAAa,QACrC,UACH,oBAAA,CAAA;AAAA,EAAA,GAEJ;AAEJ;ACba,MAAA,eAAe,CAAC,UAAmC;AAC9D,MAAI,eAAe;AAEf,MAAA,YAAwB,OAAO,KAAK,GAAG;AACnC,UAAA,MAAM,WAAW,QAAQ,CAAa,cAAA;AAC1C,s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,MAAM,aAAa,WAAW;AAAA,YAC7B,SAAS,YAAY,YAAY,SAAS,WAAW;AAAA,UACtD,CAAA;AAAA,QAAA,EACH,CAAA;AAAA,MAAA,EAEJ,CAAA;AAAA,IAAA,GACF;AAAA,IACC,sBAAuB,oBAAA,OAAA,EAAI,WAAW,OAAO,sBAAsB,GAAI,UAAmB,mBAAA,CAAA;AAAA,EAAA,GAC7F;AAEJ;"}
|
package/PopOver.js
CHANGED
|
@@ -156,7 +156,7 @@ const PopOver = React.forwardRef((props, ref) => {
|
|
|
156
156
|
const arrowRef = useRef(null);
|
|
157
157
|
const bubbleSize = useSize(bubbleRef);
|
|
158
158
|
const [controllerSize, setControllerSize] = useState();
|
|
159
|
-
const controllerisVisible = useIsVisible(
|
|
159
|
+
const controllerisVisible = useIsVisible(bubbleRef, 0);
|
|
160
160
|
const updateControllerSize = () => {
|
|
161
161
|
var _a;
|
|
162
162
|
setControllerSize((_a = controllerRef.current) == null ? void 0 : _a.getBoundingClientRect());
|
package/PopOver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PopOver.js","sources":["../src/components/PopOver/utils.ts","../src/components/PopOver/PopOver.tsx"],"sourcesContent":["import { CSSProperties } from 'react';\n\nimport { PopOverVariant } from './PopOver';\n\ntype HorizontalPosition = 'left' | 'right' | 'floating';\ntype BubblePosition = 'leftabove' | 'leftbelow' | 'rightabove' | 'rightbelow' | 'floatingabove' | 'floatingbelow';\n\n/** Bredde på hjelpeboble */\nconst BUBBLE_WIDTH_PX = 373;\n/** Hjelpeboblen skal holde avstand til venstre/høyre kant på vinduet */\nconst WINDOW_MARGIN_PX = 12;\n/** Vertikal avstand fra hjelpeboble til kontroller */\nconst BUBBLE_VERTICAL_OFFSET_PX = 16;\n/** Høyde/bredde på pil */\nconst ARROW_WIDTH_PX = 20;\n/** Avstand fra pil til hjelpeboble */\nconst ARROW_VERTICAL_OFFSET_PX = 4;\n/** Pilen skal holde avstand til venstre/høyre kant av hjelpeboblen */\nconst ARROW_HORIZONTAL_MARGIN_PX = 12;\n\n/**\n * Beregn om hjelpeboblen skal vises over eller under kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under/automatisk)\n * @returns Om hjelpeboblen skal vises over eller under\n */\nexport const getVerticalPosition = (\n controllerSize: DOMRect,\n bubbleSize: DOMRect,\n variant: keyof typeof PopOverVariant\n): keyof typeof PopOverVariant => {\n if (variant !== PopOverVariant.positionautomatic) {\n return variant;\n }\n if (controllerSize.top > bubbleSize.height + BUBBLE_VERTICAL_OFFSET_PX) {\n return PopOverVariant.positionabove;\n } else {\n return PopOverVariant.positionbelow;\n }\n};\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerLeftCenterPx = (controllerSize: DOMRect): number => controllerSize.left + controllerSize.width / 2;\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til høyre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerRightCenterPx = (controllerSize: DOMRect): number =>\n document.documentElement.clientWidth - controllerSize.right + controllerSize.width / 2;\n\n/**\n * Finn venstre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Venstre kant av hjelpeboblen i px\n */\nconst getBubbleLeftPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const controllerHorizontalCenterPx = getControllerLeftCenterPx(controllerSize);\n\n return controllerHorizontalCenterPx - bubbleSize.width / 2;\n};\n\n/**\n * Finn høyre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Høyre kant av hjelpeboblen i px\n */\nconst getBubbleRightPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx + bubbleSize.width;\n};\n\n/**\n * Sjekk om venstre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom venstre kant er innenfor vinduet\n */\nconst getBubbleLeftVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx > WINDOW_MARGIN_PX;\n};\n\n/**\n * Sjekk om høyre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom høyre kant er innenfor vinduet\n */\nconst getBubbleRightIsVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleRightPx = getBubbleRightPx(controllerSize, bubbleSize);\n\n return bubbleRightPx < document.documentElement.clientWidth - WINDOW_MARGIN_PX;\n};\n\n/**\n * Finn riktig horisontal plassering til hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns left, right eller floating\n */\nconst getHorizontalPosition = (controllerSize: DOMRect, bubbleSize: DOMRect): HorizontalPosition => {\n if (!getBubbleRightIsVisible(controllerSize, bubbleSize)) {\n return 'right';\n }\n if (!getBubbleLeftVisible(controllerSize, bubbleSize)) {\n return 'left';\n }\n\n return 'floating';\n};\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleAbovePx = (controllerSize: DOMRect, bubbleSize: DOMRect): number =>\n controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - bubbleSize.height;\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises under\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleBelowPx = (controllerSize: DOMRect): number => controllerSize.bottom + BUBBLE_VERTICAL_OFFSET_PX;\n\n/**\n * Finn maks bredde på hjelpeboblen i forhold til vinduet\n * @returns Bredde på hjelpeboblen i px\n */\nconst getBubbleWidth = (): number => document.documentElement.clientWidth - WINDOW_MARGIN_PX * 2;\n\n/**\n * Sjekk om hjelpeboblen har plass i vinduet\n * @returns true dersom det er plass til hjelpeboblen i vinduet\n */\nconst getBubbleFitsInWindow = (): boolean => {\n return document.documentElement.clientWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;\n};\n\n/**\n * Finn vertikal plassering av pilen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @returns \"Top\" for pilen i px\n */\nconst getArrowTopxPx = (controllerSize: DOMRect): number => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - ARROW_VERTICAL_OFFSET_PX;\n\n/**\n * Finn horisontal plassering av pilen i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowLeftPx = (controllerSize: DOMRect): number => getControllerLeftCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn horisontal plassering av pilen\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowRightPx = (controllerSize: DOMRect): number => getControllerRightCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns Beste mulige plassering av hjelpeboblen\n */\nconst getBubblePosition = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof PopOverVariant): BubblePosition => {\n const horizontalPosition = getHorizontalPosition(controllerSize, bubbleSize);\n const verticalPosition = getVerticalPosition(controllerSize, bubbleSize, variant);\n\n if (horizontalPosition === 'left') {\n if (verticalPosition === PopOverVariant.positionabove) {\n return 'leftabove';\n }\n return 'leftbelow';\n }\n\n if (horizontalPosition === 'right') {\n if (verticalPosition === PopOverVariant.positionabove) {\n return 'rightabove';\n }\n return 'rightbelow';\n }\n\n if (verticalPosition === PopOverVariant.positionabove) {\n return 'floatingabove';\n }\n\n return 'floatingbelow';\n};\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer hjelpeboblen riktig\n */\nexport const getBubbleStyle = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof PopOverVariant): CSSProperties => {\n const bubblePosition = getBubblePosition(controllerSize, bubbleSize, variant);\n const bubbleWidth = !getBubbleFitsInWindow() ? getBubbleWidth() : undefined;\n\n if (bubblePosition === 'leftabove') {\n return {\n left: WINDOW_MARGIN_PX,\n top: getBubbleAbovePx(controllerSize, bubbleSize),\n width: bubbleWidth,\n };\n }\n if (bubblePosition === 'leftbelow') {\n return { left: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightabove') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightbelow') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n if (bubblePosition === 'floatingbelow') {\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n};\n\n/**\n * Finn riktig plassering av pilen\n * @param bubbleStyle CSSProperties for hjelpeboblen\n * @param controllerSize DOMRect for kontrolleren\n * @param verticalPosition Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer pilen riktig\n */\nexport const getArrowStyle = (\n bubbleStyle: CSSProperties,\n controllerSize: DOMRect,\n verticalPosition: keyof typeof PopOverVariant\n): CSSProperties => {\n const leftPx = getArrowLeftPx(controllerSize);\n const rightPx = getArrowRightPx(controllerSize);\n const minLeftPx = (bubbleStyle.left as number) + ARROW_HORIZONTAL_MARGIN_PX;\n const minRightPx = (bubbleStyle.right as number) + ARROW_HORIZONTAL_MARGIN_PX;\n\n if (bubbleStyle.right) {\n if (verticalPosition === PopOverVariant.positionabove) {\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: controllerSize.bottom,\n };\n }\n\n if (verticalPosition === PopOverVariant.positionabove) {\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: controllerSize.bottom,\n };\n};\n","import React, { useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { getArrowStyle, getBubbleStyle, getVerticalPosition } from './utils';\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { useInterval } from '../../hooks/useInterval';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useLayoutEvent } from '../../hooks/useLayoutEvent';\nimport { useSize } from '../../hooks/useSize';\nimport { mergeRefs } from '../../utils/refs';\n\nimport styles from './styles.module.scss';\n\nexport enum PopOverVariant {\n positionautomatic = 'positionautomatic',\n positionbelow = 'positionbelow',\n positionabove = 'positionabove',\n}\n\nexport type PopOverRole = 'tooltip';\n\nexport interface PopOverProps {\n /** Id of the PopOver */\n id?: string;\n /** Content shown inside PopOver. Note that if role=\"tooltip\", you must not include interactive/focusable elements. */\n children: React.ReactNode;\n /** Ref for the element the PopOver is placed upon */\n controllerRef: React.RefObject<HTMLElement | SVGSVGElement>;\n /** Ref for the element the PopOver is placed upon */\n popOverRef?: React.RefObject<HTMLDivElement>;\n /** Show the popover. Only applies when role=tooltip. Default: false. */\n show?: boolean;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the arrow element. */\n arrowClassName?: string;\n /** Determines the placement of the popover. Default: automatic positioning. */\n variant?: keyof typeof PopOverVariant;\n /** Sets role of the PopOver element */\n role?: PopOverRole;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Overrides the default z-index of PopOver */\n zIndex?: number;\n}\n\nconst PopOver = React.forwardRef<HTMLDivElement | SVGSVGElement, PopOverProps>((props, ref) => {\n const {\n id,\n children,\n controllerRef,\n popOverRef,\n show = false,\n className = '',\n variant = PopOverVariant.positionautomatic,\n role,\n testId,\n arrowClassName,\n zIndex = ZIndex.PopOver,\n } = props;\n\n const bubbleRef = popOverRef || useRef<HTMLDivElement>(null);\n const arrowRef = useRef<HTMLDivElement>(null);\n const bubbleSize = useSize(bubbleRef);\n const [controllerSize, setControllerSize] = useState<DOMRect>();\n const controllerisVisible = useIsVisible(controllerRef, 0);\n\n const updateControllerSize = (): void => {\n setControllerSize(controllerRef.current?.getBoundingClientRect());\n };\n\n useInterval(updateControllerSize, 500);\n useLayoutEvent(updateControllerSize, ['scroll', 'resize'], 10);\n\n useEffect(() => {\n updateControllerSize();\n }, []);\n\n const isTooltip = role === 'tooltip';\n\n const popOverClasses = classNames(styles.popover, { [styles['popover--visible']]: isTooltip ? show : controllerisVisible }, className);\n const verticalPosition = controllerSize && bubbleSize && getVerticalPosition(controllerSize, bubbleSize, variant);\n const arrowClasses = classNames(styles.popover__arrow, arrowClassName, {\n [styles['popover__arrow--over']]: verticalPosition === PopOverVariant.positionbelow,\n [styles['popover__arrow--under']]: verticalPosition === PopOverVariant.positionabove,\n [styles['popover__arrow--visible']]: isTooltip ? show : controllerisVisible,\n });\n\n const bubbleStyle = controllerSize && bubbleSize && getBubbleStyle(controllerSize, bubbleSize, variant);\n const arrowStyle = bubbleStyle && controllerSize && verticalPosition && getArrowStyle(bubbleStyle, controllerSize, verticalPosition);\n\n return (\n <>\n <div\n id={id}\n ref={mergeRefs([ref, bubbleRef])}\n className={popOverClasses}\n style={{ ...bubbleStyle, zIndex }}\n data-testid={testId}\n data-analyticsid={AnalyticsId.PopOver}\n role={role}\n >\n {children}\n </div>\n <div ref={arrowRef} className={arrowClasses} style={{ ...arrowStyle, zIndex }} />\n </>\n );\n});\n\nPopOver.displayName = 'PopOver';\n\nexport default PopOver;\n"],"names":["PopOverVariant"],"mappings":";;;;;;;;;;AAQA,MAAM,kBAAkB;AAExB,MAAM,mBAAmB;AAEzB,MAAM,4BAA4B;AAElC,MAAM,iBAAiB;AAEvB,MAAM,2BAA2B;AAEjC,MAAM,6BAA6B;AAS5B,MAAM,sBAAsB,CACjC,gBACA,YACA,YACgC;AAC5B,MAAA,YAAY,eAAe,mBAAmB;AACzC,WAAA;AAAA,EAAA;AAET,MAAI,eAAe,MAAM,WAAW,SAAS,2BAA2B;AACtE,WAAO,eAAe;AAAA,EAAA,OACjB;AACL,WAAO,eAAe;AAAA,EAAA;AAE1B;AAOA,MAAM,4BAA4B,CAAC,mBAAoC,eAAe,OAAO,eAAe,QAAQ;AAOpH,MAAM,6BAA6B,CAAC,mBAClC,SAAS,gBAAgB,cAAc,eAAe,QAAQ,eAAe,QAAQ;AAQvF,MAAM,kBAAkB,CAAC,gBAAyB,eAAgC;AAC1E,QAAA,+BAA+B,0BAA0B,cAAc;AAEtE,SAAA,+BAA+B,WAAW,QAAQ;AAC3D;AAQA,MAAM,mBAAmB,CAAC,gBAAyB,eAAgC;AAC3E,QAAA,eAAe,gBAAgB,gBAAgB,UAAU;AAE/D,SAAO,eAAe,WAAW;AACnC;AAQA,MAAM,uBAAuB,CAAC,gBAAyB,eAAiC;AAChF,QAAA,eAAe,gBAAgB,gBAAgB,UAAU;AAE/D,SAAO,eAA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BAAkB,cAAc,oBAAoB,gBAAgB,YAAY,OAAO;AAChH,QAAM,eAAe,WAAW,OAAO,gBAAgB,gBAAgB;AAAA,IACrE,CAAC,OAAO,sBAAsB,CAAC,GAAG,qBAAqB;AAAA,IACvD,CAAC,OAAO,uBAAuB,CAAC,GAAG,qBAAqB;AAAA,IACxD,CAAC,OAAO,yBAAyB,CAAC,GAAG,YAAY,OAAO;AAAA,EAAA,CACzD;AAED,QAAM,cAAc,kBAAkB,cAAc,eAAe,gBAAgB,YAAY,OAAO;AACtG,QAAM,aAAa,eAAe,kBAAkB,oBAAoB,cAAc,aAAa,gBAAgB,gBAAgB;AAEnI,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,KAAK,UAAU,CAAC,KAAK,SAAS,CAAC;AAAA,QAC/B,WAAW;AAAA,QACX,OAAO,EAAE,GAAG,aAAa,OAAO;AAAA,QAChC,eAAa;AAAA,QACb,oBAAkB,YAAY;AAAA,QAC9B;AAAA,QAEC;AAAA,MAAA;AAAA,IACH;AAAA,IACA,oBAAC,OAAI,EAAA,KAAK,UAAU,WAAW,cAAc,OAAO,EAAE,GAAG,YAAY,OAAA,EAAU,CAAA;AAAA,EAAA,GACjF;AAEJ,CAAC;AAED,QAAQ,cAAc;"}
|
|
1
|
+
{"version":3,"file":"PopOver.js","sources":["../src/components/PopOver/utils.ts","../src/components/PopOver/PopOver.tsx"],"sourcesContent":["import { CSSProperties } from 'react';\n\nimport { PopOverVariant } from './PopOver';\n\ntype HorizontalPosition = 'left' | 'right' | 'floating';\ntype BubblePosition = 'leftabove' | 'leftbelow' | 'rightabove' | 'rightbelow' | 'floatingabove' | 'floatingbelow';\n\n/** Bredde på hjelpeboble */\nconst BUBBLE_WIDTH_PX = 373;\n/** Hjelpeboblen skal holde avstand til venstre/høyre kant på vinduet */\nconst WINDOW_MARGIN_PX = 12;\n/** Vertikal avstand fra hjelpeboble til kontroller */\nconst BUBBLE_VERTICAL_OFFSET_PX = 16;\n/** Høyde/bredde på pil */\nconst ARROW_WIDTH_PX = 20;\n/** Avstand fra pil til hjelpeboble */\nconst ARROW_VERTICAL_OFFSET_PX = 4;\n/** Pilen skal holde avstand til venstre/høyre kant av hjelpeboblen */\nconst ARROW_HORIZONTAL_MARGIN_PX = 12;\n\n/**\n * Beregn om hjelpeboblen skal vises over eller under kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under/automatisk)\n * @returns Om hjelpeboblen skal vises over eller under\n */\nexport const getVerticalPosition = (\n controllerSize: DOMRect,\n bubbleSize: DOMRect,\n variant: keyof typeof PopOverVariant\n): keyof typeof PopOverVariant => {\n if (variant !== PopOverVariant.positionautomatic) {\n return variant;\n }\n if (controllerSize.top > bubbleSize.height + BUBBLE_VERTICAL_OFFSET_PX) {\n return PopOverVariant.positionabove;\n } else {\n return PopOverVariant.positionbelow;\n }\n};\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerLeftCenterPx = (controllerSize: DOMRect): number => controllerSize.left + controllerSize.width / 2;\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til høyre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerRightCenterPx = (controllerSize: DOMRect): number =>\n document.documentElement.clientWidth - controllerSize.right + controllerSize.width / 2;\n\n/**\n * Finn venstre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Venstre kant av hjelpeboblen i px\n */\nconst getBubbleLeftPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const controllerHorizontalCenterPx = getControllerLeftCenterPx(controllerSize);\n\n return controllerHorizontalCenterPx - bubbleSize.width / 2;\n};\n\n/**\n * Finn høyre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Høyre kant av hjelpeboblen i px\n */\nconst getBubbleRightPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx + bubbleSize.width;\n};\n\n/**\n * Sjekk om venstre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom venstre kant er innenfor vinduet\n */\nconst getBubbleLeftVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx > WINDOW_MARGIN_PX;\n};\n\n/**\n * Sjekk om høyre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom høyre kant er innenfor vinduet\n */\nconst getBubbleRightIsVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleRightPx = getBubbleRightPx(controllerSize, bubbleSize);\n\n return bubbleRightPx < document.documentElement.clientWidth - WINDOW_MARGIN_PX;\n};\n\n/**\n * Finn riktig horisontal plassering til hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns left, right eller floating\n */\nconst getHorizontalPosition = (controllerSize: DOMRect, bubbleSize: DOMRect): HorizontalPosition => {\n if (!getBubbleRightIsVisible(controllerSize, bubbleSize)) {\n return 'right';\n }\n if (!getBubbleLeftVisible(controllerSize, bubbleSize)) {\n return 'left';\n }\n\n return 'floating';\n};\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleAbovePx = (controllerSize: DOMRect, bubbleSize: DOMRect): number =>\n controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - bubbleSize.height;\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises under\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleBelowPx = (controllerSize: DOMRect): number => controllerSize.bottom + BUBBLE_VERTICAL_OFFSET_PX;\n\n/**\n * Finn maks bredde på hjelpeboblen i forhold til vinduet\n * @returns Bredde på hjelpeboblen i px\n */\nconst getBubbleWidth = (): number => document.documentElement.clientWidth - WINDOW_MARGIN_PX * 2;\n\n/**\n * Sjekk om hjelpeboblen har plass i vinduet\n * @returns true dersom det er plass til hjelpeboblen i vinduet\n */\nconst getBubbleFitsInWindow = (): boolean => {\n return document.documentElement.clientWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;\n};\n\n/**\n * Finn vertikal plassering av pilen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @returns \"Top\" for pilen i px\n */\nconst getArrowTopxPx = (controllerSize: DOMRect): number => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - ARROW_VERTICAL_OFFSET_PX;\n\n/**\n * Finn horisontal plassering av pilen i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowLeftPx = (controllerSize: DOMRect): number => getControllerLeftCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn horisontal plassering av pilen\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowRightPx = (controllerSize: DOMRect): number => getControllerRightCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns Beste mulige plassering av hjelpeboblen\n */\nconst getBubblePosition = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof PopOverVariant): BubblePosition => {\n const horizontalPosition = getHorizontalPosition(controllerSize, bubbleSize);\n const verticalPosition = getVerticalPosition(controllerSize, bubbleSize, variant);\n\n if (horizontalPosition === 'left') {\n if (verticalPosition === PopOverVariant.positionabove) {\n return 'leftabove';\n }\n return 'leftbelow';\n }\n\n if (horizontalPosition === 'right') {\n if (verticalPosition === PopOverVariant.positionabove) {\n return 'rightabove';\n }\n return 'rightbelow';\n }\n\n if (verticalPosition === PopOverVariant.positionabove) {\n return 'floatingabove';\n }\n\n return 'floatingbelow';\n};\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer hjelpeboblen riktig\n */\nexport const getBubbleStyle = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof PopOverVariant): CSSProperties => {\n const bubblePosition = getBubblePosition(controllerSize, bubbleSize, variant);\n const bubbleWidth = !getBubbleFitsInWindow() ? getBubbleWidth() : undefined;\n\n if (bubblePosition === 'leftabove') {\n return {\n left: WINDOW_MARGIN_PX,\n top: getBubbleAbovePx(controllerSize, bubbleSize),\n width: bubbleWidth,\n };\n }\n if (bubblePosition === 'leftbelow') {\n return { left: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightabove') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightbelow') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n if (bubblePosition === 'floatingbelow') {\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n};\n\n/**\n * Finn riktig plassering av pilen\n * @param bubbleStyle CSSProperties for hjelpeboblen\n * @param controllerSize DOMRect for kontrolleren\n * @param verticalPosition Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer pilen riktig\n */\nexport const getArrowStyle = (\n bubbleStyle: CSSProperties,\n controllerSize: DOMRect,\n verticalPosition: keyof typeof PopOverVariant\n): CSSProperties => {\n const leftPx = getArrowLeftPx(controllerSize);\n const rightPx = getArrowRightPx(controllerSize);\n const minLeftPx = (bubbleStyle.left as number) + ARROW_HORIZONTAL_MARGIN_PX;\n const minRightPx = (bubbleStyle.right as number) + ARROW_HORIZONTAL_MARGIN_PX;\n\n if (bubbleStyle.right) {\n if (verticalPosition === PopOverVariant.positionabove) {\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: controllerSize.bottom,\n };\n }\n\n if (verticalPosition === PopOverVariant.positionabove) {\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: controllerSize.bottom,\n };\n};\n","import React, { useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { getArrowStyle, getBubbleStyle, getVerticalPosition } from './utils';\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { useInterval } from '../../hooks/useInterval';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useLayoutEvent } from '../../hooks/useLayoutEvent';\nimport { useSize } from '../../hooks/useSize';\nimport { mergeRefs } from '../../utils/refs';\n\nimport styles from './styles.module.scss';\n\nexport enum PopOverVariant {\n positionautomatic = 'positionautomatic',\n positionbelow = 'positionbelow',\n positionabove = 'positionabove',\n}\n\nexport type PopOverRole = 'tooltip';\n\nexport interface PopOverProps {\n /** Id of the PopOver */\n id?: string;\n /** Content shown inside PopOver. Note that if role=\"tooltip\", you must not include interactive/focusable elements. */\n children: React.ReactNode;\n /** Ref for the element the PopOver is placed upon */\n controllerRef: React.RefObject<HTMLElement | SVGSVGElement>;\n /** Ref for the element the PopOver is placed upon */\n popOverRef?: React.RefObject<HTMLDivElement>;\n /** Show the popover. Only applies when role=tooltip. Default: false. */\n show?: boolean;\n /** Adds custom classes to the element. */\n className?: string;\n /** Adds custom classes to the arrow element. */\n arrowClassName?: string;\n /** Determines the placement of the popover. Default: automatic positioning. */\n variant?: keyof typeof PopOverVariant;\n /** Sets role of the PopOver element */\n role?: PopOverRole;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Overrides the default z-index of PopOver */\n zIndex?: number;\n}\n\nconst PopOver = React.forwardRef<HTMLDivElement | SVGSVGElement, PopOverProps>((props, ref) => {\n const {\n id,\n children,\n controllerRef,\n popOverRef,\n show = false,\n className = '',\n variant = PopOverVariant.positionautomatic,\n role,\n testId,\n arrowClassName,\n zIndex = ZIndex.PopOver,\n } = props;\n\n const bubbleRef = popOverRef || useRef<HTMLDivElement>(null);\n const arrowRef = useRef<HTMLDivElement>(null);\n const bubbleSize = useSize(bubbleRef);\n const [controllerSize, setControllerSize] = useState<DOMRect>();\n const controllerisVisible = useIsVisible(bubbleRef, 0);\n\n const updateControllerSize = (): void => {\n setControllerSize(controllerRef.current?.getBoundingClientRect());\n };\n\n useInterval(updateControllerSize, 500);\n useLayoutEvent(updateControllerSize, ['scroll', 'resize'], 10);\n\n useEffect(() => {\n updateControllerSize();\n }, []);\n\n const isTooltip = role === 'tooltip';\n\n const popOverClasses = classNames(styles.popover, { [styles['popover--visible']]: isTooltip ? show : controllerisVisible }, className);\n const verticalPosition = controllerSize && bubbleSize && getVerticalPosition(controllerSize, bubbleSize, variant);\n const arrowClasses = classNames(styles.popover__arrow, arrowClassName, {\n [styles['popover__arrow--over']]: verticalPosition === PopOverVariant.positionbelow,\n [styles['popover__arrow--under']]: verticalPosition === PopOverVariant.positionabove,\n [styles['popover__arrow--visible']]: isTooltip ? show : controllerisVisible,\n });\n\n const bubbleStyle = controllerSize && bubbleSize && getBubbleStyle(controllerSize, bubbleSize, variant);\n const arrowStyle = bubbleStyle && controllerSize && verticalPosition && getArrowStyle(bubbleStyle, controllerSize, verticalPosition);\n\n return (\n <>\n <div\n id={id}\n ref={mergeRefs([ref, bubbleRef])}\n className={popOverClasses}\n style={{ ...bubbleStyle, zIndex }}\n data-testid={testId}\n data-analyticsid={AnalyticsId.PopOver}\n role={role}\n >\n {children}\n </div>\n <div ref={arrowRef} className={arrowClasses} style={{ ...arrowStyle, zIndex }} />\n </>\n );\n});\n\nPopOver.displayName = 'PopOver';\n\nexport default PopOver;\n"],"names":["PopOverVariant"],"mappings":";;;;;;;;;;AAQA,MAAM,kBAAkB;AAExB,MAAM,mBAAmB;AAEzB,MAAM,4BAA4B;AAElC,MAAM,iBAAiB;AAEvB,MAAM,2BAA2B;AAEjC,MAAM,6BAA6B;AAS5B,MAAM,sBAAsB,CACjC,gBACA,YACA,YACgC;AAC5B,MAAA,YAAY,eAAe,mBAAmB;AACzC,WAAA;AAAA,EAAA;AAET,MAAI,eAAe,MAAM,WAAW,SAAS,2BAA2B;AACtE,WAAO,eAAe;AAAA,EAAA,OACjB;AACL,WAAO,eAAe;AAAA,EAAA;AAE1B;AAOA,MAAM,4BAA4B,CAAC,mBAAoC,eAAe,OAAO,eAAe,QAAQ;AAOpH,MAAM,6BAA6B,CAAC,mBAClC,SAAS,gBAAgB,cAAc,eAAe,QAAQ,eAAe,QAAQ;AAQvF,MAAM,kBAAkB,CAAC,gBAAyB,eAAgC;AAC1E,QAAA,+BAA+B,0BAA0B,cAAc;AAEtE,SAAA,+BAA+B,WAAW,QAAQ;AAC3D;AAQA,MAAM,mBAAmB,CAAC,gBAAyB,eAAgC;A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B,GAAG,EAAE;AAEL,QAAM,YAAY,SAAS;AAE3B,QAAM,iBAAiB,WAAW,OAAO,SAAS,EAAE,CAAC,OAAO,kBAAkB,CAAC,GAAG,YAAY,OAAO,oBAAA,GAAuB,SAAS;AACrI,QAAM,mBAAmB,kBAAkB,cAAc,oBAAoB,gBAAgB,YAAY,OAAO;AAChH,QAAM,eAAe,WAAW,OAAO,gBAAgB,gBAAgB;AAAA,IACrE,CAAC,OAAO,sBAAsB,CAAC,GAAG,qBAAqB;AAAA,IACvD,CAAC,OAAO,uBAAuB,CAAC,GAAG,qBAAqB;AAAA,IACxD,CAAC,OAAO,yBAAyB,CAAC,GAAG,YAAY,OAAO;AAAA,EAAA,CACzD;AAED,QAAM,cAAc,kBAAkB,cAAc,eAAe,gBAAgB,YAAY,OAAO;AACtG,QAAM,aAAa,eAAe,kBAAkB,oBAAoB,cAAc,aAAa,gBAAgB,gBAAgB;AAEnI,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA,KAAK,UAAU,CAAC,KAAK,SAAS,CAAC;AAAA,QAC/B,WAAW;AAAA,QACX,OAAO,EAAE,GAAG,aAAa,OAAO;AAAA,QAChC,eAAa;AAAA,QACb,oBAAkB,YAAY;AAAA,QAC9B;AAAA,QAEC;AAAA,MAAA;AAAA,IACH;AAAA,IACA,oBAAC,OAAI,EAAA,KAAK,UAAU,WAAW,cAAc,OAAO,EAAE,GAAG,YAAY,OAAA,EAAU,CAAA;AAAA,EAAA,GACjF;AAEJ,CAAC;AAED,QAAQ,cAAc;"}
|
package/TabList.js
CHANGED
|
@@ -32,7 +32,7 @@ const TabItem = (props) => {
|
|
|
32
32
|
};
|
|
33
33
|
const itemRef = useRef(null);
|
|
34
34
|
useEffect(() => {
|
|
35
|
-
if (isSelected) {
|
|
35
|
+
if (isSelected && props.tabListVisible) {
|
|
36
36
|
scrollToTab(props.index);
|
|
37
37
|
}
|
|
38
38
|
}, [isSelected]);
|
|
@@ -82,6 +82,7 @@ const TabList = (props) => {
|
|
|
82
82
|
const lastTab = tabRefs.current && tabRefs.current[tabRefs.current.length - 1];
|
|
83
83
|
const firstTabVisible = useIsVisible(firstTab);
|
|
84
84
|
const lastTabVisible = useIsVisible(lastTab);
|
|
85
|
+
const tabListVisible = useIsVisible(listRef);
|
|
85
86
|
const shouldShowFadeStart = () => {
|
|
86
87
|
return !firstTabVisible && selectedTab !== 0;
|
|
87
88
|
};
|
|
@@ -105,6 +106,7 @@ const TabList = (props) => {
|
|
|
105
106
|
TabItem,
|
|
106
107
|
{
|
|
107
108
|
tabRefs,
|
|
109
|
+
tabListVisible,
|
|
108
110
|
index,
|
|
109
111
|
selectedTab,
|
|
110
112
|
onTabListClick,
|
package/TabList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TabList.js","sources":["../src/components/Tabs/Tab.tsx","../src/components/Tabs/TabList/TabItem.tsx","../src/components/Tabs/TabList/TabList.tsx"],"sourcesContent":["import React from 'react';\n\nimport { SvgIcon } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\n\nexport interface TabProps {\n /** Sets the tab panel content */\n children?: React.ReactNode;\n /** Optional icon on the tab */\n icon?: SvgIcon | IconName;\n /** Called when tab is selected */\n onTabClick?: (index: number) => void;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Title on the tab */\n title?: string;\n}\n\nconst Tab: React.FC<TabProps> = props => {\n return <>{props.children ?? null}</>;\n};\n\nexport default Tab;\n","import React, { useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { palette } from '../../../theme/palette';\nimport Icon, { IconSize } from '../../Icon';\nimport { IconName } from '../../Icons/IconNames';\nimport LazyIcon from '../../LazyIcon';\nimport { TabProps } from '../Tab';\nimport { TabsColors } from '../Tabs';\n\nimport styles from './styles.module.scss';\n\ninterface TabItemProps {\n tabProps: TabProps;\n index: number;\n color: TabsColors;\n selectedTab: number;\n tabRefs: React.MutableRefObject<React.RefObject<HTMLButtonElement>[] | null | undefined>;\n onTabListClick: (index: number) => void;\n}\n\nconst TabItem: React.FC<TabItemProps> = props => {\n const isSelected = props.index === props.selectedTab;\n const { title, onTabClick, icon, testId } = props.tabProps;\n const handleClick = (): void => {\n onTabClick && onTabClick(props.index);\n props.onTabListClick(props.index);\n scrollToTab(props.index);\n };\n const tabButtonClasses = classNames(styles['tab-list__tab'], styles[`tab-list__tab--${props.color}`], {\n [styles['tab-list__tab--selected']]: isSelected,\n [styles['tab-list__tab--not-selected']]: !isSelected,\n });\n\n const currentRef = props.tabRefs.current && props.tabRefs.current[props.index];\n\n const scrollToTab = (index: number): void => {\n const currentRef = props.tabRefs.current && props.tabRefs.current[index];\n currentRef?.current?.scrollIntoView && currentRef?.current?.scrollIntoView({ behavior: 'smooth', inline: 'nearest', block: 'nearest' });\n };\n\n const itemRef = useRef<HTMLLIElement>(null);\n\n useEffect(() => {\n if (isSelected) {\n scrollToTab(props.index);\n }\n }, [isSelected]);\n\n return (\n <li role=\"presentation\" ref={itemRef}>\n <button\n role=\"tab\"\n aria-selected={isSelected}\n onClick={handleClick}\n className={tabButtonClasses}\n data-testid={testId}\n ref={currentRef as React.RefObject<HTMLButtonElement>}\n style={{\n borderBottom: isSelected\n ? `2px solid var(--color-base-background-${props.color})`\n : '1px solid var(--color-action-border-onlight-focus)',\n }}\n >\n <span className={styles['tab-list__tab__title-and-icon']}>\n {icon &&\n (typeof icon === 'string' ? (\n <LazyIcon\n iconName={icon as IconName}\n size={IconSize.XSmall}\n color={isSelected ? palette[`black`] : palette['blueberry500']}\n />\n ) : (\n <Icon svgIcon={icon} size={IconSize.XSmall} color={isSelected ? palette[`black`] : palette['blueberry500']} />\n ))}\n {title}\n </span>\n </button>\n </li>\n );\n};\n\nexport default TabItem;\n","import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport TabItem from './TabItem';\nimport { useIsVisible } from '../../../hooks/useIsVisible';\nimport { useRovingFocus } from '../../../hooks/useRovingFocus';\nimport { isComponent } from '../../../utils/component';\nimport Tab, { TabProps } from '../Tab';\nimport { TabsColors, TabsOnColor } from '../Tabs';\n\nimport styles from './styles.module.scss';\ninterface TabListProps {\n children: React.ReactNode;\n onTabListClick: (index: number) => void;\n selectedTab: number;\n color: TabsColors;\n onColor: TabsOnColor;\n}\n\nconst TabList: React.FC<TabListProps> = props => {\n const { selectedTab, onTabListClick, children, color, onColor } = props;\n\n const listRef = useRef<HTMLUListElement>(null);\n\n const tabRefs = useRef(React.Children.map(children, () => React.createRef<HTMLButtonElement>()) || []);\n useRovingFocus(onTabListClick, tabRefs, listRef, true);\n\n const tablistClasses = classNames(styles['tab-list'], styles[`tab-list--${onColor}`]);\n\n const getBackgroundColor = (onColor: TabsOnColor): string => {\n switch (onColor) {\n case 'onwhite':\n return 'var(--color-base-background-white)';\n case 'onblueberry':\n return 'var(--color-base-background-blueberry)';\n case 'onneutral':\n return 'var(--color-base-background-neutral)';\n }\n };\n const firstTab = tabRefs.current && tabRefs.current[0];\n const lastTab = tabRefs.current && tabRefs.current[tabRefs.current.length - 1];\n\n const firstTabVisible = useIsVisible(firstTab);\n const lastTabVisible = useIsVisible(lastTab);\n\n const shouldShowFadeStart = (): boolean => {\n return !firstTabVisible && selectedTab !== 0;\n };\n\n const shouldShowFadeEnd = (): boolean => {\n return !lastTabVisible && selectedTab !== tabRefs.current.length - 1;\n };\n\n return (\n <div>\n <div\n className={classNames(styles['tab-list__fade-start'])}\n style={{\n display: shouldShowFadeStart() ? 'block' : 'none',\n backgroundColor: `${getBackgroundColor(onColor)}`,\n }}\n ></div>\n <ul className={tablistClasses} ref={listRef} role=\"tablist\" aria-orientation=\"horizontal\">\n {React.Children.map(children, (child, index) => {\n if (isComponent<TabProps>(child, Tab)) {\n return (\n <TabItem\n tabRefs={tabRefs}\n key={child.props.title}\n index={index}\n selectedTab={selectedTab}\n onTabListClick={onTabListClick}\n tabProps={child.props}\n color={color}\n />\n );\n }\n return null;\n })}\n </ul>\n <div\n className={classNames(styles['tab-list__fade-end'])}\n style={{\n display: shouldShowFadeEnd() ? 'block' : 'none',\n backgroundColor: `${getBackgroundColor(onColor)}`,\n }}\n ></div>\n <div className={classNames(styles['tab-list__border'])}></div>\n </div>\n );\n};\n\nexport default TabList;\n"],"names":["currentRef","onColor"],"mappings":";;;;;;;;;;;AAkBA,MAAM,MAA0B,CAAS,UAAA;AAChC,SAAA,oBAAA,UAAA,EAAG,UAAM,MAAA,YAAY,MAAK;AACnC;
|
|
1
|
+
{"version":3,"file":"TabList.js","sources":["../src/components/Tabs/Tab.tsx","../src/components/Tabs/TabList/TabItem.tsx","../src/components/Tabs/TabList/TabList.tsx"],"sourcesContent":["import React from 'react';\n\nimport { SvgIcon } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\n\nexport interface TabProps {\n /** Sets the tab panel content */\n children?: React.ReactNode;\n /** Optional icon on the tab */\n icon?: SvgIcon | IconName;\n /** Called when tab is selected */\n onTabClick?: (index: number) => void;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Title on the tab */\n title?: string;\n}\n\nconst Tab: React.FC<TabProps> = props => {\n return <>{props.children ?? null}</>;\n};\n\nexport default Tab;\n","import React, { useEffect, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { palette } from '../../../theme/palette';\nimport Icon, { IconSize } from '../../Icon';\nimport { IconName } from '../../Icons/IconNames';\nimport LazyIcon from '../../LazyIcon';\nimport { TabProps } from '../Tab';\nimport { TabsColors } from '../Tabs';\n\nimport styles from './styles.module.scss';\n\ninterface TabItemProps {\n tabProps: TabProps;\n index: number;\n color: TabsColors;\n selectedTab: number;\n tabRefs: React.MutableRefObject<React.RefObject<HTMLButtonElement>[] | null | undefined>;\n tabListVisible: boolean;\n onTabListClick: (index: number) => void;\n}\n\nconst TabItem: React.FC<TabItemProps> = props => {\n const isSelected = props.index === props.selectedTab;\n const { title, onTabClick, icon, testId } = props.tabProps;\n const handleClick = (): void => {\n onTabClick && onTabClick(props.index);\n props.onTabListClick(props.index);\n scrollToTab(props.index);\n };\n const tabButtonClasses = classNames(styles['tab-list__tab'], styles[`tab-list__tab--${props.color}`], {\n [styles['tab-list__tab--selected']]: isSelected,\n [styles['tab-list__tab--not-selected']]: !isSelected,\n });\n\n const currentRef = props.tabRefs.current && props.tabRefs.current[props.index];\n\n const scrollToTab = (index: number): void => {\n const currentRef = props.tabRefs.current && props.tabRefs.current[index];\n currentRef?.current?.scrollIntoView && currentRef?.current?.scrollIntoView({ behavior: 'smooth', inline: 'nearest', block: 'nearest' });\n };\n\n const itemRef = useRef<HTMLLIElement>(null);\n\n useEffect(() => {\n if (isSelected && props.tabListVisible) {\n scrollToTab(props.index);\n }\n }, [isSelected]);\n\n return (\n <li role=\"presentation\" ref={itemRef}>\n <button\n role=\"tab\"\n aria-selected={isSelected}\n onClick={handleClick}\n className={tabButtonClasses}\n data-testid={testId}\n ref={currentRef as React.RefObject<HTMLButtonElement>}\n style={{\n borderBottom: isSelected\n ? `2px solid var(--color-base-background-${props.color})`\n : '1px solid var(--color-action-border-onlight-focus)',\n }}\n >\n <span className={styles['tab-list__tab__title-and-icon']}>\n {icon &&\n (typeof icon === 'string' ? (\n <LazyIcon\n iconName={icon as IconName}\n size={IconSize.XSmall}\n color={isSelected ? palette[`black`] : palette['blueberry500']}\n />\n ) : (\n <Icon svgIcon={icon} size={IconSize.XSmall} color={isSelected ? palette[`black`] : palette['blueberry500']} />\n ))}\n {title}\n </span>\n </button>\n </li>\n );\n};\n\nexport default TabItem;\n","import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport TabItem from './TabItem';\nimport { useIsVisible } from '../../../hooks/useIsVisible';\nimport { useRovingFocus } from '../../../hooks/useRovingFocus';\nimport { isComponent } from '../../../utils/component';\nimport Tab, { TabProps } from '../Tab';\nimport { TabsColors, TabsOnColor } from '../Tabs';\n\nimport styles from './styles.module.scss';\ninterface TabListProps {\n children: React.ReactNode;\n onTabListClick: (index: number) => void;\n selectedTab: number;\n color: TabsColors;\n onColor: TabsOnColor;\n}\n\nconst TabList: React.FC<TabListProps> = props => {\n const { selectedTab, onTabListClick, children, color, onColor } = props;\n\n const listRef = useRef<HTMLUListElement>(null);\n\n const tabRefs = useRef(React.Children.map(children, () => React.createRef<HTMLButtonElement>()) || []);\n useRovingFocus(onTabListClick, tabRefs, listRef, true);\n\n const tablistClasses = classNames(styles['tab-list'], styles[`tab-list--${onColor}`]);\n\n const getBackgroundColor = (onColor: TabsOnColor): string => {\n switch (onColor) {\n case 'onwhite':\n return 'var(--color-base-background-white)';\n case 'onblueberry':\n return 'var(--color-base-background-blueberry)';\n case 'onneutral':\n return 'var(--color-base-background-neutral)';\n }\n };\n const firstTab = tabRefs.current && tabRefs.current[0];\n const lastTab = tabRefs.current && tabRefs.current[tabRefs.current.length - 1];\n\n const firstTabVisible = useIsVisible(firstTab);\n const lastTabVisible = useIsVisible(lastTab);\n const tabListVisible = useIsVisible(listRef);\n\n const shouldShowFadeStart = (): boolean => {\n return !firstTabVisible && selectedTab !== 0;\n };\n\n const shouldShowFadeEnd = (): boolean => {\n return !lastTabVisible && selectedTab !== tabRefs.current.length - 1;\n };\n\n return (\n <div>\n <div\n className={classNames(styles['tab-list__fade-start'])}\n style={{\n display: shouldShowFadeStart() ? 'block' : 'none',\n backgroundColor: `${getBackgroundColor(onColor)}`,\n }}\n ></div>\n <ul className={tablistClasses} ref={listRef} role=\"tablist\" aria-orientation=\"horizontal\">\n {React.Children.map(children, (child, index) => {\n if (isComponent<TabProps>(child, Tab)) {\n return (\n <TabItem\n tabRefs={tabRefs}\n tabListVisible={tabListVisible}\n key={child.props.title}\n index={index}\n selectedTab={selectedTab}\n onTabListClick={onTabListClick}\n tabProps={child.props}\n color={color}\n />\n );\n }\n return null;\n })}\n </ul>\n <div\n className={classNames(styles['tab-list__fade-end'])}\n style={{\n display: shouldShowFadeEnd() ? 'block' : 'none',\n backgroundColor: `${getBackgroundColor(onColor)}`,\n }}\n ></div>\n <div className={classNames(styles['tab-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- discourage use of this */
|
|
11
11
|
afterLabelChildren?: React.ReactNode;
|
|
12
|
-
/**
|
|
12
|
+
/** Sets the content of the Label */
|
|
13
13
|
children?: React.ReactNode;
|
|
14
14
|
/** Adds custom classes to the label tag. */
|
|
15
15
|
labelClassName?: string;
|
|
@@ -2,6 +2,8 @@ import { default as React } from 'react';
|
|
|
2
2
|
import { LabelText } from './Label';
|
|
3
3
|
import { FormOnColor } from '../../constants';
|
|
4
4
|
export interface SublabelProps {
|
|
5
|
+
/** Sets the content of the Sublabel */
|
|
6
|
+
children?: React.ReactNode;
|
|
5
7
|
/** Adds custom classes to the element. */
|
|
6
8
|
className?: string;
|
|
7
9
|
/** id that is placed on the wrapper */
|
|
@@ -7,6 +7,7 @@ interface TabItemProps {
|
|
|
7
7
|
color: TabsColors;
|
|
8
8
|
selectedTab: number;
|
|
9
9
|
tabRefs: React.MutableRefObject<React.RefObject<HTMLButtonElement>[] | null | undefined>;
|
|
10
|
+
tabListVisible: boolean;
|
|
10
11
|
onTabListClick: (index: number) => void;
|
|
11
12
|
}
|
|
12
13
|
declare const TabItem: React.FC<TabItemProps>;
|
|
@@ -2450,7 +2450,7 @@ class MotionValue {
|
|
|
2450
2450
|
* @internal
|
|
2451
2451
|
*/
|
|
2452
2452
|
constructor(init, options = {}) {
|
|
2453
|
-
this.version = "11.
|
|
2453
|
+
this.version = "11.14.3";
|
|
2454
2454
|
this.canTrackVelocity = null;
|
|
2455
2455
|
this.events = {};
|
|
2456
2456
|
this.updateAndNotify = (v, render = true) => {
|
|
@@ -2783,20 +2783,6 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
2783
2783
|
}
|
|
2784
2784
|
return animations;
|
|
2785
2785
|
}
|
|
2786
|
-
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
2787
|
-
var _a;
|
|
2788
|
-
if (elementOrSelector instanceof Element) {
|
|
2789
|
-
return [elementOrSelector];
|
|
2790
|
-
} else if (typeof elementOrSelector === "string") {
|
|
2791
|
-
let root = document;
|
|
2792
|
-
if (scope) {
|
|
2793
|
-
root = scope.current;
|
|
2794
|
-
}
|
|
2795
|
-
const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
|
|
2796
|
-
return elements ? Array.from(elements) : [];
|
|
2797
|
-
}
|
|
2798
|
-
return Array.from(elementOrSelector);
|
|
2799
|
-
}
|
|
2800
2786
|
const createAxis = () => ({ min: 0, max: 0 });
|
|
2801
2787
|
const createBox = () => ({
|
|
2802
2788
|
x: createAxis(),
|
|
@@ -2832,6 +2818,20 @@ function animateSingleValue(value, keyframes2, options) {
|
|
|
2832
2818
|
motionValue$1.start(animateMotionValue("", motionValue$1, keyframes2, options));
|
|
2833
2819
|
return motionValue$1.animation;
|
|
2834
2820
|
}
|
|
2821
|
+
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
2822
|
+
var _a;
|
|
2823
|
+
if (elementOrSelector instanceof Element) {
|
|
2824
|
+
return [elementOrSelector];
|
|
2825
|
+
} else if (typeof elementOrSelector === "string") {
|
|
2826
|
+
let root = document;
|
|
2827
|
+
if (scope) {
|
|
2828
|
+
root = scope.current;
|
|
2829
|
+
}
|
|
2830
|
+
const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
|
|
2831
|
+
return elements ? Array.from(elements) : [];
|
|
2832
|
+
}
|
|
2833
|
+
return Array.from(elementOrSelector);
|
|
2834
|
+
}
|
|
2835
2835
|
const isBrowser = typeof window !== "undefined";
|
|
2836
2836
|
function isControllingVariants(props) {
|
|
2837
2837
|
return isAnimationControls(props.animate) || variantProps.some((name) => isVariantLabel(props[name]));
|
|
@@ -3098,7 +3098,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
3098
3098
|
if (isMotionValue(nextValue)) {
|
|
3099
3099
|
element.addValue(key, nextValue);
|
|
3100
3100
|
if (process.env.NODE_ENV === "development") {
|
|
3101
|
-
warnOnce(nextValue.version === "11.
|
|
3101
|
+
warnOnce(nextValue.version === "11.14.3", `Attempting to mix Motion versions ${nextValue.version} with 11.14.3 may not work as expected.`);
|
|
3102
3102
|
}
|
|
3103
3103
|
} else if (isMotionValue(prevValue)) {
|
|
3104
3104
|
element.addValue(key, motionValue(nextValue, { owner: element }));
|