mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-07 22:18:39 +00:00
93 lines
2.2 KiB
TypeScript
93 lines
2.2 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { Button } from "@/examples/base/ui/button"
|
|
import {
|
|
Command,
|
|
CommandEmpty,
|
|
CommandGroup,
|
|
CommandInput,
|
|
CommandItem,
|
|
CommandList,
|
|
} from "@/examples/base/ui/command"
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from "@/examples/base/ui/popover"
|
|
|
|
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 ComboboxPopover() {
|
|
const [open, setOpen] = React.useState(false)
|
|
const [selectedStatus, setSelectedStatus] = React.useState<Status | null>(
|
|
null
|
|
)
|
|
|
|
return (
|
|
<div className="flex items-center space-x-4">
|
|
<p className="text-muted-foreground text-sm">Status</p>
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
<PopoverTrigger
|
|
render={
|
|
<Button variant="outline" className="w-[150px] justify-start" />
|
|
}
|
|
>
|
|
{selectedStatus ? <>{selectedStatus.label}</> : <>+ Set status</>}
|
|
</PopoverTrigger>
|
|
<PopoverContent className="p-0" side="right" align="start">
|
|
<Command>
|
|
<CommandInput placeholder="Change 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>
|
|
</PopoverContent>
|
|
</Popover>
|
|
</div>
|
|
)
|
|
}
|