├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.js ├── components │ ├── Button │ │ ├── Button.js │ │ └── index.js │ ├── H1 │ │ ├── H1.js │ │ └── index.js │ ├── List │ │ ├── List.js │ │ └── index.js │ ├── RemovableListItem │ │ ├── RemovableListItem.js │ │ └── index.js │ ├── TextInput │ │ ├── TextInput.js │ │ └── index.js │ └── ToDoList │ │ ├── ToDoList.js │ │ └── index.js ├── index.js ├── serviceWorker.js └── setupTests.js └── yarn.lock /.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 | /dist 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 | Sharing React components between projects is a very effective way to speed your app development and to ensure UI consistency. 6 | 7 | Today, thanks to powerful tools like Bit, it becomes much easier to share React components and, as a great side effect, build a stunning reusable UI library. 8 | 9 | Sharing a component from any app or project becomes a simple process of using Bit to add, tag and export components to your reusable collection. 10 | 11 | Each component you share can be quickly used in different apps, and will from now-on always be available for reuse. You will also get auto-docs, a visual sandbox and much more out of the box. And, it plays with npm and yarn so you can install components just like any other package. 12 | 13 | ### [Learn more](https://blog.bitsrc.io/writing-scalable-code-with-shared-react-components-86f702df6582) 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-demo-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^4.2.4", 7 | "@testing-library/react": "^9.4.0", 8 | "prop-types": "^15.7.2", 9 | "react": "^16.12.0", 10 | "react-dom": "^16.12.0", 11 | "react-scripts": "3.3.0", 12 | "react-transition-group": "1.x", 13 | "styled-components": "^4.4.1" 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": "react-app" 23 | }, 24 | "browserslist": { 25 | "production": [ 26 | ">0.2%", 27 | "not dead", 28 | "not op_mini all" 29 | ], 30 | "development": [ 31 | "last 1 chrome version", 32 | "last 1 firefox version", 33 | "last 1 safari version" 34 | ] 35 | }, 36 | "devDependencies": { 37 | "enzyme": "^3.11.0", 38 | "enzyme-adapter-react-16": "^1.15.2", 39 | "jest-dom": "^4.0.0", 40 | "react-test-renderer": "^16.12.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teambit/react-demo-app/907024f0aa570f452b0e041f488d5eaeb2f0bbb2/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 18 | 19 | 28 | React App 29 | 30 | 31 | 32 |
33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teambit/react-demo-app/907024f0aa570f452b0e041f488d5eaeb2f0bbb2/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teambit/react-demo-app/907024f0aa570f452b0e041f488d5eaeb2f0bbb2/public/logo512.png -------------------------------------------------------------------------------- /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 | "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 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ToDoList from './components/ToDoList'; 3 | import H1 from './components/H1' 4 | 5 | const App = () => { 6 | return( 7 |
8 |

Yet Another To-Do App

9 | 10 |
11 | ) 12 | } 13 | 14 | export default App; 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/components/Button/Button.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | import PropTypes from 'prop-types'; 3 | 4 | const Button = styled.button` 5 | color: #fff; 6 | position: relative; 7 | font-size: 16px; 8 | padding: 10px; 9 | min-width: 120px; 10 | border-radius: 5px; 11 | background-color: ${props => props.disabled ? '#6c757d' : '#007bff'}; 12 | transition: background-color 0.3s ease, box-shadow 0.7s ease; 13 | &:active { 14 | top: 2px; 15 | } 16 | &:enabled:hover { 17 | background-color: #4f9cef; 18 | box-shadow: 0px 0px 6px 2px rgba(79,156,239,0.3); 19 | } 20 | &:focus { 21 | outline: none; 22 | } 23 | ` 24 | 25 | Button.propTypes = { 26 | /** Determines if a button is active or disabled */ 27 | disabled: PropTypes.bool 28 | } 29 | 30 | export default Button; -------------------------------------------------------------------------------- /src/components/Button/index.js: -------------------------------------------------------------------------------- 1 | export { default } from './Button'; -------------------------------------------------------------------------------- /src/components/H1/H1.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components' 2 | 3 | const H1 = styled.h1` 4 | font-family: 'Caveat', cursive; 5 | text-align: center; 6 | font-size: 40px; 7 | font-weight: 400; 8 | ` 9 | 10 | export default H1; -------------------------------------------------------------------------------- /src/components/H1/index.js: -------------------------------------------------------------------------------- 1 | export { default } from './H1'; -------------------------------------------------------------------------------- /src/components/List/List.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import RemovableListItem from '../RemovableListItem'; 3 | import PropTypes from 'prop-types'; 4 | 5 | 6 | const List = (props) => { 7 | const {items, removeItem} = props; 8 | return ( 9 | 14 | ) 15 | } 16 | 17 | List.propTypes = { 18 | /** List items. 19 | * key: The item's unique key. 20 | * text: The item's description. */ 21 | items: PropTypes.arrayOf( 22 | PropTypes.shape({ 23 | key: PropTypes.string.isRequired, 24 | text: PropTypes.string.isRequired, 25 | }) 26 | ), 27 | /** A collback to be executed on a remove-item event */ 28 | removeItem: PropTypes.func 29 | }; 30 | 31 | export default List; 32 | -------------------------------------------------------------------------------- /src/components/List/index.js: -------------------------------------------------------------------------------- 1 | export {default} from './List' -------------------------------------------------------------------------------- /src/components/RemovableListItem/RemovableListItem.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styled from 'styled-components' 3 | import PropTypes from 'prop-types'; 4 | 5 | const Item = styled.li` 6 | border-bottom: 1px #d1d1d1 solid; 7 | border-right: 1px #d1d1d1 solid; 8 | border-left: 1px #d1d1d1 solid; 9 | &:first-child{ 10 | border-top: 1px #d1d1d1 solid; 11 | border-top-left-radius: 5px; 12 | border-top-right-radius: 5px; 13 | } 14 | &:last-child { 15 | border-bottom-left-radius: 5px; 16 | border-bottom-right-radius: 5px; 17 | } 18 | padding: 12px; 19 | display: flex; 20 | justify-content: space-between; 21 | align-items: center; 22 | ` 23 | const Text = styled.span` 24 | position: relative; 25 | font-family: 'Caveat', cursive; 26 | font-size: 24px; 27 | color: #343a48; 28 | transition: position 0.8 ease-out; 29 | ` 30 | const DelButton = styled.button` 31 | font-size: 18px; 32 | font-weight: 700; 33 | color: #adadad; 34 | padding: 5px; 35 | background-color: transparent; 36 | border: 0; 37 | appearance: none; 38 | outline: unset; 39 | transition: transform .8s; 40 | &:hover{ 41 | color: #c75656; 42 | transform: rotate(180deg); 43 | } 44 | ` 45 | 46 | 47 | const RemovableListItem = (props) => { 48 | const {id, text, removeItem} = props; 49 | return( 50 | 51 | {text} 52 | { (removeItem && id) && 53 | removeItem(id)}>X 54 | } 55 | 56 | ) 57 | } 58 | 59 | RemovableListItem.propTypes = { 60 | /** 61 | * The items's ID 62 | */ 63 | id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), 64 | /** 65 | * The item's text 66 | */ 67 | text: PropTypes.string.isRequired, 68 | /** 69 | * A callback to be exectuted on a remove-item event 70 | */ 71 | removeItem: PropTypes.func 72 | } 73 | 74 | export default RemovableListItem; -------------------------------------------------------------------------------- /src/components/RemovableListItem/index.js: -------------------------------------------------------------------------------- 1 | export {default} from './RemovableListItem'; -------------------------------------------------------------------------------- /src/components/TextInput/TextInput.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components'; 2 | 3 | const TextInput = styled.input` 4 | border-radius: 5px; 5 | width: 100%; 6 | padding: 8px 10px; 7 | border: 1px solid #007bff; 8 | display: inline-block; 9 | font-size: 16px; 10 | transition: box-shadow 0.3s; 11 | &:focus { 12 | outline: none; 13 | box-shadow: 0px 0px 6px 2px rgba(79,156,239,0.3); 14 | border: 1px solid #4f9cef; 15 | } 16 | ` 17 | 18 | export default TextInput; -------------------------------------------------------------------------------- /src/components/TextInput/index.js: -------------------------------------------------------------------------------- 1 | export { default } from './TextInput'; -------------------------------------------------------------------------------- /src/components/ToDoList/ToDoList.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import styled from 'styled-components' 3 | import Button from '../Button' 4 | import InputText from '../TextInput' 5 | import List from '../List'; 6 | 7 | 8 | const Container = styled.div` 9 | position: relative; 10 | margin: 50px auto; 11 | overflow: auto; 12 | width: 25%; 13 | min-height: 250px; 14 | background-color: rgb(255, 255, 255); 15 | box-shadow: 5px 5px 15px #00000047; 16 | border-radius: 10px; 17 | padding: 40px 25px 40px 25px; 18 | @media (max-width: 1200px) { 19 | width: 40% 20 | }; 21 | @media screen and (max-width: 600px){ 22 | margin: 0 0; 23 | overflow: auto; 24 | width: 85%; 25 | margin: auto; 26 | } 27 | ` 28 | 29 | const InputForm = styled.form` 30 | display: flex; 31 | margin-bottom: 25px; 32 | & > :first-child{ 33 | margin-right: 6px; 34 | } 35 | ` 36 | 37 | export default class ToDoListContainer extends Component { 38 | 39 | state = { 40 | toDoItems: [], 41 | inputText: '', 42 | submitDisabled: true 43 | } 44 | 45 | addToDo = (text) => { 46 | const key = Math.floor((Math.random() * 10000)).toString(); 47 | this.setState({toDoItems: [{text, key}, ...this.state.toDoItems], submitDisabled: true}); 48 | } 49 | 50 | delToDo = (id) => { 51 | this.setState({toDoItems: this.state.toDoItems.filter(todo => todo.key !== id)}) 52 | } 53 | 54 | updateInput = (event) => { 55 | let text = event.target.value.replace(/\s/g,''); 56 | this.setState({inputText: event.target.value}) 57 | if (text) { 58 | this.setState({submitDisabled: false}) 59 | } else { 60 | this.setState({submitDisabled: true}) 61 | } 62 | } 63 | 64 | handleSubmit= (event) =>{ 65 | event.preventDefault(); 66 | this.addToDo(this.state.inputText); 67 | this.setState({inputText: ''}); 68 | } 69 | 70 | render() { 71 | return ( 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | ) 80 | } 81 | } -------------------------------------------------------------------------------- /src/components/ToDoList/index.js: -------------------------------------------------------------------------------- 1 | export { default } from './ToDoList'; -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | import * as serviceWorker from './serviceWorker'; 5 | 6 | ReactDOM.render(, document.getElementById('root')); 7 | 8 | // If you want your app to work offline and load faster, you can change 9 | // unregister() to register() below. Note this comes with some pitfalls. 10 | // Learn more about service workers: https://bit.ly/CRA-PWA 11 | serviceWorker.unregister(); 12 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { 'Service-Worker': 'script' } 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get('content-type'); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf('javascript') === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | 'No internet connection found. App is running in offline mode.' 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ('serviceWorker' in navigator) { 133 | navigator.serviceWorker.ready.then(registration => { 134 | registration.unregister(); 135 | }); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | --------------------------------------------------------------------------------