about summary refs log tree commit diff
path: root/src/components/Dialog/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/Dialog/utils.ts')
-rw-r--r--src/components/Dialog/utils.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/components/Dialog/utils.ts b/src/components/Dialog/utils.ts
new file mode 100644
index 000000000..058d6e804
--- /dev/null
+++ b/src/components/Dialog/utils.ts
@@ -0,0 +1,18 @@
+import React from 'react'
+
+import {DialogControlProps} from '#/components/Dialog/types'
+
+export function useAutoOpen(control: DialogControlProps, showTimeout?: number) {
+  React.useEffect(() => {
+    if (showTimeout) {
+      const timeout = setTimeout(() => {
+        control.open()
+      }, showTimeout)
+      return () => {
+        clearTimeout(timeout)
+      }
+    } else {
+      control.open()
+    }
+  }, [control, showTimeout])
+}