HyeonJun Jeon

[Add] Side component

1 +import { useContext } from "react";
2 +import { CalendarStateContext } from "../pages/Calendar";
3 +import "../styles/Side.css";
4 +import SideSubject from "./SideSubject";
5 +
6 +const Side = () => {
7 + const { subs, setSubs } = useContext(CalendarStateContext);
8 +
9 + const renderSubs = () => {
10 + const sideSubjects = [];
11 +
12 + for (let i = 0; i < subs.length; i++) {
13 + sideSubjects.push(
14 + <SideSubject key={i} subject={subs[i]} setSubs={setSubs} />
15 + );
16 + }
17 +
18 + return sideSubjects;
19 + };
20 +
21 + return <aside>{renderSubs()}</aside>;
22 +};
23 +
24 +export default Side;
1 +const SideSubject = ({ subject }) => {
2 + let isChecked = false;
3 + const defaultColor = "#EFEFEF";
4 + const bgc = "background-color";
5 +
6 + const check = (e) => {
7 + if (isChecked) e.target.style["background-color"] = defaultColor;
8 + else e.target.style["background-color"] = subject.color;
9 + isChecked = !isChecked;
10 + };
11 +
12 + return (
13 + <div className="SideSubject">
14 + <div
15 + className="ssc"
16 + onClick={check}
17 + style={{
18 + [bgc]: isChecked ? subject.color : defaultColor,
19 + }}
20 + ></div>
21 +
22 + <span>{subject.name}</span>
23 + </div>
24 + );
25 +};
26 +
27 +export default SideSubject;
...@@ -2,3 +2,19 @@ h1, ...@@ -2,3 +2,19 @@ h1,
2 h2 { 2 h2 {
3 margin: 0; 3 margin: 0;
4 } 4 }
5 +
6 +.App {
7 + margin: 12px;
8 +}
9 +
10 +/* Calendar */
11 +
12 +.Calendar {
13 + display: flex;
14 + flex-direction: column;
15 +}
16 +
17 +.content {
18 + flex: 1;
19 + display: flex;
20 +}
......
1 header { 1 header {
2 background-color: rgba(255, 255, 255, 1); 2 background-color: rgba(255, 255, 255, 1);
3 display: flex; 3 display: flex;
4 - padding: 8px; 4 + margin-bottom: 12px;
5 justify-content: space-between; 5 justify-content: space-between;
6 align-items: center; 6 align-items: center;
7 } 7 }
8 8
9 .hl { 9 .hl {
10 - padding-right: 50px; 10 + padding-right: 100px;
11 } 11 }
12 12
13 .hls { 13 .hls {
...@@ -42,8 +42,8 @@ header { ...@@ -42,8 +42,8 @@ header {
42 } 42 }
43 43
44 .hrd { 44 .hrd {
45 - margin-right: 10px; 45 + margin-right: 12px;
46 - margin-left: 10px; 46 + margin-left: 12px;
47 } 47 }
48 48
49 .hrd > button { 49 .hrd > button {
......
1 +aside {
2 + width: 250px;
3 + margin-right: 8px;
4 + padding-top: 50px;
5 +}
6 +
7 +.SideSubject {
8 + height: 25px;
9 + padding: 5px;
10 + display: flex;
11 +}
12 +
13 +.ssc {
14 + height: 15px;
15 + width: 15px;
16 + margin: 5px 10px 5px 5px;
17 + border: solid thin grey;
18 + border-radius: 3px;
19 +}
1 +html,
1 body { 2 body {
3 + width: 100%;
4 + height: 100%;
2 margin: 0; 5 margin: 0;
3 - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 6 + padding: 0;
4 - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 7 +}
8 +
9 +body {
10 + overflow: hidden;
11 + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
12 + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
5 sans-serif; 13 sans-serif;
6 -webkit-font-smoothing: antialiased; 14 -webkit-font-smoothing: antialiased;
7 -moz-osx-font-smoothing: grayscale; 15 -moz-osx-font-smoothing: grayscale;
8 } 16 }
9 17
10 code { 18 code {
11 - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 19 + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
12 monospace; 20 monospace;
13 } 21 }
......
1 +class Subject {
2 + constructor(name, color, selected) {
3 + this.name = name;
4 + this.color = color;
5 + this.selected = selected;
6 + }
7 +}
8 +
9 +export default Subject;