@lifesg/react-design-system 3.6.0-canary.2 → 3.6.0-canary.3
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/cjs/modal/modal.js +1 -1
- package/cjs/modal/modal.js.map +1 -1
- package/cjs/modal-v2/modal-v2.js +1 -1
- package/cjs/modal-v2/modal-v2.js.map +1 -1
- package/cjs/overlay/overlay.js +1 -1
- package/cjs/overlay/overlay.js.map +1 -1
- package/e-signature/e-signature.styles.d.ts +1 -1
- package/modal/index.d.ts +1 -1
- package/modal/modal.d.ts +1 -1
- package/modal/modal.js +1 -1
- package/modal/modal.js.map +1 -1
- package/modal/types.d.ts +3 -0
- package/modal-v2/index.d.ts +1 -1
- package/modal-v2/modal-v2.d.ts +1 -1
- package/modal-v2/modal-v2.js +1 -1
- package/modal-v2/modal-v2.js.map +1 -1
- package/modal-v2/types.d.ts +3 -0
- package/overlay/overlay.js +1 -1
- package/overlay/overlay.js.map +1 -1
- package/overlay/types.d.ts +3 -0
- package/package.json +1 -1
package/cjs/modal/modal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../_virtual/_tslib.js"),r=require("react/jsx-runtime"),i=require("react"),
|
|
1
|
+
"use strict";var e=require("../_virtual/_tslib.js"),r=require("react/jsx-runtime"),i=require("react"),l=require("../overlay/overlay.js"),t=require("../shared/hooks/useViewport.js");require("../util/calendar-helper.js"),require("../util/date-helper.js"),require("../util/date-input-helper.js"),require("../util/file-helper.js"),require("../util/simple-id-generator.js"),require("../util/string-helper.js"),require("@react-aria/live-announcer");var a=require("../util/use-event.js"),o=require("./modal.styles.js");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(i);exports.Modal=n=>{var{id:d="modal",show:u,animationFrom:c="bottom",children:v,enableOverlayClick:h=!0,rootComponentId:m,zIndex:j,onOverlayClick:y,dismissKeyboardOnShow:b=!0,disableScrollRestore:q}=n,p=e.__rest(n,["id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","disableScrollRestore"]);const f=a.useEvent(()=>{var e,r;b&&(null===(r=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===r||r.call(e))}),{verticalHeight:O,ready:C}=t.useViewport({enabled:u,onBeforeStart:f}),w=i.useRef(null),k=v&&s.default.cloneElement(v,{ref:w});return r.jsx(l.Overlay,{"data-testid":`${d}-overlay`,show:u,enableOverlayClick:h,onOverlayClick:y,id:d,rootId:m,containerRef:w,zIndex:j,disableScrollRestore:q,children:r.jsx(o.Container,Object.assign({$show:u,$ready:C,$animationFrom:c,"data-testid":d,$verticalHeight:O},p,{children:k}))})};
|
|
2
2
|
//# sourceMappingURL=modal.js.map
|
package/cjs/modal/modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.js","sources":["../../../src/modal/modal.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { Container } from \"./modal.styles\";\nimport { ModalProps } from \"./types\";\n\nexport const Modal = ({\n id = \"modal\",\n show,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n ...otherProps\n}: ModalProps): JSX.Element => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight, ready } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =============================================================================\n // RENDER FUNCTIONS\n // =============================================================================\n return (\n <Overlay\n data-testid={`${id}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n >\n <Container\n $show={show}\n $ready={ready}\n $animationFrom={animationFrom}\n data-testid={id}\n $verticalHeight={verticalHeight}\n {...otherProps}\n >\n {childWithRef}\n </Container>\n </Overlay>\n );\n};\n"],"names":["_a","id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","ready","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$show","$ready","$verticalHeight"],"mappings":"imBAOsBA,IAAA,IAAAC,GAClBA,EAAK,QAAOC,KACZA,EAAIC,cACJA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,
|
|
1
|
+
{"version":3,"file":"modal.js","sources":["../../../src/modal/modal.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { Container } from \"./modal.styles\";\nimport { ModalProps } from \"./types\";\n\nexport const Modal = ({\n id = \"modal\",\n show,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n disableScrollRestore,\n ...otherProps\n}: ModalProps): JSX.Element => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight, ready } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =============================================================================\n // RENDER FUNCTIONS\n // =============================================================================\n return (\n <Overlay\n data-testid={`${id}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n disableScrollRestore={disableScrollRestore}\n >\n <Container\n $show={show}\n $ready={ready}\n $animationFrom={animationFrom}\n data-testid={id}\n $verticalHeight={verticalHeight}\n {...otherProps}\n >\n {childWithRef}\n </Container>\n </Overlay>\n );\n};\n"],"names":["_a","id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","disableScrollRestore","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","ready","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$show","$ready","$animationFrom","$verticalHeight"],"mappings":"imBAOsBA,IAAA,IAAAC,GAClBA,EAAK,QAAOC,KACZA,EAAIC,cACJA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,EAAIC,qBAC5BA,GAAoBV,EACjBW,EAAUC,EAAAA,OAAAZ,EAXK,0JAgBlB,MAAMa,EAAkBC,EAAAA,SAAS,aACzBL,YACAM,EAAuC,UAAtCC,SAASC,yBAA6BjB,OAAA,EAAAA,EAAEkB,iCAG3CC,eAAEA,EAAcC,MAAEA,GAAUC,cAAY,CAC1CC,QAASpB,EACTqB,cAAeV,IAEbW,EAAWC,EAAAA,OAAuB,MAClCC,EACFtB,GAAYuB,UAAMC,aAAaxB,EAAU,CAAEyB,IAAKL,IAKpD,OACIM,EAAAA,IAACC,UAAO,CAAA,cACS,GAAG9B,YAChBC,KAAMA,EACNG,mBAAoBA,EACpBG,eAAgBA,EAChBP,GAAIA,EACJ+B,OAAQ1B,EACR2B,aAAcT,EACdjB,OAAQA,EACRG,qBAAsBA,EAAoBN,SAE1C0B,MAACI,EAAAA,UAASC,OAAAC,OAAA,CAAAC,MACCnC,EAAIoC,OACHlB,EAAKmB,eACGpC,EAAa,cAChBF,EAAEuC,gBACErB,GACbR,EAAU,CAAAP,SAEbsB"}
|
package/cjs/modal-v2/modal-v2.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../_virtual/_tslib.js"),r=require("react/jsx-runtime"),i=require("@floating-ui/react"),a=require("react"),l=require("../overlay/overlay.js"),t=require("../shared/hooks/useViewport.js");require("../util/calendar-helper.js"),require("../util/date-helper.js"),require("../util/date-input-helper.js"),require("../util/file-helper.js"),require("../util/simple-id-generator.js"),require("../util/string-helper.js"),require("@react-aria/live-announcer");var
|
|
1
|
+
"use strict";var e=require("../_virtual/_tslib.js"),r=require("react/jsx-runtime"),i=require("@floating-ui/react"),a=require("react"),l=require("../overlay/overlay.js"),t=require("../shared/hooks/useViewport.js");require("../util/calendar-helper.js"),require("../util/date-helper.js"),require("../util/date-input-helper.js"),require("../util/file-helper.js"),require("../util/simple-id-generator.js"),require("../util/string-helper.js"),require("@react-aria/live-announcer");var o=require("../util/use-event.js"),n=require("./modal-context.js"),s=require("./modal-v2.styles.js");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=d(a);exports.ModalV2=d=>{var{id:c,show:b,onClose:v,animationFrom:h="bottom",children:j,enableOverlayClick:m=!0,rootComponentId:y,zIndex:g,onOverlayClick:p,dismissKeyboardOnShow:q=!0,"data-testid":C="modal","aria-label":x,"aria-labelledby":f,"aria-describedby":O,disableInitialFocus:F=!1,disableScrollRestore:I}=d,S=e.__rest(d,["id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","data-testid","aria-label","aria-labelledby","aria-describedby","disableInitialFocus","disableScrollRestore"]);const k=o.useEvent(()=>{var e,r;q&&(null===(r=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===r||r.call(e))}),{verticalHeight:w}=t.useViewport({enabled:b,onBeforeStart:k}),M=a.useRef(null),R=j&&u.default.cloneElement(j,{ref:M}),{refs:_,context:z}=i.useFloating({open:b,onOpenChange:e=>{e||null==v||v()}}),{isMounted:E,status:P}=i.useTransitionStatus(z,{duration:300}),V=i.useDismiss(z,{outsidePress:!1,enabled:!!v}),{getFloatingProps:$}=i.useInteractions([V]);return r.jsx(l.Overlay,{"data-testid":`${C}-overlay`,show:b,enableOverlayClick:m,onOverlayClick:p,id:c,rootId:y,containerRef:M,zIndex:g,disableScrollRestore:I,children:r.jsx(s.Container,Object.assign({$animationFrom:h,"data-testid":C,$verticalHeight:w,"data-status":P},S,{children:r.jsx(n.ModalContext.Provider,{value:{onClose:v},children:E&&r.jsx(i.FloatingFocusManager,{context:z,initialFocus:F?-1:_.floating,children:r.jsx(s.ScrollContainer,{children:r.jsx(s.ModalContainer,Object.assign({ref:_.setFloating},$(),{role:"dialog","aria-label":x,"aria-labelledby":f,"aria-describedby":O,children:R}))})})})}))})};
|
|
2
2
|
//# sourceMappingURL=modal-v2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal-v2.js","sources":["../../../src/modal-v2/modal-v2.tsx"],"sourcesContent":["import {\n FloatingFocusManager,\n useDismiss,\n useFloating,\n useInteractions,\n useTransitionStatus,\n} from \"@floating-ui/react\";\nimport React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { ModalContext } from \"./modal-context\";\nimport { Container, ModalContainer, ScrollContainer } from \"./modal-v2.styles\";\nimport { ModalV2Props } from \"./types\";\n\nexport const ModalV2 = ({\n id,\n show,\n onClose,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n \"data-testid\": testId = \"modal\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n disableInitialFocus = false,\n ...otherProps\n}: ModalV2Props): JSX.Element => {\n // =========================================================================\n // CONST, STATE, REF\n // =========================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =========================================================================\n // FLOATING UI CONFIG\n // =========================================================================\n const { refs, context } = useFloating({\n open: show,\n onOpenChange: (isOpen) => {\n if (!isOpen) {\n onClose?.();\n }\n },\n });\n const { isMounted, status } = useTransitionStatus(context, {\n duration: 300,\n });\n const dismiss = useDismiss(context, {\n /* handled by overlayclick */\n outsidePress: false,\n enabled: !!onClose,\n });\n const { getFloatingProps } = useInteractions([dismiss]);\n\n // =========================================================================\n // RENDER FUNCTIONS\n // =========================================================================\n return (\n <Overlay\n data-testid={`${testId}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n >\n <Container\n $animationFrom={animationFrom}\n data-testid={testId}\n $verticalHeight={verticalHeight}\n data-status={status}\n {...otherProps}\n >\n <ModalContext.Provider value={{ onClose }}>\n {isMounted && (\n <FloatingFocusManager\n context={context}\n initialFocus={\n disableInitialFocus ? -1 : refs.floating\n }\n >\n <ScrollContainer>\n <ModalContainer\n ref={refs.setFloating}\n {...getFloatingProps()}\n role=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n >\n {childWithRef}\n </ModalContainer>\n </ScrollContainer>\n </FloatingFocusManager>\n )}\n </ModalContext.Provider>\n </Container>\n </Overlay>\n );\n};\n"],"names":["_a","id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","testId","ariaLabel","ariaLabelledBy","ariaDescribedBy","disableInitialFocus","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","refs","context","useFloating","open","onOpenChange","isOpen","isMounted","status","useTransitionStatus","duration","dismiss","useDismiss","outsidePress","getFloatingProps","useInteractions","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$animationFrom","$verticalHeight","ModalContext","Provider","value","FloatingFocusManager","initialFocus","floating","ScrollContainer","ModalContainer","setFloating","role"],"mappings":"sqBAewBA,QAAAC,GACpBA,EAAEC,KACFA,EAAIC,QACJA,EAAOC,cACPA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,EACxB,cAAeC,EAAS,QACxB,aAAcC,EACd,kBAAmBC,EACnB,mBAAoBC,EAAeC,oBACnCA,GAAsB,
|
|
1
|
+
{"version":3,"file":"modal-v2.js","sources":["../../../src/modal-v2/modal-v2.tsx"],"sourcesContent":["import {\n FloatingFocusManager,\n useDismiss,\n useFloating,\n useInteractions,\n useTransitionStatus,\n} from \"@floating-ui/react\";\nimport React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { ModalContext } from \"./modal-context\";\nimport { Container, ModalContainer, ScrollContainer } from \"./modal-v2.styles\";\nimport { ModalV2Props } from \"./types\";\n\nexport const ModalV2 = ({\n id,\n show,\n onClose,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n \"data-testid\": testId = \"modal\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n disableInitialFocus = false,\n disableScrollRestore,\n ...otherProps\n}: ModalV2Props): JSX.Element => {\n // =========================================================================\n // CONST, STATE, REF\n // =========================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =========================================================================\n // FLOATING UI CONFIG\n // =========================================================================\n const { refs, context } = useFloating({\n open: show,\n onOpenChange: (isOpen) => {\n if (!isOpen) {\n onClose?.();\n }\n },\n });\n const { isMounted, status } = useTransitionStatus(context, {\n duration: 300,\n });\n const dismiss = useDismiss(context, {\n /* handled by overlayclick */\n outsidePress: false,\n enabled: !!onClose,\n });\n const { getFloatingProps } = useInteractions([dismiss]);\n\n // =========================================================================\n // RENDER FUNCTIONS\n // =========================================================================\n return (\n <Overlay\n data-testid={`${testId}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n disableScrollRestore={disableScrollRestore}\n >\n <Container\n $animationFrom={animationFrom}\n data-testid={testId}\n $verticalHeight={verticalHeight}\n data-status={status}\n {...otherProps}\n >\n <ModalContext.Provider value={{ onClose }}>\n {isMounted && (\n <FloatingFocusManager\n context={context}\n initialFocus={\n disableInitialFocus ? -1 : refs.floating\n }\n >\n <ScrollContainer>\n <ModalContainer\n ref={refs.setFloating}\n {...getFloatingProps()}\n role=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n >\n {childWithRef}\n </ModalContainer>\n </ScrollContainer>\n </FloatingFocusManager>\n )}\n </ModalContext.Provider>\n </Container>\n </Overlay>\n );\n};\n"],"names":["_a","id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","testId","ariaLabel","ariaLabelledBy","ariaDescribedBy","disableInitialFocus","disableScrollRestore","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","refs","context","useFloating","open","onOpenChange","isOpen","isMounted","status","useTransitionStatus","duration","dismiss","useDismiss","outsidePress","getFloatingProps","useInteractions","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$animationFrom","$verticalHeight","ModalContext","Provider","value","FloatingFocusManager","initialFocus","floating","ScrollContainer","ModalContainer","setFloating","role"],"mappings":"sqBAewBA,QAAAC,GACpBA,EAAEC,KACFA,EAAIC,QACJA,EAAOC,cACPA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,EACxB,cAAeC,EAAS,QACxB,aAAcC,EACd,kBAAmBC,EACnB,mBAAoBC,EAAeC,oBACnCA,GAAsB,EAAKC,qBAC3BA,GAAoBhB,EACjBiB,EAAUC,EAAAA,OAAAlB,EAjBO,CAAA,KAAA,OAAA,UAAA,gBAAA,WAAA,qBAAA,kBAAA,SAAA,iBAAA,wBAAA,cAAA,aAAA,kBAAA,mBAAA,sBAAA,yBAsBpB,MAAMmB,EAAkBC,EAAAA,SAAS,aACzBV,YACAW,EAAuC,UAAtCC,SAASC,yBAA6BvB,OAAA,EAAAA,EAAEwB,iCAG3CC,eAAEA,GAAmBC,cAAY,CACnCC,QAASzB,EACT0B,cAAeT,IAEbU,EAAWC,EAAAA,OAAuB,MAClCC,EACF1B,GAAY2B,UAAMC,aAAa5B,EAAU,CAAE6B,IAAKL,KAK9CM,KAAEA,EAAIC,QAAEA,GAAYC,cAAY,CAClCC,KAAMpC,EACNqC,aAAeC,IACNA,GACDrC,SAAAA,QAINsC,UAAEA,EAASC,OAAEA,GAAWC,EAAAA,oBAAoBP,EAAS,CACvDQ,SAAU,MAERC,EAAUC,EAAAA,WAAWV,EAAS,CAEhCW,cAAc,EACdpB,UAAWxB,KAET6C,iBAAEA,GAAqBC,kBAAgB,CAACJ,IAK9C,OACIK,EAAAA,IAACC,UAAO,CAAA,cACS,GAAGxC,YAChBT,KAAMA,EACNI,mBAAoBA,EACpBG,eAAgBA,EAChBR,GAAIA,EACJmD,OAAQ7C,EACR8C,aAAcxB,EACdrB,OAAQA,EACRQ,qBAAsBA,EAAoBX,SAE1C6C,EAAAA,IAACI,YAASC,OAAAC,OAAA,CAAAC,eACUrD,EAAa,cAChBO,EAAM+C,gBACFjC,EAAc,cAClBiB,GACTzB,EAAU,CAAAZ,SAEd6C,MAACS,EAAAA,aAAaC,SAAQ,CAACC,MAAO,CAAE1D,WAASE,SACpCoC,GACGS,MAACY,EAAAA,qBAAoB,CACjB1B,QAASA,EACT2B,aACIhD,GAAsB,EAAKoB,EAAK6B,SAAQ3D,SAG5C6C,EAAAA,IAACe,EAAAA,gBAAe,CAAA5D,SACZ6C,MAACgB,EAAAA,eAAcX,OAAAC,OAAA,CACXtB,IAAKC,EAAKgC,aACNnB,IAAkB,CACtBoB,KAAK,SAAQ,aACDxD,EAAS,kBACJC,EAAc,mBACbC,EAAeT,SAEhC0B"}
|
package/cjs/overlay/overlay.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("@floating-ui/react"),r=require("react"),n=require("react-dom");require("../util/calendar-helper.js"),require("../util/date-helper.js"),require("../util/date-input-helper.js"),require("../util/file-helper.js");var o=require("../util/simple-id-generator.js");require("../util/string-helper.js"),require("@react-aria/live-announcer");var s=require("./overlay.styles.js"),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("@floating-ui/react"),r=require("react"),n=require("react-dom");require("../util/calendar-helper.js"),require("../util/date-helper.js"),require("../util/date-input-helper.js"),require("../util/file-helper.js");var o=require("../util/simple-id-generator.js");require("../util/string-helper.js"),require("@react-aria/live-announcer");var s=require("./overlay.styles.js"),l=require("./use-floating-context.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=i(n);const u=({show:n=!1,rootId:i,onOverlayClick:u,children:v,backgroundOpacity:f,backgroundBlur:g=!0,disableTransition:p=!1,enableOverlayClick:b=!1,zIndex:h,id:j,containerRef:w,disableScrollRestore:q=!1})=>{const[x,$]=r.useState(null),[O,E]=r.useState(),k=o.useId(),L=t.useFloatingNodeId(),T=r.useRef(),P=r.useRef(!1),I=r.useRef(null),R=r.useRef(q),F=j?`lifesg-ds-overlay-root-${j}`:"lifesg-ds-overlay-root",B=null!=h?h:O?99999:99998;l.useFloatingParent(B),r.useEffect(()=>(z(),$(S()),()=>{M(),N().length<1&&(D()&&(V("remove"),G()),A("remove"))}),[]),r.useEffect(()=>{n&&(R.current=q)},[n,q]),r.useEffect(()=>{if(n){const e=W();C(e),H(),D()&&1===N().length&&(Y(),V("add"));const t=setTimeout(()=>{A("add")},200);return()=>clearTimeout(t)}{M(),D()&&N().length<1&&(V("remove"),G());const e=setTimeout(()=>{N().length<1&&A("remove")},200);return()=>clearTimeout(e)}},[n]),r.useEffect(()=>{if(n)return document.addEventListener("mousedown",J,!0),()=>{document.removeEventListener("mousedown",J,!0)}},[n]);const C=e=>{T.current=e,E(e)},D=()=>/(iPad|iPhone|iPod)/g.test(navigator.userAgent),S=()=>document&&i?document.getElementById(i):document?document.body:null,W=()=>N().length>0,z=()=>{if(!document.getElementById(a)){const e=document.createElement("style");e.id=a;const t=document.documentElement.clientWidth,r=window.innerWidth-t;e.innerHTML=`\n\t\t\t\t.${c} {\n\t\t\t\t\toverflow: hidden;\n\t\t\t\t\tpadding-right: ${r}px !important;\n\t\t\t\t\t-ms-overflow-style: none;\n\t\t\t\t\tscrollbar-width: none;\n\t\t\t\t}\n\n\t\t\t\t.${c}::-webkit-scrollbar {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\n\t\t\t\t.${m} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: var(${y}, 0);\n\t\t\t\t\tbottom: 0;\n\t\t\t\t}\n\t\t\t`,document.body.appendChild(e)}},A=e=>{const t=document.body.classList.contains(c);"add"!==e||t?"remove"===e&&t&&document.body.classList.remove(c):document.body.classList.add(c)},N=()=>{const e=document.body.dataset.lifesgDsOverlayOrder;return e?e.split(","):[]},H=()=>{const e=N();document.body.dataset.lifesgDsOverlayOrder=[...e,k].join(",")},M=()=>{const e=N();document.body.dataset.lifesgDsOverlayOrder=e.filter(e=>e!==k).join(",")},V=e=>{if(!D())return;const t=document.body.classList.contains(m);"add"!==e||t?"remove"===e&&t&&document.body.classList.remove(m):document.body.classList.add(m)},Y=()=>{const e=document.body.style,t=e.top?e.top:window.scrollY+"px";document.body.style.setProperty(y,t)},G=()=>{if(!D())return;const e=document.body.style.getPropertyValue(y);document.body.style.removeProperty(y),e&&!R.current&&requestAnimationFrame(()=>{window.scrollTo({top:parseFloat(e)})})},J=e=>{var t;const r=null!==(t=null==w?void 0:w.current)&&void 0!==t?t:I.current,n=I.current;if(!r)return void(P.current=!1);const o=e.target,s=n===o,l=r===o,i=r.contains(o);P.current=!s&&(l||i)},K=e=>{var t;const r=null!==(t=null==w?void 0:w.current)&&void 0!==t?t:I.current,n=I.current;if(!r)return void(P.current=!1);const o=e.target,s=n===o,l=r===o,i=r.contains(o);!s&&(l||i)||P.current||!u||!b||(e.preventDefault(),u()),P.current=!1};return x?d.default.createPortal(e.jsx(s.Root,{id:F,"data-testid":F,$show:n,$zIndex:B,children:v&&e.jsx(t.FloatingNode,{id:L,children:e.jsx(s.Wrapper,{ref:I,"data-testid":"overlay-wrapper",$show:n,$stacked:O,$backgroundBlur:g,$disableTransition:p,onClick:K,children:v})})}),x):null},a="lifesg-ds-overlay-stylesheet",c="lifesg-ds-overlay-open",m="lifesg-ds-overlay-scroll-lock",y="--lifesg-ds-overlay-scroll-y";exports.Overlay=r=>e.jsx(t.FloatingTree,{children:e.jsx(u,Object.assign({},r))});
|
|
2
2
|
//# sourceMappingURL=overlay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.js","sources":["../../../src/overlay/overlay.tsx"],"sourcesContent":["import {\n FloatingNode,\n FloatingTree,\n useFloatingNodeId,\n} from \"@floating-ui/react\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { useId } from \"../util\";\nimport { Root, Wrapper } from \"./overlay.styles\";\nimport { OverlayProps } from \"./types\";\nimport { useFloatingParent } from \"./use-floating-context\";\n\nconst OverlayComponent = ({\n show = false,\n rootId,\n onOverlayClick,\n children,\n backgroundOpacity: _backgroundOpacity,\n backgroundBlur = true,\n disableTransition = false,\n enableOverlayClick = false,\n zIndex: customZIndex,\n id,\n containerRef,\n}: OverlayProps): JSX.Element | null => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const [rootElement, setRootElement] = useState<HTMLElement | null>(null);\n const [isStacked, _setIsStacked] = useState<boolean>();\n const uid = useId();\n const nodeId = useFloatingNodeId();\n\n const stacked = useRef<boolean>();\n // Track where mousedown started to prevent closing drawer during text selection drag\n const mouseDownInsideModalRef = useRef(false);\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n const overlayRootId = id\n ? `lifesg-ds-overlay-root-${id}`\n : \"lifesg-ds-overlay-root\";\n const zIndex = customZIndex ?? (isStacked ? 99999 : 99998);\n\n useFloatingParent(zIndex);\n\n // =============================================================================\n // EFFECTS\n // =============================================================================\n useEffect(() => {\n addStylesheetForDocumentBody();\n setRootElement(getRootElement());\n\n return () => {\n removeOverlay();\n\n if (getOverlayOrder().length < 1) {\n if (isIOS()) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n applyBodyStyleClass(\"remove\");\n }\n };\n }, []);\n\n useEffect(() => {\n if (show) {\n const isStacked = checkIfStacked();\n setStacked(isStacked);\n\n addOverlay();\n\n if (isIOS() && getOverlayOrder().length === 1) {\n saveScrollPosition();\n applyScrollLockClassForIOS(\"add\");\n }\n\n const timerId = setTimeout(() => {\n applyBodyStyleClass(\"add\");\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n } else {\n removeOverlay();\n\n if (isIOS() && getOverlayOrder().length < 1) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n const timerId = setTimeout(() => {\n if (getOverlayOrder().length < 1) {\n applyBodyStyleClass(\"remove\");\n }\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n }\n }, [show]);\n\n // Track mousedown origin to distinguish clicks from text selection drags\n useEffect(() => {\n if (!show) return;\n\n document.addEventListener(\"mousedown\", handleDocumentMouseDown, true);\n return () => {\n document.removeEventListener(\n \"mousedown\",\n handleDocumentMouseDown,\n true\n );\n };\n }, [show]);\n\n // =============================================================================\n // REF FUNCTIONS\n // =============================================================================\n const setStacked = (data: boolean) => {\n stacked.current = data;\n _setIsStacked(data);\n };\n\n // =============================================================================\n // HELPER FUNCTIONS\n // =============================================================================\n const isIOS = () => /(iPad|iPhone|iPod)/g.test(navigator.userAgent);\n\n const getRootElement = (): HTMLElement | null => {\n if (document && rootId) {\n return document.getElementById(rootId);\n } else if (document) {\n // If rootId not specified, we'll use body\n return document.body;\n } else {\n return null;\n }\n };\n\n const checkIfStacked = () => {\n return getOverlayOrder().length > 0;\n };\n\n const addStylesheetForDocumentBody = () => {\n /**\n * This stylesheet is to manipulate the <body>. We only add once\n */\n if (!document.getElementById(STYLESHEET_ID)) {\n const overlayStyleSheet = document.createElement(\"style\");\n overlayStyleSheet.id = STYLESHEET_ID;\n\n const documentWidth = document.documentElement.clientWidth;\n const windowWidth = window.innerWidth;\n const scrollBarWidth = windowWidth - documentWidth;\n\n overlayStyleSheet.innerHTML = `\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME} {\n\t\t\t\t\toverflow: hidden;\n\t\t\t\t\tpadding-right: ${scrollBarWidth}px !important;\n\t\t\t\t\t-ms-overflow-style: none;\n\t\t\t\t\tscrollbar-width: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME}::-webkit-scrollbar {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_SCROLL_LOCK_CLASSNAME} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: var(${SCROLL_POSITION_VAR}, 0);\n\t\t\t\t\tbottom: 0;\n\t\t\t\t}\n\t\t\t`;\n\n document.body.appendChild(overlayStyleSheet);\n }\n };\n\n /**\n * This sets the style of <body> to hide the scrollbar\n */\n const applyBodyStyleClass = (action: \"add\" | \"remove\") => {\n const isOverlayStyleClassApplied = document.body.classList.contains(\n OVERLAY_OPEN_CLASSNAME\n );\n\n if (action === \"add\" && !isOverlayStyleClassApplied) {\n document.body.classList.add(OVERLAY_OPEN_CLASSNAME);\n } else if (action === \"remove\" && isOverlayStyleClassApplied) {\n document.body.classList.remove(OVERLAY_OPEN_CLASSNAME);\n }\n };\n\n const getOverlayOrder = () => {\n const attr = document.body.dataset.lifesgDsOverlayOrder;\n return attr ? attr.split(\",\") : [];\n };\n\n const addOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = [...order, uid].join(\",\");\n };\n\n const removeOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = order\n .filter((o) => o !== uid)\n .join(\",\");\n };\n\n /**\n * This sets the style of <body> to further prevent scrolling on iOS\n *\n * ref: https://stackoverflow.com/a/57455820/3932279\n * `overflow: hidden` and `overscroll-behavior` is ignored by iOS, this is\n * an alternative solution\n *\n * as a side effect this causes the scroll position to reset, so additional\n * logic to restore the scroll on close is required\n */\n const applyScrollLockClassForIOS = (action: \"add\" | \"remove\") => {\n if (!isIOS()) {\n return;\n }\n\n const isClassApplied = document.body.classList.contains(\n OVERLAY_SCROLL_LOCK_CLASSNAME\n );\n\n if (action === \"add\" && !isClassApplied) {\n document.body.classList.add(OVERLAY_SCROLL_LOCK_CLASSNAME);\n } else if (action === \"remove\" && isClassApplied) {\n document.body.classList.remove(OVERLAY_SCROLL_LOCK_CLASSNAME);\n }\n };\n\n const saveScrollPosition = () => {\n const bodyStyle = document.body.style;\n const scrollY = bodyStyle.top ? bodyStyle.top : window.scrollY + \"px\";\n\n document.body.style.setProperty(SCROLL_POSITION_VAR, scrollY);\n };\n\n const scrollToLastScrollPositionForIOS = () => {\n if (!isIOS()) {\n return;\n }\n\n const scrollY =\n document.body.style.getPropertyValue(SCROLL_POSITION_VAR);\n requestAnimationFrame(() => {\n window.scrollTo({\n top: parseFloat(scrollY),\n });\n });\n };\n\n // =============================================================================\n // EVENT HANDLERS\n // =============================================================================\n const handleDocumentMouseDown = (e: MouseEvent) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = e.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n\n // Track if mousedown started inside modal content\n mouseDownInsideModalRef.current =\n !clickedOnWrapper && (clickedOnContainer || clickedInsideContainer);\n };\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = event.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n const clickedInsideModal = clickedOnContainer || clickedInsideContainer;\n\n // Only close if both mousedown AND click happened outside modal\n if (\n (clickedOnWrapper || !clickedInsideModal) &&\n !mouseDownInsideModalRef.current &&\n onOverlayClick &&\n enableOverlayClick\n ) {\n event.preventDefault();\n onOverlayClick();\n }\n\n mouseDownInsideModalRef.current = false;\n };\n\n // =============================================================================\n // RENDER\n // =============================================================================\n const renderWrapper = () => (\n <FloatingNode id={nodeId}>\n <Wrapper\n ref={wrapperRef}\n data-testid=\"overlay-wrapper\"\n $show={show}\n $stacked={isStacked}\n $backgroundBlur={backgroundBlur}\n $disableTransition={disableTransition}\n onClick={handleWrapperClick}\n >\n {children}\n </Wrapper>\n </FloatingNode>\n );\n\n const renderComponent = () => (\n <Root\n id={overlayRootId}\n data-testid={overlayRootId}\n $show={show}\n $zIndex={zIndex}\n >\n {children && renderWrapper()}\n </Root>\n );\n\n return rootElement\n ? ReactDOM.createPortal(renderComponent(), rootElement)\n : null;\n};\n\nexport const Overlay = (props: OverlayProps) => {\n return (\n <FloatingTree>\n <OverlayComponent {...props} />\n </FloatingTree>\n );\n};\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\nconst STYLESHEET_ID = \"lifesg-ds-overlay-stylesheet\";\nconst OVERLAY_OPEN_CLASSNAME = \"lifesg-ds-overlay-open\";\nconst OVERLAY_SCROLL_LOCK_CLASSNAME = \"lifesg-ds-overlay-scroll-lock\";\nconst SCROLL_POSITION_VAR = \"--lifesg-ds-overlay-scroll-y\";\n"],"names":["OverlayComponent","show","rootId","onOverlayClick","children","backgroundOpacity","_backgroundOpacity","backgroundBlur","disableTransition","enableOverlayClick","zIndex","customZIndex","id","containerRef","rootElement","setRootElement","useState","isStacked","_setIsStacked","uid","useId","nodeId","useFloatingNodeId","stacked","useRef","mouseDownInsideModalRef","wrapperRef","overlayRootId","useFloatingParent","useEffect","addStylesheetForDocumentBody","getRootElement","removeOverlay","getOverlayOrder","length","isIOS","applyScrollLockClassForIOS","scrollToLastScrollPositionForIOS","applyBodyStyleClass","checkIfStacked","setStacked","addOverlay","saveScrollPosition","timerId","setTimeout","clearTimeout","document","addEventListener","handleDocumentMouseDown","removeEventListener","data","current","test","navigator","userAgent","getElementById","body","STYLESHEET_ID","overlayStyleSheet","createElement","documentWidth","documentElement","clientWidth","scrollBarWidth","window","innerWidth","innerHTML","OVERLAY_OPEN_CLASSNAME","OVERLAY_SCROLL_LOCK_CLASSNAME","SCROLL_POSITION_VAR","appendChild","action","isOverlayStyleClassApplied","classList","contains","remove","add","attr","dataset","lifesgDsOverlayOrder","split","order","join","filter","o","isClassApplied","bodyStyle","style","scrollY","top","setProperty","getPropertyValue","requestAnimationFrame","scrollTo","parseFloat","e","container","_a","wrapper","target","clickedOnWrapper","clickedOnContainer","clickedInsideContainer","handleWrapperClick","event","preventDefault","ReactDOM","createPortal","_jsx","Root","$show","$zIndex","FloatingNode","Wrapper","ref","$stacked","$backgroundBlur","$disableTransition","onClick","props","FloatingTree","Object","assign"],"mappings":"qiBAYA,MAAMA,EAAmB,EACrBC,QAAO,EACPC,SACAC,iBACAC,WACAC,kBAAmBC,EACnBC,kBAAiB,EACjBC,qBAAoB,EACpBC,sBAAqB,EACrBC,OAAQC,EACRC,KACAC,mBAKA,MAAOC,EAAaC,GAAkBC,EAAAA,SAA6B,OAC5DC,EAAWC,GAAiBF,aAC7BG,EAAMC,EAAAA,QACNC,EAASC,EAAAA,oBAETC,EAAUC,EAAAA,SAEVC,EAA0BD,EAAAA,QAAO,GACjCE,EAAaF,EAAAA,OAAuB,MAEpCG,EAAgBf,EAChB,0BAA0BA,IAC1B,yBACAF,EAASC,QAAAA,EAAiBM,EAAY,MAAQ,MAEpDW,EAAAA,kBAAkBlB,GAKlBmB,EAAAA,UAAU,KACNC,IACAf,EAAegB,KAER,KACHC,IAEIC,IAAkBC,OAAS,IACvBC,MACAC,EAA2B,UAC3BC,KAGJC,EAAoB,aAG7B,IAEHT,EAAAA,UAAU,KACN,GAAI5B,EAAM,CACN,MAAMgB,EAAYsB,IAClBC,EAAWvB,GAEXwB,IAEIN,KAAwC,IAA7BF,IAAkBC,SAC7BQ,IACAN,EAA2B,QAG/B,MAAMO,EAAUC,WAAW,KACvBN,EAAoB,QACrB,KAEH,MAAO,IAAMO,aAAaF,EAC9B,CAAO,CACHX,IAEIG,KAAWF,IAAkBC,OAAS,IACtCE,EAA2B,UAC3BC,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,IACAM,IAEA+F,EAAMC,iBACNtG,KAGJsB,EAAwB0B,SAAU,GAiCtC,OAAOrC,EACD4F,UAASC,aAXXC,MAACC,EAAAA,KAAI,CACDjG,GAAIe,gBACSA,EAAamF,MACnB7G,EAAI8G,QACFrG,EAAMN,SAEdA,GAtBLwG,EAAAA,IAACI,EAAAA,aAAY,CAACpG,GAAIS,EAAMjB,SACpBwG,EAAAA,IAACK,EAAAA,QAAO,CACJC,IAAKxF,EAAU,cACH,wBACLzB,EAAIkH,SACDlG,EAASmG,gBACF7G,EAAc8G,mBACX7G,EACpB8G,QAASf,EAAkBnG,SAE1BA,QAiBkCU,GACzC,MAcJ2C,EAAgB,+BAChBU,EAAyB,yBACzBC,EAAgC,gCAChCC,EAAsB,+CAdJkD,GAEhBX,MAACY,EAAAA,aAAY,CAAApH,SACTwG,EAAAA,IAAC5G,EAAgByH,OAAAC,OAAA,CAAA,EAAKH"}
|
|
1
|
+
{"version":3,"file":"overlay.js","sources":["../../../src/overlay/overlay.tsx"],"sourcesContent":["import {\n FloatingNode,\n FloatingTree,\n useFloatingNodeId,\n} from \"@floating-ui/react\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { useId } from \"../util\";\nimport { Root, Wrapper } from \"./overlay.styles\";\nimport { OverlayProps } from \"./types\";\nimport { useFloatingParent } from \"./use-floating-context\";\n\nconst OverlayComponent = ({\n show = false,\n rootId,\n onOverlayClick,\n children,\n backgroundOpacity: _backgroundOpacity,\n backgroundBlur = true,\n disableTransition = false,\n enableOverlayClick = false,\n zIndex: customZIndex,\n id,\n containerRef,\n disableScrollRestore = false,\n}: OverlayProps): JSX.Element | null => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const [rootElement, setRootElement] = useState<HTMLElement | null>(null);\n const [isStacked, _setIsStacked] = useState<boolean>();\n const uid = useId();\n const nodeId = useFloatingNodeId();\n\n const stacked = useRef<boolean>();\n // Track where mousedown started to prevent closing drawer during text selection drag\n const mouseDownInsideModalRef = useRef(false);\n const wrapperRef = useRef<HTMLDivElement>(null);\n // Value from the last render while shown, as consumers may reset it on close\n const disableScrollRestoreRef = useRef(disableScrollRestore);\n\n const overlayRootId = id\n ? `lifesg-ds-overlay-root-${id}`\n : \"lifesg-ds-overlay-root\";\n const zIndex = customZIndex ?? (isStacked ? 99999 : 99998);\n\n useFloatingParent(zIndex);\n\n // =============================================================================\n // EFFECTS\n // =============================================================================\n useEffect(() => {\n addStylesheetForDocumentBody();\n setRootElement(getRootElement());\n\n return () => {\n removeOverlay();\n\n if (getOverlayOrder().length < 1) {\n if (isIOS()) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n applyBodyStyleClass(\"remove\");\n }\n };\n }, []);\n\n // Declared before the [show] effect so the ref is up to date when it runs\n useEffect(() => {\n if (show) {\n disableScrollRestoreRef.current = disableScrollRestore;\n }\n }, [show, disableScrollRestore]);\n\n useEffect(() => {\n if (show) {\n const isStacked = checkIfStacked();\n setStacked(isStacked);\n\n addOverlay();\n\n if (isIOS() && getOverlayOrder().length === 1) {\n saveScrollPosition();\n applyScrollLockClassForIOS(\"add\");\n }\n\n const timerId = setTimeout(() => {\n applyBodyStyleClass(\"add\");\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n } else {\n removeOverlay();\n\n if (isIOS() && getOverlayOrder().length < 1) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n const timerId = setTimeout(() => {\n if (getOverlayOrder().length < 1) {\n applyBodyStyleClass(\"remove\");\n }\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n }\n }, [show]);\n\n // Track mousedown origin to distinguish clicks from text selection drags\n useEffect(() => {\n if (!show) return;\n\n document.addEventListener(\"mousedown\", handleDocumentMouseDown, true);\n return () => {\n document.removeEventListener(\n \"mousedown\",\n handleDocumentMouseDown,\n true\n );\n };\n }, [show]);\n\n // =============================================================================\n // REF FUNCTIONS\n // =============================================================================\n const setStacked = (data: boolean) => {\n stacked.current = data;\n _setIsStacked(data);\n };\n\n // =============================================================================\n // HELPER FUNCTIONS\n // =============================================================================\n const isIOS = () => /(iPad|iPhone|iPod)/g.test(navigator.userAgent);\n\n const getRootElement = (): HTMLElement | null => {\n if (document && rootId) {\n return document.getElementById(rootId);\n } else if (document) {\n // If rootId not specified, we'll use body\n return document.body;\n } else {\n return null;\n }\n };\n\n const checkIfStacked = () => {\n return getOverlayOrder().length > 0;\n };\n\n const addStylesheetForDocumentBody = () => {\n /**\n * This stylesheet is to manipulate the <body>. We only add once\n */\n if (!document.getElementById(STYLESHEET_ID)) {\n const overlayStyleSheet = document.createElement(\"style\");\n overlayStyleSheet.id = STYLESHEET_ID;\n\n const documentWidth = document.documentElement.clientWidth;\n const windowWidth = window.innerWidth;\n const scrollBarWidth = windowWidth - documentWidth;\n\n overlayStyleSheet.innerHTML = `\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME} {\n\t\t\t\t\toverflow: hidden;\n\t\t\t\t\tpadding-right: ${scrollBarWidth}px !important;\n\t\t\t\t\t-ms-overflow-style: none;\n\t\t\t\t\tscrollbar-width: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME}::-webkit-scrollbar {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_SCROLL_LOCK_CLASSNAME} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: var(${SCROLL_POSITION_VAR}, 0);\n\t\t\t\t\tbottom: 0;\n\t\t\t\t}\n\t\t\t`;\n\n document.body.appendChild(overlayStyleSheet);\n }\n };\n\n /**\n * This sets the style of <body> to hide the scrollbar\n */\n const applyBodyStyleClass = (action: \"add\" | \"remove\") => {\n const isOverlayStyleClassApplied = document.body.classList.contains(\n OVERLAY_OPEN_CLASSNAME\n );\n\n if (action === \"add\" && !isOverlayStyleClassApplied) {\n document.body.classList.add(OVERLAY_OPEN_CLASSNAME);\n } else if (action === \"remove\" && isOverlayStyleClassApplied) {\n document.body.classList.remove(OVERLAY_OPEN_CLASSNAME);\n }\n };\n\n const getOverlayOrder = () => {\n const attr = document.body.dataset.lifesgDsOverlayOrder;\n return attr ? attr.split(\",\") : [];\n };\n\n const addOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = [...order, uid].join(\",\");\n };\n\n const removeOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = order\n .filter((o) => o !== uid)\n .join(\",\");\n };\n\n /**\n * This sets the style of <body> to further prevent scrolling on iOS\n *\n * ref: https://stackoverflow.com/a/57455820/3932279\n * `overflow: hidden` and `overscroll-behavior` is ignored by iOS, this is\n * an alternative solution\n *\n * as a side effect this causes the scroll position to reset, so additional\n * logic to restore the scroll on close is required\n */\n const applyScrollLockClassForIOS = (action: \"add\" | \"remove\") => {\n if (!isIOS()) {\n return;\n }\n\n const isClassApplied = document.body.classList.contains(\n OVERLAY_SCROLL_LOCK_CLASSNAME\n );\n\n if (action === \"add\" && !isClassApplied) {\n document.body.classList.add(OVERLAY_SCROLL_LOCK_CLASSNAME);\n } else if (action === \"remove\" && isClassApplied) {\n document.body.classList.remove(OVERLAY_SCROLL_LOCK_CLASSNAME);\n }\n };\n\n const saveScrollPosition = () => {\n const bodyStyle = document.body.style;\n const scrollY = bodyStyle.top ? bodyStyle.top : window.scrollY + \"px\";\n\n document.body.style.setProperty(SCROLL_POSITION_VAR, scrollY);\n };\n\n const scrollToLastScrollPositionForIOS = () => {\n if (!isIOS()) {\n return;\n }\n\n const scrollY =\n document.body.style.getPropertyValue(SCROLL_POSITION_VAR);\n document.body.style.removeProperty(SCROLL_POSITION_VAR);\n\n if (!scrollY || disableScrollRestoreRef.current) {\n return;\n }\n\n requestAnimationFrame(() => {\n window.scrollTo({\n top: parseFloat(scrollY),\n });\n });\n };\n\n // =============================================================================\n // EVENT HANDLERS\n // =============================================================================\n const handleDocumentMouseDown = (e: MouseEvent) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = e.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n\n // Track if mousedown started inside modal content\n mouseDownInsideModalRef.current =\n !clickedOnWrapper && (clickedOnContainer || clickedInsideContainer);\n };\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = event.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n const clickedInsideModal = clickedOnContainer || clickedInsideContainer;\n\n // Only close if both mousedown AND click happened outside modal\n if (\n (clickedOnWrapper || !clickedInsideModal) &&\n !mouseDownInsideModalRef.current &&\n onOverlayClick &&\n enableOverlayClick\n ) {\n event.preventDefault();\n onOverlayClick();\n }\n\n mouseDownInsideModalRef.current = false;\n };\n\n // =============================================================================\n // RENDER\n // =============================================================================\n const renderWrapper = () => (\n <FloatingNode id={nodeId}>\n <Wrapper\n ref={wrapperRef}\n data-testid=\"overlay-wrapper\"\n $show={show}\n $stacked={isStacked}\n $backgroundBlur={backgroundBlur}\n $disableTransition={disableTransition}\n onClick={handleWrapperClick}\n >\n {children}\n </Wrapper>\n </FloatingNode>\n );\n\n const renderComponent = () => (\n <Root\n id={overlayRootId}\n data-testid={overlayRootId}\n $show={show}\n $zIndex={zIndex}\n >\n {children && renderWrapper()}\n </Root>\n );\n\n return rootElement\n ? ReactDOM.createPortal(renderComponent(), rootElement)\n : null;\n};\n\nexport const Overlay = (props: OverlayProps) => {\n return (\n <FloatingTree>\n <OverlayComponent {...props} />\n </FloatingTree>\n );\n};\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\nconst STYLESHEET_ID = \"lifesg-ds-overlay-stylesheet\";\nconst OVERLAY_OPEN_CLASSNAME = \"lifesg-ds-overlay-open\";\nconst OVERLAY_SCROLL_LOCK_CLASSNAME = \"lifesg-ds-overlay-scroll-lock\";\nconst SCROLL_POSITION_VAR = \"--lifesg-ds-overlay-scroll-y\";\n"],"names":["OverlayComponent","show","rootId","onOverlayClick","children","backgroundOpacity","_backgroundOpacity","backgroundBlur","disableTransition","enableOverlayClick","zIndex","customZIndex","id","containerRef","disableScrollRestore","rootElement","setRootElement","useState","isStacked","_setIsStacked","uid","useId","nodeId","useFloatingNodeId","stacked","useRef","mouseDownInsideModalRef","wrapperRef","disableScrollRestoreRef","overlayRootId","useFloatingParent","useEffect","addStylesheetForDocumentBody","getRootElement","removeOverlay","getOverlayOrder","length","isIOS","applyScrollLockClassForIOS","scrollToLastScrollPositionForIOS","applyBodyStyleClass","current","checkIfStacked","setStacked","addOverlay","saveScrollPosition","timerId","setTimeout","clearTimeout","document","addEventListener","handleDocumentMouseDown","removeEventListener","data","test","navigator","userAgent","getElementById","body","STYLESHEET_ID","overlayStyleSheet","createElement","documentWidth","documentElement","clientWidth","scrollBarWidth","window","innerWidth","innerHTML","OVERLAY_OPEN_CLASSNAME","OVERLAY_SCROLL_LOCK_CLASSNAME","SCROLL_POSITION_VAR","appendChild","action","isOverlayStyleClassApplied","classList","contains","remove","add","attr","dataset","lifesgDsOverlayOrder","split","order","join","filter","o","isClassApplied","bodyStyle","style","scrollY","top","setProperty","getPropertyValue","removeProperty","requestAnimationFrame","scrollTo","parseFloat","e","container","_a","wrapper","target","clickedOnWrapper","clickedOnContainer","clickedInsideContainer","handleWrapperClick","event","preventDefault","ReactDOM","createPortal","_jsx","Root","$show","$zIndex","FloatingNode","Wrapper","ref","$stacked","$backgroundBlur","$disableTransition","onClick","props","FloatingTree","Object","assign"],"mappings":"qiBAYA,MAAMA,EAAmB,EACrBC,QAAO,EACPC,SACAC,iBACAC,WACAC,kBAAmBC,E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AAA,QAAO,CACJC,IAAK1F,EAAU,cACH,wBACL1B,EAAIqH,SACDpG,EAASqG,gBACFhH,EAAciH,mBACXhH,EACpBiH,QAASf,EAAkBtG,SAE1BA,QAiBkCW,GACzC,MAcJ4C,EAAgB,+BAChBU,EAAyB,yBACzBC,EAAgC,gCAChCC,EAAsB,+CAdJmD,GAEhBX,MAACY,EAAAA,aAAY,CAAAvH,SACT2G,EAAAA,IAAC/G,EAAgB4H,OAAAC,OAAA,CAAA,EAAKH"}
|
|
@@ -17,7 +17,7 @@ export declare const Instructions: import("styled-components/dist/types").IStyle
|
|
|
17
17
|
as?: import("styled-components").WebTarget | undefined;
|
|
18
18
|
forwardedAs?: import("styled-components").WebTarget | undefined;
|
|
19
19
|
}, never>>> & string;
|
|
20
|
-
export declare const ScrollableModal: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("..").ModalProps, never> & Partial<Pick<import("..").ModalProps, never>>> & string & Omit<(({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, ...otherProps }: import("..").ModalProps) => JSX.Element) & {
|
|
20
|
+
export declare const ScrollableModal: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("..").ModalProps, never> & Partial<Pick<import("..").ModalProps, never>>> & string & Omit<(({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, disableScrollRestore, ...otherProps }: import("..").ModalProps) => JSX.Element) & {
|
|
21
21
|
Box: (props: import("..").ModalBoxProps & import("react").RefAttributes<HTMLDivElement>) => React.ReactElement | null;
|
|
22
22
|
}, keyof import("react").Component<any, {}, any>>;
|
|
23
23
|
export declare const GrowContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never> & Partial<Pick<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>>> & string;
|
package/modal/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const Modal: (({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, ...otherProps }: import("./types").ModalProps) => JSX.Element) & {
|
|
1
|
+
export declare const Modal: (({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, disableScrollRestore, ...otherProps }: import("./types").ModalProps) => JSX.Element) & {
|
|
2
2
|
Box: (props: import("./types").ModalBoxProps & import("react").RefAttributes<HTMLDivElement>) => React.ReactElement | null;
|
|
3
3
|
};
|
|
4
4
|
export * from "./types";
|
package/modal/modal.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ModalProps } from "./types";
|
|
2
|
-
export declare const Modal: ({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, ...otherProps }: ModalProps) => JSX.Element;
|
|
2
|
+
export declare const Modal: ({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, disableScrollRestore, ...otherProps }: ModalProps) => JSX.Element;
|
package/modal/modal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__rest as e}from"../_virtual/_tslib.js";import{jsx as r}from"react/jsx-runtime";import o,{useRef as i}from"react";import{Overlay as t}from"../overlay/overlay.js";import{useViewport as l}from"../shared/hooks/useViewport.js";import"../util/calendar-helper.js";import"../util/date-helper.js";import"../util/date-input-helper.js";import"../util/file-helper.js";import"../util/simple-id-generator.js";import"../util/string-helper.js";import"@react-aria/live-announcer";import{useEvent as a}from"../util/use-event.js";import{Container as n}from"./modal.styles.js";const
|
|
1
|
+
import{__rest as e}from"../_virtual/_tslib.js";import{jsx as r}from"react/jsx-runtime";import o,{useRef as i}from"react";import{Overlay as t}from"../overlay/overlay.js";import{useViewport as l}from"../shared/hooks/useViewport.js";import"../util/calendar-helper.js";import"../util/date-helper.js";import"../util/date-input-helper.js";import"../util/file-helper.js";import"../util/simple-id-generator.js";import"../util/string-helper.js";import"@react-aria/live-announcer";import{useEvent as a}from"../util/use-event.js";import{Container as n}from"./modal.styles.js";const s=s=>{var{id:m="modal",show:d,animationFrom:c="bottom",children:p,enableOverlayClick:v=!0,rootComponentId:h,zIndex:u,onOverlayClick:y,dismissKeyboardOnShow:b=!0,disableScrollRestore:j}=s,f=e(s,["id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","disableScrollRestore"]);const O=a(()=>{var e,r;b&&(null===(r=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===r||r.call(e))}),{verticalHeight:C,ready:k}=l({enabled:d,onBeforeStart:O}),w=i(null),I=p&&o.cloneElement(p,{ref:w});return r(t,{"data-testid":`${m}-overlay`,show:d,enableOverlayClick:v,onOverlayClick:y,id:m,rootId:h,containerRef:w,zIndex:u,disableScrollRestore:j,children:r(n,Object.assign({$show:d,$ready:k,$animationFrom:c,"data-testid":m,$verticalHeight:C},f,{children:I}))})};export{s as Modal};
|
|
2
2
|
//# sourceMappingURL=modal.js.map
|
package/modal/modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.js","sources":["../../src/modal/modal.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { Container } from \"./modal.styles\";\nimport { ModalProps } from \"./types\";\n\nexport const Modal = ({\n id = \"modal\",\n show,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n ...otherProps\n}: ModalProps): JSX.Element => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight, ready } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =============================================================================\n // RENDER FUNCTIONS\n // =============================================================================\n return (\n <Overlay\n data-testid={`${id}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n >\n <Container\n $show={show}\n $ready={ready}\n $animationFrom={animationFrom}\n data-testid={id}\n $verticalHeight={verticalHeight}\n {...otherProps}\n >\n {childWithRef}\n </Container>\n </Overlay>\n );\n};\n"],"names":["Modal","_a","id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","ready","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$show","$ready","$verticalHeight"],"mappings":"qjBAOO,MAAMA,EAASC,IAAA,IAAAC,GAClBA,EAAK,QAAOC,KACZA,EAAIC,cACJA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,
|
|
1
|
+
{"version":3,"file":"modal.js","sources":["../../src/modal/modal.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { Container } from \"./modal.styles\";\nimport { ModalProps } from \"./types\";\n\nexport const Modal = ({\n id = \"modal\",\n show,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n disableScrollRestore,\n ...otherProps\n}: ModalProps): JSX.Element => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight, ready } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =============================================================================\n // RENDER FUNCTIONS\n // =============================================================================\n return (\n <Overlay\n data-testid={`${id}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n disableScrollRestore={disableScrollRestore}\n >\n <Container\n $show={show}\n $ready={ready}\n $animationFrom={animationFrom}\n data-testid={id}\n $verticalHeight={verticalHeight}\n {...otherProps}\n >\n {childWithRef}\n </Container>\n </Overlay>\n );\n};\n"],"names":["Modal","_a","id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","disableScrollRestore","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","ready","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$show","$ready","$animationFrom","$verticalHeight"],"mappings":"qjBAOO,MAAMA,EAASC,IAAA,IAAAC,GAClBA,EAAK,QAAOC,KACZA,EAAIC,cACJA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,EAAIC,qBAC5BA,GAAoBV,EACjBW,EAAUC,EAAAZ,EAXK,0JAgBlB,MAAMa,EAAkBC,EAAS,aACzBL,YACAM,EAAuC,UAAtCC,SAASC,yBAA6BjB,OAAA,EAAAA,EAAEkB,iCAG3CC,eAAEA,EAAcC,MAAEA,GAAUC,EAAY,CAC1CC,QAASpB,EACTqB,cAAeV,IAEbW,EAAWC,EAAuB,MAClCC,EACFtB,GAAYuB,EAAMC,aAAaxB,EAAU,CAAEyB,IAAKL,IAKpD,OACIM,EAACC,EAAO,CAAA,cACS,GAAG9B,YAChBC,KAAMA,EACNG,mBAAoBA,EACpBG,eAAgBA,EAChBP,GAAIA,EACJ+B,OAAQ1B,EACR2B,aAAcT,EACdjB,OAAQA,EACRG,qBAAsBA,EAAoBN,SAE1C0B,EAACI,EAASC,OAAAC,OAAA,CAAAC,MACCnC,EAAIoC,OACHlB,EAAKmB,eACGpC,EAAa,cAChBF,EAAEuC,gBACErB,GACbR,EAAU,CAAAP,SAEbsB"}
|
package/modal/types.d.ts
CHANGED
|
@@ -15,6 +15,9 @@ export interface ModalProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
15
15
|
onOverlayClick?: (() => void) | undefined;
|
|
16
16
|
/** Dismiss keyboard to keep modal in fullscreen */
|
|
17
17
|
dismissKeyboardOnShow?: boolean | undefined;
|
|
18
|
+
/** Prevents restoring the page's scroll position when the modal closes. Passed to
|
|
19
|
+
* `Overlay`, only has an effect on iOS currently */
|
|
20
|
+
disableScrollRestore?: boolean | undefined;
|
|
18
21
|
}
|
|
19
22
|
export interface ModalBoxProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
20
23
|
children: React.ReactNode;
|
package/modal-v2/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const ModalV2: (({ id, show, onClose, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, "data-testid": testId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, disableInitialFocus, ...otherProps }: import("./types").ModalV2Props) => JSX.Element) & {
|
|
1
|
+
export declare const ModalV2: (({ id, show, onClose, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, "data-testid": testId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, disableInitialFocus, disableScrollRestore, ...otherProps }: import("./types").ModalV2Props) => JSX.Element) & {
|
|
2
2
|
Card: (props: import("./types").ModalCardProps & import("react").RefAttributes<HTMLDivElement>) => React.ReactElement | null;
|
|
3
3
|
CloseButton: {
|
|
4
4
|
({ "data-testid": testId, ...otherProps }: import("./types").ModalCloseButtonProps): import("react/jsx-runtime").JSX.Element;
|
package/modal-v2/modal-v2.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ModalV2Props } from "./types";
|
|
2
|
-
export declare const ModalV2: ({ id, show, onClose, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, "data-testid": testId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, disableInitialFocus, ...otherProps }: ModalV2Props) => JSX.Element;
|
|
2
|
+
export declare const ModalV2: ({ id, show, onClose, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, "data-testid": testId, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, disableInitialFocus, disableScrollRestore, ...otherProps }: ModalV2Props) => JSX.Element;
|
package/modal-v2/modal-v2.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__rest as e}from"../_virtual/_tslib.js";import{jsx as i}from"react/jsx-runtime";import{useFloating as r,useTransitionStatus as o,useDismiss as
|
|
1
|
+
import{__rest as e}from"../_virtual/_tslib.js";import{jsx as i}from"react/jsx-runtime";import{useFloating as r,useTransitionStatus as o,useDismiss as l,useInteractions as t,FloatingFocusManager as a}from"@floating-ui/react";import n,{useRef as s}from"react";import{Overlay as d}from"../overlay/overlay.js";import{useViewport as m}from"../shared/hooks/useViewport.js";import"../util/calendar-helper.js";import"../util/date-helper.js";import"../util/date-input-helper.js";import"../util/file-helper.js";import"../util/simple-id-generator.js";import"../util/string-helper.js";import"@react-aria/live-announcer";import{useEvent as c}from"../util/use-event.js";import{ModalContext as b}from"./modal-context.js";import{Container as p,ScrollContainer as u,ModalContainer as h}from"./modal-v2.styles.js";const v=v=>{var{id:y,show:f,onClose:j,animationFrom:g="bottom",children:C,enableOverlayClick:O=!0,rootComponentId:x,zIndex:F,onOverlayClick:I,dismissKeyboardOnShow:k=!0,"data-testid":w="modal","aria-label":S,"aria-labelledby":R,"aria-describedby":z,disableInitialFocus:P=!1,disableScrollRestore:$}=v,E=e(v,["id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","data-testid","aria-label","aria-labelledby","aria-describedby","disableInitialFocus","disableScrollRestore"]);const H=c(()=>{var e,i;k&&(null===(i=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===i||i.call(e))}),{verticalHeight:K}=m({enabled:f,onBeforeStart:H}),_=s(null),B=C&&n.cloneElement(C,{ref:_}),{refs:M,context:V}=r({open:f,onOpenChange:e=>{e||null==j||j()}}),{isMounted:q,status:A}=o(V,{duration:300}),D=l(V,{outsidePress:!1,enabled:!!j}),{getFloatingProps:G}=t([D]);return i(d,{"data-testid":`${w}-overlay`,show:f,enableOverlayClick:O,onOverlayClick:I,id:y,rootId:x,containerRef:_,zIndex:F,disableScrollRestore:$,children:i(p,Object.assign({$animationFrom:g,"data-testid":w,$verticalHeight:K,"data-status":A},E,{children:i(b.Provider,{value:{onClose:j},children:q&&i(a,{context:V,initialFocus:P?-1:M.floating,children:i(u,{children:i(h,Object.assign({ref:M.setFloating},G(),{role:"dialog","aria-label":S,"aria-labelledby":R,"aria-describedby":z,children:B}))})})})}))})};export{v as ModalV2};
|
|
2
2
|
//# sourceMappingURL=modal-v2.js.map
|
package/modal-v2/modal-v2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal-v2.js","sources":["../../src/modal-v2/modal-v2.tsx"],"sourcesContent":["import {\n FloatingFocusManager,\n useDismiss,\n useFloating,\n useInteractions,\n useTransitionStatus,\n} from \"@floating-ui/react\";\nimport React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { ModalContext } from \"./modal-context\";\nimport { Container, ModalContainer, ScrollContainer } from \"./modal-v2.styles\";\nimport { ModalV2Props } from \"./types\";\n\nexport const ModalV2 = ({\n id,\n show,\n onClose,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n \"data-testid\": testId = \"modal\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n disableInitialFocus = false,\n ...otherProps\n}: ModalV2Props): JSX.Element => {\n // =========================================================================\n // CONST, STATE, REF\n // =========================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =========================================================================\n // FLOATING UI CONFIG\n // =========================================================================\n const { refs, context } = useFloating({\n open: show,\n onOpenChange: (isOpen) => {\n if (!isOpen) {\n onClose?.();\n }\n },\n });\n const { isMounted, status } = useTransitionStatus(context, {\n duration: 300,\n });\n const dismiss = useDismiss(context, {\n /* handled by overlayclick */\n outsidePress: false,\n enabled: !!onClose,\n });\n const { getFloatingProps } = useInteractions([dismiss]);\n\n // =========================================================================\n // RENDER FUNCTIONS\n // =========================================================================\n return (\n <Overlay\n data-testid={`${testId}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n >\n <Container\n $animationFrom={animationFrom}\n data-testid={testId}\n $verticalHeight={verticalHeight}\n data-status={status}\n {...otherProps}\n >\n <ModalContext.Provider value={{ onClose }}>\n {isMounted && (\n <FloatingFocusManager\n context={context}\n initialFocus={\n disableInitialFocus ? -1 : refs.floating\n }\n >\n <ScrollContainer>\n <ModalContainer\n ref={refs.setFloating}\n {...getFloatingProps()}\n role=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n >\n {childWithRef}\n </ModalContainer>\n </ScrollContainer>\n </FloatingFocusManager>\n )}\n </ModalContext.Provider>\n </Container>\n </Overlay>\n );\n};\n"],"names":["ModalV2","_a","id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","testId","ariaLabel","ariaLabelledBy","ariaDescribedBy","disableInitialFocus","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","refs","context","useFloating","open","onOpenChange","isOpen","isMounted","status","useTransitionStatus","duration","dismiss","useDismiss","outsidePress","getFloatingProps","useInteractions","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$animationFrom","$verticalHeight","ModalContext","Provider","value","FloatingFocusManager","initialFocus","floating","ScrollContainer","ModalContainer","setFloating","role"],"mappings":"4xBAeO,MAAMA,EAAWC,QAAAC,GACpBA,EAAEC,KACFA,EAAIC,QACJA,EAAOC,cACPA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,EACxB,cAAeC,EAAS,QACxB,aAAcC,EACd,kBAAmBC,EACnB,mBAAoBC,EAAeC,oBACnCA,GAAsB,
|
|
1
|
+
{"version":3,"file":"modal-v2.js","sources":["../../src/modal-v2/modal-v2.tsx"],"sourcesContent":["import {\n FloatingFocusManager,\n useDismiss,\n useFloating,\n useInteractions,\n useTransitionStatus,\n} from \"@floating-ui/react\";\nimport React, { useRef } from \"react\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useEvent } from \"../util\";\nimport { ModalContext } from \"./modal-context\";\nimport { Container, ModalContainer, ScrollContainer } from \"./modal-v2.styles\";\nimport { ModalV2Props } from \"./types\";\n\nexport const ModalV2 = ({\n id,\n show,\n onClose,\n animationFrom = \"bottom\",\n children,\n enableOverlayClick = true,\n rootComponentId,\n zIndex,\n onOverlayClick,\n dismissKeyboardOnShow = true,\n \"data-testid\": testId = \"modal\",\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n disableInitialFocus = false,\n disableScrollRestore,\n ...otherProps\n}: ModalV2Props): JSX.Element => {\n // =========================================================================\n // CONST, STATE, REF\n // =========================================================================\n const dismissKeyboard = useEvent(() => {\n if (dismissKeyboardOnShow) {\n (document.activeElement as HTMLElement)?.blur?.();\n }\n });\n const { verticalHeight } = useViewport({\n enabled: show,\n onBeforeStart: dismissKeyboard,\n });\n const childRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n // =========================================================================\n // FLOATING UI CONFIG\n // =========================================================================\n const { refs, context } = useFloating({\n open: show,\n onOpenChange: (isOpen) => {\n if (!isOpen) {\n onClose?.();\n }\n },\n });\n const { isMounted, status } = useTransitionStatus(context, {\n duration: 300,\n });\n const dismiss = useDismiss(context, {\n /* handled by overlayclick */\n outsidePress: false,\n enabled: !!onClose,\n });\n const { getFloatingProps } = useInteractions([dismiss]);\n\n // =========================================================================\n // RENDER FUNCTIONS\n // =========================================================================\n return (\n <Overlay\n data-testid={`${testId}-overlay`}\n show={show}\n enableOverlayClick={enableOverlayClick}\n onOverlayClick={onOverlayClick}\n id={id}\n rootId={rootComponentId}\n containerRef={childRef}\n zIndex={zIndex}\n disableScrollRestore={disableScrollRestore}\n >\n <Container\n $animationFrom={animationFrom}\n data-testid={testId}\n $verticalHeight={verticalHeight}\n data-status={status}\n {...otherProps}\n >\n <ModalContext.Provider value={{ onClose }}>\n {isMounted && (\n <FloatingFocusManager\n context={context}\n initialFocus={\n disableInitialFocus ? -1 : refs.floating\n }\n >\n <ScrollContainer>\n <ModalContainer\n ref={refs.setFloating}\n {...getFloatingProps()}\n role=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n >\n {childWithRef}\n </ModalContainer>\n </ScrollContainer>\n </FloatingFocusManager>\n )}\n </ModalContext.Provider>\n </Container>\n </Overlay>\n );\n};\n"],"names":["ModalV2","_a","id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","testId","ariaLabel","ariaLabelledBy","ariaDescribedBy","disableInitialFocus","disableScrollRestore","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","useViewport","enabled","onBeforeStart","childRef","useRef","childWithRef","React","cloneElement","ref","refs","context","useFloating","open","onOpenChange","isOpen","isMounted","status","useTransitionStatus","duration","dismiss","useDismiss","outsidePress","getFloatingProps","useInteractions","_jsx","Overlay","rootId","containerRef","Container","Object","assign","$animationFrom","$verticalHeight","ModalContext","Provider","value","FloatingFocusManager","initialFocus","floating","ScrollContainer","ModalContainer","setFloating","role"],"mappings":"4xBAeO,MAAMA,EAAWC,QAAAC,GACpBA,EAAEC,KACFA,EAAIC,QACJA,EAAOC,cACPA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,EACxB,cAAeC,EAAS,QACxB,aAAcC,EACd,kBAAmBC,EACnB,mBAAoBC,EAAeC,oBACnCA,GAAsB,EAAKC,qBAC3BA,GAAoBhB,EACjBiB,EAAUC,EA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package/modal-v2/types.d.ts
CHANGED
|
@@ -35,4 +35,7 @@ export interface ModalV2Props extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
35
35
|
dismissKeyboardOnShow?: boolean | undefined;
|
|
36
36
|
/** Disable initial focus on the modal when it is shown */
|
|
37
37
|
disableInitialFocus?: boolean | undefined;
|
|
38
|
+
/** Prevents restoring the page's scroll position when the modal closes. Passed to
|
|
39
|
+
* `Overlay`, only has an effect on iOS currently */
|
|
40
|
+
disableScrollRestore?: boolean | undefined;
|
|
38
41
|
}
|
package/overlay/overlay.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as t}from"react/jsx-runtime";import{FloatingTree as e,useFloatingNodeId as o,FloatingNode as n}from"@floating-ui/react";import{useState as r,useRef as
|
|
1
|
+
import{jsx as t}from"react/jsx-runtime";import{FloatingTree as e,useFloatingNodeId as o,FloatingNode as n}from"@floating-ui/react";import{useState as r,useRef as l,useEffect as i}from"react";import d from"react-dom";import"../util/calendar-helper.js";import"../util/date-helper.js";import"../util/date-input-helper.js";import"../util/file-helper.js";import{useId as s}from"../util/simple-id-generator.js";import"../util/string-helper.js";import"@react-aria/live-announcer";import{Root as c,Wrapper as a}from"./overlay.styles.js";import{useFloatingParent as u}from"./use-floating-context.js";const m=({show:e=!1,rootId:m,onOverlayClick:y,children:b,backgroundOpacity:h,backgroundBlur:w=!0,disableTransition:j=!1,enableOverlayClick:$=!1,zIndex:O,id:k,containerRef:L,disableScrollRestore:x=!1})=>{const[T,P]=r(null),[E,I]=r(),B=s(),C=o(),D=l(),z=l(!1),A=l(null),F=l(x),R=k?`lifesg-ds-overlay-root-${k}`:"lifesg-ds-overlay-root",W=null!=O?O:E?99999:99998;u(W),i(()=>(V(),P(M()),()=>{K(),G().length<1&&(H()&&(N("remove"),U()),Y("remove"))}),[]),i(()=>{e&&(F.current=x)},[e,x]),i(()=>{if(e){const t=S();q(t),J(),H()&&1===G().length&&(Q(),N("add"));const e=setTimeout(()=>{Y("add")},200);return()=>clearTimeout(e)}{K(),H()&&G().length<1&&(N("remove"),U());const t=setTimeout(()=>{G().length<1&&Y("remove")},200);return()=>clearTimeout(t)}},[e]),i(()=>{if(e)return document.addEventListener("mousedown",X,!0),()=>{document.removeEventListener("mousedown",X,!0)}},[e]);const q=t=>{D.current=t,I(t)},H=()=>/(iPad|iPhone|iPod)/g.test(navigator.userAgent),M=()=>document&&m?document.getElementById(m):document?document.body:null,S=()=>G().length>0,V=()=>{if(!document.getElementById(p)){const t=document.createElement("style");t.id=p;const e=document.documentElement.clientWidth,o=window.innerWidth-e;t.innerHTML=`\n\t\t\t\t.${v} {\n\t\t\t\t\toverflow: hidden;\n\t\t\t\t\tpadding-right: ${o}px !important;\n\t\t\t\t\t-ms-overflow-style: none;\n\t\t\t\t\tscrollbar-width: none;\n\t\t\t\t}\n\n\t\t\t\t.${v}::-webkit-scrollbar {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\n\t\t\t\t.${f} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: var(${g}, 0);\n\t\t\t\t\tbottom: 0;\n\t\t\t\t}\n\t\t\t`,document.body.appendChild(t)}},Y=t=>{const e=document.body.classList.contains(v);"add"!==t||e?"remove"===t&&e&&document.body.classList.remove(v):document.body.classList.add(v)},G=()=>{const t=document.body.dataset.lifesgDsOverlayOrder;return t?t.split(","):[]},J=()=>{const t=G();document.body.dataset.lifesgDsOverlayOrder=[...t,B].join(",")},K=()=>{const t=G();document.body.dataset.lifesgDsOverlayOrder=t.filter(t=>t!==B).join(",")},N=t=>{if(!H())return;const e=document.body.classList.contains(f);"add"!==t||e?"remove"===t&&e&&document.body.classList.remove(f):document.body.classList.add(f)},Q=()=>{const t=document.body.style,e=t.top?t.top:window.scrollY+"px";document.body.style.setProperty(g,e)},U=()=>{if(!H())return;const t=document.body.style.getPropertyValue(g);document.body.style.removeProperty(g),t&&!F.current&&requestAnimationFrame(()=>{window.scrollTo({top:parseFloat(t)})})},X=t=>{var e;const o=null!==(e=null==L?void 0:L.current)&&void 0!==e?e:A.current,n=A.current;if(!o)return void(z.current=!1);const r=t.target,l=n===r,i=o===r,d=o.contains(r);z.current=!l&&(i||d)},Z=t=>{var e;const o=null!==(e=null==L?void 0:L.current)&&void 0!==e?e:A.current,n=A.current;if(!o)return void(z.current=!1);const r=t.target,l=n===r,i=o===r,d=o.contains(r);!l&&(i||d)||z.current||!y||!$||(t.preventDefault(),y()),z.current=!1};return T?d.createPortal(t(c,{id:R,"data-testid":R,$show:e,$zIndex:W,children:b&&t(n,{id:C,children:t(a,{ref:A,"data-testid":"overlay-wrapper",$show:e,$stacked:E,$backgroundBlur:w,$disableTransition:j,onClick:Z,children:b})})}),T):null},y=o=>t(e,{children:t(m,Object.assign({},o))}),p="lifesg-ds-overlay-stylesheet",v="lifesg-ds-overlay-open",f="lifesg-ds-overlay-scroll-lock",g="--lifesg-ds-overlay-scroll-y";export{y as Overlay};
|
|
2
2
|
//# sourceMappingURL=overlay.js.map
|
package/overlay/overlay.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay.js","sources":["../../src/overlay/overlay.tsx"],"sourcesContent":["import {\n FloatingNode,\n FloatingTree,\n useFloatingNodeId,\n} from \"@floating-ui/react\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { useId } from \"../util\";\nimport { Root, Wrapper } from \"./overlay.styles\";\nimport { OverlayProps } from \"./types\";\nimport { useFloatingParent } from \"./use-floating-context\";\n\nconst OverlayComponent = ({\n show = false,\n rootId,\n onOverlayClick,\n children,\n backgroundOpacity: _backgroundOpacity,\n backgroundBlur = true,\n disableTransition = false,\n enableOverlayClick = false,\n zIndex: customZIndex,\n id,\n containerRef,\n}: OverlayProps): JSX.Element | null => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const [rootElement, setRootElement] = useState<HTMLElement | null>(null);\n const [isStacked, _setIsStacked] = useState<boolean>();\n const uid = useId();\n const nodeId = useFloatingNodeId();\n\n const stacked = useRef<boolean>();\n // Track where mousedown started to prevent closing drawer during text selection drag\n const mouseDownInsideModalRef = useRef(false);\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n const overlayRootId = id\n ? `lifesg-ds-overlay-root-${id}`\n : \"lifesg-ds-overlay-root\";\n const zIndex = customZIndex ?? (isStacked ? 99999 : 99998);\n\n useFloatingParent(zIndex);\n\n // =============================================================================\n // EFFECTS\n // =============================================================================\n useEffect(() => {\n addStylesheetForDocumentBody();\n setRootElement(getRootElement());\n\n return () => {\n removeOverlay();\n\n if (getOverlayOrder().length < 1) {\n if (isIOS()) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n applyBodyStyleClass(\"remove\");\n }\n };\n }, []);\n\n useEffect(() => {\n if (show) {\n const isStacked = checkIfStacked();\n setStacked(isStacked);\n\n addOverlay();\n\n if (isIOS() && getOverlayOrder().length === 1) {\n saveScrollPosition();\n applyScrollLockClassForIOS(\"add\");\n }\n\n const timerId = setTimeout(() => {\n applyBodyStyleClass(\"add\");\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n } else {\n removeOverlay();\n\n if (isIOS() && getOverlayOrder().length < 1) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n const timerId = setTimeout(() => {\n if (getOverlayOrder().length < 1) {\n applyBodyStyleClass(\"remove\");\n }\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n }\n }, [show]);\n\n // Track mousedown origin to distinguish clicks from text selection drags\n useEffect(() => {\n if (!show) return;\n\n document.addEventListener(\"mousedown\", handleDocumentMouseDown, true);\n return () => {\n document.removeEventListener(\n \"mousedown\",\n handleDocumentMouseDown,\n true\n );\n };\n }, [show]);\n\n // =============================================================================\n // REF FUNCTIONS\n // =============================================================================\n const setStacked = (data: boolean) => {\n stacked.current = data;\n _setIsStacked(data);\n };\n\n // =============================================================================\n // HELPER FUNCTIONS\n // =============================================================================\n const isIOS = () => /(iPad|iPhone|iPod)/g.test(navigator.userAgent);\n\n const getRootElement = (): HTMLElement | null => {\n if (document && rootId) {\n return document.getElementById(rootId);\n } else if (document) {\n // If rootId not specified, we'll use body\n return document.body;\n } else {\n return null;\n }\n };\n\n const checkIfStacked = () => {\n return getOverlayOrder().length > 0;\n };\n\n const addStylesheetForDocumentBody = () => {\n /**\n * This stylesheet is to manipulate the <body>. We only add once\n */\n if (!document.getElementById(STYLESHEET_ID)) {\n const overlayStyleSheet = document.createElement(\"style\");\n overlayStyleSheet.id = STYLESHEET_ID;\n\n const documentWidth = document.documentElement.clientWidth;\n const windowWidth = window.innerWidth;\n const scrollBarWidth = windowWidth - documentWidth;\n\n overlayStyleSheet.innerHTML = `\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME} {\n\t\t\t\t\toverflow: hidden;\n\t\t\t\t\tpadding-right: ${scrollBarWidth}px !important;\n\t\t\t\t\t-ms-overflow-style: none;\n\t\t\t\t\tscrollbar-width: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME}::-webkit-scrollbar {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_SCROLL_LOCK_CLASSNAME} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: var(${SCROLL_POSITION_VAR}, 0);\n\t\t\t\t\tbottom: 0;\n\t\t\t\t}\n\t\t\t`;\n\n document.body.appendChild(overlayStyleSheet);\n }\n };\n\n /**\n * This sets the style of <body> to hide the scrollbar\n */\n const applyBodyStyleClass = (action: \"add\" | \"remove\") => {\n const isOverlayStyleClassApplied = document.body.classList.contains(\n OVERLAY_OPEN_CLASSNAME\n );\n\n if (action === \"add\" && !isOverlayStyleClassApplied) {\n document.body.classList.add(OVERLAY_OPEN_CLASSNAME);\n } else if (action === \"remove\" && isOverlayStyleClassApplied) {\n document.body.classList.remove(OVERLAY_OPEN_CLASSNAME);\n }\n };\n\n const getOverlayOrder = () => {\n const attr = document.body.dataset.lifesgDsOverlayOrder;\n return attr ? attr.split(\",\") : [];\n };\n\n const addOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = [...order, uid].join(\",\");\n };\n\n const removeOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = order\n .filter((o) => o !== uid)\n .join(\",\");\n };\n\n /**\n * This sets the style of <body> to further prevent scrolling on iOS\n *\n * ref: https://stackoverflow.com/a/57455820/3932279\n * `overflow: hidden` and `overscroll-behavior` is ignored by iOS, this is\n * an alternative solution\n *\n * as a side effect this causes the scroll position to reset, so additional\n * logic to restore the scroll on close is required\n */\n const applyScrollLockClassForIOS = (action: \"add\" | \"remove\") => {\n if (!isIOS()) {\n return;\n }\n\n const isClassApplied = document.body.classList.contains(\n OVERLAY_SCROLL_LOCK_CLASSNAME\n );\n\n if (action === \"add\" && !isClassApplied) {\n document.body.classList.add(OVERLAY_SCROLL_LOCK_CLASSNAME);\n } else if (action === \"remove\" && isClassApplied) {\n document.body.classList.remove(OVERLAY_SCROLL_LOCK_CLASSNAME);\n }\n };\n\n const saveScrollPosition = () => {\n const bodyStyle = document.body.style;\n const scrollY = bodyStyle.top ? bodyStyle.top : window.scrollY + \"px\";\n\n document.body.style.setProperty(SCROLL_POSITION_VAR, scrollY);\n };\n\n const scrollToLastScrollPositionForIOS = () => {\n if (!isIOS()) {\n return;\n }\n\n const scrollY =\n document.body.style.getPropertyValue(SCROLL_POSITION_VAR);\n requestAnimationFrame(() => {\n window.scrollTo({\n top: parseFloat(scrollY),\n });\n });\n };\n\n // =============================================================================\n // EVENT HANDLERS\n // =============================================================================\n const handleDocumentMouseDown = (e: MouseEvent) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = e.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n\n // Track if mousedown started inside modal content\n mouseDownInsideModalRef.current =\n !clickedOnWrapper && (clickedOnContainer || clickedInsideContainer);\n };\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = event.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n const clickedInsideModal = clickedOnContainer || clickedInsideContainer;\n\n // Only close if both mousedown AND click happened outside modal\n if (\n (clickedOnWrapper || !clickedInsideModal) &&\n !mouseDownInsideModalRef.current &&\n onOverlayClick &&\n enableOverlayClick\n ) {\n event.preventDefault();\n onOverlayClick();\n }\n\n mouseDownInsideModalRef.current = false;\n };\n\n // =============================================================================\n // RENDER\n // =============================================================================\n const renderWrapper = () => (\n <FloatingNode id={nodeId}>\n <Wrapper\n ref={wrapperRef}\n data-testid=\"overlay-wrapper\"\n $show={show}\n $stacked={isStacked}\n $backgroundBlur={backgroundBlur}\n $disableTransition={disableTransition}\n onClick={handleWrapperClick}\n >\n {children}\n </Wrapper>\n </FloatingNode>\n );\n\n const renderComponent = () => (\n <Root\n id={overlayRootId}\n data-testid={overlayRootId}\n $show={show}\n $zIndex={zIndex}\n >\n {children && renderWrapper()}\n </Root>\n );\n\n return rootElement\n ? ReactDOM.createPortal(renderComponent(), rootElement)\n : null;\n};\n\nexport const Overlay = (props: OverlayProps) => {\n return (\n <FloatingTree>\n <OverlayComponent {...props} />\n </FloatingTree>\n );\n};\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\nconst STYLESHEET_ID = \"lifesg-ds-overlay-stylesheet\";\nconst OVERLAY_OPEN_CLASSNAME = \"lifesg-ds-overlay-open\";\nconst OVERLAY_SCROLL_LOCK_CLASSNAME = \"lifesg-ds-overlay-scroll-lock\";\nconst SCROLL_POSITION_VAR = \"--lifesg-ds-overlay-scroll-y\";\n"],"names":["OverlayComponent","show","rootId","onOverlayClick","children","backgroundOpacity","_backgroundOpacity","backgroundBlur","disableTransition","enableOverlayClick","zIndex","customZIndex","id","containerRef","rootElement","setRootElement","useState","isStacked","_setIsStacked","uid","useId","nodeId","useFloatingNodeId","stacked","useRef","mouseDownInsideModalRef","wrapperRef","overlayRootId","useFloatingParent","useEffect","addStylesheetForDocumentBody","getRootElement","removeOverlay","getOverlayOrder","length","isIOS","applyScrollLockClassForIOS","scrollToLastScrollPositionForIOS","applyBodyStyleClass","checkIfStacked","setStacked","addOverlay","saveScrollPosition","timerId","setTimeout","clearTimeout","document","addEventListener","handleDocumentMouseDown","removeEventListener","data","current","test","navigator","userAgent","getElementById","body","STYLESHEET_ID","overlayStyleSheet","createElement","documentWidth","documentElement","clientWidth","scrollBarWidth","window","innerWidth","innerHTML","OVERLAY_OPEN_CLASSNAME","OVERLAY_SCROLL_LOCK_CLASSNAME","SCROLL_POSITION_VAR","appendChild","action","isOverlayStyleClassApplied","classList","contains","remove","add","attr","dataset","lifesgDsOverlayOrder","split","order","join","filter","o","isClassApplied","bodyStyle","style","scrollY","top","setProperty","getPropertyValue","requestAnimationFrame","scrollTo","parseFloat","e","container","_a","wrapper","target","clickedOnWrapper","clickedOnContainer","clickedInsideContainer","handleWrapperClick","event","preventDefault","ReactDOM","createPortal","_jsx","Root","$show","$zIndex","FloatingNode","Wrapper","ref","$stacked","$backgroundBlur","$disableTransition","onClick","Overlay","props","FloatingTree","Object","assign"],"mappings":"+kBAYA,MAAMA,EAAmB,EACrBC,QAAO,EACPC,SACAC,iBACAC,WACAC,kBAAmBC,EACnBC,kBAAiB,EACjBC,qBAAoB,EACpBC,sBAAqB,EACrBC,OAAQC,EACRC,KACAC,mBAKA,MAAOC,EAAaC,GAAkBC,EAA6B,OAC5DC,EAAWC,GAAiBF,IAC7BG,EAAMC,IACNC,EAASC,IAETC,EAAUC,IAEVC,EAA0BD,GAAO,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,YADAvE,EAAwB0B,SAAU,GAItC,MAAMgD,EAASJ,EAAEI,OACXC,EAAmBF,IAAYC,EAC/BE,EAAqBL,IAAcG,EACnCG,EAAyBN,EAAUtB,SAASyB,GAGlD1E,EAAwB0B,SACnBiD,IAAqBC,GAAsBC,IAG9CC,EAAsBC,UACxB,MAAMR,EAAiC,QAArBC,EAAApF,aAAY,EAAZA,EAAcsC,eAAO,IAAA8C,EAAAA,EAAIvE,EAAWyB,QAChD+C,EAAUxE,EAAWyB,QAC3B,IAAK6C,EAED,YADAvE,EAAwB0B,SAAU,GAItC,MAAMgD,EAASK,EAAML,OACfC,EAAmBF,IAAYC,EAC/BE,EAAqBL,IAAcG,EACnCG,EAAyBN,EAAUtB,SAASyB,IAK7CC,IAJsBC,GAAsBC,IAK5C7E,EAAwB0B,UACzBhD,IACAM,IAEA+F,EAAMC,iBACNtG,KAGJsB,EAAwB0B,SAAU,GAiCtC,OAAOrC,EACD4F,EAASC,aAXXC,EAACC,EAAI,CACDjG,GAAIe,gBACSA,EAAamF,MACnB7G,EAAI8G,QACFrG,EAAMN,SAEdA,GAtBLwG,EAACI,EAAY,CAACpG,GAAIS,EAAMjB,SACpBwG,EAACK,EAAO,CACJC,IAAKxF,EAAU,cACH,wBACLzB,EAAIkH,SACDlG,EAASmG,gBACF7G,EAAc8G,mBACX7G,EACpB8G,QAASf,EAAkBnG,SAE1BA,QAiBkCU,GACzC,MAGGyG,EAAWC,GAEhBZ,EAACa,EAAY,CAAArH,SACTwG,EAAC5G,EAAgB0H,OAAAC,OAAA,CAAA,EAAKH,MAQ5B/D,EAAgB,+BAChBU,EAAyB,yBACzBC,EAAgC,gCAChCC,EAAsB"}
|
|
1
|
+
{"version":3,"file":"overlay.js","sources":["../../src/overlay/overlay.tsx"],"sourcesContent":["import {\n FloatingNode,\n FloatingTree,\n useFloatingNodeId,\n} from \"@floating-ui/react\";\nimport React, { useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\nimport { useId } from \"../util\";\nimport { Root, Wrapper } from \"./overlay.styles\";\nimport { OverlayProps } from \"./types\";\nimport { useFloatingParent } from \"./use-floating-context\";\n\nconst OverlayComponent = ({\n show = false,\n rootId,\n onOverlayClick,\n children,\n backgroundOpacity: _backgroundOpacity,\n backgroundBlur = true,\n disableTransition = false,\n enableOverlayClick = false,\n zIndex: customZIndex,\n id,\n containerRef,\n disableScrollRestore = false,\n}: OverlayProps): JSX.Element | null => {\n // =============================================================================\n // CONST, STATE, REF\n // =============================================================================\n const [rootElement, setRootElement] = useState<HTMLElement | null>(null);\n const [isStacked, _setIsStacked] = useState<boolean>();\n const uid = useId();\n const nodeId = useFloatingNodeId();\n\n const stacked = useRef<boolean>();\n // Track where mousedown started to prevent closing drawer during text selection drag\n const mouseDownInsideModalRef = useRef(false);\n const wrapperRef = useRef<HTMLDivElement>(null);\n // Value from the last render while shown, as consumers may reset it on close\n const disableScrollRestoreRef = useRef(disableScrollRestore);\n\n const overlayRootId = id\n ? `lifesg-ds-overlay-root-${id}`\n : \"lifesg-ds-overlay-root\";\n const zIndex = customZIndex ?? (isStacked ? 99999 : 99998);\n\n useFloatingParent(zIndex);\n\n // =============================================================================\n // EFFECTS\n // =============================================================================\n useEffect(() => {\n addStylesheetForDocumentBody();\n setRootElement(getRootElement());\n\n return () => {\n removeOverlay();\n\n if (getOverlayOrder().length < 1) {\n if (isIOS()) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n applyBodyStyleClass(\"remove\");\n }\n };\n }, []);\n\n // Declared before the [show] effect so the ref is up to date when it runs\n useEffect(() => {\n if (show) {\n disableScrollRestoreRef.current = disableScrollRestore;\n }\n }, [show, disableScrollRestore]);\n\n useEffect(() => {\n if (show) {\n const isStacked = checkIfStacked();\n setStacked(isStacked);\n\n addOverlay();\n\n if (isIOS() && getOverlayOrder().length === 1) {\n saveScrollPosition();\n applyScrollLockClassForIOS(\"add\");\n }\n\n const timerId = setTimeout(() => {\n applyBodyStyleClass(\"add\");\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n } else {\n removeOverlay();\n\n if (isIOS() && getOverlayOrder().length < 1) {\n applyScrollLockClassForIOS(\"remove\");\n scrollToLastScrollPositionForIOS();\n }\n\n const timerId = setTimeout(() => {\n if (getOverlayOrder().length < 1) {\n applyBodyStyleClass(\"remove\");\n }\n }, 200); // Allow overlay animations to complete\n\n return () => clearTimeout(timerId);\n }\n }, [show]);\n\n // Track mousedown origin to distinguish clicks from text selection drags\n useEffect(() => {\n if (!show) return;\n\n document.addEventListener(\"mousedown\", handleDocumentMouseDown, true);\n return () => {\n document.removeEventListener(\n \"mousedown\",\n handleDocumentMouseDown,\n true\n );\n };\n }, [show]);\n\n // =============================================================================\n // REF FUNCTIONS\n // =============================================================================\n const setStacked = (data: boolean) => {\n stacked.current = data;\n _setIsStacked(data);\n };\n\n // =============================================================================\n // HELPER FUNCTIONS\n // =============================================================================\n const isIOS = () => /(iPad|iPhone|iPod)/g.test(navigator.userAgent);\n\n const getRootElement = (): HTMLElement | null => {\n if (document && rootId) {\n return document.getElementById(rootId);\n } else if (document) {\n // If rootId not specified, we'll use body\n return document.body;\n } else {\n return null;\n }\n };\n\n const checkIfStacked = () => {\n return getOverlayOrder().length > 0;\n };\n\n const addStylesheetForDocumentBody = () => {\n /**\n * This stylesheet is to manipulate the <body>. We only add once\n */\n if (!document.getElementById(STYLESHEET_ID)) {\n const overlayStyleSheet = document.createElement(\"style\");\n overlayStyleSheet.id = STYLESHEET_ID;\n\n const documentWidth = document.documentElement.clientWidth;\n const windowWidth = window.innerWidth;\n const scrollBarWidth = windowWidth - documentWidth;\n\n overlayStyleSheet.innerHTML = `\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME} {\n\t\t\t\t\toverflow: hidden;\n\t\t\t\t\tpadding-right: ${scrollBarWidth}px !important;\n\t\t\t\t\t-ms-overflow-style: none;\n\t\t\t\t\tscrollbar-width: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_OPEN_CLASSNAME}::-webkit-scrollbar {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\n\t\t\t\t.${OVERLAY_SCROLL_LOCK_CLASSNAME} {\n\t\t\t\t\tposition: fixed;\n\t\t\t\t\ttop: var(${SCROLL_POSITION_VAR}, 0);\n\t\t\t\t\tbottom: 0;\n\t\t\t\t}\n\t\t\t`;\n\n document.body.appendChild(overlayStyleSheet);\n }\n };\n\n /**\n * This sets the style of <body> to hide the scrollbar\n */\n const applyBodyStyleClass = (action: \"add\" | \"remove\") => {\n const isOverlayStyleClassApplied = document.body.classList.contains(\n OVERLAY_OPEN_CLASSNAME\n );\n\n if (action === \"add\" && !isOverlayStyleClassApplied) {\n document.body.classList.add(OVERLAY_OPEN_CLASSNAME);\n } else if (action === \"remove\" && isOverlayStyleClassApplied) {\n document.body.classList.remove(OVERLAY_OPEN_CLASSNAME);\n }\n };\n\n const getOverlayOrder = () => {\n const attr = document.body.dataset.lifesgDsOverlayOrder;\n return attr ? attr.split(\",\") : [];\n };\n\n const addOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = [...order, uid].join(\",\");\n };\n\n const removeOverlay = () => {\n const order = getOverlayOrder();\n document.body.dataset.lifesgDsOverlayOrder = order\n .filter((o) => o !== uid)\n .join(\",\");\n };\n\n /**\n * This sets the style of <body> to further prevent scrolling on iOS\n *\n * ref: https://stackoverflow.com/a/57455820/3932279\n * `overflow: hidden` and `overscroll-behavior` is ignored by iOS, this is\n * an alternative solution\n *\n * as a side effect this causes the scroll position to reset, so additional\n * logic to restore the scroll on close is required\n */\n const applyScrollLockClassForIOS = (action: \"add\" | \"remove\") => {\n if (!isIOS()) {\n return;\n }\n\n const isClassApplied = document.body.classList.contains(\n OVERLAY_SCROLL_LOCK_CLASSNAME\n );\n\n if (action === \"add\" && !isClassApplied) {\n document.body.classList.add(OVERLAY_SCROLL_LOCK_CLASSNAME);\n } else if (action === \"remove\" && isClassApplied) {\n document.body.classList.remove(OVERLAY_SCROLL_LOCK_CLASSNAME);\n }\n };\n\n const saveScrollPosition = () => {\n const bodyStyle = document.body.style;\n const scrollY = bodyStyle.top ? bodyStyle.top : window.scrollY + \"px\";\n\n document.body.style.setProperty(SCROLL_POSITION_VAR, scrollY);\n };\n\n const scrollToLastScrollPositionForIOS = () => {\n if (!isIOS()) {\n return;\n }\n\n const scrollY =\n document.body.style.getPropertyValue(SCROLL_POSITION_VAR);\n document.body.style.removeProperty(SCROLL_POSITION_VAR);\n\n if (!scrollY || disableScrollRestoreRef.current) {\n return;\n }\n\n requestAnimationFrame(() => {\n window.scrollTo({\n top: parseFloat(scrollY),\n });\n });\n };\n\n // =============================================================================\n // EVENT HANDLERS\n // =============================================================================\n const handleDocumentMouseDown = (e: MouseEvent) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = e.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n\n // Track if mousedown started inside modal content\n mouseDownInsideModalRef.current =\n !clickedOnWrapper && (clickedOnContainer || clickedInsideContainer);\n };\n\n const handleWrapperClick = (event: React.MouseEvent<HTMLDivElement>) => {\n const container = containerRef?.current ?? wrapperRef.current;\n const wrapper = wrapperRef.current;\n if (!container) {\n mouseDownInsideModalRef.current = false;\n return;\n }\n\n const target = event.target as Node;\n const clickedOnWrapper = wrapper === target;\n const clickedOnContainer = container === target;\n const clickedInsideContainer = container.contains(target);\n const clickedInsideModal = clickedOnContainer || clickedInsideContainer;\n\n // Only close if both mousedown AND click happened outside modal\n if (\n (clickedOnWrapper || !clickedInsideModal) &&\n !mouseDownInsideModalRef.current &&\n onOverlayClick &&\n enableOverlayClick\n ) {\n event.preventDefault();\n onOverlayClick();\n }\n\n mouseDownInsideModalRef.current = false;\n };\n\n // =============================================================================\n // RENDER\n // =============================================================================\n const renderWrapper = () => (\n <FloatingNode id={nodeId}>\n <Wrapper\n ref={wrapperRef}\n data-testid=\"overlay-wrapper\"\n $show={show}\n $stacked={isStacked}\n $backgroundBlur={backgroundBlur}\n $disableTransition={disableTransition}\n onClick={handleWrapperClick}\n >\n {children}\n </Wrapper>\n </FloatingNode>\n );\n\n const renderComponent = () => (\n <Root\n id={overlayRootId}\n data-testid={overlayRootId}\n $show={show}\n $zIndex={zIndex}\n >\n {children && renderWrapper()}\n </Root>\n );\n\n return rootElement\n ? ReactDOM.createPortal(renderComponent(), rootElement)\n : null;\n};\n\nexport const Overlay = (props: OverlayProps) => {\n return (\n <FloatingTree>\n <OverlayComponent {...props} />\n </FloatingTree>\n );\n};\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\nconst STYLESHEET_ID = \"lifesg-ds-overlay-stylesheet\";\nconst OVERLAY_OPEN_CLASSNAME = \"lifesg-ds-overlay-open\";\nconst OVERLAY_SCROLL_LOCK_CLASSNAME = \"lifesg-ds-overlay-scroll-lock\";\nconst SCROLL_POSITION_VAR = \"--lifesg-ds-overlay-scroll-y\";\n"],"names":["OverlayComponent","show","rootId","onOverlayClick","children","backgroundOpacity","_backgroundOpacity","backgroundBlur","disableTransition","enableOverlayClick","zIndex","customZIndex","id","containerRef","disableScrollRestore","rootElement","setRootElement","useState","isStacked","_setIsStacked","uid","useId","nodeId","useFloatingNodeId","stacked","useRef","mouseDownInsideModalRef","wrapperRef","disableScrollRestoreRef","overlayRootId","useFloatingParent","useEffect","addStylesheetForDocumentBody","getRootElement","removeOverlay","getOverlayOrder","length","isIOS","applyScrollLockClassForIOS","scrollToLastScrollPositionForIOS","applyBodyStyleClass","current","checkIfStacked","setStacked","addOverlay","saveScrollPosition","timerId","setTimeout","clearTimeout","document","addEventListener","handleDocumentMouseDown","removeEventListener","data","test","navigator","userAgent","getElementById","body","STYLESHEET_ID","overlayStyleSheet","createElement","documentWidth","documentElement","clientWidth","scrollBarWidth","window","innerWidth","innerHTML","OVERLAY_OPEN_CLASSNAME","OVERLAY_SCROLL_LOCK_CLASSNAME","SCROLL_POSITION_VAR","appendChild","action","isOverlayStyleClassApplied","classList","contains","remove","add","attr","dataset","lifesgDsOverlayOrder","split","order","join","filter","o","isClassApplied","bodyStyle","style","scrollY","top","setProperty","getPropertyValue","removeProperty","requestAnimationFrame","scrollTo","parseFloat","e","container","_a","wrapper","target","clickedOnWrapper","clickedOnContainer","clickedInsideContainer","handleWrapperClick","event","preventDefault","ReactDOM","createPortal","_jsx","Root","$show","$zIndex","FloatingNode","Wrapper","ref","$stacked","$backgroundBlur","$disableTransition","onClick","Overlay","props","FloatingTree","Object","assign"],"mappings":"+kBAYA,MAAMA,EAAmB,EACrBC,QAAO,EACPC,SACAC,iBACAC,WACAC,kBAAmBC,EACnBC,kBAAiB,EACjBC,qBAAoB,EACpBC,sBAAqB,EACrBC,OAAQC,EACRC,KACAC,eACAC,wBAAuB,MAKvB,MAAOC,EAAaC,GAAkBC,EAA6B,OAC5DC,EAAWC,GAAiBF,IAC7BG,EAAMC,IACNC,EAASC,IAETC,EAAUC,IAEVC,EAA0BD,GAAO,GACjCE,EAAaF,EAAuB,MAEpCG,EAA0BH,EAAOX,GAEjCe,EAAgBjB,EAChB,0BAA0BA,IAC1B,yBACAF,EAASC,QAAAA,EAAiBO,EAAY,MAAQ,MAEpDY,EAAkBpB,GAKlBqB,EAAU,KACNC,IACAhB,EAAeiB,KAER,KACHC,IAEIC,IAAkBC,OAAS,IACvBC,MACAC,EAA2B,UAC3BC,KAGJC,EAAoB,aAG7B,IAGHT,EAAU,KACF9B,IACA2B,EAAwBa,QAAU3B,IAEvC,CAACb,EAAMa,IAEViB,EAAU,KACN,GAAI9B,EAAM,CACN,MAAMiB,EAAYwB,IAClBC,EAAWzB,GAEX0B,IAEIP,KAAwC,IAA7BF,IAAkBC,SAC7BS,IACAP,EAA2B,QAG/B,MAAMQ,EAAUC,WAAW,KACvBP,EAAoB,QACrB,KAEH,MAAO,IAAMQ,aAAaF,EAC9B,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AAmBF,IAAYC,EAC/BE,EAAqBL,IAAcG,EACnCG,EAAyBN,EAAUvB,SAAS0B,IAK7CC,IAJsBC,GAAsBC,IAK5C/E,EAAwBe,UACzBtC,IACAM,IAEAkG,EAAMC,iBACNzG,KAGJuB,EAAwBe,SAAU,GAiCtC,OAAO1B,EACD8F,EAASC,aAXXC,EAACC,EAAI,CACDpG,GAAIiB,gBACSA,EAAaoF,MACnBhH,EAAIiH,QACFxG,EAAMN,SAEdA,GAtBL2G,EAACI,EAAY,CAACvG,GAAIU,EAAMlB,SACpB2G,EAACK,EAAO,CACJC,IAAK1F,EAAU,cACH,wBACL1B,EAAIqH,SACDpG,EAASqG,gBACFhH,EAAciH,mBACXhH,EACpBiH,QAASf,EAAkBtG,SAE1BA,QAiBkCW,GACzC,MAGG2G,EAAWC,GAEhBZ,EAACa,EAAY,CAAAxH,SACT2G,EAAC/G,EAAgB6H,OAAAC,OAAA,CAAA,EAAKH,MAQ5BhE,EAAgB,+BAChBU,EAAyB,yBACzBC,EAAgC,gCAChCC,EAAsB"}
|
package/overlay/types.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface OverlayProps {
|
|
|
13
13
|
id?: string | undefined;
|
|
14
14
|
/** The container that defines the boundaries for overlay click detection */
|
|
15
15
|
containerRef?: React.RefObject<HTMLElement> | undefined;
|
|
16
|
+
/** Prevents restoring the page's scroll position when the overlay closes. Only has an effect
|
|
17
|
+
* on iOS currently. Uses the value from the last render while `show` is `true` */
|
|
18
|
+
disableScrollRestore?: boolean | undefined;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* @deprecated For library internal use only
|