mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 07:09:07 +03:00
## Problem Our `<Button>` component breaks the default `button` contract by redefining the `type` prop to set its variant (`primary`, `default`, etc) instead of the button type (`submit`, `button`, etc). This is confusing and forces to write more code when using it with shadcn components that expect/inject the standard button props. ## Solution - rename the `type` prop to `variant` - rename the `htmlType` prop to `type` - propagate the changes where necessary - format code ## How to test As this is just prop renaming, if it builds it's ok --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
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"
|
|
variant="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>
|
|
)
|
|
}
|