Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Fragment } from "react";
- import { Listbox, Transition } from "@headlessui/react";
- import { CheckIcon, ChevronDownIcon } from "@heroicons/react/solid";
- function ListButton({ type, func, data }) {
- return (
- <Listbox value={type} onChange={func}>
- <div className="relative mt-1">
- <Listbox.Button className="relative w-44 py-2 pl-3 pr-10 text-left bg-white rounded-lg shadow-md cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-opacity-75 focus-visible:ring-white focus-visible:ring-offset-2 text-sm ring-1 ring-gray-100 hover:bg-gray-100">
- <span className="block truncate">{type}</span>
- <span className="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
- <ChevronDownIcon
- className="w-5 h-5 text-gray-400"
- aria-hidden="true"
- />
- </span>
- </Listbox.Button>
- <Transition
- as={Fragment}
- leave="transition ease-in duration-100"
- leaveFrom="opacity-100"
- leaveTo="opacity-0"
- >
- <Listbox.Options className="relative w-full py-1 mt-1 overflow-auto bg-white rounded-lg shadow-lg max-h-60 ring-opacity-5 focus:outline-none text-sm scrollbar-hide">
- {data.map((data, index) => (
- <Listbox.Option
- key={index}
- className={({ active }) =>
- `${active ? "text-blue-900 bg-blue-100" : "text-gray-900"}
- cursor-default select-none relative pl-10 pr-4`
- }
- value={`${data.name}`}
- >
- {({ selected, active }) => (
- <>
- <span
- className={`${
- selected ? "font-medium" : "font-normal"
- } block truncate`}
- >
- {`${data.name}`}
- </span>
- {selected ? (
- <span
- className={`${
- active ? "text-blue-600" : "text-blue-600"
- }
- absolute inset-y-0 left-0 flex items-center pl-3`}
- >
- <CheckIcon className="w-5 h-5" aria-hidden="true" />
- </span>
- ) : null}
- </>
- )}
- </Listbox.Option>
- ))}
- </Listbox.Options>
- </Transition>
- </div>
- </Listbox>
- );
- }
- export default ListButton;
Advertisement
Add Comment
Please, Sign In to add comment