Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spinner added to dynamic imports #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion components/layout/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import HeaderMobile from './header/mobile';
import HeaderDesktop from './header/desktop';
import dynamic from 'next/dynamic';

import Spinner from 'components/spinner';

import Content from './content';
import Footer from './footer';

Expand All @@ -11,7 +14,9 @@ const Layout = ({ story, onClose, isMobile, isStatic }) => {
if (!story) return null;

const id = CATEGORIES[story.category].index[story.index]
const DynamicComponent = dynamic(() => import(`components/layout/static-pages/${id}`));
const DynamicComponent = dynamic(
() => import(`components/layout/static-pages/${id}`),
{ loading: () => <Spinner index={story.category} /> });

return (
<div className={`l-layout block${story.category}`}>
Expand Down
18 changes: 18 additions & 0 deletions components/spinner/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';

const Spinner = ({ index }) => (
<div
className={cx("c-spinner",
{ [`theme${index}`]: index + 1 > 0 }
)}
/>
);


Spinner.propTypes = {
color: PropTypes.number.isRequired
};

export default Spinner;
1 change: 1 addition & 0 deletions components/spinner/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './component';
33 changes: 33 additions & 0 deletions components/spinner/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@import 'styles/settings';

.c-spinner {
position: relative;
margin: auto;
border: 8px solid rgba(85, 206, 200, 0.1);
opacity: 0.4;
border-radius: 50%;
width: 70px;
height: 70px;
animation: loading 2s linear infinite;

&.theme0 {
border-top: 8px solid #4B406E;
}

&.theme1 {
border-top: 8px solid #005B5D;
}

&.theme2 {
border-top: 8px solid #9E905C;
}

@keyframes loading {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

&.loading {
display: flex;
}
}
1 change: 1 addition & 0 deletions styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
@import 'components/cookie-banner/styles.scss';
@import 'components/equalizer/styles.scss';
@import 'components/link-button/styles.scss';
@import 'components/spinner/styles.scss';