@helsenorge/designsystem-react 8.6.0 → 9.0.0-beta.1
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/Button.js +7 -7
- package/Button.js.map +1 -1
- package/CHANGELOG.md +27 -3
- package/Checkbox.js +42 -42
- package/Checkbox.js.map +1 -1
- package/ErrorWrapper.js.map +1 -1
- package/FormGroup.js +47 -40
- package/FormGroup.js.map +1 -1
- package/Icon.js +21 -21
- package/Icon.js.map +1 -1
- package/Input.js +98 -88
- package/Input.js.map +1 -1
- package/Label.js +28 -28
- package/Label.js.map +1 -1
- package/MaxCharacters.js +2 -2
- package/MaxCharacters.js.map +1 -1
- package/RadioButton.js +61 -61
- package/RadioButton.js.map +1 -1
- package/Select.js +34 -33
- package/Select.js.map +1 -1
- package/Slider.js +218 -0
- package/Slider.js.map +1 -0
- package/StatusDot.js +15 -15
- package/StatusDot.js.map +1 -1
- package/TabList.js +88 -53
- package/TabList.js.map +1 -1
- package/TabPanel.js +7 -7
- package/TabPanel.js.map +1 -1
- package/Textarea.js +59 -58
- package/Textarea.js.map +1 -1
- package/Trigger.js +33 -33
- package/Trigger.js.map +1 -1
- package/components/Button/Button.d.ts +2 -2
- package/components/Checkbox/Checkbox.d.ts +4 -3
- package/components/Checkbox/styles.module.scss +0 -14
- package/components/Checkbox/styles.module.scss.d.ts +0 -1
- package/components/Dropdown/Dropdown.d.ts +2 -2
- package/components/Dropdown/index.js +25 -25
- package/components/Dropdown/index.js.map +1 -1
- package/components/ErrorWrapper/ErrorWrapper.d.ts +3 -0
- package/components/ExpanderList/ExpanderList.d.ts +4 -6
- package/components/ExpanderList/index.js +118 -126
- package/components/ExpanderList/index.js.map +1 -1
- package/components/ExpanderList/styles.module.scss +165 -49
- package/components/ExpanderList/styles.module.scss.d.ts +29 -5
- package/components/FormGroup/FormGroup.d.ts +2 -2
- package/components/Icon/Icon.d.ts +4 -4
- package/components/Icons/NoAccess.js +7 -7
- package/components/Icons/NoAccess.js.map +1 -1
- package/components/Input/Input.d.ts +4 -3
- package/components/Label/Label.d.ts +4 -4
- package/components/Label/SubLabel.d.ts +2 -2
- package/components/MaxCharacters/MaxCharacters.d.ts +2 -2
- package/components/RadioButton/RadioButton.d.ts +5 -4
- package/components/RadioButton/styles.module.scss +0 -15
- package/components/RadioButton/styles.module.scss.d.ts +0 -1
- package/components/Select/Select.d.ts +4 -3
- package/components/SharingStatus/SharingStatus.d.ts +1 -1
- package/components/SharingStatus/index.js +5 -5
- package/components/SharingStatus/index.js.map +1 -1
- package/components/SharingStatus/styles.module.scss +0 -16
- package/components/SharingStatus/styles.module.scss.d.ts +0 -4
- package/components/Slider/Slider.d.ts +9 -4
- package/components/Slider/index.js +3 -189
- package/components/Slider/index.js.map +1 -1
- package/components/Slider/styles.module.scss +19 -6
- package/components/Slider/styles.module.scss.d.ts +3 -0
- package/components/StatusDot/StatusDot.d.ts +3 -3
- package/components/StatusDot/index.js +3 -3
- package/components/Tabs/TabList/TabList.d.ts +3 -3
- package/components/Tabs/TabList/styles.module.scss +63 -51
- package/components/Tabs/TabList/styles.module.scss.d.ts +7 -3
- package/components/Tabs/TabPanel/TabPanel.d.ts +1 -2
- package/components/Tabs/TabPanel/styles.module.scss +11 -26
- package/components/Tabs/TabPanel/styles.module.scss.d.ts +0 -2
- package/components/Tabs/Tabs.d.ts +3 -3
- package/components/Tabs/index.js +60 -75
- package/components/Tabs/index.js.map +1 -1
- package/components/Tabs/styles.module.scss +5 -9
- package/components/Tabs/styles.module.scss.d.ts +0 -1
- package/components/Textarea/Textarea.d.ts +4 -3
- package/components/Toggle/index.js +1204 -1170
- package/components/Toggle/index.js.map +1 -1
- package/components/Trigger/Trigger.d.ts +2 -2
- package/components/Validation/index.js +39 -32
- package/components/Validation/index.js.map +1 -1
- package/constants.d.ts +1 -1
- package/constants.js +1 -1
- package/constants.js.map +1 -1
- package/docs/FormExample/FormExample.d.ts +3 -1
- package/index.js +23 -23
- package/package.json +4 -4
- package/utils/component.d.ts +1 -0
- package/utils/component.js +7 -3
- package/utils/component.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.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 ZIndex,\n theme,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\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. Visible for screen readers */\n label: string;\n /** Text on the trigger button that opens the dropdown */\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 /** Whether the dropdown is open or not */\n open?: boolean;\n /** Changes the visuals of the dropdown */\n mode?: keyof typeof DropdownMode;\n /** Makes the background of the trigger transparent */\n transparent?: boolean;\n /** Makes the width of the full component adjust to its parent */\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 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%' : `auto`, 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} 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","labelId","useUuid","toggleLabelId","optionIdPrefix","handleOpen","_a","handleClose","useKeyboardEvent","event","KeyboardEventKey","index","x","nextIndex","useOutsideEvent","toggleClasses","classNames","styles","contentClasses","renderChildren","child","jsx","mergeRefs","jsxs","AnalyticsId","Icon","theme","PlusSmall","IconSize","Button"],"mappings":";;;;;;;;;;;;;;;;AAuBY,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,GACnDC,IAAUC,KACVC,IAAgB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c;AAAA,QACd,iBAAeV;AAAA,QAEf,UAAA;AAAA,UAAA,gBAAA4B,EAAC,UAAK,IAAIlB,GAAe,WAAWc,EAAO,yBACxC,UACH3C,GAAA;AAAA,UACA,gBAAA+C;AAAA,YAACI;AAAA,YAAA;AAAA,cACC,OAAOzC,IAAW0C,EAAM,QAAQ,aAAaA,EAAM,QAAQ;AAAA,cAC3D,SAASC;AAAA,cACT,WAAWV,EAAO;AAAA,cAClB,WAAW,CAACjC,KAAYO;AAAA,cACxB,MAAMqC,EAAS;AAAA,YAAA;AAAA,UACjB;AAAA,QAAA;AAAA,MAAA;AAAA,IACF;AAAA,IACA,gBAAAL,EAAC,OAAI,EAAA,WAAWL,GAAgB,OAAO,EAAE,OAAOpC,IAAQ,SAAS,QAAQ,QAAAG,EAAA,GACvE,UAAA;AAAA,MAAA,gBAAAoC;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAWJ,EAAO;AAAA,UAClB,MAAK;AAAA,UACL,mBAAiBhB;AAAA,UACjB,UAAU;AAAA,UACV,yBAAuB,OAAOH,IAAiB,MAAc,GAAGM,CAAc,IAAIN,CAAY,KAAK;AAAA,UACnG,KAAKT;AAAA,UAEJ,UAAA8B;AAAA,QAAA;AAAA,MACH;AAAA,MACC,CAAC3C,KACC,gBAAA6C,EAAA,OAAA,EAAI,WAAWJ,EAAO,iBACrB,UAAC,gBAAAI,EAAAQ,IAAA,EAAO,SAAStB,GAAa,iBAAed,GAC1C,YACH,CAAA,GACF;AAAA,IAAA,GAEJ;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"index.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 ZIndex,\n theme,\n useHover,\n useKeyboardEvent,\n useOutsideEvent,\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 DropdownOnColor {\n onwhite = 'onwhite',\n ongrey = 'ongrey',\n onblueberry = 'onblueberry',\n oncherry = 'oncherry',\n}\n\nexport interface DropdownProps {\n /** Label for dropdown. Visible for screen readers */\n label: string;\n /** Text on the trigger button that opens the dropdown */\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 /** Whether the dropdown is open or not */\n open?: boolean;\n /** Changes the visuals of the dropdown */\n onColor?: keyof typeof DropdownOnColor;\n /** Makes the background of the trigger transparent */\n transparent?: boolean;\n /** Makes the width of the full component adjust to its parent */\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 onColor = DropdownOnColor.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 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']]: onColor === DropdownOnColor.onwhite,\n [styles['dropdown__toggle--on-grey']]: onColor === DropdownOnColor.ongrey,\n [styles['dropdown__toggle--on-blueberry']]: onColor === DropdownOnColor.onblueberry,\n [styles['dropdown__toggle--on-cherry']]: onColor === DropdownOnColor.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%' : `auto`, 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} aria-expanded={isOpen}>\n {closeText}\n </Button>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default Dropdown;\n"],"names":["DropdownOnColor","Dropdown","props","label","placeholder","closeText","noCloseButton","onToggle","open","children","onColor","transparent","fluid","testId","disabled","zIndex","ZIndex","dropdownRef","useRef","optionsRef","buttonRef","isHovered","useHover","isOpen","toggleIsOpen","useToggle","inputRefList","React","currentIndex","setCurrentIndex","useState","labelId","useUuid","toggleLabelId","optionIdPrefix","handleOpen","_a","handleClose","useKeyboardEvent","event","KeyboardEventKey","index","x","nextIndex","useOutsideEvent","toggleClasses","classNames","styles","contentClasses","renderChildren","child","jsx","mergeRefs","jsxs","AnalyticsId","Icon","theme","PlusSmall","IconSize","Button"],"mappings":";;;;;;;;;;;;;;;;AAuBY,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,SAAAC,IAAU;AAAA,IACV,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,GACnDC,IAAUC,KACVC,IAAgBD,KAChBE,IAAiBF,KAEjBG,IAAa,MAAY;;AAChB,IAAAX,MACbY,IAAAjB,EAAW,YAAX,QAAAiB,EAAoB;AAAA,EAAM,GAGtBC,IAAc,MAAY;;AACjB,IAAAb,MACbY,IAAAhB,EAAU,YAAV,QAAAgB,EAAmB;AAAA,EAAM;AAsC3B,EAAAE,EAAiBrB,GAnCgB,CAACsB,MAA+B;;AAG3D,QAFJA,EAAM,eAAe,GAEjB,CAACb,EAAa;AAChB;AAGF,QAA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A,cACxB,MAAMqC,EAAS;AAAA,YAAA;AAAA,UACjB;AAAA,QAAA;AAAA,MAAA;AAAA,IACF;AAAA,IACA,gBAAAL,EAAC,OAAI,EAAA,WAAWL,GAAgB,OAAO,EAAE,OAAOpC,IAAQ,SAAS,QAAQ,QAAAG,EAAA,GACvE,UAAA;AAAA,MAAA,gBAAAoC;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAWJ,EAAO;AAAA,UAClB,MAAK;AAAA,UACL,mBAAiBhB;AAAA,UACjB,UAAU;AAAA,UACV,yBAAuB,OAAOH,IAAiB,MAAc,GAAGM,CAAc,IAAIN,CAAY,KAAK;AAAA,UACnG,KAAKT;AAAA,UAEJ,UAAA8B;AAAA,QAAA;AAAA,MACH;AAAA,MACC,CAAC3C,KACC,gBAAA6C,EAAA,OAAA,EAAI,WAAWJ,EAAO,iBACrB,UAAC,gBAAAI,EAAAQ,IAAA,EAAO,SAAStB,GAAa,iBAAed,GAC1C,YACH,CAAA,GACF;AAAA,IAAA,GAEJ;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
@@ -2,14 +2,14 @@ import React from 'react';
|
|
|
2
2
|
import { PaletteNames } from '../../theme/palette';
|
|
3
3
|
import { ListHeaderType } from '../ListHeader/ListHeader';
|
|
4
4
|
import { TitleTags } from '../Title';
|
|
5
|
-
export type ExpanderListColors = PaletteNames
|
|
5
|
+
export type ExpanderListColors = Extract<PaletteNames, 'white' | 'blueberry' | 'cherry' | 'neutral'>;
|
|
6
6
|
export interface ExpanderType extends React.ForwardRefExoticComponent<ExpanderProps & React.RefAttributes<HTMLLIElement>> {
|
|
7
7
|
ListHeader?: ListHeaderType;
|
|
8
8
|
}
|
|
9
9
|
export interface ExpanderListCompound extends React.ForwardRefExoticComponent<ExpanderListProps & React.RefAttributes<HTMLUListElement>> {
|
|
10
10
|
Expander: ExpanderType;
|
|
11
11
|
}
|
|
12
|
-
export type ExpanderListVariant = 'line' | 'outline' | 'fill';
|
|
12
|
+
export type ExpanderListVariant = 'line' | 'outline' | 'fill' | 'fill-negative';
|
|
13
13
|
interface ExpanderListProps {
|
|
14
14
|
/** Toggles accordion functionality for the expanders. */
|
|
15
15
|
accordion?: boolean;
|
|
@@ -19,14 +19,12 @@ interface ExpanderListProps {
|
|
|
19
19
|
childPadding?: boolean;
|
|
20
20
|
/** Adds custom classes to the element. */
|
|
21
21
|
className?: string;
|
|
22
|
-
/** Changes the
|
|
22
|
+
/** Changes the colors of the list. */
|
|
23
23
|
color?: ExpanderListColors;
|
|
24
24
|
/** Changes the font size. */
|
|
25
25
|
large?: boolean;
|
|
26
26
|
/** Whether to render children when closed (in which case they are hidden with CSS). Default: false */
|
|
27
27
|
renderChildrenWhenClosed?: boolean;
|
|
28
|
-
/** Stick expander trigger to top of screen while scrolling down */
|
|
29
|
-
sticky?: boolean;
|
|
30
28
|
/** Sets the data-testid attribute. */
|
|
31
29
|
testId?: string;
|
|
32
30
|
/** Sets visual priority */
|
|
@@ -53,6 +51,6 @@ type ExpanderProps = Modify<React.HTMLAttributes<HTMLButtonElement>, {
|
|
|
53
51
|
onExpand?: (isExpanded: boolean) => void;
|
|
54
52
|
/** Overrides the default z-index of the expander header */
|
|
55
53
|
zIndex?: number;
|
|
56
|
-
}> & Pick<ExpanderListProps, 'renderChildrenWhenClosed' | '
|
|
54
|
+
}> & Pick<ExpanderListProps, 'renderChildrenWhenClosed' | 'variant'>;
|
|
57
55
|
export declare const ExpanderList: ExpanderListCompound;
|
|
58
56
|
export default ExpanderList;
|
|
@@ -1,142 +1,134 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { AnalyticsId as
|
|
5
|
-
import { useExpand as
|
|
6
|
-
import { useHover as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
const b = m.forwardRef((d, g) => {
|
|
1
|
+
import { jsxs as M, jsx as H } from "react/jsx-runtime";
|
|
2
|
+
import c, { useRef as z, useState as A, useEffect as V } from "react";
|
|
3
|
+
import _ from "classnames";
|
|
4
|
+
import { AnalyticsId as j, ZIndex as O } from "../../constants.js";
|
|
5
|
+
import { useExpand as P } from "../../hooks/useExpand.js";
|
|
6
|
+
import { useHover as Z } from "../../hooks/useHover.js";
|
|
7
|
+
import { useUuid as q } from "../../hooks/useUuid.js";
|
|
8
|
+
import { mergeRefs as B } from "../../utils/refs.js";
|
|
9
|
+
import { isElementInViewport as G } from "../../utils/viewport.js";
|
|
10
|
+
import J from "../Icons/ChevronDown.js";
|
|
11
|
+
import K from "../Icons/ChevronUp.js";
|
|
12
|
+
import { r as Q } from "../../ListHeader.js";
|
|
13
|
+
import e from "./styles.module.scss";
|
|
14
|
+
const v = c.forwardRef((o, k) => {
|
|
16
15
|
const {
|
|
17
|
-
id:
|
|
18
|
-
children:
|
|
19
|
-
padding:
|
|
20
|
-
color:
|
|
21
|
-
className:
|
|
22
|
-
icon:
|
|
23
|
-
large:
|
|
16
|
+
id: f,
|
|
17
|
+
children: g,
|
|
18
|
+
padding: C = !0,
|
|
19
|
+
color: r = "neutral",
|
|
20
|
+
className: h = "",
|
|
21
|
+
icon: y,
|
|
22
|
+
large: p = !1,
|
|
24
23
|
title: N,
|
|
25
|
-
titleHtmlMarkup:
|
|
26
|
-
expanded:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
24
|
+
titleHtmlMarkup: $ = "span",
|
|
25
|
+
expanded: I = !1,
|
|
26
|
+
testId: x,
|
|
27
|
+
handleExpanderClick: u,
|
|
28
|
+
onExpand: m,
|
|
29
|
+
renderChildrenWhenClosed: L,
|
|
30
|
+
variant: d = "line",
|
|
31
|
+
zIndex: R
|
|
32
|
+
} = o, [l] = P(I, m), E = z(null), t = z(null), { isHovered: i } = Z(t), n = d === "fill", s = d === "fill-negative", a = d === "outline", w = d === "line", T = _(h, e["expander-list__item"], {
|
|
33
|
+
[e["expander-list__item--fill"]]: n,
|
|
34
|
+
[e[`expander-list__item--fill--${r}`]]: n,
|
|
35
|
+
[e["expander-list__item--fill-negative"]]: s,
|
|
36
|
+
[e["expander-list__item--outline"]]: a,
|
|
37
|
+
[e[`expander-list__item--outline--${r}`]]: a,
|
|
38
|
+
[e["expander-list__item--line"]]: w,
|
|
39
|
+
[e[`expander-list__item--line--${r}`]]: w
|
|
40
|
+
}), U = _(e["expander-list-link"], e[`expander-list-link--${r}`], {
|
|
41
|
+
[e["expander-list-link--fill"]]: n,
|
|
42
|
+
[e[`expander-list-link--fill--${r}`]]: n,
|
|
43
|
+
[e["expander-list-link--fill-negative"]]: s,
|
|
44
|
+
[e["expander-list-link--outline"]]: a,
|
|
45
|
+
[e[`expander-list-link--outline--${r}`]]: a,
|
|
46
|
+
[e[`expander-list-link--line--${r}`]]: w,
|
|
47
|
+
[e["expander-list-link--closed"]]: !l,
|
|
48
|
+
[e["expander-list-link--open"]]: l,
|
|
49
|
+
[e["expander-list-link--large"]]: p
|
|
50
|
+
}), W = () => {
|
|
51
|
+
if (!L && !l)
|
|
49
52
|
return null;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const D = _(
|
|
54
|
+
e["expander-list-link__main-content"],
|
|
55
|
+
l && e["expander-list-link__main-content--expanded"],
|
|
56
|
+
C ? e["expander-list-link__main-content--padding"] : ""
|
|
54
57
|
);
|
|
55
|
-
return /* @__PURE__ */
|
|
58
|
+
return /* @__PURE__ */ H("div", { className: D, children: g });
|
|
56
59
|
};
|
|
57
|
-
return /* @__PURE__ */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
children: S(N, _, n, l ? "large" : "medium", i ? Y : X, L)
|
|
80
|
-
}
|
|
81
|
-
),
|
|
82
|
-
O()
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
}), j = (d) => m.isValidElement(d) && d.type === b, U = m.forwardRef((d, g) => {
|
|
60
|
+
return /* @__PURE__ */ M("li", { className: T, ref: B([k, E]), children: [
|
|
61
|
+
/* @__PURE__ */ H(
|
|
62
|
+
"button",
|
|
63
|
+
{
|
|
64
|
+
type: "button",
|
|
65
|
+
id: f,
|
|
66
|
+
onClick: u,
|
|
67
|
+
"data-testid": x,
|
|
68
|
+
"data-analyticsid": j.ExpanderListExpander,
|
|
69
|
+
className: U,
|
|
70
|
+
ref: t,
|
|
71
|
+
"aria-expanded": l,
|
|
72
|
+
style: {
|
|
73
|
+
zIndex: i ? R : void 0
|
|
74
|
+
},
|
|
75
|
+
children: Q(N, $, i, p ? "large" : "medium", l ? K : J, y)
|
|
76
|
+
}
|
|
77
|
+
),
|
|
78
|
+
W()
|
|
79
|
+
] });
|
|
80
|
+
}), b = (o) => c.isValidElement(o) && o.type === v, F = c.forwardRef((o, k) => {
|
|
87
81
|
const {
|
|
88
|
-
children:
|
|
89
|
-
childPadding:
|
|
90
|
-
large:
|
|
91
|
-
renderChildrenWhenClosed:
|
|
92
|
-
color:
|
|
93
|
-
className:
|
|
94
|
-
accordion:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
k((e) => l ? { [n]: !(e != null && e[n]) } : { ...e, [n]: !(e != null && e[n]) }), R(t.currentTarget);
|
|
82
|
+
children: f,
|
|
83
|
+
childPadding: g = !0,
|
|
84
|
+
large: C,
|
|
85
|
+
renderChildrenWhenClosed: r = !1,
|
|
86
|
+
color: h,
|
|
87
|
+
className: y = "",
|
|
88
|
+
accordion: p = !1,
|
|
89
|
+
testId: N,
|
|
90
|
+
variant: $,
|
|
91
|
+
zIndex: I = O.ExpanderTrigger
|
|
92
|
+
} = o, [x, u] = A(), [m, L] = A(), d = q(), R = _(e["expander-list"], y);
|
|
93
|
+
function l(t, i) {
|
|
94
|
+
u((n) => p ? { [i]: !(n != null && n[i]) } : { ...n, [i]: !(n != null && n[i]) }), L(t.currentTarget);
|
|
102
95
|
}
|
|
103
|
-
const
|
|
96
|
+
const E = (t) => `${d}-${t}`;
|
|
104
97
|
return V(() => {
|
|
105
|
-
|
|
106
|
-
}, [
|
|
107
|
-
var
|
|
108
|
-
const t = (
|
|
109
|
-
if (
|
|
110
|
-
return
|
|
111
|
-
})) == null ? void 0 :
|
|
112
|
-
|
|
113
|
-
}, [
|
|
114
|
-
if (
|
|
115
|
-
const
|
|
116
|
-
return
|
|
117
|
-
id:
|
|
118
|
-
key:
|
|
119
|
-
expanded:
|
|
120
|
-
padding:
|
|
121
|
-
color:
|
|
122
|
-
large:
|
|
123
|
-
|
|
124
|
-
"
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
zIndex: $
|
|
98
|
+
p && m && !G(m) && m.scrollIntoView();
|
|
99
|
+
}, [p, m]), V(() => {
|
|
100
|
+
var i;
|
|
101
|
+
const t = (i = c.Children.map(f, (n) => {
|
|
102
|
+
if (b(n))
|
|
103
|
+
return n;
|
|
104
|
+
})) == null ? void 0 : i.reduce((n, s, a) => (typeof s.props.expanded < "u" && (n[E(a)] = s.props.expanded), n), {});
|
|
105
|
+
u({ ...x, ...t });
|
|
106
|
+
}, [f]), /* @__PURE__ */ H("ul", { className: R, ref: k, "data-testid": N, "data-analyticsid": j.ExpanderList, children: c.Children.map(f, (t, i) => {
|
|
107
|
+
if (b(t)) {
|
|
108
|
+
const n = E(i), s = x == null ? void 0 : x[n];
|
|
109
|
+
return c.cloneElement(t, {
|
|
110
|
+
id: n,
|
|
111
|
+
key: i,
|
|
112
|
+
expanded: s,
|
|
113
|
+
padding: g,
|
|
114
|
+
color: h,
|
|
115
|
+
large: C,
|
|
116
|
+
"aria-expanded": s,
|
|
117
|
+
className: e["expander-list__item"],
|
|
118
|
+
handleExpanderClick: (a) => l(a, `${d}-${i}`),
|
|
119
|
+
renderChildrenWhenClosed: r,
|
|
120
|
+
variant: $,
|
|
121
|
+
zIndex: I
|
|
130
122
|
});
|
|
131
123
|
}
|
|
132
124
|
return t;
|
|
133
125
|
}) });
|
|
134
126
|
});
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
F.displayName = "ExpanderList";
|
|
128
|
+
F.Expander = v;
|
|
129
|
+
v.displayName = "ExpanderList.Expander";
|
|
138
130
|
export {
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
F as ExpanderList,
|
|
132
|
+
F as default
|
|
141
133
|
};
|
|
142
134
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/ExpanderList/ExpanderList.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } 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 { useUuid } from '../../hooks/useUuid';\nimport { PaletteNames } from '../../theme/palette';\nimport { mergeRefs } from '../../utils/refs';\nimport { isElementInViewport } from '../../utils/viewport';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { ListHeaderType, renderListHeader } from '../ListHeader/ListHeader';\nimport { TitleTags } from '../Title';\n\nimport expanderListStyles from './styles.module.scss';\n\nexport type ExpanderListColors = PaletteNames;\nexport interface ExpanderType extends React.ForwardRefExoticComponent<ExpanderProps & React.RefAttributes<HTMLLIElement>> {\n ListHeader?: ListHeaderType;\n}\n\nexport interface ExpanderListCompound extends React.ForwardRefExoticComponent<ExpanderListProps & React.RefAttributes<HTMLUListElement>> {\n Expander: ExpanderType;\n}\n\nexport type ExpanderListVariant = 'line' | 'outline' | 'fill';\n\ninterface ExpanderListProps {\n /** Toggles accordion functionality for the expanders. */\n accordion?: boolean;\n /** Items in the ExpanderList */\n children: React.ReactNode;\n /** Toggles padding of child elements */\n childPadding?: boolean;\n /** Adds custom classes to the element. */\n className?: string;\n /** Changes the link list background color on hover. */\n color?: ExpanderListColors;\n /** Changes the font size. */\n large?: boolean;\n /** Whether to render children when closed (in which case they are hidden with CSS). Default: false */\n renderChildrenWhenClosed?: boolean;\n /** Stick expander trigger to top of screen while scrolling down */\n sticky?: boolean;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Sets visual priority */\n variant?: ExpanderListVariant;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n}\n\ntype Modify<T, R> = Omit<T, keyof R> & R;\n\ntype ExpanderProps = Modify<\n React.HTMLAttributes<HTMLButtonElement>,\n {\n id?: string;\n title: JSX.Element | string;\n /** Changes the underlying element of the title. Default: span*/\n titleHtmlMarkup?: TitleTags;\n children: React.ReactNode;\n className?: string;\n color?: ExpanderListColors;\n icon?: React.ReactElement;\n padding?: boolean;\n expanded?: boolean;\n large?: boolean;\n testId?: string;\n handleExpanderClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n }\n> &\n Pick<ExpanderListProps, 'renderChildrenWhenClosed' | 'sticky' | 'variant'>;\n\nconst Expander: ExpanderType = React.forwardRef<HTMLLIElement, ExpanderProps>((props, ref) => {\n const {\n id,\n children,\n padding = true,\n color = 'neutral',\n className = '',\n icon,\n large = false,\n title,\n titleHtmlMarkup = 'span',\n expanded = false,\n sticky,\n testId,\n handleExpanderClick,\n onExpand,\n renderChildrenWhenClosed,\n variant = 'line',\n zIndex,\n } = props;\n const [isExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLLIElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered } = useHover(triggerRef);\n\n const { isOutsideWindow, isLeavingWindow, offsetHeight, contentWidth } = useSticky(expanderRef, triggerRef);\n const isSticky = sticky && isExpanded && isOutsideWindow;\n\n const itemClasses = classNames(\n className,\n (variant === 'line' || variant === 'outline') && expanderListStyles[`expander-list__item--${variant}`]\n );\n\n const expanderClasses = classNames(\n expanderListStyles['expander-list-link'],\n color !== 'black' && expanderListStyles[`expander-list-link--${color}`],\n {\n [expanderListStyles['expander-list-link--fill']]: variant === 'fill',\n [expanderListStyles['expander-list-link--closed']]: !isExpanded,\n [expanderListStyles['expander-list-link--large']]: large,\n [expanderListStyles['expander-list-link--sticky']]: isSticky && !isLeavingWindow,\n [expanderListStyles['expander-list-link--absolute']]: isSticky && isLeavingWindow,\n }\n );\n\n const renderContent = (): React.ReactNode => {\n if (!renderChildrenWhenClosed && !isExpanded) {\n return null;\n }\n\n const mainContentClasses = classNames(\n expanderListStyles['expander-list-link__main-content'],\n isExpanded && expanderListStyles['expander-list-link__main-content--expanded'],\n padding ? expanderListStyles['expander-list-link__main-content--padding'] : ''\n );\n\n return <div className={mainContentClasses}>{children}</div>;\n };\n\n return (\n <li\n className={itemClasses}\n ref={mergeRefs([ref, expanderRef])}\n style={{ paddingTop: isSticky && offsetHeight ? `${offsetHeight}px` : undefined }}\n >\n <button\n type=\"button\"\n id={id}\n onClick={handleExpanderClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.ExpanderListExpander}\n className={expanderClasses}\n ref={triggerRef}\n aria-expanded={isExpanded}\n style={{\n zIndex: isHovered || isSticky ? zIndex : undefined,\n width: isSticky && contentWidth ? `${contentWidth}px` : undefined,\n }}\n >\n {renderListHeader(title, titleHtmlMarkup, isHovered, large ? 'large' : 'medium', isExpanded ? ChevronUp : ChevronDown, icon)}\n </button>\n {renderContent()}\n </li>\n );\n});\n\ntype ActiveExpander = Record<string, boolean>;\n\nconst isExpanderComponent = (element: {} | null | undefined): element is React.ReactElement<ExpanderProps> =>\n React.isValidElement<ExpanderProps>(element) && (element as React.ReactElement).type === Expander;\n\nexport const ExpanderList = React.forwardRef((props: ExpanderListProps, ref: React.Ref<HTMLUListElement>) => {\n const {\n children,\n childPadding = true,\n large,\n renderChildrenWhenClosed = false,\n color,\n className = '',\n accordion = false,\n sticky = false,\n testId,\n variant,\n zIndex = ZIndex.ExpanderTrigger,\n } = props;\n const [activeExpander, setActiveExpander] = useState<ActiveExpander>();\n const [latestExpander, setLatestExpander] = useState<HTMLElement>();\n const uuid = useUuid();\n const expanderListClasses = classNames(expanderListStyles['expander-list'], className);\n\n function handleExpanderClick(event: React.MouseEvent<HTMLElement, MouseEvent>, id: string): void {\n setActiveExpander(prevState => (accordion ? { [id]: !prevState?.[id] } : { ...prevState, [id]: !prevState?.[id] }));\n setLatestExpander(event.currentTarget);\n }\n\n const getExpanderId = (index: number): string => `${uuid}-${index}`;\n\n useEffect(() => {\n if (accordion && latestExpander && !isElementInViewport(latestExpander)) {\n latestExpander.scrollIntoView();\n }\n }, [accordion, latestExpander]);\n\n useEffect(() => {\n const newActiveExpander = React.Children.map(children, child => {\n if (isExpanderComponent(child)) {\n return child;\n }\n })?.reduce((acc, child, index) => {\n // Expanded-status skal bare settes dersom prop er satt av den som bruker komponenten\n if (typeof child.props.expanded !== 'undefined') {\n acc[getExpanderId(index)] = child.props.expanded;\n }\n return acc;\n }, {} as ActiveExpander);\n\n setActiveExpander({ ...activeExpander, ...newActiveExpander });\n }, [children]);\n\n return (\n <ul className={expanderListClasses} ref={ref} data-testid={testId} data-analyticsid={AnalyticsId.ExpanderList}>\n {React.Children.map(children, (child, index) => {\n if (isExpanderComponent(child)) {\n const id = getExpanderId(index);\n const expanded = activeExpander?.[id];\n\n return React.cloneElement(child as React.ReactElement<ExpanderProps>, {\n id,\n key: index,\n expanded,\n padding: childPadding,\n color,\n large,\n sticky,\n 'aria-expanded': expanded,\n className: expanderListStyles['expander-list__item'],\n handleExpanderClick: (event: React.MouseEvent<HTMLElement>) => handleExpanderClick(event, `${uuid}-${index}`),\n renderChildrenWhenClosed,\n variant,\n zIndex: zIndex,\n });\n }\n return child;\n })}\n </ul>\n );\n}) as ExpanderListCompound;\n\nExpanderList.displayName = 'ExpanderList';\nExpanderList.Expander = Expander;\nExpander.displayName = 'ExpanderList.Expander';\n\nexport default ExpanderList;\n"],"names":["Expander","React","props","ref","id","children","padding","color","className","icon","large","title","titleHtmlMarkup","expanded","sticky","testId","handleExpanderClick","onExpand","renderChildrenWhenClosed","variant","zIndex","isExpanded","useExpand","expanderRef","useRef","triggerRef","isHovered","useHover","isOutsideWindow","isLeavingWindow","offsetHeight","contentWidth","useSticky","isSticky","itemClasses","classNames","expanderListStyles","expanderClasses","renderContent","mainContentClasses","jsx","jsxs","mergeRefs","AnalyticsId","renderListHeader","ChevronUp","ChevronDown","isExpanderComponent","element","ExpanderList","childPadding","accordion","ZIndex","activeExpander","setActiveExpander","useState","latestExpander","setLatestExpander","uuid","useUuid","expanderListClasses","event","prevState","getExpanderId","index","useEffect","isElementInViewport","newActiveExpander","_a","child","acc"],"mappings":";;;;;;;;;;;;;;AAiFA,MAAMA,IAAyBC,EAAM,WAAyC,CAACC,GAAOC,MAAQ;AACtF,QAAA;AAAA,IACJ,IAAAC;AAAA,IACA,UAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,OAAAC,IAAQ;AAAA,IACR,WAAAC,IAAY;AAAA,IACZ,MAAAC;AAAA,IACA,OAAAC,IAAQ;AAAA,IACR,OAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IA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AM,aAAaoE,GAA4C;AAAA,QACpE,IAAAjE;AAAA,QACA,KAAK4D;AAAA,QACL,UAAAnD;AAAA,QACA,SAASqC;AAAA,QACT,OAAA3C;AAAA,QACA,OAAAG;AAAA,QACA,QAAAI;AAAA,QACA,iBAAiBD;AAAA,QACjB,WAAWuB,EAAmB,qBAAqB;AAAA,QACnD,qBAAqB,CAACyB,MAAyC7C,EAAoB6C,GAAO,GAAGH,CAAI,IAAIM,CAAK,EAAE;AAAA,QAC5G,0BAAA9C;AAAA,QACA,SAAAC;AAAA,QACA,QAAAC;AAAA,MAAA,CACD;AAAA,IACH;AACO,WAAAiD;AAAA,EACR,CAAA,EACH,CAAA;AAEJ,CAAC;AAEDpB,EAAa,cAAc;AAC3BA,EAAa,WAAWjD;AACxBA,EAAS,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/ExpanderList/ExpanderList.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, ZIndex } from '../../constants';\nimport { useExpand } from '../../hooks/useExpand';\nimport { useHover } from '../../hooks/useHover';\nimport { useUuid } from '../../hooks/useUuid';\nimport { PaletteNames } from '../../theme/palette';\nimport { mergeRefs } from '../../utils/refs';\nimport { isElementInViewport } from '../../utils/viewport';\nimport ChevronDown from '../Icons/ChevronDown';\nimport ChevronUp from '../Icons/ChevronUp';\nimport { ListHeaderType, renderListHeader } from '../ListHeader/ListHeader';\nimport { TitleTags } from '../Title';\n\nimport expanderListStyles from './styles.module.scss';\n\nexport type ExpanderListColors = Extract<PaletteNames, 'white' | 'blueberry' | 'cherry' | 'neutral'>;\nexport interface ExpanderType extends React.ForwardRefExoticComponent<ExpanderProps & React.RefAttributes<HTMLLIElement>> {\n ListHeader?: ListHeaderType;\n}\n\nexport interface ExpanderListCompound extends React.ForwardRefExoticComponent<ExpanderListProps & React.RefAttributes<HTMLUListElement>> {\n Expander: ExpanderType;\n}\n\nexport type ExpanderListVariant = 'line' | 'outline' | 'fill' | 'fill-negative';\n\ninterface ExpanderListProps {\n /** Toggles accordion functionality for the expanders. */\n accordion?: boolean;\n /** Items in the ExpanderList */\n children: React.ReactNode;\n /** Toggles padding of child elements */\n childPadding?: boolean;\n /** Adds custom classes to the element. */\n className?: string;\n /** Changes the colors of the list. */\n color?: ExpanderListColors;\n /** Changes the font size. */\n large?: boolean;\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. */\n testId?: string;\n /** Sets visual priority */\n variant?: ExpanderListVariant;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n}\n\ntype Modify<T, R> = Omit<T, keyof R> & R;\n\ntype ExpanderProps = Modify<\n React.HTMLAttributes<HTMLButtonElement>,\n {\n id?: string;\n title: JSX.Element | string;\n /** Changes the underlying element of the title. Default: span*/\n titleHtmlMarkup?: TitleTags;\n children: React.ReactNode;\n className?: string;\n color?: ExpanderListColors;\n icon?: React.ReactElement;\n padding?: boolean;\n expanded?: boolean;\n large?: boolean;\n testId?: string;\n handleExpanderClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Called when expander is open/closed. */\n onExpand?: (isExpanded: boolean) => void;\n /** Overrides the default z-index of the expander header */\n zIndex?: number;\n }\n> &\n Pick<ExpanderListProps, 'renderChildrenWhenClosed' | 'variant'>;\n\nconst Expander: ExpanderType = React.forwardRef<HTMLLIElement, ExpanderProps>((props, ref) => {\n const {\n id,\n children,\n padding = true,\n color = 'neutral',\n className = '',\n icon,\n large = false,\n title,\n titleHtmlMarkup = 'span',\n expanded = false,\n testId,\n handleExpanderClick,\n onExpand,\n renderChildrenWhenClosed,\n variant = 'line',\n zIndex,\n } = props;\n const [isExpanded] = useExpand(expanded, onExpand);\n const expanderRef = useRef<HTMLLIElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const { isHovered } = useHover(triggerRef);\n\n const isFill = variant === 'fill';\n const isFillNegative = variant === 'fill-negative';\n const isOutline = variant === 'outline';\n const isLine = variant === 'line';\n\n const itemClasses = classNames(className, expanderListStyles['expander-list__item'], {\n [expanderListStyles[`expander-list__item--fill`]]: isFill,\n [expanderListStyles[`expander-list__item--fill--${color}`]]: isFill,\n [expanderListStyles[`expander-list__item--fill-negative`]]: isFillNegative,\n [expanderListStyles['expander-list__item--outline']]: isOutline,\n [expanderListStyles[`expander-list__item--outline--${color}`]]: isOutline,\n [expanderListStyles['expander-list__item--line']]: isLine,\n [expanderListStyles[`expander-list__item--line--${color}`]]: isLine,\n });\n\n const expanderClasses = classNames(expanderListStyles['expander-list-link'], expanderListStyles[`expander-list-link--${color}`], {\n [expanderListStyles[`expander-list-link--fill`]]: isFill,\n [expanderListStyles[`expander-list-link--fill--${color}`]]: isFill,\n [expanderListStyles[`expander-list-link--fill-negative`]]: isFillNegative,\n [expanderListStyles['expander-list-link--outline']]: isOutline,\n [expanderListStyles[`expander-list-link--outline--${color}`]]: isOutline,\n [expanderListStyles[`expander-list-link--line--${color}`]]: isLine,\n [expanderListStyles['expander-list-link--closed']]: !isExpanded,\n [expanderListStyles['expander-list-link--open']]: isExpanded,\n [expanderListStyles['expander-list-link--large']]: large,\n });\n\n const renderContent = (): React.ReactNode => {\n if (!renderChildrenWhenClosed && !isExpanded) {\n return null;\n }\n\n const mainContentClasses = classNames(\n expanderListStyles['expander-list-link__main-content'],\n isExpanded && expanderListStyles['expander-list-link__main-content--expanded'],\n padding ? expanderListStyles['expander-list-link__main-content--padding'] : ''\n );\n\n return <div className={mainContentClasses}>{children}</div>;\n };\n\n return (\n <li className={itemClasses} ref={mergeRefs([ref, expanderRef])}>\n <button\n type=\"button\"\n id={id}\n onClick={handleExpanderClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.ExpanderListExpander}\n className={expanderClasses}\n ref={triggerRef}\n aria-expanded={isExpanded}\n style={{\n zIndex: isHovered ? zIndex : undefined,\n }}\n >\n {renderListHeader(title, titleHtmlMarkup, isHovered, large ? 'large' : 'medium', isExpanded ? ChevronUp : ChevronDown, icon)}\n </button>\n {renderContent()}\n </li>\n );\n});\n\ntype ActiveExpander = Record<string, boolean>;\n\nconst isExpanderComponent = (element: {} | null | undefined): element is React.ReactElement<ExpanderProps> =>\n React.isValidElement<ExpanderProps>(element) && (element as React.ReactElement).type === Expander;\n\nexport const ExpanderList = React.forwardRef((props: ExpanderListProps, ref: React.Ref<HTMLUListElement>) => {\n const {\n children,\n childPadding = true,\n large,\n renderChildrenWhenClosed = false,\n color,\n className = '',\n accordion = false,\n testId,\n variant,\n zIndex = ZIndex.ExpanderTrigger,\n } = props;\n const [activeExpander, setActiveExpander] = useState<ActiveExpander>();\n const [latestExpander, setLatestExpander] = useState<HTMLElement>();\n const uuid = useUuid();\n const expanderListClasses = classNames(expanderListStyles['expander-list'], className);\n\n function handleExpanderClick(event: React.MouseEvent<HTMLElement, MouseEvent>, id: string): void {\n setActiveExpander(prevState => (accordion ? { [id]: !prevState?.[id] } : { ...prevState, [id]: !prevState?.[id] }));\n setLatestExpander(event.currentTarget);\n }\n\n const getExpanderId = (index: number): string => `${uuid}-${index}`;\n\n useEffect(() => {\n if (accordion && latestExpander && !isElementInViewport(latestExpander)) {\n latestExpander.scrollIntoView();\n }\n }, [accordion, latestExpander]);\n\n useEffect(() => {\n const newActiveExpander = React.Children.map(children, child => {\n if (isExpanderComponent(child)) {\n return child;\n }\n })?.reduce((acc, child, index) => {\n // Expanded-status skal bare settes dersom prop er satt av den som bruker komponenten\n if (typeof child.props.expanded !== 'undefined') {\n acc[getExpanderId(index)] = child.props.expanded;\n }\n return acc;\n }, {} as ActiveExpander);\n\n setActiveExpander({ ...activeExpander, ...newActiveExpander });\n }, [children]);\n\n return (\n <ul className={expanderListClasses} ref={ref} data-testid={testId} data-analyticsid={AnalyticsId.ExpanderList}>\n {React.Children.map(children, (child, index) => {\n if (isExpanderComponent(child)) {\n const id = getExpanderId(index);\n const expanded = activeExpander?.[id];\n\n return React.cloneElement(child as React.ReactElement<ExpanderProps>, {\n id,\n key: index,\n expanded,\n padding: childPadding,\n color,\n large,\n 'aria-expanded': expanded,\n className: expanderListStyles['expander-list__item'],\n handleExpanderClick: (event: React.MouseEvent<HTMLElement>) => handleExpanderClick(event, `${uuid}-${index}`),\n renderChildrenWhenClosed,\n variant,\n zIndex: zIndex,\n });\n }\n return child;\n })}\n </ul>\n );\n}) as ExpanderListCompound;\n\nExpanderList.displayName = 'ExpanderList';\nExpanderList.Expander = Expander;\nExpander.displayName = 'ExpanderList.Expander';\n\nexport default ExpanderList;\n"],"names":["Expander","React","props","ref","id","children","padding","color","className","icon","large","title","titleHtmlMarkup","expanded","testId","handleExpanderClick","onExpand","renderChildrenWhenClosed","variant","zIndex","isExpanded","useExpand","expanderRef","useRef","triggerRef","isHovered","useHover","isFill","isFillNegative","isOutline","isLine","itemClasses","classNames","expanderListStyles","expanderClasses","renderContent","mainContentClasses","jsx","jsxs","mergeRefs","AnalyticsId","renderListHeader","ChevronUp","ChevronDown","isExpanderComponent","element","ExpanderList","childPadding","accordion","ZIndex","activeExpander","setActiveExpander","useState","latestExpander","setLatestExpander","uuid","useUuid","expanderListClasses","event","prevState","getExpanderId","index","useEffect","isElementInViewport","newActiveExpander","_a","child","acc"],"mappings":";;;;;;;;;;;;;AA8EA,MAAMA,IAAyBC,EAAM,WAAyC,CAACC,GAAOC,MAAQ;AACtF,QAAA;AAAA,IACJ,IAAAC;AAAA,IACA,UAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,OAAAC,IAAQ;AAAA,IACR,WAAAC,IAAY;AAAA,IACZ,MAAAC;AAAA,IACA,OAAAC,IAAQ;AAAA,IACR,OAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IAClB,UAAAC,IAAW;AAAA,IACX,QAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,UAAAC;AAAA,IACA,0BAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,QAAAC;AAAA,EACE,IAAAjB,GACE,C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