{"version":3,"file":"sheetBackdrop.mjs","names":[],"sources":["../../../../package/common/sheetBackdrop/sheetBackdrop.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport cx from 'classnames';\n\nimport styles from '../styles/sheet.module.pcss';\nimport type { SheetBackdropProps } from './sheetBackdrop.types';\n\n/** The pointer events a popup's own outside-click handling listens for. */\nconst SWALLOWED_EVENTS = ['pointerdown', 'pointerup', 'mousedown', 'mouseup', 'touchstart', 'touchend'];\n\n/**\n * The dimmed layer behind a bottom sheet, and the thing that closes it when tapped.\n *\n * It closes on its own `click` rather than letting the sheet's usual outside-click handling see\n * the press, because that handling fires on mousedown/mouseup — and the sheet, backdrop included,\n * unmounts the moment it closes. The browser then dispatches the `click` that completes the tap\n * at whatever is under the cursor by then, which is the page behind the sheet: tapping to dismiss\n * would also press a button underneath it.\n *\n * The press is stopped with native listeners rather than React's `stopPropagation`, which would\n * not be enough: React listens at its own root container, so a native handler on `document` or\n * `window` still runs afterwards.\n */\nfunction SheetBackdrop({ onClose, className, style }: SheetBackdropProps) {\n  const ref = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const element = ref.current;\n    if (!element) return;\n    const stop = (event: Event) => event.stopPropagation();\n    SWALLOWED_EVENTS.forEach((type) => element.addEventListener(type, stop));\n    return () => SWALLOWED_EVENTS.forEach((type) => element.removeEventListener(type, stop));\n  }, []);\n\n  return (\n    <div\n      ref={ref}\n      className={cx(styles.sheetBackdrop, className)}\n      style={style}\n      onClick={(event) => {\n        event.stopPropagation();\n        onClose();\n      }}\n    />\n  );\n}\n\nexport default SheetBackdrop;\n"],"mappings":"uKAOA,IAAM,EAAmB,CAAC,cAAe,YAAa,YAAa,UAAW,aAAc,UAAU,EAetG,SAAS,EAAc,CAAE,UAAS,YAAW,SAA6B,CACxE,IAAM,EAAM,EAAuB,IAAI,EAUvC,OARA,MAAgB,CACd,IAAM,EAAU,EAAI,QACpB,GAAI,CAAC,EAAS,OACd,IAAM,EAAQ,GAAiB,EAAM,gBAAgB,EAErD,OADA,EAAiB,QAAS,GAAS,EAAQ,iBAAiB,EAAM,CAAI,CAAC,MAC1D,EAAiB,QAAS,GAAS,EAAQ,oBAAoB,EAAM,CAAI,CAAC,CACzF,EAAG,CAAC,CAAC,EAGH,EAAC,MAAD,CACO,MACL,UAAW,EAAG,EAAO,cAAe,CAAS,EACtC,QACP,QAAU,GAAU,CAClB,EAAM,gBAAgB,EACtB,EAAQ,CACV,CACD,CAAA,CAEL"}