-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathListBox.tsx
More file actions
66 lines (63 loc) · 2.28 KB
/
Copy pathListBox.tsx
File metadata and controls
66 lines (63 loc) · 2.28 KB
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
import { ReactElement } from 'react';
interface IListBox {
title?: string | ReactElement;
selectedOption: string;
setSelectedOption: (_option: string) => void;
availableOptions: { id: number; name: string; value: string }[];
}
import {
Listbox,
ListboxButton,
ListboxOption,
ListboxOptions,
} from '@headlessui/react';
import { CheckIcon, ChevronDownIcon } from '@heroicons/react/20/solid';
import clsx from 'clsx';
export default function ListBoxComp({
title,
selectedOption,
setSelectedOption,
availableOptions,
}: IListBox) {
return (
<div className='w-full mr-4 hover:translate-[1px] rounded-md z-50 '>
<Listbox value={selectedOption} onChange={setSelectedOption}>
<ListboxButton
tabIndex={0}
className={clsx(
'relative block w-full rounded-lg bg-gradient-to-r from-[#292e30] to-[#3d3737] py-1.5 pr-8 pl-3 text-left text-md/6 text-white',
'focus:outline-white data-[focus]:outline-2 data-[focus]:-outline-offset-2 data-[focus]:outline-white hover:outline-blue-700 hover:outline-1',
)}
>
{title ??
availableOptions.find((opt) => opt.value === selectedOption)
?.name ??
'Select...'}
<ChevronDownIcon
className='group pointer-events-none absolute top-2.5 right-2.5 size-4 fill-white/60'
aria-hidden='true'
/>
</ListboxButton>
<ListboxOptions
anchor='bottom'
transition
className={clsx(
'w-[var(--button-width)] rounded-xl border z-100 border-white/5 bg-black p-1 [--anchor-gap:var(--spacing-1)] focus:outline-none',
'transition duration-100 ease-in data-[leave]:data-[closed]:opacity-0',
)}
>
{availableOptions.map((opt) => (
<ListboxOption
key={opt.name}
value={opt.value}
className='group flex cursor-default items-center gap-2 rounded-lg py-1.5 px-3 select-none data-[focus]:bg-white/10'
>
<CheckIcon className='invisible size-4 fill-white group-data-[selected]:visible' />
<div className='text-sm/6 text-white'>{opt.name}</div>
</ListboxOption>
))}
</ListboxOptions>
</Listbox>
</div>
);
}