el.xwx.moe/components/SortDropdown.tsx

67 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-06-13 23:40:23 -05:00
import React, { Dispatch, SetStateAction } from "react";
2023-05-28 17:40:28 -05:00
import ClickAwayHandler from "./ClickAwayHandler";
import RadioButton from "./RadioButton";
2023-06-13 21:44:50 -05:00
import { Sort } from "@/types/global";
2023-05-28 17:40:28 -05:00
type Props = {
2023-06-13 21:44:50 -05:00
sortBy: Sort;
2023-06-13 23:40:23 -05:00
setSort: Dispatch<SetStateAction<Sort>>;
2023-05-28 17:40:28 -05:00
toggleSortDropdown: Function;
};
2023-06-13 23:40:23 -05:00
export default function SortDropdown({
2023-05-28 17:40:28 -05:00
sortBy,
toggleSortDropdown,
2023-06-13 23:40:23 -05:00
setSort,
2023-05-28 17:40:28 -05:00
}: Props) {
return (
<ClickAwayHandler
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "sort-dropdown") toggleSortDropdown();
}}
2023-08-02 12:53:55 -05:00
className="absolute top-8 right-0 border border-sky-100 dark:border-sky-800 shadow-md bg-gray-50 dark:bg-blue-925 rounded-md p-2 z-20 w-48"
2023-05-28 17:40:28 -05:00
>
2023-08-02 12:53:55 -05:00
<p className="mb-2 text-sky-900 dark:text-sky-200 text-center font-semibold">Sort by</p>
2023-05-28 17:40:28 -05:00
<div className="flex flex-col gap-2">
<RadioButton
label="Date (Newest First)"
state={sortBy === Sort.DateNewestFirst}
onClick={() => setSort(Sort.DateNewestFirst)}
/>
<RadioButton
label="Date (Oldest First)"
state={sortBy === Sort.DateOldestFirst}
onClick={() => setSort(Sort.DateOldestFirst)}
/>
2023-05-28 17:40:28 -05:00
<RadioButton
label="Name (A-Z)"
2023-06-13 21:44:50 -05:00
state={sortBy === Sort.NameAZ}
2023-06-13 23:40:23 -05:00
onClick={() => setSort(Sort.NameAZ)}
2023-05-28 17:40:28 -05:00
/>
<RadioButton
label="Name (Z-A)"
2023-06-13 21:44:50 -05:00
state={sortBy === Sort.NameZA}
2023-06-13 23:40:23 -05:00
onClick={() => setSort(Sort.NameZA)}
2023-05-28 17:40:28 -05:00
/>
<RadioButton
2023-06-13 23:40:23 -05:00
label="Description (A-Z)"
state={sortBy === Sort.DescriptionAZ}
onClick={() => setSort(Sort.DescriptionAZ)}
2023-05-28 17:40:28 -05:00
/>
<RadioButton
2023-06-13 23:40:23 -05:00
label="Description (Z-A)"
state={sortBy === Sort.DescriptionZA}
onClick={() => setSort(Sort.DescriptionZA)}
2023-05-28 17:40:28 -05:00
/>
</div>
</ClickAwayHandler>
);
}