@lifesg/react-design-system 4.0.0-alpha.15 → 4.0.0-alpha.16

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/modal/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * @deprecated Use `ModalV2` instead, which provides a more composable API, improved scroll behaviour, and proper accessibility.
11
11
  * @keywords dialog, overlay, popup
12
12
  */
13
- export declare const Modal: (({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, className, ...otherProps }: import("./types").ModalProps) => JSX.Element) & {
13
+ export declare const Modal: (({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, disableScrollRestore, className, ...otherProps }: import("./types").ModalProps) => JSX.Element) & {
14
14
  /**
15
15
  * A styled content container for use inside `Modal`. Renders an optional
16
16
  * close button and stops click events from propagating to the overlay.
package/modal/modal.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { ModalProps } from "./types";
2
- export declare const Modal: ({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, className, ...otherProps }: ModalProps) => JSX.Element;
2
+ export declare const Modal: ({ id, show, animationFrom, children, enableOverlayClick, rootComponentId, zIndex, onOverlayClick, dismissKeyboardOnShow, disableScrollRestore, className, ...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 t}from"react/jsx-runtime";import o from"clsx";import r,{useRef as i}from"react";import{Overlay as l}from"../overlay/overlay.js";import{useViewport as m}from"../shared/hooks/useViewport.js";import"../theme/theme-provider/index.js";import"../theme/theme-provider/context.js";import"../theme/tokens/border.js";import"../theme/tokens/colour.js";import"../theme/tokens/font.js";import"../theme/tokens/media-query.js";import{useApplyStyle as s}from"../theme/utils/use-apply-styles.js";import"../theme/utils/use-media-query.js";import"../util/calendar-helper.js";import"../external/dayjs/dayjs.min.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 n}from"../util/use-event.js";import{tokens as a,container as d,containerFromRight as p,containerFromLeft as c,containerFromBottom as h,containerFromTop as u,containerFromRightShow as v,containerFromLeftShow as j,containerFromBottomShow as y,containerFromTopShow as f,containerShow as b,containerHide as k}from"./modal.styles.js";const x={top:u,bottom:h,left:c,right:p},O={top:f,bottom:y,left:j,right:v},C=p=>{var{id:c="modal",show:h,animationFrom:u="bottom",children:v,enableOverlayClick:j=!0,rootComponentId:y,zIndex:f,onOverlayClick:C,dismissKeyboardOnShow:g=!0,className:w}=p,I=e(p,["id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","className"]);const z=n((()=>{var e,t;g&&(null===(t=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===t||t.call(e))})),{verticalHeight:N,ready:S}=m({enabled:h,onBeforeStart:z}),q=i(null),E=i(null),F=v&&r.cloneElement(v,{ref:q});return s(E,{[a.container.verticalHeight]:null==N?null:`${N}px`}),t(l,{"data-testid":`${c}-overlay`,show:h,enableOverlayClick:j,onOverlayClick:C,id:c,rootId:y,containerRef:q,zIndex:f,children:t("div",Object.assign({ref:E,"data-testid":c},I,{className:o(d,x[u],h&&S?[O[u],b]:k,w),children:F}))})};export{C as Modal};
1
+ import{__rest as e}from"../_virtual/_tslib.js";import{jsx as t}from"react/jsx-runtime";import o from"clsx";import r,{useRef as i}from"react";import{Overlay as l}from"../overlay/overlay.js";import{useViewport as s}from"../shared/hooks/useViewport.js";import"../theme/theme-provider/index.js";import"../theme/theme-provider/context.js";import"../theme/tokens/border.js";import"../theme/tokens/colour.js";import"../theme/tokens/font.js";import"../theme/tokens/media-query.js";import{useApplyStyle as m}from"../theme/utils/use-apply-styles.js";import"../theme/utils/use-media-query.js";import"../util/calendar-helper.js";import"../external/dayjs/dayjs.min.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{tokens as n,container as d,containerFromRight as p,containerFromLeft as c,containerFromBottom as h,containerFromTop as u,containerFromRightShow as v,containerFromLeftShow as j,containerFromBottomShow as y,containerFromTopShow as f,containerShow as b,containerHide as k}from"./modal.styles.js";const x={top:u,bottom:h,left:c,right:p},O={top:f,bottom:y,left:j,right:v},C=p=>{var{id:c="modal",show:h,animationFrom:u="bottom",children:v,enableOverlayClick:j=!0,rootComponentId:y,zIndex:f,onOverlayClick:C,dismissKeyboardOnShow:g=!0,disableScrollRestore:w,className:I}=p,S=e(p,["id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","disableScrollRestore","className"]);const R=a((()=>{var e,t;g&&(null===(t=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===t||t.call(e))})),{verticalHeight:z,ready:N}=s({enabled:h,onBeforeStart:R}),q=i(null),E=i(null),F=v&&r.cloneElement(v,{ref:q});return m(E,{[n.container.verticalHeight]:null==z?null:`${z}px`}),t(l,{"data-testid":`${c}-overlay`,show:h,enableOverlayClick:j,onOverlayClick:C,id:c,rootId:y,containerRef:q,zIndex:f,disableScrollRestore:w,children:t("div",Object.assign({ref:E,"data-testid":c},S,{className:o(d,x[u],h&&N?[O[u],b]:k,I),children:F}))})};export{C as Modal};
2
2
  //# sourceMappingURL=modal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modal.js","sources":["../../src/modal/modal.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { useRef } from \"react\";\n\nimport type { ModalAnimationDirection } from \"../modal-v2/types\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useApplyStyle } from \"../theme\";\nimport { useEvent } from \"../util\";\nimport * as styles from \"./modal.styles\";\nimport type { ModalProps } from \"./types\";\n\nconst ANIMATION_FROM_CLASS_MAP: Record<ModalAnimationDirection, string> = {\n top: styles.containerFromTop,\n bottom: styles.containerFromBottom,\n left: styles.containerFromLeft,\n right: styles.containerFromRight,\n};\n\nconst ANIMATION_FROM_SHOW_CLASS_MAP: Record<ModalAnimationDirection, string> = {\n top: styles.containerFromTopShow,\n bottom: styles.containerFromBottomShow,\n left: styles.containerFromLeftShow,\n right: styles.containerFromRightShow,\n};\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 className,\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 containerRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n useApplyStyle(containerRef, {\n [styles.tokens.container.verticalHeight]:\n verticalHeight == null ? null : `${verticalHeight}px`,\n });\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 <div\n ref={containerRef}\n data-testid={id}\n {...otherProps}\n className={clsx(\n styles.container,\n ANIMATION_FROM_CLASS_MAP[animationFrom],\n show && ready\n ? [\n ANIMATION_FROM_SHOW_CLASS_MAP[animationFrom],\n styles.containerShow,\n ]\n : styles.containerHide,\n className\n )}\n >\n {childWithRef}\n </div>\n </Overlay>\n );\n};\n"],"names":["ANIMATION_FROM_CLASS_MAP","top","styles.containerFromTop","bottom","styles.containerFromBottom","left","styles.containerFromLeft","right","styles.containerFromRight","ANIMATION_FROM_SHOW_CLASS_MAP","styles.containerFromTopShow","styles.containerFromBottomShow","styles.containerFromLeftShow","styles.containerFromRightShow","Modal","_a","id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","className","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","ready","useViewport","enabled","onBeforeStart","childRef","useRef","containerRef","childWithRef","React","cloneElement","ref","useApplyStyle","styles.tokens","container","_jsx","Overlay","rootId","Object","assign","clsx","styles.container","styles.containerShow","styles.containerHide"],"mappings":"snCAWA,MAAMA,EAAoE,CACtEC,IAAKC,EACLC,OAAQC,EACRC,KAAMC,EACNC,MAAOC,GAGLC,EAAyE,CAC3ER,IAAKS,EACLP,OAAQQ,EACRN,KAAMO,EACNL,MAAOM,GAGEC,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,UAC5BA,GAASV,EACNW,EAAUC,EAAAZ,EAXK,+IAgBlB,MAAMa,EAAkBC,GAAS,aACzBL,YACAM,EAAuC,UAAtCC,SAASC,qBAA6B,IAAAjB,OAAA,EAAAA,EAAEkB,6BAC7C,KAEEC,eAAEA,EAAcC,MAAEA,GAAUC,EAAY,CAC1CC,QAASpB,EACTqB,cAAeV,IAEbW,EAAWC,EAAuB,MAClCC,EAAeD,EAAuB,MACtCE,EACFvB,GAAYwB,EAAMC,aAAazB,EAAU,CAAE0B,IAAKN,IAUpD,OARAO,EAAcL,EAAc,CACxB,CAACM,EAAcC,UAAUd,gBACH,MAAlBA,EAAyB,KAAO,GAAGA,QAOvCe,EAACC,EAAO,CAAA,cACS,GAAGlC,YAChBC,KAAMA,EACNG,mBAAoBA,EACpBG,eAAgBA,EAChBP,GAAIA,EACJmC,OAAQ9B,EACRoB,aAAcF,EACdjB,OAAQA,EAAMH,SAEd8B,EAAA,MAAAG,OAAAC,OAAA,CACIR,IAAKJ,EAAY,cACJzB,GACTU,EAAU,CACdD,UAAW6B,EACPC,EACAvD,EAAyBkB,GACzBD,GAAQkB,EACF,CACI1B,EAA8BS,GAC9BsC,GAEJC,EACNhC,GACHN,SAEAuB,MAEC"}
1
+ {"version":3,"file":"modal.js","sources":["../../src/modal/modal.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { useRef } from \"react\";\n\nimport type { ModalAnimationDirection } from \"../modal-v2/types\";\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useApplyStyle } from \"../theme\";\nimport { useEvent } from \"../util\";\nimport * as styles from \"./modal.styles\";\nimport type { ModalProps } from \"./types\";\n\nconst ANIMATION_FROM_CLASS_MAP: Record<ModalAnimationDirection, string> = {\n top: styles.containerFromTop,\n bottom: styles.containerFromBottom,\n left: styles.containerFromLeft,\n right: styles.containerFromRight,\n};\n\nconst ANIMATION_FROM_SHOW_CLASS_MAP: Record<ModalAnimationDirection, string> = {\n top: styles.containerFromTopShow,\n bottom: styles.containerFromBottomShow,\n left: styles.containerFromLeftShow,\n right: styles.containerFromRightShow,\n};\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 className,\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 containerRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n useApplyStyle(containerRef, {\n [styles.tokens.container.verticalHeight]:\n verticalHeight == null ? null : `${verticalHeight}px`,\n });\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 <div\n ref={containerRef}\n data-testid={id}\n {...otherProps}\n className={clsx(\n styles.container,\n ANIMATION_FROM_CLASS_MAP[animationFrom],\n show && ready\n ? [\n ANIMATION_FROM_SHOW_CLASS_MAP[animationFrom],\n styles.containerShow,\n ]\n : styles.containerHide,\n className\n )}\n >\n {childWithRef}\n </div>\n </Overlay>\n );\n};\n"],"names":["ANIMATION_FROM_CLASS_MAP","top","styles.containerFromTop","bottom","styles.containerFromBottom","left","styles.containerFromLeft","right","styles.containerFromRight","ANIMATION_FROM_SHOW_CLASS_MAP","styles.containerFromTopShow","styles.containerFromBottomShow","styles.containerFromLeftShow","styles.containerFromRightShow","Modal","_a","id","show","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","disableScrollRestore","className","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","ready","useViewport","enabled","onBeforeStart","childRef","useRef","containerRef","childWithRef","React","cloneElement","ref","useApplyStyle","styles.tokens","container","_jsx","Overlay","rootId","Object","assign","clsx","styles.container","styles.containerShow","styles.containerHide"],"mappings":"snCAWA,MAAMA,EAAoE,CACtEC,IAAKC,EACLC,OAAQC,EACRC,KAAMC,EACNC,MAAOC,GAGLC,EAAyE,CAC3ER,IAAKS,EACLP,OAAQQ,EACRN,KAAMO,EACNL,MAAOM,GAGEC,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,EAAoBC,UACpBA,GAASX,EACNY,EAAUC,EAAAb,EAZK,sKAiBlB,MAAMc,EAAkBC,GAAS,aACzBN,YACAO,EAAuC,UAAtCC,SAASC,qBAA6B,IAAAlB,OAAA,EAAAA,EAAEmB,6BAC7C,KAEEC,eAAEA,EAAcC,MAAEA,GAAUC,EAAY,CAC1CC,QAASrB,EACTsB,cAAeV,IAEbW,EAAWC,EAAuB,MAClCC,EAAeD,EAAuB,MACtCE,EACFxB,GAAYyB,EAAMC,aAAa1B,EAAU,CAAE2B,IAAKN,IAUpD,OARAO,EAAcL,EAAc,CACxB,CAACM,EAAcC,UAAUd,gBACH,MAAlBA,EAAyB,KAAO,GAAGA,QAOvCe,EAACC,EAAO,CAAA,cACS,GAAGnC,YAChBC,KAAMA,EACNG,mBAAoBA,EACpBG,eAAgBA,EAChBP,GAAIA,EACJoC,OAAQ/B,EACRqB,aAAcF,EACdlB,OAAQA,EACRG,qBAAsBA,EAAoBN,SAE1C+B,EAAA,MAAAG,OAAAC,OAAA,CACIR,IAAKJ,EAAY,cACJ1B,GACTW,EAAU,CACdD,UAAW6B,EACPC,EACAxD,EAAyBkB,GACzBD,GAAQmB,EACF,CACI3B,EAA8BS,GAC9BuC,GAEJC,EACNhC,GACHP,SAEAwB,MAEC"}
package/modal/types.d.ts CHANGED
@@ -50,6 +50,19 @@ export interface ModalProps extends React.HTMLAttributes<HTMLDivElement> {
50
50
  * @default true
51
51
  */
52
52
  dismissKeyboardOnShow?: boolean | undefined;
53
+ /**
54
+ * Prevents the page's scroll position from being restored when the modal
55
+ * closes. Useful when the page navigates or scrolls programmatically while
56
+ * the modal is open, e.g. a loading modal between pages.
57
+ *
58
+ * @remarks
59
+ * - Passed to `Overlay`. Only has an effect where the overlay restores
60
+ * scroll, currently iOS.
61
+ * - The value from the last render while `show` is `true` is used.
62
+ *
63
+ * @default false
64
+ */
65
+ disableScrollRestore?: boolean | undefined;
53
66
  }
54
67
  /**
55
68
  * Props for the `Modal.Box` sub-component.
@@ -13,7 +13,7 @@ import type { ModalV2Props } from "./types";
13
13
  * - `ModalV2.Footer` — footer area for primary and secondary action buttons.
14
14
  * @keywords dialog, overlay, popup
15
15
  */
16
- 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, className, ...otherProps }: ModalV2Props) => JSX.Element) & {
16
+ 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, className, ...otherProps }: ModalV2Props) => JSX.Element) & {
17
17
  /** Wraps modal content and arranges `Content`, `Footer`, and `CloseButton` slots in the correct layout. Supports a `fullscreen` prop. */
18
18
  Card: (props: import("./types").ModalCardProps & React.RefAttributes<HTMLDivElement>) => React.ReactElement | null;
19
19
  /** Renders an accessible close button that invokes the modal's `onClose` callback. */
@@ -1,2 +1,2 @@
1
- import{__rest as e}from"../_virtual/_tslib.js";import{jsx as o}from"react/jsx-runtime";import{useFloating as t,useTransitionStatus as r,useDismiss as i,useInteractions as a,FloatingFocusManager as l}from"@floating-ui/react";import s from"clsx";import n,{useRef as m}from"react";import{Overlay as d}from"../overlay/overlay.js";import{useViewport as c}from"../shared/hooks/useViewport.js";import"../theme/theme-provider/index.js";import"../theme/theme-provider/context.js";import"../theme/tokens/border.js";import"../theme/tokens/colour.js";import"../theme/tokens/font.js";import"../theme/tokens/media-query.js";import{useApplyStyle as p}from"../theme/utils/use-apply-styles.js";import"../theme/utils/use-media-query.js";import"../util/calendar-helper.js";import"../external/dayjs/dayjs.min.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 u}from"../util/use-event.js";import{ModalContext as b}from"./modal-context.js";import{tokens as h,scrollContainer as j,modalContainer as f,container as v}from"./modal-v2.styles.js";import{Card as y}from"./slots/card.js";import{CloseButton as C}from"./slots/close-button.js";import{Content as g}from"./slots/content.js";import{Footer as x}from"./slots/footer.js";import{Header as O}from"./slots/header.js";const k=Object.assign((y=>{var{id:C,show:g,onClose:x,animationFrom:O="bottom",children:k,enableOverlayClick:F=!0,rootComponentId:I,zIndex:w,onOverlayClick:N,dismissKeyboardOnShow:z=!0,"data-testid":H="modal","aria-label":P,"aria-labelledby":S,"aria-describedby":q,disableInitialFocus:B=!1,className:E}=y,K=e(y,["id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","data-testid","aria-label","aria-labelledby","aria-describedby","disableInitialFocus","className"]);const $=u((()=>{var e,o;z&&(null===(o=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===o||o.call(e))})),{verticalHeight:_}=c({enabled:g,onBeforeStart:$}),M=m(null),R=m(null),V=k&&n.cloneElement(k,{ref:M});p(R,{[h.container.verticalHeight]:null==_?null:`${_}px`});const{refs:A,context:D}=t({open:g,onOpenChange:e=>{e||null==x||x()}}),{isMounted:G,status:J}=r(D,{duration:300}),L=i(D,{outsidePress:!1,enabled:!!x}),{getFloatingProps:Q}=a([L]);return o(d,{"data-testid":`${H}-overlay`,show:g,enableOverlayClick:F,onOverlayClick:N,id:C,rootId:I,containerRef:M,zIndex:w,children:o("div",Object.assign({ref:R,"data-testid":H,"data-status":J,"data-animation-from":O},K,{className:s(v,E),children:o(b.Provider,{value:{onClose:x},children:G&&o(l,{context:D,initialFocus:B?-1:A.floating,children:o("div",{className:j,children:o("div",Object.assign({ref:A.setFloating},Q(),{role:"dialog","aria-label":P,"aria-labelledby":S,"aria-describedby":q,className:f,children:V}))})})})}))})}),{Card:y,CloseButton:C,Content:g,Footer:x,Header:O});export{k as ModalV2};
1
+ import{__rest as e}from"../_virtual/_tslib.js";import{jsx as o}from"react/jsx-runtime";import{useFloating as t,useTransitionStatus as r,useDismiss as i,useInteractions as l,FloatingFocusManager as a}from"@floating-ui/react";import s from"clsx";import n,{useRef as m}from"react";import{Overlay as d}from"../overlay/overlay.js";import{useViewport as c}from"../shared/hooks/useViewport.js";import"../theme/theme-provider/index.js";import"../theme/theme-provider/context.js";import"../theme/tokens/border.js";import"../theme/tokens/colour.js";import"../theme/tokens/font.js";import"../theme/tokens/media-query.js";import{useApplyStyle as p}from"../theme/utils/use-apply-styles.js";import"../theme/utils/use-media-query.js";import"../util/calendar-helper.js";import"../external/dayjs/dayjs.min.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 u}from"../util/use-event.js";import{ModalContext as b}from"./modal-context.js";import{tokens as h,scrollContainer as j,modalContainer as f,container as v}from"./modal-v2.styles.js";import{Card as y}from"./slots/card.js";import{CloseButton as C}from"./slots/close-button.js";import{Content as g}from"./slots/content.js";import{Footer as x}from"./slots/footer.js";import{Header as O}from"./slots/header.js";const k=Object.assign((y=>{var{id:C,show:g,onClose:x,animationFrom:O="bottom",children:k,enableOverlayClick:F=!0,rootComponentId:I,zIndex:w,onOverlayClick:S,dismissKeyboardOnShow:N=!0,"data-testid":R="modal","aria-label":z,"aria-labelledby":H,"aria-describedby":P,disableInitialFocus:q=!1,disableScrollRestore:B,className:E}=y,K=e(y,["id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","data-testid","aria-label","aria-labelledby","aria-describedby","disableInitialFocus","disableScrollRestore","className"]);const $=u((()=>{var e,o;N&&(null===(o=null===(e=document.activeElement)||void 0===e?void 0:e.blur)||void 0===o||o.call(e))})),{verticalHeight:_}=c({enabled:g,onBeforeStart:$}),M=m(null),V=m(null),A=k&&n.cloneElement(k,{ref:M});p(V,{[h.container.verticalHeight]:null==_?null:`${_}px`});const{refs:D,context:G}=t({open:g,onOpenChange:e=>{e||null==x||x()}}),{isMounted:J,status:L}=r(G,{duration:300}),Q=i(G,{outsidePress:!1,enabled:!!x}),{getFloatingProps:T}=l([Q]);return o(d,{"data-testid":`${R}-overlay`,show:g,enableOverlayClick:F,onOverlayClick:S,id:C,rootId:I,containerRef:M,zIndex:w,disableScrollRestore:B,children:o("div",Object.assign({ref:V,"data-testid":R,"data-status":L,"data-animation-from":O},K,{className:s(v,E),children:o(b.Provider,{value:{onClose:x},children:J&&o(a,{context:G,initialFocus:q?-1:D.floating,children:o("div",{className:j,children:o("div",Object.assign({ref:D.setFloating},T(),{role:"dialog","aria-label":z,"aria-labelledby":H,"aria-describedby":P,className:f,children:A}))})})})}))})}),{Card:y,CloseButton:C,Content:g,Footer:x,Header:O});export{k as ModalV2};
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 clsx from \"clsx\";\nimport React, { useRef } from \"react\";\n\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useApplyStyle } from \"../theme\";\nimport { useEvent } from \"../util\";\nimport { ModalContext } from \"./modal-context\";\nimport * as styles from \"./modal-v2.styles\";\nimport { Card, CloseButton, Content, Footer, Header } from \"./slots\";\nimport type { ModalV2Props } from \"./types\";\n\nconst Base = ({\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 className,\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 containerRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n useApplyStyle(containerRef, {\n [styles.tokens.container.verticalHeight]:\n verticalHeight == null ? null : `${verticalHeight}px`,\n });\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 <div\n ref={containerRef}\n data-testid={testId}\n data-status={status}\n data-animation-from={animationFrom}\n {...otherProps}\n className={clsx(styles.container, className)}\n >\n <ModalContext.Provider value={{ onClose }}>\n {isMounted && (\n <FloatingFocusManager\n context={context}\n initialFocus={\n disableInitialFocus ? -1 : refs.floating\n }\n >\n <div className={styles.scrollContainer}>\n <div\n ref={refs.setFloating}\n {...getFloatingProps()}\n role=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n className={styles.modalContainer}\n >\n {childWithRef}\n </div>\n </div>\n </FloatingFocusManager>\n )}\n </ModalContext.Provider>\n </div>\n </Overlay>\n );\n};\n\n// @catalog\n/**\n * A composable modal dialog with slot-based content layout.\n *\n * Use `ModalV2` when you need a controlled overlay dialog with structured\n * content slots.\n *\n * Sub-components:\n * - `ModalV2.Card` — wraps modal content and arranges `Content`, `Footer`, and `CloseButton` slots in the correct layout. Supports a `fullscreen` prop that makes the card fill the viewport.\n * - `ModalV2.CloseButton` — renders an accessible close button that invokes the modal's `onClose` callback.\n * - `ModalV2.Content` — container for the body content of the modal card.\n * - `ModalV2.Footer` — footer area for primary and secondary action buttons.\n * @keywords dialog, overlay, popup\n */\nexport const ModalV2 = Object.assign(Base, {\n /** Wraps modal content and arranges `Content`, `Footer`, and `CloseButton` slots in the correct layout. Supports a `fullscreen` prop. */\n Card,\n /** Renders an accessible close button that invokes the modal's `onClose` callback. */\n CloseButton,\n /** Container for the body content of the modal card. */\n Content,\n /** Footer area for primary and secondary action buttons. */\n Footer,\n /** Header bar with a close button and optional title. Use instead of `CloseButton` when a heading is needed. */\n Header,\n});\n"],"names":["ModalV2","Object","assign","_a","id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","testId","ariaLabel","ariaLabelledBy","ariaDescribedBy","disableInitialFocus","className","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","useViewport","enabled","onBeforeStart","childRef","useRef","containerRef","childWithRef","React","cloneElement","ref","useApplyStyle","styles.tokens","container","refs","context","useFloating","open","onOpenChange","isOpen","isMounted","status","useTransitionStatus","duration","dismiss","useDismiss","outsidePress","getFloatingProps","useInteractions","_jsx","Overlay","rootId","clsx","styles.container","ModalContext","Provider","value","FloatingFocusManager","initialFocus","floating","styles.scrollContainer","setFloating","role","styles.modalContainer","Card","CloseButton","Content","Footer","Header"],"mappings":"20CAmBA,MA+HaA,EAAUC,OAAOC,QA/HhBC,QAAAC,GACVA,EAAEC,KACFA,EAAIC,QACJA,EAAOC,cAC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,GACJD,UAAWyC,EAAKC,EAAkB1C,GAAUX,SAE5CiD,EAACK,EAAaC,SAAQ,CAACC,MAAO,CAAE1D,WAASE,SACpCwC,GACGS,EAACQ,EAAoB,CACjBtB,QAASA,EACTuB,aACIhD,GAAsB,EAAKwB,EAAKyB,SAAQ3D,SAG5CiD,EAAA,MAAA,CAAKtC,UAAWiD,EAAsB5D,SAClCiD,EAAA,MAAAxD,OAAAC,OAAA,CACIoC,IAAKI,EAAK2B,aACNd,IAAkB,CACtBe,KAAK,SAAQ,aACDvD,EAAS,kBACJC,EAAc,mBACbC,EAClBE,UAAWoD,WAEVpC,eAOnB,GAkByB,CAEvCqC,OAEAC,cAEAC,UAEAC,SAEAC"}
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 clsx from \"clsx\";\nimport React, { useRef } from \"react\";\n\nimport { Overlay } from \"../overlay/overlay\";\nimport { useViewport } from \"../shared/hooks\";\nimport { useApplyStyle } from \"../theme\";\nimport { useEvent } from \"../util\";\nimport { ModalContext } from \"./modal-context\";\nimport * as styles from \"./modal-v2.styles\";\nimport { Card, CloseButton, Content, Footer, Header } from \"./slots\";\nimport type { ModalV2Props } from \"./types\";\n\nconst Base = ({\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 className,\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 containerRef = useRef<HTMLDivElement>(null);\n const childWithRef =\n children && React.cloneElement(children, { ref: childRef });\n\n useApplyStyle(containerRef, {\n [styles.tokens.container.verticalHeight]:\n verticalHeight == null ? null : `${verticalHeight}px`,\n });\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 <div\n ref={containerRef}\n data-testid={testId}\n data-status={status}\n data-animation-from={animationFrom}\n {...otherProps}\n className={clsx(styles.container, className)}\n >\n <ModalContext.Provider value={{ onClose }}>\n {isMounted && (\n <FloatingFocusManager\n context={context}\n initialFocus={\n disableInitialFocus ? -1 : refs.floating\n }\n >\n <div className={styles.scrollContainer}>\n <div\n ref={refs.setFloating}\n {...getFloatingProps()}\n role=\"dialog\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-describedby={ariaDescribedBy}\n className={styles.modalContainer}\n >\n {childWithRef}\n </div>\n </div>\n </FloatingFocusManager>\n )}\n </ModalContext.Provider>\n </div>\n </Overlay>\n );\n};\n\n// @catalog\n/**\n * A composable modal dialog with slot-based content layout.\n *\n * Use `ModalV2` when you need a controlled overlay dialog with structured\n * content slots.\n *\n * Sub-components:\n * - `ModalV2.Card` — wraps modal content and arranges `Content`, `Footer`, and `CloseButton` slots in the correct layout. Supports a `fullscreen` prop that makes the card fill the viewport.\n * - `ModalV2.CloseButton` — renders an accessible close button that invokes the modal's `onClose` callback.\n * - `ModalV2.Content` — container for the body content of the modal card.\n * - `ModalV2.Footer` — footer area for primary and secondary action buttons.\n * @keywords dialog, overlay, popup\n */\nexport const ModalV2 = Object.assign(Base, {\n /** Wraps modal content and arranges `Content`, `Footer`, and `CloseButton` slots in the correct layout. Supports a `fullscreen` prop. */\n Card,\n /** Renders an accessible close button that invokes the modal's `onClose` callback. */\n CloseButton,\n /** Container for the body content of the modal card. */\n Content,\n /** Footer area for primary and secondary action buttons. */\n Footer,\n /** Header bar with a close button and optional title. Use instead of `CloseButton` when a heading is needed. */\n Header,\n});\n"],"names":["ModalV2","Object","assign","_a","id","show","onClose","animationFrom","children","enableOverlayClick","rootComponentId","zIndex","onOverlayClick","dismissKeyboardOnShow","testId","ariaLabel","ariaLabelledBy","ariaDescribedBy","disableInitialFocus","disableScrollRestore","className","otherProps","__rest","dismissKeyboard","useEvent","_b","document","activeElement","blur","verticalHeight","useViewport","enabled","onBeforeStart","childRef","useRef","containerRef","childWithRef","React","cloneElement","ref","useApplyStyle","styles.tokens","container","refs","context","useFloating","open","onOpenChange","isOpen","isMounted","status","useTransitionStatus","duration","dismiss","useDismiss","outsidePress","getFloatingProps","useInteractions","_jsx","Overlay","rootId","clsx","styles.container","ModalContext","Provider","value","FloatingFocusManager","initialFocus","floating","styles.scrollContainer","setFloating","role","styles.modalContainer","Card","CloseButton","Content","Footer","Header"],"mappings":"20CAmBA,MAiIaA,EAAUC,OAAOC,QAjIhBC,QAAAC,GACVA,EAAEC,KACFA,EAAIC,QACJA,EAAOC,cACPA,EAAgB,SAAQC,SACxBA,EAAQC,mBACRA,GAAqB,EAAIC,gBACzBA,EAAeC,OACfA,EAAMC,eACNA,EAAcC,sBACdA,GAAwB,EACxB,cAAeC,EAAS,QAC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CACjBtB,QAASA,EACTuB,aACIjD,GAAsB,EAAKyB,EAAKyB,SAAQ5D,SAG5CkD,EAAA,MAAA,CAAKtC,UAAWiD,EAAsB7D,SAClCkD,EAAA,MAAAzD,OAAAC,OAAA,CACIqC,IAAKI,EAAK2B,aACNd,IAAkB,CACtBe,KAAK,SAAQ,aACDxD,oBACKC,EAAc,mBACbC,EAClBG,UAAWoD,EAAqBhE,SAE/B4B,eAOnB,GAkByB,CAEvCqC,OAEAC,cAEAC,UAEAC,SAEAC"}
@@ -145,4 +145,17 @@ export interface ModalV2Props extends React.HTMLAttributes<HTMLDivElement> {
145
145
  * @default false
146
146
  */
147
147
  disableInitialFocus?: boolean | undefined;
148
+ /**
149
+ * Prevents the page's scroll position from being restored when the modal
150
+ * closes. Useful when the page navigates or scrolls programmatically while
151
+ * the modal is open, e.g. a loading modal between pages.
152
+ *
153
+ * @remarks
154
+ * - Passed to `Overlay`. Only has an effect where the overlay restores
155
+ * scroll, currently iOS.
156
+ * - The value from the last render while `show` is `true` is used.
157
+ *
158
+ * @default false
159
+ */
160
+ disableScrollRestore?: boolean | undefined;
148
161
  }
@@ -1,2 +1,2 @@
1
- import{jsx as e}from"react/jsx-runtime";import{FloatingTree as t,useFloatingNodeId as o,FloatingNode as r}from"@floating-ui/react";import n from"clsx";import{useState as l,useRef as s,useEffect as i}from"react";import a from"react-dom";import"../theme/theme-provider/index.js";import{useInheritedThemeScope as d}from"../theme/theme-provider/hooks.js";import"../theme/tokens/border.js";import"../theme/tokens/colour.js";import"../theme/tokens/font.js";import"../theme/tokens/media-query.js";import{useApplyStyle as c}from"../theme/utils/use-apply-styles.js";import"../theme/utils/use-media-query.js";import"../util/calendar-helper.js";import"../external/dayjs/dayjs.min.js";import"../util/file-helper.js";import{useId as m}from"../util/simple-id-generator.js";import"../util/string-helper.js";import"@react-aria/live-announcer";import{tokens as u,root as p,rootShow as y,wrapper as v,wrapperShow as g,wrapperHide as h,wrapperStacked as f,wrapperBackgroundBlur as b,wrapperDisableTransition as j}from"./overlay.styles.js";import{useFloatingParent as O}from"./use-floating-context.js";const k=({show:t=!1,rootId:k,onOverlayClick:L,children:w,backgroundBlur:x=!0,disableTransition:C=!1,enableOverlayClick:P=!1,zIndex:T,id:E,containerRef:D})=>{const[I,S]=l(null),[q,W]=l(),Y=m(),z=o(),A=s(),B=s(!1),F=s(null),N=s(null),$=E?`lifesg-ds-overlay-root-${E}`:"lifesg-ds-overlay-root",R=null!=T?T:q?99999:99998,{themeProps:V,themeStyle:G}=d(t);O(R),c(F,{[u.root.zIndex]:R}),i((()=>(Q(),S(K()),()=>{_(),X().length<1&&(J()&&(ee("remove"),oe()),U("remove"))})),[]),i((()=>{if(t){const e=M();H(e),Z(),J()&&1===X().length&&(te(),ee("add"));const t=setTimeout((()=>{U("add")}),200);return()=>clearTimeout(t)}{_(),J()&&X().length<1&&(ee("remove"),oe());const e=setTimeout((()=>{X().length<1&&U("remove")}),200);return()=>clearTimeout(e)}}),[t]),i((()=>{if(t)return document.addEventListener("mousedown",re,!0),()=>{document.removeEventListener("mousedown",re,!0)}}),[t]);const H=e=>{A.current=e,W(e)},J=()=>/(iPad|iPhone|iPod)/g.test(navigator.userAgent),K=()=>document&&k?document.getElementById(k):document?document.body:null,M=()=>X().length>0,Q=()=>{const e=document.documentElement.clientWidth,t=window.innerWidth-e;document.documentElement.style.setProperty(u.global.scrollbarWidth,`${t}px`)},U=e=>{const t=document.body.classList.contains(u.global.overlayOpenClass);"add"!==e||t?"remove"===e&&t&&document.body.classList.remove(u.global.overlayOpenClass):document.body.classList.add(u.global.overlayOpenClass)},X=()=>{const e=document.body.dataset.lifesgDsOverlayOrder;return e?e.split(","):[]},Z=()=>{const e=X();document.body.dataset.lifesgDsOverlayOrder=[...e,Y].join(",")},_=()=>{const e=X();document.body.dataset.lifesgDsOverlayOrder=e.filter((e=>e!==Y)).join(",")},ee=e=>{if(!J())return;const t=document.body.classList.contains(u.global.overlayScrollLockClass);"add"!==e||t?"remove"===e&&t&&document.body.classList.remove(u.global.overlayScrollLockClass):document.body.classList.add(u.global.overlayScrollLockClass)},te=()=>{const e=document.body.style,t=e.top?e.top:window.scrollY+"px";document.body.style.setProperty(u.global.scrollY,t)},oe=()=>{if(!J())return;const e=document.body.style.getPropertyValue(u.global.scrollY);requestAnimationFrame((()=>{window.scrollTo({top:parseFloat(e)})}))},re=e=>{var t;const o=null!==(t=null==D?void 0:D.current)&&void 0!==t?t:N.current,r=N.current;if(!o)return void(B.current=!1);const n=e.target,l=r===n,s=o===n,i=o.contains(n);B.current=!l&&(s||i)},ne=e=>{var t;const o=null!==(t=null==D?void 0:D.current)&&void 0!==t?t:N.current,r=N.current;if(!o)return void(B.current=!1);const n=e.target,l=r===n,s=o===n,i=o.contains(n);!l&&(s||i)||B.current||!L||!P||(e.preventDefault(),L()),B.current=!1};return I?a.createPortal(e("div",Object.assign({ref:F,id:$,"data-testid":$,className:n(p,t&&y)},V,{style:G,children:w&&e(r,{id:z,children:e("div",{ref:N,"data-testid":"overlay-wrapper",className:n(v,t?g:h,q&&f,x&&b,C&&j),onClick:ne,children:w})})})),I):null},L=o=>e(t,{children:e(k,Object.assign({},o))});export{L as Overlay};
1
+ import{jsx as e}from"react/jsx-runtime";import{FloatingTree as t,useFloatingNodeId as o,FloatingNode as r}from"@floating-ui/react";import l from"clsx";import{useState as n,useRef as s,useEffect as i}from"react";import a from"react-dom";import"../theme/theme-provider/index.js";import{useInheritedThemeScope as d}from"../theme/theme-provider/hooks.js";import"../theme/tokens/border.js";import"../theme/tokens/colour.js";import"../theme/tokens/font.js";import"../theme/tokens/media-query.js";import{useApplyStyle as c}from"../theme/utils/use-apply-styles.js";import"../theme/utils/use-media-query.js";import"../util/calendar-helper.js";import"../external/dayjs/dayjs.min.js";import"../util/file-helper.js";import{useId as m}from"../util/simple-id-generator.js";import"../util/string-helper.js";import"@react-aria/live-announcer";import{tokens as u,root as p,rootShow as y,wrapper as v,wrapperShow as g,wrapperHide as b,wrapperStacked as h,wrapperBackgroundBlur as f,wrapperDisableTransition as j}from"./overlay.styles.js";import{useFloatingParent as O}from"./use-floating-context.js";const k=({show:t=!1,rootId:k,onOverlayClick:L,children:w,backgroundBlur:x=!0,disableTransition:C=!1,enableOverlayClick:P=!1,zIndex:T,id:E,containerRef:S,disableScrollRestore:D=!1})=>{const[I,Y]=n(null),[q,W]=n(),z=m(),A=o(),B=s(),F=s(!1),N=s(null),R=s(null),$=s(D),V=E?`lifesg-ds-overlay-root-${E}`:"lifesg-ds-overlay-root",G=null!=T?T:q?99999:99998,{themeProps:H,themeStyle:J}=d(t);O(G),c(N,{[u.root.zIndex]:G}),i((()=>(X(),Y(Q()),()=>{te(),_().length<1&&(M()&&(oe("remove"),le()),Z("remove"))})),[]),i((()=>{t&&($.current=D)}),[t,D]),i((()=>{if(t){const e=U();K(e),ee(),M()&&1===_().length&&(re(),oe("add"));const t=setTimeout((()=>{Z("add")}),200);return()=>clearTimeout(t)}{te(),M()&&_().length<1&&(oe("remove"),le());const e=setTimeout((()=>{_().length<1&&Z("remove")}),200);return()=>clearTimeout(e)}}),[t]),i((()=>{if(t)return document.addEventListener("mousedown",ne,!0),()=>{document.removeEventListener("mousedown",ne,!0)}}),[t]);const K=e=>{B.current=e,W(e)},M=()=>/(iPad|iPhone|iPod)/g.test(navigator.userAgent),Q=()=>document&&k?document.getElementById(k):document?document.body:null,U=()=>_().length>0,X=()=>{const e=document.documentElement.clientWidth,t=window.innerWidth-e;document.documentElement.style.setProperty(u.global.scrollbarWidth,`${t}px`)},Z=e=>{const t=document.body.classList.contains(u.global.overlayOpenClass);"add"!==e||t?"remove"===e&&t&&document.body.classList.remove(u.global.overlayOpenClass):document.body.classList.add(u.global.overlayOpenClass)},_=()=>{const e=document.body.dataset.lifesgDsOverlayOrder;return e?e.split(","):[]},ee=()=>{const e=_();document.body.dataset.lifesgDsOverlayOrder=[...e,z].join(",")},te=()=>{const e=_();document.body.dataset.lifesgDsOverlayOrder=e.filter((e=>e!==z)).join(",")},oe=e=>{if(!M())return;const t=document.body.classList.contains(u.global.overlayScrollLockClass);"add"!==e||t?"remove"===e&&t&&document.body.classList.remove(u.global.overlayScrollLockClass):document.body.classList.add(u.global.overlayScrollLockClass)},re=()=>{const e=document.body.style,t=e.top?e.top:window.scrollY+"px";document.body.style.setProperty(u.global.scrollY,t)},le=()=>{if(!M())return;const e=document.body.style.getPropertyValue(u.global.scrollY);document.body.style.removeProperty(u.global.scrollY),e&&!$.current&&requestAnimationFrame((()=>{window.scrollTo({top:parseFloat(e)})}))},ne=e=>{var t;const o=null!==(t=null==S?void 0:S.current)&&void 0!==t?t:R.current,r=R.current;if(!o)return void(F.current=!1);const l=e.target,n=r===l,s=o===l,i=o.contains(l);F.current=!n&&(s||i)},se=e=>{var t;const o=null!==(t=null==S?void 0:S.current)&&void 0!==t?t:R.current,r=R.current;if(!o)return void(F.current=!1);const l=e.target,n=r===l,s=o===l,i=o.contains(l);!n&&(s||i)||F.current||!L||!P||(e.preventDefault(),L()),F.current=!1};return I?a.createPortal(e("div",Object.assign({ref:N,id:V,"data-testid":V,className:l(p,t&&y)},H,{style:J,children:w&&e(r,{id:A,children:e("div",{ref:R,"data-testid":"overlay-wrapper",className:l(v,t?g:b,q&&h,x&&f,C&&j),onClick:se,children:w})})})),I):null},L=o=>e(t,{children:e(k,Object.assign({},o))});export{L as Overlay};
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 clsx from \"clsx\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\n\nimport { useApplyStyle, useInheritedThemeScope } from \"../theme\";\nimport { useId } from \"../util\";\nimport * as styles from \"./overlay.styles\";\nimport type { OverlayProps } from \"./types\";\nimport { useFloatingParent } from \"./use-floating-context\";\n\nconst OverlayComponent = ({\n show = false,\n rootId,\n onOverlayClick,\n children,\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 rootRef = useRef<HTMLDivElement>(null);\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 const { themeProps, themeStyle } = useInheritedThemeScope(show);\n\n useFloatingParent(zIndex);\n\n useApplyStyle(rootRef, { [styles.tokens.root.zIndex]: zIndex });\n\n // =============================================================================\n // EFFECTS\n // =============================================================================\n useEffect(() => {\n initialiseStylesForDocumentBody();\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 // eslint-disable-next-line react-hooks/exhaustive-deps\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 // eslint-disable-next-line react-hooks/exhaustive-deps\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 // eslint-disable-next-line react-hooks/exhaustive-deps\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 initialiseStylesForDocumentBody = () => {\n const documentWidth = document.documentElement.clientWidth;\n const windowWidth = window.innerWidth;\n const scrollBarWidth = windowWidth - documentWidth;\n\n document.documentElement.style.setProperty(\n styles.tokens.global.scrollbarWidth,\n `${scrollBarWidth}px`\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 styles.tokens.global.overlayOpenClass\n );\n\n if (action === \"add\" && !isOverlayStyleClassApplied) {\n document.body.classList.add(styles.tokens.global.overlayOpenClass);\n } else if (action === \"remove\" && isOverlayStyleClassApplied) {\n document.body.classList.remove(\n styles.tokens.global.overlayOpenClass\n );\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 styles.tokens.global.overlayScrollLockClass\n );\n\n if (action === \"add\" && !isClassApplied) {\n document.body.classList.add(\n styles.tokens.global.overlayScrollLockClass\n );\n } else if (action === \"remove\" && isClassApplied) {\n document.body.classList.remove(\n styles.tokens.global.overlayScrollLockClass\n );\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(styles.tokens.global.scrollY, scrollY);\n };\n\n const scrollToLastScrollPositionForIOS = () => {\n if (!isIOS()) {\n return;\n }\n\n const scrollY = document.body.style.getPropertyValue(\n styles.tokens.global.scrollY\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 <div\n ref={wrapperRef}\n data-testid=\"overlay-wrapper\"\n className={clsx(\n styles.wrapper,\n show ? styles.wrapperShow : styles.wrapperHide,\n isStacked && styles.wrapperStacked,\n backgroundBlur && styles.wrapperBackgroundBlur,\n disableTransition && styles.wrapperDisableTransition\n )}\n onClick={handleWrapperClick}\n >\n {children}\n </div>\n </FloatingNode>\n );\n\n const renderComponent = () => (\n <div\n ref={rootRef}\n id={overlayRootId}\n data-testid={overlayRootId}\n className={clsx(styles.root, show && styles.rootShow)}\n {...themeProps}\n style={themeStyle}\n >\n {children && renderWrapper()}\n </div>\n );\n\n return rootElement\n ? ReactDOM.createPortal(renderComponent(), rootElement)\n : null;\n};\n\n// @catalog\n/**\n * A full-screen dimmed overlay backdrop.\n *\n * Use `Overlay` as the backdrop for modal dialogs, drawers, and similar\n * blocking UI patterns. It manages body scroll-lock automatically and stacks\n * correctly when multiple overlays are open at once.\n * @keywords backdrop, dim, modal\n */\nexport const Overlay = (props: OverlayProps) => {\n return (\n <FloatingTree>\n <OverlayComponent {...props} />\n </FloatingTree>\n );\n};\n"],"names":["OverlayComponent","show","rootId","onOverlayClick","children","backgroundBlur","disableTransition","enableOverlayClick","zIndex","customZIndex","id","containerRef","rootElement","setRootElement","useState","isStacked","_setIsStacked","uid","useId","nodeId","useFloatingNodeId","stacked","useRef","mouseDownInsideModalRef","rootRef","wrapperRef","overlayRootId","themeProps","themeStyle","useInheritedThemeScope","useFloatingParent","useApplyStyle","styles.tokens","root","useEffect","initialiseStylesForDocumentBody","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","documentWidth","documentElement","clientWidth","scrollBarWidth","window","innerWidth","style","setProperty","global","scrollbarWidth","action","isOverlayStyleClassApplied","classList","contains","overlayOpenClass","remove","add","attr","dataset","lifesgDsOverlayOrder","split","order","join","filter","o","isClassApplied","overlayScrollLockClass","bodyStyle","scrollY","top","getPropertyValue","requestAnimationFrame","scrollTo","parseFloat","e","container","_a","wrapper","target","clickedOnWrapper","clickedOnContainer","clickedInsideContainer","handleWrapperClick","event","preventDefault","ReactDOM","createPortal","_jsx","Object","assign","ref","className","clsx","styles.root","styles.rootShow","FloatingNode","styles.wrapper","styles.wrapperShow","styles.wrapperHide","styles.wrapperStacked","styles.wrapperBackgroundBlur","styles.wrapperDisableTransition","onClick","Overlay","props","FloatingTree"],"mappings":"0jCAgBA,MAAMA,EAAmB,EACrBC,QAAO,EACPC,SACAC,iBACAC,WACAC,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,GACjCE,EAAUF,EAAuB,MACjCG,EAAaH,EAAuB,MAEpCI,EAAgBhB,EAChB,0BAA0BA,IAC1B,yBACAF,EAASC,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"overlay.js","sources":["../../src/overlay/overlay.tsx"],"sourcesContent":["import {\n FloatingNode,\n FloatingTree,\n useFloatingNodeId,\n} from \"@floating-ui/react\";\nimport clsx from \"clsx\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport ReactDOM from \"react-dom\";\n\nimport { useApplyStyle, useInheritedThemeScope } from \"../theme\";\nimport { useId } from \"../util\";\nimport * as styles from \"./overlay.styles\";\nimport type { OverlayProps } from \"./types\";\nimport { useFloatingParent } from \"./use-floating-context\";\n\nconst OverlayComponent = ({\n show = false,\n rootId,\n onOverlayClick,\n children,\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 rootRef = useRef<HTMLDivElement>(null);\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 const { themeProps, themeStyle } = useInheritedThemeScope(show);\n\n useFloatingParent(zIndex);\n\n useApplyStyle(rootRef, { [styles.tokens.root.zIndex]: zIndex });\n\n // =============================================================================\n // EFFECTS\n // =============================================================================\n useEffect(() => {\n initialiseStylesForDocumentBody();\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 // eslint-disable-next-line react-hooks/exhaustive-deps\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 // eslint-disable-next-line react-hooks/exhaustive-deps\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 // eslint-disable-next-line react-hooks/exhaustive-deps\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 initialiseStylesForDocumentBody = () => {\n const documentWidth = document.documentElement.clientWidth;\n const windowWidth = window.innerWidth;\n const scrollBarWidth = windowWidth - documentWidth;\n\n document.documentElement.style.setProperty(\n styles.tokens.global.scrollbarWidth,\n `${scrollBarWidth}px`\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 styles.tokens.global.overlayOpenClass\n );\n\n if (action === \"add\" && !isOverlayStyleClassApplied) {\n document.body.classList.add(styles.tokens.global.overlayOpenClass);\n } else if (action === \"remove\" && isOverlayStyleClassApplied) {\n document.body.classList.remove(\n styles.tokens.global.overlayOpenClass\n );\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 styles.tokens.global.overlayScrollLockClass\n );\n\n if (action === \"add\" && !isClassApplied) {\n document.body.classList.add(\n styles.tokens.global.overlayScrollLockClass\n );\n } else if (action === \"remove\" && isClassApplied) {\n document.body.classList.remove(\n styles.tokens.global.overlayScrollLockClass\n );\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(styles.tokens.global.scrollY, scrollY);\n };\n\n const scrollToLastScrollPositionForIOS = () => {\n if (!isIOS()) {\n return;\n }\n\n const scrollY = document.body.style.getPropertyValue(\n styles.tokens.global.scrollY\n );\n document.body.style.removeProperty(styles.tokens.global.scrollY);\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 <div\n ref={wrapperRef}\n data-testid=\"overlay-wrapper\"\n className={clsx(\n styles.wrapper,\n show ? styles.wrapperShow : styles.wrapperHide,\n isStacked && styles.wrapperStacked,\n backgroundBlur && styles.wrapperBackgroundBlur,\n disableTransition && styles.wrapperDisableTransition\n )}\n onClick={handleWrapperClick}\n >\n {children}\n </div>\n </FloatingNode>\n );\n\n const renderComponent = () => (\n <div\n ref={rootRef}\n id={overlayRootId}\n data-testid={overlayRootId}\n className={clsx(styles.root, show && styles.rootShow)}\n {...themeProps}\n style={themeStyle}\n >\n {children && renderWrapper()}\n </div>\n );\n\n return rootElement\n ? ReactDOM.createPortal(renderComponent(), rootElement)\n : null;\n};\n\n// @catalog\n/**\n * A full-screen dimmed overlay backdrop.\n *\n * Use `Overlay` as the backdrop for modal dialogs, drawers, and similar\n * blocking UI patterns. It manages body scroll-lock automatically and stacks\n * correctly when multiple overlays are open at once.\n * @keywords backdrop, dim, modal\n */\nexport const Overlay = (props: OverlayProps) => {\n return (\n <FloatingTree>\n <OverlayComponent {...props} />\n </FloatingTree>\n );\n};\n"],"names":["OverlayComponent","show","rootId","onOverlayClick","children","backgroundBlur","disableTransition","enableOverlayClick","zIndex","customZIndex","id","containerRef","disableScrollRestore","rootElement","setRootElement","useState","isStacked","_setIsStacked","uid","useId","nodeId","useFloatingNodeId","stacked","useRef","mouseDownInsideModalRef","rootRef","wrapperRef","disableScrollRestoreRef","overlayRootId","themeProps","themeStyle","useInheritedThemeScope","useFloatingParent","useApplyStyle","styles.tokens","root","useEffect","initialiseStylesForDocumentBody","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","documentWidth","documentElement","clientWidth","scrollBarWidth","window","innerWidth","style","setProperty","global","scrollbarWidth","action","isOverlayStyleClassApplied","classList","contains","overlayOpenClass","remove","add","attr","dataset","lifesgDsOverlayOrder","split","order","join","filter","o","isClassApplied","overlayScrollLockClass","bodyStyle","scrollY","top","getPropertyValue","removeProperty","requestAnimationFrame","scrollTo","parseFloat","e","container","_a","wrapper","target","clickedOnWrapper","clickedOnContainer","clickedInsideContainer","handleWrapperClick","event","preventDefault","ReactDOM","createPortal","_jsx","Object","assign","ref","className","clsx","styles.root","styles.rootShow","FloatingNode","styles.wrapper","styles.wrapperShow","styles.wrapperHide","styles.wrapperStacked","styles.wrapperBackgroundBlur","styles.wrapperDisableTransition","onClick","Overlay","props","FloatingTree"],"mappings":"0jCAgBA,MAAMA,EAAmB,EACrBC,QAAO,EACPC,SACAC,iBACAC,WACAC,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,EAAUF,EAAuB,MACjCG,EAAaH,EAAuB,MAEpCI,EAA0BJ,EAAOX,GAEjCgB,EAAgBlB,EAChB,0BAA0BA,IAC1B,yBACAF,EAASC,QAAAA,EAAiBO,EAAY,MAAQ,OAC9Ca,WAAEA,EAAUC,WAAEA,GAAeC,EAAuB9B,GAE1D+B,EAAkBxB,GAElByB,EAAcR,EAAS,CAAE,CAACS,EAAcC,KAAK3B,QAASA,IAKtD4B,GAAU,KACNC,IACAvB,EAAewB,KAER,KACHC,KAEIC,IAAkBC,OAAS,IACvBC,MACAC,GAA2B,UAC3BC,MAGJC,EAAoB,UACxB,IAGL,IAGHT,GAAU,KACFnC,IACA0B,EAAwBmB,QAAUlC,EACtC,GACD,CAACX,EAAMW,IAEVwB,GAAU,KACN,GAAInC,EAAM,CACN,MAAMe,EAAY+B,IAClBC,EAAWhC,GAEXiC,KAEIP,KAAwC,IAA7BF,IAAkBC,SAC7BS,KACAP,GAA2B,QAG/B,MAAMQ,EAAUC,YAAW,KACvBP,EAAoB,MAAM,GAC3B,KAEH,MAAO,IAAMQ,aA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uD,EAAAA,EAAI3E,EAAWoB,QAChDwD,EAAU5E,EAAWoB,QAC3B,IAAKsD,EAED,YADA5E,EAAwBsB,SAAU,GAItC,MAAMyD,EAASK,EAAML,OACfC,EAAmBF,IAAYC,EAC/BE,EAAqBL,IAAcG,EACnCG,EAAyBN,EAAUvB,SAAS0B,IAK7CC,IAJsBC,GAAsBC,IAK5ClF,EAAwBsB,UACzB3C,IACAI,IAEAqG,EAAMC,iBACN1G,KAGJqB,EAAwBsB,SAAU,CAAK,EAsC3C,OAAOjC,EACDiG,EAASC,aAbXC,EAAA,MAAAC,OAAAC,OAAA,CACIC,IAAK1F,EACLf,GAAIkB,EAAa,cACJA,EACbwF,UAAWC,EAAKC,EAAarH,GAAQsH,IACjC1F,EAAU,CACdyC,MAAOxC,WAEN1B,GA3BL4G,EAACQ,EAAY,CAAC9G,GAAIU,EAAMhB,SACpB4G,SACIG,IAAKzF,EAAU,cACH,kBACZ0F,UAAWC,EACPI,EACAxH,EAAOyH,EAAqBC,EAC5B3G,GAAa4G,EACbvH,GAAkBwH,EAClBvH,GAAqBwH,GAEzBC,QAASpB,GAAkBvG,SAE1BA,SAmBkCS,GACzC,IAAI,EAYDmH,EAAWC,GAEhBjB,EAACkB,EAAY,CAAA9H,SACT4G,EAAChH,EAAgBiH,OAAAC,OAAA,CAAA,EAAKe"}
@@ -66,4 +66,16 @@ export interface OverlayProps {
66
66
  * @remarks Falls back to the internal wrapper element when omitted.
67
67
  */
68
68
  containerRef?: React.RefObject<HTMLElement> | undefined;
69
+ /**
70
+ * Prevents the overlay from restoring the page's scroll position when it
71
+ * closes. Useful when the page navigates or scrolls programmatically while
72
+ * the overlay is open, e.g. a loading modal between pages.
73
+ *
74
+ * @remarks
75
+ * - Only has an effect on iOS currently.
76
+ * - The value from the last render while `show` is `true` is used.
77
+ *
78
+ * @default false
79
+ */
80
+ disableScrollRestore?: boolean | undefined;
69
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifesg/react-design-system",
3
- "version": "4.0.0-alpha.15",
3
+ "version": "4.0.0-alpha.16",
4
4
  "description": "A component design system for LifeSG web apps",
5
5
  "keywords": [
6
6
  "design-system"