├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
└── index.html
└── src
├── App.css
├── App.jsx
├── components
├── Modal.jsx
├── Todo.jsx
├── TodoActions.jsx
├── TodoBox.jsx
├── TodoForm.jsx
└── TodoList.jsx
├── index.css
└── index.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "alihan-app",
3 | "version": "0.1.0",
4 | "private": true,
5 | "homepage": "https://alihanio.github.io/Todo-in-react",
6 | "dependencies": {
7 | "@testing-library/jest-dom": "^5.17.0",
8 | "@testing-library/react": "^13.4.0",
9 | "@testing-library/user-event": "^13.5.0",
10 | "gh-pages": "^6.0.0",
11 | "react": "^18.2.0",
12 | "react-dom": "^18.2.0",
13 | "react-icons": "^4.11.0",
14 | "react-scripts": "5.0.1",
15 | "react-uuid": "^2.0.0",
16 | "styled-components": "^6.1.0",
17 | "web-vitals": "^2.1.4"
18 | },
19 | "scripts": {
20 | "start": "react-scripts start",
21 | "build": "react-scripts build",
22 | "test": "react-scripts test",
23 | "eject": "react-scripts eject",
24 | "predeploy": "npm run build",
25 | "deploy": "gh-pages -d build"
26 | },
27 | "eslintConfig": {
28 | "extends": [
29 | "react-app",
30 | "react-app/jest"
31 | ]
32 | },
33 | "browserslist": {
34 | "production": [
35 | ">0.2%",
36 | "not dead",
37 | "not op_mini all"
38 | ],
39 | "development": [
40 | "last 1 chrome version",
41 | "last 1 firefox version",
42 | "last 1 safari version"
43 | ]
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alihanio/Todo-in-react/a95bf5cdb714fe241d44f2ab194cfbdf063e076d/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | React App
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | body {
2 | background-color: #112d49;
3 | }
4 | .todoFillStyle {
5 | font-size: 1.8rem;
6 | padding: 0 5px;
7 | color: teal;
8 | margin-right: 1rem;
9 | }
10 | .todoDeleteStyle {
11 | font-size: 1.8rem;
12 | color: grey;
13 | padding: 0 5px;
14 | cursor: pointer;
15 | position: absolute;
16 | right: 0;
17 | }
18 | .todoDeleteStyle:hover {
19 | color: red;
20 | }
21 | .checkIcon {
22 | cursor: pointer;
23 | color: lightgrey;
24 | padding: 0 5px;
25 | font-size: 1.8rem;
26 | position: absolute;
27 | right: 2rem;
28 | }
29 | .checkIcon:hover {
30 | color: greenyellow;
31 | }
32 | .updateIcon {
33 | font-size: 1.8rem;
34 | color: grey;
35 | padding: 0 5px;
36 | cursor: pointer;
37 | position: absolute;
38 | right: 4rem;
39 | }
40 | .updateIcon:hover {
41 | color: blue;
42 | }
43 | .refresh {
44 | font-size: 1.8rem;
45 | }
46 | .allDelete {
47 | font-size: 1.8rem;
48 | }
49 |
--------------------------------------------------------------------------------
/src/App.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import "./App.css";
3 | import TodoBox from "./components/TodoBox";
4 |
5 | const App = () => {
6 | return (
7 | <>
8 |
9 | >
10 | );
11 | };
12 |
13 | export default App;
14 |
--------------------------------------------------------------------------------
/src/components/Modal.jsx:
--------------------------------------------------------------------------------
1 | import ReactDOM from "react-dom";
2 | import styled from "styled-components";
3 |
4 | const Modal = ({ children, onClose }) => {
5 | return ReactDOM.createPortal(
6 | <>
7 |
8 |
9 | {children}
10 | Cansel
11 |
12 | >,
13 | document.getElementById("portal")
14 | );
15 | };
16 | export default Modal;
17 |
18 | const Backdrop = styled.div`
19 | position: fixed;
20 | top: 0;
21 | left: 0;
22 | right: 0;
23 | bottom: 0;
24 | background-color: rgba(0, 0, 0, 0.7);
25 | z-index: 1000;
26 | `;
27 | const ModalConteiner = styled.div`
28 | position: fixed;
29 | top: 50%;
30 | left: 50%;
31 | transform: translate(-50%, -50%);
32 | background-color: #fff;
33 | padding: 50px;
34 | z-index: 1000;
35 | width: 30rem;
36 | border-radius: 1rem;
37 | text-align: center;
38 | `;
39 | const CanselBtn = styled.button`
40 | width: 5rem;
41 | height: 2rem;
42 | border-radius: 0.5rem;
43 | background-color: blue;
44 | color: white;
45 | border: none;
46 | font-weight: bold;
47 | &:hover {
48 | background-color: lightblue;
49 | color: black;
50 | }
51 | &:focus {
52 | background-color: blue;
53 | color: white;
54 | }
55 | `;
56 |
--------------------------------------------------------------------------------
/src/components/Todo.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import styled from "styled-components";
3 | import { RiTodoFill, RiDeleteBack2Line } from "react-icons/ri";
4 | import { FaCheck } from "react-icons/fa";
5 | import { BsFillPencilFill } from "react-icons/bs";
6 | import Modal from "./Modal";
7 |
8 | const Todo = ({ todo, onDelateTodo, onToggle, onUpdate }) => {
9 | const [isOpen, setIsOpen] = useState(false);
10 | const [openUpdateModal, setOpenUpdateModal] = useState(false);
11 | const [changeText, setChangeText] = useState(todo.text);
12 |
13 | const modalHandler = () => {
14 | setIsOpen((prev) => !prev);
15 | };
16 | //бул функция бизде мадалканы ачып жапканга жардам берет
17 |
18 | const updateModal = () => {
19 | setOpenUpdateModal((prev) => !prev);
20 | };
21 | //бул функция болсо update мадалканы ачып жапканга жардам берет
22 | const changeTextValue = (e) => {
23 | setChangeText(e.target.value);
24 | };
25 | //бул жакта биз инпуттун ичиндеги значениени алып жатабыз
26 |
27 | const changeTextBtn = () => {
28 | onUpdate(todo.id, changeText);
29 | setOpenUpdateModal((prev) => !prev);
30 | };
31 | //бул болсо когда озгорткрндо update кылганда озгортуу деген кнопканы басканда id жана жаны текстти props кылып берет ,жана модаканы жабат
32 |
33 | return (
34 | <>
35 |
36 |
37 |
38 | {todo.text}
39 | date: {todo.data}
40 |
41 |
42 | onToggle(todo.id)} />
43 |
44 |
45 |
46 | {isOpen && (
47 |
48 | Are you sure you want to delate this todo...
49 | onDelateTodo(todo.id)}>
50 | Delate
51 |
52 |
53 | )}
54 | {openUpdateModal && (
55 |
56 | Enter your update todo ...
57 |
62 | add
63 |
64 | )}
65 | >
66 | );
67 | };
68 |
69 | export default Todo;
70 |
71 | const COMPLATED = {
72 | backgroundColor: " unset",
73 | borderColor: " gray",
74 | color: "gray",
75 | };
76 | const TodoConteiner = styled.div`
77 | display: flex;
78 | flex-direction: column;
79 | `;
80 | const TodoList = styled.div`
81 | width: 28rem;
82 | display: flex;
83 | border: 1px solid black;
84 | position: relative;
85 | background-color: white;
86 | margin-top: 1rem;
87 | `;
88 | const TodoText = styled.p`
89 | font-family: monospace;
90 | font-size: 1.2rem;
91 | `;
92 | const TodoTime = styled.p`
93 | font-family: monospace;
94 | font-size: 0.8rem;
95 | margin-top: 0.2rem;
96 | `;
97 | const ModalDelateBtn = styled.button`
98 | width: 5rem;
99 | height: 2rem;
100 | border-radius: 0.5rem;
101 | background-color: red;
102 | color: white;
103 | border: none;
104 | margin-right: 5rem;
105 | font-weight: bold;
106 | &:hover {
107 | background-color: green;
108 | }
109 | &:focus {
110 | background-color: red;
111 | }
112 | `;
113 | const Warning = styled.h2`
114 | font-family: monospace;
115 | font-size: 1.5rem;
116 | margin-bottom: 2rem;
117 | `;
118 | const UpdateInput = styled.input`
119 | width: 20rem;
120 | height: 2rem;
121 | border: 1px solid black;
122 | padding: 1rem 1rem;
123 | margin-bottom: 4rem;
124 | `;
125 | const UpdateBtn = styled.button`
126 | width: 5rem;
127 | height: 2rem;
128 | border: none;
129 | background: green;
130 | border-radius: 0.5rem;
131 | transition: 0.3s;
132 | margin-right: 3rem;
133 | &:hover {
134 | transform: scale(0.95);
135 | }
136 | `;
137 | const UpdateHeading = styled.h2`
138 | font-family: monospace;
139 | font-size: 1.5rem;
140 | margin-bottom: 2rem;
141 | `;
142 |
--------------------------------------------------------------------------------
/src/components/TodoActions.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import styled from "styled-components";
3 | import { RiDeleteBack2Line, RiRefreshLine } from "react-icons/ri";
4 |
5 | const TodoActions = ({
6 | resetTodosHandler,
7 | delateCompletedTodosHandler,
8 | isExistingCompletedTodo,
9 | }) => {
10 | return (
11 |
12 |
13 |
14 |
15 |
19 |
20 |
21 |
22 | );
23 | };
24 |
25 | export default TodoActions;
26 |
27 | const ButtonReset = styled.button`
28 | width: 3rem;
29 | height: 2.5rem;
30 | margin-right: 2rem;
31 | margin: 1rem 1rem;
32 | border-radius: 0.2rem;
33 | border: none;
34 | cursor: pointer;
35 | `;
36 | const ButtonRefresh = styled.button`
37 | disabled: ${({ disabled }) => disabled};
38 | width: 3rem;
39 | height: 2.5rem;
40 | margin-right: 2rem;
41 | margin: 1rem 1rem;
42 | border-radius: 0.2rem;
43 | cursor: pointer;
44 | border: none;
45 | `;
46 | const ActionsConteiner = styled.div`
47 | display: flex;
48 | `;
49 |
--------------------------------------------------------------------------------
/src/components/TodoBox.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from "react";
2 | import styled from "styled-components";
3 | import TodoForm from "./TodoForm";
4 | import TodoList from "./TodoList";
5 | import uuid from "react-uuid";
6 | import TodoActions from "./TodoActions";
7 |
8 | const TodoBox = () => {
9 | const [todos, setTodos] = useState(getLocalItems());
10 |
11 | function getLocalItems() {
12 | const list = localStorage.getItem("todos");
13 | if (list) {
14 | return JSON.parse(localStorage.getItem("todos"));
15 | } else {
16 | return [];
17 | }
18 | }
19 |
20 | useEffect(() => {
21 | localStorage.setItem("todos", JSON.stringify(todos));
22 | }, [todos]);
23 |
24 | const addTodoHandler = (text) => {
25 | const newTodo = {
26 | text: text,
27 | isCompleted: false,
28 | id: uuid(),
29 | data: new Date().toLocaleString(),
30 | };
31 |
32 | setTodos((prev) => [...prev, newTodo]);
33 | };
34 | //Бул addTodoHandler деген функцияда биз newTodo деген обьект ачып аны биз todosтагы пустой массивке сактадык. Мындайча айтканда жаны тудунун данныйларын бердик
35 |
36 | const delateTodoHandler = (id) => {
37 | const exchangeTodos = todos.filter((item) => item.id !== id);
38 | setTodos(exchangeTodos);
39 | };
40 | //бул жакта болсо todos филтер кылып жатабыз жана эгер item.id барабар болбосо todo нан келип жаткан id геудальтетет
41 |
42 | const updateTodoHandler = (id, changeText) => {
43 | setTodos((prev) =>
44 | prev.map((todo) =>
45 | todo.id === id
46 | ? {
47 | ...todo,
48 | text: changeText,
49 | data: new Date().toLocaleString(),
50 | }
51 | : todo
52 | )
53 | );
54 | };
55 | // бул жакта предудущий значенмени иттерация кылып text тин значениесин жаны todo дан келген значенияга алмаштырып жатабыз ошондой эле датаны жаны датага алмаштырып жатабыз
56 |
57 | const toggleTodoHandler = (id) => {
58 | setTodos(
59 | todos.map((todo) => {
60 | return todo.id === id
61 | ? {
62 | ...todo,
63 | isCompleted: !todo.isCompleted,
64 | data: new Date().toLocaleString(),
65 | }
66 | : todo;
67 | })
68 | );
69 | };
70 | //бул жакта todos ту иттерация кылып жатабыз , эгер todo нун id сине todo.jsx тен келген idсалыштырып жатабыз . эгер окшош болсо isCompleted ти озгортуп жатабыз , типа true= false, false=true, и плюс датаны жаны датага алмаштырып жатабыз
71 |
72 | const resetTodosHandler = () => {
73 | setTodos([]);
74 | };
75 | //бул жакта болсо биз бут тудо листтерди очуруп жатабыз
76 |
77 | const delateCompletedTodosHandler = () => {
78 | setTodos(todos.filter((todo) => !todo.isCompleted));
79 | };
80 | //Бул функция когда комплайтед басылса ошолорду очурот , мындайча айтканда буткон задачаларды очурот
81 |
82 | const completedTodosCaunt = todos.filter((todo) => todo.isCompleted).length;
83 | //бул болсо канча задачан буткон болсо ошону санап турат
84 |
85 | return (
86 |
87 |
88 | {!!todos.length && (
89 |
94 | )}
95 |
101 | {!!completedTodosCaunt > 0 && (
102 |
103 | You have to completed {completedTodosCaunt}
104 | {completedTodosCaunt > 1 ? " todos" : " todo"}
105 |
106 | )}
107 |
108 | );
109 | };
110 |
111 | export default TodoBox;
112 |
113 | const Conteiner = styled.div`
114 | display: flex;
115 | flex-direction: column;
116 | align-items: center;
117 | `;
118 | const Caunt = styled.h2`
119 | font-family: monospace;
120 | font-size: 1.2rem;
121 | margin-top: 2rem;
122 | color: white;
123 | `;
124 |
--------------------------------------------------------------------------------
/src/components/TodoForm.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import styled from "styled-components";
3 |
4 | const TodoForm = ({ onAddTodo }) => {
5 | const [enteredValue, setEnteredValue] = useState("");
6 | const [error, setError] = useState("");
7 |
8 | const submitHandler = (event) => {
9 | event.preventDefault();
10 | if (enteredValue !== "") {
11 | onAddTodo(enteredValue);
12 | } else if (enteredValue === "") {
13 | setError("The field should not be empty.");
14 | }
15 | setEnteredValue("");
16 | };
17 | //бул жакта биз сабмитке функция берип жатабыз жана инпутка валидация берип жатабыз
18 |
19 | const changeValue = (e) => {
20 | setEnteredValue(e.target.value);
21 | if (e.target.value === "") {
22 | setError("The field should not be empty.");
23 | } else {
24 | setError("");
25 | }
26 | };
27 | //бул жакта болсо инпутка валидация берип жатабыз
28 |
29 | return (
30 |
42 | );
43 | };
44 |
45 | export default TodoForm;
46 |
47 | const Form = styled.form`
48 | display: flex;
49 | `;
50 | const Button = styled.button`
51 | width: 4rem;
52 | height: 2rem;
53 | border-radius: 0.5rem;
54 | margin-left: 2rem;
55 | margin-top: 4.5rem;
56 | color: white;
57 | background: rgb(24, 148, 250);
58 | border: none;
59 | &:active {
60 | background: blue;
61 | }
62 | `;
63 | const Input = styled.input`
64 | width: 30rem;
65 | height: 3rem;
66 | padding: 1rem 1rem;
67 | &:focus {
68 | outline: none;
69 | border: 3px solid blue;
70 | }
71 | `;
72 | const InputWarning = styled.p`
73 | color: red;
74 | `;
75 | const Box = styled.div`
76 | display: flex;
77 | flex-direction: column;
78 | margin-top: 4rem;
79 | `;
80 |
--------------------------------------------------------------------------------
/src/components/TodoList.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import Todo from "./Todo";
3 |
4 | const TodoList = ({ todos, onDelateTodo, onToggle, onUpdate }) => {
5 | return (
6 |
7 | {todos.map((todo) => (
8 |
15 | ))}
16 |
17 | );
18 | };
19 |
20 | export default TodoList;
21 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | *{
2 | margin: 0;
3 | padding: 0;
4 | box-sizing: border-box;
5 | }
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 |
6 | const root = ReactDOM.createRoot(document.getElementById('root'));
7 | root.render(
8 |
9 |
10 |
11 | );
12 |
13 |
--------------------------------------------------------------------------------