2022-11-19 14:21:26 +00:00
|
|
|
import React from "react";
|
|
|
|
// react hook form
|
|
|
|
import { Controller } from "react-hook-form";
|
|
|
|
// headless ui
|
|
|
|
import { Listbox, Transition } from "@headlessui/react";
|
|
|
|
// icons
|
|
|
|
import { CheckIcon } from "@heroicons/react/20/solid";
|
2022-12-05 05:57:14 +00:00
|
|
|
// constants
|
|
|
|
import { PRIORITIES } from "constants/";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
// types
|
|
|
|
import type { IIssue } from "types";
|
|
|
|
import type { Control } from "react-hook-form";
|
|
|
|
import { ChartBarIcon } from "@heroicons/react/24/outline";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
control: Control<IIssue, any>;
|
|
|
|
};
|
|
|
|
|
|
|
|
const SelectPriority: React.FC<Props> = ({ control }) => {
|
|
|
|
return (
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="priority"
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
<Listbox value={value} onChange={onChange}>
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<div className="relative">
|
|
|
|
<Listbox.Button className="flex items-center gap-1 hover:bg-gray-100 relative border rounded-md shadow-sm px-2 py-1 cursor-pointer focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm duration-300">
|
2022-12-03 13:41:07 +00:00
|
|
|
<ChartBarIcon className="h-3 w-3 text-gray-500" />
|
|
|
|
<span className="block capitalize">
|
|
|
|
{value && value !== "" ? value : "Priority"}
|
|
|
|
</span>
|
2022-11-19 14:21:26 +00:00
|
|
|
</Listbox.Button>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
show={open}
|
|
|
|
as={React.Fragment}
|
|
|
|
leave="transition ease-in duration-100"
|
|
|
|
leaveFrom="opacity-100"
|
|
|
|
leaveTo="opacity-0"
|
|
|
|
>
|
2022-11-24 13:48:18 +00:00
|
|
|
<Listbox.Options className="absolute z-10 mt-1 w-full w-[5rem] bg-white shadow-lg max-h-28 rounded-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none text-xs">
|
2022-11-19 14:21:26 +00:00
|
|
|
<div className="p-1">
|
|
|
|
{PRIORITIES.map((priority) => (
|
|
|
|
<Listbox.Option
|
|
|
|
key={priority}
|
|
|
|
className={({ active }) =>
|
|
|
|
`${
|
|
|
|
active ? "text-white bg-theme" : "text-gray-900"
|
|
|
|
} cursor-pointer select-none relative p-2 rounded-md`
|
|
|
|
}
|
|
|
|
value={priority}
|
|
|
|
>
|
|
|
|
{({ selected, active }) => (
|
|
|
|
<>
|
|
|
|
<span
|
|
|
|
className={`block capitalize ${
|
2022-11-24 13:48:18 +00:00
|
|
|
selected ? "font-medium" : "font-normal"
|
2022-11-19 14:21:26 +00:00
|
|
|
}`}
|
|
|
|
>
|
|
|
|
{priority}
|
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Listbox.Option>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</Listbox.Options>
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Listbox>
|
|
|
|
)}
|
|
|
|
></Controller>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SelectPriority;
|