mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03: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 -->
114 lines
3.1 KiB
TypeScript
114 lines
3.1 KiB
TypeScript
import { Box, Check, ChevronDown } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import {
|
|
Button,
|
|
cn,
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from 'ui'
|
|
|
|
import { ConnectionType } from './Connect.constants'
|
|
import { ConnectionIcon } from './ConnectionIcon'
|
|
|
|
interface ConnectDropdownProps {
|
|
state: string
|
|
updateState: (state: string) => void
|
|
label: string
|
|
items: ConnectionType[]
|
|
iconFolder?: string
|
|
supportsDarkMode?: boolean
|
|
}
|
|
|
|
export const ConnectDropdown = ({
|
|
state,
|
|
updateState,
|
|
label,
|
|
|
|
items,
|
|
iconFolder,
|
|
supportsDarkMode,
|
|
}: ConnectDropdownProps) => {
|
|
const [open, setOpen] = useState(false)
|
|
|
|
function onSelectLib(key: string) {
|
|
updateState(key)
|
|
setOpen(false)
|
|
}
|
|
|
|
const selectedItem = items.find((item) => item.key === state)
|
|
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen} modal={false}>
|
|
<div className="flex ">
|
|
<span className="flex items-center text-foreground-lighter px-3 rounded-lg rounded-r-none text-xs border border-button border-r-0">
|
|
{label}
|
|
</span>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
size="small"
|
|
type="default"
|
|
className="gap-0 rounded-l-none"
|
|
iconRight={<ChevronDown strokeWidth={1.5} />}
|
|
>
|
|
<div className="flex items-center gap-2">
|
|
{selectedItem?.icon ? (
|
|
<ConnectionIcon
|
|
icon={selectedItem.icon}
|
|
iconFolder={iconFolder}
|
|
supportsDarkMode={supportsDarkMode}
|
|
/>
|
|
) : (
|
|
<Box size={12} />
|
|
)}
|
|
{selectedItem?.label}
|
|
</div>
|
|
</Button>
|
|
</PopoverTrigger>
|
|
</div>
|
|
<PopoverContent className="p-0 max-w-48" side="bottom" align="start">
|
|
<Command>
|
|
<CommandInput placeholder="Search..." />
|
|
<CommandList>
|
|
<CommandEmpty>No results found.</CommandEmpty>
|
|
<CommandGroup>
|
|
{items.map((item) => (
|
|
<CommandItem
|
|
key={item.key}
|
|
value={item.key}
|
|
onSelect={() => {
|
|
onSelectLib(item.key)
|
|
setOpen(false)
|
|
}}
|
|
className="flex gap-2 items-center"
|
|
>
|
|
{item.icon ? (
|
|
<ConnectionIcon
|
|
icon={item.icon}
|
|
iconFolder={iconFolder}
|
|
supportsDarkMode={supportsDarkMode}
|
|
/>
|
|
) : (
|
|
<Box size={12} />
|
|
)}
|
|
{item.label}
|
|
<Check
|
|
size={15}
|
|
className={cn('ml-auto ', item.key === state ? 'opacity-100' : 'opacity-0')}
|
|
/>
|
|
</CommandItem>
|
|
))}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|