mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## Problem - We still use/maintain the legacy theming even though we moved to Shadcn - We have two themes list with similar code ## Solution - Migrate some components to `cva` and `cn` instead of `styleHandler` - Remove redundant `themes` in favor of `singleThemes` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Standardized theme selection across the app so theme menus consistently offer the same light/dark/system options, including dropdowns, navigation menus, and command menus. * **Refactor** * Refreshed styling for multiple shared UI components (menus, tabs, side panels, loading indicators, icons, and modal dialogs) to improve consistency while preserving visual behavior. * **Chores** * Improved the UI patterns CI “validate exports” check for clearer failure output when exports change unexpectedly. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
100 lines
3.2 KiB
TypeScript
100 lines
3.2 KiB
TypeScript
import { FlaskConical, Settings } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import Link from 'next/link'
|
|
import { useRouter } from 'next/router'
|
|
import {
|
|
cn,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuRadioGroup,
|
|
DropdownMenuRadioItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
singleThemes,
|
|
} from 'ui'
|
|
|
|
import { ButtonTooltip } from '../ui/ButtonTooltip'
|
|
import { useFeaturePreviewModal } from './App/FeaturePreview/FeaturePreviewContext'
|
|
import { ProfileImage } from '@/components/ui/ProfileImage'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
export const LocalDropdown = ({
|
|
triggerClassName,
|
|
contentClassName,
|
|
}: {
|
|
triggerClassName?: string
|
|
contentClassName?: string
|
|
}) => {
|
|
const router = useRouter()
|
|
const { theme, setTheme } = useTheme()
|
|
const appStateSnapshot = useAppStateSnapshot()
|
|
const { toggleFeaturePreviewModal } = useFeaturePreviewModal()
|
|
const track = useTrack()
|
|
|
|
return (
|
|
<DropdownMenu
|
|
onOpenChange={(open) => {
|
|
if (open) track('header_local_dropdown_opened')
|
|
}}
|
|
>
|
|
<DropdownMenuTrigger className={cn('border shrink-0 px-3', triggerClassName)} asChild>
|
|
<ButtonTooltip
|
|
variant="default"
|
|
className="[&>span]:flex px-0 py-0 rounded-full overflow-hidden h-8 w-8"
|
|
tooltip={{ content: { text: 'Settings' } }}
|
|
>
|
|
<ProfileImage className="w-8 h-8 rounded-md" />
|
|
<span className="sr-only">Settings</span>
|
|
</ButtonTooltip>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="bottom" align="end" className={cn('w-44', contentClassName)}>
|
|
<DropdownMenuItem className="flex gap-2 cursor-pointer" asChild>
|
|
<Link
|
|
href="/account/me"
|
|
onClick={() => {
|
|
if (router.pathname !== '/account/me') {
|
|
appStateSnapshot.setLastRouteBeforeVisitingAccountPage(router.asPath)
|
|
}
|
|
}}
|
|
>
|
|
<Settings size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Preferences
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
className="flex gap-2 cursor-pointer"
|
|
onClick={() => toggleFeaturePreviewModal(true)}
|
|
onSelect={() => toggleFeaturePreviewModal(true)}
|
|
>
|
|
<FlaskConical size={14} strokeWidth={1.5} className="text-foreground-lighter" />
|
|
Feature previews
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuLabel>Theme</DropdownMenuLabel>
|
|
<DropdownMenuRadioGroup
|
|
value={theme}
|
|
onValueChange={(value) => {
|
|
setTheme(value)
|
|
}}
|
|
>
|
|
{singleThemes.map((theme) => (
|
|
<DropdownMenuRadioItem
|
|
key={theme.value}
|
|
value={theme.value}
|
|
className="cursor-pointer"
|
|
>
|
|
{theme.name}
|
|
</DropdownMenuRadioItem>
|
|
))}
|
|
</DropdownMenuRadioGroup>
|
|
</DropdownMenuGroup>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|