mirror of
https://github.com/supabase/supabase.git
synced 2026-06-09 03:22:27 +08:00
## Problem The `_Shadcn_` suffix isn't needed anymore on `Command` components ## Solution - Remove the `_Shadcn_` suffix - Simplify UI package exports - Apply prettier <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Simplified command component imports and exports across the UI library by removing internal naming aliases and adopting direct component references. Updated the public UI package barrel export to use wildcard re-exports for cleaner API surface. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46153?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
113 lines
3.8 KiB
TypeScript
113 lines
3.8 KiB
TypeScript
'use client'
|
|
|
|
import { CircleIcon, LaptopIcon, MoonIcon, SunIcon } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import { useRouter } from 'next/navigation'
|
|
import * as React from 'react'
|
|
import {
|
|
Button,
|
|
CommandDialog,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
CommandSeparator,
|
|
DialogProps,
|
|
} from 'ui'
|
|
|
|
import { COMMAND_ITEMS } from '@/config/docs'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
export function CommandMenu({ ...props }: DialogProps) {
|
|
const router = useRouter()
|
|
const [open, setOpen] = React.useState(false)
|
|
const { setTheme } = useTheme()
|
|
|
|
React.useEffect(() => {
|
|
const down = (e: KeyboardEvent) => {
|
|
if ((e.key === 'k' && (e.metaKey || e.ctrlKey)) || e.key === '/') {
|
|
if (
|
|
(e.target instanceof HTMLElement && e.target.isContentEditable) ||
|
|
e.target instanceof HTMLInputElement ||
|
|
e.target instanceof HTMLTextAreaElement ||
|
|
e.target instanceof HTMLSelectElement
|
|
) {
|
|
return
|
|
}
|
|
|
|
e.preventDefault()
|
|
setOpen((open) => !open)
|
|
}
|
|
}
|
|
|
|
document.addEventListener('keydown', down)
|
|
return () => document.removeEventListener('keydown', down)
|
|
}, [])
|
|
|
|
const runCommand = React.useCallback((command: () => unknown) => {
|
|
setOpen(false)
|
|
command()
|
|
}, [])
|
|
|
|
return (
|
|
<>
|
|
<Button
|
|
type="outline"
|
|
className={cn(
|
|
`relative h-8 w-full justify-start rounded-[0.5rem] bg-background text-sm font-normal text-foreground-muted shadow-none sm:pr-12
|
|
hover:border-foreground-muted hover:bg-surface-100 hover:text-foreground-lighter
|
|
`
|
|
)}
|
|
onClick={() => setOpen(true)}
|
|
{...props}
|
|
>
|
|
<span className="hidden lg:inline-flex">Search...</span>
|
|
<span className="inline-flex lg:hidden">Search...</span>
|
|
<kbd className="pointer-events-none absolute right-[0.3rem] top-[0.3rem] hidden h-5 select-none items-center gap-1 rounded border bg-surface-200 px-1.5 font-mono text-[10px] font-medium opacity-100 sm:flex text-foreground-light">
|
|
<span className="text-sm">⌘</span>K
|
|
</kbd>
|
|
</Button>
|
|
<CommandDialog open={open} onOpenChange={setOpen}>
|
|
<CommandInput placeholder="Type a command or search..." />
|
|
<CommandList>
|
|
<CommandEmpty>No results found.</CommandEmpty>
|
|
<CommandGroup key="pages" heading="Pages">
|
|
{COMMAND_ITEMS.map((navItem) => (
|
|
<CommandItem
|
|
key={navItem.href}
|
|
value={navItem.label}
|
|
onSelect={() => runCommand(() => router.push(navItem.href as string))}
|
|
>
|
|
<div className="mr-2 flex h-4 w-4 items-center justify-center">
|
|
<CircleIcon className="h-3 w-3" strokeWidth={1} />
|
|
</div>
|
|
{navItem.label}
|
|
</CommandItem>
|
|
))}
|
|
</CommandGroup>
|
|
<CommandSeparator />
|
|
<CommandGroup heading="Theme">
|
|
<CommandItem onSelect={() => runCommand(() => setTheme('light'))}>
|
|
<SunIcon className="mr-2 h-4 w-4" strokeWidth={1} />
|
|
Light
|
|
</CommandItem>
|
|
<CommandItem onSelect={() => runCommand(() => setTheme('dark'))}>
|
|
<MoonIcon className="mr-2 h-4 w-4" strokeWidth={1} />
|
|
Dark
|
|
</CommandItem>
|
|
<CommandItem onSelect={() => runCommand(() => setTheme('classic-dark'))}>
|
|
<MoonIcon className="mr-2 h-4 w-4" strokeWidth={1} />
|
|
Classic dark
|
|
</CommandItem>
|
|
<CommandItem onSelect={() => runCommand(() => setTheme('system'))}>
|
|
<LaptopIcon className="mr-2 h-4 w-4" strokeWidth={1} />
|
|
System
|
|
</CommandItem>
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</CommandDialog>
|
|
</>
|
|
)
|
|
}
|