forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDayRangeSidebar.tsx
More file actions
63 lines (57 loc) · 1.93 KB
/
Copy pathDayRangeSidebar.tsx
File metadata and controls
63 lines (57 loc) · 1.93 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
61
62
63
// src/components/dashboard/DayRangeSidebar.tsx
"use client"
import clsx from "clsx"
import { CHART_THEME } from "@/components/charts/lib/theme"
import { hexToRgba } from "@/lib/color-utils"
import type { DayRange } from "@/types/api"
const DAY_RANGES: { value: DayRange; label: string }[] = [
{ value: 1, label: "24h" },
{ value: 7, label: "7d" },
{ value: 30, label: "30d" },
{ value: 90, label: "90d" },
{ value: 365, label: "1y" },
{ value: 0, label: "All" },
]
interface DayRangeSidebarProps {
days: DayRange
onChange: (days: DayRange) => void
accentColor: string
}
function DayRangeSidebar({ days, onChange, accentColor }: DayRangeSidebarProps) {
return (
<div className="order-first md:order-0 md:sticky md:top-6 flex flex-row flex-wrap md:flex-col gap-1 p-3 nm-raised-sm bg-elevated md:self-start md:ml-6 rounded-nm-lg">
<span className="w-full text-4xs font-sans font-medium text-muted uppercase tracking-wider px-2 pb-1 md:pb-1">
Range
</span>
{DAY_RANGES.map((d) => {
const isActive = days === d.value
return (
<button
key={d.value}
type="button"
onClick={() => onChange(d.value)}
className={clsx(
"px-3 py-1.5 text-xs font-mono cursor-pointer text-center rounded-nm-sm",
isActive
? "nm-inset-sm"
: "transition-all duration-150 hover:nm-raised-sm active:nm-inset-sm active:scale-[0.96]"
)}
style={
isActive
? {
backgroundColor: hexToRgba(accentColor, 0.12),
color: accentColor,
fontWeight: 600,
}
: { color: CHART_THEME.textTertiary }
}
>
{d.label}
</button>
)
})}
</div>
)
}
export type { DayRange, DayRangeSidebarProps }
export { DAY_RANGES, DayRangeSidebar }