@lumx/react 2.1.3 → 2.1.4
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/esm/_internal/Dialog2.js +13 -8
- package/esm/_internal/Dialog2.js.map +1 -1
- package/esm/_internal/Flag2.js +1 -3
- package/esm/_internal/Flag2.js.map +1 -1
- package/esm/_internal/Message2.js +2 -2
- package/esm/_internal/Message2.js.map +1 -1
- package/esm/_internal/SlideshowControls.js +2 -2
- package/esm/_internal/SlideshowControls.js.map +1 -1
- package/package.json +4 -4
- package/src/components/dialog/Dialog.stories.tsx +44 -2
- package/src/components/dialog/Dialog.tsx +15 -11
- package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +76 -0
- package/src/components/flag/Flag.test.tsx +1 -2
- package/src/components/flag/Flag.tsx +2 -10
- package/src/components/flag/__snapshots__/Flag.test.tsx.snap +0 -15
- package/src/components/message/Message.tsx +2 -2
- package/src/components/slideshow/useKeyNavigate.ts +2 -2
package/esm/_internal/Dialog2.js
CHANGED
|
@@ -151,17 +151,22 @@ var Dialog = forwardRef(function (props, ref) {
|
|
|
151
151
|
zIndex = props.zIndex,
|
|
152
152
|
dialogProps = props.dialogProps,
|
|
153
153
|
onVisibilityChange = props.onVisibilityChange,
|
|
154
|
-
forwardedProps = _objectWithoutProperties(props, ["children", "className", "header", "focusElement", "forceFooterDivider", "forceHeaderDivider", "footer", "isLoading", "isOpen", "onClose", "parentElement", "contentRef", "preventAutoClose", "size", "zIndex", "dialogProps", "onVisibilityChange"]);
|
|
154
|
+
forwardedProps = _objectWithoutProperties(props, ["children", "className", "header", "focusElement", "forceFooterDivider", "forceHeaderDivider", "footer", "isLoading", "isOpen", "onClose", "parentElement", "contentRef", "preventAutoClose", "size", "zIndex", "dialogProps", "onVisibilityChange"]); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
155
155
|
|
|
156
|
-
var handleClose = onClose ? function () {
|
|
157
|
-
onClose(); // Focus the parent element on close.
|
|
158
156
|
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
var previousOpen = React.useRef(isOpen); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
158
|
+
|
|
159
|
+
React.useEffect(function () {
|
|
160
|
+
if (isOpen !== previousOpen.current) {
|
|
161
|
+
previousOpen.current = isOpen; // Focus the parent element on close.
|
|
162
|
+
|
|
163
|
+
if (!isOpen && parentElement && parentElement.current) {
|
|
164
|
+
parentElement.current.focus();
|
|
165
|
+
}
|
|
161
166
|
}
|
|
162
|
-
}
|
|
167
|
+
}, [isOpen, parentElement]); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
163
168
|
|
|
164
|
-
useCallbackOnEscape(
|
|
169
|
+
useCallbackOnEscape(onClose, isOpen && !preventAutoClose); // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
165
170
|
|
|
166
171
|
var wrapperRef = useRef(null);
|
|
167
172
|
/**
|
|
@@ -234,7 +239,7 @@ var Dialog = forwardRef(function (props, ref) {
|
|
|
234
239
|
role: "dialog",
|
|
235
240
|
"aria-modal": "true"
|
|
236
241
|
}, dialogProps), React.createElement(ClickAwayProvider, {
|
|
237
|
-
callback: !preventAutoClose &&
|
|
242
|
+
callback: !preventAutoClose && onClose,
|
|
238
243
|
refs: clickAwayRefs
|
|
239
244
|
}, React.createElement("div", {
|
|
240
245
|
className: "".concat(CLASSNAME, "__wrapper"),
|
|
@@ -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 const handleClose = onClose\n ? () => {\n onClose();\n // Focus the parent element on close.\n if (parentElement && parentElement.current) {\n parentElement.current.focus();\n }\n }\n : undefined;\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCallbackOnEscape(handleClose, 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 && handleClose} 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","handleClose","current","focus","useCallbackOnEscape","wrapperRef","useRef","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;AAAA,YAArBiB,OAAqB;;AAC5B,YAAIA,OAAJ,EAAa;AACTN,UAAA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AAAK,IAAA,GAAG,EAAEa,SAAS,CAAC7C,UAAD,EAAaY,eAAb,CAAnB;AAAkD,IAAA,SAAS,YAAKlC,SAAL;AAA3D,KACI;AACI,IAAA,SAAS,YAAKA,SAAL,wBAA4BA,SAA5B,oBADb;AAEI,IAAA,GAAG,EAAEsC;AAFT,IADJ,EAMKc,OANL,EAQI;AACI,IAAA,SAAS,YAAKpD,SAAL,wBAA4BA,SAA5B,uBADb;AAEI,IAAA,GAAG,EAAEwC;AAFT,IARJ,CAhBJ,EA8BK,CAACvB,MAAM,IAAIuC,kBAAX,KACG,2CACQD,gBADR;AAEI,IAAA,SAAS,EAAEO,UAAU,WACd9D,SADc,eAEjB,CAACe,kBAAkB,IAAI8B,qBAAvB,eACO7C,SADP,0BAFiB,EAIjBuD,gBAJiB,aAIjBA,gBAJiB,uBAIjBA,gBAAgB,CAAE3C,SAJD;AAFzB,MASKK,MATL,EAUKuC,kBAVL,CA/BR,EA6CKtC,SAAS,IACN;AAAK,IAAA,SAAS,YAAKlB,SAAL;AAAd,KACI,oBAAC,QAAD;AAAU,IAAA,OAAO,EAAEoE,eAAe,CAACC;AAAnC,IADJ,CA9CR,CADJ,CADJ,CAjBJ,CADQ,EA0ERC,QAAQ,CAACC,IA1ED,CADX,GA6ED,IA7EN;AA8EH,CAlKkE;AAmKnEjE,MAAM,CAACkE,WAAP,GAAqBzE,cAArB;AACAO,MAAM,CAACM,SAAP,GAAmBZ,SAAnB;AACAM,MAAM,CAACmE,YAAP,GAAsBvE,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, 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;;;;;;;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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E;AAuKnElE,MAAM,CAACmE,WAAP,GAAqB1E,cAArB;AACAO,MAAM,CAACM,SAAP,GAAmBZ,SAAnB;AACAM,MAAM,CAACoE,YAAP,GAAsBxE,aAAtB;;;;"}
|
package/esm/_internal/Flag2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { b as _objectWithoutProperties, c as _extends } from './_rollupPluginBabelHelpers.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Size, Theme, ColorPalette } from './components.js';
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
4
|
import { g as getRootClassName, c as classnames, h as handleBasicClasses } from './getRootClassName.js';
|
|
5
5
|
import { I as Icon } from './Icon2.js';
|
|
@@ -34,8 +34,6 @@ var Flag = forwardRef(function (props, ref) {
|
|
|
34
34
|
ref: ref
|
|
35
35
|
}), icon && React.createElement(Icon, {
|
|
36
36
|
icon: icon,
|
|
37
|
-
color: color,
|
|
38
|
-
colorVariant: ColorVariant.D2,
|
|
39
37
|
size: Size.xxs,
|
|
40
38
|
className: "".concat(CLASSNAME, "__icon")
|
|
41
39
|
}), React.createElement("span", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Flag2.js","sources":["../../../src/components/flag/Flag.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport classNames from 'classnames';\n\nimport { ColorPalette,
|
|
1
|
+
{"version":3,"file":"Flag2.js","sources":["../../../src/components/flag/Flag.tsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport classNames from 'classnames';\n\nimport { ColorPalette, Icon, Size, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\nexport interface FlagProps extends GenericProps {\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Color of the component. */\n color?: ColorPalette;\n /** Icon to use before the label. */\n icon?: string;\n /** Text label of the flag. */\n label: string;\n}\n\nconst COMPONENT_NAME = 'Flag';\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\nconst DEFAULT_PROPS: Partial<FlagProps> = {\n theme: Theme.light,\n};\n\n/**\n * Flag component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Flag: Comp<FlagProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { label, icon, color, className, theme, ...forwardedProps } = props;\n const flagColor = color || (theme === Theme.light ? ColorPalette.dark : ColorPalette.light);\n\n return (\n <div\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, color: flagColor }))}\n ref={ref}\n >\n {icon && <Icon icon={icon} size={Size.xxs} className={`${CLASSNAME}__icon`} />}\n <span className={`${CLASSNAME}__label`}>{label}</span>\n </div>\n );\n});\nFlag.displayName = COMPONENT_NAME;\nFlag.className = CLASSNAME;\nFlag.defaultProps = DEFAULT_PROPS;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","theme","Theme","light","Flag","forwardRef","props","ref","label","icon","color","className","forwardedProps","flagColor","ColorPalette","dark","classNames","handleBasicClasses","prefix","Size","xxs","displayName","defaultProps"],"mappings":";;;;;;AAiBA,IAAMA,cAAc,GAAG,MAAvB;AACA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AACA,IAAMG,aAAiC,GAAG;AACtCC,EAAAA,KAAK,EAAEC,KAAK,CAACC;AADyB,CAA1C;AAIA;;;;;;;;IAOaC,IAAqC,GAAGC,UAAU,CAAC,UAACC,KAAD,EAAQC,GAAR,EAAgB;AAAA,MACpEC,KADoE,GACRF,KADQ,CACpEE,KADoE;AAAA,MAC7DC,IAD6D,GACRH,KADQ,CAC7DG,IAD6D;AAAA,MACvDC,KADuD,GACRJ,KADQ,CACvDI,KADuD;AAAA,MAChDC,SADgD,GACRL,KADQ,CAChDK,SADgD;AAAA,MACrCV,KADqC,GACRK,KADQ,CACrCL,KADqC;AAAA,MAC3BW,cAD2B,4BACRN,KADQ;;AAE5E,MAAMO,SAAS,GAAGH,KAAK,KAAKT,KAAK,KAAKC,KAAK,CAACC,KAAhB,GAAwBW,YAAY,CAACC,IAArC,GAA4CD,YAAY,CAACX,KAA9D,CAAvB;AAEA,SACI,wCACQS,cADR;AAEI,IAAA,SAAS,EAAEI,UAAU,CAACL,SAAD,EAAYM,kBAAkB,CAAC;AAAEC,MAAAA,MAAM,EAAEpB,SAAV;AAAqBY,MAAAA,KAAK,EAAEG;AAA5B,KAAD,CAA9B,CAFzB;AAGI,IAAA,GAAG,EAAEN;AAHT,MAKKE,IAAI,IAAI,oBAAC,IAAD;AAAM,IAAA,IAAI,EAAEA,IAAZ;AAAkB,IAAA,IAAI,EAAEU,IAAI,CAACC,GAA7B;AAAkC,IAAA,SAAS,YAAKtB,SAAL;AAA3C,IALb,EAMI;AAAM,IAAA,SAAS,YAAKA,SAAL;AAAf,KAAyCU,KAAzC,CANJ,CADJ;AAUH,CAd8D;AAe/DJ,IAAI,CAACiB,WAAL,GAAmBxB,cAAnB;AACAO,IAAI,CAACO,SAAL,GAAiBb,SAAjB;AACAM,IAAI,CAACkB,YAAL,GAAoBtB,aAApB;;;;"}
|
|
@@ -64,11 +64,11 @@ var Message = forwardRef(function (props, ref) {
|
|
|
64
64
|
prefix: CLASSNAME
|
|
65
65
|
}))
|
|
66
66
|
}, forwardedProps), (customIcon || icon) && React.createElement(Icon, {
|
|
67
|
-
className: "
|
|
67
|
+
className: "".concat(CLASSNAME, "__icon"),
|
|
68
68
|
icon: customIcon || icon,
|
|
69
69
|
size: Size.xs
|
|
70
70
|
}), React.createElement("div", {
|
|
71
|
-
className: "
|
|
71
|
+
className: "".concat(CLASSNAME, "__text")
|
|
72
72
|
}, children));
|
|
73
73
|
});
|
|
74
74
|
Message.displayName = COMPONENT_NAME;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Message2.js","sources":["../../../src/components/message/Message.tsx"],"sourcesContent":["import { mdiAlert, mdiAlertCircle, mdiCheckCircle, mdiInformation } from '@lumx/icons';\nimport { ColorPalette, Icon, Kind, Size } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport classNames from 'classnames';\nimport React, { forwardRef, ReactNode } from 'react';\n\n/**\n * Defines the props of the component.\n */\nexport interface MessageProps extends GenericProps {\n /** Content. */\n children?: ReactNode;\n /** Whether the message has a background or not. */\n hasBackground?: boolean;\n /** Message variant. */\n kind?: Kind;\n /** Message custom icon SVG path. */\n icon?: string;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Message';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Associative map from message kind to color and icon.\n */\nconst CONFIG = {\n [Kind.error]: { color: ColorPalette.red, icon: mdiAlert },\n [Kind.info]: { color: ColorPalette.dark, icon: mdiInformation },\n [Kind.success]: { color: ColorPalette.green, icon: mdiCheckCircle },\n [Kind.warning]: { color: ColorPalette.yellow, icon: mdiAlertCircle },\n};\n\n/**\n * Message component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Message: Comp<MessageProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { children, className, hasBackground, kind, icon: customIcon, ...forwardedProps } = props;\n const { color, icon } = CONFIG[kind as Kind] || {};\n\n return (\n <div\n ref={ref}\n className={classNames(\n className,\n handleBasicClasses({\n color,\n hasBackground,\n prefix: CLASSNAME,\n }),\n )}\n {...forwardedProps}\n >\n {(customIcon || icon) && <Icon className
|
|
1
|
+
{"version":3,"file":"Message2.js","sources":["../../../src/components/message/Message.tsx"],"sourcesContent":["import { mdiAlert, mdiAlertCircle, mdiCheckCircle, mdiInformation } from '@lumx/icons';\nimport { ColorPalette, Icon, Kind, Size } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport classNames from 'classnames';\nimport React, { forwardRef, ReactNode } from 'react';\n\n/**\n * Defines the props of the component.\n */\nexport interface MessageProps extends GenericProps {\n /** Content. */\n children?: ReactNode;\n /** Whether the message has a background or not. */\n hasBackground?: boolean;\n /** Message variant. */\n kind?: Kind;\n /** Message custom icon SVG path. */\n icon?: string;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Message';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * Associative map from message kind to color and icon.\n */\nconst CONFIG = {\n [Kind.error]: { color: ColorPalette.red, icon: mdiAlert },\n [Kind.info]: { color: ColorPalette.dark, icon: mdiInformation },\n [Kind.success]: { color: ColorPalette.green, icon: mdiCheckCircle },\n [Kind.warning]: { color: ColorPalette.yellow, icon: mdiAlertCircle },\n};\n\n/**\n * Message component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Message: Comp<MessageProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { children, className, hasBackground, kind, icon: customIcon, ...forwardedProps } = props;\n const { color, icon } = CONFIG[kind as Kind] || {};\n\n return (\n <div\n ref={ref}\n className={classNames(\n className,\n handleBasicClasses({\n color,\n hasBackground,\n prefix: CLASSNAME,\n }),\n )}\n {...forwardedProps}\n >\n {(customIcon || icon) && <Icon className={`${CLASSNAME}__icon`} icon={customIcon || icon} size={Size.xs} />}\n <div className={`${CLASSNAME}__text`}>{children}</div>\n </div>\n );\n});\nMessage.displayName = COMPONENT_NAME;\nMessage.className = CLASSNAME;\n"],"names":["COMPONENT_NAME","CLASSNAME","getRootClassName","CONFIG","Kind","error","color","ColorPalette","red","icon","mdiAlert","info","dark","mdiInformation","success","green","mdiCheckCircle","warning","yellow","mdiAlertCircle","Message","forwardRef","props","ref","children","className","hasBackground","kind","customIcon","forwardedProps","classNames","handleBasicClasses","prefix","Size","xs","displayName"],"mappings":";;;;;;;;AAMA;;;;AAcA;;;AAGA,IAAMA,cAAc,GAAG,SAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAE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YK,CAACD,UAAU,IAAInB,IAAf,KAAwB,oBAAC,IAAD;AAAM,IAAA,SAAS,YAAKR,SAAL,WAAf;AAAuC,IAAA,IAAI,EAAE2B,UAAU,IAAInB,IAA3D;AAAiE,IAAA,IAAI,EAAEwB,IAAI,CAACC;AAA5E,IAZ7B,EAaI;AAAK,IAAA,SAAS,YAAKjC,SAAL;AAAd,KAAuCuB,QAAvC,CAbJ,CADJ;AAiBH,CArBoE;AAsBrEJ,OAAO,CAACe,WAAR,GAAsBnC,cAAtB;AACAoB,OAAO,CAACK,SAAR,GAAoBxB,SAApB;;;;"}
|
|
@@ -302,9 +302,9 @@ function useKeyNavigate(element, onNext, onPrevious) {
|
|
|
302
302
|
var callback;
|
|
303
303
|
|
|
304
304
|
if ((evt === null || evt === void 0 ? void 0 : evt.key) === 'ArrowRight') {
|
|
305
|
-
callback = onPrevious;
|
|
306
|
-
} else if ((evt === null || evt === void 0 ? void 0 : evt.key) === 'ArrowLeft') {
|
|
307
305
|
callback = onNext;
|
|
306
|
+
} else if ((evt === null || evt === void 0 ? void 0 : evt.key) === 'ArrowLeft') {
|
|
307
|
+
callback = onPrevious;
|
|
308
308
|
}
|
|
309
309
|
|
|
310
310
|
if (!callback) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlideshowControls.js","sources":["../../../src/components/slideshow/constants.ts","../../../src/hooks/useInterval.tsx","../../../src/components/slideshow/Slideshow.tsx","../../../src/components/slideshow/SlideshowItem.tsx","../../../src/components/slideshow/useSwipeNavigate.ts","../../../src/components/slideshow/useKeyNavigate.ts","../../../src/components/slideshow/usePaginationVisibleRange.ts","../../../src/components/slideshow/SlideshowControls.tsx"],"sourcesContent":["/**\n * Autoplay default interval in ms.\n */\nexport const AUTOPLAY_DEFAULT_INTERVAL = 5000;\n\n/**\n * Full width size in percent.\n */\nexport const FULL_WIDTH_PERCENT = 100;\n\n/**\n * Edge from the active index.\n */\nexport const EDGE_FROM_ACTIVE_INDEX = 2;\n\n/**\n * Max number of pagination items.\n */\nexport const PAGINATION_ITEMS_MAX = 5;\n\n/**\n * Size of a pagination item. Used to translate wrapper.\n */\nexport const PAGINATION_ITEM_SIZE = 12;\n","import { useEffect, useRef } from 'react';\n\nimport isFunction from 'lodash/isFunction';\nimport { Callback } from '../utils';\n\n/**\n * Making setInterval Declarative with React Hooks.\n * Credits: https://overreacted.io/making-setinterval-declarative-with-react-hooks/\n *\n * @param callback Function called by setInterval.\n * @param delay Delay for setInterval.\n */\nexport function useInterval(callback: Callback, delay: number | null): void {\n const savedCallback = useRef<Callback>();\n\n useEffect(() => {\n savedCallback.current = callback;\n });\n\n useEffect(() => {\n if (delay === null) return undefined;\n\n function tick() {\n if (isFunction(savedCallback.current)) {\n savedCallback.current();\n }\n }\n const id = setInterval(tick, delay);\n return () => clearInterval(id);\n }, [delay]);\n}\n","import React, { CSSProperties, forwardRef, useCallback, useEffect, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { SlideshowControls, SlideshowControlsProps, Theme } from '@lumx/react';\n\nimport { AUTOPLAY_DEFAULT_INTERVAL, FULL_WIDTH_PERCENT } from '@lumx/react/components/slideshow/constants';\nimport { useInterval } from '@lumx/react/hooks/useInterval';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\n/**\n * Defines the props of the component.\n */\nexport interface SlideshowProps extends GenericProps {\n /** Index of the current slide. */\n activeIndex?: number;\n /** Whether the automatic rotation of the slideshow is enabled or not. */\n autoPlay?: boolean;\n /** Whether the image has to fill its container height or not. */\n fillHeight?: boolean;\n /** Number of slides to group together. */\n groupBy?: number;\n /** Interval between each slide when automatic rotation is enabled. */\n interval?: number;\n /** Props to pass to the slideshow controls (minus those already set by the Slideshow props). */\n slideshowControlsProps?: Pick<SlideshowControlsProps, 'nextButtonProps' | 'previousButtonProps'> &\n Omit<\n SlideshowControlsProps,\n | 'activeIndex'\n | 'onPaginationClick'\n | 'onNextClick'\n | 'onPreviousClick'\n | 'slidesCount'\n | 'parentRef'\n | 'theme'\n >;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Callback when slide changes */\n onChange?(index: number): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Slideshow';\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<SlideshowProps> = {\n activeIndex: 0,\n groupBy: 1,\n interval: AUTOPLAY_DEFAULT_INTERVAL,\n theme: Theme.light,\n};\n\n/**\n * Slideshow component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Slideshow: Comp<SlideshowProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n activeIndex,\n autoPlay,\n children,\n className,\n fillHeight,\n groupBy,\n interval,\n onChange,\n slideshowControlsProps,\n theme,\n ...forwardedProps\n } = props;\n const [currentIndex, setCurrentIndex] = useState(activeIndex as number);\n // Use state instead of a ref to make the slideshow controls update directly when the element is set.\n const [element, setElement] = useState<HTMLDivElement>();\n\n // Number of slideshow items.\n const itemsCount = React.Children.count(children);\n // Number of slides when using groupBy prop.\n const slidesCount = Math.ceil(itemsCount / Math.min(groupBy as number, itemsCount));\n // Inline style of wrapper element.\n const wrapperStyle: CSSProperties = { transform: `translateX(-${FULL_WIDTH_PERCENT * currentIndex}%)` };\n\n // Change current index to display next slide.\n const goToNextSlide = useCallback(\n (loopback = true) => {\n setCurrentIndex((index) => {\n if (loopback && index === slidesCount - 1) {\n // Loopback to the start.\n return 0;\n }\n if (index < slidesCount - 1) {\n // Next slide.\n return index + 1;\n }\n return index;\n });\n },\n [slidesCount, setCurrentIndex],\n );\n\n // Change current index to display previous slide.\n const goToPreviousSlide = useCallback(\n (loopback = true) => {\n setCurrentIndex((index) => {\n if (loopback && index === 0) {\n // Loopback to the end.\n return slidesCount - 1;\n }\n if (index > 0) {\n // Previous slide.\n return index - 1;\n }\n return index;\n });\n },\n [slidesCount, setCurrentIndex],\n );\n\n // Auto play\n const [isAutoPlaying, setIsAutoPlaying] = useState(Boolean(autoPlay));\n // Start\n useInterval(goToNextSlide, isAutoPlaying && slidesCount > 1 ? (interval as number) : null);\n\n // Reset current index if it become invalid.\n useEffect(() => {\n if (currentIndex > slidesCount - 1) {\n setCurrentIndex(DEFAULT_PROPS.activeIndex as number);\n }\n }, [currentIndex, slidesCount]);\n\n // Handle click on a bullet to go to a specific slide.\n const handleControlGotToSlide = useCallback(\n (index: number) => {\n setIsAutoPlaying(false);\n\n if (index >= 0 && index < slidesCount) {\n setCurrentIndex(index);\n }\n },\n [slidesCount, setCurrentIndex],\n );\n\n // Handle click or keyboard event to go to next slide.\n const handleControlNextSlide = useCallback(\n (loopback = true) => {\n setIsAutoPlaying(false);\n goToNextSlide(loopback);\n },\n [goToNextSlide],\n );\n\n // Handle click or keyboard event to go to previous slide.\n const handleControlPreviousSlide = useCallback(\n (loopback = true) => {\n setIsAutoPlaying(false);\n goToPreviousSlide(loopback);\n },\n [goToPreviousSlide],\n );\n\n // If the activeIndex props changes, update the current slide\n useEffect(() => {\n setCurrentIndex(activeIndex as number);\n }, [activeIndex]);\n\n // If the slide changes, with autoplay for example, trigger \"onChange\"\n useEffect(() => {\n if (!onChange) return;\n onChange(currentIndex);\n }, [currentIndex, onChange]);\n\n /* eslint-disable jsx-a11y/no-noninteractive-tabindex */\n return (\n <div\n ref={mergeRefs(ref, setElement)}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }), {\n [`${CLASSNAME}--fill-height`]: fillHeight,\n [`${CLASSNAME}--group-by-${groupBy}`]: Boolean(groupBy),\n })}\n tabIndex={0}\n >\n <div className={`${CLASSNAME}__slides`}>\n <div className={`${CLASSNAME}__wrapper`} style={wrapperStyle}>\n {children}\n </div>\n </div>\n\n {slideshowControlsProps && slidesCount > 1 && (\n <div className={`${CLASSNAME}__controls`}>\n <SlideshowControls\n {...slideshowControlsProps}\n activeIndex={currentIndex}\n onPaginationClick={handleControlGotToSlide}\n onNextClick={handleControlNextSlide}\n onPreviousClick={handleControlPreviousSlide}\n slidesCount={slidesCount}\n parentRef={element}\n theme={theme}\n />\n </div>\n )}\n </div>\n );\n});\nSlideshow.displayName = COMPONENT_NAME;\nSlideshow.className = CLASSNAME;\nSlideshow.defaultProps = DEFAULT_PROPS;\n","import React, { forwardRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport type SlideshowItemProps = GenericProps;\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SlideshowItem';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * SlideshowItem component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SlideshowItem: Comp<SlideshowItemProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { className, children, ...forwardedProps } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n }),\n )}\n >\n {children}\n </div>\n );\n});\nSlideshowItem.displayName = COMPONENT_NAME;\nSlideshowItem.className = CLASSNAME;\n","import { useEffect } from 'react';\nimport { detectHorizontalSwipe } from '@lumx/core/js/utils';\n\nconst isTouchDevice = () => 'ontouchstart' in window;\n\n/**\n * Listen swipe to navigate left and right.\n */\nexport function useSwipeNavigate(element?: HTMLElement | null, onNext?: () => void, onPrevious?: () => void): void {\n useEffect(() => {\n if (!element || !isTouchDevice()) return undefined;\n\n return detectHorizontalSwipe(element, (swipe) => {\n const callback = swipe === 'right' ? onPrevious : onNext;\n callback?.();\n });\n }, [onPrevious, onNext, element]);\n}\n","import { useEffect } from 'react';\n\n/**\n * Listen keyboard to navigate left and right.\n */\nexport function useKeyNavigate(element?: HTMLElement | null, onNext?: () => void, onPrevious?: () => void): void {\n useEffect(() => {\n if (!element) return undefined;\n const onKeyNavigate = (evt: KeyboardEvent) => {\n let callback;\n if (evt?.key === 'ArrowRight') {\n callback = onPrevious;\n } else if (evt?.key === 'ArrowLeft') {\n callback = onNext;\n }\n if (!callback) return;\n\n callback();\n evt.preventDefault();\n evt.stopPropagation();\n };\n\n element.addEventListener('keydown', onKeyNavigate);\n return () => {\n element.removeEventListener('keydown', onKeyNavigate);\n };\n }, [onPrevious, onNext, element]);\n}\n","import { useMemo, useRef } from 'react';\nimport { EDGE_FROM_ACTIVE_INDEX, PAGINATION_ITEMS_MAX } from '@lumx/react/components/slideshow/constants';\n\ntype Range = { min: number; max: number };\n\n/**\n * Calculate the currently visible pagination \"bullet\" range.\n */\nexport function usePaginationVisibleRange(activeIndex: number, slideCount: number): Range {\n const previousVisibleRangeRef = useRef<Range>();\n return useMemo(() => {\n const lastSlide = slideCount - 1;\n const { current: previousVisibleRange } = previousVisibleRangeRef;\n let newVisibleRange: Range;\n if (activeIndex === previousVisibleRange?.max && activeIndex < lastSlide) {\n newVisibleRange = { min: previousVisibleRange.min + 1, max: previousVisibleRange.max + 1 };\n } else if (activeIndex === previousVisibleRange?.min && activeIndex > 0) {\n newVisibleRange = { min: previousVisibleRange.min - 1, max: previousVisibleRange.max - 1 };\n } else {\n const deltaItems = PAGINATION_ITEMS_MAX - 1;\n let min = activeIndex - EDGE_FROM_ACTIVE_INDEX;\n let max = activeIndex + EDGE_FROM_ACTIVE_INDEX;\n\n if (activeIndex > lastSlide - EDGE_FROM_ACTIVE_INDEX) {\n min = lastSlide - deltaItems;\n max = lastSlide;\n } else if (activeIndex < deltaItems) {\n min = 0;\n max = deltaItems;\n }\n\n newVisibleRange = { min, max };\n }\n previousVisibleRangeRef.current = newVisibleRange;\n return newVisibleRange;\n }, [activeIndex, slideCount]);\n}\n","import React, { forwardRef, RefObject, useCallback, useMemo } from 'react';\n\nimport classNames from 'classnames';\nimport range from 'lodash/range';\n\nimport { mdiChevronLeft, mdiChevronRight } from '@lumx/icons';\nimport { Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { WINDOW } from '@lumx/react/constants';\n\nimport { useSwipeNavigate } from './useSwipeNavigate';\nimport { useKeyNavigate } from './useKeyNavigate';\nimport { PAGINATION_ITEM_SIZE, PAGINATION_ITEMS_MAX } from './constants';\nimport { usePaginationVisibleRange } from './usePaginationVisibleRange';\n\n/**\n * Defines the props of the component.\n */\nexport interface SlideshowControlsProps extends GenericProps {\n /** Index of the current slide. */\n activeIndex?: number;\n /** Props to pass to the next button (minus those already set by the SlideshowControls props). */\n nextButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** Reference to the parent element on which we want to listen touch swipe. */\n parentRef?: RefObject<HTMLDivElement> | HTMLDivElement;\n /** Props to pass to the previous button (minus those already set by the SlideshowControls props). */\n previousButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** Number of slides. */\n slidesCount: number;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** On next button click callback. */\n onNextClick?(loopback?: boolean): void;\n /** On pagination change callback. */\n onPaginationClick?(index: number): void;\n /** On previous button click callback. */\n onPreviousClick?(loopback?: boolean): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SlideshowControls';\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<SlideshowControlsProps> = {\n activeIndex: 0,\n theme: Theme.light,\n};\n\n/**\n * SlideshowControls component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SlideshowControls: Comp<SlideshowControlsProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n activeIndex,\n className,\n nextButtonProps,\n onNextClick,\n onPaginationClick,\n onPreviousClick,\n parentRef,\n previousButtonProps,\n slidesCount,\n theme,\n ...forwardedProps\n } = props;\n\n let parent;\n if (WINDOW) {\n // Checking window object to avoid errors in SSR.\n parent = parentRef instanceof HTMLElement ? parentRef : parentRef?.current;\n }\n // Listen to keyboard navigate left & right.\n useKeyNavigate(parent, onNextClick, onPreviousClick);\n // Listen to touch swipe navigate left & right.\n useSwipeNavigate(\n parent,\n // Go next without loopback.\n useCallback(() => onNextClick?.(false), [onNextClick]),\n // Go previous without loopback.\n useCallback(() => onPreviousClick?.(false), [onPreviousClick]),\n );\n\n // Pagination \"bullet\" range.\n const visibleRange = usePaginationVisibleRange(activeIndex as number, slidesCount);\n\n // Inline style of wrapper element.\n const wrapperStyle = { transform: `translateX(-${PAGINATION_ITEM_SIZE * visibleRange.min}px)` };\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }), {\n [`${CLASSNAME}--has-infinite-pagination`]: slidesCount > PAGINATION_ITEMS_MAX,\n })}\n >\n <IconButton\n {...previousButtonProps}\n icon={mdiChevronLeft}\n className={`${CLASSNAME}__navigation`}\n color={theme === Theme.dark ? 'light' : 'dark'}\n emphasis={Emphasis.low}\n onClick={onPreviousClick}\n tabIndex={-1}\n />\n <div className={`${CLASSNAME}__pagination`}>\n <div className={`${CLASSNAME}__pagination-items`} style={wrapperStyle}>\n {useMemo(\n () =>\n range(slidesCount).map((index) => {\n const isOnEdge =\n index !== 0 &&\n index !== slidesCount - 1 &&\n (index === visibleRange.min || index === visibleRange.max);\n const isActive = activeIndex === index;\n const isOutRange = index < visibleRange.min || index > visibleRange.max;\n return (\n // eslint-disable-next-line jsx-a11y/control-has-associated-label\n <button\n className={classNames(\n handleBasicClasses({\n prefix: `${CLASSNAME}__pagination-item`,\n isActive,\n isOnEdge,\n isOutRange,\n }),\n )}\n key={index}\n type=\"button\"\n onClick={() => onPaginationClick?.(index)}\n tabIndex={-1}\n />\n );\n }),\n [slidesCount, visibleRange.min, visibleRange.max, activeIndex, onPaginationClick],\n )}\n </div>\n </div>\n <IconButton\n {...nextButtonProps}\n icon={mdiChevronRight}\n className={`${CLASSNAME}__navigation`}\n color={theme === Theme.dark ? 'light' : 'dark'}\n emphasis={Emphasis.low}\n onClick={onNextClick}\n tabIndex={-1}\n />\n </div>\n );\n});\nSlideshowControls.displayName = COMPONENT_NAME;\nSlideshowControls.className = CLASSNAME;\nSlideshowControls.defaultProps = DEFAULT_PROPS;\n"],"names":["AUTOPLAY_DEFAULT_INTERVAL","FULL_WIDTH_PERCENT","EDGE_FROM_ACTIVE_INDEX","PAGINATION_ITEMS_MAX","PAGINATION_ITEM_SIZE","useInterval","callback","delay","savedCallback","useRef","useEffect","current","undefined","tick","isFunction","id","setInterval","clearInterval","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","activeIndex","groupBy","interval","theme","Theme","light","Slideshow","forwardRef","props","ref","autoPlay","children","className","fillHeight","onChange","slideshowControlsProps","forwardedProps","useState","currentIndex","setCurrentIndex","element","setElement","itemsCount","React","Children","count","slidesCount","Math","ceil","min","wrapperStyle","transform","goToNextSlide","useCallback","loopback","index","goToPreviousSlide","Boolean","isAutoPlaying","setIsAutoPlaying","handleControlGotToSlide","handleControlNextSlide","handleControlPreviousSlide","mergeRefs","classNames","handleBasicClasses","prefix","displayName","defaultProps","SlideshowItem","isTouchDevice","window","useSwipeNavigate","onNext","onPrevious","detectHorizontalSwipe","swipe","useKeyNavigate","onKeyNavigate","evt","key","preventDefault","stopPropagation","addEventListener","removeEventListener","usePaginationVisibleRange","slideCount","previousVisibleRangeRef","useMemo","lastSlide","previousVisibleRange","newVisibleRange","max","deltaItems","SlideshowControls","nextButtonProps","onNextClick","onPaginationClick","onPreviousClick","parentRef","previousButtonProps","parent","WINDOW","HTMLElement","visibleRange","mdiChevronLeft","dark","Emphasis","low","range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AAAA,QAAQ,EAARA,QAFe;AAGfD,YAAAA,QAAQ,EAARA,QAHe;AAIfE,YAAAA,UAAU,EAAVA;AAJe,WAAD,CADD,CADzB;AASI,UAAA,GAAG,EAAE1D,KATT;AAUI,UAAA,IAAI,EAAC,QAVT;AAWI,UAAA,OAAO,EAAE;AAAA,mBAAM0C,iBAAN,aAAMA,iBAAN,uBAAMA,iBAAiB,CAAG1C,KAAH,CAAvB;AAAA,WAXb;AAYI,UAAA,QAAQ,EAAE,CAAC;AAZf;AAFJ;AAiBH,KAxBD,CADJ;AAAA,GADI,EA2BJ,CAACT,WAAD,EAAc0D,YAAY,CAACvD,GAA3B,EAAgCuD,YAAY,CAACZ,GAA7C,EAAkDxE,WAAlD,EAA+D6E,iBAA/D,CA3BI,CADZ,CADJ,CAhBJ,EAiDI,oBAAC,UAAD,eACQF,eADR;AAEI,IAAA,IAAI,EAAEmB,eAFV;AAGI,IAAA,SAAS,YAAKjG,WAAL,iBAHb;AAII,IAAA,KAAK,EAAEM,KAAK,KAAKC,KAAK,CAACkF,IAAhB,GAAuB,OAAvB,GAAiC,MAJ5C;AAKI,IAAA,QAAQ,EAAEC,QAAQ,CAACC,GALvB;AAMI,IAAA,OAAO,EAAEZ,WANb;AAOI,IAAA,QAAQ,EAAE,CAAC;AAPf,KAjDJ,CADJ;AA6DH,CAlGwF;AAmGzFF,iBAAiB,CAAC3B,WAAlB,GAAgCnD,gBAAhC;AACA8E,iBAAiB,CAAC9D,SAAlB,GAA8Bf,WAA9B;AACA6E,iBAAiB,CAAC1B,YAAlB,GAAiCjD,eAAjC;;;;"}
|
|
1
|
+
{"version":3,"file":"SlideshowControls.js","sources":["../../../src/components/slideshow/constants.ts","../../../src/hooks/useInterval.tsx","../../../src/components/slideshow/Slideshow.tsx","../../../src/components/slideshow/SlideshowItem.tsx","../../../src/components/slideshow/useSwipeNavigate.ts","../../../src/components/slideshow/useKeyNavigate.ts","../../../src/components/slideshow/usePaginationVisibleRange.ts","../../../src/components/slideshow/SlideshowControls.tsx"],"sourcesContent":["/**\n * Autoplay default interval in ms.\n */\nexport const AUTOPLAY_DEFAULT_INTERVAL = 5000;\n\n/**\n * Full width size in percent.\n */\nexport const FULL_WIDTH_PERCENT = 100;\n\n/**\n * Edge from the active index.\n */\nexport const EDGE_FROM_ACTIVE_INDEX = 2;\n\n/**\n * Max number of pagination items.\n */\nexport const PAGINATION_ITEMS_MAX = 5;\n\n/**\n * Size of a pagination item. Used to translate wrapper.\n */\nexport const PAGINATION_ITEM_SIZE = 12;\n","import { useEffect, useRef } from 'react';\n\nimport isFunction from 'lodash/isFunction';\nimport { Callback } from '../utils';\n\n/**\n * Making setInterval Declarative with React Hooks.\n * Credits: https://overreacted.io/making-setinterval-declarative-with-react-hooks/\n *\n * @param callback Function called by setInterval.\n * @param delay Delay for setInterval.\n */\nexport function useInterval(callback: Callback, delay: number | null): void {\n const savedCallback = useRef<Callback>();\n\n useEffect(() => {\n savedCallback.current = callback;\n });\n\n useEffect(() => {\n if (delay === null) return undefined;\n\n function tick() {\n if (isFunction(savedCallback.current)) {\n savedCallback.current();\n }\n }\n const id = setInterval(tick, delay);\n return () => clearInterval(id);\n }, [delay]);\n}\n","import React, { CSSProperties, forwardRef, useCallback, useEffect, useState } from 'react';\n\nimport classNames from 'classnames';\n\nimport { SlideshowControls, SlideshowControlsProps, Theme } from '@lumx/react';\n\nimport { AUTOPLAY_DEFAULT_INTERVAL, FULL_WIDTH_PERCENT } from '@lumx/react/components/slideshow/constants';\nimport { useInterval } from '@lumx/react/hooks/useInterval';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { mergeRefs } from '@lumx/react/utils/mergeRefs';\n\n/**\n * Defines the props of the component.\n */\nexport interface SlideshowProps extends GenericProps {\n /** Index of the current slide. */\n activeIndex?: number;\n /** Whether the automatic rotation of the slideshow is enabled or not. */\n autoPlay?: boolean;\n /** Whether the image has to fill its container height or not. */\n fillHeight?: boolean;\n /** Number of slides to group together. */\n groupBy?: number;\n /** Interval between each slide when automatic rotation is enabled. */\n interval?: number;\n /** Props to pass to the slideshow controls (minus those already set by the Slideshow props). */\n slideshowControlsProps?: Pick<SlideshowControlsProps, 'nextButtonProps' | 'previousButtonProps'> &\n Omit<\n SlideshowControlsProps,\n | 'activeIndex'\n | 'onPaginationClick'\n | 'onNextClick'\n | 'onPreviousClick'\n | 'slidesCount'\n | 'parentRef'\n | 'theme'\n >;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** Callback when slide changes */\n onChange?(index: number): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'Slideshow';\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<SlideshowProps> = {\n activeIndex: 0,\n groupBy: 1,\n interval: AUTOPLAY_DEFAULT_INTERVAL,\n theme: Theme.light,\n};\n\n/**\n * Slideshow component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const Slideshow: Comp<SlideshowProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n activeIndex,\n autoPlay,\n children,\n className,\n fillHeight,\n groupBy,\n interval,\n onChange,\n slideshowControlsProps,\n theme,\n ...forwardedProps\n } = props;\n const [currentIndex, setCurrentIndex] = useState(activeIndex as number);\n // Use state instead of a ref to make the slideshow controls update directly when the element is set.\n const [element, setElement] = useState<HTMLDivElement>();\n\n // Number of slideshow items.\n const itemsCount = React.Children.count(children);\n // Number of slides when using groupBy prop.\n const slidesCount = Math.ceil(itemsCount / Math.min(groupBy as number, itemsCount));\n // Inline style of wrapper element.\n const wrapperStyle: CSSProperties = { transform: `translateX(-${FULL_WIDTH_PERCENT * currentIndex}%)` };\n\n // Change current index to display next slide.\n const goToNextSlide = useCallback(\n (loopback = true) => {\n setCurrentIndex((index) => {\n if (loopback && index === slidesCount - 1) {\n // Loopback to the start.\n return 0;\n }\n if (index < slidesCount - 1) {\n // Next slide.\n return index + 1;\n }\n return index;\n });\n },\n [slidesCount, setCurrentIndex],\n );\n\n // Change current index to display previous slide.\n const goToPreviousSlide = useCallback(\n (loopback = true) => {\n setCurrentIndex((index) => {\n if (loopback && index === 0) {\n // Loopback to the end.\n return slidesCount - 1;\n }\n if (index > 0) {\n // Previous slide.\n return index - 1;\n }\n return index;\n });\n },\n [slidesCount, setCurrentIndex],\n );\n\n // Auto play\n const [isAutoPlaying, setIsAutoPlaying] = useState(Boolean(autoPlay));\n // Start\n useInterval(goToNextSlide, isAutoPlaying && slidesCount > 1 ? (interval as number) : null);\n\n // Reset current index if it become invalid.\n useEffect(() => {\n if (currentIndex > slidesCount - 1) {\n setCurrentIndex(DEFAULT_PROPS.activeIndex as number);\n }\n }, [currentIndex, slidesCount]);\n\n // Handle click on a bullet to go to a specific slide.\n const handleControlGotToSlide = useCallback(\n (index: number) => {\n setIsAutoPlaying(false);\n\n if (index >= 0 && index < slidesCount) {\n setCurrentIndex(index);\n }\n },\n [slidesCount, setCurrentIndex],\n );\n\n // Handle click or keyboard event to go to next slide.\n const handleControlNextSlide = useCallback(\n (loopback = true) => {\n setIsAutoPlaying(false);\n goToNextSlide(loopback);\n },\n [goToNextSlide],\n );\n\n // Handle click or keyboard event to go to previous slide.\n const handleControlPreviousSlide = useCallback(\n (loopback = true) => {\n setIsAutoPlaying(false);\n goToPreviousSlide(loopback);\n },\n [goToPreviousSlide],\n );\n\n // If the activeIndex props changes, update the current slide\n useEffect(() => {\n setCurrentIndex(activeIndex as number);\n }, [activeIndex]);\n\n // If the slide changes, with autoplay for example, trigger \"onChange\"\n useEffect(() => {\n if (!onChange) return;\n onChange(currentIndex);\n }, [currentIndex, onChange]);\n\n /* eslint-disable jsx-a11y/no-noninteractive-tabindex */\n return (\n <div\n ref={mergeRefs(ref, setElement)}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }), {\n [`${CLASSNAME}--fill-height`]: fillHeight,\n [`${CLASSNAME}--group-by-${groupBy}`]: Boolean(groupBy),\n })}\n tabIndex={0}\n >\n <div className={`${CLASSNAME}__slides`}>\n <div className={`${CLASSNAME}__wrapper`} style={wrapperStyle}>\n {children}\n </div>\n </div>\n\n {slideshowControlsProps && slidesCount > 1 && (\n <div className={`${CLASSNAME}__controls`}>\n <SlideshowControls\n {...slideshowControlsProps}\n activeIndex={currentIndex}\n onPaginationClick={handleControlGotToSlide}\n onNextClick={handleControlNextSlide}\n onPreviousClick={handleControlPreviousSlide}\n slidesCount={slidesCount}\n parentRef={element}\n theme={theme}\n />\n </div>\n )}\n </div>\n );\n});\nSlideshow.displayName = COMPONENT_NAME;\nSlideshow.className = CLASSNAME;\nSlideshow.defaultProps = DEFAULT_PROPS;\n","import React, { forwardRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\n\n/**\n * Defines the props of the component.\n */\nexport type SlideshowItemProps = GenericProps;\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SlideshowItem';\n\n/**\n * Component default class name and class prefix.\n */\nconst CLASSNAME = getRootClassName(COMPONENT_NAME);\n\n/**\n * SlideshowItem component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SlideshowItem: Comp<SlideshowItemProps, HTMLDivElement> = forwardRef((props, ref) => {\n const { className, children, ...forwardedProps } = props;\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(\n className,\n handleBasicClasses({\n prefix: CLASSNAME,\n }),\n )}\n >\n {children}\n </div>\n );\n});\nSlideshowItem.displayName = COMPONENT_NAME;\nSlideshowItem.className = CLASSNAME;\n","import { useEffect } from 'react';\nimport { detectHorizontalSwipe } from '@lumx/core/js/utils';\n\nconst isTouchDevice = () => 'ontouchstart' in window;\n\n/**\n * Listen swipe to navigate left and right.\n */\nexport function useSwipeNavigate(element?: HTMLElement | null, onNext?: () => void, onPrevious?: () => void): void {\n useEffect(() => {\n if (!element || !isTouchDevice()) return undefined;\n\n return detectHorizontalSwipe(element, (swipe) => {\n const callback = swipe === 'right' ? onPrevious : onNext;\n callback?.();\n });\n }, [onPrevious, onNext, element]);\n}\n","import { useEffect } from 'react';\n\n/**\n * Listen keyboard to navigate left and right.\n */\nexport function useKeyNavigate(element?: HTMLElement | null, onNext?: () => void, onPrevious?: () => void): void {\n useEffect(() => {\n if (!element) return undefined;\n const onKeyNavigate = (evt: KeyboardEvent) => {\n let callback;\n if (evt?.key === 'ArrowRight') {\n callback = onNext;\n } else if (evt?.key === 'ArrowLeft') {\n callback = onPrevious;\n }\n if (!callback) return;\n\n callback();\n evt.preventDefault();\n evt.stopPropagation();\n };\n\n element.addEventListener('keydown', onKeyNavigate);\n return () => {\n element.removeEventListener('keydown', onKeyNavigate);\n };\n }, [onPrevious, onNext, element]);\n}\n","import { useMemo, useRef } from 'react';\nimport { EDGE_FROM_ACTIVE_INDEX, PAGINATION_ITEMS_MAX } from '@lumx/react/components/slideshow/constants';\n\ntype Range = { min: number; max: number };\n\n/**\n * Calculate the currently visible pagination \"bullet\" range.\n */\nexport function usePaginationVisibleRange(activeIndex: number, slideCount: number): Range {\n const previousVisibleRangeRef = useRef<Range>();\n return useMemo(() => {\n const lastSlide = slideCount - 1;\n const { current: previousVisibleRange } = previousVisibleRangeRef;\n let newVisibleRange: Range;\n if (activeIndex === previousVisibleRange?.max && activeIndex < lastSlide) {\n newVisibleRange = { min: previousVisibleRange.min + 1, max: previousVisibleRange.max + 1 };\n } else if (activeIndex === previousVisibleRange?.min && activeIndex > 0) {\n newVisibleRange = { min: previousVisibleRange.min - 1, max: previousVisibleRange.max - 1 };\n } else {\n const deltaItems = PAGINATION_ITEMS_MAX - 1;\n let min = activeIndex - EDGE_FROM_ACTIVE_INDEX;\n let max = activeIndex + EDGE_FROM_ACTIVE_INDEX;\n\n if (activeIndex > lastSlide - EDGE_FROM_ACTIVE_INDEX) {\n min = lastSlide - deltaItems;\n max = lastSlide;\n } else if (activeIndex < deltaItems) {\n min = 0;\n max = deltaItems;\n }\n\n newVisibleRange = { min, max };\n }\n previousVisibleRangeRef.current = newVisibleRange;\n return newVisibleRange;\n }, [activeIndex, slideCount]);\n}\n","import React, { forwardRef, RefObject, useCallback, useMemo } from 'react';\n\nimport classNames from 'classnames';\nimport range from 'lodash/range';\n\nimport { mdiChevronLeft, mdiChevronRight } from '@lumx/icons';\nimport { Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';\nimport { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';\nimport { WINDOW } from '@lumx/react/constants';\n\nimport { useSwipeNavigate } from './useSwipeNavigate';\nimport { useKeyNavigate } from './useKeyNavigate';\nimport { PAGINATION_ITEM_SIZE, PAGINATION_ITEMS_MAX } from './constants';\nimport { usePaginationVisibleRange } from './usePaginationVisibleRange';\n\n/**\n * Defines the props of the component.\n */\nexport interface SlideshowControlsProps extends GenericProps {\n /** Index of the current slide. */\n activeIndex?: number;\n /** Props to pass to the next button (minus those already set by the SlideshowControls props). */\n nextButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** Reference to the parent element on which we want to listen touch swipe. */\n parentRef?: RefObject<HTMLDivElement> | HTMLDivElement;\n /** Props to pass to the previous button (minus those already set by the SlideshowControls props). */\n previousButtonProps: Pick<IconButtonProps, 'label'> &\n Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;\n /** Number of slides. */\n slidesCount: number;\n /** Theme adapting the component to light or dark background. */\n theme?: Theme;\n /** On next button click callback. */\n onNextClick?(loopback?: boolean): void;\n /** On pagination change callback. */\n onPaginationClick?(index: number): void;\n /** On previous button click callback. */\n onPreviousClick?(loopback?: boolean): void;\n}\n\n/**\n * Component display name.\n */\nconst COMPONENT_NAME = 'SlideshowControls';\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<SlideshowControlsProps> = {\n activeIndex: 0,\n theme: Theme.light,\n};\n\n/**\n * SlideshowControls component.\n *\n * @param props Component props.\n * @param ref Component ref.\n * @return React element.\n */\nexport const SlideshowControls: Comp<SlideshowControlsProps, HTMLDivElement> = forwardRef((props, ref) => {\n const {\n activeIndex,\n className,\n nextButtonProps,\n onNextClick,\n onPaginationClick,\n onPreviousClick,\n parentRef,\n previousButtonProps,\n slidesCount,\n theme,\n ...forwardedProps\n } = props;\n\n let parent;\n if (WINDOW) {\n // Checking window object to avoid errors in SSR.\n parent = parentRef instanceof HTMLElement ? parentRef : parentRef?.current;\n }\n // Listen to keyboard navigate left & right.\n useKeyNavigate(parent, onNextClick, onPreviousClick);\n // Listen to touch swipe navigate left & right.\n useSwipeNavigate(\n parent,\n // Go next without loopback.\n useCallback(() => onNextClick?.(false), [onNextClick]),\n // Go previous without loopback.\n useCallback(() => onPreviousClick?.(false), [onPreviousClick]),\n );\n\n // Pagination \"bullet\" range.\n const visibleRange = usePaginationVisibleRange(activeIndex as number, slidesCount);\n\n // Inline style of wrapper element.\n const wrapperStyle = { transform: `translateX(-${PAGINATION_ITEM_SIZE * visibleRange.min}px)` };\n\n return (\n <div\n ref={ref}\n {...forwardedProps}\n className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, theme }), {\n [`${CLASSNAME}--has-infinite-pagination`]: slidesCount > PAGINATION_ITEMS_MAX,\n })}\n >\n <IconButton\n {...previousButtonProps}\n icon={mdiChevronLeft}\n className={`${CLASSNAME}__navigation`}\n color={theme === Theme.dark ? 'light' : 'dark'}\n emphasis={Emphasis.low}\n onClick={onPreviousClick}\n tabIndex={-1}\n />\n <div className={`${CLASSNAME}__pagination`}>\n <div className={`${CLASSNAME}__pagination-items`} style={wrapperStyle}>\n {useMemo(\n () =>\n range(slidesCount).map((index) => {\n const isOnEdge =\n index !== 0 &&\n index !== slidesCount - 1 &&\n (index === visibleRange.min || index === visibleRange.max);\n const isActive = activeIndex === index;\n const isOutRange = index < visibleRange.min || index > visibleRange.max;\n return (\n // eslint-disable-next-line jsx-a11y/control-has-associated-label\n <button\n className={classNames(\n handleBasicClasses({\n prefix: `${CLASSNAME}__pagination-item`,\n isActive,\n isOnEdge,\n isOutRange,\n }),\n )}\n key={index}\n type=\"button\"\n onClick={() => onPaginationClick?.(index)}\n tabIndex={-1}\n />\n );\n }),\n [slidesCount, visibleRange.min, visibleRange.max, activeIndex, onPaginationClick],\n )}\n </div>\n </div>\n <IconButton\n {...nextButtonProps}\n icon={mdiChevronRight}\n className={`${CLASSNAME}__navigation`}\n color={theme === Theme.dark ? 'light' : 'dark'}\n emphasis={Emphasis.low}\n onClick={onNextClick}\n tabIndex={-1}\n />\n </div>\n );\n});\nSlideshowControls.displayName = COMPONENT_NAME;\nSlideshowControls.className = CLASSNAME;\nSlideshowControls.defaultProps = DEFAULT_PROPS;\n"],"names":["AUTOPLAY_DEFAULT_INTERVAL","FULL_WIDTH_PERCENT","EDGE_FROM_ACTIVE_INDEX","PAGINATION_ITEMS_MAX","PAGINATION_ITEM_SIZE","useInterval","callback","delay","savedCallback","useRef","useEffect","current","undefined","tick","isFunction","id","setInterval","clearInterval","COMPONENT_NAME","CLASSNAME","getRootClassName","DEFAULT_PROPS","activeIndex","groupBy","interval","theme","Theme","light","Slideshow","forwardRef","props","ref","autoPlay","children","className","fillHeight","onChange","slideshowControlsProps","forwardedProps","useState","currentIndex","setCurrentIndex","element","setElement","itemsCount","React","Children","count","slidesCount","Math","ceil","min","wrapperStyle","transform","goToNextSlide","useCallback","loopback","index","goToPreviousSlide","Boolean","isAutoPlaying","setIsAutoPlaying","handleControlGotToSlide","handleControlNextSlide","handleControlPreviousSlide","mergeRefs","classNames","handleBasicClasses","prefix","displayName","defaultProps","SlideshowItem","isTouchDevice","window","useSwipeNavigate","onNext","onPrevious","detectHorizontalSwipe","swipe","useKeyNavigate","onKeyNavigate","evt","key","preventDefault","stopPropagation","addEventListener","removeEventListener","usePaginationVisibleRange","slideCount","previousVisibleRangeRef","useMemo","lastSlide","previousVisibleRange","newVisibleRange","max","deltaItems","SlideshowControls","nextButtonProps","onNextClick","onPaginationClick","onPreviousClick","parentRef","previousButtonProps","parent","WINDOW","HTMLElement","visibleRange","mdiChevronLeft","dark","Emphasis","low","range","map","isOnEdge","isActive","isOutRange","mdiChevronRight"],"mappings":";;;;;;;;;;;AAAA;;;AAGO,IAAMA,yBAAyB,GAAG,IAAlC;AAEP;;;;AAGO,IAAMC,kBAAkB,GAAG,GAA3B;AAEP;;;;AAGO,IAAMC,sBAAsB,GAAG,CAA/B;AAEP;;;;AAGO,IAAMC,oBAAoB,GAAG,CAA7B;AAEP;;;;AAGO,IAAMC,oBAAoB,GAAG,EAA7B;;AClBP;;;;;;;AAOO,SAASC,WAAT,CAAqBC,QAArB,EAAyCC,KAAzC,EAAqE;AACxE,MAAMC,aAAa,GAAGC,MAAM,EAA5B;AAEAC,EAAAA,SAAS,CAAC,YAAM;AACZF,IAAAA,aAAa,CAACG,OAAd,GAAwBL,QAAxB;AACH,GAFQ,CAAT;AAIAI,EAAAA,SAAS,CAAC,YAAM;AACZ,QAAIH,KAAK,KAAK,IAAd,EAAoB,OAAOK,SAAP;;AAEpB,aAASC,IAAT,GAAgB;AACZ,UAAIC,UAAU,CAACN,aAAa,CAACG,OAAf,CAAd,EAAuC;AACnCH,QAAAA,aAAa,CAACG,OAAd;AACH;AACJ;;AACD,QAAMI,EAAE,GAAGC,WAAW,CAACH,IAAD,EAAON,KAAP,CAAtB;AACA,WAAO;AAAA,aAAMU,aAAa,CAACF,EAAD,CAAnB;AAAA,KAAP;AACH,GAVQ,EAUN,CAACR,KAAD,CAVM,CAAT;AAWH;;ACnBD;;;;AAgCA;;;AAGA,IAAMW,cAAc,GAAG,WAAvB;AAEA;;;;AAGA,IAAMC,SAAS,GAAGC,gBAAgB,CAACF,cAAD,CAAlC;AAEA;;;;AAGA,IAAMG,aAAsC,GAAG;AA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@@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@juggle/resize-observer": "^3.2.0",
|
|
10
|
-
"@lumx/core": "^2.1.
|
|
11
|
-
"@lumx/icons": "^2.1.
|
|
10
|
+
"@lumx/core": "^2.1.4",
|
|
11
|
+
"@lumx/icons": "^2.1.4",
|
|
12
12
|
"@popperjs/core": "^2.5.4",
|
|
13
13
|
"body-scroll-lock": "^3.1.5",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
@@ -123,9 +123,9 @@
|
|
|
123
123
|
"storybook": "start-storybook -s ../site-demo/static/ -p 9000"
|
|
124
124
|
},
|
|
125
125
|
"sideEffects": false,
|
|
126
|
-
"version": "2.1.
|
|
126
|
+
"version": "2.1.4",
|
|
127
127
|
"resolutions": {
|
|
128
128
|
"**/style-loader": "^1.0.0"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "de78ddf378468c55a56149bcb4568e66a9a88f32"
|
|
131
131
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mdiClose } from '@lumx/icons';
|
|
2
2
|
import {
|
|
3
|
+
AlertDialog,
|
|
3
4
|
Button,
|
|
4
5
|
Checkbox,
|
|
5
6
|
DatePickerField,
|
|
@@ -32,9 +33,9 @@ const content = <div className="lumx-spacing-padding">{loremIpsum('short')}</div
|
|
|
32
33
|
const longContent = <div className="lumx-spacing-padding">{loremIpsum('long')}</div>;
|
|
33
34
|
const footer = <footer className="lumx-spacing-padding">Dialog footer</footer>;
|
|
34
35
|
|
|
35
|
-
function useOpenButton(theme: Theme) {
|
|
36
|
+
function useOpenButton(theme: Theme, defaultState = true) {
|
|
36
37
|
const buttonRef = useRef() as RefObject<HTMLButtonElement>;
|
|
37
|
-
const [isOpen, setOpen] = useState(
|
|
38
|
+
const [isOpen, setOpen] = useState(defaultState);
|
|
38
39
|
const openDialog = () => setOpen(true);
|
|
39
40
|
const closeDialog = () => setOpen(false);
|
|
40
41
|
|
|
@@ -45,6 +46,7 @@ function useOpenButton(theme: Theme) {
|
|
|
45
46
|
</Button>
|
|
46
47
|
),
|
|
47
48
|
buttonRef,
|
|
49
|
+
openDialog,
|
|
48
50
|
closeDialog,
|
|
49
51
|
isOpen,
|
|
50
52
|
};
|
|
@@ -83,6 +85,46 @@ export const PreventDialogAutoClose = ({ theme }: any) => {
|
|
|
83
85
|
);
|
|
84
86
|
};
|
|
85
87
|
|
|
88
|
+
export const DialogWithAlertDialog = ({ theme }: any) => {
|
|
89
|
+
const { button, buttonRef, closeDialog, isOpen } = useOpenButton(theme);
|
|
90
|
+
const { openDialog: openAlertDialog, closeDialog: closeAlertDialog, isOpen: isAlertDialogOpen } = useOpenButton(
|
|
91
|
+
theme,
|
|
92
|
+
false,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const handleSubmitDialog = () => {
|
|
96
|
+
closeDialog();
|
|
97
|
+
openAlertDialog();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<>
|
|
102
|
+
{button}
|
|
103
|
+
<Dialog isOpen={isOpen} onClose={closeDialog} parentElement={buttonRef}>
|
|
104
|
+
{content}
|
|
105
|
+
<footer>
|
|
106
|
+
<Toolbar
|
|
107
|
+
after={
|
|
108
|
+
<Button onClick={handleSubmitDialog} emphasis={Emphasis.low}>
|
|
109
|
+
Close
|
|
110
|
+
</Button>
|
|
111
|
+
}
|
|
112
|
+
/>
|
|
113
|
+
</footer>
|
|
114
|
+
</Dialog>
|
|
115
|
+
<AlertDialog
|
|
116
|
+
isOpen={isAlertDialogOpen}
|
|
117
|
+
onClose={closeDialog}
|
|
118
|
+
parentElement={buttonRef}
|
|
119
|
+
title="Default (info)"
|
|
120
|
+
confirmProps={{ onClick: closeAlertDialog, label: 'Confirm' }}
|
|
121
|
+
>
|
|
122
|
+
Consequat deserunt officia aute laborum tempor anim sint est.
|
|
123
|
+
</AlertDialog>
|
|
124
|
+
</>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
86
128
|
export const Sizes = ({ theme }: any) => {
|
|
87
129
|
const { button, buttonRef, closeDialog, isOpen } = useOpenButton(theme);
|
|
88
130
|
const sizes: DialogSizes[] = [Size.tiny, Size.regular, Size.big, Size.huge];
|
|
@@ -115,18 +115,22 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
|
|
|
115
115
|
...forwardedProps
|
|
116
116
|
} = props;
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
119
|
+
const previousOpen = React.useRef(isOpen);
|
|
120
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
121
|
+
React.useEffect(() => {
|
|
122
|
+
if (isOpen !== previousOpen.current) {
|
|
123
|
+
previousOpen.current = isOpen;
|
|
124
|
+
|
|
125
|
+
// Focus the parent element on close.
|
|
126
|
+
if (!isOpen && parentElement && parentElement.current) {
|
|
127
|
+
parentElement.current.focus();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, [isOpen, parentElement]);
|
|
127
131
|
|
|
128
132
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
129
|
-
useCallbackOnEscape(
|
|
133
|
+
useCallbackOnEscape(onClose, isOpen && !preventAutoClose);
|
|
130
134
|
|
|
131
135
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
132
136
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
@@ -192,7 +196,7 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
|
|
|
192
196
|
<div className={`${CLASSNAME}__overlay`} />
|
|
193
197
|
|
|
194
198
|
<section className={`${CLASSNAME}__container`} role="dialog" aria-modal="true" {...dialogProps}>
|
|
195
|
-
<ClickAwayProvider callback={!preventAutoClose &&
|
|
199
|
+
<ClickAwayProvider callback={!preventAutoClose && onClose} refs={clickAwayRefs}>
|
|
196
200
|
<div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>
|
|
197
201
|
{(header || headerChildContent) && (
|
|
198
202
|
<header
|
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`<Dialog> Snapshots and structure should render story DialogWithAlertDialog 1`] = `
|
|
4
|
+
<Fragment>
|
|
5
|
+
<Button
|
|
6
|
+
emphasis="high"
|
|
7
|
+
onClick={[Function]}
|
|
8
|
+
size="m"
|
|
9
|
+
theme="light"
|
|
10
|
+
>
|
|
11
|
+
Open dialog
|
|
12
|
+
</Button>
|
|
13
|
+
<Dialog
|
|
14
|
+
isOpen={true}
|
|
15
|
+
onClose={[Function]}
|
|
16
|
+
parentElement={
|
|
17
|
+
Object {
|
|
18
|
+
"current": undefined,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
size="big"
|
|
22
|
+
>
|
|
23
|
+
<div
|
|
24
|
+
className="lumx-spacing-padding"
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
Nihil hic munitissimus habendi senatus locus, nihil horum? At nos hinc posthac, sitientis piros
|
|
28
|
+
Afros. Magna pars studiorum, prodita quaerimus. Integer legentibus erat a ante historiarum
|
|
29
|
+
dapibus. Praeterea iter est quasdam res quas ex communi. Ullamco laboris nisi ut aliquid ex ea
|
|
30
|
+
commodi consequat. Inmensae subtilitatis, obscuris et malesuada fames. Me non paenitet nullum
|
|
31
|
+
festiviorem excogitasse ad hoc. Cum ceteris in veneratione tui montes, nascetur mus. Etiam
|
|
32
|
+
habebis sem dicantur magna mollis euismod. Quis aute iure reprehenderit in voluptate velit esse.
|
|
33
|
+
Phasellus laoreet lorem vel dolor tempus vehicula. Ambitioni dedisse scripsisse iudicaretur.
|
|
34
|
+
Paullum deliquit, ponderibus modulisque suis ratio utitur. Ab illo tempore, ab est sed
|
|
35
|
+
immemorabili. Nec dubitamus multa iter quae et nos invenerat. Tu quoque, Brute, fili mi, nihil
|
|
36
|
+
timor populi, nihil! Morbi fringilla convallis sapien, id pulvinar odio volutpat. Cras mattis
|
|
37
|
+
iudicium purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus.
|
|
38
|
+
Quisque ut dolor gravida, placerat libero vel, euismod. Unam incolunt Belgae, aliam Aquitani,
|
|
39
|
+
tertiam. Cras mattis iudicium purus sit amet fermentum
|
|
40
|
+
</div>
|
|
41
|
+
<footer>
|
|
42
|
+
<Toolbar
|
|
43
|
+
after={
|
|
44
|
+
<Button
|
|
45
|
+
emphasis="low"
|
|
46
|
+
onClick={[Function]}
|
|
47
|
+
size="m"
|
|
48
|
+
theme="light"
|
|
49
|
+
>
|
|
50
|
+
Close
|
|
51
|
+
</Button>
|
|
52
|
+
}
|
|
53
|
+
/>
|
|
54
|
+
</footer>
|
|
55
|
+
</Dialog>
|
|
56
|
+
<AlertDialog
|
|
57
|
+
confirmProps={
|
|
58
|
+
Object {
|
|
59
|
+
"label": "Confirm",
|
|
60
|
+
"onClick": [Function],
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
isOpen={false}
|
|
64
|
+
kind="info"
|
|
65
|
+
onClose={[Function]}
|
|
66
|
+
parentElement={
|
|
67
|
+
Object {
|
|
68
|
+
"current": undefined,
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
size="tiny"
|
|
72
|
+
title="Default (info)"
|
|
73
|
+
>
|
|
74
|
+
Consequat deserunt officia aute laborum tempor anim sint est.
|
|
75
|
+
</AlertDialog>
|
|
76
|
+
</Fragment>
|
|
77
|
+
`;
|
|
78
|
+
|
|
3
79
|
exports[`<Dialog> Snapshots and structure should render story DialogWithFocusableElements 1`] = `
|
|
4
80
|
<Fragment>
|
|
5
81
|
<Button
|
|
@@ -69,9 +69,8 @@ describe(`<${Flag.displayName} />`, () => {
|
|
|
69
69
|
|
|
70
70
|
it('should use the color', () => {
|
|
71
71
|
const color = ColorPalette.green;
|
|
72
|
-
const { wrapper
|
|
72
|
+
const { wrapper } = setup({ icon: mdiAbTesting, color });
|
|
73
73
|
|
|
74
|
-
expect(iconEl.prop('color')).toEqual(color);
|
|
75
74
|
expect(wrapper).toHaveClassName(
|
|
76
75
|
getBasicClass({
|
|
77
76
|
prefix: CLASSNAME,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
|
|
4
|
-
import { ColorPalette,
|
|
4
|
+
import { ColorPalette, Icon, Size, Theme } from '@lumx/react';
|
|
5
5
|
import { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';
|
|
6
6
|
|
|
7
7
|
export interface FlagProps extends GenericProps {
|
|
@@ -38,15 +38,7 @@ export const Flag: Comp<FlagProps, HTMLDivElement> = forwardRef((props, ref) =>
|
|
|
38
38
|
className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, color: flagColor }))}
|
|
39
39
|
ref={ref}
|
|
40
40
|
>
|
|
41
|
-
{icon &&
|
|
42
|
-
<Icon
|
|
43
|
-
icon={icon}
|
|
44
|
-
color={color}
|
|
45
|
-
colorVariant={ColorVariant.D2}
|
|
46
|
-
size={Size.xxs}
|
|
47
|
-
className={`${CLASSNAME}__icon`}
|
|
48
|
-
/>
|
|
49
|
-
)}
|
|
41
|
+
{icon && <Icon icon={icon} size={Size.xxs} className={`${CLASSNAME}__icon`} />}
|
|
50
42
|
<span className={`${CLASSNAME}__label`}>{label}</span>
|
|
51
43
|
</div>
|
|
52
44
|
);
|
|
@@ -19,8 +19,6 @@ Array [
|
|
|
19
19
|
>
|
|
20
20
|
<Icon
|
|
21
21
|
className="lumx-flag__icon"
|
|
22
|
-
color="blue"
|
|
23
|
-
colorVariant="D2"
|
|
24
22
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
25
23
|
size="xxs"
|
|
26
24
|
/>
|
|
@@ -35,8 +33,6 @@ Array [
|
|
|
35
33
|
>
|
|
36
34
|
<Icon
|
|
37
35
|
className="lumx-flag__icon"
|
|
38
|
-
color="dark"
|
|
39
|
-
colorVariant="D2"
|
|
40
36
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
41
37
|
size="xxs"
|
|
42
38
|
/>
|
|
@@ -51,8 +47,6 @@ Array [
|
|
|
51
47
|
>
|
|
52
48
|
<Icon
|
|
53
49
|
className="lumx-flag__icon"
|
|
54
|
-
color="green"
|
|
55
|
-
colorVariant="D2"
|
|
56
50
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
57
51
|
size="xxs"
|
|
58
52
|
/>
|
|
@@ -67,8 +61,6 @@ Array [
|
|
|
67
61
|
>
|
|
68
62
|
<Icon
|
|
69
63
|
className="lumx-flag__icon"
|
|
70
|
-
color="primary"
|
|
71
|
-
colorVariant="D2"
|
|
72
64
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
73
65
|
size="xxs"
|
|
74
66
|
/>
|
|
@@ -83,8 +75,6 @@ Array [
|
|
|
83
75
|
>
|
|
84
76
|
<Icon
|
|
85
77
|
className="lumx-flag__icon"
|
|
86
|
-
color="red"
|
|
87
|
-
colorVariant="D2"
|
|
88
78
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
89
79
|
size="xxs"
|
|
90
80
|
/>
|
|
@@ -99,8 +89,6 @@ Array [
|
|
|
99
89
|
>
|
|
100
90
|
<Icon
|
|
101
91
|
className="lumx-flag__icon"
|
|
102
|
-
color="secondary"
|
|
103
|
-
colorVariant="D2"
|
|
104
92
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
105
93
|
size="xxs"
|
|
106
94
|
/>
|
|
@@ -115,8 +103,6 @@ Array [
|
|
|
115
103
|
>
|
|
116
104
|
<Icon
|
|
117
105
|
className="lumx-flag__icon"
|
|
118
|
-
color="yellow"
|
|
119
|
-
colorVariant="D2"
|
|
120
106
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
121
107
|
size="xxs"
|
|
122
108
|
/>
|
|
@@ -135,7 +121,6 @@ exports[`<Flag /> Snapshots and structure should render story 'withIcon' 1`] = `
|
|
|
135
121
|
>
|
|
136
122
|
<Icon
|
|
137
123
|
className="lumx-flag__icon"
|
|
138
|
-
colorVariant="D2"
|
|
139
124
|
icon="M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z"
|
|
140
125
|
size="xxs"
|
|
141
126
|
/>
|
|
@@ -62,8 +62,8 @@ export const Message: Comp<MessageProps, HTMLDivElement> = forwardRef((props, re
|
|
|
62
62
|
)}
|
|
63
63
|
{...forwardedProps}
|
|
64
64
|
>
|
|
65
|
-
{(customIcon || icon) && <Icon className=
|
|
66
|
-
<div className=
|
|
65
|
+
{(customIcon || icon) && <Icon className={`${CLASSNAME}__icon`} icon={customIcon || icon} size={Size.xs} />}
|
|
66
|
+
<div className={`${CLASSNAME}__text`}>{children}</div>
|
|
67
67
|
</div>
|
|
68
68
|
);
|
|
69
69
|
});
|
|
@@ -9,9 +9,9 @@ export function useKeyNavigate(element?: HTMLElement | null, onNext?: () => void
|
|
|
9
9
|
const onKeyNavigate = (evt: KeyboardEvent) => {
|
|
10
10
|
let callback;
|
|
11
11
|
if (evt?.key === 'ArrowRight') {
|
|
12
|
-
callback = onPrevious;
|
|
13
|
-
} else if (evt?.key === 'ArrowLeft') {
|
|
14
12
|
callback = onNext;
|
|
13
|
+
} else if (evt?.key === 'ArrowLeft') {
|
|
14
|
+
callback = onPrevious;
|
|
15
15
|
}
|
|
16
16
|
if (!callback) return;
|
|
17
17
|
|