HomeCalendar.js
2.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import React from "react";
import styled from "styled-components";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowLeft, faArrowRight } from "@fortawesome/free-solid-svg-icons";
import moment from "moment";
const HomeCalendarWrapper = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 50%;
width: 100%;
background-color: white;
opacity: 0.8;
border-radius: 10px;
`;
const CalenderBox = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
`;
const CalenderMenuBox = styled.div`
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
height: 15%;
width: 100%;
`;
const DateInfoSpan = styled.span`
font-size: 15px;
font-family: "Kanit", sans-serif;
`;
const DateBodyBox = styled.div`
height: 85%;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`;
const DateRow = styled.div`
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
`;
const DateText = styled.span`
text-align: center;
font-family: "Overpass", sans-serif;
color: ${(props) => {
if (props.className === "Sunday") return "#EA2027";
else if (props.className === "Saturday") return "#0652DD";
}};
`;
export default () => {
const generate = () => {
const today = moment();
const startWeek = today.clone().startOf("month").week();
const endWeek =
today.clone().endOf("month").week() === 1
? 53
: today.clone().endOf("month").week();
let calendar = [];
for (let week = startWeek; week <= endWeek; week++) {
calendar.push(
<DateRow key={week}>
{Array(7)
.fill(0)
.map((n, i) => {
let current = today
.clone()
.week(week)
.startOf("week")
.add(n + i, "day");
return (
<DateText className={`text`} key={i}>
{current.format("D")}
</DateText>
);
})}
</DateRow>
);
}
return calendar;
};
return (
<HomeCalendarWrapper>
<CalenderBox>
<CalenderMenuBox>
<FontAwesomeIcon icon={faArrowLeft} />
<DateInfoSpan>May 2020</DateInfoSpan>
<FontAwesomeIcon icon={faArrowRight} />
</CalenderMenuBox>
<DateBodyBox>
<DateRow>
<DateText className="Sunday">SUN</DateText>
<DateText>MON</DateText>
<DateText>TUE</DateText>
<DateText>WED</DateText>
<DateText>THU</DateText>
<DateText>FRI</DateText>
<DateText className="Saturday">SAT</DateText>
</DateRow>
{generate()}
</DateBodyBox>
</CalenderBox>
</HomeCalendarWrapper>
);
};