Skip to content

Commit

Permalink
feat(components/base): create <Spinner />
Browse files Browse the repository at this point in the history
use on <ImgLoader />
  • Loading branch information
aneurysmjs committed May 2, 2019
1 parent e0bf04e commit a3ea886
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/app/components/base/Spinner/Spinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @flow strict
import React from 'react';

import './Spinner.scss';

type PropsType = {
height: number | string,
width: number | string,
};

const Spinner = ({ height, width }: PropsType) => (
<div
style={{
height: `${height}px`,
width: `${width}px`,
}}
className="spinner"
>
<div className="spinner__outer-circle" />
<div className="spinner__inner-circle" />
</div>
);

Spinner.defaultProps = {
height: '24',
width: '24',
};

export default Spinner;
38 changes: 38 additions & 0 deletions src/app/components/base/Spinner/Spinner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@import '~styles/functions/px-to-rem';
@import '~styles/mixins';
@import '~styles/variables';

.spinner {
display: inline-block;
position: relative;

@include element(outer-circle) {
animation: lds-ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
border-radius: 50%;
border: px-to-rem(4) solid #222222;
opacity: 1;
position: absolute;
}

@include element(inner-circle) {
animation-delay: -0.5s;
}
}

@keyframes lds-ripple {
0% {
top: px-to-rem(28);
left: px-to-rem(28);
width: 0;
height: 0;
opacity: 1;
}

100% {
top: -1px;
left: -1px;
width: px-to-rem(58);
height: px-to-rem(58);
opacity: 0;
}
}
13 changes: 13 additions & 0 deletions src/app/components/base/Spinner/Spinner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @flow strict
import React from 'react';
import { shallow } from 'enzyme';

import Spinner from './Spinner';

describe('Spinner', () => {
const defaultProps = {};

it('tests something', () => {
shallow(<Spinner {...defaultProps} />);
});
});
4 changes: 3 additions & 1 deletion src/app/components/shared/ImgLoader/ImgLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow strict
import React, { useState } from 'react';

import Spinner from '@/components/base/Spinner/Spinner';

import './ImgLoader.scss';

type PropsType = {
Expand All @@ -15,7 +17,7 @@ function ImgLoader({ src }: PropsType) {
image.src = src;

return (
imgObj.isLoading ? 'Loading...' : (<img className="imgLoader img-fluid" src={imgObj.img} alt="img" />)
imgObj.isLoading ? (<Spinner />) : (<img className="imgLoader img-fluid" src={imgObj.img} alt="img" />)
);
}

Expand Down
1 change: 0 additions & 1 deletion src/app/components/shared/ProductCard/ProductCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import React, { Component } from 'react';

import ImgLoader from '@/components/shared/ImgLoader/ImgLoader';
// import spinner from '@/components/shared/ImgLoader/ImgLoader';

import './ProductCard.scss';

Expand Down

0 comments on commit a3ea886

Please sign in to comment.