├── public
├── robots.txt
├── favicon.ico
├── logo192.png
├── logo512.png
├── manifest.json
└── index.html
├── src
├── setupTests.js
├── App.test.js
├── index.css
├── index.js
├── App.js
├── components
│ ├── Contact.js
│ └── Home.js
├── App.css
└── serviceWorker.js
├── README.md
├── package.json
└── LICENSE
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShyamBhuptani/React-Barba-Effect/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShyamBhuptani/React-Barba-Effect/HEAD/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ShyamBhuptani/React-Barba-Effect/HEAD/public/logo512.png
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from '@testing-library/react';
3 | import App from './App';
4 |
5 | test('renders learn react link', () => {
6 | const { getByText } = render();
7 | const linkElement = getByText(/learn react/i);
8 | expect(linkElement).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | padding: 0;
9 | user-select: none;
10 | }
11 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | serviceWorker.unregister();
15 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import "./App.css";
3 | import Home from "./components/Home";
4 | import Contact from "./components/Contact";
5 | import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
6 |
7 | function App() {
8 | return (
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | );
18 | }
19 |
20 | export default App;
21 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React-Barba-Effect
2 |
3 | [Barba.js](https://barba.js.org/) provides a smooth transition between the website's page but in the world of SPA, the designs made up of React/Vue have a challenging path to implement the same transition while routing internally. This project is to produce the same effect while transiting from one to another page in a SPA using react-router and the animation is produced using GSAP.
4 |
5 | ## Installation
6 |
7 | Make sure node.js is installed in the system.
8 |
9 | ```bash
10 | git clone https://github.com/ShyamBhuptani/React-Barba-Effect/
11 | cd React-Barba-Effect/
12 | npm install
13 | npm run start
14 | ```
15 |
16 |
17 | ## Motivation
18 | [Codegrid](https://www.youtube.com/watch?v=ergc889Jghc) has published a fantastic video to demonstrate barba.js which I framed into React producing the same effect and Barba.js isn't used yet the same effect has been reproduced.
19 |
20 | ## License
21 | [MIT](https://choosealicense.com/licenses/mit/)
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "barba_react",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.5.0",
8 | "@testing-library/user-event": "^7.2.1",
9 | "gsap": "^3.4.2",
10 | "react": "^16.13.1",
11 | "react-dom": "^16.13.1",
12 | "react-router": "^5.2.0",
13 | "react-router-dom": "^5.2.0",
14 | "react-scripts": "3.4.1"
15 | },
16 | "scripts": {
17 | "start": "react-scripts start",
18 | "build": "react-scripts build",
19 | "test": "react-scripts test",
20 | "eject": "react-scripts eject"
21 | },
22 | "eslintConfig": {
23 | "extends": "react-app"
24 | },
25 | "browserslist": {
26 | "production": [
27 | ">0.2%",
28 | "not dead",
29 | "not op_mini all"
30 | ],
31 | "development": [
32 | "last 1 chrome version",
33 | "last 1 firefox version",
34 | "last 1 safari version"
35 | ]
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
19 | React App
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Shyam Bhuptani
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/components/Contact.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { NavLink } from "react-router-dom";
3 | import { TweenMax, TimelineMax, Power3, Power4 } from "gsap";
4 | import { useRef, useEffect } from "react";
5 |
6 | function Contact() {
7 | let screen = useRef(null);
8 | let body = useRef(null);
9 | useEffect(() => {
10 | var tl = new TimelineMax();
11 | tl.to(screen, {
12 | duration: 1.2,
13 | height: "100%",
14 | ease: Power3.easeInOut,
15 | });
16 | tl.to(screen, {
17 | duration: 1,
18 | top: "100%",
19 | ease: Power3.easeInOut,
20 | delay: 0.3,
21 | });
22 | tl.set(screen, { left: "-100%" });
23 | TweenMax.to(body, .3, {css: {
24 | opacity: "1",
25 | pointerEvents: "auto",
26 | ease: Power4.easeInOut
27 | }}).delay(2);
28 | return () => {
29 | TweenMax.to(body, 1, {css: {
30 | opacity: "0",
31 | pointerEvents: 'none'
32 | }});
33 | }
34 | });
35 | return (
36 |
37 |
38 |
(screen = el)}>
39 |
40 |
41 |
(body = el)} className="Headd">
42 |
Contact Me!!!
43 |
Home
44 |
45 |
46 |
47 | );
48 | }
49 |
50 | export default Contact;
51 |
--------------------------------------------------------------------------------
/src/components/Home.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { NavLink } from "react-router-dom";
3 | import { TweenMax, TimelineMax, Power3, Power4 } from "gsap";
4 | import { useRef, useEffect } from "react";
5 |
6 | function Home() {
7 | let screen = useRef(null);
8 | let body = useRef(null);
9 | useEffect(() => {
10 | var tl = new TimelineMax();
11 | tl.to(screen, {
12 | duration: 1.2,
13 | width: "100%",
14 | left: "0%",
15 | ease: Power3.easeInOut,
16 | });
17 | tl.to(screen, {
18 | duration: 1,
19 | left: "100%",
20 | ease: Power3.easeInOut,
21 | delay: 0.3,
22 | });
23 | tl.set(screen, { left: "-100%" });
24 | TweenMax.to(body, .3, {css: {
25 | opacity: "1",
26 | pointerEvents: "auto",
27 | ease: Power4.easeInOut
28 | }}).delay(2);
29 | return () => {
30 | TweenMax.to(body, 1, {css: {
31 | opacity: "0",
32 | pointerEvents: 'none'
33 | }});
34 | }
35 | });
36 | return (
37 |
38 |
39 |
(screen = el)}>
40 |
41 |
42 |
43 |
(body = el)} className="Headd">
44 |
Welcome to Home!!!
45 |
Contact
46 |
47 |
48 |
49 | );
50 | }
51 |
52 | export default Home;
53 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | font-family: 'Poppins', sans-serif;
3 | text-align: center;
4 | }
5 |
6 | .Home, .Contact {
7 | height: 100vh;
8 | background-color: #161616;
9 | width: 100%;
10 | position: absolute;
11 | left: 50%;
12 | transform: translate(-50%,0%);
13 | }
14 |
15 | .Home > div , .Contact > div {
16 | padding-top: 300px !important;
17 | color: #ff7f82;
18 | font-size: 7rem;
19 | }
20 |
21 | .Contact > div {
22 | color: #ffa260;
23 | }
24 |
25 | .button {
26 | background: none;
27 | border: 2px solid #a972cb;
28 | font: inherit;
29 | line-height: 1;
30 | padding: .3rem 3rem;
31 | text-decoration: none;
32 | font-size: 30px;
33 | color: #a972cb;
34 | font-family: 'Roboto Mono', monospace;
35 | text-transform: uppercase;
36 | outline: none;
37 | transition: all .3s;
38 | }
39 |
40 | .button:hover,
41 | .button:focus {
42 | box-shadow: inset 0 0 0 2em rgb(169, 114, 203,.2);
43 | }
44 |
45 | .load-container {
46 | position: fixed;
47 | top: 0;
48 | left: 0;
49 | width: 100%;
50 | height: 100vh;
51 | overflow: hidden;
52 | z-index: 10;
53 | pointer-events: none;
54 | }
55 |
56 | .load-screen {
57 | position: relative;
58 | padding-top: 0px;
59 | padding-left: 0px;
60 | padding-right: 0px;
61 | background-color: #19bc8b;
62 | width: 0%;
63 | height: 100%;
64 | }
65 |
66 | .load-screen1 {
67 | position: relative;
68 | padding-top: 0px;
69 | padding-left: 0px;
70 | padding-right: 0px;
71 | background-color: #e4cb58;
72 | width: 100%;
73 | height: 0%;
74 | }
75 |
76 | .Headd {
77 | opacity: 0;
78 | pointer-events: none;
79 | }
--------------------------------------------------------------------------------
/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
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------