11import "@/globals.css"
22
33import { useEffect , useMemo , useRef } from "react"
4+ import { DarkModeProvider , useTheme , type DarkModeOption } from "@/dark-mode-context"
45import { RedisProvider , type RedisCredentials } from "@/redis-context"
56import type { TabId } from "@/store"
67import { DatabrowserProvider , useDatabrowserStore } from "@/store"
@@ -9,6 +10,7 @@ import { TooltipProvider } from "@radix-ui/react-tooltip"
910import { QueryClientProvider } from "@tanstack/react-query"
1011
1112import { queryClient } from "@/lib/clients"
13+ import { portalWrapper } from "@/lib/portal-root"
1214
1315import { DatabrowserInstance } from "./components/databrowser-instance"
1416import { DatabrowserTabs } from "./components/databrowser-tabs"
@@ -27,6 +29,7 @@ export const RedisBrowser = ({
2729 hideTabs,
2830 storage,
2931 onFullScreenClick,
32+ theme = "light" ,
3033} : RedisCredentials & {
3134 hideTabs ?: boolean
3235
@@ -49,6 +52,21 @@ export const RedisBrowser = ({
4952 * ```
5053 */
5154 storage ?: RedisBrowserStorage
55+
56+ /**
57+ * Theme configuration (light or dark).
58+ *
59+ * @default "light"
60+ * @example
61+ * ```tsx
62+ * // Light mode (default)
63+ * <RedisBrowser theme="light" />
64+ *
65+ * // Dark mode
66+ * <RedisBrowser theme="dark" />
67+ * ```
68+ */
69+ theme ?: DarkModeOption
5270} ) => {
5371 const credentials = useMemo ( ( ) => ( { token, url } ) , [ token , url ] )
5472 const rootRef = useRef < HTMLDivElement > ( null )
@@ -60,24 +78,53 @@ export const RedisBrowser = ({
6078 return (
6179 < QueryClientProvider client = { queryClient } >
6280 < RedisProvider redisCredentials = { credentials } >
63- < DatabrowserProvider storage = { storage } rootRef = { rootRef } >
64- < TooltipProvider >
65- { /* ups-db is the custom class used to prefix every style in the css bundle */ }
66- < div
67- className = "ups-db"
68- style = { { height : "100%" , display : "flex" , flexDirection : "column" } }
69- ref = { rootRef }
70- >
71- { ! hideTabs && < DatabrowserTabs onFullScreenClick = { onFullScreenClick } /> }
72- < DatabrowserInstances />
73- </ div >
74- </ TooltipProvider >
75- </ DatabrowserProvider >
81+ < DarkModeProvider theme = { theme } >
82+ < DatabrowserProvider storage = { storage } rootRef = { rootRef } >
83+ < TooltipProvider >
84+ < RedisBrowserRoot
85+ hideTabs = { hideTabs }
86+ rootRef = { rootRef }
87+ onFullScreenClick = { onFullScreenClick }
88+ />
89+ </ TooltipProvider >
90+ </ DatabrowserProvider >
91+ </ DarkModeProvider >
7692 </ RedisProvider >
7793 </ QueryClientProvider >
7894 )
7995}
8096
97+ const RedisBrowserRoot = ( {
98+ hideTabs,
99+ rootRef,
100+ onFullScreenClick,
101+ } : {
102+ hideTabs ?: boolean
103+ rootRef : React . RefObject < HTMLDivElement >
104+ onFullScreenClick ?: ( ) => void
105+ } ) => {
106+ const theme = useTheme ( )
107+
108+ useEffect ( ( ) => {
109+ portalWrapper . classList . add ( "text-zinc-700" )
110+ portalWrapper . classList . toggle ( "dark" , theme === "dark" )
111+ } , [ theme ] )
112+
113+ return (
114+ /* ups-db is the custom class used to prefix every style in the css bundle */
115+ < div
116+ className = { `ups-db ${ theme === "dark" ? "dark" : "" } ` }
117+ style = { { height : "100%" } }
118+ ref = { rootRef }
119+ >
120+ < div className = "flex h-full flex-col text-zinc-700" >
121+ { ! hideTabs && < DatabrowserTabs onFullScreenClick = { onFullScreenClick } /> }
122+ < DatabrowserInstances />
123+ </ div >
124+ </ div >
125+ )
126+ }
127+
81128const DatabrowserInstances = ( ) => {
82129 const { tabs, selectedTab, selectTab, addTab } = useDatabrowserStore ( )
83130
0 commit comments