mirror of
https://github.com/dylanbenzi/yellowbird.git
synced 2026-11-27 01:07:01 +00:00
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import React from "react";
|
|
import { ResponsiveTimeRange } from "@nivo/calendar";
|
|
import { earningsCalendar } from "../../../public/MockData/MockData";
|
|
import {
|
|
compareAsc,
|
|
format,
|
|
lightFormat,
|
|
parse,
|
|
startOfWeek,
|
|
subDays,
|
|
} from "date-fns";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
interface earningsData {
|
|
value: number;
|
|
day: string;
|
|
}
|
|
|
|
interface calendarSquaresProps {
|
|
data: earningsData[];
|
|
}
|
|
|
|
const CalendarSquares = ({ data }: calendarSquaresProps) => {
|
|
const today = new Date();
|
|
const thisWeek = startOfWeek(today);
|
|
const lastWeek = lightFormat(subDays(thisWeek, 6), "yyyy-MM-dd");
|
|
|
|
const calendar = data.filter(
|
|
(item: any) => compareAsc(item.day, lastWeek) >= 0
|
|
);
|
|
|
|
const values = calendar.map((obj) => obj.value);
|
|
|
|
const minValue = Math.min(...values);
|
|
const maxValue = Math.max(...values);
|
|
|
|
const valueRange = maxValue - minValue;
|
|
|
|
const lowBreakpoint = minValue + valueRange / 3;
|
|
const mediumBreakpoint = minValue + (2 * valueRange) / 3;
|
|
|
|
return (
|
|
<div className="h-full grid grid-rows-4 grid-cols-7 xl:grid-rows-5 2xl:grid-rows-6 overflow-hidden text-neutral-900">
|
|
{calendar.map((item: any) => (
|
|
<div
|
|
className={cn(
|
|
compareAsc(item.day, today) < 0
|
|
? "bg-neutral-500 text-neutral-700"
|
|
: item.value < lowBreakpoint
|
|
? "bg-[#fef7dc]/75"
|
|
: item.value < mediumBreakpoint
|
|
? "bg-[#fdedaa]/75"
|
|
: "bg-primary/75",
|
|
"flex flex-col items-center justify-center font-bold hover:cursor-pointer"
|
|
)}
|
|
key={item.day}
|
|
>
|
|
<div className={"text-xs"}>{format(item.day, "MMM")}</div>
|
|
<div className="">{lightFormat(item.day, "d")}</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default CalendarSquares;
|