react-modal-sheet 1.11.1 → 2.0.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"react-modal-sheet.cjs.production.min.js","sources":["../src/constants.ts","../src/utils.ts","../src/hooks.tsx","../src/context.tsx","../src/use-prevent-scroll.ts","../src/styles.ts","../src/sheet.tsx","../src/SheetContainer.tsx","../src/SheetContent.tsx","../src/SheetHeader.tsx","../src/SheetBackdrop.tsx","../src/index.tsx"],"sourcesContent":["export const MAX_HEIGHT = 'calc(100% - env(safe-area-inset-top) - 34px)';\n\nexport const IS_SSR = typeof window === 'undefined';\n\nexport const DEFAULT_SPRING_CONFIG = {\n stiffness: 300,\n damping: 30,\n mass: 0.2,\n};\n\nexport const DRAG_CLOSE_THRESHOLD = 0.6;\n\nexport const DRAG_VELOCITY_THRESHOLD = 500;\n","import * as React from 'react';\n\nexport function getClosest(nums: number[], goal: number) {\n let closest = nums[0];\n let minDifference = Math.abs(nums[0] - goal);\n\n for (let i = 1; i < nums.length; i++) {\n const difference = Math.abs(nums[i] - goal);\n if (difference < minDifference) {\n closest = nums[i];\n minDifference = difference;\n }\n }\n\n return closest;\n}\n\nconst highlightId = 'react-modal-sheet-highlight';\n\nexport function applyRootStyles(rootId: string) {\n const body = document.querySelector('body') as HTMLBodyElement;\n const root = document.querySelector(`#${rootId}`) as HTMLDivElement;\n\n if (root) {\n const p = 24;\n const h = window.innerHeight;\n const s = (h - p) / h;\n body.style.backgroundColor = '#000';\n root.style.overflow = 'hidden';\n root.style.willChange = 'transform';\n root.style.transition = 'transform 200ms linear';\n root.style.transform = `translateY(calc(env(safe-area-inset-top) + ${p / 2}px)) scale(${s})`; // prettier-ignore\n root.style.borderTopRightRadius = '10px';\n root.style.borderTopLeftRadius = '10px';\n\n // Add highlighed overlay to emphasize the modality effect\n const highlight = document.createElement('div');\n highlight.setAttribute('aria-hidden', 'true');\n highlight.id = highlightId;\n highlight.style.position = 'absolute';\n highlight.style.top = '0px';\n highlight.style.left = '0px';\n highlight.style.bottom = '0px';\n highlight.style.right = '0px';\n highlight.style.opacity = '0';\n highlight.style.transition = 'opacity 200ms linear';\n highlight.style.backgroundColor = 'rgba(150, 150, 150, 0.1)';\n\n root.appendChild(highlight);\n requestAnimationFrame(() => (highlight.style.opacity = '1'));\n }\n}\n\nexport function cleanupRootStyles(rootId: string) {\n const body = document.querySelector('body') as HTMLBodyElement;\n const root = document.getElementById(rootId) as HTMLDivElement;\n const highlight = document.getElementById(highlightId) as HTMLDivElement;\n\n function onTransitionEnd() {\n root.style.removeProperty('overflow');\n root.style.removeProperty('will-change');\n root.style.removeProperty('transition');\n body.style.removeProperty('background-color');\n root.removeEventListener('transitionend', onTransitionEnd);\n highlight.parentNode?.removeChild(highlight);\n }\n\n if (root && highlight) {\n // Start animating back\n root.style.removeProperty('border-top-right-radius');\n root.style.removeProperty('border-top-left-radius');\n root.style.removeProperty('transform');\n highlight.style.opacity = '0';\n\n // Remove temp properties after animation is finished\n root.addEventListener('transitionend', onTransitionEnd);\n }\n}\n\nexport function inDescendingOrder(arr: number[]) {\n for (let i = 0; i < arr.length; i++) {\n if (arr[i + 1] > arr[i]) return false;\n }\n\n return true;\n}\n\nexport function validateSnapTo({\n snapTo,\n sheetHeight,\n}: {\n snapTo: number;\n sheetHeight: number;\n}) {\n if (snapTo < 0) {\n console.warn(\n `Snap point is out of bounds. Sheet height is ${sheetHeight} but snap point is ${sheetHeight +\n Math.abs(snapTo)}.`\n );\n }\n\n return Math.max(Math.round(snapTo), 0);\n}\n\nexport function mergeRefs<T = any>(\n refs: React.ForwardedRef<T>[]\n): React.RefCallback<T> {\n return (value: any) => {\n refs.forEach((ref: any) => {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n ref.current = value;\n }\n });\n };\n}\n","import * as React from 'react';\n\nimport { IS_SSR } from './constants';\nimport { SheetEvents } from './types';\nimport { applyRootStyles, cleanupRootStyles } from './utils';\n\nexport const useIsomorphicLayoutEffect = IS_SSR\n ? React.useEffect\n : React.useLayoutEffect;\n\nexport const useModalEffect = (isOpen: boolean, rootId?: string) => {\n const prevOpen = usePrevious(isOpen);\n\n // Automatically apply the iOS modal effect to the body when sheet opens/closes\n React.useEffect(() => {\n if (rootId && !prevOpen && isOpen) {\n applyRootStyles(rootId);\n } else if (rootId && !isOpen && prevOpen) {\n cleanupRootStyles(rootId);\n }\n }, [isOpen, prevOpen]); // eslint-disable-line\n\n // Make sure to cleanup modal styles on unmount\n React.useEffect(() => {\n return () => {\n if (rootId && isOpen) cleanupRootStyles(rootId);\n };\n }, [isOpen]); // eslint-disable-line\n};\n\nexport const useEventCallbacks = (\n isOpen: boolean,\n callbacks: React.MutableRefObject<SheetEvents>\n) => {\n const prevOpen = usePrevious(isOpen);\n const didOpen = React.useRef(false);\n\n // Because of AnimatePrecence we don't have access to latest isOpen value\n // so we need to read and write to a ref to determine if we are\n // opening or closing the sheet\n const handleAnimationComplete = React.useCallback(() => {\n if (!didOpen.current) {\n callbacks.current.onOpenEnd?.();\n didOpen.current = true;\n } else {\n callbacks.current.onCloseEnd?.();\n didOpen.current = false;\n }\n }, [isOpen, prevOpen]); // eslint-disable-line\n\n React.useEffect(() => {\n if (!prevOpen && isOpen) {\n callbacks.current.onOpenStart?.();\n } else if (!isOpen && prevOpen) {\n callbacks.current.onCloseStart?.();\n }\n }, [isOpen, prevOpen]); // eslint-disable-line\n\n return { handleAnimationComplete };\n};\n\nexport function useWindowHeight() {\n const [windowHeight, setWindowHeight] = React.useState(0);\n\n useIsomorphicLayoutEffect(() => {\n const updateHeight = () => setWindowHeight(window.innerHeight);\n window.addEventListener('resize', updateHeight);\n updateHeight();\n return () => window.removeEventListener('resize', updateHeight);\n }, []);\n\n return windowHeight;\n}\n\nexport function usePrevious<T>(state: T): T | undefined {\n const ref = React.useRef<T>();\n\n React.useEffect(() => {\n ref.current = state;\n });\n\n return ref.current;\n}\n\n// Userland version of the `useEvent` React hook:\n// RFC: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\nexport function useEvent<T extends (...args: any[]) => any>(handler: T) {\n const handlerRef = React.useRef<T>();\n\n useIsomorphicLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return React.useCallback((...args: any[]) => {\n const fn = handlerRef.current;\n return fn?.(...args);\n }, []) as T;\n}\n","import * as React from 'react';\nimport { SheetContextType } from './types';\n\nexport const SheetContext = React.createContext<SheetContextType | undefined>(\n undefined\n);\n\nexport const useSheetContext = () => {\n const context = React.useContext(SheetContext);\n if (!context) throw Error('Sheet context error');\n return context;\n};\n","// Source: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/overlays/src/usePreventScroll.ts\nimport {\n chain,\n getScrollParent,\n isIOS,\n useLayoutEffect,\n} from '@react-aria/utils';\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n}\n\n// @ts-ignore\nconst visualViewport = typeof window !== 'undefined' && window.visualViewport;\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset',\n]);\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: any;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function usePreventScroll(options: PreventScrollOptions = {}) {\n let { isDisabled } = options;\n\n useLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n } else {\n restore = preventScrollStandard();\n }\n }\n\n return () => {\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore();\n }\n };\n }, [isDisabled]);\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard() {\n return chain(\n setStyle(\n document.documentElement,\n 'paddingRight',\n `${window.innerWidth - document.documentElement.clientWidth}px`\n ),\n setStyle(document.documentElement, 'overflow', 'hidden')\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Prevent default on `touchmove` events inside a scrollable element when the scroll position is at the\n// top or bottom. This avoids the whole page scrolling instead, but does prevent overscrolling.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let lastY = 0;\n let onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target as Element);\n if (\n scrollable === document.documentElement &&\n scrollable === document.body\n ) {\n return;\n }\n\n lastY = e.changedTouches[0].pageY;\n };\n\n let onTouchMove = (e: TouchEvent) => {\n // Prevent scrolling the window.\n if (\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n return;\n }\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead. Unfortunately, this disables bounce scrolling when at\n // the top but it's the best we can do.\n let y = e.changedTouches[0].pageY;\n let scrollTop = scrollable.scrollTop;\n let bottom = scrollable.scrollHeight - scrollable.clientHeight;\n\n // Fix for: https://github.com/adobe/react-spectrum/pull/3780/files\n if (bottom === 0) {\n return;\n }\n\n if ((scrollTop <= 0 && y > lastY) || (scrollTop >= bottom && y < lastY)) {\n e.preventDefault();\n }\n\n lastY = y;\n };\n\n let onTouchEnd = (e: TouchEvent) => {\n let target = e.target as HTMLElement;\n\n // Apply this change if we're not already focused on the target element\n if (willOpenKeyboard(target) && target !== document.activeElement) {\n e.preventDefault();\n\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view. When tapping on an input, this needs to\n // be done before the \"focus\" event, so we have to focus the element ourselves.\n target.style.transform = 'translateY(-2000px)';\n target.focus();\n requestAnimationFrame(() => {\n target.style.transform = '';\n });\n }\n };\n\n let onFocus = (e: FocusEvent) => {\n let target = e.target as HTMLElement;\n if (willOpenKeyboard(target)) {\n // Transform also needs to be applied in the focus event in cases where focus moves\n // other than tapping on an input directly, e.g. the next/previous buttons in the\n // software keyboard. In these cases, it seems applying the transform in the focus event\n // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️\n target.style.transform = 'translateY(-2000px)';\n requestAnimationFrame(() => {\n target.style.transform = '';\n\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(() => {\n scrollIntoView(target);\n });\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener(\n 'resize',\n () => scrollIntoView(target),\n { once: true }\n );\n }\n }\n });\n }\n };\n\n let onWindowScroll = () => {\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n let scrollX = window.pageXOffset;\n let scrollY = window.pageYOffset;\n\n let restoreStyles = chain(\n setStyle(\n document.documentElement,\n 'paddingRight',\n `${window.innerWidth - document.documentElement.clientWidth}px`\n ),\n setStyle(document.documentElement, 'overflow', 'hidden'),\n setStyle(document.body, 'marginTop', `-${scrollY}px`)\n );\n\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\n\n let removeEvents = chain(\n addEvent(document, 'touchstart', onTouchStart, {\n passive: false,\n capture: true,\n }),\n addEvent(document, 'touchmove', onTouchMove, {\n passive: false,\n capture: true,\n }),\n addEvent(document, 'touchend', onTouchEnd, {\n passive: false,\n capture: true,\n }),\n addEvent(document, 'focus', onFocus, true),\n addEvent(window, 'scroll', onWindowScroll)\n );\n\n return () => {\n // Restore styles and scroll the page back to where it was.\n restoreStyles();\n removeEvents();\n window.scrollTo(scrollX, scrollY);\n };\n}\n\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element: any, style: string, value: string) {\n let cur = element.style[style];\n element.style[style] = value;\n\n return () => {\n element.style[style] = cur;\n };\n}\n\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent<K extends keyof GlobalEventHandlersEventMap>(\n target: EventTarget,\n event: K,\n handler: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n target.addEventListener(event, handler as any, options);\n return () => {\n target.removeEventListener(event, handler as any, options);\n };\n}\n\nfunction scrollIntoView(target: Element) {\n let root = document.scrollingElement || document.documentElement;\n while (target && target !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n let scrollable = getScrollParent(target);\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== target\n ) {\n let scrollableTop = scrollable.getBoundingClientRect().top;\n let targetTop = target.getBoundingClientRect().top;\n if (targetTop > scrollableTop + target.clientHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n\n target = scrollable.parentElement as any;\n }\n}\n\nfunction willOpenKeyboard(target: Element) {\n return (\n (target instanceof HTMLInputElement &&\n !nonTextInputTypes.has(target.type)) ||\n target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLElement && target.isContentEditable)\n );\n}\n","import * as CSS from 'csstype';\n\nconst styles: { [key: string]: CSS.Properties } = {\n wrapper: {\n position: 'fixed',\n top: 0,\n bottom: 0,\n left: 0,\n right: 0,\n overflow: 'hidden',\n pointerEvents: 'none',\n },\n backdrop: {\n zIndex: 1,\n position: 'fixed',\n top: 0,\n left: 0,\n width: '100%',\n height: '100%',\n backgroundColor: 'rgba(51, 51, 51, 0.5)',\n touchAction: 'none', // Disable iOS body scrolling\n border: 'none',\n },\n container: {\n zIndex: 2,\n position: 'absolute',\n left: 0,\n bottom: 0,\n width: '100%',\n backgroundColor: '#fff',\n borderTopRightRadius: '8px',\n borderTopLeftRadius: '8px',\n boxShadow: '0px -2px 16px rgba(0, 0, 0, 0.3)',\n display: 'flex',\n flexDirection: 'column',\n pointerEvents: 'auto',\n },\n headerWrapper: {\n width: '100%',\n },\n header: {\n height: '40px',\n width: '100%',\n position: 'relative',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n },\n indicator: {\n width: '18px',\n height: '4px',\n borderRadius: '99px',\n backgroundColor: '#ddd',\n },\n content: {\n flex: 1,\n overflow: 'auto',\n position: 'relative',\n },\n};\n\nexport default styles;\n","import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport {\n animate,\n AnimatePresence,\n motion,\n PanInfo,\n Transition,\n useMotionValue,\n useReducedMotion,\n useTransform,\n} from 'framer-motion';\n\nimport {\n useModalEffect,\n useWindowHeight,\n useIsomorphicLayoutEffect,\n useEvent,\n} from './hooks';\n\nimport {\n DEFAULT_SPRING_CONFIG,\n DRAG_CLOSE_THRESHOLD,\n DRAG_VELOCITY_THRESHOLD,\n IS_SSR,\n} from './constants';\n\nimport { SheetContextType, SheetProps } from './types';\nimport { SheetContext } from './context';\nimport { getClosest, inDescendingOrder, validateSnapTo } from './utils';\nimport { usePreventScroll } from './use-prevent-scroll';\nimport styles from './styles';\n\nconst Sheet = React.forwardRef<any, SheetProps>(\n (\n {\n onOpenStart,\n onOpenEnd,\n onClose,\n onCloseStart,\n onCloseEnd,\n onSnap,\n children,\n isOpen,\n snapPoints,\n rootId,\n mountPoint,\n style,\n detent = 'full-height',\n initialSnap = 0,\n springConfig = DEFAULT_SPRING_CONFIG,\n disableDrag = false,\n prefersReducedMotion = false,\n ...rest\n },\n ref\n ) => {\n const sheetRef = React.useRef<any>(null);\n const indicatorRotation = useMotionValue(0);\n const windowHeight = useWindowHeight();\n const shouldReduceMotion = useReducedMotion();\n const reduceMotion = Boolean(prefersReducedMotion || shouldReduceMotion);\n const animationOptions: Transition = reduceMotion\n ? { type: 'tween', duration: 0.01 }\n : { type: 'spring', ...springConfig };\n\n // NOTE: the inital value for `y` doesn't matter since it is overwritten by\n // the value driven by the `AnimatePresence` component when the sheet is opened\n // and after that it is driven by the gestures and/or snapping\n const y = useMotionValue(0);\n\n const zIndex = useTransform(y, value =>\n value >= windowHeight ? -1 : 9999999\n );\n\n const visibility = useTransform(y, value =>\n value >= windowHeight ? 'hidden' : 'visible'\n );\n\n // Keep the callback fns up-to-date so that they can be accessed inside\n // the effect without including them to the dependencies array\n const callbacks = React.useRef({\n onOpenStart,\n onOpenEnd,\n onCloseStart,\n onCloseEnd,\n });\n\n useIsomorphicLayoutEffect(() => {\n callbacks.current = {\n onOpenStart,\n onOpenEnd,\n onCloseStart,\n onCloseEnd,\n };\n });\n\n if (snapPoints) {\n // Convert negative / percentage snap points to absolute values\n snapPoints = snapPoints.map(point => {\n // Percentage values e.g. between 0.0 and 1.0\n if (point > 0 && point <= 1) return Math.round(point * windowHeight);\n return point < 0 ? windowHeight + point : point; // negative values\n });\n\n console.assert(\n inDescendingOrder(snapPoints) || windowHeight === 0,\n `Snap points need to be in descending order got: [${snapPoints}]`\n );\n }\n\n const onDrag = useEvent((_, { delta }: PanInfo) => {\n // Update drag indicator rotation based on drag velocity\n const velocity = y.getVelocity();\n\n if (velocity > 0) indicatorRotation.set(10);\n if (velocity < 0) indicatorRotation.set(-10);\n\n // Make sure user cannot drag beyond the top of the sheet\n y.set(Math.max(y.get() + delta.y, 0));\n });\n\n const onDragEnd = useEvent((_, { velocity }: PanInfo) => {\n if (velocity.y > DRAG_VELOCITY_THRESHOLD) {\n // User flicked the sheet down\n onClose();\n } else {\n const sheetEl = sheetRef.current as HTMLDivElement;\n const sheetHeight = sheetEl.getBoundingClientRect().height;\n const currentY = y.get();\n\n let snapTo = 0;\n\n if (snapPoints) {\n const snapToValues = snapPoints.map(\n p => sheetHeight - Math.min(p, sheetHeight)\n );\n\n // Allow snapping to the top of the sheet if detent is set to `content-height`\n if (detent === 'content-height' && !snapToValues.includes(0)) {\n snapToValues.unshift(0);\n }\n\n // Get the closest snap point\n snapTo = getClosest(snapToValues, currentY);\n } else if (currentY / sheetHeight > DRAG_CLOSE_THRESHOLD) {\n // Close if dragged over enough far\n snapTo = sheetHeight;\n }\n\n snapTo = validateSnapTo({ snapTo, sheetHeight });\n\n // Update the spring value so that the sheet is animated to the snap point\n animate(y, snapTo, animationOptions);\n\n if (snapPoints && onSnap) {\n const snapValue = Math.abs(Math.round(snapPoints[0] - snapTo));\n const snapIndex = snapPoints.indexOf(getClosest(snapPoints, snapValue)); // prettier-ignore\n onSnap(snapIndex);\n }\n\n const roundedSheetHeight = Math.round(sheetHeight);\n const shouldClose = snapTo >= roundedSheetHeight;\n\n if (shouldClose) onClose();\n }\n\n // Reset indicator rotation after dragging\n indicatorRotation.set(0);\n });\n\n // Trigger onSnap callback when sheet is opened or closed\n React.useEffect(() => {\n if (!snapPoints || !onSnap) return;\n const snapIndex = isOpen ? initialSnap : snapPoints.length - 1;\n onSnap(snapIndex);\n }, [isOpen]); // eslint-disable-line\n\n React.useImperativeHandle(ref, () => ({\n y,\n snapTo: (snapIndex: number) => {\n const sheetEl = sheetRef.current as HTMLDivElement | null;\n\n if (\n snapPoints &&\n snapPoints[snapIndex] !== undefined &&\n sheetEl !== null\n ) {\n const sheetHeight = sheetEl.getBoundingClientRect().height;\n const snapPoint = snapPoints[snapIndex];\n const snapTo = validateSnapTo({\n snapTo: sheetHeight - snapPoint,\n sheetHeight,\n });\n\n animate(y, snapTo, animationOptions);\n if (onSnap) onSnap(snapIndex);\n if (snapTo >= sheetHeight) onClose();\n }\n },\n }));\n\n useModalEffect(isOpen, rootId);\n\n // Framer Motion should handle body scroll locking but it's not working\n // properly on iOS. Scroll locking from React Aria seems to work much better.\n usePreventScroll({ isDisabled: !isOpen });\n\n const dragProps = React.useMemo(() => {\n const dragProps: SheetContextType['dragProps'] = {\n drag: 'y',\n dragElastic: 0,\n dragConstraints: { top: 0, bottom: 0 },\n dragMomentum: false,\n dragPropagation: false,\n onDrag,\n onDragEnd,\n };\n\n return disableDrag ? undefined : dragProps;\n }, [disableDrag]); // eslint-disable-line\n\n const context: SheetContextType = {\n y,\n sheetRef,\n isOpen,\n initialSnap,\n snapPoints,\n detent,\n indicatorRotation,\n callbacks,\n dragProps,\n windowHeight,\n animationOptions,\n reduceMotion,\n };\n\n const sheet = (\n <SheetContext.Provider value={context}>\n <motion.div\n {...rest}\n ref={ref}\n style={{ ...styles.wrapper, zIndex, visibility, ...style }}\n >\n <AnimatePresence>\n {/* NOTE: AnimatePresence requires us to set keys to children */}\n {isOpen\n ? React.Children.map(children, (child: any, i) =>\n React.cloneElement(child, { key: `sheet-child-${i}` })\n )\n : null}\n </AnimatePresence>\n </motion.div>\n </SheetContext.Provider>\n );\n\n if (IS_SSR) return sheet;\n\n return ReactDOM.createPortal(sheet, mountPoint ?? document.body);\n }\n);\n\nexport default Sheet;\n","import * as React from 'react';\nimport { motion } from 'framer-motion';\n\nimport { SheetContainerProps } from './types';\nimport { useSheetContext } from './context';\nimport { useEventCallbacks } from './hooks';\nimport { MAX_HEIGHT } from './constants';\nimport { mergeRefs } from './utils';\nimport styles from './styles';\n\nconst SheetContainer = React.forwardRef<any, SheetContainerProps>(\n ({ children, style = {}, className = '', ...rest }, ref) => {\n const {\n y,\n isOpen,\n callbacks,\n snapPoints,\n initialSnap = 0,\n sheetRef,\n windowHeight,\n detent,\n animationOptions,\n reduceMotion,\n } = useSheetContext();\n\n const { handleAnimationComplete } = useEventCallbacks(isOpen, callbacks);\n const initialY = snapPoints ? snapPoints[0] - snapPoints[initialSnap] : 0;\n const maxSnapHeight = snapPoints ? snapPoints[0] : null;\n\n const height =\n maxSnapHeight !== null\n ? `min(${maxSnapHeight}px, ${MAX_HEIGHT})`\n : MAX_HEIGHT;\n\n return (\n <motion.div\n {...rest}\n ref={mergeRefs([sheetRef, ref])}\n className={`react-modal-sheet-container ${className}`}\n style={{\n ...styles.container,\n ...style,\n ...(detent === 'full-height' && { height }),\n ...(detent === 'content-height' && { maxHeight: height }),\n y,\n }}\n initial={reduceMotion ? false : { y: windowHeight }}\n animate={{ y: initialY, transition: animationOptions }}\n exit={{ y: windowHeight, transition: animationOptions }}\n onAnimationComplete={handleAnimationComplete}\n >\n {children}\n </motion.div>\n );\n }\n);\n\nexport default SheetContainer;\n","import * as React from 'react';\nimport { motion } from 'framer-motion';\n\nimport { SheetDraggableProps } from './types';\nimport { useSheetContext } from './context';\nimport styles from './styles';\n\nconst SheetContent = React.forwardRef<any, SheetDraggableProps>(\n ({ children, style, disableDrag, className = '', ...rest }, ref) => {\n const { dragProps } = useSheetContext();\n const _dragProps = disableDrag ? undefined : dragProps;\n\n return (\n <motion.div\n {...rest}\n ref={ref}\n className={`react-modal-sheet-content ${className}`}\n style={{ ...styles.content, ...style }}\n {..._dragProps}\n >\n {children}\n </motion.div>\n );\n }\n);\n\nexport default SheetContent;\n","import * as React from 'react';\nimport { motion, useTransform } from 'framer-motion';\n\nimport { SheetDraggableProps } from './types';\nimport { useSheetContext } from './context';\nimport styles from './styles';\n\nconst SheetHeader = React.forwardRef<any, SheetDraggableProps>(\n ({ children, style, disableDrag, ...rest }, ref) => {\n const { indicatorRotation, dragProps } = useSheetContext();\n const _dragProps = disableDrag ? undefined : dragProps;\n\n const indicator1Transform = useTransform(\n indicatorRotation,\n r => `translateX(2px) rotate(${r}deg)`\n );\n\n const indicator2Transform = useTransform(\n indicatorRotation,\n r => `translateX(-2px) rotate(${-1 * r}deg)`\n );\n\n return (\n <motion.div\n {...rest}\n ref={ref}\n style={{ ...styles.headerWrapper, ...style }}\n {..._dragProps}\n >\n {children || (\n <div className=\"react-modal-sheet-header\" style={styles.header}>\n <motion.span\n className=\"react-modal-sheet-drag-indicator\"\n style={{ ...styles.indicator, transform: indicator1Transform }}\n />\n <motion.span\n className=\"react-modal-sheet-drag-indicator\"\n style={{ ...styles.indicator, transform: indicator2Transform }}\n />\n </div>\n )}\n </motion.div>\n );\n }\n);\n\nexport default SheetHeader;\n","import * as React from 'react';\nimport { motion } from 'framer-motion';\n\nimport { SheetBackdropProps } from './types';\nimport styles from './styles';\n\nconst isClickable = (props: any) => !!props.onClick || !!props.onTap;\n\nconst SheetBackdrop = React.forwardRef<any, SheetBackdropProps>(\n ({ style = {}, className = '', ...rest }, ref) => {\n const Comp = isClickable(rest) ? motion.button : motion.div;\n const pointerEvents = isClickable(rest) ? 'auto' : 'none';\n\n return (\n <Comp\n {...rest}\n ref={ref}\n className={`react-modal-sheet-backdrop ${className}`}\n style={{ ...styles.backdrop, ...style, pointerEvents }}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n />\n );\n }\n);\n\nexport default SheetBackdrop;\n","import { MotionValue } from 'framer-motion';\n\nimport Sheet from './sheet';\nimport SheetContainer from './SheetContainer';\nimport SheetContent from './SheetContent';\nimport SheetHeader from './SheetHeader';\nimport SheetBackdrop from './SheetBackdrop';\nimport { SheetCompound } from './types';\n\nexport type SheetRef = {\n y: MotionValue<number>;\n snapTo: (index: number) => void;\n};\n\n// HACK: this is needed to get the typing to work properly...\nconst _SheetCompound: any = Sheet;\n_SheetCompound.Container = SheetContainer;\n_SheetCompound.Header = SheetHeader;\n_SheetCompound.Content = SheetContent;\n_SheetCompound.Backdrop = SheetBackdrop;\n\nexport default _SheetCompound as SheetCompound;\n"],"names":["MAX_HEIGHT","IS_SSR","window","DEFAULT_SPRING_CONFIG","stiffness","damping","mass","getClosest","nums","goal","closest","minDifference","Math","abs","i","length","difference","cleanupRootStyles","rootId","body","document","querySelector","root","getElementById","highlight","style","removeProperty","opacity","addEventListener","onTransitionEnd","removeEventListener","parentNode","removeChild","validateSnapTo","snapTo","sheetHeight","console","warn","max","round","useIsomorphicLayoutEffect","React","usePrevious","state","ref","current","useEvent","handler","handlerRef","fn","args","restore","SheetContext","undefined","useSheetContext","context","Error","visualViewport","nonTextInputTypes","Set","preventScrollCount","setStyle","element","value","cur","addEvent","target","event","options","scrollIntoView","scrollingElement","documentElement","scrollable","getScrollParent","scrollableTop","getBoundingClientRect","top","targetTop","clientHeight","scrollTop","parentElement","willOpenKeyboard","HTMLInputElement","has","type","HTMLTextAreaElement","HTMLElement","isContentEditable","styles","wrapper","position","bottom","left","right","overflow","pointerEvents","backdrop","zIndex","width","height","backgroundColor","touchAction","border","container","borderTopRightRadius","borderTopLeftRadius","boxShadow","display","flexDirection","headerWrapper","header","alignItems","justifyContent","indicator","borderRadius","content","flex","Sheet","onOpenStart","onOpenEnd","onClose","onCloseStart","onCloseEnd","onSnap","children","isOpen","snapPoints","mountPoint","detent","initialSnap","springConfig","disableDrag","prefersReducedMotion","rest","sheetRef","indicatorRotation","useMotionValue","windowHeight","setWindowHeight","updateHeight","innerHeight","useWindowHeight","shouldReduceMotion","useReducedMotion","reduceMotion","Boolean","animationOptions","duration","y","useTransform","visibility","callbacks","map","point","assert","arr","inDescendingOrder","onDrag","_","delta","velocity","getVelocity","set","get","onDragEnd","currentY","snapToValues","p","min","includes","unshift","animate","snapValue","snapIndex","indexOf","sheetEl","prevOpen","h","s","willChange","transition","transform","createElement","setAttribute","id","appendChild","requestAnimationFrame","applyRootStyles","useModalEffect","isDisabled","useLayoutEffect","isIOS","lastY","scrollX","pageXOffset","scrollY","pageYOffset","restoreStyles","chain","innerWidth","clientWidth","scrollTo","removeEvents","e","changedTouches","pageY","passive","capture","scrollHeight","preventDefault","activeElement","focus","once","preventScrollMobileSafari","usePreventScroll","dragProps","drag","dragElastic","dragConstraints","dragMomentum","dragPropagation","sheet","Provider","motion","div","AnimatePresence","child","key","ReactDOM","SheetContainer","refs","className","handleAnimationComplete","didOpen","useEventCallbacks","initialY","maxSnapHeight","forEach","maxHeight","initial","exit","onAnimationComplete","SheetContent","_dragProps","SheetHeader","indicator1Transform","r","indicator2Transform","span","isClickable","props","onClick","onTap","SheetBackdrop","Comp","button","_SheetCompound","Container","Header","Content","Backdrop"],"mappings":"+fAAO,IAAMA,EAAa,+CAEbC,EAA2B,oBAAXC,OAEhBC,EAAwB,CACnCC,UAAW,IACXC,QAAS,GACTC,KAAM,aCLQC,EAAWC,EAAgBC,WACrCC,EAAUF,EAAK,GACfG,EAAgBC,KAAKC,IAAIL,EAAK,GAAKC,GAE9BK,EAAI,EAAGA,EAAIN,EAAKO,OAAQD,IAAK,KAC9BE,EAAaJ,KAAKC,IAAIL,EAAKM,GAAKL,GAClCO,EAAaL,IACfD,EAAUF,EAAKM,GACfH,EAAgBK,UAIbN,WAuCOO,EAAkBC,OAC1BC,EAAOC,SAASC,cAAc,QAC9BC,EAAOF,SAASG,eAAeL,GAC/BM,EAAYJ,SAASG,eAvCT,+BAkDdD,GAAQE,IAEVF,EAAKG,MAAMC,eAAe,2BAC1BJ,EAAKG,MAAMC,eA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pBgJ,QAAS,CAAEhJ,QAAS,GACpBqN,KAAM,CAAErN,QAAS,SCNnBqO,EAAsB3I,EAC5B2I,EAAeC,UAAY5B,EAC3B2B,EAAeE,OAASd,EACxBY,EAAeG,QAAUjB,EACzBc,EAAeI,SAAWP"}
1
+ {"version":3,"file":"react-modal-sheet.cjs.production.min.js","sources":["../src/constants.ts","../src/utils.ts","../src/hooks.tsx","../src/context.tsx","../src/use-prevent-scroll.ts","../src/styles.ts","../src/sheet.tsx","../src/SheetContainer.tsx","../src/SheetContent.tsx","../src/SheetHeader.tsx","../src/SheetBackdrop.tsx","../src/SheetScroller.tsx","../src/index.tsx"],"sourcesContent":["export const MAX_HEIGHT = 'calc(100% - env(safe-area-inset-top) - 34px)';\n\nexport const IS_SSR = typeof window === 'undefined';\n\nexport const DEFAULT_TWEEN_CONFIG = {\n ease: 'easeOut',\n duration: 0.2,\n};\n\nexport const REDUCED_MOTION_TWEEN_CONFIG = {\n ease: 'linear',\n duration: 0.01,\n};\n\nexport const DRAG_CLOSE_THRESHOLD = 0.6;\n\nexport const DRAG_VELOCITY_THRESHOLD = 500;\n","import * as React from 'react';\n\nexport function getClosest(nums: number[], goal: number) {\n let closest = nums[0];\n let minDifference = Math.abs(nums[0] - goal);\n\n for (let i = 1; i < nums.length; i++) {\n const difference = Math.abs(nums[i] - goal);\n if (difference < minDifference) {\n closest = nums[i];\n minDifference = difference;\n }\n }\n\n return closest;\n}\n\nexport function applyRootStyles(rootId: string) {\n const body = document.querySelector('body') as HTMLBodyElement;\n const root = document.querySelector(`#${rootId}`) as HTMLDivElement;\n\n if (root) {\n const p = 24;\n const h = window.innerHeight;\n const s = (h - p) / h;\n body.style.backgroundColor = '#000';\n root.style.overflow = 'hidden';\n root.style.willChange = 'transform';\n root.style.transition =\n 'transform 200ms ease-in-out, border-radius 200ms linear';\n root.style.transform = `translateY(calc(env(safe-area-inset-top) + ${p / 2}px)) scale(${s})`; // prettier-ignore\n root.style.borderTopRightRadius = '10px';\n root.style.borderTopLeftRadius = '10px';\n }\n}\n\nexport function cleanupRootStyles(rootId: string) {\n const body = document.querySelector('body') as HTMLBodyElement;\n const root = document.getElementById(rootId) as HTMLDivElement;\n\n function onTransitionEnd() {\n root.style.removeProperty('overflow');\n root.style.removeProperty('will-change');\n root.style.removeProperty('transition');\n body.style.removeProperty('background-color');\n root.removeEventListener('transitionend', onTransitionEnd);\n }\n\n if (root) {\n // Start animating back\n root.style.removeProperty('border-top-right-radius');\n root.style.removeProperty('border-top-left-radius');\n root.style.removeProperty('transform');\n\n // Remove temp properties after animation is finished\n root.addEventListener('transitionend', onTransitionEnd);\n }\n}\n\nexport function inDescendingOrder(arr: number[]) {\n for (let i = 0; i < arr.length; i++) {\n if (arr[i + 1] > arr[i]) return false;\n }\n\n return true;\n}\n\nexport function validateSnapTo({\n snapTo,\n sheetHeight,\n}: {\n snapTo: number;\n sheetHeight: number;\n}) {\n if (snapTo < 0) {\n console.warn(\n `Snap point is out of bounds. Sheet height is ${sheetHeight} but snap point is ${sheetHeight +\n Math.abs(snapTo)}.`\n );\n }\n\n return Math.max(Math.round(snapTo), 0);\n}\n\nexport function mergeRefs<T = any>(\n refs: React.ForwardedRef<T>[]\n): React.RefCallback<T> {\n return (value: any) => {\n refs.forEach((ref: any) => {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n ref.current = value;\n }\n });\n };\n}\n\nexport function isTouchDevice() {\n if (typeof window === 'undefined') return false;\n return 'ontouchstart' in window || navigator.maxTouchPoints > 0;\n}\n","import * as React from 'react';\n\nimport { IS_SSR } from './constants';\nimport { SheetEvents } from './types';\nimport { applyRootStyles, cleanupRootStyles } from './utils';\n\nexport const useIsomorphicLayoutEffect = IS_SSR\n ? React.useEffect\n : React.useLayoutEffect;\n\nexport function useModalEffect(isOpen: boolean, rootId?: string) {\n const prevOpen = usePrevious(isOpen);\n\n // Automatically apply the iOS modal effect to the body when sheet opens/closes\n React.useEffect(() => {\n if (rootId && !prevOpen && isOpen) {\n applyRootStyles(rootId);\n } else if (rootId && !isOpen && prevOpen) {\n cleanupRootStyles(rootId);\n }\n }, [isOpen, prevOpen]); // eslint-disable-line\n\n // Make sure to cleanup modal styles on unmount\n React.useEffect(() => {\n return () => {\n if (rootId && isOpen) cleanupRootStyles(rootId);\n };\n }, [isOpen]); // eslint-disable-line\n}\n\nexport function useEventCallbacks(\n isOpen: boolean,\n callbacks: React.MutableRefObject<SheetEvents>\n) {\n const prevOpen = usePrevious(isOpen);\n const didOpen = React.useRef(false);\n\n // Because of AnimatePrecence we don't have access to latest isOpen value\n // so we need to read and write to a ref to determine if we are\n // opening or closing the sheet\n const handleAnimationComplete = React.useCallback(() => {\n if (!didOpen.current) {\n callbacks.current.onOpenEnd?.();\n didOpen.current = true;\n } else {\n callbacks.current.onCloseEnd?.();\n didOpen.current = false;\n }\n }, [isOpen, prevOpen]); // eslint-disable-line\n\n React.useEffect(() => {\n if (!prevOpen && isOpen) {\n callbacks.current.onOpenStart?.();\n } else if (!isOpen && prevOpen) {\n callbacks.current.onCloseStart?.();\n }\n }, [isOpen, prevOpen]); // eslint-disable-line\n\n return { handleAnimationComplete };\n}\n\nexport function useWindowHeight() {\n const [windowHeight, setWindowHeight] = React.useState(0);\n\n useIsomorphicLayoutEffect(() => {\n const updateHeight = () => setWindowHeight(window.innerHeight);\n window.addEventListener('resize', updateHeight);\n updateHeight();\n return () => window.removeEventListener('resize', updateHeight);\n }, []);\n\n return windowHeight;\n}\n\nexport function usePrevious<T>(state: T): T | undefined {\n const ref = React.useRef<T>();\n\n React.useEffect(() => {\n ref.current = state;\n });\n\n return ref.current;\n}\n\n// Userland version of the `useEvent` React hook:\n// RFC: https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md\nexport function useEvent<T extends (...args: any[]) => any>(handler: T) {\n const handlerRef = React.useRef<T>();\n\n useIsomorphicLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return React.useCallback((...args: any[]) => {\n const fn = handlerRef.current;\n return fn?.(...args);\n }, []) as T;\n}\n","import * as React from 'react';\nimport { SheetScrollerContextType, SheetContextType } from './types';\n\nexport const SheetContext = React.createContext<SheetContextType | undefined>(\n undefined\n);\n\nexport const useSheetContext = () => {\n const context = React.useContext(SheetContext);\n if (!context) throw Error('Sheet context error');\n return context;\n};\n\nexport const SheetScrollerContext = React.createContext<\n SheetScrollerContextType | undefined\n>(undefined);\n\nexport function SheetScrollerContextProvider({\n children,\n}: {\n children: React.ReactNode;\n}) {\n const sheetContext = useSheetContext();\n const [disableDrag, setDisableDrag] = React.useState(\n !!sheetContext.disableDrag\n );\n\n function setDragEnabled() {\n if (!sheetContext.disableDrag) setDisableDrag(false);\n }\n\n function setDragDisabled() {\n if (!disableDrag) setDisableDrag(true);\n }\n\n return (\n <SheetScrollerContext.Provider\n value={{ disableDrag, setDragEnabled, setDragDisabled }}\n >\n {children}\n </SheetScrollerContext.Provider>\n );\n}\n\nexport const useSheetScrollerContext = () => {\n const context = React.useContext(SheetScrollerContext);\n if (!context) throw Error('Sheet scroller context error');\n return context;\n};\n","// Source: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/overlays/src/usePreventScroll.ts\nimport {\n chain,\n getScrollParent,\n isIOS,\n useLayoutEffect,\n} from '@react-aria/utils';\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean;\n}\n\n// @ts-ignore\nconst visualViewport = typeof window !== 'undefined' && window.visualViewport;\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset',\n]);\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore: any;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function usePreventScroll(options: PreventScrollOptions = {}) {\n let { isDisabled } = options;\n\n useLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n } else {\n restore = preventScrollStandard();\n }\n }\n\n return () => {\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore();\n }\n };\n }, [isDisabled]);\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard() {\n return chain(\n setStyle(\n document.documentElement,\n 'paddingRight',\n `${window.innerWidth - document.documentElement.clientWidth}px`\n ),\n setStyle(document.documentElement, 'overflow', 'hidden')\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Prevent default on `touchmove` events inside a scrollable element when the scroll position is at the\n// top or bottom. This avoids the whole page scrolling instead, but does prevent overscrolling.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let lastY = 0;\n let onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target as Element);\n if (\n scrollable === document.documentElement &&\n scrollable === document.body\n ) {\n return;\n }\n\n lastY = e.changedTouches[0].pageY;\n };\n\n let onTouchMove = (e: TouchEvent) => {\n // Prevent scrolling the window.\n if (\n scrollable === document.documentElement ||\n scrollable === document.body\n ) {\n e.preventDefault();\n return;\n }\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead. Unfortunately, this disables bounce scrolling when at\n // the top but it's the best we can do.\n let y = e.changedTouches[0].pageY;\n let scrollTop = scrollable.scrollTop;\n let bottom = scrollable.scrollHeight - scrollable.clientHeight;\n\n // Fix for: https://github.com/adobe/react-spectrum/pull/3780/files\n if (bottom === 0) {\n return;\n }\n\n if ((scrollTop <= 0 && y > lastY) || (scrollTop >= bottom && y < lastY)) {\n e.preventDefault();\n }\n\n lastY = y;\n };\n\n let onTouchEnd = (e: TouchEvent) => {\n let target = e.target as HTMLElement;\n\n // Apply this change if we're not already focused on the target element\n if (willOpenKeyboard(target) && target !== document.activeElement) {\n e.preventDefault();\n\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view. When tapping on an input, this needs to\n // be done before the \"focus\" event, so we have to focus the element ourselves.\n target.style.transform = 'translateY(-2000px)';\n target.focus();\n requestAnimationFrame(() => {\n target.style.transform = '';\n });\n }\n };\n\n let onFocus = (e: FocusEvent) => {\n let target = e.target as HTMLElement;\n if (willOpenKeyboard(target)) {\n // Transform also needs to be applied in the focus event in cases where focus moves\n // other than tapping on an input directly, e.g. the next/previous buttons in the\n // software keyboard. In these cases, it seems applying the transform in the focus event\n // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️\n target.style.transform = 'translateY(-2000px)';\n requestAnimationFrame(() => {\n target.style.transform = '';\n\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(() => {\n scrollIntoView(target);\n });\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener(\n 'resize',\n () => scrollIntoView(target),\n { once: true }\n );\n }\n }\n });\n }\n };\n\n let onWindowScroll = () => {\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n let scrollX = window.pageXOffset;\n let scrollY = window.pageYOffset;\n\n let restoreStyles = chain(\n setStyle(\n document.documentElement,\n 'paddingRight',\n `${window.innerWidth - document.documentElement.clientWidth}px`\n ),\n setStyle(document.documentElement, 'overflow', 'hidden'),\n setStyle(document.body, 'marginTop', `-${scrollY}px`)\n );\n\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\n\n let removeEvents = chain(\n addEvent(document, 'touchstart', onTouchStart, {\n passive: false,\n capture: true,\n }),\n addEvent(document, 'touchmove', onTouchMove, {\n passive: false,\n capture: true,\n }),\n addEvent(document, 'touchend', onTouchEnd, {\n passive: false,\n capture: true,\n }),\n addEvent(document, 'focus', onFocus, true),\n addEvent(window, 'scroll', onWindowScroll)\n );\n\n return () => {\n // Restore styles and scroll the page back to where it was.\n restoreStyles();\n removeEvents();\n window.scrollTo(scrollX, scrollY);\n };\n}\n\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element: any, style: string, value: string) {\n let cur = element.style[style];\n element.style[style] = value;\n\n return () => {\n element.style[style] = cur;\n };\n}\n\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent<K extends keyof GlobalEventHandlersEventMap>(\n target: EventTarget,\n event: K,\n handler: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n target.addEventListener(event, handler as any, options);\n return () => {\n target.removeEventListener(event, handler as any, options);\n };\n}\n\nfunction scrollIntoView(target: Element) {\n let root = document.scrollingElement || document.documentElement;\n while (target && target !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n let scrollable = getScrollParent(target);\n if (\n scrollable !== document.documentElement &&\n scrollable !== document.body &&\n scrollable !== target\n ) {\n let scrollableTop = scrollable.getBoundingClientRect().top;\n let targetTop = target.getBoundingClientRect().top;\n if (targetTop > scrollableTop + target.clientHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n\n target = scrollable.parentElement as any;\n }\n}\n\nfunction willOpenKeyboard(target: Element) {\n return (\n (target instanceof HTMLInputElement &&\n !nonTextInputTypes.has(target.type)) ||\n target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLElement && target.isContentEditable)\n );\n}\n","import * as CSS from 'csstype';\n\nconst styles: { [key: string]: CSS.Properties } = {\n wrapper: {\n position: 'fixed',\n top: 0,\n bottom: 0,\n left: 0,\n right: 0,\n overflow: 'hidden',\n pointerEvents: 'none',\n },\n backdrop: {\n zIndex: 1,\n position: 'fixed',\n top: 0,\n left: 0,\n width: '100%',\n height: '100%',\n backgroundColor: 'rgba(0, 0, 0, 0.2)',\n touchAction: 'none', // Disable iOS body scrolling\n border: 'none',\n },\n container: {\n zIndex: 2,\n position: 'absolute',\n left: 0,\n bottom: 0,\n width: '100%',\n backgroundColor: '#fff',\n borderTopRightRadius: '8px',\n borderTopLeftRadius: '8px',\n boxShadow: '0px -2px 16px rgba(0, 0, 0, 0.3)',\n display: 'flex',\n flexDirection: 'column',\n pointerEvents: 'auto',\n },\n headerWrapper: {\n width: '100%',\n },\n header: {\n height: '40px',\n width: '100%',\n position: 'relative',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n },\n indicator: {\n width: '18px',\n height: '4px',\n borderRadius: '99px',\n backgroundColor: '#ddd',\n },\n content: {\n flexGrow: 1,\n display: 'flex',\n flexDirection: 'column',\n minHeight: '0px',\n position: 'relative',\n },\n scroller: {\n height: '100%',\n overflowY: 'auto',\n },\n};\n\nexport default styles;\n","import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\n\nimport {\n animate,\n AnimatePresence,\n motion,\n PanInfo,\n Transition,\n useMotionValue,\n useReducedMotion,\n useTransform,\n} from 'framer-motion';\n\nimport {\n useModalEffect,\n useWindowHeight,\n useIsomorphicLayoutEffect,\n useEvent,\n} from './hooks';\n\nimport {\n REDUCED_MOTION_TWEEN_CONFIG,\n DEFAULT_TWEEN_CONFIG,\n DRAG_CLOSE_THRESHOLD,\n DRAG_VELOCITY_THRESHOLD,\n IS_SSR,\n} from './constants';\n\nimport { SheetContextType, SheetProps } from './types';\nimport { SheetScrollerContextProvider, SheetContext } from './context';\nimport { getClosest, inDescendingOrder, validateSnapTo } from './utils';\nimport { usePreventScroll } from './use-prevent-scroll';\nimport styles from './styles';\n\nconst Sheet = React.forwardRef<any, SheetProps>(\n (\n {\n onOpenStart,\n onOpenEnd,\n onClose,\n onCloseStart,\n onCloseEnd,\n onSnap,\n children,\n isOpen,\n snapPoints,\n rootId,\n mountPoint,\n style,\n detent = 'full-height',\n initialSnap = 0,\n disableDrag = false,\n prefersReducedMotion = false,\n tweenConfig = DEFAULT_TWEEN_CONFIG,\n ...rest\n },\n ref\n ) => {\n const sheetRef = React.useRef<any>(null);\n const indicatorRotation = useMotionValue(0);\n const windowHeight = useWindowHeight();\n const shouldReduceMotion = useReducedMotion();\n const reduceMotion = Boolean(prefersReducedMotion || shouldReduceMotion);\n const animationOptions: Transition = {\n type: 'tween',\n ...(reduceMotion ? REDUCED_MOTION_TWEEN_CONFIG : tweenConfig),\n };\n\n // NOTE: the inital value for `y` doesn't matter since it is overwritten by\n // the value driven by the `AnimatePresence` component when the sheet is opened\n // and after that it is driven by the gestures and/or snapping\n const y = useMotionValue(0);\n\n const zIndex = useTransform(y, value =>\n value >= windowHeight ? -1 : 9999999\n );\n\n const visibility = useTransform(y, value =>\n value >= windowHeight ? 'hidden' : 'visible'\n );\n\n // Keep the callback fns up-to-date so that they can be accessed inside\n // the effect without including them to the dependencies array\n const callbacks = React.useRef({\n onOpenStart,\n onOpenEnd,\n onCloseStart,\n onCloseEnd,\n });\n\n useIsomorphicLayoutEffect(() => {\n callbacks.current = {\n onOpenStart,\n onOpenEnd,\n onCloseStart,\n onCloseEnd,\n };\n });\n\n if (snapPoints) {\n // Convert negative / percentage snap points to absolute values\n snapPoints = snapPoints.map(point => {\n // Percentage values e.g. between 0.0 and 1.0\n if (point > 0 && point <= 1) return Math.round(point * windowHeight);\n return point < 0 ? windowHeight + point : point; // negative values\n });\n\n console.assert(\n inDescendingOrder(snapPoints) || windowHeight === 0,\n `Snap points need to be in descending order got: [${snapPoints}]`\n );\n }\n\n const onDrag = useEvent((_, { delta }: PanInfo) => {\n // Update drag indicator rotation based on drag velocity\n const velocity = y.getVelocity();\n\n if (velocity > 0) indicatorRotation.set(10);\n if (velocity < 0) indicatorRotation.set(-10);\n\n // Make sure user cannot drag beyond the top of the sheet\n y.set(Math.max(y.get() + delta.y, 0));\n });\n\n const onDragEnd = useEvent((_, { velocity }: PanInfo) => {\n if (velocity.y > DRAG_VELOCITY_THRESHOLD) {\n // User flicked the sheet down\n onClose();\n } else {\n const sheetEl = sheetRef.current as HTMLDivElement;\n const sheetHeight = sheetEl.getBoundingClientRect().height;\n const currentY = y.get();\n\n let snapTo = 0;\n\n if (snapPoints) {\n const snapToValues = snapPoints.map(\n p => sheetHeight - Math.min(p, sheetHeight)\n );\n\n // Allow snapping to the top of the sheet if detent is set to `content-height`\n if (detent === 'content-height' && !snapToValues.includes(0)) {\n snapToValues.unshift(0);\n }\n\n // Get the closest snap point\n snapTo = getClosest(snapToValues, currentY);\n } else if (currentY / sheetHeight > DRAG_CLOSE_THRESHOLD) {\n // Close if dragged over enough far\n snapTo = sheetHeight;\n }\n\n snapTo = validateSnapTo({ snapTo, sheetHeight });\n\n // Update the spring value so that the sheet is animated to the snap point\n animate(y, snapTo, animationOptions);\n\n if (snapPoints && onSnap) {\n const snapValue = Math.abs(Math.round(snapPoints[0] - snapTo));\n const snapIndex = snapPoints.indexOf(getClosest(snapPoints, snapValue)); // prettier-ignore\n onSnap(snapIndex);\n }\n\n const roundedSheetHeight = Math.round(sheetHeight);\n const shouldClose = snapTo >= roundedSheetHeight;\n\n if (shouldClose) onClose();\n }\n\n // Reset indicator rotation after dragging\n indicatorRotation.set(0);\n });\n\n // Trigger onSnap callback when sheet is opened or closed\n React.useEffect(() => {\n if (!snapPoints || !onSnap) return;\n const snapIndex = isOpen ? initialSnap : snapPoints.length - 1;\n onSnap(snapIndex);\n }, [isOpen]); // eslint-disable-line\n\n React.useImperativeHandle(ref, () => ({\n y,\n snapTo: (snapIndex: number) => {\n const sheetEl = sheetRef.current as HTMLDivElement | null;\n\n if (\n snapPoints &&\n snapPoints[snapIndex] !== undefined &&\n sheetEl !== null\n ) {\n const sheetHeight = sheetEl.getBoundingClientRect().height;\n const snapPoint = snapPoints[snapIndex];\n const snapTo = validateSnapTo({\n snapTo: sheetHeight - snapPoint,\n sheetHeight,\n });\n\n animate(y, snapTo, animationOptions);\n if (onSnap) onSnap(snapIndex);\n if (snapTo >= sheetHeight) onClose();\n }\n },\n }));\n\n useModalEffect(isOpen, rootId);\n\n // Framer Motion should handle body scroll locking but it's not working\n // properly on iOS. Scroll locking from React Aria seems to work much better.\n usePreventScroll({ isDisabled: !isOpen });\n\n const dragProps = React.useMemo(() => {\n const dragProps: SheetContextType['dragProps'] = {\n drag: 'y',\n dragElastic: 0,\n dragConstraints: { top: 0, bottom: 0 },\n dragMomentum: false,\n dragPropagation: false,\n onDrag,\n onDragEnd,\n };\n\n return disableDrag ? undefined : dragProps;\n }, [disableDrag]); // eslint-disable-line\n\n const context: SheetContextType = {\n y,\n sheetRef,\n isOpen,\n initialSnap,\n snapPoints,\n detent,\n indicatorRotation,\n callbacks,\n dragProps,\n windowHeight,\n animationOptions,\n reduceMotion,\n disableDrag,\n };\n\n const sheet = (\n <SheetContext.Provider value={context}>\n <motion.div\n {...rest}\n ref={ref}\n style={{ ...styles.wrapper, zIndex, visibility, ...style }}\n >\n <AnimatePresence>\n {/* NOTE: AnimatePresence requires us to set keys to children */}\n {isOpen ? (\n <SheetScrollerContextProvider>\n {React.Children.map(children, (child: any, i) =>\n React.cloneElement(child, { key: `sheet-child-${i}` })\n )}\n </SheetScrollerContextProvider>\n ) : null}\n </AnimatePresence>\n </motion.div>\n </SheetContext.Provider>\n );\n\n if (IS_SSR) return sheet;\n\n return ReactDOM.createPortal(sheet, mountPoint ?? document.body);\n }\n);\n\nexport default Sheet;\n","import * as React from 'react';\nimport { motion } from 'framer-motion';\n\nimport { SheetContainerProps } from './types';\nimport { useSheetContext } from './context';\nimport { useEventCallbacks } from './hooks';\nimport { MAX_HEIGHT } from './constants';\nimport { mergeRefs } from './utils';\nimport styles from './styles';\n\nconst SheetContainer = React.forwardRef<any, SheetContainerProps>(\n ({ children, style = {}, className = '', ...rest }, ref) => {\n const {\n y,\n isOpen,\n callbacks,\n snapPoints,\n initialSnap = 0,\n sheetRef,\n windowHeight,\n detent,\n animationOptions,\n reduceMotion,\n } = useSheetContext();\n\n const { handleAnimationComplete } = useEventCallbacks(isOpen, callbacks);\n const initialY = snapPoints ? snapPoints[0] - snapPoints[initialSnap] : 0;\n const maxSnapHeight = snapPoints ? snapPoints[0] : null;\n\n const height =\n maxSnapHeight !== null\n ? `min(${maxSnapHeight}px, ${MAX_HEIGHT})`\n : MAX_HEIGHT;\n\n return (\n <motion.div\n {...rest}\n ref={mergeRefs([sheetRef, ref])}\n className={`react-modal-sheet-container ${className}`}\n style={{\n ...styles.container,\n ...style,\n ...(detent === 'full-height' && { height }),\n ...(detent === 'content-height' && { maxHeight: height }),\n y,\n }}\n initial={reduceMotion ? false : { y: windowHeight }}\n animate={{ y: initialY, transition: animationOptions }}\n exit={{ y: windowHeight, transition: animationOptions }}\n onAnimationComplete={handleAnimationComplete}\n >\n {children}\n </motion.div>\n );\n }\n);\n\nexport default SheetContainer;\n","import * as React from 'react';\nimport { motion } from 'framer-motion';\n\nimport { SheetDraggableProps } from './types';\nimport { useSheetScrollerContext, useSheetContext } from './context';\nimport styles from './styles';\n\nconst SheetContent = React.forwardRef<any, SheetDraggableProps>(\n ({ children, style, disableDrag, className = '', ...rest }, ref) => {\n const sheetContext = useSheetContext();\n const sheetScrollerContext = useSheetScrollerContext();\n\n const dragProps =\n disableDrag || sheetScrollerContext.disableDrag\n ? undefined\n : sheetContext.dragProps;\n\n return (\n <motion.div\n {...rest}\n ref={ref}\n className={`react-modal-sheet-content ${className}`}\n style={{ ...styles.content, ...style }}\n {...dragProps}\n >\n {children}\n </motion.div>\n );\n }\n);\n\nexport default SheetContent;\n","import * as React from 'react';\nimport { motion, useTransform } from 'framer-motion';\n\nimport { SheetDraggableProps } from './types';\nimport { useSheetContext } from './context';\nimport styles from './styles';\n\nconst SheetHeader = React.forwardRef<any, SheetDraggableProps>(\n ({ children, style, disableDrag, ...rest }, ref) => {\n const { indicatorRotation, dragProps } = useSheetContext();\n const _dragProps = disableDrag ? undefined : dragProps;\n\n const indicator1Transform = useTransform(\n indicatorRotation,\n r => `translateX(2px) rotate(${r}deg)`\n );\n\n const indicator2Transform = useTransform(\n indicatorRotation,\n r => `translateX(-2px) rotate(${-1 * r}deg)`\n );\n\n return (\n <motion.div\n {...rest}\n ref={ref}\n style={{ ...styles.headerWrapper, ...style }}\n {..._dragProps}\n >\n {children || (\n <div className=\"react-modal-sheet-header\" style={styles.header}>\n <motion.span\n className=\"react-modal-sheet-drag-indicator\"\n style={{ ...styles.indicator, transform: indicator1Transform }}\n />\n <motion.span\n className=\"react-modal-sheet-drag-indicator\"\n style={{ ...styles.indicator, transform: indicator2Transform }}\n />\n </div>\n )}\n </motion.div>\n );\n }\n);\n\nexport default SheetHeader;\n","import * as React from 'react';\nimport { motion } from 'framer-motion';\n\nimport { SheetBackdropProps } from './types';\nimport styles from './styles';\n\nconst isClickable = (props: any) => !!props.onClick || !!props.onTap;\n\nconst SheetBackdrop = React.forwardRef<any, SheetBackdropProps>(\n ({ style = {}, className = '', ...rest }, ref) => {\n const Comp = isClickable(rest) ? motion.button : motion.div;\n const pointerEvents = isClickable(rest) ? 'auto' : 'none';\n\n return (\n <Comp\n {...rest}\n ref={ref}\n className={`react-modal-sheet-backdrop ${className}`}\n style={{ ...styles.backdrop, ...style, pointerEvents }}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n />\n );\n }\n);\n\nexport default SheetBackdrop;\n","import * as React from 'react';\n\nimport { useSheetScrollerContext } from './context';\nimport { SheetScrollerProps } from './types';\nimport { isTouchDevice } from './utils';\nimport styles from './styles';\n\nconst SheetScroller = React.forwardRef<any, SheetScrollerProps>(\n ({ draggableAt = 'top', children, style, className = '', ...rest }, ref) => {\n const sheetScrollerContext = useSheetScrollerContext();\n\n function determineDragState(element: HTMLDivElement) {\n const { scrollTop, scrollHeight, clientHeight } = element;\n const isScrollable = scrollHeight > clientHeight;\n\n if (!isScrollable) return;\n\n const isAtTop = scrollTop <= 0;\n const isAtBottom = scrollHeight - scrollTop === clientHeight;\n\n const shouldEnable =\n (draggableAt === 'top' && isAtTop) ||\n (draggableAt === 'bottom' && isAtBottom) ||\n (draggableAt === 'both' && (isAtTop || isAtBottom));\n\n if (shouldEnable) {\n sheetScrollerContext.setDragEnabled();\n } else {\n sheetScrollerContext.setDragDisabled();\n }\n }\n\n function onScroll(e: React.UIEvent<HTMLDivElement>) {\n determineDragState(e.currentTarget);\n }\n\n function onTouchStart(e: React.TouchEvent<HTMLDivElement>) {\n determineDragState(e.currentTarget);\n }\n\n const scrollProps = isTouchDevice()\n ? { onScroll, onTouchStart }\n : undefined;\n\n return (\n <div\n {...rest}\n ref={ref}\n className={`react-modal-sheet-scroller ${className}`}\n style={{ ...styles.scroller, ...style }}\n {...scrollProps}\n >\n {children}\n </div>\n );\n }\n);\n\nexport default SheetScroller;\n","import { MotionValue } from 'framer-motion';\n\nimport Sheet from './sheet';\nimport SheetContainer from './SheetContainer';\nimport SheetContent from './SheetContent';\nimport SheetHeader from './SheetHeader';\nimport SheetBackdrop from './SheetBackdrop';\nimport SheetScroller from './SheetScroller';\nimport { SheetCompound } from './types';\n\nexport type SheetRef = {\n y: MotionValue<number>;\n snapTo: (index: number) => void;\n};\n\n// HACK: this is needed to get the typing to work properly...\nconst _SheetCompound: any = Sheet;\n_SheetCompound.Container = SheetContainer;\n_SheetCompound.Header = SheetHeader;\n_SheetCompound.Content = SheetContent;\n_SheetCompound.Backdrop = SheetBackdrop;\n_SheetCompound.Scroller = SheetScroller;\n\nexport default _SheetCompound as SheetCompound;\n"],"names":["MAX_HEIGHT","IS_SSR","window","DEFAULT_TWEEN_CONFIG","ease","duration","REDUCED_MOTION_TWEEN_CONFIG","getClosest","nums","goal","closest","minDifference","Math","abs","i","length","difference","cleanupRootStyles","rootId","body","document","querySelector","root","getElementById","style","removeProperty","addEventListener","onTransitionEnd","removeEventListener","validateSnapTo","snapTo","sheetHeight","console","warn","max","round","useIsomorphicLayoutEffect","React","usePrevious","state","ref","current","useEvent","handler","handlerRef","fn","args","SheetContext","undefined","useSheetContext","context","Error","SheetScrollerContext","SheetScrollerContextProvider","children","sheetContext","disableDrag","setDisableDrag","Provider","value","setDragEnabled","setDragDisabled","restore","useSheetScrollerContext","visualViewport","nonTextInputTypes","Set","preventScrollCount","setStyle","element","cur","addEvent","target","event","options","scrollIntoView","scrollingElement","documentElement","scrollable","getScrollParent","scrollableTop","getBoundingClientRect","top","targetTop","clientHeight","scrollTop","parentElement","willOpenKeyboard","HTMLInputElement","has","type","HTMLTextAreaElement","HTMLElement","isContentEditable","styles","wrapper","position","bottom","left","right","overflow","pointerEvents","backdrop","zIndex","width","height","backgroundColor","touchAction","border","container","borderTopRightRadius","borderTopLeftRadius","boxShadow","display","flexDirection","headerWrapper","header","alignItems","justifyContent","indicator","borderRadius","content","flexGrow","minHeight","scroller","overflowY","Sheet","onOpenStart","onOpenEnd","onClose","onCloseStart","onCloseEnd","onSnap","isOpen","snapPoints","mountPoint","detent","initialSnap","prefersReducedMotion","tweenConfig","rest","sheetRef","indicatorRotation","useMotionValue","windowHeight","setWindowHeight","updateHeight","innerHeight","useWindowHeight","shouldReduceMotion","useReducedMotion","reduceMotion","Boolean","animationOptions","y","useTransform","visibility","callbacks","map","point","assert","arr","inDescendingOrder","onDrag","_","delta","velocity","getVelocity","set","get","onDragEnd","currentY","snapToValues","p","min","includes","unshift","animate","snapValue","snapIndex","indexOf","sheetEl","prevOpen","h","s","willChange","transition","transform","applyRootStyles","useModalEffect","isDisabled","useLayoutEffect","isIOS","lastY","scrollX","pageXOffset","scrollY","pageYOffset","restoreStyles","chain","innerWidth","clientWidth","scrollTo","removeEvents","e","changedTouches","pageY","passive","capture","scrollHeight","preventDefault","activeElement","focus","requestAnimationFrame","once","preventScrollMobileSafari","usePreventScroll","dragProps","drag","dragElastic","dragConstraints","dragMomentum","dragPropagation","sheet","motion","div","AnimatePresence","child","key","ReactDOM","SheetContainer","refs","className","handleAnimationComplete","didOpen","useEventCallbacks","initialY","maxSnapHeight","forEach","maxHeight","initial","exit","onAnimationComplete","SheetContent","sheetScrollerContext","SheetHeader","_dragProps","indicator1Transform","r","indicator2Transform","span","isClickable","props","onClick","onTap","SheetBackdrop","Comp","button","opacity","SheetScroller","draggableAt","determineDragState","isAtTop","isAtBottom","scrollProps","navigator","maxTouchPoints","onScroll","currentTarget","onTouchStart","_SheetCompound","Container","Header","Content","Backdrop","Scroller"],"mappings":"+fAAO,IAAMA,EAAa,+CAEbC,EAA2B,oBAAXC,OAEhBC,EAAuB,CAClCC,KAAM,UACNC,SAAU,IAGCC,EAA8B,CACzCF,KAAM,SACN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1,4 @@
1
- import { useCallback, useEffect, useLayoutEffect, useRef, useState, createContext, useContext, forwardRef, useImperativeHandle, useMemo, createElement, Children, cloneElement } from 'react';
1
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState, createContext, useContext, createElement, forwardRef, useImperativeHandle, useMemo, Children, cloneElement } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { useMotionValue, useReducedMotion, useTransform, animate, motion, AnimatePresence } from 'framer-motion';
4
4
  import { useLayoutEffect as useLayoutEffect$1, isIOS, chain, getScrollParent } from '@react-aria/utils';
@@ -38,10 +38,13 @@ function _objectWithoutPropertiesLoose(source, excluded) {
38
38
 
39
39
  var MAX_HEIGHT = 'calc(100% - env(safe-area-inset-top) - 34px)';
40
40
  var IS_SSR = typeof window === 'undefined';
41
- var DEFAULT_SPRING_CONFIG = {
42
- stiffness: 300,
43
- damping: 30,
44
- mass: 0.2
41
+ var DEFAULT_TWEEN_CONFIG = {
42
+ ease: 'easeOut',
43
+ duration: 0.2
44
+ };
45
+ var REDUCED_MOTION_TWEEN_CONFIG = {
46
+ ease: 'linear',
47
+ duration: 0.01
45
48
  };
46
49
  var DRAG_CLOSE_THRESHOLD = 0.6;
47
50
  var DRAG_VELOCITY_THRESHOLD = 500;
@@ -61,7 +64,6 @@ function getClosest(nums, goal) {
61
64
 
62
65
  return closest;
63
66
  }
64
- var highlightId = 'react-modal-sheet-highlight';
65
67
  function applyRootStyles(rootId) {
66
68
  var body = document.querySelector('body');
67
69
  var root = document.querySelector("#" + rootId);
@@ -73,51 +75,30 @@ function applyRootStyles(rootId) {
73
75
  body.style.backgroundColor = '#000';
74
76
  root.style.overflow = 'hidden';
75
77
  root.style.willChange = 'transform';
76
- root.style.transition = 'transform 200ms linear';
78
+ root.style.transition = 'transform 200ms ease-in-out, border-radius 200ms linear';
77
79
  root.style.transform = "translateY(calc(env(safe-area-inset-top) + " + p / 2 + "px)) scale(" + s + ")"; // prettier-ignore
78
80
 
79
81
  root.style.borderTopRightRadius = '10px';
80
- root.style.borderTopLeftRadius = '10px'; // Add highlighed overlay to emphasize the modality effect
81
-
82
- var highlight = document.createElement('div');
83
- highlight.setAttribute('aria-hidden', 'true');
84
- highlight.id = highlightId;
85
- highlight.style.position = 'absolute';
86
- highlight.style.top = '0px';
87
- highlight.style.left = '0px';
88
- highlight.style.bottom = '0px';
89
- highlight.style.right = '0px';
90
- highlight.style.opacity = '0';
91
- highlight.style.transition = 'opacity 200ms linear';
92
- highlight.style.backgroundColor = 'rgba(150, 150, 150, 0.1)';
93
- root.appendChild(highlight);
94
- requestAnimationFrame(function () {
95
- return highlight.style.opacity = '1';
96
- });
82
+ root.style.borderTopLeftRadius = '10px';
97
83
  }
98
84
  }
99
85
  function cleanupRootStyles(rootId) {
100
86
  var body = document.querySelector('body');
101
87
  var root = document.getElementById(rootId);
102
- var highlight = document.getElementById(highlightId);
103
88
 
104
89
  function onTransitionEnd() {
105
- var _highlight$parentNode;
106
-
107
90
  root.style.removeProperty('overflow');
108
91
  root.style.removeProperty('will-change');
109
92
  root.style.removeProperty('transition');
110
93
  body.style.removeProperty('background-color');
111
94
  root.removeEventListener('transitionend', onTransitionEnd);
112
- (_highlight$parentNode = highlight.parentNode) == null ? void 0 : _highlight$parentNode.removeChild(highlight);
113
95
  }
114
96
 
115
- if (root && highlight) {
97
+ if (root) {
116
98
  // Start animating back
117
99
  root.style.removeProperty('border-top-right-radius');
118
100
  root.style.removeProperty('border-top-left-radius');
119
- root.style.removeProperty('transform');
120
- highlight.style.opacity = '0'; // Remove temp properties after animation is finished
101
+ root.style.removeProperty('transform'); // Remove temp properties after animation is finished
121
102
 
122
103
  root.addEventListener('transitionend', onTransitionEnd);
123
104
  }
@@ -150,9 +131,13 @@ function mergeRefs(refs) {
150
131
  });
151
132
  };
152
133
  }
134
+ function isTouchDevice() {
135
+ if (typeof window === 'undefined') return false;
136
+ return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
137
+ }
153
138
 
154
139
  var useIsomorphicLayoutEffect = IS_SSR ? useEffect : useLayoutEffect;
155
- var useModalEffect = function useModalEffect(isOpen, rootId) {
140
+ function useModalEffect(isOpen, rootId) {
156
141
  var prevOpen = usePrevious(isOpen); // Automatically apply the iOS modal effect to the body when sheet opens/closes
157
142
 
158
143
  useEffect(function () {
@@ -169,8 +154,8 @@ var useModalEffect = function useModalEffect(isOpen, rootId) {
169
154
  if (rootId && isOpen) cleanupRootStyles(rootId);
170
155
  };
171
156
  }, [isOpen]); // eslint-disable-line
172
- };
173
- var useEventCallbacks = function useEventCallbacks(isOpen, callbacks) {
157
+ }
158
+ function useEventCallbacks(isOpen, callbacks) {
174
159
  var prevOpen = usePrevious(isOpen);
175
160
  var didOpen = useRef(false); // Because of AnimatePrecence we don't have access to latest isOpen value
176
161
  // so we need to read and write to a ref to determine if we are
@@ -197,7 +182,7 @@ var useEventCallbacks = function useEventCallbacks(isOpen, callbacks) {
197
182
  return {
198
183
  handleAnimationComplete: handleAnimationComplete
199
184
  };
200
- };
185
+ }
201
186
  function useWindowHeight() {
202
187
  var _React$useState = useState(0),
203
188
  windowHeight = _React$useState[0],
@@ -247,6 +232,36 @@ var useSheetContext = function useSheetContext() {
247
232
  if (!context) throw Error('Sheet context error');
248
233
  return context;
249
234
  };
235
+ var SheetScrollerContext = /*#__PURE__*/createContext(undefined);
236
+ function SheetScrollerContextProvider(_ref) {
237
+ var children = _ref.children;
238
+ var sheetContext = useSheetContext();
239
+
240
+ var _React$useState = useState(!!sheetContext.disableDrag),
241
+ disableDrag = _React$useState[0],
242
+ setDisableDrag = _React$useState[1];
243
+
244
+ function setDragEnabled() {
245
+ if (!sheetContext.disableDrag) setDisableDrag(false);
246
+ }
247
+
248
+ function setDragDisabled() {
249
+ if (!disableDrag) setDisableDrag(true);
250
+ }
251
+
252
+ return createElement(SheetScrollerContext.Provider, {
253
+ value: {
254
+ disableDrag: disableDrag,
255
+ setDragEnabled: setDragEnabled,
256
+ setDragDisabled: setDragDisabled
257
+ }
258
+ }, children);
259
+ }
260
+ var useSheetScrollerContext = function useSheetScrollerContext() {
261
+ var context = useContext(SheetScrollerContext);
262
+ if (!context) throw Error('Sheet scroller context error');
263
+ return context;
264
+ };
250
265
 
251
266
  // Source: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/overlays/src/usePreventScroll.ts
252
267
 
@@ -506,7 +521,7 @@ var styles = {
506
521
  left: 0,
507
522
  width: '100%',
508
523
  height: '100%',
509
- backgroundColor: 'rgba(51, 51, 51, 0.5)',
524
+ backgroundColor: 'rgba(0, 0, 0, 0.2)',
510
525
  touchAction: 'none',
511
526
  border: 'none'
512
527
  },
@@ -542,9 +557,15 @@ var styles = {
542
557
  backgroundColor: '#ddd'
543
558
  },
544
559
  content: {
545
- flex: 1,
546
- overflow: 'auto',
560
+ flexGrow: 1,
561
+ display: 'flex',
562
+ flexDirection: 'column',
563
+ minHeight: '0px',
547
564
  position: 'relative'
565
+ },
566
+ scroller: {
567
+ height: '100%',
568
+ overflowY: 'auto'
548
569
  }
549
570
  };
550
571
 
@@ -565,28 +586,27 @@ var Sheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
565
586
  detent = _ref$detent === void 0 ? 'full-height' : _ref$detent,
566
587
  _ref$initialSnap = _ref.initialSnap,
567
588
  initialSnap = _ref$initialSnap === void 0 ? 0 : _ref$initialSnap,
568
- _ref$springConfig = _ref.springConfig,
569
- springConfig = _ref$springConfig === void 0 ? DEFAULT_SPRING_CONFIG : _ref$springConfig,
570
589
  _ref$disableDrag = _ref.disableDrag,
571
590
  disableDrag = _ref$disableDrag === void 0 ? false : _ref$disableDrag,
572
591
  _ref$prefersReducedMo = _ref.prefersReducedMotion,
573
592
  prefersReducedMotion = _ref$prefersReducedMo === void 0 ? false : _ref$prefersReducedMo,
574
- rest = _objectWithoutPropertiesLoose(_ref, ["onOpenStart", "onOpenEnd", "onClose", "onCloseStart", "onCloseEnd", "onSnap", "children", "isOpen", "snapPoints", "rootId", "mountPoint", "style", "detent", "initialSnap", "springConfig", "disableDrag", "prefersReducedMotion"]);
593
+ _ref$tweenConfig = _ref.tweenConfig,
594
+ tweenConfig = _ref$tweenConfig === void 0 ? DEFAULT_TWEEN_CONFIG : _ref$tweenConfig,
595
+ rest = _objectWithoutPropertiesLoose(_ref, ["onOpenStart", "onOpenEnd", "onClose", "onCloseStart", "onCloseEnd", "onSnap", "children", "isOpen", "snapPoints", "rootId", "mountPoint", "style", "detent", "initialSnap", "disableDrag", "prefersReducedMotion", "tweenConfig"]);
575
596
 
576
597
  var sheetRef = useRef(null);
577
598
  var indicatorRotation = useMotionValue(0);
578
599
  var windowHeight = useWindowHeight();
579
600
  var shouldReduceMotion = useReducedMotion();
580
601
  var reduceMotion = Boolean(prefersReducedMotion || shouldReduceMotion);
581
- var animationOptions = reduceMotion ? {
582
- type: 'tween',
583
- duration: 0.01
584
- } : _extends({
585
- type: 'spring'
586
- }, springConfig); // NOTE: the inital value for `y` doesn't matter since it is overwritten by
602
+
603
+ var animationOptions = _extends({
604
+ type: 'tween'
605
+ }, reduceMotion ? REDUCED_MOTION_TWEEN_CONFIG : tweenConfig); // NOTE: the inital value for `y` doesn't matter since it is overwritten by
587
606
  // the value driven by the `AnimatePresence` component when the sheet is opened
588
607
  // and after that it is driven by the gestures and/or snapping
589
608
 
609
+
590
610
  var y = useMotionValue(0);
591
611
  var zIndex = useTransform(y, function (value) {
592
612
  return value >= windowHeight ? -1 : 9999999;
@@ -741,7 +761,8 @@ var Sheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
741
761
  dragProps: dragProps,
742
762
  windowHeight: windowHeight,
743
763
  animationOptions: animationOptions,
744
- reduceMotion: reduceMotion
764
+ reduceMotion: reduceMotion,
765
+ disableDrag: disableDrag
745
766
  };
746
767
  var sheet = createElement(SheetContext.Provider, {
747
768
  value: context
@@ -751,11 +772,11 @@ var Sheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
751
772
  zIndex: zIndex,
752
773
  visibility: visibility
753
774
  }, style)
754
- }), createElement(AnimatePresence, null, isOpen ? Children.map(children, function (child, i) {
775
+ }), createElement(AnimatePresence, null, isOpen ? createElement(SheetScrollerContextProvider, null, Children.map(children, function (child, i) {
755
776
  return cloneElement(child, {
756
777
  key: "sheet-child-" + i
757
778
  });
758
- }) : null)));
779
+ })) : null)));
759
780
  if (IS_SSR) return sheet;
760
781
  return createPortal(sheet, mountPoint != null ? mountPoint : document.body);
761
782
  });
@@ -820,16 +841,14 @@ var SheetContent = /*#__PURE__*/forwardRef(function (_ref, ref) {
820
841
  className = _ref$className === void 0 ? '' : _ref$className,
821
842
  rest = _objectWithoutPropertiesLoose(_ref, ["children", "style", "disableDrag", "className"]);
822
843
 
823
- var _useSheetContext = useSheetContext(),
824
- dragProps = _useSheetContext.dragProps;
825
-
826
- var _dragProps = disableDrag ? undefined : dragProps;
827
-
844
+ var sheetContext = useSheetContext();
845
+ var sheetScrollerContext = useSheetScrollerContext();
846
+ var dragProps = disableDrag || sheetScrollerContext.disableDrag ? undefined : sheetContext.dragProps;
828
847
  return createElement(motion.div, Object.assign({}, rest, {
829
848
  ref: ref,
830
849
  className: "react-modal-sheet-content " + className,
831
850
  style: _extends({}, styles.content, style)
832
- }, _dragProps), children);
851
+ }, dragProps), children);
833
852
  });
834
853
 
835
854
  var SheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
@@ -900,11 +919,59 @@ var SheetBackdrop = /*#__PURE__*/forwardRef(function (_ref, ref) {
900
919
  }));
901
920
  });
902
921
 
922
+ var SheetScroller = /*#__PURE__*/forwardRef(function (_ref, ref) {
923
+ var _ref$draggableAt = _ref.draggableAt,
924
+ draggableAt = _ref$draggableAt === void 0 ? 'top' : _ref$draggableAt,
925
+ children = _ref.children,
926
+ style = _ref.style,
927
+ _ref$className = _ref.className,
928
+ className = _ref$className === void 0 ? '' : _ref$className,
929
+ rest = _objectWithoutPropertiesLoose(_ref, ["draggableAt", "children", "style", "className"]);
930
+
931
+ var sheetScrollerContext = useSheetScrollerContext();
932
+
933
+ function determineDragState(element) {
934
+ var scrollTop = element.scrollTop,
935
+ scrollHeight = element.scrollHeight,
936
+ clientHeight = element.clientHeight;
937
+ var isScrollable = scrollHeight > clientHeight;
938
+ if (!isScrollable) return;
939
+ var isAtTop = scrollTop <= 0;
940
+ var isAtBottom = scrollHeight - scrollTop === clientHeight;
941
+ var shouldEnable = draggableAt === 'top' && isAtTop || draggableAt === 'bottom' && isAtBottom || draggableAt === 'both' && (isAtTop || isAtBottom);
942
+
943
+ if (shouldEnable) {
944
+ sheetScrollerContext.setDragEnabled();
945
+ } else {
946
+ sheetScrollerContext.setDragDisabled();
947
+ }
948
+ }
949
+
950
+ function onScroll(e) {
951
+ determineDragState(e.currentTarget);
952
+ }
953
+
954
+ function onTouchStart(e) {
955
+ determineDragState(e.currentTarget);
956
+ }
957
+
958
+ var scrollProps = isTouchDevice() ? {
959
+ onScroll: onScroll,
960
+ onTouchStart: onTouchStart
961
+ } : undefined;
962
+ return createElement("div", Object.assign({}, rest, {
963
+ ref: ref,
964
+ className: "react-modal-sheet-scroller " + className,
965
+ style: _extends({}, styles.scroller, style)
966
+ }, scrollProps), children);
967
+ });
968
+
903
969
  var _SheetCompound = Sheet;
904
970
  _SheetCompound.Container = SheetContainer;
905
971
  _SheetCompound.Header = SheetHeader;
906
972
  _SheetCompound.Content = SheetContent;
907
973
  _SheetCompound.Backdrop = SheetBackdrop;
974
+ _SheetCompound.Scroller = SheetScroller;
908
975
 
909
976
  export default _SheetCompound;
910
977
  //# sourceMappingURL=react-modal-sheet.esm.js.map