el.xwx.moe/components/SortDropdown.tsx

124 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-06-13 23:40:23 -05:00
import React, { Dispatch, SetStateAction } from "react";
2023-06-13 21:44:50 -05:00
import { Sort } from "@/types/global";
2024-01-14 09:09:09 -06:00
import { dropdownTriggerer } from "@/lib/client/utils";
import { TFunction } from "i18next";
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>>;
t: TFunction<"translation", undefined>;
2023-05-28 17:40:28 -05:00
};
export default function SortDropdown({ sortBy, setSort, t }: Props) {
2023-05-28 17:40:28 -05:00
return (
2023-11-29 14:17:51 -06:00
<div className="dropdown dropdown-bottom dropdown-end">
<div
tabIndex={0}
role="button"
2024-01-14 09:09:09 -06:00
onMouseDown={dropdownTriggerer}
2024-02-10 23:55:00 -06:00
className="btn btn-sm btn-square btn-ghost border-none"
2023-11-29 14:17:51 -06:00
>
2023-12-17 22:32:33 -06:00
<i className="bi-chevron-expand text-neutral text-2xl"></i>
2023-05-28 17:40:28 -05:00
</div>
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-xl w-52 mt-1">
2023-11-29 14:17:51 -06:00
<li>
<label
className="label cursor-pointer flex justify-start"
2023-11-29 14:17:51 -06:00
tabIndex={0}
role="button"
>
<input
type="radio"
name="sort-radio"
className="radio checked:bg-primary"
checked={sortBy === Sort.DateNewestFirst}
onChange={() => setSort(Sort.DateNewestFirst)}
2023-11-29 14:17:51 -06:00
/>
<span className="label-text">{t("date_newest_first")}</span>
2023-11-29 14:17:51 -06:00
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
2023-11-29 14:17:51 -06:00
tabIndex={0}
role="button"
>
<input
type="radio"
name="sort-radio"
className="radio checked:bg-primary"
checked={sortBy === Sort.DateOldestFirst}
onChange={() => setSort(Sort.DateOldestFirst)}
/>
<span className="label-text">{t("date_oldest_first")}</span>
2023-11-29 14:17:51 -06:00
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
2023-11-29 14:17:51 -06:00
tabIndex={0}
role="button"
>
<input
type="radio"
name="sort-radio"
className="radio checked:bg-primary"
checked={sortBy === Sort.NameAZ}
onChange={() => setSort(Sort.NameAZ)}
/>
<span className="label-text">{t("name_az")}</span>
2023-11-29 14:17:51 -06:00
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
2023-11-29 14:17:51 -06:00
tabIndex={0}
role="button"
>
<input
type="radio"
name="sort-radio"
className="radio checked:bg-primary"
checked={sortBy === Sort.NameZA}
onChange={() => setSort(Sort.NameZA)}
/>
<span className="label-text">{t("name_za")}</span>
2023-11-29 14:17:51 -06:00
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
2023-11-29 14:17:51 -06:00
tabIndex={0}
role="button"
>
<input
type="radio"
name="sort-radio"
className="radio checked:bg-primary"
checked={sortBy === Sort.DescriptionAZ}
onChange={() => setSort(Sort.DescriptionAZ)}
/>
<span className="label-text">{t("description_az")}</span>
2023-11-29 14:17:51 -06:00
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
2023-11-29 14:17:51 -06:00
tabIndex={0}
role="button"
>
<input
type="radio"
name="sort-radio"
className="radio checked:bg-primary"
checked={sortBy === Sort.DescriptionZA}
onChange={() => setSort(Sort.DescriptionZA)}
/>
<span className="label-text">{t("description_za")}</span>
2023-11-29 14:17:51 -06:00
</label>
</li>
</ul>
</div>
2023-05-28 17:40:28 -05:00
);
}