├── medium ├── Position1.png ├── Position3.png ├── Position4.png ├── Position 2.png └── SketchAssets.sketch ├── public ├── favicon.ico ├── manifest.json └── index.html ├── src ├── assets │ ├── test.jpg │ ├── slide1.jpg │ ├── slide2.jpg │ ├── slide3.jpg │ ├── slide4.jpg │ └── slide5.jpg ├── index.js ├── Spacer.js ├── Dot.js ├── Slide.js ├── Dots.js ├── App.js ├── custom.css ├── Slideshow.js └── serviceWorker.js ├── .gitignore ├── package.json └── README.md /medium/Position1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/medium/Position1.png -------------------------------------------------------------------------------- /medium/Position3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/medium/Position3.png -------------------------------------------------------------------------------- /medium/Position4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/medium/Position4.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/assets/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/src/assets/test.jpg -------------------------------------------------------------------------------- /medium/Position 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/medium/Position 2.png -------------------------------------------------------------------------------- /src/assets/slide1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/src/assets/slide1.jpg -------------------------------------------------------------------------------- /src/assets/slide2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/src/assets/slide2.jpg -------------------------------------------------------------------------------- /src/assets/slide3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/src/assets/slide3.jpg -------------------------------------------------------------------------------- /src/assets/slide4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/src/assets/slide4.jpg -------------------------------------------------------------------------------- /src/assets/slide5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/src/assets/slide5.jpg -------------------------------------------------------------------------------- /medium/SketchAssets.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwanth1109/ReactSlideshow/HEAD/medium/SketchAssets.sketch -------------------------------------------------------------------------------- /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": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./App"; 4 | import "./custom.css"; 5 | import * as serviceWorker from "./serviceWorker"; 6 | 7 | ReactDOM.render(, document.getElementById("root")); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: http://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /src/Spacer.js: -------------------------------------------------------------------------------- 1 | //=========================================== 2 | // IMPORT DEPENDENCIES 3 | //=========================================== 4 | import React, { memo } from "react"; 5 | 6 | //=========================================== 7 | // SPACER FUNCTIONAL COMPONENT 8 | //=========================================== 9 | const Spacer = ({ w, h }) => { 10 | if (w) { 11 | return
; 12 | } else if (h) { 13 | return
; 14 | } 15 | }; 16 | 17 | export default memo(Spacer); 18 | -------------------------------------------------------------------------------- /src/Dot.js: -------------------------------------------------------------------------------- 1 | //=========================================== 2 | // IMPORT DEPENDENCIES 3 | //=========================================== 4 | import React, { memo } from "react"; 5 | import Spacer from "./Spacer"; 6 | 7 | //=========================================== 8 | // DOT FUNCTIONAL COMPONENT 9 | //=========================================== 10 | const Dot = ({ slideId, dotId }) => ( 11 |
12 | 13 |
14 | 15 |
16 | ); 17 | 18 | export default memo(Dot); 19 | -------------------------------------------------------------------------------- /src/Slide.js: -------------------------------------------------------------------------------- 1 | //=========================================== 2 | // IMPORT DEPENDENCIES 3 | //=========================================== 4 | import React, { memo } from "react"; 5 | 6 | //=========================================== 7 | // STYLES OBJECT 8 | //=========================================== 9 | const s = { 10 | container: "abs fullW fullH", 11 | slideImage: "fullH fullW imgCover" 12 | }; 13 | 14 | //=========================================== 15 | // SLIDE FUNCTIONAL COMPONENT 16 | //=========================================== 17 | const Slide = ({ position, transition, image }) => { 18 | return ( 19 |
20 | slide 21 |
22 | ); 23 | }; 24 | 25 | export default memo(Slide); 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-slideshow", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": "https://ashwanth1109.github.io/ReactSlideshow/", 6 | "dependencies": { 7 | "gh-pages": "^2.0.1", 8 | "react": "^16.6.3", 9 | "react-dom": "^16.6.3", 10 | "react-scripts": "2.1.1" 11 | }, 12 | "scripts": { 13 | "predeploy": "npm run build", 14 | "deploy": "gh-pages -d build", 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": [ 24 | ">0.2%", 25 | "not dead", 26 | "not ie <= 11", 27 | "not op_mini all" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /src/Dots.js: -------------------------------------------------------------------------------- 1 | //=========================================== 2 | // IMPORT DEPENDENCIES 3 | //=========================================== 4 | import React, { memo } from "react"; 5 | import Dot from "./Dot"; 6 | 7 | //=========================================== 8 | // STYLE OBJECT 9 | //=========================================== 10 | const s = { 11 | container: "fullW height70 abs bot0 fCenter black50" 12 | }; 13 | 14 | //=========================================== 15 | // DOTS FUNCTIONAL COMPONENT 16 | //=========================================== 17 | const Dots = ({ slideId, slides }) => { 18 | return ( 19 |
20 |
21 | {slides.map((slide, id) => ( 22 | 23 | ))} 24 |
25 |
26 | ); 27 | }; 28 | 29 | export default memo(Dots); 30 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | //=========================================== 2 | // IMPORT DEPENDENCIES 3 | //=========================================== 4 | import React, { Component } from "react"; 5 | import Slideshow from "./Slideshow"; 6 | import slide1 from "./assets/slide1.jpg"; 7 | import slide2 from "./assets/slide2.jpg"; 8 | import slide3 from "./assets/slide3.jpg"; 9 | import slide4 from "./assets/slide4.jpg"; 10 | import slide5 from "./assets/slide5.jpg"; 11 | 12 | //=========================================== 13 | // CREATE STYLES OBJECT 14 | //=========================================== 15 | const s = { 16 | container: "screenW screenH dGray col", 17 | header: "flex1 fCenter fSize2", 18 | main: "flex8 white", 19 | footer: "flex1 fCenter" 20 | }; 21 | 22 | //=========================================== 23 | // SLIDES DATA 24 | //=========================================== 25 | const slides = [slide1, slide2, slide3, slide4, slide5]; 26 | 27 | //=========================================== 28 | // APP COMPONENT 29 | //=========================================== 30 | class App extends Component { 31 | render() { 32 | return ( 33 |
34 |
Automatic Slideshow Carousel
35 |
36 | 37 |
38 |
Built in React - by Ashwanth A R
39 |
40 | ); 41 | } 42 | } 43 | 44 | export default App; 45 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | React App 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/custom.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css?family=Quicksand"); 2 | * { 3 | margin: 0; 4 | padding: 0; 5 | font-family: "Quicksand", sans-serif; 6 | color: #fff; 7 | } 8 | 9 | /*====== WIDTH ======*/ 10 | .screenW { 11 | width: 100vw; 12 | } 13 | .fullW { 14 | width: 100%; 15 | } 16 | /*====== HEIGHT ======*/ 17 | .screenH { 18 | height: 100vh; 19 | } 20 | .fullH { 21 | height: 100%; 22 | } 23 | .height70 { 24 | height: 70px; 25 | } 26 | /*====== BG COLOR ======*/ 27 | .dGray { 28 | background-color: #333; 29 | } 30 | .white { 31 | background-color: #fff; 32 | } 33 | .white50 { 34 | background-color: #ffffff80; 35 | } 36 | .black50 { 37 | background-color: #00000080; 38 | } 39 | /*====== FONT ======*/ 40 | .fSize2 { 41 | font-size: 2rem; 42 | } 43 | /*====== IMAGE ======*/ 44 | .imgCover { 45 | object-fit: cover; 46 | } 47 | /*====== OVERFLOW ======*/ 48 | .overflowH { 49 | overflow: hidden; 50 | } 51 | /*====== TRANSITIONS ======*/ 52 | .transition1l { 53 | transition: left 1s ease-in-out; 54 | } 55 | /*====== POSITION ======*/ 56 | .abs { 57 | position: absolute; 58 | } 59 | .rel { 60 | position: relative; 61 | } 62 | .left0 { 63 | left: 0px; 64 | } 65 | .left100vw { 66 | left: 100vw; 67 | } 68 | .leftM100vw { 69 | left: -100vw; 70 | } 71 | .bot0 { 72 | bottom: 0; 73 | } 74 | /*====== FLEX ======*/ 75 | .df { 76 | display: flex; 77 | } 78 | .row { 79 | display: flex; 80 | flex-direction: row; 81 | } 82 | .col { 83 | display: flex; 84 | flex-direction: column; 85 | } 86 | .fCenter { 87 | display: flex; 88 | justify-content: center; 89 | align-items: center; 90 | } 91 | .flex1 { 92 | flex: 1; 93 | } 94 | .flex8 { 95 | flex: 8; 96 | } 97 | 98 | /*====== CUSTOM ======*/ 99 | .dot { 100 | width: 10px; 101 | height: 10px; 102 | border-radius: 5px; 103 | transition: background-color 1s ease-in-out; 104 | } 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ReactSlideshow 2 | 3 | Automatic Slideshow Component built in React 4 | 5 | Link: https://ashwanth1109.github.io/ReactSlideshow/ 6 | 7 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 8 | 9 | ## Available Scripts 10 | 11 | In the project directory, you can run: 12 | 13 | ### `npm start` 14 | 15 | Runs the app in the development mode.
16 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 17 | 18 | The page will reload if you make edits.
19 | You will also see any lint errors in the console. 20 | 21 | ### `npm test` 22 | 23 | Launches the test runner in the interactive watch mode.
24 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 25 | 26 | ### `npm run build` 27 | 28 | Builds the app for production to the `build` folder.
29 | It correctly bundles React in production mode and optimizes the build for the best performance. 30 | 31 | The build is minified and the filenames include the hashes.
32 | Your app is ready to be deployed! 33 | 34 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 35 | 36 | ### `npm run eject` 37 | 38 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 39 | 40 | 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. 41 | 42 | 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. 43 | 44 | 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. 45 | 46 | ## Learn More 47 | 48 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 49 | 50 | To learn React, check out the [React documentation](https://reactjs.org/). 51 | -------------------------------------------------------------------------------- /src/Slideshow.js: -------------------------------------------------------------------------------- 1 | //=========================================== 2 | // IMPORT DEPENDENCIES 3 | //=========================================== 4 | import React, { Component } from "react"; 5 | import Slide from "./Slide"; 6 | import Dots from "./Dots"; 7 | 8 | //=========================================== 9 | // CREATE STYLES OBJECT 10 | //=========================================== 11 | const s = { 12 | container: "fullW fullH rel overflowH", 13 | onScreen: "left0", 14 | offScreenRight: "left100vw", 15 | offScreenLeft: "leftM100vw", 16 | transition: "transition1l" 17 | }; 18 | 19 | //=========================================== 20 | // SLIDESHOW COMPONENT 21 | //=========================================== 22 | class Slideshow extends Component { 23 | constructor(props) { 24 | super(props); 25 | this.state = { 26 | slide1: { 27 | id: 0, 28 | position: s.onScreen, 29 | transition: true 30 | }, 31 | slide2: { 32 | id: 1, 33 | position: s.offScreenRight, 34 | transition: true 35 | }, 36 | currentId: 0 37 | }; 38 | } 39 | 40 | componentDidMount() { 41 | this.startCarousel(); 42 | } 43 | 44 | componentWillUnmount() { 45 | clearInterval(this.carouselInterval); 46 | } 47 | 48 | startCarousel = () => { 49 | this.carouselInterval = setInterval(() => { 50 | this.transitionSlides(); 51 | }, 4000); 52 | }; 53 | 54 | setSlideState = (slide1, slide2, currentId) => { 55 | this.setState({ 56 | slide1: slide1, 57 | slide2: slide2, 58 | currentId: currentId 59 | }); 60 | }; 61 | 62 | transitionSlides = () => { 63 | const { slide1, slide2 } = this.state; 64 | let currentId; 65 | if (slide1["position"] === s.onScreen) { 66 | slide1["position"] = s.offScreenLeft; 67 | slide2["position"] = s.onScreen; 68 | currentId = slide2.id; 69 | } else { 70 | slide1["position"] = s.onScreen; 71 | slide2["position"] = s.offScreenLeft; 72 | currentId = slide1.id; 73 | } 74 | this.setSlideState(slide1, slide2, currentId); 75 | setTimeout(() => { 76 | this.resetSlideOffScreen(); 77 | }, 1000); 78 | }; 79 | 80 | resetSlideOffScreen = () => { 81 | const { slide1, slide2, currentId } = this.state; 82 | const { slides } = this.props; 83 | if (slide1["position"] === s.offScreenLeft) { 84 | slide1["transition"] = false; 85 | slide1["position"] = s.offScreenRight; 86 | slide1["id"] = slide2.id + 1 === slides.length ? 0 : slide2.id + 1; 87 | } else { 88 | slide2["transition"] = false; 89 | slide2["position"] = s.offScreenRight; 90 | slide2["id"] = slide1.id + 1 === slides.length ? 0 : slide1.id + 1; 91 | } 92 | this.setSlideState(slide1, slide2, currentId); 93 | this.resetSlideTransitions(slide1, slide2, currentId); 94 | }; 95 | 96 | resetSlideTransitions = (slide1, slide2, currentId) => { 97 | setTimeout(() => { 98 | slide1["transition"] = true; 99 | slide2["transition"] = true; 100 | this.setSlideState(slide1, slide2, currentId); 101 | }, 500); 102 | }; 103 | 104 | render() { 105 | const { slide1, slide2, currentId } = this.state; 106 | const { slides } = this.props; 107 | return ( 108 |
109 | 114 | 119 | 120 |
121 | ); 122 | } 123 | } 124 | 125 | export default Slideshow; 126 | -------------------------------------------------------------------------------- /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 http://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.1/8 is 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 http://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 http://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 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | --------------------------------------------------------------------------------