Skip to content

Commit 874ac6f

Browse files
authored
Add files via upload
0 parents  commit 874ac6f

20 files changed

+37606
-0
lines changed

package-lock.json

+37,174
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "react-complete-guide",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^5.11.6",
7+
"@testing-library/react": "^11.2.2",
8+
"@testing-library/user-event": "^12.5.0",
9+
"react": "^17.0.1",
10+
"react-dom": "^17.0.1",
11+
"react-scripts": "4.0.1",
12+
"styled-components": "^5.3.3",
13+
"web-vitals": "^0.2.4"
14+
},
15+
"scripts": {
16+
"start": "react-scripts start",
17+
"build": "react-scripts build",
18+
"test": "react-scripts test",
19+
"eject": "react-scripts eject"
20+
},
21+
"eslintConfig": {
22+
"extends": [
23+
"react-app",
24+
"react-app/jest"
25+
]
26+
},
27+
"browserslist": {
28+
"production": [
29+
">0.2%",
30+
"not dead",
31+
"not op_mini all"
32+
],
33+
"development": [
34+
"last 1 chrome version",
35+
"last 1 firefox version",
36+
"last 1 safari version"
37+
]
38+
}
39+
}

public/favicon.ico

3.78 KB
Binary file not shown.

public/index.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>React App</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>

public/logo192.png

5.22 KB
Loading

public/logo512.png

9.44 KB
Loading

public/manifest.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}

public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

src/App.css

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#goals {
2+
width: 35rem;
3+
max-width: 90%;
4+
margin: 3rem auto;
5+
}
6+
7+
#goal-form {
8+
width: 30rem;
9+
max-width: 90%;
10+
margin: 3rem auto;
11+
padding: 2rem;
12+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
13+
border-radius: 10px;
14+
}

src/App.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { useState } from "react";
2+
3+
import CourseGoalList from "./components/CourseGoals/CourseGoalList/CourseGoalList";
4+
import CourseInput from "./components/CourseGoals/CourseInput/CourseInput";
5+
import "./App.css";
6+
7+
const App = () => {
8+
const [courseGoals, setCourseGoals] = useState([
9+
{ text: "Do all exercises!", id: "g1" },
10+
{ text: "Finish the course!", id: "g2" },
11+
]);
12+
13+
const addGoalHandler = (enteredText) => {
14+
setCourseGoals((prevGoals) => {
15+
const updatedGoals = [...prevGoals];
16+
updatedGoals.unshift({ text: enteredText, id: Math.random().toString() });
17+
return updatedGoals;
18+
});
19+
};
20+
21+
const deleteItemHandler = (goalId) => {
22+
setCourseGoals((prevGoals) => {
23+
const updatedGoals = prevGoals.filter((goal) => goal.id !== goalId);
24+
return updatedGoals;
25+
});
26+
};
27+
28+
let content = ( <
29+
p style = {
30+
{ textAlign: "center" } } > No goals found.Maybe add one ? < /p>
31+
);
32+
33+
if (courseGoals.length > 0) {
34+
content = ( <
35+
CourseGoalList items = { courseGoals }
36+
onDeleteItem = { deleteItemHandler }
37+
/>
38+
);
39+
}
40+
41+
return ( <
42+
div >
43+
<
44+
section id = "goal-form" >
45+
<
46+
CourseInput onAddGoal = { addGoalHandler }
47+
/>{" "} <
48+
/section>{" "} <
49+
section id = "goals" > { " " } { content } { " " } {
50+
/* {courseGoals.length > 0 && (
51+
<CourseGoalList
52+
items={courseGoals}
53+
onDeleteItem={deleteItemHandler}
54+
/>
55+
) // <p style={{ textAlign: 'center' }}>No goals found. Maybe add one?</p>
56+
} */
57+
} { " " } <
58+
/section>{" "} <
59+
/div>
60+
);
61+
};
62+
63+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.goal-item {
2+
margin: 1rem 0;
3+
background: #8b005d;
4+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
5+
color: white;
6+
padding: 1rem 2rem;
7+
cursor: pointer;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
3+
import './CourseGoalItem.css';
4+
5+
const CourseGoalItem = props => {
6+
// const [deleteText, setDeleteText] = useState('');
7+
8+
const deleteHandler = () => {
9+
// setDeleteText('(Deleted!)');
10+
props.onDelete(props.id);
11+
};
12+
13+
return (
14+
<li className="goal-item" onClick={deleteHandler}>
15+
{props.children}
16+
</li>
17+
);
18+
};
19+
20+
export default CourseGoalItem;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.goal-list {
2+
list-style: none;
3+
margin: 0;
4+
padding: 0;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
3+
import CourseGoalItem from '../CourseGoalItem/CourseGoalItem';
4+
import './CourseGoalList.css';
5+
6+
const CourseGoalList = props => {
7+
return (
8+
<ul className="goal-list">
9+
{props.items.map(goal => (
10+
<CourseGoalItem
11+
key={goal.id}
12+
id={goal.id}
13+
onDelete={props.onDeleteItem}
14+
>
15+
{goal.text}
16+
</CourseGoalItem>
17+
))}
18+
</ul>
19+
);
20+
};
21+
22+
export default CourseGoalList;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React, { useState } from "react";
2+
import Button from "../../UI/Button/Button";
3+
import styles from "./CourseInput.module.css";
4+
5+
// const FormControl = styled.div `
6+
// margin: 0.5rem 0;
7+
8+
// & label {
9+
// font-weight: bold;
10+
// display: block;
11+
// margin-bottom: 0.5rem;
12+
// }
13+
14+
// & input {
15+
// display: block;
16+
// width: 100%;
17+
// border: 1px solid #ccc;
18+
// font: inherit;
19+
// line-height: 1.5rem;
20+
// padding: 0 0.25rem;
21+
// }
22+
23+
// & input:focus {
24+
// outline: none;
25+
// background: #fad0ec;
26+
// border-color: #8b005d;
27+
// }
28+
29+
// &.invalid input {
30+
// border-color: red;
31+
// background: rgb(236, 173, 173);
32+
// }
33+
34+
// &.invalid label {
35+
// color: red;
36+
// }
37+
// `;
38+
39+
const CourseInput = (props) => {
40+
const [enteredValue, setEnteredValue] = useState("");
41+
const [isValid, setIsValid] = useState(true);
42+
43+
const goalInputChangeHandler = (event) => {
44+
if (event.target.value.trim().length > 0) {
45+
setIsValid(true);
46+
}
47+
setEnteredValue(event.target.value);
48+
};
49+
50+
const formSubmitHandler = (event) => {
51+
event.preventDefault();
52+
if (enteredValue.trim().length === 0) {
53+
setIsValid(false);
54+
return;
55+
}
56+
props.onAddGoal(enteredValue);
57+
};
58+
59+
return ( <
60+
form onSubmit = { formSubmitHandler } >
61+
<
62+
div className = { `${styles["form-control"]} ${!isValid && styles.invalid}` } >
63+
<
64+
label > Course Goal < /label>{" "} <
65+
input type = "text"
66+
onChange = { goalInputChangeHandler }
67+
/>{" "} <
68+
/div>{" "} <
69+
Button type = "submit" > Add Goal < /Button>{" "} <
70+
/form>
71+
);
72+
};
73+
74+
export default CourseInput;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.form-control {
2+
margin: 0.5rem 0;
3+
}
4+
5+
.form-control label {
6+
font-weight: bold;
7+
display: block;
8+
margin-bottom: 0.5rem;
9+
}
10+
11+
.form-control input {
12+
display: block;
13+
width: 100%;
14+
border: 1px solid #ccc;
15+
font: inherit;
16+
line-height: 1.5rem;
17+
padding: 0 0.25rem;
18+
}
19+
20+
.form-control input:focus {
21+
outline: none;
22+
background: #fad0ec;
23+
border-color: #8b005d;
24+
}
25+
26+
.form-control.invalid input {
27+
border-color: red;
28+
background: rgb(236, 173, 173);
29+
}
30+
31+
.form-control.invalid label {
32+
color: red;
33+
}

0 commit comments

Comments
 (0)