Browse Source

jsx-homework

kurkabein 3 years ago
parent
commit
e508f2e006

+ 18 - 0
JSX-homework/.gitignore

@@ -0,0 +1,18 @@
+# See https://help.github.com/ignore-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+
+# testing
+/coverage
+
+# production
+/build
+
+# misc
+.DS_Store
+.env
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+

File diff suppressed because it is too large
+ 1623 - 0
JSX-homework/README.md


File diff suppressed because it is too large
+ 10225 - 0
JSX-homework/package-lock.json


+ 21 - 0
JSX-homework/package.json

@@ -0,0 +1,21 @@
+{
+  "name": "redux-shop",
+  "version": "0.1.0",
+  "private": true,
+  "dependencies": {
+    "node-sass": "^7.0.1",
+    "react": "^17.0.2",
+    "react-dom": "^17.0.2",
+    "react-redux": "^7.2.6",
+    "react-scripts": "0.9.5",
+    "redux": "^4.1.2",
+    "redux-thunk": "^2.4.1"
+  },
+  "devDependencies": {},
+  "scripts": {
+    "start": "react-scripts start",
+    "build": "react-scripts build",
+    "test": "react-scripts test --env=jsdom",
+    "eject": "react-scripts eject"
+  }
+}

BIN
JSX-homework/public/favicon.ico


+ 31 - 0
JSX-homework/public/index.html

@@ -0,0 +1,31 @@
+<!doctype html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
+    <!--
+      Notice the use of %PUBLIC_URL% in the tag 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>
+    <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`.
+      To create a production bundle, use `npm run build`.
+    -->
+  </body>
+</html>

+ 156 - 0
JSX-homework/src/App.js

@@ -0,0 +1,156 @@
+import React, { useEffect, useState } from 'react';
+import defaultLogo from './logo.svg';
+import './App.scss';
+
+const Logo = ({logo=defaultLogo}) =>
+<img  className="Logo" src={logo} alt='logo'/>
+
+const Header = ({children}) =>
+<header>
+    <Logo />
+    {children}
+</header>
+
+let defaultCategories = [{
+  "name": "     Smartphones",
+  "_id": "5dc458985df9d670df48cc47"
+},
+{
+  "name": "Холодильники",
+  "_id": "5dc4b2553f23b553bf3540fc"
+},
+{
+  "name": "Стиральные машины",
+  "_id": "5dc4b2553f23b553bf3540fd"
+},
+{
+  "name": "Стирально-сушильные машины",
+  "_id": "5dc4b2553f23b553bf3540fe"
+},
+{
+  "name": "Стиральные машины",
+  "_id": "5dc4b2553f23b553bf3540ff"
+},
+{
+  "name": "Духовые шкафы",
+  "_id": "5dc4b2553f23b553bf354100"
+},
+{
+  "name": "Крупная бытовая техника",
+  "_id": "5dc4b2553f23b553bf354101"
+},
+{
+  "name": " Макароны",
+  "_id": "5dcac1b56d09c45440d14cf8"
+},
+{
+  "name": "Drinks",
+  "_id": "5dcac6cf6d09c45440d14cfd"
+}]
+const CategoryItem = ({category:{_id,name}= {}}) =>
+<li className='CategoryItem'>
+  {name}
+</li>
+
+const RootCategories = ({categories = defaultCategories}) =>
+<ul className='RootCategories'>
+      {categories.map(category => <CategoryItem category={category}/>)}
+</ul>
+
+
+const Aside = ({}) =>
+<aside>
+  <RootCategories/>
+</aside>
+const Content = ({children}) =>
+<section className='Content'>
+    {children}
+</section>
+
+const Main = ({children}) =>
+<section>
+  <Aside/>
+  <Content>
+    <Logo/>
+    {children}
+  </Content>
+  {children}
+</section>
+
+const Footer = ({children}) =>
+<footer>
+  <Logo/>
+  {children}
+</footer>
+
+const Input = () => {
+  const [text, setText] = useState('text');
+  return <div>
+    <h1>{text}</h1>
+    <input value={text} onChange={e => setText(e.target.value)} />
+  </div>
+  
+}
+const LoginForm = ({onLogin}) => {
+  const [login, setLogin] = useState('');
+  const [pswd, setPswd] = useState('');
+
+  return <div>
+      <input value={login} onChange={e => setLogin(e.target.value)}/> 
+      <input value={pswd} onChange={e => setPswd(e.target.value)}/>
+      <button disabled={login.length<3 || pswd.length<8 ? true:""} onClick={() => onLogin(login,pswd)}>Login</button>   
+  </div>
+}
+
+const Counter = ({ms=1000}) => {
+  const [counter, setCounter] = useState(0)
+  useEffect(() => {
+   const interval = setInterval (() => setCounter(counter => counter+1), ms)
+    return () => {
+      console.log('DID UNMOUNT')
+      clearInterval(interval)
+    }
+  }, [ms])
+  /* setInterval (() => setCounter(counter+1), 1000) */
+  return (
+    <div>{counter}</div>
+  )
+}
+const Spoiler = ({children}) => {
+  const [open, setOpen] = useState(true)
+  return (
+    <div>
+        <button onClick={()=>setOpen(!open)}>Toggle</button>
+        {open && children}
+    </div>
+  )
+}
+
+const Counters = () => {
+  const [cntrs, setCntrs] = useState([1,2,3])
+  const [ms, setMs] = useState(1000)
+  return (
+    <div>
+      <button onClick={() => setCntrs(ms+100)}>+</button>
+      <button onClick={() => setCntrs(ms-100)}>-</button>
+      {cntrs.map(() => <Counter/>)}
+      <button onClick={() => setCntrs([...cntrs, cntrs.length])}>Add</button>
+    </div>
+  )
+}
+
+
+
+
+function App () {
+  return(
+    <div className='App'>
+      <Input/>
+      <LoginForm onLogin={(login, password) => console.log(login,password)}/>
+      <Spoiler>
+      <Counter/>
+      </Spoiler>
+    </div>
+  );
+}
+export default App;

+ 11 - 0
JSX-homework/src/App.scss

@@ -0,0 +1,11 @@
+.App {
+  text-align: center;
+  header {
+    .Logo{
+      max-width: 100px;
+    }
+  }
+}
+.RootCategories {
+  list-style: none;
+}

+ 8 - 0
JSX-homework/src/App.test.js

@@ -0,0 +1,8 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import App from './App';
+
+it('renders without crashing', () => {
+  const div = document.createElement('div');
+  ReactDOM.render(<App />, div);
+});

+ 5 - 0
JSX-homework/src/index.css

@@ -0,0 +1,5 @@
+body {
+  margin: 0;
+  padding: 0;
+  font-family: sans-serif;
+}

+ 9 - 0
JSX-homework/src/index.js

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

File diff suppressed because it is too large
+ 7 - 0
JSX-homework/src/logo.svg