react-modal-sheet 1.11.0 → 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.
- package/README.md +81 -51
- package/dist/SheetBackdrop.d.ts +1 -1
- package/dist/SheetContainer.d.ts +1 -1
- package/dist/SheetContent.d.ts +1 -1
- package/dist/SheetHeader.d.ts +1 -1
- package/dist/SheetScroller.d.ts +5 -0
- package/dist/constants.d.ts +7 -4
- package/dist/context.d.ts +6 -1
- package/dist/hooks.d.ts +2 -2
- package/dist/react-modal-sheet.cjs.development.js +137 -63
- package/dist/react-modal-sheet.cjs.development.js.map +1 -1
- package/dist/react-modal-sheet.cjs.production.min.js +1 -1
- package/dist/react-modal-sheet.cjs.production.min.js.map +1 -1
- package/dist/react-modal-sheet.esm.js +138 -64
- package/dist/react-modal-sheet.esm.js.map +1 -1
- package/dist/sheet.d.ts +1 -1
- package/dist/types.d.ts +17 -2
- package/dist/utils.d.ts +1 -0
- package/package.json +2 -3
- package/src/SheetContent.tsx +9 -4
- package/src/SheetScroller.tsx +59 -0
- package/src/constants.ts +8 -4
- package/src/context.tsx +38 -1
- package/src/hooks.tsx +5 -5
- package/src/index.tsx +2 -0
- package/src/sheet.tsx +19 -13
- package/src/styles.ts +9 -3
- package/src/types.tsx +24 -3
- package/src/utils.ts +20 -26
|
@@ -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 return nums.reduce((prev, curr) => {\n return Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev;\n });\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\n .map(p => sheetHeight - p)\n .filter(p => p >= 0); // negative values can occur with `content-height` detent\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","reduce","prev","curr","Math","abs","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","i","length","inDescendingOrder","onDrag","_","delta","velocity","getVelocity","set","get","onDragEnd","currentY","snapToValues","p","filter","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,UAClCD,EAAKE,QAAO,SAACC,EAAMC,UACjBC,KAAKC,IAAIF,EAAOH,GAAQI,KAAKC,IAAIH,EAAOF,GAAQG,EAAOD,cAwClDI,EAAkBC,OAC1BC,EAAOC,SAASC,cAAc,QAC9BC,EAAOF,SAASG,eAAeL,GAC/BM,EAAYJ,SAASG,eAvCT,+BAkDdD,GAAQE,IAEVF,EAAKG,MAAMC,eAAe,2BAC1BJ,EAAKG,MAAMC,eAAe,0BAC1BJ,EAAKG,MAAMC,eAAe,aAC1BF,EAAUC,MAAME,QAAU,IAG1BL,EAAKM,iBAAiB,0BAjBfC,UACPP,EAAKG,MAAMC,eAAe,YAC1BJ,EAAKG,MAAMC,eAAe,eAC1BJ,EAAKG,MAAMC,eAAe,cAC1BP,EAAKM,MAAMC,eAAe,oBAC1BJ,EAAKQ,oBAAoB,gBAAiBD,YAC1CL,EAAUO,eAAYC,YAAYR,gBAuBtBS,SACdC,IAAAA,OACAC,IAAAA,mBAKID,EAAS,GACXE,QAAQC,qDAC0CF,yBAAiCA,EAC/EpB,KAAKC,IAAIkB,SAIRnB,KAAKuB,IAAIvB,KAAKwB,MAAML,GAAS,OCtFzBM,EAA4BrC,EACrCsC,YACAA,2BAkEYC,EAAeC,OACvBC,EAAMH,kBAEZA,aAAgB,WACdG,EAAIC,QAAUF,KAGTC,EAAIC,iBAKGC,EAA4CC,OACpDC,EAAaP,kBAEnBD,GAA0B,WACxBQ,EAAWH,QAAUE,KAGhBN,eAAkB,mBACjBQ,EAAKD,EAAWH,2BADKK,2BAAAA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AU,2BAA2BhN,MAAO+D,EAAOsB,QACtDrE,gBAACwL,SAAOyB,MACNjB,UAAU,mCACVhN,WAAY+D,EAAOyB,WAAWsE,UAAWgE,MAE3C9M,gBAACwL,SAAOyB,MACNjB,UAAU,mCACVhN,WAAY+D,EAAOyB,WAAWsE,UAAWkE,WC/BjDE,EAAc,SAACC,WAAiBA,EAAMC,WAAaD,EAAME,OAEzDC,EAAgBtN,cACpB,WAA0CG,WAAvCnB,MAAAA,aAAQ,SAAIgN,UAAAA,aAAY,KAAOpG,6BAC1B2H,EAAOL,EAAYtH,GAAQ4F,SAAOgC,OAAShC,SAAOC,IAClDnI,EAAgB4J,EAAYtH,GAAQ,OAAS,cAGjD5F,gBAACuN,mBACK3H,GACJzF,IAAKA,EACL6L,wCAAyCA,EACzChN,WAAY+D,EAAOQ,SAAavE,GAAOsE,cAAAA,IACvCkJ,QAAS,CAAEtN,QAAS,GACpBkJ,QAAS,CAAElJ,QAAS,GACpBuN,KAAM,CAAEvN,QAAS,SCNnBuO,EAAsB7I,EAC5B6I,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,SACNC,SAAU,cCTIE,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,WAsBOO,EAAkBC,OAC1BC,EAAOC,SAASC,cAAc,QAC9BC,EAAOF,SAASG,eAAeL,GAUjCI,IAEFA,EAAKE,MAAMC,eAAe,2BAC1BH,EAAKE,MAAMC,eAAe,0BAC1BH,EAAKE,MAAMC,eAAe,aAG1BH,EAAKI,iBAAiB,0BAffC,IACPL,EAAKE,MAAMC,eAAe,YAC1BH,EAAKE,MAAMC,eAAe,eAC1BH,EAAKE,MAAMC,eAAe,cAC1BN,EAAKK,MAAMC,eAAe,oBAC1BH,EAAKM,oBAAoB,gBAAiBD,gBAsB9BE,SACdC,IAAAA,OACAC,IAAAA,mBAKID,EAAS,GACXE,QAAQC,qD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EACvBkL,EAAatD,EAAe5H,IAAcD,EAG7B,QAAhBgL,GAAyBE,GACT,WAAhBF,GAA4BG,GACZ,SAAhBH,IAA2BE,GAAWC,GAGvCnB,EAAqBxL,iBAErBwL,EAAqBvL,uBAYnB2M,EV2Dc,oBAAXtQ,SACJ,iBAAkBA,QAAUuQ,UAAUC,eAAiB,GU3DxD,CAAEC,kBATY/D,GAChByD,EAAmBzD,EAAEgE,gBAQPC,sBALMjE,GACpByD,EAAmBzD,EAAEgE,sBAKnB5N,SAGFX,uCACMuG,GACJpG,IAAKA,EACLgM,wCAAyCA,EACzChN,WAAYsE,EAAO8B,SAAapG,IAC5BgP,GAEHlN,MCpCHwN,EAAsBhJ,EAC5BgJ,EAAeC,UAAYzC,EAC3BwC,EAAeE,OAAS3B,EACxByB,EAAeG,QAAU9B,EACzB2B,EAAeI,SAAWnB,EAC1Be,EAAeK,SAAWhB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState, createContext, useContext, forwardRef, useImperativeHandle, useMemo,
|
|
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,20 +38,32 @@ 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
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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;
|
|
48
51
|
|
|
49
52
|
function getClosest(nums, goal) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
var closest = nums[0];
|
|
54
|
+
var minDifference = Math.abs(nums[0] - goal);
|
|
55
|
+
|
|
56
|
+
for (var i = 1; i < nums.length; i++) {
|
|
57
|
+
var difference = Math.abs(nums[i] - goal);
|
|
58
|
+
|
|
59
|
+
if (difference < minDifference) {
|
|
60
|
+
closest = nums[i];
|
|
61
|
+
minDifference = difference;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return closest;
|
|
53
66
|
}
|
|
54
|
-
var highlightId = 'react-modal-sheet-highlight';
|
|
55
67
|
function applyRootStyles(rootId) {
|
|
56
68
|
var body = document.querySelector('body');
|
|
57
69
|
var root = document.querySelector("#" + rootId);
|
|
@@ -63,51 +75,30 @@ function applyRootStyles(rootId) {
|
|
|
63
75
|
body.style.backgroundColor = '#000';
|
|
64
76
|
root.style.overflow = 'hidden';
|
|
65
77
|
root.style.willChange = 'transform';
|
|
66
|
-
root.style.transition = 'transform 200ms linear';
|
|
78
|
+
root.style.transition = 'transform 200ms ease-in-out, border-radius 200ms linear';
|
|
67
79
|
root.style.transform = "translateY(calc(env(safe-area-inset-top) + " + p / 2 + "px)) scale(" + s + ")"; // prettier-ignore
|
|
68
80
|
|
|
69
81
|
root.style.borderTopRightRadius = '10px';
|
|
70
|
-
root.style.borderTopLeftRadius = '10px';
|
|
71
|
-
|
|
72
|
-
var highlight = document.createElement('div');
|
|
73
|
-
highlight.setAttribute('aria-hidden', 'true');
|
|
74
|
-
highlight.id = highlightId;
|
|
75
|
-
highlight.style.position = 'absolute';
|
|
76
|
-
highlight.style.top = '0px';
|
|
77
|
-
highlight.style.left = '0px';
|
|
78
|
-
highlight.style.bottom = '0px';
|
|
79
|
-
highlight.style.right = '0px';
|
|
80
|
-
highlight.style.opacity = '0';
|
|
81
|
-
highlight.style.transition = 'opacity 200ms linear';
|
|
82
|
-
highlight.style.backgroundColor = 'rgba(150, 150, 150, 0.1)';
|
|
83
|
-
root.appendChild(highlight);
|
|
84
|
-
requestAnimationFrame(function () {
|
|
85
|
-
return highlight.style.opacity = '1';
|
|
86
|
-
});
|
|
82
|
+
root.style.borderTopLeftRadius = '10px';
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
85
|
function cleanupRootStyles(rootId) {
|
|
90
86
|
var body = document.querySelector('body');
|
|
91
87
|
var root = document.getElementById(rootId);
|
|
92
|
-
var highlight = document.getElementById(highlightId);
|
|
93
88
|
|
|
94
89
|
function onTransitionEnd() {
|
|
95
|
-
var _highlight$parentNode;
|
|
96
|
-
|
|
97
90
|
root.style.removeProperty('overflow');
|
|
98
91
|
root.style.removeProperty('will-change');
|
|
99
92
|
root.style.removeProperty('transition');
|
|
100
93
|
body.style.removeProperty('background-color');
|
|
101
94
|
root.removeEventListener('transitionend', onTransitionEnd);
|
|
102
|
-
(_highlight$parentNode = highlight.parentNode) == null ? void 0 : _highlight$parentNode.removeChild(highlight);
|
|
103
95
|
}
|
|
104
96
|
|
|
105
|
-
if (root
|
|
97
|
+
if (root) {
|
|
106
98
|
// Start animating back
|
|
107
99
|
root.style.removeProperty('border-top-right-radius');
|
|
108
100
|
root.style.removeProperty('border-top-left-radius');
|
|
109
|
-
root.style.removeProperty('transform');
|
|
110
|
-
highlight.style.opacity = '0'; // Remove temp properties after animation is finished
|
|
101
|
+
root.style.removeProperty('transform'); // Remove temp properties after animation is finished
|
|
111
102
|
|
|
112
103
|
root.addEventListener('transitionend', onTransitionEnd);
|
|
113
104
|
}
|
|
@@ -140,9 +131,13 @@ function mergeRefs(refs) {
|
|
|
140
131
|
});
|
|
141
132
|
};
|
|
142
133
|
}
|
|
134
|
+
function isTouchDevice() {
|
|
135
|
+
if (typeof window === 'undefined') return false;
|
|
136
|
+
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
137
|
+
}
|
|
143
138
|
|
|
144
139
|
var useIsomorphicLayoutEffect = IS_SSR ? useEffect : useLayoutEffect;
|
|
145
|
-
|
|
140
|
+
function useModalEffect(isOpen, rootId) {
|
|
146
141
|
var prevOpen = usePrevious(isOpen); // Automatically apply the iOS modal effect to the body when sheet opens/closes
|
|
147
142
|
|
|
148
143
|
useEffect(function () {
|
|
@@ -159,8 +154,8 @@ var useModalEffect = function useModalEffect(isOpen, rootId) {
|
|
|
159
154
|
if (rootId && isOpen) cleanupRootStyles(rootId);
|
|
160
155
|
};
|
|
161
156
|
}, [isOpen]); // eslint-disable-line
|
|
162
|
-
}
|
|
163
|
-
|
|
157
|
+
}
|
|
158
|
+
function useEventCallbacks(isOpen, callbacks) {
|
|
164
159
|
var prevOpen = usePrevious(isOpen);
|
|
165
160
|
var didOpen = useRef(false); // Because of AnimatePrecence we don't have access to latest isOpen value
|
|
166
161
|
// so we need to read and write to a ref to determine if we are
|
|
@@ -187,7 +182,7 @@ var useEventCallbacks = function useEventCallbacks(isOpen, callbacks) {
|
|
|
187
182
|
return {
|
|
188
183
|
handleAnimationComplete: handleAnimationComplete
|
|
189
184
|
};
|
|
190
|
-
}
|
|
185
|
+
}
|
|
191
186
|
function useWindowHeight() {
|
|
192
187
|
var _React$useState = useState(0),
|
|
193
188
|
windowHeight = _React$useState[0],
|
|
@@ -237,6 +232,36 @@ var useSheetContext = function useSheetContext() {
|
|
|
237
232
|
if (!context) throw Error('Sheet context error');
|
|
238
233
|
return context;
|
|
239
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
|
+
};
|
|
240
265
|
|
|
241
266
|
// Source: https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/overlays/src/usePreventScroll.ts
|
|
242
267
|
|
|
@@ -496,7 +521,7 @@ var styles = {
|
|
|
496
521
|
left: 0,
|
|
497
522
|
width: '100%',
|
|
498
523
|
height: '100%',
|
|
499
|
-
backgroundColor: 'rgba(
|
|
524
|
+
backgroundColor: 'rgba(0, 0, 0, 0.2)',
|
|
500
525
|
touchAction: 'none',
|
|
501
526
|
border: 'none'
|
|
502
527
|
},
|
|
@@ -532,9 +557,15 @@ var styles = {
|
|
|
532
557
|
backgroundColor: '#ddd'
|
|
533
558
|
},
|
|
534
559
|
content: {
|
|
535
|
-
|
|
536
|
-
|
|
560
|
+
flexGrow: 1,
|
|
561
|
+
display: 'flex',
|
|
562
|
+
flexDirection: 'column',
|
|
563
|
+
minHeight: '0px',
|
|
537
564
|
position: 'relative'
|
|
565
|
+
},
|
|
566
|
+
scroller: {
|
|
567
|
+
height: '100%',
|
|
568
|
+
overflowY: 'auto'
|
|
538
569
|
}
|
|
539
570
|
};
|
|
540
571
|
|
|
@@ -555,28 +586,27 @@ var Sheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
555
586
|
detent = _ref$detent === void 0 ? 'full-height' : _ref$detent,
|
|
556
587
|
_ref$initialSnap = _ref.initialSnap,
|
|
557
588
|
initialSnap = _ref$initialSnap === void 0 ? 0 : _ref$initialSnap,
|
|
558
|
-
_ref$springConfig = _ref.springConfig,
|
|
559
|
-
springConfig = _ref$springConfig === void 0 ? DEFAULT_SPRING_CONFIG : _ref$springConfig,
|
|
560
589
|
_ref$disableDrag = _ref.disableDrag,
|
|
561
590
|
disableDrag = _ref$disableDrag === void 0 ? false : _ref$disableDrag,
|
|
562
591
|
_ref$prefersReducedMo = _ref.prefersReducedMotion,
|
|
563
592
|
prefersReducedMotion = _ref$prefersReducedMo === void 0 ? false : _ref$prefersReducedMo,
|
|
564
|
-
|
|
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"]);
|
|
565
596
|
|
|
566
597
|
var sheetRef = useRef(null);
|
|
567
598
|
var indicatorRotation = useMotionValue(0);
|
|
568
599
|
var windowHeight = useWindowHeight();
|
|
569
600
|
var shouldReduceMotion = useReducedMotion();
|
|
570
601
|
var reduceMotion = Boolean(prefersReducedMotion || shouldReduceMotion);
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
} :
|
|
575
|
-
type: 'spring'
|
|
576
|
-
}, 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
|
|
577
606
|
// the value driven by the `AnimatePresence` component when the sheet is opened
|
|
578
607
|
// and after that it is driven by the gestures and/or snapping
|
|
579
608
|
|
|
609
|
+
|
|
580
610
|
var y = useMotionValue(0);
|
|
581
611
|
var zIndex = useTransform(y, function (value) {
|
|
582
612
|
return value >= windowHeight ? -1 : 9999999;
|
|
@@ -634,11 +664,8 @@ var Sheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
634
664
|
|
|
635
665
|
if (snapPoints) {
|
|
636
666
|
var snapToValues = snapPoints.map(function (p) {
|
|
637
|
-
return sheetHeight - p;
|
|
638
|
-
})
|
|
639
|
-
return p >= 0;
|
|
640
|
-
}); // negative values can occur with `content-height` detent
|
|
641
|
-
// Allow snapping to the top of the sheet if detent is set to `content-height`
|
|
667
|
+
return sheetHeight - Math.min(p, sheetHeight);
|
|
668
|
+
}); // Allow snapping to the top of the sheet if detent is set to `content-height`
|
|
642
669
|
|
|
643
670
|
if (detent === 'content-height' && !snapToValues.includes(0)) {
|
|
644
671
|
snapToValues.unshift(0);
|
|
@@ -734,7 +761,8 @@ var Sheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
734
761
|
dragProps: dragProps,
|
|
735
762
|
windowHeight: windowHeight,
|
|
736
763
|
animationOptions: animationOptions,
|
|
737
|
-
reduceMotion: reduceMotion
|
|
764
|
+
reduceMotion: reduceMotion,
|
|
765
|
+
disableDrag: disableDrag
|
|
738
766
|
};
|
|
739
767
|
var sheet = createElement(SheetContext.Provider, {
|
|
740
768
|
value: context
|
|
@@ -744,11 +772,11 @@ var Sheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
744
772
|
zIndex: zIndex,
|
|
745
773
|
visibility: visibility
|
|
746
774
|
}, style)
|
|
747
|
-
}), createElement(AnimatePresence, null, isOpen ? Children.map(children, function (child, i) {
|
|
775
|
+
}), createElement(AnimatePresence, null, isOpen ? createElement(SheetScrollerContextProvider, null, Children.map(children, function (child, i) {
|
|
748
776
|
return cloneElement(child, {
|
|
749
777
|
key: "sheet-child-" + i
|
|
750
778
|
});
|
|
751
|
-
}) : null)));
|
|
779
|
+
})) : null)));
|
|
752
780
|
if (IS_SSR) return sheet;
|
|
753
781
|
return createPortal(sheet, mountPoint != null ? mountPoint : document.body);
|
|
754
782
|
});
|
|
@@ -813,16 +841,14 @@ var SheetContent = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
813
841
|
className = _ref$className === void 0 ? '' : _ref$className,
|
|
814
842
|
rest = _objectWithoutPropertiesLoose(_ref, ["children", "style", "disableDrag", "className"]);
|
|
815
843
|
|
|
816
|
-
var
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
var _dragProps = disableDrag ? undefined : dragProps;
|
|
820
|
-
|
|
844
|
+
var sheetContext = useSheetContext();
|
|
845
|
+
var sheetScrollerContext = useSheetScrollerContext();
|
|
846
|
+
var dragProps = disableDrag || sheetScrollerContext.disableDrag ? undefined : sheetContext.dragProps;
|
|
821
847
|
return createElement(motion.div, Object.assign({}, rest, {
|
|
822
848
|
ref: ref,
|
|
823
849
|
className: "react-modal-sheet-content " + className,
|
|
824
850
|
style: _extends({}, styles.content, style)
|
|
825
|
-
},
|
|
851
|
+
}, dragProps), children);
|
|
826
852
|
});
|
|
827
853
|
|
|
828
854
|
var SheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
@@ -893,11 +919,59 @@ var SheetBackdrop = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
893
919
|
}));
|
|
894
920
|
});
|
|
895
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
|
+
|
|
896
969
|
var _SheetCompound = Sheet;
|
|
897
970
|
_SheetCompound.Container = SheetContainer;
|
|
898
971
|
_SheetCompound.Header = SheetHeader;
|
|
899
972
|
_SheetCompound.Content = SheetContent;
|
|
900
973
|
_SheetCompound.Backdrop = SheetBackdrop;
|
|
974
|
+
_SheetCompound.Scroller = SheetScroller;
|
|
901
975
|
|
|
902
976
|
export default _SheetCompound;
|
|
903
977
|
//# sourceMappingURL=react-modal-sheet.esm.js.map
|