mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +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>
122 lines
2.8 KiB
TypeScript
122 lines
2.8 KiB
TypeScript
'use client'
|
|
|
|
import { Plus } from 'lucide-react'
|
|
import * as React from 'react'
|
|
import {
|
|
Button,
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
Drawer,
|
|
DrawerContent,
|
|
DrawerTrigger,
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from 'ui'
|
|
|
|
import { useMediaQuery } from '@/hooks/use-media-query'
|
|
|
|
type Status = {
|
|
value: string
|
|
label: string
|
|
}
|
|
|
|
const statuses: Status[] = [
|
|
{
|
|
value: 'backlog',
|
|
label: 'Backlog',
|
|
},
|
|
{
|
|
value: 'todo',
|
|
label: 'Todo',
|
|
},
|
|
{
|
|
value: 'in progress',
|
|
label: 'In Progress',
|
|
},
|
|
{
|
|
value: 'done',
|
|
label: 'Done',
|
|
},
|
|
{
|
|
value: 'canceled',
|
|
label: 'Canceled',
|
|
},
|
|
]
|
|
|
|
export default function ComboBoxResponsive() {
|
|
const [open, setOpen] = React.useState(false)
|
|
const isDesktop = useMediaQuery('(min-width: 768px)')
|
|
const [selectedStatus, setSelectedStatus] = React.useState<Status | null>(null)
|
|
|
|
if (isDesktop) {
|
|
return (
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
variant="default"
|
|
size="small"
|
|
className="w-[150px] justify-start"
|
|
icon={!selectedStatus && <Plus className="text-foreground-muted" />}
|
|
>
|
|
{selectedStatus ? <>{selectedStatus.label}</> : <>Set status</>}
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-[200px] p-0" align="start">
|
|
<StatusList setOpen={setOpen} setSelectedStatus={setSelectedStatus} />
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Drawer open={open} onOpenChange={setOpen}>
|
|
<DrawerTrigger asChild>
|
|
<Button variant="outline" className="w-[150px] justify-start">
|
|
{selectedStatus ? <>{selectedStatus.label}</> : <>+ Set status</>}
|
|
</Button>
|
|
</DrawerTrigger>
|
|
<DrawerContent>
|
|
<div className="mt-4 border-t">
|
|
<StatusList setOpen={setOpen} setSelectedStatus={setSelectedStatus} />
|
|
</div>
|
|
</DrawerContent>
|
|
</Drawer>
|
|
)
|
|
}
|
|
|
|
function StatusList({
|
|
setOpen,
|
|
setSelectedStatus,
|
|
}: {
|
|
setOpen: (open: boolean) => void
|
|
setSelectedStatus: (status: Status | null) => void
|
|
}) {
|
|
return (
|
|
<Command>
|
|
<CommandInput placeholder="Filter status..." />
|
|
<CommandList>
|
|
<CommandEmpty>No results found.</CommandEmpty>
|
|
<CommandGroup>
|
|
{statuses.map((status) => (
|
|
<CommandItem
|
|
key={status.value}
|
|
value={status.value}
|
|
onSelect={(value) => {
|
|
setSelectedStatus(statuses.find((priority) => priority.value === value) || null)
|
|
setOpen(false)
|
|
}}
|
|
>
|
|
{status.label}
|
|
</CommandItem>
|
|
))}
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
)
|
|
}
|