@helsenorge/designsystem-react 7.0.0-beta.2 → 7.0.0-beta.5
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 +19 -0
- package/__mocks__/usePseudoClasses.d.ts +1 -0
- package/__mocks__/usePseudoClasses.js +5 -0
- package/__mocks__/usePseudoClasses.js.map +1 -0
- package/components/AnchorLink/AnchorLink.d.ts +2 -1
- package/components/AnchorLink/AnchorLink.js.map +1 -1
- package/components/Badge/Badge.stories.d.ts +1 -1
- package/components/Button/Button.d.ts +2 -1
- package/components/Button/Button.js +88 -88
- package/components/Button/Button.js.map +1 -1
- package/components/Button/Button.stories.d.ts +1 -0
- package/components/Button/styles.module.scss +4 -0
- package/components/Button/styles.module.scss.d.ts +1 -0
- package/components/Checkbox/Checkbox.d.ts +2 -0
- package/components/Checkbox/Checkbox.js +72 -70
- package/components/Checkbox/Checkbox.js.map +1 -1
- package/components/Dropdown/Dropdown.d.ts +2 -0
- package/components/Dropdown/Dropdown.js +32 -31
- package/components/Dropdown/Dropdown.js.map +1 -1
- package/components/ErrorWrapper/ErrorWrapper.d.ts +4 -2
- package/components/ErrorWrapper/ErrorWrapper.js +7 -7
- package/components/ErrorWrapper/ErrorWrapper.js.map +1 -1
- package/components/Expander/Expander.d.ts +2 -0
- package/components/Expander/Expander.js +30 -29
- package/components/Expander/Expander.js.map +1 -1
- package/components/ExpanderHierarchy/expander.module.scss +0 -20
- package/components/ExpanderHierarchy/expander.module.scss.d.ts +0 -1
- package/components/ExpanderList/ExpanderList.d.ts +4 -0
- package/components/ExpanderList/ExpanderList.js +78 -75
- package/components/ExpanderList/ExpanderList.js.map +1 -1
- package/components/ExpanderList/ExpanderList.stories.d.ts +1 -1
- package/components/FormExample/FormExample.js +136 -216
- package/components/FormExample/FormExample.js.map +1 -1
- package/components/FormGroup/FormGroup.d.ts +2 -0
- package/components/FormGroup/FormGroup.js +62 -48
- package/components/FormGroup/FormGroup.js.map +1 -1
- package/components/FormGroup/FormGroup.stories.d.ts +1 -0
- package/components/FormLayout/styles.module.scss +1 -2
- package/components/GridExample/GridExample.js +1 -1
- package/components/GridExample/GridExample.js.map +1 -1
- package/components/HelpQuestion/styles.module.scss +3 -3
- package/components/Icon/Icon.stories.d.ts +5 -2
- package/components/Input/Input.d.ts +2 -0
- package/components/Input/Input.js +75 -74
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.stories.d.ts +2 -2
- package/components/LinkList/LinkList.stories.d.ts +1 -1
- package/components/Loader/Loader.stories.d.ts +1 -1
- package/components/Logo/Logo.stories.d.ts +1 -1
- package/components/NotificationPanel/DetailButton/styles.module.scss +1 -1
- package/components/PopMenu/PopMenu.js +73 -61
- package/components/PopMenu/PopMenu.js.map +1 -1
- package/components/PopOver/PopOver.d.ts +2 -0
- package/components/PopOver/PopOver.js +37 -36
- package/components/PopOver/PopOver.js.map +1 -1
- package/components/RadioButton/RadioButton.d.ts +2 -0
- package/components/RadioButton/RadioButton.js +62 -60
- package/components/RadioButton/RadioButton.js.map +1 -1
- package/components/Select/Select.d.ts +2 -0
- package/components/Select/Select.js +40 -39
- package/components/Select/Select.js.map +1 -1
- package/components/SharingStatus/styles.module.scss +2 -0
- package/components/Textarea/Textarea.d.ts +4 -0
- package/components/Textarea/Textarea.js +70 -67
- package/components/Textarea/Textarea.js.map +1 -1
- package/components/Trigger/styles.module.scss +24 -4
- package/components/Validation/ErrorList.d.ts +7 -0
- package/components/Validation/ErrorList.js +8 -0
- package/components/Validation/ErrorList.js.map +1 -0
- package/components/Validation/ErrorListItem.d.ts +8 -0
- package/components/Validation/ErrorListItem.js +12 -0
- package/components/Validation/ErrorListItem.js.map +1 -0
- package/components/Validation/Validation.d.ts +9 -1
- package/components/Validation/Validation.js +15 -13
- package/components/Validation/Validation.js.map +1 -1
- package/components/Validation/ValidationSummary.d.ts +15 -0
- package/components/Validation/ValidationSummary.js +17 -0
- package/components/Validation/ValidationSummary.js.map +1 -0
- package/components/Validation/styles.module.scss +13 -5
- package/components/Validation/styles.module.scss.d.ts +4 -1
- package/components/Validation/types.d.ts +9 -0
- package/constants.d.ts +1 -0
- package/constants.js +1 -1
- package/constants.js.map +1 -1
- package/fonts/source-sans-pro-200-extralight.woff +0 -0
- package/fonts/source-sans-pro-200-extralight.woff2 +0 -0
- package/fonts/source-sans-pro-300-light.woff +0 -0
- package/fonts/source-sans-pro-300-light.woff2 +0 -0
- package/fonts/source-sans-pro-400-regular.woff +0 -0
- package/fonts/source-sans-pro-400-regular.woff2 +0 -0
- package/fonts/source-sans-pro-600-semibold.woff +0 -0
- package/fonts/source-sans-pro-600-semibold.woff2 +0 -0
- package/fonts/source-sans-pro-700-bold.woff +0 -0
- package/fonts/source-sans-pro-700-bold.woff2 +0 -0
- package/fonts/source-sans-pro-900-black.woff +0 -0
- package/fonts/source-sans-pro-900-black.woff2 +0 -0
- package/package.json +3 -3
- package/scss/_icon.scss +8 -0
- package/utils/tests/setup-test.d.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormMode, FormSize, IconSize } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { getColor } from '../../theme/currys/color';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport { uuid } from '../../utils/uuid';\nimport Icon from '../Icon';\nimport Check from '../Icons/Check';\nimport { getLabelText, renderLabelAsParent } from '../Label';\n\nimport checkboxStyles from './styles.module.scss';\n\nexport interface CheckboxProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'aria-describedby' | 'name' | 'value' | 'disabled' | 'checked' | 'required' | 'onChange'\n > {\n /** Adds custom classes to the element. */\n className?: string;\n /** The <Label/> next to the checkbox - sublabels kan ikke kombineres med large variant */\n label: React.ReactNode;\n /** input id of the checkbox */\n inputId?: string;\n /** Changes the visuals of the checkbox */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the checkbox */\n size?: keyof typeof FormSize;\n /** Activates Error style for the checkbox - This is can be true while errorText is empty, when in a FormGroup */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Checkbox = React.forwardRef((props: CheckboxProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n checked = false,\n disabled,\n label,\n inputId = uuid(),\n mode = FormMode.onwhite,\n name = inputId,\n size,\n errorText,\n error = !!errorText,\n value = getLabelText(label),\n testId,\n required,\n onChange,\n ...rest\n } = props;\n const [isChecked, setIsChecked] = useState(checked);\n const onWhite = mode === FormMode.onwhite;\n const onGrey = mode === FormMode.ongrey;\n const onBlueberry = mode === FormMode.onblueberry;\n const onInvalid = error || mode === FormMode.oninvalid;\n const onDark = mode === FormMode.ondark;\n const large = size === FormSize.large;\n const { refObject, isFocused } = usePseudoClasses<HTMLInputElement>(isMutableRefObject(ref) ? ref : null);\n const mergedRefs = mergeRefs([ref, refObject]);\n\n const checkboxWrapperClasses = classNames(checkboxStyles['checkbox-wrapper'], {\n [checkboxStyles['checkbox-wrapper--with-error']]: errorText,\n [checkboxStyles['checkbox-wrapper--large']]: large,\n });\n const checkboxLabelClasses = classNames(checkboxStyles['checkbox-label'], {\n [checkboxStyles['checkbox-label--disabled']]: disabled,\n [checkboxStyles['checkbox-label--on-dark']]: onDark,\n [checkboxStyles['checkbox-label--large']]: large,\n [checkboxStyles['checkbox-label__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__large--focus']]: large && isFocused,\n [checkboxStyles['checkbox-label__large--on-white']]: large && onWhite,\n [checkboxStyles['checkbox-label__large--on-grey']]: large && onGrey,\n [checkboxStyles['checkbox-label__large--on-blueberry']]: large && onBlueberry,\n [checkboxStyles['checkbox-label__large--on-invalid']]: large && onInvalid,\n [checkboxStyles['checkbox-label__large--disabled']]: large && disabled,\n });\n const checkboxClasses = classNames(checkboxStyles.checkbox, className);\n const checkboxIconWrapperClasses = classNames(checkboxStyles['checkbox__icon-wrapper'], {\n [checkboxStyles['checkbox__icon-wrapper--on-white']]: onWhite,\n [checkboxStyles['checkbox__icon-wrapper--on-grey']]: onGrey,\n [checkboxStyles['checkbox__icon-wrapper--on-invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--disabled']]: disabled,\n [checkboxStyles['checkbox__icon-wrapper__regular--checked']]: !large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__regular--invalid']]: !large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__regular--on-dark']]: !large && isChecked && onDark,\n [checkboxStyles['checkbox__icon-wrapper__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--on-dark']]: onDark,\n [checkboxStyles['checkbox__icon-wrapper--on-blueberry']]: onBlueberry,\n [checkboxStyles['checkbox__icon-wrapper--invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--disabled']]: disabled && large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--disabled']]: disabled && large && isChecked,\n });\n const labelTextClasses = classNames(checkboxStyles['checkbox-label__text'], {\n [checkboxStyles['checkbox-label__text__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__text__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox-label__text--on-dark']]: onDark,\n [checkboxStyles['checkbox-label__text--disabled']]: disabled,\n });\n const errorStyles = classNames(checkboxStyles['checkbox-errors']);\n\n let iconColor = getColor('white');\n if (onDark || (large && isChecked)) iconColor = getColor('blueberry', 900);\n if (onInvalid && large && isChecked) iconColor = getColor('white');\n if (disabled) iconColor = getColor('neutral', 400);\n\n useEffect(() => {\n setIsChecked(checked);\n }, [checked]);\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>): void => {\n if (onChange) {\n onChange(e);\n }\n\n setIsChecked(!isChecked);\n };\n\n const getLabelContent = (): React.ReactNode => {\n return (\n <>\n <input\n id={inputId}\n name={name}\n className={checkboxClasses}\n type=\"checkbox\"\n checked={isChecked}\n disabled={disabled}\n value={value}\n ref={mergedRefs}\n aria-describedby={props['aria-describedby'] ?? undefined}\n aria-invalid={error}\n required={required}\n onChange={onChangeHandler}\n {...rest}\n />\n <span className={checkboxIconWrapperClasses}>\n {isChecked && <Icon color={iconColor} className={checkboxStyles['checkbox__icon']} svgIcon={Check} size={IconSize.XSmall} />}\n </span>\n </>\n );\n };\n\n return (\n <div data-testid={testId} data-analyticsid={AnalyticsId.Checkbox} className={checkboxWrapperClasses}>\n {errorText && <p className={errorStyles}>{errorText}</p>}\n {renderLabelAsParent(\n label,\n getLabelContent(),\n inputId,\n mode as FormMode,\n checkboxLabelClasses,\n labelTextClasses,\n checkboxStyles['checkbox-sublabel-wrapper'],\n large\n )}\n </div>\n );\n});\n\nCheckbox.displayName = 'Checkbox';\n\nexport default Checkbox;\n"],"names":["Checkbox","React","props","ref","className","checked","disabled","label","inputId","uuid","mode","FormMode","name","size","errorText","error","value","getLabelText","testId","required","onChange","rest","isChecked","setIsChecked","useState","onWhite","onGrey","onBlueberry","onInvalid","onDark","large","FormSize","refObject","isFocused","usePseudoClasses","isMutableRefObject","mergedRefs","mergeRefs","checkboxWrapperClasses","classNames","checkboxStyles","checkboxLabelClasses","checkboxClasses","checkboxIconWrapperClasses","labelTextClasses","errorStyles","iconColor","getColor","useEffect","onChangeHandler","e","getLabelContent","Icon","Check","IconSize","AnalyticsId","renderLabelAsParent","Checkbox$1"],"mappings":";;;;;;;;;;;AAsCO,MAAMA,IAAWC,EAAM,WAAW,CAACC,GAAsBC,MAAqC;AAC7F,QAAA;AAAA,IACJ,WAA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,cAAA,OAAA,EAAI,eAAaiB,GAAQ,oBAAkBqC,EAAY,UAAU,WAAWjB,EAAA,GAC1ExB,KAAcb,gBAAAA,EAAA,cAAA,KAAA,EAAE,WAAW4C,EAAA,GAAc/B,CAAU,GACnD0C;AAAA,IACCjD;AAAA,IACA4C,EAAgB;AAAA,IAChB3C;AAAA,IACAE;AAAA,IACA+B;AAAA,IACAG;AAAA,IACAJ,EAAe,2BAA2B;AAAA,IAC1CV;AAAA,EAAA,CAEJ;AAEJ,CAAC;AAED9B,EAAS,cAAc;AAEvB,MAAAyD,KAAezD;"}
|
|
1
|
+
{"version":3,"file":"Checkbox.js","sources":["../../../src/components/Checkbox/Checkbox.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormMode, FormSize, IconSize } from '../../constants';\nimport { usePseudoClasses } from '../../hooks/usePseudoClasses';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys/color';\nimport { isMutableRefObject, mergeRefs } from '../../utils/refs';\nimport { uuid } from '../../utils/uuid';\nimport Icon from '../Icon';\nimport Check from '../Icons/Check';\nimport { getLabelText, renderLabelAsParent } from '../Label';\n\nimport checkboxStyles from './styles.module.scss';\n\nexport interface CheckboxProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'aria-describedby' | 'name' | 'value' | 'disabled' | 'checked' | 'required' | 'onChange'\n > {\n /** Adds custom classes to the element. */\n className?: string;\n /** The <Label/> next to the checkbox - sublabels kan ikke kombineres med large variant */\n label: React.ReactNode;\n /** input id of the checkbox */\n inputId?: string;\n /** Changes the visuals of the checkbox */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the checkbox */\n size?: keyof typeof FormSize;\n /** Activates Error style for the checkbox - This is can be true while errorText is empty, when in a FormGroup */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Checkbox = React.forwardRef((props: CheckboxProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n checked = false,\n disabled,\n label,\n inputId = uuid(),\n mode = FormMode.onwhite,\n name = inputId,\n size,\n errorText,\n error = !!errorText,\n errorTextId,\n value = getLabelText(label),\n testId,\n required,\n onChange,\n ...rest\n } = props;\n const [isChecked, setIsChecked] = useState(checked);\n const errorTextUuid = useUuid(errorTextId);\n const onWhite = mode === FormMode.onwhite;\n const onGrey = mode === FormMode.ongrey;\n const onBlueberry = mode === FormMode.onblueberry;\n const onInvalid = error || mode === FormMode.oninvalid;\n const onDark = mode === FormMode.ondark;\n const large = size === FormSize.large;\n const { refObject, isFocused } = usePseudoClasses<HTMLInputElement>(isMutableRefObject(ref) ? ref : null);\n const mergedRefs = mergeRefs([ref, refObject]);\n\n const checkboxWrapperClasses = classNames(checkboxStyles['checkbox-wrapper'], {\n [checkboxStyles['checkbox-wrapper--with-error']]: errorText,\n [checkboxStyles['checkbox-wrapper--large']]: large,\n });\n const checkboxLabelClasses = classNames(checkboxStyles['checkbox-label'], {\n [checkboxStyles['checkbox-label--disabled']]: disabled,\n [checkboxStyles['checkbox-label--on-dark']]: onDark,\n [checkboxStyles['checkbox-label--large']]: large,\n [checkboxStyles['checkbox-label__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__large--focus']]: large && isFocused,\n [checkboxStyles['checkbox-label__large--on-white']]: large && onWhite,\n [checkboxStyles['checkbox-label__large--on-grey']]: large && onGrey,\n [checkboxStyles['checkbox-label__large--on-blueberry']]: large && onBlueberry,\n [checkboxStyles['checkbox-label__large--on-invalid']]: large && onInvalid,\n [checkboxStyles['checkbox-label__large--disabled']]: large && disabled,\n });\n const checkboxClasses = classNames(checkboxStyles.checkbox, className);\n const checkboxIconWrapperClasses = classNames(checkboxStyles['checkbox__icon-wrapper'], {\n [checkboxStyles['checkbox__icon-wrapper--on-white']]: onWhite,\n [checkboxStyles['checkbox__icon-wrapper--on-grey']]: onGrey,\n [checkboxStyles['checkbox__icon-wrapper--on-invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--disabled']]: disabled,\n [checkboxStyles['checkbox__icon-wrapper__regular--checked']]: !large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__regular--invalid']]: !large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__regular--on-dark']]: !large && isChecked && onDark,\n [checkboxStyles['checkbox__icon-wrapper__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper--on-dark']]: onDark,\n [checkboxStyles['checkbox__icon-wrapper--on-blueberry']]: onBlueberry,\n [checkboxStyles['checkbox__icon-wrapper--invalid']]: onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--disabled']]: disabled && large && isChecked,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox__icon-wrapper__large--checked--disabled']]: disabled && large && isChecked,\n });\n const labelTextClasses = classNames(checkboxStyles['checkbox-label__text'], {\n [checkboxStyles['checkbox-label__text__large--checked']]: large && isChecked,\n [checkboxStyles['checkbox-label__text__large--invalid']]: large && isChecked && onInvalid,\n [checkboxStyles['checkbox-label__text--on-dark']]: onDark,\n [checkboxStyles['checkbox-label__text--disabled']]: disabled,\n });\n const errorStyles = classNames(checkboxStyles['checkbox-errors']);\n\n let iconColor = getColor('white');\n if (onDark || (large && isChecked)) iconColor = getColor('blueberry', 900);\n if (onInvalid && large && isChecked) iconColor = getColor('white');\n if (disabled) iconColor = getColor('neutral', 400);\n\n useEffect(() => {\n setIsChecked(checked);\n }, [checked]);\n\n const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>): void => {\n if (onChange) {\n onChange(e);\n }\n\n setIsChecked(!isChecked);\n };\n\n const getLabelContent = (): React.ReactNode => {\n return (\n <>\n <input\n id={inputId}\n name={name}\n className={checkboxClasses}\n type=\"checkbox\"\n checked={isChecked}\n disabled={disabled}\n value={value}\n ref={mergedRefs}\n aria-describedby={[props['aria-describedby'] || '', errorTextUuid].join(' ')}\n aria-invalid={error}\n required={required}\n onChange={onChangeHandler}\n {...rest}\n />\n <span className={checkboxIconWrapperClasses}>\n {isChecked && <Icon color={iconColor} className={checkboxStyles['checkbox__icon']} svgIcon={Check} size={IconSize.XSmall} />}\n </span>\n </>\n );\n };\n\n return (\n <div data-testid={testId} data-analyticsid={AnalyticsId.Checkbox} className={checkboxWrapperClasses}>\n {errorText && (\n <p className={errorStyles} id={errorTextUuid}>\n {errorText}\n </p>\n )}\n {renderLabelAsParent(\n label,\n getLabelContent(),\n inputId,\n mode as FormMode,\n checkboxLabelClasses,\n labelTextClasses,\n checkboxStyles['checkbox-sublabel-wrapper'],\n large\n )}\n </div>\n );\n});\n\nCheckbox.displayName = 'Checkbox';\n\nexport default Checkbox;\n"],"names":["Checkbox","React","props","ref","className","checked","disabled","label","inputId","uuid","mode","FormMode","name","size","errorText","error","errorTextId","value","getLabelText","testId","required","onChange","rest","isChecked","setIsChecked","useState","errorTextUuid","useUuid","onWhite","onGrey","onBlueberry","onInvalid","onDark","large","FormSize","refObject","isFocused","usePseudoClasses","isMutableRefObject","mergedRefs","mergeRefs","checkboxWrapperClasses","classNames","checkboxStyles","checkboxLabelClasses","checkboxClasses","checkboxIconWrapperClasses","labelTextClasses","errorStyles","iconColor","getColor","useEffect","onChangeHandler","e","getLabelContent","Icon","Check","IconSize","AnalyticsId","renderLabelAsParent","Checkbox$1"],"mappings":";;;;;;;;;;;;AAyCO,MAAMA,IAAWC,EAAM,WAAW,CAACC,GAAsBC,MAAqC;AAC7F,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,UAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC,IAAUC,GAAK;AAAA,IACf,MAAAC,IAAOC,EAA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AU,WAAWjB,EAC1E,GAAA3B,qCACE,KAAE,EAAA,WAAWkC,GAAa,IAAItB,EAAA,GAC5BZ,CACH,GAED6C;AAAA,IACCpD;AAAA,IACA+C,EAAgB;AAAA,IAChB9C;AAAA,IACAE;AAAA,IACAkC;AAAA,IACAG;AAAA,IACAJ,EAAe,2BAA2B;AAAA,IAC1CV;AAAA,EAAA,CAEJ;AAEJ,CAAC;AAEDjC,EAAS,cAAc;AAEvB,MAAA4D,KAAe5D;"}
|
|
@@ -30,6 +30,8 @@ export interface DropdownProps {
|
|
|
30
30
|
disabled?: boolean;
|
|
31
31
|
/** Sets the data-testid attribute on the dropdown button. */
|
|
32
32
|
testId?: string;
|
|
33
|
+
/** Overrides the default z-index of the DropDownContent */
|
|
34
|
+
zIndex?: number;
|
|
33
35
|
}
|
|
34
36
|
declare const Dropdown: React.FC<DropdownProps>;
|
|
35
37
|
export default Dropdown;
|
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import r, { useRef as g, useState as
|
|
1
|
+
import r, { useRef as g, useState as X } from "react";
|
|
2
2
|
import k from "classnames";
|
|
3
3
|
import { theme as C } from "../../theme/index.js";
|
|
4
4
|
import "../../hooks/useBreakpoint.js";
|
|
5
|
-
import { useHover as
|
|
5
|
+
import { useHover as Z } from "../../hooks/useHover.js";
|
|
6
6
|
import { useSize as j } from "../../hooks/useSize.js";
|
|
7
7
|
import { useToggle as q } from "../../hooks/useToggle.js";
|
|
8
8
|
import { useKeyboardEvent as F } from "../../hooks/useKeyboardEvent.js";
|
|
9
9
|
import { useOutsideEvent as G } from "../../hooks/useOutsideEvent.js";
|
|
10
10
|
import { useUuid as _ } from "../../hooks/useUuid.js";
|
|
11
|
-
import { KeyboardEventKey as n, AnalyticsId as
|
|
12
|
-
import { mergeRefs as
|
|
13
|
-
import
|
|
14
|
-
import { Icon as
|
|
15
|
-
import
|
|
11
|
+
import { ZIndex as J, KeyboardEventKey as n, AnalyticsId as Q, IconSize as Y } from "../../constants.js";
|
|
12
|
+
import { mergeRefs as M } from "../../utils/refs.js";
|
|
13
|
+
import ee from "../Button/Button.js";
|
|
14
|
+
import { Icon as oe } from "../Icon/Icon.js";
|
|
15
|
+
import re from "../Icons/PlusSmall.js";
|
|
16
16
|
import o from "./styles.module.scss";
|
|
17
|
-
var
|
|
18
|
-
const
|
|
17
|
+
var te = /* @__PURE__ */ ((d) => (d.onwhite = "onwhite", d.ongrey = "ongrey", d.onblueberry = "onblueberry", d.oncherry = "oncherry", d))(te || {});
|
|
18
|
+
const ne = (d) => {
|
|
19
19
|
const {
|
|
20
20
|
label: R,
|
|
21
21
|
placeholder: $,
|
|
22
22
|
closeText: A = "Lukk",
|
|
23
23
|
noCloseButton: H = !1,
|
|
24
24
|
onToggle: K,
|
|
25
|
-
open:
|
|
25
|
+
open: O = !1,
|
|
26
26
|
children: y,
|
|
27
27
|
mode: c = "onwhite",
|
|
28
|
-
transparent:
|
|
28
|
+
transparent: S = !1,
|
|
29
29
|
fluid: b = !1,
|
|
30
30
|
testId: z,
|
|
31
|
-
disabled: i
|
|
32
|
-
|
|
31
|
+
disabled: i,
|
|
32
|
+
zIndex: D = J.PopOver
|
|
33
|
+
} = d, p = g(null), w = g(null), { hoverRef: m, isHovered: L } = Z(), { value: l, toggleValue: h } = q(!i && O, K), a = g(r.Children.map(y, () => r.createRef())), [u, P] = X(), { width: T } = j(m) || {}, E = _(), I = _(), x = _(), v = () => {
|
|
33
34
|
var e;
|
|
34
35
|
h(), (e = w.current) == null || e.focus();
|
|
35
36
|
}, f = () => {
|
|
@@ -37,7 +38,7 @@ const re = (d) => {
|
|
|
37
38
|
h(), (e = m.current) == null || e.focus();
|
|
38
39
|
};
|
|
39
40
|
F(p, (e) => {
|
|
40
|
-
var
|
|
41
|
+
var N;
|
|
41
42
|
if (e.preventDefault(), !a.current)
|
|
42
43
|
return;
|
|
43
44
|
if (l) {
|
|
@@ -46,12 +47,12 @@ const re = (d) => {
|
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
49
|
} else {
|
|
49
|
-
|
|
50
|
+
v();
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
|
-
const t = a.current.findIndex((
|
|
53
|
+
const t = a.current.findIndex((W) => W.current === e.target);
|
|
53
54
|
let s = t;
|
|
54
|
-
e.key === n.Home ? s = 0 : e.key === n.End ? s = a.current.length - 1 : e.key === n.ArrowDown && t < a.current.length - 1 ? s = t + 1 : e.key === n.ArrowUp && t > 0 ? s = t - 1 : e.key === n.Enter && t !== -1 && (s = t), s !== -1 && ((
|
|
55
|
+
e.key === n.Home ? s = 0 : e.key === n.End ? s = a.current.length - 1 : e.key === n.ArrowDown && t < a.current.length - 1 ? s = t + 1 : e.key === n.ArrowUp && t > 0 ? s = t - 1 : e.key === n.Enter && t !== -1 && (s = t), s !== -1 && ((N = a.current[s].current) == null || N.focus(), P(s));
|
|
55
56
|
}, [
|
|
56
57
|
n.ArrowDown,
|
|
57
58
|
n.ArrowUp,
|
|
@@ -67,20 +68,20 @@ const re = (d) => {
|
|
|
67
68
|
[o["dropdown__toggle--on-grey"]]: c === "ongrey",
|
|
68
69
|
[o["dropdown__toggle--on-blueberry"]]: c === "onblueberry",
|
|
69
70
|
[o["dropdown__toggle--on-cherry"]]: c === "oncherry",
|
|
70
|
-
[o["dropdown__toggle--transparent"]]:
|
|
71
|
+
[o["dropdown__toggle--transparent"]]: S,
|
|
71
72
|
[o["dropdown__toggle--fluid"]]: b,
|
|
72
73
|
[o["dropdown__toggle--open"]]: l
|
|
73
74
|
}
|
|
74
|
-
), B = k(o.dropdown__content, l && o["dropdown__content--open"]),
|
|
75
|
+
), B = k(o.dropdown__content, l && o["dropdown__content--open"]), V = r.Children.map(y, (e, t) => /* @__PURE__ */ r.createElement("li", { className: o.dropdown__input, role: "option", id: `${x}-${t}`, "aria-selected": t === u }, r.isValidElement(e) && a.current && a.current[t] ? r.cloneElement(e, { ref: M([e.props.ref, a.current[t]]) }) : e));
|
|
75
76
|
return /* @__PURE__ */ r.createElement("div", { className: o.dropdown, ref: p }, /* @__PURE__ */ r.createElement("span", { id: E, className: o.dropdown__label }, R), /* @__PURE__ */ r.createElement(
|
|
76
77
|
"button",
|
|
77
78
|
{
|
|
78
79
|
type: "button",
|
|
79
|
-
onClick: () => !l &&
|
|
80
|
+
onClick: () => !l && v(),
|
|
80
81
|
className: U,
|
|
81
82
|
ref: m,
|
|
82
83
|
"data-testid": z,
|
|
83
|
-
"data-analyticsid":
|
|
84
|
+
"data-analyticsid": Q.Dropdown,
|
|
84
85
|
disabled: i,
|
|
85
86
|
"aria-labelledby": I,
|
|
86
87
|
"aria-haspopup": "listbox",
|
|
@@ -88,16 +89,16 @@ const re = (d) => {
|
|
|
88
89
|
},
|
|
89
90
|
/* @__PURE__ */ r.createElement("span", { id: I, className: o.dropdown__toggle__label }, $),
|
|
90
91
|
/* @__PURE__ */ r.createElement(
|
|
91
|
-
|
|
92
|
+
oe,
|
|
92
93
|
{
|
|
93
94
|
color: i ? C.palette.neutral700 : C.palette.blueberry600,
|
|
94
|
-
svgIcon:
|
|
95
|
+
svgIcon: re,
|
|
95
96
|
className: o.dropdown__icon,
|
|
96
|
-
isHovered: !i &&
|
|
97
|
-
size:
|
|
97
|
+
isHovered: !i && L,
|
|
98
|
+
size: Y.XSmall
|
|
98
99
|
}
|
|
99
100
|
)
|
|
100
|
-
), /* @__PURE__ */ r.createElement("div", { className: B, style: { width: b ? "100%" : `${T}px
|
|
101
|
+
), /* @__PURE__ */ r.createElement("div", { className: B, style: { width: b ? "100%" : `${T}px`, zIndex: D } }, /* @__PURE__ */ r.createElement(
|
|
101
102
|
"ul",
|
|
102
103
|
{
|
|
103
104
|
className: o.dropdown__options,
|
|
@@ -107,11 +108,11 @@ const re = (d) => {
|
|
|
107
108
|
"aria-activedescendant": typeof u < "u" ? `${x}-${u}` : void 0,
|
|
108
109
|
ref: w
|
|
109
110
|
},
|
|
110
|
-
|
|
111
|
-
), !H && /* @__PURE__ */ r.createElement("div", { className: o.dropdown__close }, /* @__PURE__ */ r.createElement(
|
|
112
|
-
},
|
|
111
|
+
V
|
|
112
|
+
), !H && /* @__PURE__ */ r.createElement("div", { className: o.dropdown__close }, /* @__PURE__ */ r.createElement(ee, { onClick: f, fluid: !0, "aria-expanded": l }, A))));
|
|
113
|
+
}, Ie = ne;
|
|
113
114
|
export {
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
te as DropdownMode,
|
|
116
|
+
Ie as default
|
|
116
117
|
};
|
|
117
118
|
//# sourceMappingURL=Dropdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown.js","sources":["../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport {\n AnalyticsId,\n IconSize,\n KeyboardEventKey,\n theme,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\n useSize,\n useToggle,\n useUuid,\n} from '../..';\nimport { mergeRefs } from '../../utils/refs';\nimport Button from '../Button';\nimport Icon from '../Icon';\nimport PlusSmall from '../Icons/PlusSmall';\n\nimport styles from './styles.module.scss';\n\nexport enum DropdownMode {\n onwhite = 'onwhite',\n ongrey = 'ongrey',\n onblueberry = 'onblueberry',\n oncherry = 'oncherry',\n}\n\nexport interface DropdownProps {\n /** Label for dropdown. Synlig for skjermlesere. */\n label: string;\n /** Tekst på knappen som åpner dropdownen */\n placeholder: string;\n /** Sets the dropdown content */\n children: React.ReactNode;\n /** Close button text */\n closeText?: string;\n /** No close button */\n noCloseButton?: boolean;\n /** Called when dropdown is open/closed. */\n onToggle?: (isOpen: boolean) => void;\n /** Om dropdown er åpen */\n open?: boolean;\n /** Changes the visuals of the dropdown */\n mode?: keyof typeof DropdownMode;\n /** Makes the background transparent */\n transparent?: boolean;\n /** Makes the background transparent */\n fluid?: boolean;\n /** Makes the dropdown disabled */\n disabled?: boolean;\n /** Sets the data-testid attribute on the dropdown button. */\n testId?: string;\n}\n\nconst Dropdown: React.FC<DropdownProps> = props => {\n const {\n label,\n placeholder,\n closeText = 'Lukk',\n noCloseButton = false,\n onToggle,\n open = false,\n children,\n mode = DropdownMode.onwhite,\n transparent = false,\n fluid = false,\n testId,\n disabled,\n } = props;\n const dropdownRef = useRef<HTMLDivElement>(null);\n const optionsRef = useRef<HTMLUListElement>(null);\n const { hoverRef: buttonRef, isHovered } = useHover<HTMLButtonElement>();\n const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);\n const inputRefList = useRef(React.Children.map(children, () => React.createRef<HTMLElement>()));\n const [currentIndex, setCurrentIndex] = useState<number>();\n const { width: buttonWidth } = useSize(buttonRef) || {};\n const labelId = useUuid();\n const toggleLabelId = useUuid();\n const optionIdPrefix = useUuid();\n\n const handleOpen = (): void => {\n toggleIsOpen();\n optionsRef.current?.focus();\n };\n\n const handleClose = (): void => {\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n event.preventDefault();\n\n if (!inputRefList.current) {\n return;\n }\n\n if (!isOpen) {\n handleOpen();\n return;\n } else if (event.key === KeyboardEventKey.Escape && isOpen) {\n handleClose();\n return;\n }\n\n const index = inputRefList.current.findIndex(x => x.current === event.target);\n let nextIndex = index;\n\n if (event.key === KeyboardEventKey.Home) {\n nextIndex = 0;\n } else if (event.key === KeyboardEventKey.End) {\n nextIndex = inputRefList.current.length - 1;\n } else if (event.key === KeyboardEventKey.ArrowDown && index < inputRefList.current.length - 1) {\n nextIndex = index + 1;\n } else if (event.key === KeyboardEventKey.ArrowUp && index > 0) {\n nextIndex = index - 1;\n } else if (event.key === KeyboardEventKey.Enter && index !== -1) {\n nextIndex = index;\n }\n if (nextIndex !== -1) {\n inputRefList.current[nextIndex].current?.focus();\n setCurrentIndex(nextIndex);\n }\n };\n\n useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [\n KeyboardEventKey.ArrowDown,\n KeyboardEventKey.ArrowUp,\n KeyboardEventKey.End,\n KeyboardEventKey.Enter,\n KeyboardEventKey.Escape,\n KeyboardEventKey.Home,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const toggleClasses = classNames(\n styles.dropdown__toggle,\n !disabled && {\n [styles['dropdown__toggle--on-white']]: mode === DropdownMode.onwhite,\n [styles['dropdown__toggle--on-grey']]: mode === DropdownMode.ongrey,\n [styles['dropdown__toggle--on-blueberry']]: mode === DropdownMode.onblueberry,\n [styles['dropdown__toggle--on-cherry']]: mode === DropdownMode.oncherry,\n [styles['dropdown__toggle--transparent']]: transparent,\n [styles['dropdown__toggle--fluid']]: fluid,\n [styles['dropdown__toggle--open']]: isOpen,\n }\n );\n\n const contentClasses = classNames(styles.dropdown__content, isOpen && styles['dropdown__content--open']);\n\n const renderChildren = React.Children.map(children, (child, index) => (\n <li className={styles.dropdown__input} role=\"option\" id={`${optionIdPrefix}-${index}`} aria-selected={index === currentIndex}>\n {React.isValidElement(child) && inputRefList.current && inputRefList.current[index]\n ? React.cloneElement(child as React.ReactElement, { ref: mergeRefs([child.props.ref, inputRefList.current[index]]) })\n : child}\n </li>\n ));\n\n return (\n <div className={styles.dropdown} ref={dropdownRef}>\n <span id={labelId} className={styles.dropdown__label}>\n {label}\n </span>\n <button\n type=\"button\"\n onClick={() => !isOpen && handleOpen()}\n className={toggleClasses}\n ref={buttonRef}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Dropdown}\n disabled={disabled}\n aria-labelledby={toggleLabelId}\n aria-haspopup=\"listbox\"\n aria-expanded={isOpen}\n >\n <span id={toggleLabelId} className={styles.dropdown__toggle__label}>\n {placeholder}\n </span>\n <Icon\n color={disabled ? theme.palette.neutral700 : theme.palette.blueberry600}\n svgIcon={PlusSmall}\n className={styles.dropdown__icon}\n isHovered={!disabled && isHovered}\n size={IconSize.XSmall}\n />\n </button>\n <div className={contentClasses} style={{ width: fluid ? '100%' : `${buttonWidth}px` }}>\n <ul\n className={styles.dropdown__options}\n role=\"listbox\"\n aria-labelledby={labelId}\n tabIndex={-1}\n aria-activedescendant={typeof currentIndex !== 'undefined' ? `${optionIdPrefix}-${currentIndex}` : undefined}\n ref={optionsRef}\n >\n {renderChildren}\n </ul>\n {!noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose} fluid aria-expanded={isOpen}>\n {closeText}\n </Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"names":["DropdownMode","Dropdown","props","label","placeholder","closeText","noCloseButton","onToggle","open","children","mode","transparent","fluid","testId","disabled","dropdownRef","useRef","optionsRef","buttonRef","isHovered","useHover","isOpen","toggleIsOpen","useToggle","inputRefList","React","currentIndex","setCurrentIndex","useState","buttonWidth","useSize","labelId","useUuid","toggleLabelId","optionIdPrefix","handleOpen","_a","handleClose","useKeyboardEvent","event","KeyboardEventKey","index","x","nextIndex","useOutsideEvent","toggleClasses","classNames","styles","contentClasses","renderChildren","child","mergeRefs","AnalyticsId","Icon","theme","PlusSmall","IconSize","Button","Dropdown$1"],"mappings":";;;;;;;;;;;;;;;;AAuBY,IAAAA,uBAAAA,OACVA,EAAA,UAAU,WACVA,EAAA,SAAS,UACTA,EAAA,cAAc,eACdA,EAAA,WAAW,YAJDA,IAAAA,MAAA,CAAA,CAAA;AAkCZ,MAAMC,KAAoC,CAASC,MAAA;AAC3C,QAAA;AAAA,IACJ,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,eAAAC,IAAgB;AAAA,IAChB,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,aAAAC,IAAc;AAAA,IACd,OAAAC,IAAQ;AAAA,IACR,QAAAC;AAAA,IACA,UAAAC;AAAA,EACE,IAAAZ,GACEa,IAAcC,EAAuB,IAAI,GACzCC,IAAaD,EAAyB,IAAI,GAC1C,EAAE,UAAUE,GAAW,WAAAC,MAAcC,EAA4B,GACjE,EAAE,OAAOC,GAAQ,aAAaC,EAAA,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src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport {\n AnalyticsId,\n IconSize,\n KeyboardEventKey,\n ZIndex,\n theme,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\n useSize,\n useToggle,\n useUuid,\n} from '../..';\nimport { mergeRefs } from '../../utils/refs';\nimport Button from '../Button';\nimport Icon from '../Icon';\nimport PlusSmall from '../Icons/PlusSmall';\n\nimport styles from './styles.module.scss';\n\nexport enum DropdownMode {\n onwhite = 'onwhite',\n ongrey = 'ongrey',\n onblueberry = 'onblueberry',\n oncherry = 'oncherry',\n}\n\nexport interface DropdownProps {\n /** Label for dropdown. Synlig for skjermlesere. */\n label: string;\n /** Tekst på knappen som åpner dropdownen */\n placeholder: string;\n /** Sets the dropdown content */\n children: React.ReactNode;\n /** Close button text */\n closeText?: string;\n /** No close button */\n noCloseButton?: boolean;\n /** Called when dropdown is open/closed. */\n onToggle?: (isOpen: boolean) => void;\n /** Om dropdown er åpen */\n open?: boolean;\n /** Changes the visuals of the dropdown */\n mode?: keyof typeof DropdownMode;\n /** Makes the background transparent */\n transparent?: boolean;\n /** Makes the background transparent */\n fluid?: boolean;\n /** Makes the dropdown disabled */\n disabled?: boolean;\n /** Sets the data-testid attribute on the dropdown button. */\n testId?: string;\n /** Overrides the default z-index of the DropDownContent */\n zIndex?: number;\n}\n\nconst Dropdown: React.FC<DropdownProps> = props => {\n const {\n label,\n placeholder,\n closeText = 'Lukk',\n noCloseButton = false,\n onToggle,\n open = false,\n children,\n mode = DropdownMode.onwhite,\n transparent = false,\n fluid = false,\n testId,\n disabled,\n zIndex = ZIndex.PopOver,\n } = props;\n const dropdownRef = useRef<HTMLDivElement>(null);\n const optionsRef = useRef<HTMLUListElement>(null);\n const { hoverRef: buttonRef, isHovered } = useHover<HTMLButtonElement>();\n const { value: isOpen, toggleValue: toggleIsOpen } = useToggle(!disabled && open, onToggle);\n const inputRefList = useRef(React.Children.map(children, () => React.createRef<HTMLElement>()));\n const [currentIndex, setCurrentIndex] = useState<number>();\n const { width: buttonWidth } = useSize(buttonRef) || {};\n const labelId = useUuid();\n const toggleLabelId = useUuid();\n const optionIdPrefix = useUuid();\n\n const handleOpen = (): void => {\n toggleIsOpen();\n optionsRef.current?.focus();\n };\n\n const handleClose = (): void => {\n toggleIsOpen();\n buttonRef.current?.focus();\n };\n\n const handleKeyboardNavigation = (event: KeyboardEvent): void => {\n event.preventDefault();\n\n if (!inputRefList.current) {\n return;\n }\n\n if (!isOpen) {\n handleOpen();\n return;\n } else if (event.key === KeyboardEventKey.Escape && isOpen) {\n handleClose();\n return;\n }\n\n const index = inputRefList.current.findIndex(x => x.current === event.target);\n let nextIndex = index;\n\n if (event.key === KeyboardEventKey.Home) {\n nextIndex = 0;\n } else if (event.key === KeyboardEventKey.End) {\n nextIndex = inputRefList.current.length - 1;\n } else if (event.key === KeyboardEventKey.ArrowDown && index < inputRefList.current.length - 1) {\n nextIndex = index + 1;\n } else if (event.key === KeyboardEventKey.ArrowUp && index > 0) {\n nextIndex = index - 1;\n } else if (event.key === KeyboardEventKey.Enter && index !== -1) {\n nextIndex = index;\n }\n if (nextIndex !== -1) {\n inputRefList.current[nextIndex].current?.focus();\n setCurrentIndex(nextIndex);\n }\n };\n\n useKeyboardEvent(dropdownRef, handleKeyboardNavigation, [\n KeyboardEventKey.ArrowDown,\n KeyboardEventKey.ArrowUp,\n KeyboardEventKey.End,\n KeyboardEventKey.Enter,\n KeyboardEventKey.Escape,\n KeyboardEventKey.Home,\n ]);\n\n useOutsideEvent(dropdownRef, () => isOpen && handleClose());\n\n const toggleClasses = classNames(\n styles.dropdown__toggle,\n !disabled && {\n [styles['dropdown__toggle--on-white']]: mode === DropdownMode.onwhite,\n [styles['dropdown__toggle--on-grey']]: mode === DropdownMode.ongrey,\n [styles['dropdown__toggle--on-blueberry']]: mode === DropdownMode.onblueberry,\n [styles['dropdown__toggle--on-cherry']]: mode === DropdownMode.oncherry,\n [styles['dropdown__toggle--transparent']]: transparent,\n [styles['dropdown__toggle--fluid']]: fluid,\n [styles['dropdown__toggle--open']]: isOpen,\n }\n );\n\n const contentClasses = classNames(styles.dropdown__content, isOpen && styles['dropdown__content--open']);\n\n const renderChildren = React.Children.map(children, (child, index) => (\n <li className={styles.dropdown__input} role=\"option\" id={`${optionIdPrefix}-${index}`} aria-selected={index === currentIndex}>\n {React.isValidElement(child) && inputRefList.current && inputRefList.current[index]\n ? React.cloneElement(child as React.ReactElement, { ref: mergeRefs([child.props.ref, inputRefList.current[index]]) })\n : child}\n </li>\n ));\n\n return (\n <div className={styles.dropdown} ref={dropdownRef}>\n <span id={labelId} className={styles.dropdown__label}>\n {label}\n </span>\n <button\n type=\"button\"\n onClick={(): false | void => !isOpen && handleOpen()}\n className={toggleClasses}\n ref={buttonRef}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Dropdown}\n disabled={disabled}\n aria-labelledby={toggleLabelId}\n aria-haspopup=\"listbox\"\n aria-expanded={isOpen}\n >\n <span id={toggleLabelId} className={styles.dropdown__toggle__label}>\n {placeholder}\n </span>\n <Icon\n color={disabled ? theme.palette.neutral700 : theme.palette.blueberry600}\n svgIcon={PlusSmall}\n className={styles.dropdown__icon}\n isHovered={!disabled && isHovered}\n size={IconSize.XSmall}\n />\n </button>\n <div className={contentClasses} style={{ width: fluid ? '100%' : `${buttonWidth}px`, zIndex: zIndex }}>\n <ul\n className={styles.dropdown__options}\n role=\"listbox\"\n aria-labelledby={labelId}\n tabIndex={-1}\n aria-activedescendant={typeof currentIndex !== 'undefined' ? `${optionIdPrefix}-${currentIndex}` : undefined}\n ref={optionsRef}\n >\n {renderChildren}\n </ul>\n {!noCloseButton && (\n <div className={styles.dropdown__close}>\n <Button onClick={handleClose} fluid aria-expanded={isOpen}>\n {closeText}\n </Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"names":["DropdownMode","Dropdown","props","label","placeholder","closeText","noCloseButton","onToggle","open","children","mode","transparent","fluid","testId","disabled","zIndex","ZIndex","dropdownRef","useRef","optionsRef","buttonRef","isHovered","useHover","isOpen","toggleIsOpen","useToggle","inputRefList","React","currentIndex","setCurrentIndex","useState","buttonWidth","useSize","labelId","useUuid","toggleLabelId","optionIdPrefix","handleOpen","_a","handleClose","useKeyboardEvent","event","KeyboardEventKey","index","x","nextIndex","useOutsideEvent","toggleClasses","classNames","styles","contentClasses","renderChildren","child","mergeRefs","AnalyticsId","Icon","theme","PlusSmall","IconSize","Button","Dropdown$1"],"mappings":";;;;;;;;;;;;;;;;AAwBY,IAAAA,uBAAAA,OACVA,EAAA,UAAU,WACVA,EAAA,SAAS,UACTA,EAAA,cAAc,eACdA,EAAA,WAAW,YAJDA,IAAAA,MAAA,CAAA,CAAA;AAoCZ,MAAMC,KAAoC,CAASC,MAAA;AAC3C,QAAA;AAAA,IACJ,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,eAAAC,IAAgB;AAAA,IAChB,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,aAAAC,IAAc;AAAA,IACd,OAAAC,IAAQ;AAAA,IACR,QAAAC;AAAA,IACA,UAAAC;AAAA,IACA,QAAAC,IAASC,EAAO;AAAA,EACd,IAAAd,GACEe,IAAcC,EAAuB,IAAI,GACzCC,IAAaD,EAAyB,IAAI,GAC1C,EAAE,UAAUE,GAAW,WAAAC,MAAcC,EAA4B,GACjE,EAAE,OAAOC,GAAQ,aAAaC,EAAA,IAAiBC,EAAU,CAACX,KAAYN,GAAMD,CAAQ,GACpFmB,IAAeR,EAAOS,EAAM,SAAS,IAAIlB,GAAU,MAAMkB,EAAM,UAAwB,CAAA,CAAC,GACxF,CAACC,GAAcC,CAAe,IAAIC,EAAiB,GACnD,EAAE,OAAOC,EAAA,IAAgBC,EAAQZ,CAAS,KAAK,IAC/Ca,IAAUC,KACVC,IAAgBD,KA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AiBqB;AAAA,MACjB,iBAAc;AAAA,MACd,iBAAeZ;AAAA,IAAA;AAAA,oCAEd,QAAK,EAAA,IAAIY,GAAe,WAAWc,EAAO,2BACxC7C,CACH;AAAA,IACAuB,gBAAAA,EAAA;AAAA,MAAC4B;AAAA,MAAA;AAAA,QACC,OAAOzC,IAAW0C,EAAM,QAAQ,aAAaA,EAAM,QAAQ;AAAA,QAC3D,SAASC;AAAA,QACT,WAAWR,EAAO;AAAA,QAClB,WAAW,CAACnC,KAAYO;AAAA,QACxB,MAAMqC,EAAS;AAAA,MAAA;AAAA,IACjB;AAAA,EAAA,GAEF/B,gBAAAA,EAAA,cAAC,OAAI,EAAA,WAAWuB,GAAgB,OAAO,EAAE,OAAOtC,IAAQ,SAAS,GAAGmB,CAAW,MAAM,QAAAhB,EACnF,EAAA,GAAAY,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWsB,EAAO;AAAA,MAClB,MAAK;AAAA,MACL,mBAAiBhB;AAAA,MACjB,UAAU;AAAA,MACV,yBAAuB,OAAOL,IAAiB,MAAc,GAAGQ,CAAc,IAAIR,CAAY,KAAK;AAAA,MACnG,KAAKT;AAAA,IAAA;AAAA,IAEJgC;AAAA,EAAA,GAEF,CAAC7C,qCACC,OAAI,EAAA,WAAW2C,EAAO,gBACrB,GAAAtB,gBAAAA,EAAA,cAACgC,MAAO,SAASpB,GAAa,OAAK,IAAC,iBAAehB,KAChDlB,CACH,CACF,CAEJ,CACF;AAEJ,GAEAuD,KAAe3D;"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface ErrorWrapperProps {
|
|
3
|
-
/** Error message */
|
|
4
|
-
errorText?: string;
|
|
5
3
|
/** Form component */
|
|
6
4
|
children?: React.ReactNode;
|
|
5
|
+
/** Error message */
|
|
6
|
+
errorText?: string;
|
|
7
|
+
/** Error text id */
|
|
8
|
+
errorTextId?: string;
|
|
7
9
|
/** Adds custom classes to the element. */
|
|
8
10
|
className?: string;
|
|
9
11
|
/** Sets the data-testid attribute. */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import t from "react";
|
|
2
2
|
import o from "classnames";
|
|
3
3
|
import e from "./styles.module.scss";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
return /* @__PURE__ */
|
|
7
|
-
},
|
|
4
|
+
const s = (r) => {
|
|
5
|
+
const a = o(e["error-wrapper"], r.errorText && e["error-wrapper--with-error"], r.className);
|
|
6
|
+
return /* @__PURE__ */ t.createElement("div", { className: a, "data-testid": r.testId }, r.errorText && /* @__PURE__ */ t.createElement("p", { className: e["error-wrapper__errors"], id: r.errorTextId }, r.errorText), r.children);
|
|
7
|
+
}, d = s;
|
|
8
8
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
s as ErrorWrapper,
|
|
10
|
+
d as default
|
|
11
11
|
};
|
|
12
12
|
//# sourceMappingURL=ErrorWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorWrapper.js","sources":["../../../src/components/ErrorWrapper/ErrorWrapper.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport styles from './styles.module.scss';\n\nexport interface ErrorWrapperProps {\n /** Error message */\n errorText?: string;\n /**
|
|
1
|
+
{"version":3,"file":"ErrorWrapper.js","sources":["../../../src/components/ErrorWrapper/ErrorWrapper.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport styles from './styles.module.scss';\n\nexport interface ErrorWrapperProps {\n /** Form component */\n children?: React.ReactNode;\n /** Error message */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const ErrorWrapper: React.FC<ErrorWrapperProps> = props => {\n const errorWrapperClasses = cn(styles['error-wrapper'], props.errorText && styles[`error-wrapper--with-error`], props.className);\n\n return (\n <div className={errorWrapperClasses} data-testid={props.testId}>\n {props.errorText && (\n <p className={styles['error-wrapper__errors']} id={props.errorTextId}>\n {props.errorText}\n </p>\n )}\n {props.children}\n </div>\n );\n};\n\nexport default ErrorWrapper;\n"],"names":["ErrorWrapper","props","errorWrapperClasses","cn","styles","React","ErrorWrapper$1"],"mappings":";;;AAmBO,MAAMA,IAA4C,CAASC,MAAA;AAC1D,QAAAC,IAAsBC,EAAGC,EAAO,eAAe,GAAGH,EAAM,aAAaG,EAAO,2BAA2B,GAAGH,EAAM,SAAS;AAG7H,SAAAI,gBAAAA,EAAA,cAAC,SAAI,WAAWH,GAAqB,eAAaD,EAAM,OAAA,GACrDA,EAAM,aACJI,gBAAAA,EAAA,cAAA,KAAA,EAAE,WAAWD,EAAO,uBAAuB,GAAG,IAAIH,EAAM,eACtDA,EAAM,SACT,GAEDA,EAAM,QACT;AAEJ,GAEAK,IAAeN;"}
|
|
@@ -30,6 +30,8 @@ export interface ExpanderProps {
|
|
|
30
30
|
renderChildrenWhenClosed?: boolean;
|
|
31
31
|
/** Sets the data-testid attribute on the expander button. */
|
|
32
32
|
testId?: string;
|
|
33
|
+
/** Overrides the default z-index of the expander header */
|
|
34
|
+
zIndex?: number;
|
|
33
35
|
}
|
|
34
36
|
declare const Expander: React.FC<ExpanderProps>;
|
|
35
37
|
export default Expander;
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import r, { useRef as N } from "react";
|
|
2
2
|
import d from "classnames";
|
|
3
|
-
import { ZIndex as
|
|
4
|
-
import { useExpand as
|
|
5
|
-
import { useHover as
|
|
6
|
-
import { useSticky as
|
|
7
|
-
import
|
|
3
|
+
import { ZIndex as D, AnalyticsId as C, IconSize as p } from "../../constants.js";
|
|
4
|
+
import { useExpand as O } from "../../hooks/useExpand.js";
|
|
5
|
+
import { useHover as U } from "../../hooks/useHover.js";
|
|
6
|
+
import { useSticky as Z } from "../../hooks/useSticky.js";
|
|
7
|
+
import j from "../Button/Button.js";
|
|
8
8
|
import { Icon as _ } from "../Icon/Icon.js";
|
|
9
9
|
import b from "../Icons/ChevronDown.js";
|
|
10
10
|
import h from "../Icons/ChevronUp.js";
|
|
11
|
-
import
|
|
11
|
+
import q from "../LazyIcon/LazyIcon.js";
|
|
12
12
|
import e from "./styles.module.scss";
|
|
13
|
-
var
|
|
14
|
-
const
|
|
13
|
+
var F = /* @__PURE__ */ ((s) => (s.small = "small", s.large = "large", s))(F || {});
|
|
14
|
+
const G = (s) => {
|
|
15
15
|
const {
|
|
16
16
|
title: x,
|
|
17
|
-
children:
|
|
17
|
+
children: z,
|
|
18
18
|
size: n = "small",
|
|
19
19
|
color: g,
|
|
20
20
|
svgIcon: o,
|
|
21
|
-
expanded:
|
|
22
|
-
noNestedLine:
|
|
21
|
+
expanded: $ = !1,
|
|
22
|
+
noNestedLine: k = !1,
|
|
23
23
|
sticky: S = !1,
|
|
24
24
|
testId: f,
|
|
25
25
|
onExpand: w,
|
|
26
|
-
renderChildrenWhenClosed: R = !1
|
|
27
|
-
|
|
26
|
+
renderChildrenWhenClosed: R = !1,
|
|
27
|
+
zIndex: W = D.ExpanderTrigger
|
|
28
|
+
} = s, [t, u] = O($, w), E = N(null), l = N(null), { isHovered: i } = U(l), { isOutsideWindow: X, isLeavingWindow: c, offsetHeight: v, contentWidth: y } = Z(E, l), a = S && t && X, I = (m) => /* @__PURE__ */ r.createElement("span", { className: d(e.expander__icon, e[`expander__icon--${m}`]) }, /* @__PURE__ */ r.createElement(_, { svgIcon: t ? h : b, size: p.XSmall, isHovered: i })), H = d(
|
|
28
29
|
e.expander__trigger,
|
|
29
30
|
n === "large" && e[`expander__trigger--${n}`],
|
|
30
31
|
n === "large" && e[`expander__trigger--${g || "neutral"}`],
|
|
@@ -32,13 +33,13 @@ const F = (s) => {
|
|
|
32
33
|
t && e["expander__trigger--expanded"],
|
|
33
34
|
a && !c && e["expander__trigger--sticky"],
|
|
34
35
|
a && c && e["expander__trigger--absolute"]
|
|
35
|
-
),
|
|
36
|
+
), L = () => /* @__PURE__ */ r.createElement(
|
|
36
37
|
"button",
|
|
37
38
|
{
|
|
38
39
|
type: "button",
|
|
39
|
-
className:
|
|
40
|
+
className: H,
|
|
40
41
|
style: {
|
|
41
|
-
zIndex: i || a ?
|
|
42
|
+
zIndex: i || a ? W : void 0,
|
|
42
43
|
width: a && y ? `${y}px` : void 0
|
|
43
44
|
},
|
|
44
45
|
"aria-expanded": t,
|
|
@@ -48,19 +49,19 @@ const F = (s) => {
|
|
|
48
49
|
"data-analyticsid": C.Expander
|
|
49
50
|
},
|
|
50
51
|
n === "small" && I("left"),
|
|
51
|
-
o && /* @__PURE__ */ r.createElement("span", { className: d(e.expander__icon, e["expander__icon--left"]) }, typeof o == "string" ? /* @__PURE__ */ r.createElement(
|
|
52
|
+
o && /* @__PURE__ */ r.createElement("span", { className: d(e.expander__icon, e["expander__icon--left"]) }, typeof o == "string" ? /* @__PURE__ */ r.createElement(q, { iconName: o, size: p.XSmall, isHovered: i }) : /* @__PURE__ */ r.createElement(_, { svgIcon: o, size: p.XSmall, isHovered: i })),
|
|
52
53
|
x,
|
|
53
54
|
n === "large" && I("right")
|
|
54
|
-
),
|
|
55
|
+
), T = d(
|
|
55
56
|
e.expander__button,
|
|
56
57
|
t && e["expander__button--expanded"],
|
|
57
58
|
a && !c && e["expander__button--sticky"],
|
|
58
59
|
a && c && e["expander__button--absolute"]
|
|
59
|
-
),
|
|
60
|
-
|
|
60
|
+
), B = () => /* @__PURE__ */ r.createElement(
|
|
61
|
+
j,
|
|
61
62
|
{
|
|
62
63
|
variant: "borderless",
|
|
63
|
-
className:
|
|
64
|
+
className: T,
|
|
64
65
|
"aria-expanded": t,
|
|
65
66
|
ref: l,
|
|
66
67
|
onClick: () => u(!t),
|
|
@@ -69,7 +70,7 @@ const F = (s) => {
|
|
|
69
70
|
},
|
|
70
71
|
/* @__PURE__ */ r.createElement(_, { svgIcon: t ? h : b, size: p.XSmall }),
|
|
71
72
|
x
|
|
72
|
-
),
|
|
73
|
+
), A = () => {
|
|
73
74
|
if (!R && !t)
|
|
74
75
|
return null;
|
|
75
76
|
const m = d(
|
|
@@ -78,9 +79,9 @@ const F = (s) => {
|
|
|
78
79
|
n === "large" && e[`expander__content--${g || "neutral"}`],
|
|
79
80
|
n === "large" && o && e["expander__content--icon"],
|
|
80
81
|
t && e["expander__content--expanded"],
|
|
81
|
-
n === "small" && !
|
|
82
|
+
n === "small" && !k && e["expander__content--nested-line"]
|
|
82
83
|
);
|
|
83
|
-
return /* @__PURE__ */ r.createElement("div", { className: m },
|
|
84
|
+
return /* @__PURE__ */ r.createElement("div", { className: m }, z);
|
|
84
85
|
};
|
|
85
86
|
return /* @__PURE__ */ r.createElement(
|
|
86
87
|
"div",
|
|
@@ -89,12 +90,12 @@ const F = (s) => {
|
|
|
89
90
|
ref: E,
|
|
90
91
|
style: { paddingTop: a && v ? `${v}px` : void 0 }
|
|
91
92
|
},
|
|
92
|
-
n === "large" ?
|
|
93
|
-
|
|
93
|
+
n === "large" ? L() : B(),
|
|
94
|
+
A()
|
|
94
95
|
);
|
|
95
|
-
},
|
|
96
|
+
}, oe = G;
|
|
96
97
|
export {
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
F as ExpanderSize,
|
|
99
|
+
oe as default
|
|
99
100
|
};
|
|
100
101
|
//# sourceMappingURL=Expander.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Expander.js","sources":["../../../src/components/Expander/Expander.tsx"],"sourcesContent":["import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { useExpand } from '../../hooks/useExpand';\nimport { useHover } from '../../hooks/useHover';\nimport { useSticky } from '../../hooks/useSticky';\nimport { PaletteNames } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { IconName } from '../Icons/IconNames';\nimport LazyIcon from '../LazyIcon';\n\nimport styles from './styles.module.scss';\n\nexport enum ExpanderSize {\n small = 'small',\n large = 'large',\n}\n\nexport type ExpanderColors = Extract<PaletteNames, 'banana' | 'blueberry' | 'cherry' | 'kiwi' | 'neutral' | 'plum' | 'white'>;\n\nexport interface ExpanderProps {\n /** Sets the trigger title */\n title: string;\n /** Sets the expanded content */\n children?: React.ReactNode;\n /** Sets the size of the expander. Default: ExpanderSize.small */\n size?: ExpanderSize;\n /** Sets the background of the expander. Requires size=ExpanderSize.large. */\n color?: ExpanderColors;\n /** Adds an icon to the expander trigger. Requires size=ExpanderSize.large. */\n svgIcon?: SvgIcon | IconName;\n /** Opens or closes the expander */\n expanded?: boolean;\n /** Removes border to the left of the content. Requires size=ExpanderSize.small. */\n noNestedLine?: boolean;\n /** Stick expander trigger to top of screen while scrolling down */\n sticky?: boolean;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Whether to render children when closed (in which case they are hidden with CSS). Default: false */\n renderChildrenWhenClosed?: boolean;\n /** Sets the data-testid attribute on the expander button. */\n testId?: string;\n}\n\nconst Expander: React.FC<ExpanderProps> = props => {\n const {\n title,\n children,\n size = ExpanderSize.small,\n color,\n svgIcon: icon,\n expanded = false,\n noNestedLine = false,\n sticky = false,\n testId,\n onExpand,\n renderChildrenWhenClosed = false,\n } = props;\n const [isExpanded, setIsExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered } = useHover(triggerRef);\n const { isOutsideWindow, isLeavingWindow, offsetHeight, contentWidth } = useSticky(expanderRef, triggerRef);\n\n const isSticky = sticky && isExpanded && isOutsideWindow;\n\n const renderChevron = (align: 'left' | 'right') => (\n <span className={classNames(styles['expander__icon'], styles[`expander__icon--${align}`])}>\n <Icon svgIcon={isExpanded ? ChevronUp : ChevronDown} size={IconSize.XSmall} isHovered={isHovered} />\n </span>\n );\n\n const triggerClassName = classNames(\n styles['expander__trigger'],\n size === ExpanderSize.large && styles[`expander__trigger--${size}`],\n size === ExpanderSize.large && styles[`expander__trigger--${color || 'neutral'}`],\n size === ExpanderSize.large && icon && styles['expander__trigger--icon'],\n isExpanded && styles['expander__trigger--expanded'],\n isSticky && !isLeavingWindow && styles['expander__trigger--sticky'],\n isSticky && isLeavingWindow && styles['expander__trigger--absolute']\n );\n\n const renderTrigger = () => (\n <button\n type=\"button\"\n className={triggerClassName}\n style={{\n zIndex: isHovered || isSticky ?
|
|
1
|
+
{"version":3,"file":"Expander.js","sources":["../../../src/components/Expander/Expander.tsx"],"sourcesContent":["import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { useExpand } from '../../hooks/useExpand';\nimport { useHover } from '../../hooks/useHover';\nimport { useSticky } from '../../hooks/useSticky';\nimport { PaletteNames } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { IconName } from '../Icons/IconNames';\nimport LazyIcon from '../LazyIcon';\n\nimport styles from './styles.module.scss';\n\nexport enum ExpanderSize {\n small = 'small',\n large = 'large',\n}\n\nexport type ExpanderColors = Extract<PaletteNames, 'banana' | 'blueberry' | 'cherry' | 'kiwi' | 'neutral' | 'plum' | 'white'>;\n\nexport interface ExpanderProps {\n /** Sets the trigger title */\n title: string;\n /** Sets the expanded content */\n children?: React.ReactNode;\n /** Sets the size of the expander. Default: ExpanderSize.small */\n size?: ExpanderSize;\n /** Sets the background of the expander. Requires size=ExpanderSize.large. */\n color?: ExpanderColors;\n /** Adds an icon to the expander trigger. Requires size=ExpanderSize.large. */\n svgIcon?: SvgIcon | IconName;\n /** Opens or closes the expander */\n expanded?: boolean;\n /** Removes border to the left of the content. Requires size=ExpanderSize.small. */\n noNestedLine?: boolean;\n /** Stick expander trigger to top of screen while scrolling down */\n sticky?: boolean;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Whether to render children when closed (in which case they are hidden with CSS). Default: false */\n renderChildrenWhenClosed?: boolean;\n /** Sets the data-testid attribute on the expander button. */\n testId?: string;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n}\n\nconst Expander: React.FC<ExpanderProps> = props => {\n const {\n title,\n children,\n size = ExpanderSize.small,\n color,\n svgIcon: icon,\n expanded = false,\n noNestedLine = false,\n sticky = false,\n testId,\n onExpand,\n renderChildrenWhenClosed = false,\n zIndex = ZIndex.ExpanderTrigger,\n } = props;\n const [isExpanded, setIsExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered } = useHover(triggerRef);\n const { isOutsideWindow, isLeavingWindow, offsetHeight, contentWidth } = useSticky(expanderRef, triggerRef);\n\n const isSticky = sticky && isExpanded && isOutsideWindow;\n\n const renderChevron = (align: 'left' | 'right'): React.ReactNode => (\n <span className={classNames(styles['expander__icon'], styles[`expander__icon--${align}`])}>\n <Icon svgIcon={isExpanded ? ChevronUp : ChevronDown} size={IconSize.XSmall} isHovered={isHovered} />\n </span>\n );\n\n const triggerClassName = classNames(\n styles['expander__trigger'],\n size === ExpanderSize.large && styles[`expander__trigger--${size}`],\n size === ExpanderSize.large && styles[`expander__trigger--${color || 'neutral'}`],\n size === ExpanderSize.large && icon && styles['expander__trigger--icon'],\n isExpanded && styles['expander__trigger--expanded'],\n isSticky && !isLeavingWindow && styles['expander__trigger--sticky'],\n isSticky && isLeavingWindow && styles['expander__trigger--absolute']\n );\n\n const renderTrigger = (): React.ReactNode => (\n <button\n type=\"button\"\n className={triggerClassName}\n style={{\n zIndex: isHovered || isSticky ? zIndex : undefined,\n width: isSticky && contentWidth ? `${contentWidth}px` : undefined,\n }}\n aria-expanded={isExpanded}\n ref={triggerRef}\n onClick={(): void => setIsExpanded(!isExpanded)}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Expander}\n >\n {size === ExpanderSize.small && renderChevron('left')}\n {icon && (\n <span className={classNames(styles['expander__icon'], styles['expander__icon--left'])}>\n {typeof icon === 'string' ? (\n <LazyIcon iconName={icon} size={IconSize.XSmall} isHovered={isHovered} />\n ) : (\n <Icon svgIcon={icon} size={IconSize.XSmall} isHovered={isHovered} />\n )}\n </span>\n )}\n {title}\n {size === ExpanderSize.large && renderChevron('right')}\n </button>\n );\n\n const buttonClassName = classNames(\n styles['expander__button'],\n isExpanded && styles['expander__button--expanded'],\n isSticky && !isLeavingWindow && styles['expander__button--sticky'],\n isSticky && isLeavingWindow && styles['expander__button--absolute']\n );\n\n const renderButton = (): React.ReactNode => (\n <Button\n variant=\"borderless\"\n className={buttonClassName}\n aria-expanded={isExpanded}\n ref={triggerRef}\n onClick={(): void => setIsExpanded(!isExpanded)}\n testId={testId}\n data-analyticsid={AnalyticsId.Expander}\n >\n <Icon svgIcon={isExpanded ? ChevronUp : ChevronDown} size={IconSize.XSmall} />\n {title}\n </Button>\n );\n\n const renderContent = (): React.ReactNode => {\n if (!renderChildrenWhenClosed && !isExpanded) {\n return null;\n }\n\n const contentClassName = classNames(\n styles['expander__content'],\n styles[`expander__content--${size}`],\n size === ExpanderSize.large && styles[`expander__content--${color || 'neutral'}`],\n size === ExpanderSize.large && icon && styles['expander__content--icon'],\n isExpanded && styles['expander__content--expanded'],\n size === ExpanderSize.small && !noNestedLine && styles['expander__content--nested-line']\n );\n\n return <div className={contentClassName}>{children}</div>;\n };\n\n return (\n <div\n className={styles['expander']}\n ref={expanderRef}\n style={{ paddingTop: isSticky && offsetHeight ? `${offsetHeight}px` : undefined }}\n >\n {size === ExpanderSize.large ? renderTrigger() : renderButton()}\n {renderContent()}\n </div>\n );\n};\n\nexport default Expander;\n"],"names":["ExpanderSize","Expander","props","title","children","size","color","icon","expanded","noNestedLine","sticky","testId","onExpand","renderChildrenWhenClosed","zIndex","ZIndex","isExpanded","setIsExpanded","useExpand","expanderRef","useRef","triggerRef","isHovered","useHover","isOutsideWindow","isLeavingWindow","offsetHeight","contentWidth","useSticky","isSticky","renderChevron","align","React","classNames","styles","Icon","ChevronUp","ChevronDown","IconSize","triggerClassName","renderTrigger","AnalyticsId","LazyIcon","buttonClassName","renderButton","Button","renderContent","contentClassName","Expander$1"],"mappings":";;;;;;;;;;;;AAkBY,IAAAA,sBAAAA,OACVA,EAAA,QAAQ,SACRA,EAAA,QAAQ,SAFEA,IAAAA,KAAA,CAAA,CAAA;AAkCZ,MAAMC,IAAoC,CAASC,MAAA;AAC3C,QAAA;AAAA,IACJ,OAAAC;AAAA,IACA,UAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,OAAAC;AAAA,IACA,SAASC;AAAA,IACT,UAAAC,IAAW;AAAA,IACX,cAAAC,IAAe;AAAA,IACf,QAAAC,IAAS;AAAA,IACT,QAAAC;AAAA,IACA,UAAAC;AAAA,IACA,0BAAAC,IAA2B;AAAA,IAC3B,QAAAC,IAASC,EAAO;AAAA,EACd,IAAAb,GACE,CAACc,GAAYC,CAAa,IAAIC,EAAUV,GAAUI,CAAQ,GAC1DO,IAAcC,EAAuB,IAAI,GACzCC,IAAaD,EAA0B,IAAI,GAC3C,EAAE,WAAAE,EAAA,IAAcC,EAASF,CAAU,GACnC,EAAE,iBAAAG,GAAiB,iBAAAC,GAAiB,cAAAC,GAAc,cAAAC,MAAiBC,EAAUT,GAAaE,CAAU,GAEpGQ,IAAWnB,KAAUM,KAAcQ,GAEnCM,IAAgB,CAACC,MACpBC,gBAAAA,EAAA,cAAA,QAAA,EAAK,WAAWC,EAAWC,EAAO,gBAAmBA,EAAO,mBAAmBH,CAAK,EAAE,CAAC,EAAA,GACrFC,gBAAAA,EAAA,cAAAG,GAAA,EAAK,SAASnB,IAAaoB,IAAYC,GAAa,MAAMC,EAAS,QAAQ,WAAAhB,EAAA,CAAsB,CACpG,GAGIiB,IAAmBN;AAAA,IACvBC,EAAO;AAAA,IACP7B,MAAS,WAA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: no-preference) {
|
|
11
|
-
animation: fade-in 150ms linear forwards;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
&:first-of-type {
|
|
15
11
|
border-top: 1px solid $neutral500;
|
|
16
12
|
}
|
|
@@ -141,19 +137,3 @@
|
|
|
141
137
|
}
|
|
142
138
|
}
|
|
143
139
|
}
|
|
144
|
-
|
|
145
|
-
@keyframes fade-in {
|
|
146
|
-
0% {
|
|
147
|
-
opacity: 0;
|
|
148
|
-
max-height: 0;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
99% {
|
|
152
|
-
max-height: 24rem;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
100% {
|
|
156
|
-
opacity: 1;
|
|
157
|
-
max-height: none;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
@@ -31,6 +31,8 @@ interface ExpanderListProps {
|
|
|
31
31
|
testId?: string;
|
|
32
32
|
/** Sets visual priority */
|
|
33
33
|
variant?: ExpanderListVariant;
|
|
34
|
+
/** Overrides the default z-index of the expander header */
|
|
35
|
+
zIndex?: number;
|
|
34
36
|
}
|
|
35
37
|
type Modify<T, R> = Omit<T, keyof R> & R;
|
|
36
38
|
type ExpanderProps = Modify<React.HTMLAttributes<HTMLButtonElement>, {
|
|
@@ -49,6 +51,8 @@ type ExpanderProps = Modify<React.HTMLAttributes<HTMLButtonElement>, {
|
|
|
49
51
|
handleExpanderClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
50
52
|
/** Called when expander is open/closed. */
|
|
51
53
|
onExpand?: (isExpanded: boolean) => void;
|
|
54
|
+
/** Overrides the default z-index of the expander header */
|
|
55
|
+
zIndex?: number;
|
|
52
56
|
}> & Pick<ExpanderListProps, 'renderChildrenWhenClosed' | 'sticky' | 'variant'>;
|
|
53
57
|
export declare const ExpanderList: ExpanderListCompound;
|
|
54
58
|
export default ExpanderList;
|