about summary refs log tree commit diff
path: root/modules/bottom-sheet/src/BottomSheetPortal.tsx
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-10-09 21:30:42 +0300
committerGitHub <noreply@github.com>2024-10-09 11:30:42 -0700
commitcca344a3d1cdca3d4e63806a9bd5f7867f8961d4 (patch)
tree999d7dffe5d53989b7e217db13f451c6d019ff57 /modules/bottom-sheet/src/BottomSheetPortal.tsx
parentb3ade19bbe3da3caf07bf9561cebb11dac4b6afc (diff)
downloadvoidsky-cca344a3d1cdca3d4e63806a9bd5f7867f8961d4.tar.zst
Allow nested sheets without boilerplate (#5660)
Co-authored-by: Hailey <me@haileyok.com>
Diffstat (limited to 'modules/bottom-sheet/src/BottomSheetPortal.tsx')
-rw-r--r--modules/bottom-sheet/src/BottomSheetPortal.tsx40
1 files changed, 40 insertions, 0 deletions
diff --git a/modules/bottom-sheet/src/BottomSheetPortal.tsx b/modules/bottom-sheet/src/BottomSheetPortal.tsx
new file mode 100644
index 000000000..da14cfa77
--- /dev/null
+++ b/modules/bottom-sheet/src/BottomSheetPortal.tsx
@@ -0,0 +1,40 @@
+import React from 'react'
+
+import {createPortalGroup_INTERNAL} from './lib/Portal'
+
+type PortalContext = React.ElementType<{children: React.ReactNode}>
+
+const Context = React.createContext({} as PortalContext)
+
+export const useBottomSheetPortal_INTERNAL = () => React.useContext(Context)
+
+export function BottomSheetPortalProvider({
+  children,
+}: {
+  children: React.ReactNode
+}) {
+  const portal = React.useMemo(() => {
+    return createPortalGroup_INTERNAL()
+  }, [])
+
+  return (
+    <Context.Provider value={portal.Portal}>
+      <portal.Provider>
+        {children}
+        <portal.Outlet />
+      </portal.Provider>
+    </Context.Provider>
+  )
+}
+
+const defaultPortal = createPortalGroup_INTERNAL()
+
+export const BottomSheetOutlet = defaultPortal.Outlet
+
+export function BottomSheetProvider({children}: {children: React.ReactNode}) {
+  return (
+    <Context.Provider value={defaultPortal.Portal}>
+      <defaultPortal.Provider>{children}</defaultPortal.Provider>
+    </Context.Provider>
+  )
+}