Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: create select for theme option in navigation-bar

Harsh Karandee27547d27796
diff --git a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
index be9ca0cb30d..d37f6245343 100644
--- a/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
+++ b/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.tsx
@@ -1,9 +1,9 @@
-import React, { FC } from 'react'
+import React, { FC, useEffect, useState } from 'react'
import Link from 'next/link'
import { observer } from 'mobx-react-lite'
import { useRouter } from 'next/router'
import { isUndefined } from 'lodash'
-import { Button, Divider, IconHome, Dropdown, IconUser, Toggle, Typography } from '@supabase/ui'
+import { Button, Divider, IconHome, Dropdown, IconUser, Select, Typography } from '@supabase/ui'
import { IS_PLATFORM } from 'lib/constants'
import { useStore } from 'hooks'
@@ -21,6 +21,28 @@ const NavigationBar: FC<Props> = ({}) => {
const productRoutes = generateProductRoutes(projectRef)
const otherRoutes = generateOtherRoutes(projectRef)
+ const [value, setValue] = useState('')
+
+ useEffect(() => {
+ const localStorageThemeOption = window.localStorage.getItem('theme') as string
+ if (localStorageThemeOption) return setValue(localStorageThemeOption)
+ window.localStorage.setItem('theme', 'dark')
+ setValue('dark')
+ }, [])
+
+ const onThemeOptionChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
+ const themeOption = e.target.value as 'dark' | 'light' | 'system'
+ setValue(themeOption)
+ if (themeOption === 'system') {
+ window.localStorage.setItem('theme', 'system')
+ return ui.setTheme(
+ window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
+ )
+ }
+ window.localStorage.setItem('theme', themeOption)
+ ui.setTheme(themeOption)
+ }
+
return (
<div className="h-screen w-14 flex flex-col justify-between p-2 overflow-y-hidden bg-sidebar-light dark:bg-sidebar-dark border-r dark:border-dark">
<ul className="flex flex-col space-y-2">
@@ -77,13 +99,13 @@ const NavigationBar: FC<Props> = ({}) => {
: []),
<Divider key="d1" light />,
<Dropdown.Misc key="theme">
- <div className="w-[200px] pt-1">
- <Toggle
- size="small"
- label="Enable dark mode"
- checked={ui.isDarkTheme}
- onChange={() => ui.toggleTheme()}
- />
+ <div className="w-[240px] py-1 flex items-center justify-between">
+ <Typography.Text>Theme</Typography.Text>
+ <Select value={value} onChange={onThemeOptionChange}>
+ <Select.Option value="system">System default</Select.Option>
+ <Select.Option value="dark">Dark</Select.Option>
+ <Select.Option value="light">Light</Select.Option>
+ </Select>
</div>
</Dropdown.Misc>,
]}