├── .eslintrc ├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json ├── src ├── App.js ├── index.css ├── index.js ├── layout │ ├── footer │ │ ├── footer.css │ │ └── footer.jsx │ ├── home │ │ ├── constants.js │ │ ├── home.css │ │ └── home.jsx │ ├── main │ │ ├── main.css │ │ └── main.jsx │ └── navigation │ │ ├── navigation.css │ │ └── navigation.jsx └── registerServiceWorker.js └── yarn.lock /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended", 4 | "plugin:import/errors", 5 | "plugin:import/warnings", 6 | "airbnb" 7 | ], 8 | "plugins": [ 9 | "react" 10 | ], 11 | "parser": "babel-eslint", 12 | "parserOptions": { 13 | "ecmaVersion": 6, 14 | "sourceType": "module", 15 | "ecmaFeatures": { 16 | "jsx": true 17 | } 18 | }, 19 | "env": { 20 | "es6": true, 21 | "browser": true, 22 | "node": true, 23 | "jquery": true, 24 | "mocha": true 25 | }, 26 | "rules": { 27 | "arrow-parens": ["error", "as-needed"], 28 | "no-console": "off", 29 | "consistent-return": "off", 30 | "no-param-reassign": "off", 31 | "jsx-a11y/click-events-have-key-events": "off", 32 | "jsx-a11y/no-static-element-interactions": "off", 33 | "jsx-a11y/label-has-for": "off", 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Components 2 | 3 | ### Описание курса: 4 | В данном видео-курсе мы с вами создадим библиотеку компонентов для проектов на **ReactJS**. Целью данного курса лекций является не создать абсалютно универсальные компоненты, а научиться мыслить в компонентном стиле и постараться создавать гибкие и переиспользуемые модули. Мы с вами рассмотрим создание как простых компонентов таких как кнопки, бейджики, иконки и т.д. так и объединение их в более сложные компоненты: табы, чипы, модальные окна. 5 | 6 | ### Поддержать развитие канала: 7 | [webDev | YouTube Sponsor][sponsor] 8 | [webDev | Patreon][patron] 9 | 10 | --- 11 | 12 | ### Используемые ресурсы и инструменты: 13 | - [Atom (Редактор кода)](https://atom.io/) 14 | - [Create React App (рабочее окружение)](https://github.com/facebook/create-react-app) 15 | - [React Developer Tools (расширение для браузера)](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=ru) 16 | 17 | ### Полезные ссылки: 18 | - [React (документация)](https://reactjs.org/docs/getting-started.html) 19 | 20 | --- 21 | 22 | ### Быстрый старт: 23 | - Клонируйте репозиторий: `git clone https://github.com/YauhenKavalchuk/react-components.git` 24 | - Перейдите в нужную ветку соответствующую уроку: 25 | - `git checkout 02_button` 26 | - `git checkout 04_icon` и т.д. 27 | - Установите зависимости: `yarn install` или `npm install` 28 | - Запустите проект: `yarn start` или `npm start` 29 | 30 | ### Дополнительные комманды: 31 | 32 | - Запустить линт проекта: `yarn lint` или `npm run lint` 33 | 34 | --- 35 | 36 | ### Список уроков: 37 | - [#0 Введение в курс (Introduction)](https://youtu.be/YBwUfpDIMgw) 38 | - [#1 Установка окружения (Environment)](https://youtu.be/B0CL6vwuQnk) 39 | - [#2 Кнопка (Button)](https://youtu.be/cZIm24kxDzU) 40 | - [#3 Группа кнопок (Button group)](https://youtu.be/tfTM3WecJx8) 41 | - [#4 Иконка (Icon)](https://youtu.be/oSe7_r-H_Wo) 42 | - [#5 Картинка (Image)](https://youtu.be/RHBfeKNjcmQ) 43 | - [#6 Фишка (Chip)](https://youtu.be/pHPEOmudb4I) 44 | - [#7 Бейдж (Badge)](https://youtu.be/m4BiLKfe_x8) 45 | - [#8 Группированный список (List group)](https://youtu.be/zqTkDPxaLZU) 46 | - [#9 Поле ввода (Input)](https://youtu.be/lffkJxoUEeY) 47 | - [#10 Табы (Tabs)](https://youtu.be/hPfzI1-to6A) 48 | - [#11 Подсказка (Tooltip)](https://youtu.be/WsxjZgw5LBg) 49 | - [#12 Модальное окно (Modal window)](https://youtu.be/olTU0zfN_Wk) 50 | 51 | --- 52 | 53 | ### Связаться со мной: 54 | [webDev | YouTube][youtube] 55 | [webDev | Instagram][instagram] 56 | [webDev | LinkedIn][linkedin] 57 | [webDev | Twitter][twitter] 58 | [webDev | VK][vk] 59 | 60 | [youtube]: https://youtube.com/YauhenKavalchuk 61 | [instagram]: https://instagram.com/YauhenKavalchuk 62 | [linkedin]: https://linkedin.com/in/YauhenKavalchuk 63 | [vk]: https://vk.com/YauhenKavalchuk 64 | [twitter]: https://twitter.com/YauhenKavalchuk 65 | [sponsor]: https://www.youtube.com/channel/UCE9ODjNIkOHrnSdkYWLfYhg/join 66 | [patron]: https://www.patreon.com/YauhenKavalchuk 67 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "React_Components", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "classnames": "2.2.6", 7 | "eslint-config-airbnb": "^17.1.0", 8 | "prop-types": "15.6.2", 9 | "react": "16.6.0", 10 | "react-dom": "16.6.0", 11 | "react-router-dom": "^4.3.1", 12 | "react-scripts": "2.0.5" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test --env=jsdom", 18 | "eject": "react-scripts eject", 19 | "lint": "eslint src/**/*.jsx" 20 | }, 21 | "browserslist": [ 22 | ">0.2%", 23 | "not dead", 24 | "not ie <= 11", 25 | "not op_mini all" 26 | ], 27 | "devDependencies": { 28 | "eslint-plugin-react": "^7.11.1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YauhenKavalchuk/react-components/0e058987aad66d373176962a3ed5a49de1be4970/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | React Components 12 | 13 | 14 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 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 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import Navigation from './layout/navigation/navigation'; 4 | import Main from './layout/main/main'; 5 | 6 | const App = ({ children }) => [ 7 | , 8 |
9 | {children} 10 |
, 11 | ]; 12 | 13 | export default App; 14 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: 'Roboto', sans-serif; 5 | font-size: 14px; 6 | } 7 | 8 | body * { 9 | font-family: 'Roboto', sans-serif; 10 | outline: none; 11 | } 12 | 13 | #root { 14 | min-height: 100vh; 15 | display: grid; 16 | grid-template-columns: 1fr 5fr; 17 | } 18 | 19 | h1 span, h2 span, h3 span, h4 span, h5 span, h6 span { 20 | border-bottom: 1px solid #C0C0C0; 21 | display: inline-block; 22 | padding-bottom: 5px; 23 | } 24 | 25 | a { 26 | text-decoration: none; 27 | color: #000; 28 | } 29 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import { BrowserRouter, Switch, Route } from 'react-router-dom'; 5 | import App from './App'; 6 | import registerServiceWorker from './registerServiceWorker'; 7 | 8 | import Home from './layout/home/home'; 9 | 10 | ReactDOM.render(( 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ), document.getElementById('root')); 19 | registerServiceWorker(); 20 | -------------------------------------------------------------------------------- /src/layout/footer/footer.css: -------------------------------------------------------------------------------- 1 | .footer { 2 | min-height: 100px; 3 | background-color: #D43728; 4 | display: flex; 5 | align-items: center; 6 | justify-content: center; 7 | padding: 0 50px; 8 | color: #fff; 9 | box-shadow: 1px 1px 10px #777; 10 | } 11 | -------------------------------------------------------------------------------- /src/layout/footer/footer.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './footer.css'; 3 | 4 | const Footer = () => ( 5 |
Created with love
6 | ); 7 | 8 | export default Footer; 9 | -------------------------------------------------------------------------------- /src/layout/home/constants.js: -------------------------------------------------------------------------------- 1 | export const SOCIAL_CONFIG = [ 2 | { 3 | id: 'youtube', 4 | socialLink: 'https://youtube.com/c/YauhenKavalchuk', 5 | imageLink: 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Logo_of_YouTube_%282015-2017%29.svg/1280px-Logo_of_YouTube_%282015-2017%29.svg.png', 6 | imgHeight: '37', 7 | }, 8 | { 9 | id: 'linkedin', 10 | socialLink: 'https://www.linkedin.com/in/YauhenKavalchuk', 11 | imageLink: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/01/LinkedIn_Logo.svg/1280px-LinkedIn_Logo.svg.png', 12 | imgHeight: '30', 13 | }, 14 | { 15 | id: 'vk', 16 | socialLink: 'https://vk.com/YauhenKavalchuk', 17 | imageLink: 'http://pngimg.com/uploads/vkontakte/vkontakte_PNG27.png', 18 | imgHeight: '35', 19 | }, 20 | { 21 | id: 'twitter', 22 | socialLink: 'https://twitter.com/YauhenKavalchuk', 23 | imageLink: 'http://www.fehrandpeers.com/wp-content/uploads/2015/12/TwitterLogo.png', 24 | imgHeight: '35', 25 | }, 26 | ]; 27 | 28 | export const DEPENDENCIES = [ 29 | { 30 | id: 'proptypes', 31 | name: 'PropTypes', 32 | link: 'https://www.npmjs.com/package/prop-types', 33 | }, 34 | { 35 | id: 'classnames', 36 | name: 'classNames', 37 | link: 'https://www.npmjs.com/package/classnames', 38 | }, 39 | ]; 40 | -------------------------------------------------------------------------------- /src/layout/home/home.css: -------------------------------------------------------------------------------- 1 | .title { 2 | padding: 10px 0; 3 | } 4 | 5 | .dependencies, 6 | .socialList { 7 | list-style-type: none; 8 | padding: 0; 9 | } 10 | 11 | .socialList { 12 | display: flex; 13 | align-items: center; 14 | } 15 | 16 | .dependencyItem, 17 | .socialItem { 18 | margin: 0 10px; 19 | } 20 | 21 | .socialLink { 22 | display: block; 23 | } 24 | 25 | .dependencyLink { 26 | display: inline-block; 27 | color: #23C9FF; 28 | margin-bottom: 5px; 29 | } 30 | 31 | .dependencyLink:hover { 32 | text-decoration: underline; 33 | } 34 | -------------------------------------------------------------------------------- /src/layout/home/home.jsx: -------------------------------------------------------------------------------- 1 | import React, { Fragment } from 'react'; 2 | import { SOCIAL_CONFIG, DEPENDENCIES } from './constants'; 3 | import './home.css'; 4 | 5 | 6 | const Home = () => ( 7 | 8 |

Расширяемая коллекция Реакт компонентов.

9 |

В данном видео-курсе мы с вами создадим библиотеку компонентов для проектов на ReactJS.

10 |

Целью данного курса лекций является не создать абсалютно универсальные компоненты, а научиться мыслить в компонентном стиле и постараться создавать гибкие и переиспользуемые модули.

11 |

Мы с вами рассмотрим создание как простых компонентов таких как кнопки, бейджики, иконки и т.д. так и объединение их в более сложные компоненты: табы, чипы, модальные окна.

12 |

Все компоненты написаны с проверкой esLint.

13 |

Любой компонент вы можете скачать и свободно переписать под свои задачи, либо расширить его функциональность

14 |

Dependencies:

15 | 22 |

Author in social networks:

23 | 34 |
35 | ); 36 | 37 | export default Home; 38 | -------------------------------------------------------------------------------- /src/layout/main/main.css: -------------------------------------------------------------------------------- 1 | .main { 2 | padding: 25px 50px; 3 | position: relative; 4 | } 5 | -------------------------------------------------------------------------------- /src/layout/main/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import './main.css'; 4 | 5 | const Main = ({ children }) => ( 6 |
7 | {children} 8 |
9 | ); 10 | 11 | Main.propTypes = { 12 | children: PropTypes.node.isRequired, 13 | }; 14 | 15 | export default Main; 16 | -------------------------------------------------------------------------------- /src/layout/navigation/navigation.css: -------------------------------------------------------------------------------- 1 | .logoWrapper { 2 | text-align: center; 3 | } 4 | 5 | .navigation { 6 | background-color: #D43728; 7 | box-shadow: 1px 1px 10px #777; 8 | } 9 | 10 | .nav { 11 | list-style-type: none; 12 | margin: 0; 13 | padding: 0; 14 | display: flex; 15 | flex-wrap: wrap; 16 | } 17 | 18 | .nav li { 19 | display: flex; 20 | align-items: center; 21 | flex: 1 0 100%; 22 | } 23 | 24 | .nav a { 25 | color: #fff; 26 | text-decoration: none; 27 | display: flex; 28 | height: 100%; 29 | width: 100%; 30 | align-items: center; 31 | justify-content: flex-start; 32 | padding: 15px 0 15px 30px; 33 | box-sizing: border-box; 34 | border-left: 3px solid transparent; 35 | font-weight: 600; 36 | } 37 | 38 | .nav a:hover, 39 | .nav a.active { 40 | background-color: rgba(0,0,0,.2); 41 | border-color: #EBEBEB; 42 | } 43 | -------------------------------------------------------------------------------- /src/layout/navigation/navigation.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { NavLink } from 'react-router-dom'; 3 | import './navigation.css'; 4 | 5 | const Navigation = () => ( 6 |
7 |
8 | logo 9 |
10 | 15 |
16 | ); 17 | 18 | export default Navigation; 19 | -------------------------------------------------------------------------------- /src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' 13 | // [::1] is the IPv6 localhost address. 14 | || window.location.hostname === '[::1]' 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | || window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/, 18 | ), 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Lets check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl); 38 | 39 | // Add some additional logging to localhost, pointing developers to the 40 | // service worker/PWA documentation. 41 | navigator.serviceWorker.ready.then(() => { 42 | console.log( 43 | 'This web app is being served cache-first by a service ' 44 | + 'worker. To learn more, visit https://goo.gl/SC7cgQ', 45 | ); 46 | }); 47 | } else { 48 | // Is not local host. Just register service worker 49 | registerValidSW(swUrl); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | function registerValidSW(swUrl) { 56 | navigator.serviceWorker 57 | .register(swUrl) 58 | .then(registration => { 59 | registration.onupdatefound = () => { 60 | const installingWorker = registration.installing; 61 | installingWorker.onstatechange = () => { 62 | if (installingWorker.state === 'installed') { 63 | if (navigator.serviceWorker.controller) { 64 | // At this point, the old content will have been purged and 65 | // the fresh content will have been added to the cache. 66 | // It's the perfect time to display a "New content is 67 | // available; please refresh." message in your web app. 68 | console.log('New content is available; please refresh.'); 69 | } else { 70 | // At this point, everything has been precached. 71 | // It's the perfect time to display a 72 | // "Content is cached for offline use." message. 73 | console.log('Content is cached for offline use.'); 74 | } 75 | } 76 | }; 77 | }; 78 | }) 79 | .catch(error => { 80 | console.error('Error during service worker registration:', error); 81 | }); 82 | } 83 | 84 | function checkValidServiceWorker(swUrl) { 85 | // Check if the service worker can be found. If it can't reload the page. 86 | fetch(swUrl) 87 | .then(response => { 88 | // Ensure service worker exists, and that we really are getting a JS file. 89 | if ( 90 | response.status === 404 91 | || response.headers.get('content-type').indexOf('javascript') === -1 92 | ) { 93 | // No service worker found. Probably a different app. Reload the page. 94 | navigator.serviceWorker.ready.then(registration => { 95 | registration.unregister().then(() => { 96 | window.location.reload(); 97 | }); 98 | }); 99 | } else { 100 | // Service worker found. Proceed as normal. 101 | registerValidSW(swUrl); 102 | } 103 | }) 104 | .catch(() => { 105 | console.log( 106 | 'No internet connection found. App is running in offline mode.', 107 | ); 108 | }); 109 | } 110 | 111 | export function unregister() { 112 | if ('serviceWorker' in navigator) { 113 | navigator.serviceWorker.ready.then(registration => { 114 | registration.unregister(); 115 | }); 116 | } 117 | } 118 | --------------------------------------------------------------------------------