about summary refs log tree commit diff
path: root/src/components/Dialog
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-03-05 21:15:42 -0600
committerGitHub <noreply@github.com>2024-03-05 21:15:42 -0600
commit317e0cda7a30d21f35229c096b6ef3284819d19a (patch)
tree1999f3a766966bda7bcc8934ac0a8b45cc7633cd /src/components/Dialog
parente721f84a2cd64bd98f54049bd17925ddf1b194c8 (diff)
downloadvoidsky-317e0cda7a30d21f35229c096b6ef3284819d19a.tar.zst
Add `Menu` component (#3097)
* Add POC menu abstraction

* Better platform handling

* Remove ignore

* Add some menu items

* Add controlled dropdown

* Pass through a11y props

* Ignore uninitialized context

* Tweaks

* Usability improvements

* Rename handlers to props

* Add radix comment

* Ignore known type

* Remove todo

* Move storybook item

* Improve Group matching

* Adjust theming
Diffstat (limited to 'src/components/Dialog')
-rw-r--r--src/components/Dialog/context.ts27
-rw-r--r--src/components/Dialog/types.ts1
2 files changed, 17 insertions, 11 deletions
diff --git a/src/components/Dialog/context.ts b/src/components/Dialog/context.ts
index eb717d8e2..9b571e8e9 100644
--- a/src/components/Dialog/context.ts
+++ b/src/components/Dialog/context.ts
@@ -21,7 +21,8 @@ export function useDialogControl(): DialogOuterProps['control'] {
     open: () => {},
     close: () => {},
   })
-  const {activeDialogs} = useDialogStateContext()
+  const {activeDialogs, openDialogs} = useDialogStateContext()
+  const isOpen = openDialogs.includes(id)
 
   React.useEffect(() => {
     activeDialogs.current.set(id, control)
@@ -31,14 +32,18 @@ export function useDialogControl(): DialogOuterProps['control'] {
     }
   }, [id, activeDialogs])
 
-  return {
-    id,
-    ref: control,
-    open: () => {
-      control.current.open()
-    },
-    close: cb => {
-      control.current.close(cb)
-    },
-  }
+  return React.useMemo<DialogOuterProps['control']>(
+    () => ({
+      id,
+      ref: control,
+      isOpen,
+      open: () => {
+        control.current.open()
+      },
+      close: cb => {
+        control.current.close(cb)
+      },
+    }),
+    [id, control, isOpen],
+  )
 }
diff --git a/src/components/Dialog/types.ts b/src/components/Dialog/types.ts
index 78dfedf5a..fa9398fe0 100644
--- a/src/components/Dialog/types.ts
+++ b/src/components/Dialog/types.ts
@@ -22,6 +22,7 @@ export type DialogControlRefProps = {
 export type DialogControlProps = DialogControlRefProps & {
   id: string
   ref: React.RefObject<DialogControlRefProps>
+  isOpen: boolean
 }
 
 export type DialogContextProps = {