Skip to content

Commit b72c550

Browse files
committed
Create calendar grid
1 parent f568bc0 commit b72c550

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

src/routes/Events/index.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { useState } from "react";
2+
import { changeMonth, dayNames, months } from "./utils.ts";
3+
import times from "lodash/times";
4+
import DayCard from "./DayCard.tsx";
5+
6+
export default function Events() {
7+
// const today = new Date();
8+
const [currentDate, setCurrentDate] = useState<Date>(new Date());
9+
10+
return (
11+
<main className="flex h-full w-full flex-col">
12+
<section className="flex h-full flex-col justify-center">
13+
<h3 className="my-12 text-center text-3xl text-secondary">Events</h3>
14+
<div className="flex w-full flex-col items-center justify-center bg-background px-16">
15+
<div className="mb-6 flex w-full justify-center">
16+
<button
17+
className="text-3xl"
18+
onClick={() => {
19+
const newDate = changeMonth(-1, currentDate);
20+
setCurrentDate(new Date(newDate.toDateString()));
21+
}}
22+
>
23+
&#60;
24+
</button>
25+
<span className="mx-12 text-3xl">
26+
{months[currentDate.getMonth()][0]}
27+
</span>
28+
<button
29+
className="text-3xl"
30+
onClick={() => {
31+
const newDate = changeMonth(1, currentDate);
32+
setCurrentDate(new Date(newDate.toDateString()));
33+
}}
34+
>
35+
&#62;
36+
</button>
37+
</div>
38+
<div className="grid w-full grid-cols-7 gap-4">
39+
{dayNames.map((dayName, i) => (
40+
<span key={i} className="text-center">
41+
{dayName}
42+
</span>
43+
))}
44+
</div>
45+
<div className="grid w-full grid-cols-7 gap-4">
46+
{times(months[currentDate.getMonth()][1], (i) => (
47+
<DayCard key={i} date={i + 1} />
48+
))}
49+
</div>
50+
</div>
51+
</section>
52+
</main>
53+
);
54+
}

src/routes/Events/utils.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export const months: [string, number][] = [
2+
["January", 31],
3+
["February", 28],
4+
["March", 31],
5+
["April", 30],
6+
["May", 31],
7+
["June", 30],
8+
["July", 31],
9+
["August", 31],
10+
["September", 30],
11+
["October", 31],
12+
["November", 30],
13+
["December", 31],
14+
];
15+
export const dayNames = [
16+
"Sunday",
17+
"Monday",
18+
"Tuesday",
19+
"Wednesday",
20+
"Thursday",
21+
"Friday",
22+
"Saturday",
23+
];
24+
25+
export const changeMonth = (value: number, currentDate: Date): Date => {
26+
const newDate = currentDate;
27+
newDate.setMonth(currentDate.getMonth() + value);
28+
return newDate;
29+
};

0 commit comments

Comments
 (0)