-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendar.js
60 lines (55 loc) · 1.45 KB
/
Calendar.js
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 React, { useState, useEffect } from "react";
import "./Calendar.css";
import moment from "moment";
export const Calendar = () => {
const [days, setDays] = useState([]);
const [today, setToday] = useState(false);
useEffect(() => {
let monthDate = moment().startOf("month");
let array = [...Array(monthDate.daysInMonth())].map((_, i) =>
monthDate.clone().add(i, "day")
);
setDays(array);
console.log("days" + days);
return () => {
console.log("cleanup");
};
}, []);
const isToday = (day) => {
return moment().isSame(day, "day");
};
const columns = (index) => {
if (index == 0) {
return days[0].day() + 1;
}
};
return (
<>
<div className="calendar-labels">
<div>FRI</div>
<div>SAT</div>
<div>SUN</div> <div>FRI</div>
<div>MON</div>
<div>TUE</div>
<div>WED</div>
</div>
<div className="calendar">
{
days.map((day, index) => {
let p = columns(index) | index;
return isToday(day) ? (
<div className="today" key={p}>
{day.format("D")}
</div>
) : (
<div className="days" key={p}>
{day.format("D")}
</div>
);
})
//days.map((day, index)=>moment().format(day,'D'))
}
</div>
</>
);
};