Skip to content

Commit b067936

Browse files
committed
First Commnit
1 parent fd1cd6f commit b067936

File tree

9 files changed

+3143
-152
lines changed

9 files changed

+3143
-152
lines changed

package-lock.json

Lines changed: 3055 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
"last 1 firefox version",
3535
"last 1 safari version"
3636
]
37+
},
38+
"devDependencies": {
39+
"node-sass": "^7.0.1"
3740
}
3841
}

src/App.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/App.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
import logo from './logo.svg';
2-
import './App.css';
1+
import React, { useState } from "react";
2+
import "./App.scss";
3+
import ColorBox from "./Components/ColorBox/ColorBox";
4+
import TodoList from "./Components/TodoList/TodoList";
35

46
function App() {
7+
const [todoList, setTodoList] = useState([
8+
{ id: 1, title: "I love Easy Frontend" },
9+
{ id: 2, title: "We love Easy Frontend" },
10+
{ id: 3, title: "They love Easy Frontend" },
11+
]);
512
return (
6-
<div className="App">
7-
<header className="App-header">
8-
<img src={logo} className="App-logo" alt="logo" />
9-
<p>
10-
Edit <code>src/App.js</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
Learn React
19-
</a>
20-
</header>
13+
<div className="app">
14+
<h1>Welcome to React hooks!</h1>
15+
<TodoList todos={todoList} />
2116
</div>
2217
);
2318
}

src/App.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.app{
2+
color: deeppink
3+
}

src/Components/ColorBox/ColorBox.jsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { useState } from "react";
2+
import "./ColorBox.scss";
3+
4+
ColorBox.propTypes = {};
5+
6+
const getRandomColor = () => {
7+
const COLOR_LIST = ["deeppink", "green", "yellow", "orange", "blue"];
8+
const randomIndex = Math.trunc(Math.random() * COLOR_LIST.length);
9+
return COLOR_LIST[randomIndex];
10+
};
11+
12+
function ColorBox() {
13+
const [color, setColor] = useState(() => {
14+
const initColor = localStorage.getItem("color") || "deeppink";
15+
return initColor;
16+
});
17+
18+
function handleBoxClick() {
19+
// get color -> set color
20+
const newColor = getRandomColor();
21+
setColor(newColor);
22+
23+
localStorage.setItem("color", newColor);
24+
}
25+
return (
26+
<div
27+
className="color-box"
28+
style={{ backgroundColor: color }}
29+
onClick={handleBoxClick}
30+
>
31+
ColorBox
32+
</div>
33+
);
34+
}
35+
36+
export default ColorBox;

src/Components/ColorBox/ColorBox.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.color-box{
2+
$box-size: 200px;
3+
4+
display: inline-block;
5+
width: $box-size;
6+
height: $box-size;
7+
border-radius: 8px;
8+
9+
transition: all 0.35s ease-in-out;
10+
cursor: pointer;
11+
}

src/Components/TodoList/TodoList.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
4+
TodoList.propTypes = {
5+
todos: PropTypes.array,
6+
onTodoClick: PropTypes.func,
7+
};
8+
TodoList.defaultProps = {
9+
todos: [],
10+
onTodoClick: null,
11+
};
12+
function TodoList(props) {
13+
const { todos, onTodoClick } = props;
14+
return (
15+
<ul>
16+
{todos.map((todo) => (
17+
<li key={todo.id}>{todo.title}</li>
18+
))}
19+
</ul>
20+
);
21+
}
22+
23+
export default TodoList;

src/Components/TodoList/TodoList.scss

Whitespace-only changes.

0 commit comments

Comments
 (0)