-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f75a808
commit 7a6fe9a
Showing
9 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "managing-a-component-tree-practice-completed", | ||
"version": "1.0.0", | ||
"description": "", | ||
"keywords": [], | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"react": "16.8.6", | ||
"react-dom": "16.8.6", | ||
"react-scripts": "3.2.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "3.3.3" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>React App</title> | ||
<link | ||
href="https://fonts.googleapis.com/css?family=Architects+Daughter&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<link rel="stylesheet" href="styles.css" /> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
<script src="../src/index.js" type="text/jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
body { | ||
background-color: #ffeaa7; | ||
min-height: 70vh; | ||
padding: 1rem; | ||
box-sizing: border-box; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
color: hsl(198, 1%, 29%); | ||
font-family: "Architects Daughter", cursive; | ||
text-align: center; | ||
font-size: 130%; | ||
} | ||
|
||
.container { | ||
width: 100%; | ||
height: auto; | ||
min-height: 500px; | ||
max-width: 500px; | ||
min-width: 250px; | ||
background: #f1f5f8; | ||
background-image: radial-gradient(#bfc0c1 7.2%, transparent 0); | ||
background-size: 25px 25px; | ||
border-radius: 20px; | ||
box-shadow: 4px 3px 7px 2px #00000040; | ||
padding: 1rem; | ||
box-sizing: border-box; | ||
} | ||
.heading { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
margin-bottom: 1rem; | ||
} | ||
.heading h1 { | ||
transform: rotate(2deg); | ||
padding: 0.2rem 1.2rem; | ||
border-radius: 20% 5% 20% 5%/5% 20% 25% 20%; | ||
background-color: #fdcb6e; | ||
font-size: 1.5rem; | ||
} | ||
|
||
.form input { | ||
box-sizing: border-box; | ||
background-color: transparent; | ||
padding: 0.7rem; | ||
border-bottom-right-radius: 15px 3px; | ||
border-bottom-left-radius: 3px 15px; | ||
border: solid 3px transparent; | ||
border-bottom: dashed 3px #fdcb6e; | ||
font-family: "Architects Daughter", cursive; | ||
font-size: 1rem; | ||
color: hsla(260, 2%, 25%, 0.7); | ||
width: 70%; | ||
margin-bottom: 20px; | ||
} | ||
|
||
button { | ||
padding: 0; | ||
border: none; | ||
font-family: "Architects Daughter", cursive; | ||
text-decoration: none; | ||
padding-bottom: 3px; | ||
border-radius: 5px; | ||
background-color: #ffeaa7; | ||
} | ||
button span { | ||
background: #f1f5f8; | ||
display: block; | ||
padding: 0.5rem 1rem; | ||
border-radius: 5px; | ||
border: 2px solid hsl(198, 1%, 29%); | ||
} | ||
|
||
li { | ||
text-align: left; | ||
position: relative; | ||
padding: 0.5rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useState } from "react"; | ||
import ToDoItem from "./ToDoItem"; | ||
import InputArea from "./InputArea"; | ||
import Heading from "./Heading"; | ||
|
||
function App() { | ||
const [items, setItems] = useState([]); | ||
|
||
function addItem(inputText) { | ||
setItems((prevItems) => { | ||
return [...prevItems, inputText]; | ||
}); | ||
} | ||
|
||
function deleteItem(id) { | ||
setItems((prevItems) => { | ||
return prevItems.filter((item, index) => { | ||
return index !== id; | ||
}); | ||
}); | ||
} | ||
|
||
return ( | ||
<div className="container"> | ||
<Heading /> | ||
<InputArea onAdd={addItem} /> | ||
<div> | ||
<ul> | ||
{items.map((todoItem, index) => ( | ||
<ToDoItem | ||
key={index} | ||
id={index} | ||
text={todoItem} | ||
onChecked={deleteItem} | ||
/> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React, { useState } from "react"; | ||
|
||
function Heading() { | ||
return ( | ||
<div className="heading"> | ||
<h1>To-Do List</h1> | ||
</div> | ||
); | ||
} | ||
export default Heading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { useState } from "react"; | ||
|
||
function InputArea(props) { | ||
const [inputText, setInputText] = useState(""); | ||
|
||
function handleChange(event) { | ||
const newValue = event.target.value; | ||
setInputText(newValue); | ||
} | ||
|
||
return ( | ||
<div className="form"> | ||
<input onChange={handleChange} type="text" value={inputText} /> | ||
<button | ||
onClick={() => { | ||
props.onAdd(inputText); | ||
setInputText(""); | ||
}} | ||
> | ||
<span>Add</span> | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
export default InputArea; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react"; | ||
|
||
function ToDoItem(props) { | ||
return ( | ||
<div | ||
onClick={() => { | ||
props.onChecked(props.id); | ||
}} | ||
> | ||
<li>{props.text}</li> | ||
</div> | ||
); | ||
} | ||
|
||
export default ToDoItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import App from "./components/App"; | ||
|
||
ReactDOM.render(<App />, document.getElementById("root")); | ||
|
||
//CHALLENGE: I have extracted the Input Area, including the <input> and | ||
//<button> elements into a seperate Component called InputArea. | ||
//Your job is to make the app work as it did before but this time with the | ||
//InputArea as a seperate Component. | ||
|
||
// DO NOT: Modify the ToDoItem.jsx | ||
// DO NOT: Move the input/button elements back into the App.jsx | ||
|
||
//Hint 1: You will need to think about how to manage the state of the input element | ||
//in InputArea.jsx. | ||
//Hint 2: You will need to think about how to pass the input value back into | ||
//the addItem() function in App.jsx. |