-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderByDropdown.tsx
More file actions
60 lines (56 loc) · 1.7 KB
/
OrderByDropdown.tsx
File metadata and controls
60 lines (56 loc) · 1.7 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
import { ChevronDown } from "lucide-react";
import { useState } from "react";
import { cn } from "@/lib/utils";
type OrderByDropdownProps = {
ascending: boolean;
setAscending: (ascending: boolean) => void;
};
export function OrderByDropdown({
ascending,
setAscending,
}: OrderByDropdownProps) {
const [open, setOpen] = useState(false);
const label = ascending ? "Ascending" : "Descending";
return (
<div
className="relative min-w-0 w-full max-w-31.5"
onBlur={(e) => {
if (!e.currentTarget.contains(e.relatedTarget)) setOpen(false);
}}
>
<button
type="button"
className={cn(
"flex w-full items-center justify-between gap-2 py-1 pl-2 pr-1 border border-stroke-subtle bg-bg-primary text-left",
open ? "rounded-t-md" : "rounded-md",
)}
onClick={() => setOpen((o) => !o)}
aria-expanded={open}
>
<span className="min-w-0 truncate text-md text-text-default">
{label}
</span>
<ChevronDown
className={cn(
"h-4 w-4 shrink-0 transition-transform",
open && "rotate-180",
)}
/>
</button>
{open && (
<div className="absolute left-0 top-full z-10 w-full rounded-b-md border border-t-0 border-stroke-subtle bg-bg-primary shadow-md">
<button
type="button"
className="block w-full pl-2 pr-1 py-1 text-left text-md text-text-default hover:bg-bg-selected"
onClick={() => {
setAscending(!ascending);
setOpen(false);
}}
>
{ascending ? "Descending" : "Ascending"}
</button>
</div>
)}
</div>
);
}