@lumx/react 2.2.19 → 2.2.20-alpha-type.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.
Files changed (96) hide show
  1. package/esm/_internal/AutocompleteMultiple.js.map +1 -1
  2. package/esm/_internal/ButtonRoot.js.map +1 -1
  3. package/esm/_internal/Checkbox2.js +3 -1
  4. package/esm/_internal/Checkbox2.js.map +1 -1
  5. package/esm/_internal/ClickAwayProvider.js +90 -12
  6. package/esm/_internal/ClickAwayProvider.js.map +1 -1
  7. package/esm/_internal/DatePickerField.js +18 -11
  8. package/esm/_internal/DatePickerField.js.map +1 -1
  9. package/esm/_internal/Dialog2.js +2 -2
  10. package/esm/_internal/Dialog2.js.map +1 -1
  11. package/esm/_internal/Dropdown2.js.map +1 -1
  12. package/esm/_internal/GenericBlock.js +90 -0
  13. package/esm/_internal/GenericBlock.js.map +1 -0
  14. package/esm/_internal/Lightbox2.js +2 -2
  15. package/esm/_internal/Lightbox2.js.map +1 -1
  16. package/esm/_internal/LinkPreview.js +22 -12
  17. package/esm/_internal/LinkPreview.js.map +1 -1
  18. package/esm/_internal/Popover2.js +21 -8
  19. package/esm/_internal/Popover2.js.map +1 -1
  20. package/esm/_internal/SelectMultiple.js +16 -4
  21. package/esm/_internal/SelectMultiple.js.map +1 -1
  22. package/esm/_internal/TextField.js.map +1 -1
  23. package/esm/_internal/Thumbnail2.js.map +1 -1
  24. package/esm/_internal/alert-dialog.js +2 -2
  25. package/esm/_internal/autocomplete.js +2 -1
  26. package/esm/_internal/autocomplete.js.map +1 -1
  27. package/esm/_internal/button.js +2 -1
  28. package/esm/_internal/button.js.map +1 -1
  29. package/esm/_internal/comment-block.js +2 -1
  30. package/esm/_internal/comment-block.js.map +1 -1
  31. package/esm/_internal/date-picker.js +3 -2
  32. package/esm/_internal/date-picker.js.map +1 -1
  33. package/esm/_internal/dialog.js +2 -2
  34. package/esm/_internal/dropdown.js +2 -1
  35. package/esm/_internal/dropdown.js.map +1 -1
  36. package/esm/_internal/expansion-panel.js +1 -1
  37. package/esm/_internal/generic-block.js +12 -0
  38. package/esm/_internal/generic-block.js.map +1 -0
  39. package/esm/_internal/lightbox.js +3 -2
  40. package/esm/_internal/lightbox.js.map +1 -1
  41. package/esm/_internal/popover.js +2 -1
  42. package/esm/_internal/popover.js.map +1 -1
  43. package/esm/_internal/select.js +2 -1
  44. package/esm/_internal/select.js.map +1 -1
  45. package/esm/_internal/side-navigation.js +2 -1
  46. package/esm/_internal/side-navigation.js.map +1 -1
  47. package/esm/_internal/slideshow.js +2 -1
  48. package/esm/_internal/slideshow.js.map +1 -1
  49. package/esm/_internal/text-field.js +2 -1
  50. package/esm/_internal/text-field.js.map +1 -1
  51. package/esm/_internal/tooltip.js +2 -1
  52. package/esm/_internal/tooltip.js.map +1 -1
  53. package/esm/_internal/type.js.map +1 -1
  54. package/esm/_internal/useFocusTrap.js +62 -78
  55. package/esm/_internal/useFocusTrap.js.map +1 -1
  56. package/esm/index.js +3 -2
  57. package/esm/index.js.map +1 -1
  58. package/package.json +5 -5
  59. package/src/components/autocomplete/Autocomplete.tsx +4 -4
  60. package/src/components/button/Button.stories.tsx +1 -0
  61. package/src/components/button/ButtonRoot.tsx +4 -4
  62. package/src/components/checkbox/Checkbox.tsx +2 -1
  63. package/src/components/checkbox/__snapshots__/Checkbox.test.tsx.snap +4 -0
  64. package/src/components/date-picker/DatePickerField.tsx +15 -16
  65. package/src/components/date-picker/types.ts +2 -2
  66. package/src/components/dialog/Dialog.stories.tsx +57 -13
  67. package/src/components/dialog/Dialog.tsx +3 -3
  68. package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +82 -14
  69. package/src/components/dropdown/Dropdown.tsx +4 -3
  70. package/src/components/generic-block/GenericBlock.stories.tsx +149 -0
  71. package/src/components/generic-block/GenericBlock.test.tsx +28 -0
  72. package/src/components/generic-block/GenericBlock.tsx +120 -0
  73. package/src/components/generic-block/__snapshots__/GenericBlock.test.tsx.snap +92 -0
  74. package/src/components/generic-block/index.ts +1 -0
  75. package/src/components/lightbox/Lightbox.tsx +1 -1
  76. package/src/components/link-preview/LinkPreview.test.tsx +50 -55
  77. package/src/components/link-preview/LinkPreview.tsx +43 -16
  78. package/src/components/popover/Popover.tsx +20 -4
  79. package/src/components/select/Select.stories.tsx +2 -0
  80. package/src/components/select/Select.tsx +11 -1
  81. package/src/components/select/SelectMultiple.stories.tsx +2 -0
  82. package/src/components/select/SelectMultiple.tsx +11 -1
  83. package/src/components/select/constants.ts +2 -0
  84. package/src/components/table/__snapshots__/Table.test.tsx.snap +5 -0
  85. package/src/components/text-field/TextField.tsx +4 -4
  86. package/src/components/thumbnail/Thumbnail.tsx +2 -2
  87. package/src/hooks/useCallbackOnEscape.ts +21 -13
  88. package/src/hooks/useFocusTrap.ts +68 -51
  89. package/src/index.ts +1 -0
  90. package/src/stories/generated/GenericBlock/Demos.stories.tsx +6 -0
  91. package/src/utils/focus/getFirstAndLastFocusable.test.ts +6 -0
  92. package/src/utils/focus/getFirstAndLastFocusable.ts +2 -2
  93. package/src/utils/makeListenerTowerContext.ts +32 -0
  94. package/src/utils/type.ts +3 -0
  95. package/types.d.ts +70 -16
  96. package/src/components/link-preview/__snapshots__/LinkPreview.test.tsx.snap +0 -51
@@ -6,9 +6,9 @@ import { D as DOCUMENT } from './constants.js';
6
6
  import { p as partitionMulti } from './partitionMulti.js';
7
7
  import { i as isComponent } from './type.js';
8
8
  import { m as mergeRefs } from './mergeRefs.js';
9
+ import { u as useCallbackOnEscape, C as ClickAwayProvider } from './ClickAwayProvider.js';
9
10
  import { u as useFocusTrap } from './useFocusTrap.js';
10
11
  import { createPortal } from 'react-dom';
11
- import { u as useCallbackOnEscape, C as ClickAwayProvider } from './ClickAwayProvider.js';
12
12
  import { u as useDelayedVisibility } from './useDelayedVisibility.js';
13
13
  import { u as useDisableBodyScroll } from './useDisableBodyScroll.js';
14
14
  import { a as Progress, P as ProgressVariant } from './Progress2.js';
@@ -178,7 +178,7 @@ var Dialog = forwardRef(function (props, ref) {
178
178
  var localContentRef = useRef(null); // Handle focus trap.
179
179
  // eslint-disable-next-line react-hooks/rules-of-hooks
180
180
 
181
- useFocusTrap(wrapperRef.current, focusElement === null || focusElement === void 0 ? void 0 : focusElement.current); // eslint-disable-next-line react-hooks/rules-of-hooks
181
+ useFocusTrap(isOpen && wrapperRef.current, focusElement === null || focusElement === void 0 ? void 0 : focusElement.current); // eslint-disable-next-line react-hooks/rules-of-hooks
182
182
 
183
183
  useDisableBodyScroll(isOpen && localContentRef.current); // eslint-disable-next-line react-hooks/rules-of-hooks
184
184
 
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog2.js","sources":["../../../src/hooks/useIntersectionObserver.tsx","../../../src/components/dialog/Dialog.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport type Intersections<T> = Map<T, IntersectionObserverEntry>;\n\n/**\n * Convenient hook to create interaction observers.\n *\n * @param elements Elements to observe.\n * @param options IntersectionObserver options.\n * @return Map of intersections.\n */\nexport function useIntersectionObserver<T extends Element>(\n elements: Array<T | null | undefined>,\n options?: IntersectionObserverInit,\n): Intersections<T> {\n const [intersections, setIntersections] = useState<Intersections<T>>(() => new Map());\n\n useEffect(\n () => {\n if (elements.length < 1 || !elements.some(Boolean)) {\n return undefined;\n }\n\n const observer = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n intersections.set(entry.target as T, entry);\n }\n setIntersections(new Map(intersections));\n }, options);\n\n for (const element of elements) {\n if (element) {\n observer.observe(element);\n }\n }\n return () => observer.disconnect();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...elements],\n );\n\n return intersections;\n}\n","import React, { Children, forwardRef, ReactElement, ReactNode, RefObject, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport classNames from 'classnames';\n\nimport { Progress, ProgressVariant, Size } from '@lumx/react';\n\nimport { DIALOG_TRANSITION_DURATION, DOCUMENT } from '@lumx/react/constants';\nimport { useCallbackOnEscape } from '@lumx/react/hooks/useCallbackOnEscape';\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\nimport { useIntersectionObserver } from '@lumx/react/hooks/useIntersectionObserver';\nimport {\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n partitionMulti,\n} from '@lumx/react/utils';\nimport { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\nimport { useDelayedVisibility } from '@lumx/react/hooks/useDelayedVisibility';\nimport { useDisableBodyScroll } from '@lumx/react/hooks/useDisableBodyScroll';\n\n/**\n * Defines the props of the component.\n */\nexport interface DialogProps extends GenericProps {\n /** Footer content. */\n footer?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceFooterDivider?: boolean;\n /** Header content. */\n header?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceHeaderDivider?: boolean;\n /** Whether the indefinite progress indicator over the dialog content is displayed or not. */\n isLoading?: boolean;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Reference to the parent element that triggered modal opening (will get back focus on close). */\n parentElement?: RefObject<HTMLElement>;\n /** Reference to the dialog content element. */\n contentRef?: RefObject<HTMLDivElement>;\n /** Reference to the of the element that should get the focus when the dialogs opens. By default, the first child will take focus. */\n focusElement?: RefObject<HTMLElement>;\n /** Whether to keep the dialog open on clickaway or escape press. */\n preventAutoClose?: boolean;\n /** Size variant. */\n size?: DialogSizes;\n /** Z-axis position. */\n zIndex?: number;\n /** Z-axis position. */\n dialogProps?: GenericProps;\n /** On close callback. */\n onClose?(): void;\n /** Callback called when the open animation starts and the close animation finishes. */\n onVisibilityChange?(isVisible: boolean): void;\n}\n\nexport type DialogSizes = Extract<Size, 'tiny' | 'regular' | 'big' | 'huge'>;\n\nconst isHeader = isComponent('header');\nconst isFooter = isComponent('footer');\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dialog';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DialogProps> = {\n size: Size.big,\n};\n\n/**\n * Dialog component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref) => {\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n\n const {\n children,\n className,\n header,\n focusElement,\n forceFooterDivider,\n forceHeaderDivider,\n footer,\n isLoading,\n isOpen,\n onClose,\n parentElement,\n contentRef,\n preventAutoClose,\n size,\n zIndex,\n dialogProps,\n onVisibilityChange,\n ...forwardedProps\n } = props;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const previousOpen = React.useRef(isOpen);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isOpen !== previousOpen.current) {\n previousOpen.current = isOpen;\n\n // Focus the parent element on close.\n if (!isOpen && parentElement && parentElement.current) {\n parentElement.current.focus();\n }\n }\n }, [isOpen, parentElement]);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCallbackOnEscape(onClose, isOpen && !preventAutoClose);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const wrapperRef = useRef<HTMLDivElement>(null);\n /**\n * Since the `contentRef` comes from the parent and is optional,\n * we need to create a stable contentRef that will always be available.\n */\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const localContentRef = useRef<HTMLDivElement>(null);\n // Handle focus trap.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFocusTrap(wrapperRef.current, focusElement?.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useDisableBodyScroll(isOpen && localContentRef.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelTop, setSentinelTop] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelBottom, setSentinelBottom] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const intersections = useIntersectionObserver([sentinelTop, sentinelBottom], {\n threshold: [0, 1],\n });\n\n const hasTopIntersection = sentinelTop && !(intersections.get(sentinelTop)?.isIntersecting ?? true);\n const hasBottomIntersection = sentinelBottom && !(intersections.get(sentinelBottom)?.isIntersecting ?? true);\n\n // Separate header, footer and dialog content from children.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [[headerChild], [footerChild], content] = useMemo(\n () => partitionMulti(Children.toArray(children), [isHeader, isFooter]),\n [children],\n );\n const headerChildProps = (headerChild as ReactElement)?.props;\n const headerChildContent = headerChildProps?.children;\n const footerChildProps = (footerChild as ReactElement)?.props;\n const footerChildContent = footerChildProps?.children;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const isVisible = useDelayedVisibility(Boolean(isOpen), DIALOG_TRANSITION_DURATION, onVisibilityChange);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const clickAwayRefs = useRef([wrapperRef]);\n\n return isOpen || isVisible\n ? createPortal(\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n isHidden: !isOpen,\n isLoading,\n isShown: isOpen || isVisible,\n prefix: CLASSNAME,\n size,\n }),\n )}\n style={{ zIndex }}\n >\n <div className={`${CLASSNAME}__overlay`} />\n\n <section className={`${CLASSNAME}__container`} role=\"dialog\" aria-modal=\"true\" {...dialogProps}>\n <ClickAwayProvider callback={!preventAutoClose && onClose} refs={clickAwayRefs}>\n <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>\n {(header || headerChildContent) && (\n <header\n {...headerChildProps}\n className={classNames(\n `${CLASSNAME}__header`,\n (forceHeaderDivider || hasTopIntersection) &&\n `${CLASSNAME}__header--has-divider`,\n headerChildProps?.className,\n )}\n >\n {header}\n {headerChildContent}\n </header>\n )}\n\n <div ref={mergeRefs(contentRef, localContentRef)} className={`${CLASSNAME}__content`}>\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--top`}\n ref={setSentinelTop}\n />\n\n {content}\n\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--bottom`}\n ref={setSentinelBottom}\n />\n </div>\n\n {(footer || footerChildContent) && (\n <footer\n {...footerChildProps}\n className={classNames(\n `${CLASSNAME}__footer`,\n (forceFooterDivider || hasBottomIntersection) &&\n `${CLASSNAME}__footer--has-divider`,\n footerChildProps?.className,\n )}\n >\n {footer}\n {footerChildContent}\n </footer>\n )}\n\n {isLoading && (\n <div className={`${CLASSNAME}__progress-overlay`}>\n <Progress variant={ProgressVariant.circular} />\n </div>\n )}\n </div>\n </ClickAwayProvider>\n </section>\n </div>,\n document.body,\n )\n : null;\n});\nDialog.displayName = COMPONENT_NAME;\nDialog.className = CLASSNAME;\nDialog.defaultProps = DEFAULT_PROPS;\n"],"names":["useIntersectionObserver","elements","options","useState","Map","intersections","setIntersections","useEffect","length","some","Boolean","undefined","observer","IntersectionObserver","entries","entry","set","target","element","observe","disconnect","isHeader","isComponent","isFooter","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","size","Size","big","Dialog","forwardRef","props","ref","DOCUMENT","children","className","header","focusElement","forceFooterDivider","forceHeaderDivider","footer","isLoading","isOpen","onClose","parentElement","contentRef","preventAutoClose","zIndex","dialogProps","onVisibilityChange","forwardedProps","previousOpen","React","useRef","current","focus","useCallbackOnEscape","wrapperRef","localContentRef","useFocusTrap","useDisableBodyScroll","sentinelTop","setSentinelTop","sentinelBottom","setSentinelBottom","threshold","hasTopIntersection","get","isIntersecting","hasBottomIntersection","useMemo","partitionMulti","Children","toArray","headerChild","footerChild","content","headerChildProps","headerChildContent","footerChildProps","footerChildContent","isVisible","useDelayedVisibility","DIALOG_TRANSITION_DURATION","clickAwayRefs","createPortal","classNames","handleBasicClasses","isHidden","isShown","prefix","mergeRefs","ProgressVariant","circular","document","body","displayName","defaultProps"],"mappings":";;;;;;;;;;;;;;;AAIA;;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AA4BA,SAA5B,oBADb;AAEI,IAAA,GAAG,EAAEuC;AAFT,IADJ,EAMKc,OANL,EAQI;AACI,IAAA,SAAS,YAAKrD,SAAL,wBAA4BA,SAA5B,uBADb;AAEI,IAAA,GAAG,EAAEyC;AAFT,IARJ,CAhBJ,EA8BK,CAACxB,MAAM,IAAIwC,kBAAX,KACG,2CACQD,gBADR;AAEI,IAAA,SAAS,EAAEO,UAAU,WACd/D,SADc,eAEjB,CAACe,kBAAkB,IAAI+B,qBAAvB,eACO9C,SADP,0BAFiB,EAIjBwD,gBAJiB,aAIjBA,gBAJiB,uBAIjBA,gBAAgB,CAAE5C,SAJD;AAFzB,MASKK,MATL,EAUKwC,kBAVL,CA/BR,EA6CKvC,SAAS,IACN;AAAK,IAAA,SAAS,YAAKlB,SAAL;AAAd,KACI,oBAAC,QAAD;AAAU,IAAA,OAAO,EAAEqE,eAAe,CAACC;AAAnC,IADJ,CA9CR,CADJ,CADJ,CAjBJ,CADQ,EA0ERC,QAAQ,CAACC,IA1ED,CADX,GA6ED,IA7EN;AA8EH,CAtKkE;AAuKnElE,MAAM,CAACmE,WAAP,GAAqB1E,cAArB;AACAO,MAAM,CAACM,SAAP,GAAmBZ,SAAnB;AACAM,MAAM,CAACoE,YAAP,GAAsBxE,aAAtB;;;;"}
1
+ {"version":3,"file":"Dialog2.js","sources":["../../../src/hooks/useIntersectionObserver.tsx","../../../src/components/dialog/Dialog.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport type Intersections<T> = Map<T, IntersectionObserverEntry>;\n\n/**\n * Convenient hook to create interaction observers.\n *\n * @param elements Elements to observe.\n * @param options IntersectionObserver options.\n * @return Map of intersections.\n */\nexport function useIntersectionObserver<T extends Element>(\n elements: Array<T | null | undefined>,\n options?: IntersectionObserverInit,\n): Intersections<T> {\n const [intersections, setIntersections] = useState<Intersections<T>>(() => new Map());\n\n useEffect(\n () => {\n if (elements.length < 1 || !elements.some(Boolean)) {\n return undefined;\n }\n\n const observer = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n intersections.set(entry.target as T, entry);\n }\n setIntersections(new Map(intersections));\n }, options);\n\n for (const element of elements) {\n if (element) {\n observer.observe(element);\n }\n }\n return () => observer.disconnect();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...elements],\n );\n\n return intersections;\n}\n","import React, { Children, forwardRef, ReactElement, ReactNode, Ref, RefObject, useMemo, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\n\nimport classNames from 'classnames';\n\nimport { Progress, ProgressVariant, Size } from '@lumx/react';\n\nimport { DIALOG_TRANSITION_DURATION, DOCUMENT } from '@lumx/react/constants';\nimport { useCallbackOnEscape } from '@lumx/react/hooks/useCallbackOnEscape';\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\nimport { useIntersectionObserver } from '@lumx/react/hooks/useIntersectionObserver';\nimport {\n Comp,\n GenericProps,\n getRootClassName,\n handleBasicClasses,\n isComponent,\n partitionMulti,\n} from '@lumx/react/utils';\nimport { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\nimport { useDelayedVisibility } from '@lumx/react/hooks/useDelayedVisibility';\nimport { useDisableBodyScroll } from '@lumx/react/hooks/useDisableBodyScroll';\n\n/**\n * Defines the props of the component.\n */\nexport interface DialogProps extends GenericProps {\n /** Footer content. */\n footer?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceFooterDivider?: boolean;\n /** Header content. */\n header?: ReactNode;\n /** Whether the divider between the dialog content and the footer is always displayed (instead of showing it on scroll). */\n forceHeaderDivider?: boolean;\n /** Whether the indefinite progress indicator over the dialog content is displayed or not. */\n isLoading?: boolean;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Reference to the parent element that triggered modal opening (will get back focus on close). */\n parentElement?: RefObject<HTMLElement>;\n /** Reference to the dialog content element. */\n contentRef?: Ref<HTMLDivElement>;\n /** Reference to the of the element that should get the focus when the dialogs opens. By default, the first child will take focus. */\n focusElement?: RefObject<HTMLElement>;\n /** Whether to keep the dialog open on clickaway or escape press. */\n preventAutoClose?: boolean;\n /** Size variant. */\n size?: DialogSizes;\n /** Z-axis position. */\n zIndex?: number;\n /** Z-axis position. */\n dialogProps?: GenericProps;\n /** On close callback. */\n onClose?(): void;\n /** Callback called when the open animation starts and the close animation finishes. */\n onVisibilityChange?(isVisible: boolean): void;\n}\n\nexport type DialogSizes = Extract<Size, 'tiny' | 'regular' | 'big' | 'huge'>;\n\nconst isHeader = isComponent('header');\nconst isFooter = isComponent('footer');\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dialog';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DialogProps> = {\n size: Size.big,\n};\n\n/**\n * Dialog component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref) => {\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n\n const {\n children,\n className,\n header,\n focusElement,\n forceFooterDivider,\n forceHeaderDivider,\n footer,\n isLoading,\n isOpen,\n onClose,\n parentElement,\n contentRef,\n preventAutoClose,\n size,\n zIndex,\n dialogProps,\n onVisibilityChange,\n ...forwardedProps\n } = props;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const previousOpen = React.useRef(isOpen);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isOpen !== previousOpen.current) {\n previousOpen.current = isOpen;\n\n // Focus the parent element on close.\n if (!isOpen && parentElement && parentElement.current) {\n parentElement.current.focus();\n }\n }\n }, [isOpen, parentElement]);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCallbackOnEscape(onClose, isOpen && !preventAutoClose);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const wrapperRef = useRef<HTMLDivElement>(null);\n /**\n * Since the `contentRef` comes from the parent and is optional,\n * we need to create a stable contentRef that will always be available.\n */\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const localContentRef = useRef<HTMLDivElement>(null);\n // Handle focus trap.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFocusTrap(isOpen && wrapperRef.current, focusElement?.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useDisableBodyScroll(isOpen && localContentRef.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelTop, setSentinelTop] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [sentinelBottom, setSentinelBottom] = useState<Element | null>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const intersections = useIntersectionObserver([sentinelTop, sentinelBottom], {\n threshold: [0, 1],\n });\n\n const hasTopIntersection = sentinelTop && !(intersections.get(sentinelTop)?.isIntersecting ?? true);\n const hasBottomIntersection = sentinelBottom && !(intersections.get(sentinelBottom)?.isIntersecting ?? true);\n\n // Separate header, footer and dialog content from children.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const [[headerChild], [footerChild], content] = useMemo(\n () => partitionMulti(Children.toArray(children), [isHeader, isFooter]),\n [children],\n );\n const headerChildProps = (headerChild as ReactElement)?.props;\n const headerChildContent = headerChildProps?.children;\n const footerChildProps = (footerChild as ReactElement)?.props;\n const footerChildContent = footerChildProps?.children;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const isVisible = useDelayedVisibility(Boolean(isOpen), DIALOG_TRANSITION_DURATION, onVisibilityChange);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const clickAwayRefs = useRef([wrapperRef]);\n\n return isOpen || isVisible\n ? createPortal(\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n isHidden: !isOpen,\n isLoading,\n isShown: isOpen || isVisible,\n prefix: CLASSNAME,\n size,\n }),\n )}\n style={{ zIndex }}\n >\n <div className={`${CLASSNAME}__overlay`} />\n\n <section className={`${CLASSNAME}__container`} role=\"dialog\" aria-modal=\"true\" {...dialogProps}>\n <ClickAwayProvider callback={!preventAutoClose && onClose} refs={clickAwayRefs}>\n <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>\n {(header || headerChildContent) && (\n <header\n {...headerChildProps}\n className={classNames(\n `${CLASSNAME}__header`,\n (forceHeaderDivider || hasTopIntersection) &&\n `${CLASSNAME}__header--has-divider`,\n headerChildProps?.className,\n )}\n >\n {header}\n {headerChildContent}\n </header>\n )}\n\n <div ref={mergeRefs(contentRef, localContentRef)} className={`${CLASSNAME}__content`}>\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--top`}\n ref={setSentinelTop}\n />\n\n {content}\n\n <div\n className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--bottom`}\n ref={setSentinelBottom}\n />\n </div>\n\n {(footer || footerChildContent) && (\n <footer\n {...footerChildProps}\n className={classNames(\n `${CLASSNAME}__footer`,\n (forceFooterDivider || hasBottomIntersection) &&\n `${CLASSNAME}__footer--has-divider`,\n footerChildProps?.className,\n )}\n >\n {footer}\n {footerChildContent}\n </footer>\n )}\n\n {isLoading && (\n <div className={`${CLASSNAME}__progress-overlay`}>\n <Progress variant={ProgressVariant.circular} />\n </div>\n )}\n </div>\n </ClickAwayProvider>\n </section>\n </div>,\n document.body,\n )\n : null;\n});\nDialog.displayName = COMPONENT_NAME;\nDialog.className = CLASSNAME;\nDialog.defaultProps = DEFAULT_PROPS;\n"],"names":["useIntersectionObserver","elements","options","useState","Map","intersections","setIntersections","useEffect","length","some","Boolean","undefined","observer","IntersectionObserver","entries","entry","set","target","element","observe","disconnect","isHeader","isComponent","isFooter","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","size","Size","big","Dialog","forwardRef","props","ref","DOCUMENT","children","className","header","focusElement","forceFooterDivider","forceHeaderDivider","footer","isLoading","isOpen","onClose","parentElement","contentRef","preventAutoClose","zIndex","dialogProps","onVisibilityChange","forwardedProps","previousOpen","React","useRef","current","focus","useCallbackOnEscape","wrapperRef","localContentRef","useFocusTrap","useDisableBodyScroll","sentinelTop","setSentinelTop","sentinelBottom","setSentinelBottom","threshold","hasTopIntersection","get","isIntersecting","hasBottomIntersection","useMemo","partitionMulti","Children","toArray","headerChild","footerChild","content","headerChildProps","headerChildContent","footerChildProps","footerChildContent","isVisible","useDelayedVisibility","DIALOG_TRANSITION_DURATION","clickAwayRefs","createPortal","classNames","handleBasicClasses","isHidden","isShown","prefix","mergeRefs","ProgressVariant","circular","document","body","displayName","defaultProps"],"mappings":";;;;;;;;;;;;;;;AAIA;;;;;;;AAOO,SAASA,uBAAT,CACHC,QADG,EAEHC,OAFG,EAGa;AAAA,kBAC0BC,QAAQ,CAAmB;AAAA,WAAM,IAAIC,GAAJ,EAAN;AAAA,GAAnB,CADlC;AAAA;AAAA,MACTC,aADS;AAAA,MACMC,gBADN;;AAGhBC,EAAAA,SAAS,CACL,YAAM;AACF,QAAIN,QAAQ,CAACO,MAAT,GAAkB,CAAlB,IAAuB,CAACP,QAAQ,CAACQ,IAAT,CAAcC,OAAd,CAA5B,EAAoD;AAChD,aAAOC,SAAP;AACH;;AAED,QAAMC,QAAQ,GAAG,IAAIC,oBAAJ,CAAyB,UAACC,OAAD,EAAa;AAAA;AAAA;AAAA;;AAAA;AACnD,6BAAoBA,OAApB,8HAA6B;AAAA,cAAlBC,KAAkB;AACzBV,UAAAA,aAAa,CAACW,GAAd,CAAkBD,KAAK,CAACE,MAAxB,EAAqCF,KAArC;AACH;AAHkD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAInDT,MAAAA,gBAAgB,CAAC,IAAIF,GAAJ,CAAQC,aAAR,CAAD,CAAhB;AACH,KALgB,EAKdH,OALc,CAAjB;AALE;AAAA;AAAA;;AAAA;AAYF,4BAAsBD,QAAtB,mIAAgC;A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tB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown2.js","sources":["../../../src/hooks/useInfiniteScroll.tsx","../../../src/components/dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\n\ntype useInfiniteScrollType = (\n ref: React.RefObject<HTMLElement>,\n callback?: EventCallback,\n callbackOnMount?: boolean,\n) => void;\ntype EventCallback = (evt?: Event) => void;\n\n// The error margin in px we want to have for triggering infinite scroll\nconst SCROLL_TRIGGER_MARGIN = 5;\n\n/**\n * Listen to clicks away from a given element and callback the passed in function.\n *\n * @param ref A reference to the element on which you want to listen scroll event.\n * @param [callback] A callback function to call when the bottom of the reference element is reached.\n * @param [callbackOnMount] A callback function to call when the component is mounted.\n */\nexport const useInfiniteScroll: useInfiniteScrollType = (\n ref,\n callback,\n callbackOnMount = false,\n scrollTriggerMargin = SCROLL_TRIGGER_MARGIN,\n) => {\n useEffect(() => {\n const { current } = ref;\n if (!callback || !current) {\n return undefined;\n }\n\n const isAtBottom = () =>\n Boolean(\n current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin,\n );\n\n const onScroll = (e?: Event): void => {\n if (isAtBottom()) {\n callback(e);\n }\n };\n\n if (isAtBottom()) {\n onScroll();\n }\n\n current.addEventListener('scroll', onScroll);\n current.addEventListener('resize', onScroll);\n return () => {\n current.removeEventListener('scroll', onScroll);\n current.removeEventListener('resize', onScroll);\n };\n }, [ref, callback, scrollTriggerMargin]);\n\n useEffect(() => {\n if (callback && callbackOnMount) {\n callback();\n }\n }, [callback, callbackOnMount]);\n};\n","import React, { cloneElement, forwardRef, useMemo, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { List, ListProps } from '@lumx/react/components/list/List';\nimport { Offset, Placement, Popover } from '@lumx/react/components/popover/Popover';\nimport { useInfiniteScroll } from '@lumx/react/hooks/useInfiniteScroll';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DropdownProps extends GenericProps {\n /** Reference to the element around which the dropdown is placed.\n * @see {@link PopoverProps#anchorRef}\n */\n anchorRef: React.RefObject<HTMLElement>;\n /** Dropdown content. */\n children: React.ReactNode;\n /**\n * Whether a click anywhere out of the Dropdown would close it or not.\n * @see {@link PopoverProps#closeOnClickAway}\n */\n closeOnClickAway?: boolean;\n /**\n * Whether to close the Dropdown when clicking in it or not.\n */\n closeOnClick?: boolean;\n /**\n * Whether an escape key press would close the Dropdown or not.\n * @see {@link PopoverProps#closeOnEscape}\n */\n closeOnEscape?: boolean;\n /**\n * Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.\n * @see {@link PopoverProps#fitToAnchorWidth}\n */\n fitToAnchorWidth?: boolean;\n /**\n * Whether the dropdown should shrink to fit within the viewport height or not.\n * @see {@link PopoverProps#fitWithinViewportHeight}\n */\n fitWithinViewportHeight?: boolean;\n /**\n * Whether the dropdown should be displayed or not. Useful to control the Dropdown from outside the component.\n * @see {@link PopoverProps#isOpen}\n */\n isOpen: boolean;\n /**\n * Offset applied to the Dropdown position.\n * @see {@link PopoverProps#offset}\n */\n offset?: Offset;\n /**\n * Preferred Dropdown placement against the anchor element.\n * @see {@link PopoverProps#placement}\n */\n placement?: Placement;\n /** Whether the focus should be set on the list when the dropdown is open or not. */\n shouldFocusOnOpen?: boolean;\n /** Whether the focus should go back on the anchor when dropdown closes and focus is within. */\n focusAnchorOnClose?: boolean;\n /**\n * Z-axis position.\n * @see {@link PopoverProps#zIndex}\n */\n zIndex?: number;\n /**\n * On close callback.\n * @see {@link PopoverProps#onClose}\n */\n onClose?(): void;\n /** On scroll end callback. */\n onInfiniteScroll?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dropdown';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DropdownProps> = {\n closeOnClick: true,\n closeOnClickAway: true,\n closeOnEscape: true,\n fitToAnchorWidth: true,\n fitWithinViewportHeight: true,\n placement: Placement.BOTTOM_START,\n shouldFocusOnOpen: true,\n focusAnchorOnClose: true,\n};\n\n/**\n * Dropdown component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n anchorRef,\n children,\n className,\n closeOnClick,\n closeOnClickAway,\n closeOnEscape,\n fitToAnchorWidth,\n fitWithinViewportHeight,\n isOpen,\n offset,\n focusAnchorOnClose,\n onClose,\n onInfiniteScroll,\n placement,\n shouldFocusOnOpen,\n zIndex,\n ...forwardedProps\n } = props;\n const innerRef = useRef<HTMLDivElement>(null);\n const listElement = useRef(null);\n\n useInfiniteScroll(innerRef, onInfiniteScroll);\n\n const popperElement = useMemo(() => {\n return !Array.isArray(children) && isComponent(List)(children)\n ? cloneElement<ListProps>(children, {\n ...children.props,\n ref: listElement,\n onClick(evt: MouseEvent) {\n children.props.onClick?.(evt);\n\n if (closeOnClick) {\n onClose?.();\n }\n },\n isClickable: true,\n })\n : children;\n }, [children, closeOnClick, onClose]);\n\n return isOpen ? (\n <Popover\n ref={ref}\n {...forwardedProps}\n focusAnchorOnClose={focusAnchorOnClose}\n anchorRef={anchorRef}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME }))}\n elevation={0 as any}\n closeOnClickAway={closeOnClickAway}\n closeOnEscape={closeOnEscape}\n fitToAnchorWidth={fitToAnchorWidth}\n fitWithinViewportHeight={fitWithinViewportHeight}\n focusElement={shouldFocusOnOpen ? listElement : undefined}\n isOpen={isOpen}\n offset={offset}\n onClose={onClose}\n placement={placement}\n zIndex={zIndex}\n >\n <div className={`${CLASSNAME}__menu`} ref={innerRef}>\n {popperElement}\n </div>\n </Popover>\n ) : null;\n});\nDropdown.displayName = COMPONENT_NAME;\nDropdown.className = CLASSNAME;\nDropdown.defaultProps = DEFAULT_PROPS;\n"],"names":["SCROLL_TRIGGER_MARGIN","useInfiniteScroll","ref","callback","callbackOnMount","scrollTriggerMargin","useEffect","current","undefined","isAtBottom","Boolean","scrollHeight","scrollTop","clientHeight","onScroll","e","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","closeOnClick","closeOnClickAway","closeOnEscape","fitToAnchorWidth","fitWithinViewportHeight","placement","Placement","BOTTOM_START","shouldFocusOnOpen","focusAnchorOnClose","Dropdown","forwardRef","props","anchorRef","children","className","isOpen","offset","onClose","onInfiniteScroll","zIndex","forwardedProps","innerRef","useRef","listElement","popperElement","useMemo","Array","isArray","isComponent","List","cloneElement","onClick","evt","isClickable","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":";;;;;;;AASA;AACA,IAAMA,qBAAqB,GAAG,CAA9B;AAEA;;;;;;;;AAOO,IAAMC,iBAAwC,GAAG,SAA3CA,iBAA2C,CACpDC,GADoD,EAEpDC,QAFoD,EAKnD;AAAA,MAFDC,eAEC,uEAFiB,KAEjB;AAAA,MADDC,mBACC,uEADqBL,qBACrB;AACDM,EAAAA,SAAS,CAAC,YAAM;AAAA,QACJC,OADI,GACQL,GADR,CACJK,OADI;;AAEZ,QAAI,CAACJ,QAAD,IAAa,CAACI,OAAlB,EAA2B;AACvB,aAAOC,SAAP;AACH;;AAED,QAAMC,UAAU,GAAG,SAAbA,UAAa;AAAA,aACfC,OAAO,CACHH,OAAO,IAAIA,OAAO,CAACI,YAAR,IAAwBJ,OAAO,CAACK,SAAR,GAAoBL,OAAO,CAACM,YAApD,KAAqER,mBAD7E,CADQ;AAAA,KAAnB;;AAKA,QAAMS,QAAQ,GAAG,SAAXA,QAAW,CAACC,CAAD,EAAqB;AAClC,UAAIN,UAAU,EAAd,EAAkB;AACdN,QAAAA,QAAQ,CAACY,CAAD,CAAR;AACH;AACJ,KAJD;;AAMA,QAAIN,UAAU,EAAd,EAAkB;AACdK,MAAAA,QAAQ;AACX;;AAEDP,IAAAA,OAAO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B;;;;"}
1
+ {"version":3,"file":"Dropdown2.js","sources":["../../../src/hooks/useInfiniteScroll.tsx","../../../src/components/dropdown/Dropdown.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\n\ntype useInfiniteScrollType = (\n ref: React.RefObject<HTMLElement>,\n callback?: EventCallback,\n callbackOnMount?: boolean,\n) => void;\ntype EventCallback = (evt?: Event) => void;\n\n// The error margin in px we want to have for triggering infinite scroll\nconst SCROLL_TRIGGER_MARGIN = 5;\n\n/**\n * Listen to clicks away from a given element and callback the passed in function.\n *\n * @param ref A reference to the element on which you want to listen scroll event.\n * @param [callback] A callback function to call when the bottom of the reference element is reached.\n * @param [callbackOnMount] A callback function to call when the component is mounted.\n */\nexport const useInfiniteScroll: useInfiniteScrollType = (\n ref,\n callback,\n callbackOnMount = false,\n scrollTriggerMargin = SCROLL_TRIGGER_MARGIN,\n) => {\n useEffect(() => {\n const { current } = ref;\n if (!callback || !current) {\n return undefined;\n }\n\n const isAtBottom = () =>\n Boolean(\n current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin,\n );\n\n const onScroll = (e?: Event): void => {\n if (isAtBottom()) {\n callback(e);\n }\n };\n\n if (isAtBottom()) {\n onScroll();\n }\n\n current.addEventListener('scroll', onScroll);\n current.addEventListener('resize', onScroll);\n return () => {\n current.removeEventListener('scroll', onScroll);\n current.removeEventListener('resize', onScroll);\n };\n }, [ref, callback, scrollTriggerMargin]);\n\n useEffect(() => {\n if (callback && callbackOnMount) {\n callback();\n }\n }, [callback, callbackOnMount]);\n};\n","import React, { cloneElement, forwardRef, useMemo, useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { List, ListProps } from '@lumx/react/components/list/List';\nimport { Offset, Placement, Popover, PopoverProps } from '@lumx/react/components/popover/Popover';\nimport { useInfiniteScroll } from '@lumx/react/hooks/useInfiniteScroll';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface DropdownProps extends GenericProps {\n /**\n * Reference to the element around which the dropdown is placed.\n * @see {@link PopoverProps#anchorRef}\n */\n anchorRef: PopoverProps['anchorRef'];\n /** Dropdown content. */\n children: React.ReactNode;\n /**\n * Whether a click anywhere out of the Dropdown would close it or not.\n * @see {@link PopoverProps#closeOnClickAway}\n */\n closeOnClickAway?: boolean;\n /**\n * Whether to close the Dropdown when clicking in it or not.\n */\n closeOnClick?: boolean;\n /**\n * Whether an escape key press would close the Dropdown or not.\n * @see {@link PopoverProps#closeOnEscape}\n */\n closeOnEscape?: boolean;\n /**\n * Whether the dropdown should fit to the anchor width (if dropdown is smaller) or not.\n * @see {@link PopoverProps#fitToAnchorWidth}\n */\n fitToAnchorWidth?: boolean;\n /**\n * Whether the dropdown should shrink to fit within the viewport height or not.\n * @see {@link PopoverProps#fitWithinViewportHeight}\n */\n fitWithinViewportHeight?: boolean;\n /**\n * Whether the dropdown should be displayed or not. Useful to control the Dropdown from outside the component.\n * @see {@link PopoverProps#isOpen}\n */\n isOpen: boolean;\n /**\n * Offset applied to the Dropdown position.\n * @see {@link PopoverProps#offset}\n */\n offset?: Offset;\n /**\n * Preferred Dropdown placement against the anchor element.\n * @see {@link PopoverProps#placement}\n */\n placement?: Placement;\n /** Whether the focus should be set on the list when the dropdown is open or not. */\n shouldFocusOnOpen?: boolean;\n /** Whether the focus should go back on the anchor when dropdown closes and focus is within. */\n focusAnchorOnClose?: boolean;\n /**\n * Z-axis position.\n * @see {@link PopoverProps#zIndex}\n */\n zIndex?: number;\n /**\n * On close callback.\n * @see {@link PopoverProps#onClose}\n */\n onClose?(): void;\n /** On scroll end callback. */\n onInfiniteScroll?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Dropdown';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<DropdownProps> = {\n closeOnClick: true,\n closeOnClickAway: true,\n closeOnEscape: true,\n fitToAnchorWidth: true,\n fitWithinViewportHeight: true,\n placement: Placement.BOTTOM_START,\n shouldFocusOnOpen: true,\n focusAnchorOnClose: true,\n};\n\n/**\n * Dropdown component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Dropdown: Comp<DropdownProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n anchorRef,\n children,\n className,\n closeOnClick,\n closeOnClickAway,\n closeOnEscape,\n fitToAnchorWidth,\n fitWithinViewportHeight,\n isOpen,\n offset,\n focusAnchorOnClose,\n onClose,\n onInfiniteScroll,\n placement,\n shouldFocusOnOpen,\n zIndex,\n ...forwardedProps\n } = props;\n const innerRef = useRef<HTMLDivElement>(null);\n const listElement = useRef(null);\n\n useInfiniteScroll(innerRef, onInfiniteScroll);\n\n const popperElement = useMemo(() => {\n return !Array.isArray(children) && isComponent(List)(children)\n ? cloneElement<ListProps>(children, {\n ...children.props,\n ref: listElement,\n onClick(evt: MouseEvent) {\n children.props.onClick?.(evt);\n\n if (closeOnClick) {\n onClose?.();\n }\n },\n isClickable: true,\n })\n : children;\n }, [children, closeOnClick, onClose]);\n\n return isOpen ? (\n <Popover\n ref={ref}\n {...forwardedProps}\n focusAnchorOnClose={focusAnchorOnClose}\n anchorRef={anchorRef}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME }))}\n elevation={0 as any}\n closeOnClickAway={closeOnClickAway}\n closeOnEscape={closeOnEscape}\n fitToAnchorWidth={fitToAnchorWidth}\n fitWithinViewportHeight={fitWithinViewportHeight}\n focusElement={shouldFocusOnOpen ? listElement : undefined}\n isOpen={isOpen}\n offset={offset}\n onClose={onClose}\n placement={placement}\n zIndex={zIndex}\n >\n <div className={`${CLASSNAME}__menu`} ref={innerRef}>\n {popperElement}\n </div>\n </Popover>\n ) : null;\n});\nDropdown.displayName = COMPONENT_NAME;\nDropdown.className = CLASSNAME;\nDropdown.defaultProps = DEFAULT_PROPS;\n"],"names":["SCROLL_TRIGGER_MARGIN","useInfiniteScroll","ref","callback","callbackOnMount","scrollTriggerMargin","useEffect","current","undefined","isAtBottom","Boolean","scrollHeight","scrollTop","clientHeight","onScroll","e","addEventListener","removeEventListener","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","closeOnClick","closeOnClickAway","closeOnEscape","fitToAnchorWidth","fitWithinViewportHeight","placement","Placement","BOTTOM_START","shouldFocusOnOpen","focusAnchorOnClose","Dropdown","forwardRef","props","anchorRef","children","className","isOpen","offset","onClose","onInfiniteScroll","zIndex","forwardedProps","innerRef","useRef","listElement","popperElement","useMemo","Array","isArray","isComponent","List","cloneElement","onClick","evt","isClickable","classNames","handleBasicClasses","prefix","displayName","defaultProps"],"mappings":";;;;;;;AASA;AACA,IAAMA,qBAAqB,GAAG,CAA9B;AAEA;;;;;;;;AAOO,IAAMC,iBAAwC,GAAG,SAA3CA,iBAA2C,CACpDC,GADoD,EAEpDC,QAFoD,EAKnD;AAAA,MAFDC,eAEC,uEAFiB,KAEjB;AAAA,MADDC,mBACC,uEADqBL,qBACrB;AACDM,EAAAA,SAAS,CAAC,YAAM;AAAA,QACJC,OADI,GACQL,GADR,CACJK,OADI;;AAEZ,QAAI,CAACJ,QAAD,IAAa,CAACI,OAAlB,EAA2B;AACvB,aAAOC,SAAP;AACH;;AAED,QAAMC,UAAU,GAAG,SAAbA,UAAa;AAAA,aACfC,OAAO,CACHH,OAAO,IAAIA,OAAO,CAACI,YAAR,IAAwBJ,OAAO,CAACK,SAAR,GAAoBL,OAAO,CAACM,YAApD,KAAqER,mBAD7E,CADQ;AAAA,KAAnB;;AAKA,QAAMS,QAAQ,GAAG,SAAXA,QAAW,CAACC,CAAD,EAAqB;AAClC,UAAIN,UAAU,EAAd,EAAkB;AACdN,QAAAA,QAAQ,CAACY,CAAD,CAAR;AACH;AACJ,KAJD;;AAMA,QAAIN,UAAU,EAAd,EAAkB;AACdK,MAAAA,QAAQ;AACX;;AAEDP,IAAAA,OAAO,CA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;;"}
@@ -0,0 +1,90 @@
1
+ import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
2
+ import { Orientation, Size, Alignment } from './components.js';
3
+ import React, { forwardRef } from 'react';
4
+ import { g as getRootClassName, c as classnames } from './getRootClassName.js';
5
+ import 'lodash/isBoolean';
6
+ import 'lodash/isEmpty';
7
+ import 'lodash/kebabCase';
8
+ import 'lodash/noop';
9
+ import { F as FlexBox } from './FlexBox.js';
10
+
11
+ /**
12
+ * Component display name.
13
+ */
14
+ var COMPONENT_NAME = 'GenericBlock';
15
+ /**
16
+ * Component default class name and class prefix.
17
+ */
18
+
19
+ var CLASSNAME = getRootClassName(COMPONENT_NAME);
20
+ /**
21
+ * Component default props.
22
+ */
23
+
24
+ var DEFAULT_PROPS = {
25
+ gap: Size.regular,
26
+ orientation: Orientation.vertical,
27
+ hAlign: Alignment.center,
28
+ vAlign: Alignment.center
29
+ };
30
+ /**
31
+ * The GenericBlock is a layout component made of 3 sections that can be
32
+ * displayed either horizontally of vertically with the same gap between each section.
33
+ *
34
+ * The sections are:
35
+ * * (Optional) `Figure` => A visual element to display before the main content.
36
+ * * (Required) `Content` => The main content displayed
37
+ * * (Optional) `Actions` => One or more actions to set after the element.
38
+ *
39
+ * @see https://www.figma.com/file/lzzrQmsfaXRaOyRfoEogPZ/DS%3A-playground?node-id=1%3A4076
40
+ */
41
+
42
+ var GenericBlock = forwardRef(function (props, ref) {
43
+ var className = props.className,
44
+ figure = props.figure,
45
+ figureProps = props.figureProps,
46
+ children = props.children,
47
+ actions = props.actions,
48
+ actionsProps = props.actionsProps,
49
+ gap = props.gap,
50
+ orientation = props.orientation,
51
+ contentProps = props.contentProps,
52
+ forwardedProps = _objectWithoutProperties(props, ["className", "figure", "figureProps", "children", "actions", "actionsProps", "gap", "orientation", "contentProps"]);
53
+
54
+ var actionsVAlign = Alignment.center;
55
+
56
+ if (orientation === Orientation.horizontal) {
57
+ actionsVAlign = Alignment.right;
58
+ }
59
+
60
+ var contentVAlign = Alignment.center;
61
+
62
+ if (orientation === Orientation.horizontal) {
63
+ contentVAlign = Alignment.left;
64
+ }
65
+
66
+ return React.createElement(FlexBox, _extends({
67
+ ref: ref,
68
+ className: classnames(className, CLASSNAME),
69
+ gap: gap,
70
+ orientation: orientation
71
+ }, forwardedProps), React.createElement(FlexBox, _extends({}, figureProps, {
72
+ className: classnames(figureProps === null || figureProps === void 0 ? void 0 : figureProps.className, "".concat(CLASSNAME, "__figure"))
73
+ }), figure), children && React.createElement(FlexBox, _extends({
74
+ orientation: Orientation.vertical,
75
+ fillSpace: true,
76
+ vAlign: contentVAlign
77
+ }, contentProps, {
78
+ className: classnames(contentProps === null || contentProps === void 0 ? void 0 : contentProps.className, "".concat(CLASSNAME, "__content"))
79
+ }), children), React.createElement(FlexBox, _extends({
80
+ vAlign: actionsVAlign
81
+ }, actionsProps, {
82
+ className: classnames(actionsProps === null || actionsProps === void 0 ? void 0 : actionsProps.className, "".concat(CLASSNAME, "__actions"))
83
+ }), actions));
84
+ });
85
+ GenericBlock.displayName = COMPONENT_NAME;
86
+ GenericBlock.className = CLASSNAME;
87
+ GenericBlock.defaultProps = DEFAULT_PROPS;
88
+
89
+ export { GenericBlock as G };
90
+ //# sourceMappingURL=GenericBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenericBlock.js","sources":["../../../src/components/generic-block/GenericBlock.tsx"],"sourcesContent":["import React, { forwardRef, ReactNode } from 'react';\nimport classNames from 'classnames';\nimport { Comp, getRootClassName } from '@lumx/react/utils';\nimport { Orientation, Size, FlexBox, FlexBoxProps, Alignment, HorizontalAlignment } from '@lumx/react';\n\nexport interface GenericBlockProps extends FlexBoxProps {\n /** Component to use as visual element. */\n figure?: ReactNode;\n /** Actions to set after the main content. */\n actions?: ReactNode;\n /** Main content to display */\n children: ReactNode;\n /** Orientation of the 3 sections */\n orientation?: FlexBoxProps['orientation'];\n /** Horizontal alignment. */\n hAlign?: FlexBoxProps['hAlign'];\n /** Vertical alignment. */\n vAlign?: FlexBoxProps['vAlign'];\n /**\n * The props to forward to the content.\n * By default, the content will have the same alignment as wrapper.\n */\n contentProps?: Omit<FlexBoxProps, 'children'>;\n /** props to forward to the actions element. */\n actionsProps?: Omit<FlexBoxProps, 'children'>;\n /** props to forward to the figure element. */\n figureProps?: Omit<FlexBoxProps, 'children'>;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'GenericBlock';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<GenericBlockProps> = {\n gap: Size.regular,\n orientation: Orientation.vertical,\n hAlign: Alignment.center,\n vAlign: Alignment.center,\n};\n\n/**\n * The GenericBlock is a layout component made of 3 sections that can be\n * displayed either horizontally of vertically with the same gap between each section.\n *\n * The sections are:\n * * (Optional) `Figure` => A visual element to display before the main content.\n * * (Required) `Content` => The main content displayed\n * * (Optional) `Actions` => One or more actions to set after the element.\n *\n * @see https://www.figma.com/file/lzzrQmsfaXRaOyRfoEogPZ/DS%3A-playground?node-id=1%3A4076\n */\nexport const GenericBlock: Comp<GenericBlockProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n className,\n figure,\n figureProps,\n children,\n actions,\n actionsProps,\n gap,\n orientation,\n contentProps,\n ...forwardedProps\n } = props;\n\n let actionsVAlign: HorizontalAlignment = Alignment.center;\n if (orientation === Orientation.horizontal) {\n actionsVAlign = Alignment.right;\n }\n let contentVAlign: HorizontalAlignment = Alignment.center;\n if (orientation === Orientation.horizontal) {\n contentVAlign = Alignment.left;\n }\n\n return (\n <FlexBox\n ref={ref}\n className={classNames(className, CLASSNAME)}\n gap={gap}\n orientation={orientation}\n {...forwardedProps}\n >\n <FlexBox {...figureProps} className={classNames(figureProps?.className, `${CLASSNAME}__figure`)}>\n {figure}\n </FlexBox>\n\n {children && (\n <FlexBox\n orientation={Orientation.vertical}\n fillSpace\n vAlign={contentVAlign}\n {...contentProps}\n className={classNames(contentProps?.className, `${CLASSNAME}__content`)}\n >\n {children}\n </FlexBox>\n )}\n\n <FlexBox\n vAlign={actionsVAlign}\n {...actionsProps}\n className={classNames(actionsProps?.className, `${CLASSNAME}__actions`)}\n >\n {actions}\n </FlexBox>\n </FlexBox>\n );\n});\nGenericBlock.displayName = COMPONENT_NAME;\nGenericBlock.className = CLASSNAME;\nGenericBlock.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","gap","Size","regular","orientation","Orientation","vertical","hAlign","Alignment","center","vAlign","GenericBlock","forwardRef","props","ref","className","figure","figureProps","children","actions","actionsProps","contentProps","forwardedProps","actionsVAlign","horizontal","right","contentVAlign","left","classNames","displayName","defaultProps"],"mappings":";;;;;;;;;;AA6BA;;;AAGA,IAAMA,cAAc,GAAG,cAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,aAAyC,GAAG;AAC9CC,EAAAA,GAAG,EAAEC,IAAI,CAACC,OADoC;AAE9CC,EAAAA,WAAW,EAAEC,WAAW,CAACC,QAFqB;AAG9CC,EAAAA,MAAM,EAAEC,SAAS,CAACC,MAH4B;AAI9CC,EAAAA,MAAM,EAAEF,SAAS,CAACC;AAJ4B,CAAlD;AAOA;;;;;;;;;;;;IAWaE,YAAqD,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAExFC,SAFwF,GAYxFF,KAZwF,CAExFE,SAFwF;AAAA,MAGxFC,MAHwF,GAYxFH,KAZwF,CAGxFG,MAHwF;AAAA,MAIxFC,WAJwF,GAYxFJ,KAZwF,CAIxFI,WAJwF;AAAA,MAKxFC,QALwF,GAYxFL,KAZwF,CAKxFK,QALwF;AAAA,MAMxFC,OANwF,GAYxFN,KAZwF,CAMxFM,OANwF;AAAA,MAOxFC,YAPwF,GAYxFP,KAZwF,CA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EQ,UAAU,CAACR,YAAD,aAACA,YAAD,uBAACA,YAAY,CAAEL,SAAf,YAA6BjB,SAA7B;AAHzB,MAKKqB,OALL,CAvBJ,CADJ;AAiCH,CAxD8E;AAyD/ER,YAAY,CAACkB,WAAb,GAA2BhC,cAA3B;AACAc,YAAY,CAACI,SAAb,GAAyBjB,SAAzB;AACAa,YAAY,CAACmB,YAAb,GAA4B9B,aAA5B;;;;"}
@@ -6,9 +6,9 @@ import { d as mdiClose } from './Icon2.js';
6
6
  import { D as DOCUMENT } from './constants.js';
7
7
  import { m as mergeRefs } from './mergeRefs.js';
8
8
  import { I as IconButton } from './IconButton.js';
9
+ import { u as useCallbackOnEscape, C as ClickAwayProvider } from './ClickAwayProvider.js';
9
10
  import { u as useFocusTrap } from './useFocusTrap.js';
10
11
  import { createPortal } from 'react-dom';
11
- import { u as useCallbackOnEscape, C as ClickAwayProvider } from './ClickAwayProvider.js';
12
12
  import { u as useDelayedVisibility } from './useDelayedVisibility.js';
13
13
  import { u as useDisableBodyScroll } from './useDisableBodyScroll.js';
14
14
 
@@ -64,7 +64,7 @@ var Lightbox = forwardRef(function (props, ref) {
64
64
  var isVisible = useDelayedVisibility(!!isOpen, LIGHTBOX_TRANSITION_DURATION); // Handle focus trap.
65
65
  // eslint-disable-next-line react-hooks/rules-of-hooks
66
66
 
67
- useFocusTrap(wrapperRef.current, (_childrenRef$current = childrenRef.current) === null || _childrenRef$current === void 0 ? void 0 : _childrenRef$current.firstChild); // eslint-disable-next-line react-hooks/rules-of-hooks
67
+ useFocusTrap(isOpen && wrapperRef.current, (_childrenRef$current = childrenRef.current) === null || _childrenRef$current === void 0 ? void 0 : _childrenRef$current.firstChild); // eslint-disable-next-line react-hooks/rules-of-hooks
68
68
 
69
69
  var previousOpen = useRef(isOpen); // eslint-disable-next-line react-hooks/rules-of-hooks
70
70
 
@@ -1 +1 @@
1
- {"version":3,"file":"Lightbox2.js","sources":["../../../src/components/lightbox/Lightbox.tsx"],"sourcesContent":["import React, { forwardRef, RefObject, useRef, useEffect } from 'react';\n\nimport classNames from 'classnames';\nimport { createPortal } from 'react-dom';\n\nimport { mdiClose } from '@lumx/icons';\nimport { ColorPalette, Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';\nimport { DOCUMENT } from '@lumx/react/constants';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\nimport { useDelayedVisibility } from '@lumx/react/hooks/useDelayedVisibility';\nimport { useDisableBodyScroll } from '@lumx/react/hooks/useDisableBodyScroll';\nimport { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\nimport { useCallbackOnEscape } from '@lumx/react/hooks/useCallbackOnEscape';\n\nconst LIGHTBOX_TRANSITION_DURATION = 400;\n\n/**\n * Defines the props of the component.\n */\nexport interface LightboxProps extends GenericProps {\n /** Props to pass to the close button (minus those already set by the Lightbox props). */\n closeButtonProps?: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Reference to the element that triggered modal opening to set focus on. */\n parentElement: RefObject<any>;\n /** Whether to keep the dialog open on clickaway or escape press. */\n preventAutoClose?: boolean;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Z-axis position. */\n zIndex?: number;\n /** On close callback. */\n onClose?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Lightbox';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Lightbox component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Lightbox: Comp<LightboxProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n ariaLabel,\n children,\n className,\n closeButtonProps,\n isOpen,\n onClose,\n parentElement,\n preventAutoClose,\n theme,\n zIndex,\n ...forwardedProps\n } = props;\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const childrenRef = useRef<any>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useDisableBodyScroll(isOpen && wrapperRef.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const isVisible = useDelayedVisibility(!!isOpen, LIGHTBOX_TRANSITION_DURATION);\n\n // Handle focus trap.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFocusTrap(wrapperRef.current, childrenRef.current?.firstChild);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const previousOpen = useRef(isOpen);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (isOpen !== previousOpen.current) {\n previousOpen.current = isOpen;\n\n // Focus the parent element on close.\n if (!isOpen && parentElement && parentElement.current) {\n parentElement.current.focus();\n }\n }\n }, [isOpen, parentElement]);\n\n // Close lightbox on escape key pressed.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCallbackOnEscape(onClose);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const clickAwayRefs = useRef([wrapperRef]);\n\n if (!isOpen && !isVisible) return null;\n\n return createPortal(\n /* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */\n <div\n ref={mergeRefs(ref, wrapperRef)}\n {...forwardedProps}\n aria-label={ariaLabel}\n aria-modal=\"true\"\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n isHidden: !isOpen,\n isShown: isOpen || isVisible,\n theme,\n }),\n )}\n style={{ zIndex }}\n >\n {closeButtonProps && (\n <IconButton\n {...closeButtonProps}\n className={`${CLASSNAME}__close`}\n color={ColorPalette.light}\n emphasis={Emphasis.low}\n icon={mdiClose}\n theme={theme}\n type=\"button\"\n onClick={onClose}\n />\n )}\n <ClickAwayProvider callback={!preventAutoClose && onClose} refs={clickAwayRefs}>\n <div ref={childrenRef} className={`${CLASSNAME}__wrapper`} role=\"presentation\">\n {children}\n </div>\n </ClickAwayProvider>\n </div>,\n document.body,\n );\n});\nLightbox.displayName = COMPONENT_NAME;\nLightbox.className = CLASSNAME;\n"],"names":["LIGHTBOX_TRANSITION_DURATION","COMPONENT_NAME","CLASSNAME","getRootClassName","Lightbox","forwardRef","props","ref","ariaLabel","children","className","closeButtonProps","isOpen","onClose","parentElement","preventAutoClose","theme","zIndex","forwardedProps","DOCUMENT","childrenRef","useRef","wrapperRef","useDisableBodyScroll","current","isVisible","useDelayedVisibility","useFocusTrap","firstChild","previousOpen","useEffect","focus","useCallbackOnEscape","clickAwayRefs","createPortal","mergeRefs","classNames","handleBasicClasses","prefix","isHidden","isShown","ColorPalette","light","Emphasis","low","mdiClose","document","body","displayName"],"mappings":";;;;;;;;;;;;;;AAiBA,IAAMA,4BAA4B,GAAG,GAArC;AAEA;;;;AAqBA;;;AAGA,IAAMC,cAAc,GAAG,UAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;;;;;IAOaG,QAA6C,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA;;AAAA,MAEhFC,SAFgF,GAahFF,KAbgF,CAEhFE,SAFgF;AAAA,MAGhFC,QAHgF,GAahFH,KAbgF,CAGhFG,QAHgF;AAAA,MAIhFC,SAJgF,GAahFJ,KAbgF,CAIhFI,SAJgF;AAAA,MAKhFC,gBALgF,GAahFL,KAbgF,CAKhFK,gBALgF;AAAA,MAMhFC,MANgF,GAahFN,KAbgF,CAMhFM,MANgF;AAAA,MAOhFC,OAPgF,GAahFP,KAbgF,CAOhFO,OAPgF;AAAA,MAQhFC,aARgF,GAahFR,KAbgF,CAQhFQ,aARgF;AAAA,MAShFC,gBATgF,GAahFT,KAbgF,CAShF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box.tsx"],"sourcesContent":["import React, { forwardRef, RefObject, useRef, useEffect } from 'react';\n\nimport classNames from 'classnames';\nimport { createPortal } from 'react-dom';\n\nimport { mdiClose } from '@lumx/icons';\nimport { ColorPalette, Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';\nimport { DOCUMENT } from '@lumx/react/constants';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\nimport { useFocusTrap } from '@lumx/react/hooks/useFocusTrap';\nimport { useDelayedVisibility } from '@lumx/react/hooks/useDelayedVisibility';\nimport { useDisableBodyScroll } from '@lumx/react/hooks/useDisableBodyScroll';\nimport { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\nimport { useCallbackOnEscape } from '@lumx/react/hooks/useCallbackOnEscape';\n\nconst LIGHTBOX_TRANSITION_DURATION = 400;\n\n/**\n * Defines the props of the component.\n */\nexport interface LightboxProps extends GenericProps {\n /** Props to pass to the close button (minus those already set by the Lightbox props). */\n closeButtonProps?: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** Whether the component is open or not. */\n isOpen?: boolean;\n /** Reference to the element that triggered modal opening to set focus on. */\n parentElement: RefObject<any>;\n /** Whether to keep the dialog open on clickaway or escape press. */\n preventAutoClose?: boolean;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Z-axis position. */\n zIndex?: number;\n /** On close callback. */\n onClose?(): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Lightbox';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Lightbox component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Lightbox: Comp<LightboxProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n ariaLabel,\n children,\n className,\n closeButtonProps,\n isOpen,\n onClose,\n parentElement,\n preventAutoClose,\n theme,\n zIndex,\n ...forwardedProps\n } = props;\n if (!DOCUMENT) {\n // Can't render in SSR.\n return null;\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const childrenRef = useRef<any>(null);\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useDisableBodyScroll(isOpen && wrapperRef.current);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const isVisible = useDelayedVisibility(!!isOpen, LIGHTBOX_TRANSITION_DURATION);\n\n // Handle focus trap.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFocusTrap(isOpen && wrapperRef.current, childrenRef.current?.firstChild);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const previousOpen = useRef(isOpen);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (isOpen !== previousOpen.current) {\n previousOpen.current = isOpen;\n\n // Focus the parent element on close.\n if (!isOpen && parentElement && parentElement.current) {\n parentElement.current.focus();\n }\n }\n }, [isOpen, parentElement]);\n\n // Close lightbox on escape key pressed.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCallbackOnEscape(onClose);\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const clickAwayRefs = useRef([wrapperRef]);\n\n if (!isOpen && !isVisible) return null;\n\n return createPortal(\n /* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */\n <div\n ref={mergeRefs(ref, wrapperRef)}\n {...forwardedProps}\n aria-label={ariaLabel}\n aria-modal=\"true\"\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n isHidden: !isOpen,\n isShown: isOpen || isVisible,\n theme,\n }),\n )}\n style={{ zIndex }}\n >\n {closeButtonProps && (\n <IconButton\n {...closeButtonProps}\n className={`${CLASSNAME}__close`}\n color={ColorPalette.light}\n emphasis={Emphasis.low}\n icon={mdiClose}\n theme={theme}\n type=\"button\"\n onClick={onClose}\n />\n )}\n <ClickAwayProvider callback={!preventAutoClose && onClose} refs={clickAwayRefs}>\n <div ref={childrenRef} className={`${CLASSNAME}__wrapper`} role=\"presentation\">\n {children}\n </div>\n </ClickAwayProvider>\n </div>,\n document.body,\n );\n});\nLightbox.displayName = COMPONENT_NAME;\nLightbox.className = CLASSNAME;\n"],"names":["LIGHTBOX_TRANSITION_DURATION","COMPONENT_NAME","CLASSNAME","getRootClassName","Lightbox","forwardRef","props","ref","ariaLabel","children","className","closeButtonProps","isOpen","onClose","parentElement","preventAutoClose","theme","zIndex","forwardedProps","DOCUMENT","childrenRef","useRef","wrapperRef","useDisableBodyScroll","current","isVisible","useDelayedVisibility","useFocusTrap","firstChild","previousOpen","useEffect","focus","useCallbackOnEscape","clickAwayRefs","createPortal","mergeRefs","classNames","handleBasicClasses","prefix","isHidden","isShown","ColorPalette","light","Emphasis","low","mdiClose","document","body","displayName"],"mappings":";;;;;;;;;;;;;;AAiBA,IAAMA,4BAA4B,GAAG,GAArC;AAEA;;;;AAqBA;;;AAGA,IAAMC,cAAc,GAAG,UAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;;;;;IAOaG,QAA6C,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA;;AAAA,MAEhFC,SAFgF,GAahFF,KAbgF,CAEhFE,SAFgF;AAAA,MAGhFC,QAHgF,GAahFH,KAbgF,CAGhFG,QAHgF;AAAA,MAIhFC,SAJgF,GAahFJ,KAbgF,CAIhFI,SAJgF;AAAA,MAKhFC,gBALgF,GAahFL,KAbgF,CAKhFK,gBALgF;AAAA,MAMhFC,MANgF,GAahFN,KAbgF,CAMhFM,MANgF;AAAA,MAOhFC,OAPgF,GAahFP,KAbgF,CAOhFO,OAPgF;AAAA,MAQhFC,aARgF,GAahFR,KAbgF,CAQhFQ,aARgF;AAAA,MAShF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+1,6 @@
1
- import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
1
+ import { b as _objectWithoutProperties, c as _extends, _ as _objectSpread2 } from './_rollupPluginBabelHelpers.js';
2
2
  import { AspectRatio, Theme, ColorPalette, ColorVariant, Size } from './components.js';
3
- import React, { forwardRef, useCallback } from 'react';
3
+ import React, { forwardRef } from 'react';
4
4
  import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
5
5
  import { L as Link } from './Link2.js';
6
6
  import { T as Thumbnail } from './Thumbnail2.js';
@@ -24,7 +24,8 @@ var CLASSNAME = getRootClassName(COMPONENT_NAME);
24
24
 
25
25
  var DEFAULT_PROPS = {
26
26
  size: Size.regular,
27
- theme: Theme.light
27
+ theme: Theme.light,
28
+ titleHeading: 'h2'
28
29
  };
29
30
  /**
30
31
  * LinkPreview component.
@@ -38,18 +39,18 @@ var LinkPreview = forwardRef(function (props, ref) {
38
39
  var className = props.className,
39
40
  description = props.description,
40
41
  link = props.link,
42
+ linkAs = props.linkAs,
41
43
  linkProps = props.linkProps,
42
44
  size = props.size,
43
45
  theme = props.theme,
44
46
  thumbnailProps = props.thumbnailProps,
45
47
  title = props.title,
46
- forwardedProps = _objectWithoutProperties(props, ["className", "description", "link", "linkProps", "size", "theme", "thumbnailProps", "title"]); //TODO: a11y
48
+ titleHeading = props.titleHeading,
49
+ forwardedProps = _objectWithoutProperties(props, ["className", "description", "link", "linkAs", "linkProps", "size", "theme", "thumbnailProps", "title", "titleHeading"]); // Use title heading as title wrapper (see DEFAULT_PROPS for the default value).
47
50
 
48
51
 
49
- var goToUrl = useCallback(function () {
50
- return window.open(link, '_blank');
51
- }, [link]);
52
- return React.createElement("div", _extends({
52
+ var TitleHeading = titleHeading;
53
+ return React.createElement("article", _extends({
53
54
  ref: ref
54
55
  }, forwardedProps, {
55
56
  className: classnames(className, handleBasicClasses({
@@ -62,15 +63,21 @@ var LinkPreview = forwardRef(function (props, ref) {
62
63
  }, thumbnailProps && React.createElement("div", {
63
64
  className: "".concat(CLASSNAME, "__thumbnail")
64
65
  }, React.createElement(Thumbnail, _extends({}, thumbnailProps, {
65
- onClick: goToUrl,
66
- role: "link",
66
+ linkAs: linkAs,
67
+ linkProps: _objectSpread2({}, linkProps, {
68
+ href: link,
69
+ target: '_blank',
70
+ // Avoid redundant links in focus order
71
+ tabIndex: -1
72
+ }),
67
73
  aspectRatio: AspectRatio.free,
68
74
  fillHeight: true
69
75
  }))), React.createElement("div", {
70
76
  className: "".concat(CLASSNAME, "__container")
71
- }, title && React.createElement("div", {
77
+ }, title && React.createElement(TitleHeading, {
72
78
  className: "".concat(CLASSNAME, "__title")
73
79
  }, React.createElement(Link, _extends({}, linkProps, {
80
+ linkAs: linkAs,
74
81
  target: "_blank",
75
82
  href: link,
76
83
  color: theme === Theme.light ? ColorPalette.dark : ColorPalette.light,
@@ -80,11 +87,14 @@ var LinkPreview = forwardRef(function (props, ref) {
80
87
  }, description), React.createElement("div", {
81
88
  className: "".concat(CLASSNAME, "__link")
82
89
  }, React.createElement(Link, _extends({}, linkProps, {
90
+ linkAs: linkAs,
83
91
  className: classnames("".concat(CLASSNAME, "__link"), linkProps === null || linkProps === void 0 ? void 0 : linkProps.className),
84
92
  target: "_blank",
85
93
  href: link,
86
94
  color: theme === Theme.light ? ColorPalette.primary : ColorPalette.light,
87
- colorVariant: ColorVariant.N
95
+ colorVariant: ColorVariant.N // Avoid redundant links in focus order
96
+ ,
97
+ tabIndex: title ? '-1' : undefined
88
98
  }), link)))));
89
99
  });
90
100
  LinkPreview.displayName = COMPONENT_NAME;
@@ -1 +1 @@
1
- {"version":3,"file":"LinkPreview.js","sources":["../../../src/components/link-preview/LinkPreview.tsx"],"sourcesContent":["import React, { forwardRef, useCallback } from 'react';\n\nimport classNames from 'classnames';\n\nimport {\n AspectRatio,\n ColorPalette,\n ColorVariant,\n Link,\n LinkProps,\n Size,\n Theme,\n Thumbnail,\n ThumbnailProps,\n} from '@lumx/react';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface LinkPreviewProps extends GenericProps {\n /** Description (either a string, or sanitized html). */\n description?: string | { __html: string };\n /** Link URL. */\n link: string;\n /** Props to pass to the link (minus those already set by the LinkPreview props). */\n linkProps?: Omit<LinkProps, 'color' | 'colorVariant' | 'href' | 'target'>;\n /** Size variant. */\n size?: Extract<Size, 'regular' | 'big'>;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Thumbnail for the link preview. */\n thumbnailProps?: ThumbnailProps;\n /** Title. */\n title?: string;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'LinkPreview';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS: Partial<LinkPreviewProps> = {\n size: Size.regular,\n theme: Theme.light,\n};\n\n/**\n * LinkPreview component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const LinkPreview: Comp<LinkPreviewProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { className, description, link, linkProps, size, theme, thumbnailProps, title, ...forwardedProps } = props;\n\n //TODO: a11y\n const goToUrl = useCallback(() => window.open(link, '_blank'), [link]);\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n size: size === Size.big && thumbnailProps ? Size.big : Size.regular,\n theme,\n }),\n )}\n >\n <div className={`${CLASSNAME}__wrapper`}>\n {thumbnailProps && (\n <div className={`${CLASSNAME}__thumbnail`}>\n <Thumbnail\n {...thumbnailProps}\n onClick={goToUrl}\n role=\"link\"\n aspectRatio={AspectRatio.free}\n fillHeight\n />\n </div>\n )}\n\n <div className={`${CLASSNAME}__container`}>\n {title && (\n <div className={`${CLASSNAME}__title`}>\n <Link\n {...linkProps}\n target=\"_blank\"\n href={link}\n color={theme === Theme.light ? ColorPalette.dark : ColorPalette.light}\n colorVariant={ColorVariant.N}\n >\n {title}\n </Link>\n </div>\n )}\n {description && <p className={`${CLASSNAME}__description`}>{description}</p>}\n\n <div className={`${CLASSNAME}__link`}>\n <Link\n {...linkProps}\n className={classNames(`${CLASSNAME}__link`, linkProps?.className)}\n target=\"_blank\"\n href={link}\n color={theme === Theme.light ? ColorPalette.primary : ColorPalette.light}\n colorVariant={ColorVariant.N}\n >\n {link}\n </Link>\n </div>\n </div>\n </div>\n </div>\n );\n});\n\nLinkPreview.displayName = COMPONENT_NAME;\nLinkPreview.className = CLASSNAME;\nLinkPreview.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","size","Size","regular","theme","Theme","light","LinkPreview","forwardRef","props","ref","className","description","link","linkProps","thumbnailProps","title","forwardedProps","goToUrl","useCallback","window","open","classNames","handleBasicClasses","prefix","big","AspectRatio","free","ColorPalette","dark","ColorVariant","N","primary","displayName","defaultProps"],"mappings":";;;;;;;AAkBA;;;;AAoBA;;;AAGA,IAAMA,cAAc,GAAG,aAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,aAAwC,GAAG;AAC7CC,EAAAA,IAAI,EAAEC,IAAI,CAACC,OADkC;AAE7CC,EAAAA,KAAK,EAAEC,KAAK,CAACC;AAFgC,CAAjD;AAKA;;;;;;;;IAOaC,WAAmD,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAClFC,SADkF,GACiBF,KADjB,CAClFE,SADkF;AAAA,MACvEC,WADuE,GACiBH,KADjB,CACvEG,WADuE;AAAA,MAC1DC,IAD0D,GACiBJ,KADjB,CAC1DI,IAD0D;AAAA,MACpDC,SADoD,GACiBL,KADjB,CACpDK,SADoD;AAAA,MACzCb,IADyC,GACiBQ,KADjB,CACzCR,IADyC;AAAA,MACnCG,KADmC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,EAAEwB,YAAY,CAACC;AAL/B,MAOKf,KAPL,CADJ,CAFR,EAcKJ,WAAW,IAAI;AAAG,IAAA,SAAS,YAAKd,SAAL;AAAZ,KAA4Cc,WAA5C,CAdpB,EAgBI;AAAK,IAAA,SAAS,YAAKd,SAAL;AAAd,KACI,oBAAC,IAAD,eACQgB,SADR;AAEI,IAAA,SAAS,EAAEQ,UAAU,WAAIxB,SAAJ,aAAuBgB,SAAvB,aAAuBA,SAAvB,uBAAuBA,SAAS,CAAEH,SAAlC,CAFzB;AAGI,IAAA,MAAM,EAAC,QAHX;AAII,IAAA,IAAI,EAAEE,IAJV;AAKI,IAAA,KAAK,EAAET,KAAK,KAAKC,KAAK,CAACC,KAAhB,GAAwBsB,YAAY,CAACI,OAArC,GAA+CJ,YAAY,CAACtB,KALvE;AAMI,IAAA,YAAY,EAAEwB,YAAY,CAACC;AAN/B,MAQKlB,IARL,CADJ,CAhBJ,CAbJ,CAZJ,CADJ;AA0DH,CAhE4E;AAkE7EN,WAAW,CAAC0B,WAAZ,GAA0BpC,cAA1B;AACAU,WAAW,CAACI,SAAZ,GAAwBb,SAAxB;AACAS,WAAW,CAAC2B,YAAZ,GAA2BlC,aAA3B;;;;"}
1
+ {"version":3,"file":"LinkPreview.js","sources":["../../../src/components/link-preview/LinkPreview.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport {\n AspectRatio,\n ColorPalette,\n ColorVariant,\n Link,\n LinkProps,\n Size,\n Theme,\n Thumbnail,\n ThumbnailProps,\n} from '@lumx/react';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses, HeadingElement } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport interface LinkPreviewProps extends GenericProps {\n /** Description. */\n description?: string;\n /** Link URL. */\n link: string;\n /** Custom react component for the link (can be used to inject react router Link). */\n linkAs?: 'a' | any;\n /** Props to pass to the link (minus those already set by the LinkPreview props). */\n linkProps?: Omit<LinkProps, 'color' | 'colorVariant' | 'href' | 'target'>;\n /** Size variant. */\n size?: Extract<Size, 'regular' | 'big'>;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Thumbnail for the link preview. */\n thumbnailProps?: ThumbnailProps;\n /** Title. */\n title?: string;\n /** Customize the title heading tag. */\n titleHeading?: HeadingElement;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'LinkPreview';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Component default props.\n */\nconst DEFAULT_PROPS = {\n size: Size.regular,\n theme: Theme.light,\n titleHeading: 'h2',\n} as const;\n\n/**\n * LinkPreview component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const LinkPreview: Comp<LinkPreviewProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n className,\n description,\n link,\n linkAs,\n linkProps,\n size,\n theme,\n thumbnailProps,\n title,\n titleHeading,\n ...forwardedProps\n } = props;\n // Use title heading as title wrapper (see DEFAULT_PROPS for the default value).\n const TitleHeading = titleHeading as HeadingElement;\n\n return (\n <article\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n size: size === Size.big && thumbnailProps ? Size.big : Size.regular,\n theme,\n }),\n )}\n >\n <div className={`${CLASSNAME}__wrapper`}>\n {thumbnailProps && (\n <div className={`${CLASSNAME}__thumbnail`}>\n <Thumbnail\n {...thumbnailProps}\n linkAs={linkAs}\n linkProps={{\n ...linkProps,\n href: link,\n target: '_blank',\n // Avoid redundant links in focus order\n tabIndex: -1,\n }}\n aspectRatio={AspectRatio.free}\n fillHeight\n />\n </div>\n )}\n\n <div className={`${CLASSNAME}__container`}>\n {title && (\n <TitleHeading className={`${CLASSNAME}__title`}>\n <Link\n {...linkProps}\n linkAs={linkAs}\n target=\"_blank\"\n href={link}\n color={theme === Theme.light ? ColorPalette.dark : ColorPalette.light}\n colorVariant={ColorVariant.N}\n >\n {title}\n </Link>\n </TitleHeading>\n )}\n\n {description && <p className={`${CLASSNAME}__description`}>{description}</p>}\n\n <div className={`${CLASSNAME}__link`}>\n <Link\n {...linkProps}\n linkAs={linkAs}\n className={classNames(`${CLASSNAME}__link`, linkProps?.className)}\n target=\"_blank\"\n href={link}\n color={theme === Theme.light ? ColorPalette.primary : ColorPalette.light}\n colorVariant={ColorVariant.N}\n // Avoid redundant links in focus order\n tabIndex={title ? '-1' : undefined}\n >\n {link}\n </Link>\n </div>\n </div>\n </div>\n </article>\n );\n});\n\nLinkPreview.displayName = COMPONENT_NAME;\nLinkPreview.className = CLASSNAME;\nLinkPreview.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","size","Size","regular","theme","Theme","light","titleHeading","LinkPreview","forwardRef","props","ref","className","description","link","linkAs","linkProps","thumbnailProps","title","forwardedProps","TitleHeading","classNames","handleBasicClasses","prefix","big","href","target","tabIndex","AspectRatio","free","ColorPalette","dark","ColorVariant","N","primary","undefined","displayName","defaultProps"],"mappings":";;;;;;;AAkBA;;;;AAwBA;;;AAGA,IAAMA,cAAc,GAAG,aAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,aAAa,GAAG;AAClBC,EAAAA,IAAI,EAAEC,IAAI,CAACC,OADO;AAElBC,EAAAA,KAAK,EAAEC,KAAK,CAACC,KAFK;AAGlBC,EAAAA,YAAY,EAAE;AAHI,CAAtB;AAMA;;;;;;;;IAOaC,WAAmD,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MAEtFC,SAFsF,GAatFF,KAbsF,CAEtFE,SAFsF;AAAA,MAGtFC,WAHsF,GAatFH,KAbsF,CAGtFG,WAHsF;AAAA,MAItFC,IAJsF,GAatFJ,KAbsF,CAItFI,IAJsF;AAAA,MAKtFC,MALsF,GAatF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L;AAAvB,KACI,oBAAC,IAAD,eACQkB,SADR;AAEI,IAAA,MAAM,EAAED,MAFZ;AAGI,IAAA,MAAM,EAAC,QAHX;AAII,IAAA,IAAI,EAAED,IAJV;AAKI,IAAA,KAAK,EAAEV,KAAK,KAAKC,KAAK,CAACC,KAAhB,GAAwBwB,YAAY,CAACC,IAArC,GAA4CD,YAAY,CAACxB,KALpE;AAMI,IAAA,YAAY,EAAE0B,YAAY,CAACC;AAN/B,MAQKf,KARL,CADJ,CAFR,EAgBKL,WAAW,IAAI;AAAG,IAAA,SAAS,YAAKf,SAAL;AAAZ,KAA4Ce,WAA5C,CAhBpB,EAkBI;AAAK,IAAA,SAAS,YAAKf,SAAL;AAAd,KACI,oBAAC,IAAD,eACQkB,SADR;AAEI,IAAA,MAAM,EAAED,MAFZ;AAGI,IAAA,SAAS,EAAEM,UAAU,WAAIvB,SAAJ,aAAuBkB,SAAvB,aAAuBA,SAAvB,uBAAuBA,SAAS,CAAEJ,SAAlC,CAHzB;AAII,IAAA,MAAM,EAAC,QAJX;AAKI,IAAA,IAAI,EAAEE,IALV;AAMI,IAAA,KAAK,EAAEV,KAAK,KAAKC,KAAK,CAACC,KAAhB,GAAwBwB,YAAY,CAACI,OAArC,GAA+CJ,YAAY,CAACxB,KANvE;AAOI,IAAA,YAAY,EAAE0B,YAAY,CAACC,CAP/B;AAAA;AASI,IAAA,QAAQ,EAAEf,KAAK,GAAG,IAAH,GAAUiB;AAT7B,MAWKrB,IAXL,CADJ,CAlBJ,CAnBJ,CAZJ,CADJ;AAqEH,CAtF4E;AAwF7EN,WAAW,CAAC4B,WAAZ,GAA0BvC,cAA1B;AACAW,WAAW,CAACI,SAAZ,GAAwBd,SAAxB;AACAU,WAAW,CAAC6B,YAAZ,GAA2BrC,aAA3B;;;;"}
@@ -1,10 +1,10 @@
1
1
  import { d as _slicedToArray, b as _objectWithoutProperties, _ as _objectSpread2, c as _extends } from './_rollupPluginBabelHelpers.js';
2
- import React, { useState, useEffect, useLayoutEffect, useRef, useMemo, forwardRef } from 'react';
2
+ import React, { useState, useEffect, useLayoutEffect, useRef, useMemo, forwardRef, useCallback } from 'react';
3
3
  import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
4
4
  import { D as DOCUMENT, W as WINDOW } from './constants.js';
5
5
  import { m as mergeRefs } from './mergeRefs.js';
6
+ import { g as getFirstAndLastFocusable, u as useCallbackOnEscape, C as ClickAwayProvider } from './ClickAwayProvider.js';
6
7
  import { createPortal } from 'react-dom';
7
- import { u as useCallbackOnEscape, C as ClickAwayProvider } from './ClickAwayProvider.js';
8
8
 
9
9
  /**
10
10
  * Hook focusing an element when defined and `focus` boolean `true`.
@@ -2295,13 +2295,14 @@ var Popover = forwardRef(function (props, ref) {
2295
2295
  isOpen = props.isOpen,
2296
2296
  offset = props.offset,
2297
2297
  onClose = props.onClose,
2298
+ parentElement = props.parentElement,
2298
2299
  placement = props.placement,
2299
2300
  style = props.style,
2300
2301
  usePortal = props.usePortal,
2301
2302
  zIndex = props.zIndex,
2302
2303
  _props$focusAnchorOnC = props.focusAnchorOnClose,
2303
2304
  focusAnchorOnClose = _props$focusAnchorOnC === void 0 ? true : _props$focusAnchorOnC,
2304
- forwardedProps = _objectWithoutProperties(props, ["anchorRef", "boundaryRef", "children", "className", "closeOnClickAway", "closeOnEscape", "elevation", "fitToAnchorWidth", "fitWithinViewportHeight", "focusElement", "hasArrow", "isOpen", "offset", "onClose", "placement", "style", "usePortal", "zIndex", "focusAnchorOnClose"]); // eslint-disable-next-line react-hooks/rules-of-hooks
2305
+ forwardedProps = _objectWithoutProperties(props, ["anchorRef", "boundaryRef", "children", "className", "closeOnClickAway", "closeOnEscape", "elevation", "fitToAnchorWidth", "fitWithinViewportHeight", "focusElement", "hasArrow", "isOpen", "offset", "onClose", "parentElement", "placement", "style", "usePortal", "zIndex", "focusAnchorOnClose"]); // eslint-disable-next-line react-hooks/rules-of-hooks
2305
2306
 
2306
2307
 
2307
2308
  var _useState = useState(),
@@ -2335,8 +2336,9 @@ var Popover = forwardRef(function (props, ref) {
2335
2336
  }
2336
2337
  });
2337
2338
  /** Action on close */
2339
+ // eslint-disable-next-line react-hooks/rules-of-hooks
2338
2340
 
2339
- var handleClose = function handleClose() {
2341
+ var handleClose = useCallback(function () {
2340
2342
  if (!onClose) {
2341
2343
  return;
2342
2344
  }
@@ -2348,14 +2350,25 @@ var Popover = forwardRef(function (props, ref) {
2348
2350
 
2349
2351
 
2350
2352
  if (isFocusedWithin.current && focusAnchorOnClose) {
2351
- var _anchorRef$current;
2353
+ if (parentElement === null || parentElement === void 0 ? void 0 : parentElement.current) {
2354
+ parentElement === null || parentElement === void 0 ? void 0 : parentElement.current.focus();
2355
+ }
2356
+
2357
+ var firstFocusable = (anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current) && getFirstAndLastFocusable(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current).first;
2358
+
2359
+ if (firstFocusable) {
2360
+ // Focus the first focusable element in anchor.
2361
+ firstFocusable.focus();
2362
+ } else {
2363
+ var _anchorRef$current;
2352
2364
 
2353
- (_anchorRef$current = anchorRef.current) === null || _anchorRef$current === void 0 ? void 0 : _anchorRef$current.focus();
2365
+ // Fallback on the anchor element.
2366
+ anchorRef === null || anchorRef === void 0 ? void 0 : (_anchorRef$current = anchorRef.current) === null || _anchorRef$current === void 0 ? void 0 : _anchorRef$current.focus();
2367
+ }
2354
2368
  }
2355
2369
 
2356
2370
  onClose();
2357
- };
2358
-
2371
+ }, [anchorRef, focusAnchorOnClose, onClose, parentElement]);
2359
2372
  var modifiers = [];
2360
2373
  var actualOffset = [(_ref5 = offset === null || offset === void 0 ? void 0 : offset.along) !== null && _ref5 !== void 0 ? _ref5 : 0, ((_ref6 = offset === null || offset === void 0 ? void 0 : offset.away) !== null && _ref6 !== void 0 ? _ref6 : 0) + (hasArrow ? ARROW_SIZE : 0)];
2361
2374
  modifiers.push({