-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcombobox-badges.tsx
76 lines (70 loc) · 2.25 KB
/
combobox-badges.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use client'
import { Dispatch, SetStateAction, useState } from 'react'
import { LIST_BADGES } from '@/badges'
import { Check, ChevronsUpDown } from 'lucide-react'
import { BadgeOption } from '@/types/builder'
import { cn } from '@/lib/utils'
import { Button } from '@/components/ui/button'
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem
} from '@/components/ui/command'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
type ComboboxBadgesProps = {
setBadgeOptionData: Dispatch<SetStateAction<BadgeOption>>
}
export function ComboboxBadges({ setBadgeOptionData }: ComboboxBadgesProps) {
const [open, setOpen] = useState(false)
const [value, setValue] = useState('frontend')
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant='outline'
role='combobox'
aria-expanded={open}
className='w-full justify-between'
>
{value
? LIST_BADGES.find((item) => item.label.toLowerCase() === value)?.label
: 'Select badge category...'}
<ChevronsUpDown className='ml-2 size-4 shrink-0 opacity-50' />
</Button>
</PopoverTrigger>
<PopoverContent className='w-full p-0'>
<Command>
<CommandInput placeholder='Search category...' />
<CommandEmpty>No badge found.</CommandEmpty>
<CommandGroup>
{LIST_BADGES.map(({ id, label, data }) => (
<CommandItem
key={id}
value={label}
onSelect={(currentValue) => {
setValue(currentValue === value.toLowerCase() ? '' : currentValue)
setOpen(false)
setBadgeOptionData({
id,
label,
data
})
}}
>
{label}
<Check
className={cn(
'ml-auto size-4',
value === label.toLowerCase() ? 'opacity-100' : 'opacity-0'
)}
/>
</CommandItem>
))}
</CommandGroup>
</Command>
</PopoverContent>
</Popover>
)
}