Files
supabase/packages/ui-patterns/ThemeToggle.tsx
Jonathan Summers-Muir 754ee55cd0 chore: update themes and add dark-new theme set (#20865)
* chore: update themes and add dark-new theme set

* chore: update

* add deep dark css theme

* fix issue with wrong class

* chore: add `bg-studio` as a custom remapped color for studio background

* updated surface classes to use a surface-75.

* update backgrounds and borders

* Update CardButton.tsx

* Update NavigationIconButton.tsx

* chore: add theme selection

* Update package.json

* Update index.ts

* Update package.json

* update alias

* Update ThemeSettings.tsx

* chore: split up theme support

* remove old code

* Update index.ts

* add back in

* Update ThemeSettingsOld.tsx

* fix issue with system theme leaking through

* reset themes

* update imports

* packagelock updated

* Update ThemeSettingsWithPreferredTheme.tsx

* Update system.svg

* Update NavigationIconButton.tsx

* Update NavigationBar.tsx

* update

* Update light.css

* updated some colors

* light mode updated

* hacked

* prettier

---------

Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>
Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2024-02-15 16:56:18 +01:00

60 lines
1.9 KiB
TypeScript

import { useTheme } from 'next-themes'
import { useState } from 'react'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger,
IconMoon,
IconSun,
Theme,
themes,
} from 'ui'
interface ThemeToggleProps {
forceDark?: boolean
}
export const ThemeToggle = ({ forceDark = false }: ThemeToggleProps) => {
const { theme, setTheme } = useTheme()
const [open, setOpen] = useState(false)
// Conditionally force the theme to 'dark' when disabled is true
const currentTheme = forceDark ? 'dark' : theme
return (
<DropdownMenu open={open} onOpenChange={() => setOpen(!open)} modal={false}>
<DropdownMenuTrigger asChild disabled={forceDark}>
<button
id="user-settings-dropdown"
className="flex items-center justify-center h-7 w-7 text-foreground"
>
<IconSun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<IconMoon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span className="sr-only">Toggle theme</span>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-60">
<DropdownMenuGroup>
<DropdownMenuRadioGroup
value={currentTheme} // Use the currentTheme variable here
onValueChange={(value) => {
setTheme(value)
}}
>
{themes
.filter((x) => x.value === 'dark' || x.value === 'light' || x.value === 'system')
.map((theme: Theme) => (
<DropdownMenuRadioItem key={theme.value} value={theme.value}>
{theme.name}
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
)
}