Browse Source

react hw 3

Olga1108 4 years ago
commit
4738f7250f
43 changed files with 17128 additions and 0 deletions
  1. 1 0
      .eslintcache
  2. 23 0
      .gitignore
  3. 70 0
      README.md
  4. 16404 0
      package-lock.json
  5. 38 0
      package.json
  6. BIN
      public/favicon.ico
  7. 43 0
      public/index.html
  8. BIN
      public/logo192.png
  9. BIN
      public/logo512.png
  10. 25 0
      public/manifest.json
  11. 3 0
      public/robots.txt
  12. 12 0
      src/App/App.css
  13. 25 0
      src/App/App.jsx
  14. 2 0
      src/App/index.js
  15. 10 0
      src/components/Button/Button.jsx
  16. 15 0
      src/components/Button/button.css
  17. 2 0
      src/components/Button/index.js
  18. 16 0
      src/components/Input/Input.jsx
  19. 2 0
      src/components/Input/index.js
  20. 6 0
      src/components/Input/input.css
  21. 14 0
      src/components/Label/Label.jsx
  22. 2 0
      src/components/Label/index.js
  23. 0 0
      src/components/Label/label.css
  24. 25 0
      src/components/UserCard/UserCard.jsx
  25. 2 0
      src/components/UserCard/index.js
  26. 36 0
      src/components/UserCard/userCard.css
  27. 43 0
      src/containers/CreateNewUser/CreateNewUser.jsx
  28. 24 0
      src/containers/CreateNewUser/createNewUser.css
  29. 2 0
      src/containers/CreateNewUser/index.js
  30. 14 0
      src/containers/Footer/Footer.jsx
  31. 7 0
      src/containers/Footer/footer.css
  32. 2 0
      src/containers/Footer/index.js
  33. 35 0
      src/containers/Main/Main.jsx
  34. 2 0
      src/containers/Main/index.js
  35. 5 0
      src/containers/Main/main.css
  36. 71 0
      src/containers/Popup/Popup.jsx
  37. 2 0
      src/containers/Popup/index.js
  38. 61 0
      src/containers/Popup/popup.css
  39. 25 0
      src/containers/UsersComponent/UsersComponent.jsx
  40. 2 0
      src/containers/UsersComponent/index.js
  41. 27 0
      src/containers/UsersComponent/usersComponent.css
  42. 19 0
      src/index.css
  43. 11 0
      src/index.js

File diff suppressed because it is too large
+ 1 - 0
.eslintcache


+ 23 - 0
.gitignore

@@ -0,0 +1,23 @@
+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+/.pnp
+.pnp.js
+
+# testing
+/coverage
+
+# production
+/build
+
+# misc
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*

+ 70 - 0
README.md

@@ -0,0 +1,70 @@
+# Getting Started with Create React App
+
+This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
+
+## Available Scripts
+
+In the project directory, you can run:
+
+### `npm start`
+
+Runs the app in the development mode.\
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
+
+The page will reload if you make edits.\
+You will also see any lint errors in the console.
+
+### `npm test`
+
+Launches the test runner in the interactive watch mode.\
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
+
+### `npm run build`
+
+Builds the app for production to the `build` folder.\
+It correctly bundles React in production mode and optimizes the build for the best performance.
+
+The build is minified and the filenames include the hashes.\
+Your app is ready to be deployed!
+
+See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
+
+### `npm run eject`
+
+**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
+
+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.
+
+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.
+
+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.
+
+## Learn More
+
+You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
+
+To learn React, check out the [React documentation](https://reactjs.org/).
+
+### Code Splitting
+
+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)
+
+### Analyzing the Bundle Size
+
+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)
+
+### Making a Progressive Web App
+
+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)
+
+### Advanced Configuration
+
+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)
+
+### Deployment
+
+This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
+
+### `npm run build` fails to minify
+
+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)

File diff suppressed because it is too large
+ 16404 - 0
package-lock.json


+ 38 - 0
package.json

@@ -0,0 +1,38 @@
+{
+  "name": "hw3react",
+  "version": "0.1.0",
+  "private": true,
+  "dependencies": {
+    "@testing-library/jest-dom": "^5.11.6",
+    "@testing-library/react": "^11.2.2",
+    "@testing-library/user-event": "^12.6.0",
+    "react": "^17.0.1",
+    "react-dom": "^17.0.1",
+    "react-scripts": "4.0.1",
+    "web-vitals": "^0.2.4"
+  },
+  "scripts": {
+    "start": "react-scripts start",
+    "build": "react-scripts build",
+    "test": "react-scripts test",
+    "eject": "react-scripts eject"
+  },
+  "eslintConfig": {
+    "extends": [
+      "react-app",
+      "react-app/jest"
+    ]
+  },
+  "browserslist": {
+    "production": [
+      ">0.2%",
+      "not dead",
+      "not op_mini all"
+    ],
+    "development": [
+      "last 1 chrome version",
+      "last 1 firefox version",
+      "last 1 safari version"
+    ]
+  }
+}

BIN
public/favicon.ico


+ 43 - 0
public/index.html

@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8" />
+    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <meta name="theme-color" content="#000000" />
+    <meta
+      name="description"
+      content="Web site created using create-react-app"
+    />
+    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
+    <!--
+      manifest.json provides metadata used when your web app is installed on a
+      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
+    -->
+    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
+    <!--
+      Notice the use of %PUBLIC_URL% in the tags above.
+      It will be replaced with the URL of the `public` folder during the build.
+      Only files inside the `public` folder can be referenced from the HTML.
+
+      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
+      work correctly both with client-side routing and a non-root public URL.
+      Learn how to configure a non-root public URL by running `npm run build`.
+    -->
+    <title>React App</title>
+  </head>
+  <body>
+    <noscript>You need to enable JavaScript to run this app.</noscript>
+    <div id="root"></div>
+    <!--
+      This HTML file is a template.
+      If you open it directly in the browser, you will see an empty page.
+
+      You can add webfonts, meta tags, or analytics to this file.
+      The build step will place the bundled scripts into the <body> tag.
+
+      To begin the development, run `npm start` or `yarn start`.
+      To create a production bundle, use `npm run build` or `yarn build`.
+    -->
+  </body>
+</html>

BIN
public/logo192.png


BIN
public/logo512.png


+ 25 - 0
public/manifest.json

@@ -0,0 +1,25 @@
+{
+  "short_name": "React App",
+  "name": "Create React App Sample",
+  "icons": [
+    {
+      "src": "favicon.ico",
+      "sizes": "64x64 32x32 24x24 16x16",
+      "type": "image/x-icon"
+    },
+    {
+      "src": "logo192.png",
+      "type": "image/png",
+      "sizes": "192x192"
+    },
+    {
+      "src": "logo512.png",
+      "type": "image/png",
+      "sizes": "512x512"
+    }
+  ],
+  "start_url": ".",
+  "display": "standalone",
+  "theme_color": "#000000",
+  "background_color": "#ffffff"
+}

+ 3 - 0
public/robots.txt

@@ -0,0 +1,3 @@
+# https://www.robotstxt.org/robotstxt.html
+User-agent: *
+Disallow:

+ 12 - 0
src/App/App.css

@@ -0,0 +1,12 @@
+.wrapper {
+  position: relative;
+  max-width: 100%;
+  overflow: hidden;
+}
+
+.container {
+  width: 100%;
+  max-width: 1400px;
+  margin: 0 auto;
+  padding: 0 15px;
+}

+ 25 - 0
src/App/App.jsx

@@ -0,0 +1,25 @@
+import React, { useState } from 'react';
+import Main from '../containers/Main';
+import Popup from '../containers/Popup';
+import './App.css';
+
+function App() {
+  
+  const [isOpenPopup, setOpenPopup] = useState(false);
+
+  const handleSwitchPopup = () => {
+    setOpenPopup(!isOpenPopup);
+  }
+
+  const [userPopup, setUserPopup] = useState({});
+  
+  
+  return (
+    <div className="wrapper">
+      <Main setUserPopup={setUserPopup} handleSwitchPopup={handleSwitchPopup} />
+      {isOpenPopup && <Popup userPopup={userPopup} handleSwitchPopup={handleSwitchPopup} />}
+    </div>
+  );
+}
+
+export default App;

+ 2 - 0
src/App/index.js

@@ -0,0 +1,2 @@
+import App from './App';
+export default App;

+ 10 - 0
src/components/Button/Button.jsx

@@ -0,0 +1,10 @@
+import React from 'react';
+import './button.css';
+
+const Input = ({ type, buttonName }) => {
+  return (
+    <button className="btn" type={type}>{buttonName}</button>
+  )
+}
+
+export default Input;

+ 15 - 0
src/components/Button/button.css

@@ -0,0 +1,15 @@
+.btn {
+    display: inline-block;
+    margin-top: 30px;
+    padding: 10px 20px;
+    font-size: 14px;
+    background-color: #3080f8;
+    border: none;
+    cursor: pointer;
+    transition: 0.3s;
+}
+  
+.btn:hover {
+    background-color: #0f49c7;
+    color: white;
+} 

+ 2 - 0
src/components/Button/index.js

@@ -0,0 +1,2 @@
+import Button from './Button';
+export default Button;

+ 16 - 0
src/components/Input/Input.jsx

@@ -0,0 +1,16 @@
+import React from 'react';
+import './input.css';
+
+const Input = (props) => {
+  return (
+    <input
+      type={props.type}
+      name={props.name}
+      placeholder={props.placeholder}
+      value={props.value}
+      onChange={props.onChange}
+    />
+  )
+}
+
+export default Input;

+ 2 - 0
src/components/Input/index.js

@@ -0,0 +1,2 @@
+import Input from './Input';
+export default Input;

+ 6 - 0
src/components/Input/input.css

@@ -0,0 +1,6 @@
+input {
+    margin-right: 10px;
+    padding: 10px;
+    font-size: 14px;
+    border: 1px solid rgb(8, 8, 8);
+} 

+ 14 - 0
src/components/Label/Label.jsx

@@ -0,0 +1,14 @@
+import React from 'react';
+import './label.css'
+
+const Label = ({
+   
+    children
+})=> {
+    return <label>
+                   {children}
+            </label>
+   
+}
+
+export default Label;

+ 2 - 0
src/components/Label/index.js

@@ -0,0 +1,2 @@
+import Label from './Label';
+export default Label;

+ 0 - 0
src/components/Label/label.css


+ 25 - 0
src/components/UserCard/UserCard.jsx

@@ -0,0 +1,25 @@
+import React from 'react';
+import './userCard.css';
+
+const UserCard = ({ user, deleteUser, setUserPopup, handleSwitchPopup }) => {
+
+  const openPopup = (e) => {
+    if (!e.target.classList.contains('btn')) {
+      setUserPopup(user);
+      handleSwitchPopup();
+    }
+  }
+
+  return (
+    <div className="user" onClick={openPopup}>
+      <div className="user__body">
+        <h3>{user.name}</h3>
+        <h4>{user.surname}</h4>
+        <p>{user.address}</p>
+        <button type="button" className="btn" onClick={() => deleteUser(user.id)}>delete</button>
+      </div>
+    </div>
+  );
+}
+
+export default UserCard;

+ 2 - 0
src/components/UserCard/index.js

@@ -0,0 +1,2 @@
+import UserCard from './UserCard';
+export default UserCard;

+ 36 - 0
src/components/UserCard/userCard.css

@@ -0,0 +1,36 @@
+.user {
+    margin-bottom: 30px;
+    padding: 0 15px;
+    text-align: center;
+  }
+.user  p {
+    margin: 0;
+  }
+  
+.user__body {
+    padding: 10px 0;
+    border: 1px solid black;
+}
+
+.user__body:hover {
+    box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
+    cursor: pointer;
+}
+   
+  
+  
+@media (min-width: 768px) {
+  
+    .user {
+      width: 50%;
+    }
+  
+}
+  
+@media (min-width: 1200px) {
+  
+    .user {
+      width: calc(100% / 3);
+    }
+  
+}

+ 43 - 0
src/containers/CreateNewUser/CreateNewUser.jsx

@@ -0,0 +1,43 @@
+import React from 'react';
+import Input from '../../components/Input';
+import Button from '../../components/Button';
+import Label from '../../components/Label';
+import './createNewUser.css';
+
+const CreateNewUser = ({ users, setUsers }) => {
+  let id = new Date().getTime();
+  const createUser = (target) => {
+    const name = target.elements['name'].value;
+    const surname = target.elements['surname'].value;
+    const address = target.elements['address'].value;
+
+    if (name && surname && address) {
+      const newUser = {
+        id: id,
+        name, surname, address
+      }
+
+      users.push(newUser);
+      setUsers([...users]);
+      target.reset();
+    } 
+
+  }
+
+  return (
+    <form className="form_create_user" onSubmit={(e) => {
+      e.preventDefault()
+      createUser(e.target)
+    }}>
+      <Label>Enter Name
+      <Input type={'text'} name={'name'} /></Label>
+      <Label>Enter Surname
+      <Input type={'text'} name={'surname'} /></Label>
+      <Label>Enter address
+      <Input type={'text'} name={'address'} /></Label>
+      <Button type="submit" buttonName={'Create user'} />
+    </form>
+  )
+}
+
+export default CreateNewUser;

+ 24 - 0
src/containers/CreateNewUser/createNewUser.css

@@ -0,0 +1,24 @@
+.form_create_user {  
+    display: flex;
+    flex-direction: column;
+    margin-top: 20px;
+    padding: 10px;
+    border: 1px solid black;
+  }
+    .form_create_user input {
+      margin-right: 50px;
+      margin-bottom: 5px;
+    }
+  
+    .form_create_user button {    
+      align-self: center;
+      padding: 10px 60px;    
+    }
+  
+  
+  @media (min-width: 768px) {
+    .form_create_user {  
+      max-width: 40%;
+      margin-right: 20px;
+    }
+  }

+ 2 - 0
src/containers/CreateNewUser/index.js

@@ -0,0 +1,2 @@
+import CreateNewUser from './CreateNewUser';
+export default CreateNewUser;

+ 14 - 0
src/containers/Footer/Footer.jsx

@@ -0,0 +1,14 @@
+import React from 'react';
+import './footer.css';
+
+const Footer = (props) => {
+  return (
+    
+      <p className="footer_count">
+        Total users count: {props.users.length}
+      </p>
+   
+  )
+}
+
+export default Footer;

+ 7 - 0
src/containers/Footer/footer.css

@@ -0,0 +1,7 @@
+.footer_count {
+  padding: 15px;
+  font-size: 24px;
+  font-weight: bold;
+  text-align: center;
+  border: 1px solid black;
+}

+ 2 - 0
src/containers/Footer/index.js

@@ -0,0 +1,2 @@
+import Footer from './Footer';
+export default Footer;

+ 35 - 0
src/containers/Main/Main.jsx

@@ -0,0 +1,35 @@
+import React, { useState } from 'react';
+import UsersComponent from '../UsersComponent';
+import CreateNewUser from '../CreateNewUser';
+import './main.css';
+import Footer from '../Footer';
+
+
+const Main = ({ setUserPopup, handleSwitchPopup }) => {
+  
+   
+  const [users, setUsers] = useState([]);
+  
+  const deleteUser = (id) => {
+    setUsers(users.filter(u => u.id !== id));
+  }
+
+  return (
+    <main>
+      <div className="container">
+        <div className="users_wrapper">
+          <CreateNewUser users={users} setUsers={setUsers} />
+          <UsersComponent
+            users={users}
+            deleteUser={deleteUser}
+            setUserPopup={setUserPopup}
+            handleSwitchPopup={handleSwitchPopup}
+          />
+        </div>
+        <Footer users={users}/>
+      </div>
+    </main>
+  );
+}
+
+export default Main;

+ 2 - 0
src/containers/Main/index.js

@@ -0,0 +1,2 @@
+import Main from './Main';
+export default Main;

+ 5 - 0
src/containers/Main/main.css

@@ -0,0 +1,5 @@
+@media (min-width: 768px) {
+    .users_wrapper {
+      display: flex;    
+    }
+  }

+ 71 - 0
src/containers/Popup/Popup.jsx

@@ -0,0 +1,71 @@
+import React, { useState } from 'react';
+import Input from '../../components/Input'
+import Button from '../../components/Button'
+import './popup.css';
+
+const Popup = ({ userPopup, handleSwitchPopup }) => {
+  const [name, setName] = useState(userPopup.name);
+  const [surname, setSurname] = useState(userPopup.surname);
+  const [address, setAddress] = useState(userPopup.address);
+
+  const closePopup = (e) => {
+    e.stopPropagation();
+    if (e.target.classList.contains("popup")) {
+      handleSwitchPopup();
+    }
+  }
+
+  const changeUser = (target) => {
+    const name = target.elements['name'].value;
+    const surname = target.elements['surname'].value;
+    const address = target.elements['address'].value;
+
+    if (name && surname && address) {
+      userPopup.name = name;
+      userPopup.surname = surname;
+      userPopup.address = address;
+    }
+
+    handleSwitchPopup();
+
+  }
+
+  return (
+    <div className="popup" onClick={closePopup}>
+      <div className="popup_content">
+        <span className="close" onClick={handleSwitchPopup}>&times;</span>
+        <form className="form_change_user" onSubmit={(e) => {
+          e.preventDefault()
+          changeUser(e.target)
+        }}>
+
+          <Input
+            type={'text'} 
+            name={'name'}
+            value={name}
+            onChange={(e) => setName(e.target.value)}
+          />
+          <Input
+            type={'text'}
+            name={'surname'}
+            value={surname}
+            onChange={(e) => setSurname(e.target.value)}
+          />
+          <Input
+            type={'text'}
+            name={'address'}
+            value={address}
+            onChange={(e) => setAddress(e.target.value)}
+          />
+
+          <Button buttonName={'Save'} />
+
+          
+        </form>
+      </div>
+    </div>
+
+  )
+}
+
+export default Popup;

+ 2 - 0
src/containers/Popup/index.js

@@ -0,0 +1,2 @@
+import Popup from './Popup';
+export default Popup;

+ 61 - 0
src/containers/Popup/popup.css

@@ -0,0 +1,61 @@
+.popup {
+    position: fixed;
+    z-index: 1;
+    left: 0;
+    top: 0;
+    width: 100%;
+    height: 100%;
+    overflow: auto;
+    background-color: rgba(0, 0, 0, .4);
+    animation-name: zoomIn;
+  }
+  .popup_content {
+      position: absolute;
+      top: 50%;
+      left: 50%;
+      width: 80%;
+      padding: 20px;
+      text-align: center;
+      background-color: #fefefe;
+      border: 1px solid rgb(28, 28, 29);
+      transform: translate(-50%, -50%);
+  }
+  
+  .close {
+    position: absolute;
+    top: -10px;
+    right: 2px;
+    color: rgb(92, 112, 138);
+    font-size: 28px;
+    font-weight: bold;
+    transition: color .3s ease;
+  }
+.close:hover,
+.close:focus {
+      color: rgb(60, 61, 63);
+      text-decoration: none;
+      cursor: pointer;
+    }
+  
+.form_change_user input {
+      margin-bottom: 10px;
+      width: 100%;
+}
+.form_change_user:first-child {
+        margin-top: 10px;
+}
+    
+  
+  
+  @media (min-width: 768px) {
+    .popup_content {
+      width: 50%;  
+    }
+  }
+  
+  @media (min-width: 1200px) {
+    .popup_content {
+      width: 35%;
+    }
+    
+  }

+ 25 - 0
src/containers/UsersComponent/UsersComponent.jsx

@@ -0,0 +1,25 @@
+import React from 'react';
+import UserCard from '../../components/UserCard';
+import './usersComponent.css';
+
+const UsersComponent = ({ users, deleteUser, setUserPopup, handleSwitchPopup }) => {
+
+  let listOfUsers = users.map(user =>
+    <UserCard
+      key={user.id}
+      user={user}
+      deleteUser={deleteUser}
+      setUserPopup={setUserPopup}
+      handleSwitchPopup={handleSwitchPopup}
+    />);
+
+  return (
+    <section className="users_box">
+      <div className="users_component">
+        {listOfUsers}
+      </div>
+    </section>
+  );
+}
+
+export default UsersComponent;

+ 2 - 0
src/containers/UsersComponent/index.js

@@ -0,0 +1,2 @@
+import UsersComponent from './UsersComponent';
+export default UsersComponent;

+ 27 - 0
src/containers/UsersComponent/usersComponent.css

@@ -0,0 +1,27 @@
+.users_box {
+    padding: 20px 0;
+    border: 1px solid black;
+    margin-top: 20px;
+  }
+  
+  .users_component {
+    margin-bottom: -30px;
+  }
+  
+  
+  @media (min-width: 768px) {
+  
+    .users_component {
+      display: flex;
+      flex-wrap: wrap;
+    }
+  
+  }
+  
+  @media (min-width: 1200px) {
+  
+    .users_box {
+      width: 80%;
+    }
+    
+  }

+ 19 - 0
src/index.css

@@ -0,0 +1,19 @@
+*,
+*::before,
+*::after {
+  box-sizing: border-box;
+}
+
+body {
+  margin: 0;
+  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
+    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
+    sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+}
+
+code {
+  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
+    monospace;
+}

+ 11 - 0
src/index.js

@@ -0,0 +1,11 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import './index.css';
+import App from './App';
+
+ReactDOM.render(
+  <React.StrictMode>
+    <App />
+  </React.StrictMode>,
+  document.getElementById('root')
+);