Skip to content

Commit

Permalink
feat(atoms): add loader
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Sep 3, 2018
1 parent 6d167d9 commit b8dd374
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/atoms/Loader/Loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';

import { createStyledTag, createTheme } from '../../utils';
import LoaderIcon from './Loader.svg';

type LoaderProps = {|
size?: 'sm' | 'md' | 'lg',
|};

const name = 'loader';

const theme = createTheme(name, {
modifiers: {
size: {
sm: {
width: '4rem',
height: '4rem',
},
md: {
width: '6rem',
height: '6rem',
},
lg: {
width: '8rem',
height: '8rem',
},
},
},
defaults: {
size: 'md',
},
});

const StyledTag = createStyledTag(name, () => ({}));

const WrapperTag = createStyledTag(`${name}Wrapper`, () => ({
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flex: 1,
width: '100%',
height: '100%',
}));

function Loader(props: LoaderProps) {
if (props.stretch) {
return <WrapperTag><StyledTag { ...props } tagName={ LoaderIcon } /></WrapperTag>;
}

return <StyledTag { ...props } tagName={ LoaderIcon } />;
}

Loader.defaultProps = {
stretch: false,
};

export { Loader, theme };
20 changes: 20 additions & 0 deletions src/atoms/Loader/Loader.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';

export default (asStory) => {
asStory('ATOMS/Loader', module, (story, { Loader }) => {
story
.add('with various size', () => (
<React.Fragment>
<Loader size="sm" />
<Loader size="md" />
<Loader size="lg" />
</React.Fragment>
))
.add('with stretch', () => (
<React.Fragment>
<Loader stretch />
</React.Fragment>
));
});
};

36 changes: 36 additions & 0 deletions src/atoms/Loader/Loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/atoms/Loader/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Loader, theme } from './Loader';
1 change: 1 addition & 0 deletions src/atoms/atoms.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export { Tabs } from './Tabs';
export { Text } from './typography/Text';
export { TextArea } from './dataEntry/TextArea';
export { TextAreaField } from './dataEntry/TextAreaField';
export { Loader } from './Loader';
2 changes: 2 additions & 0 deletions src/atoms/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { theme as starsTheme } from './Stars';
import { theme as textAreaFieldTheme } from './dataEntry/TextAreaField';
import { theme as textAreaTheme } from './dataEntry/TextArea';
import { theme as textTheme } from './typography/Text';
import { theme as loaderTheme } from './Loader';

export const theme = {
...avatarTheme,
Expand Down Expand Up @@ -60,4 +61,5 @@ export const theme = {
...textAreaFieldTheme,
...textAreaTheme,
...textTheme,
...loaderTheme,
};
Loading

0 comments on commit b8dd374

Please sign in to comment.