Skip to content

Commit

Permalink
feat(atoms): expand Icon component. add babel svg plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed May 18, 2018
1 parent 6bc6685 commit f8637e2
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"react-app",
"flow"
],
"plugins": ["flow-react-proptypes", "jsx-control-statements"]
}
"plugins": ["inline-react-svg", "flow-react-proptypes", "jsx-control-statements"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"babel-eslint": "7.2.3",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-flow-react-proptypes": "^23.0.0",
"babel-plugin-inline-react-svg": "^0.5.2",
"babel-plugin-jsx-control-statements": "^3.2.8",
"babel-preset-flow": "^6.23.0",
"babel-preset-react-app": "^3.1.1",
Expand Down
63 changes: 51 additions & 12 deletions src/atoms/typography/Icon/Icon.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,71 @@
// @flow

import React from 'react';

import { createStyledTag, createTheme } from 'utils';
import * as glyphs from './glyphs';

type IconProps = {|
type IconProps = {
/** icon name */
name: string,
|};
/** icon color */
color?: 'red' | 'green' | 'blue' | 'primary',
/** icon size */
size?: 'xs' | 'sm' | 'md' | 'lg' | 'stretch',
};

const name = 'icon';

const theme = createTheme(name, {
const theme : Theme<IconProps> = createTheme(name, (colors: *): * => ({
modifiers: {
color: {
primary: { color: colors.PRIMARY },
red: { color: colors.RED },
green: { color: colors.GREEN },
blue: { color: colors.BLUE },
},
size: {
xs: {
width: '1.4rem',
height: '1.4rem',
},
sm: {
width: '2.4rem',
height: '2.4rem',
},
md: {
width: '3.6rem',
height: '3.6rem',
},
lg: {
width: '4.8rem',
height: '4.8rem',
},
stretch: {
width: '100%',
height: '100%',
},
},
},
defaults: {
},
});
defaults: {},
}));

const StyledTag = createStyledTag(name, {
const IconTag = createStyledTag(name, {
display: 'inline-flex',
});

function Icon({ name, rest }: IconProps) {
const Icon = ({ name, ...rest }: IconProps) => {
const Glyph = glyphs[name];

return (
<StyledTag { ...rest } tagName="div">
<Glyph />
</StyledTag>
<IconTag { ...rest } tagName="div">
<Glyph width="100%" height="100%" />
</IconTag>
);
}
};

Icon.defaultProps = {
size: 'sm',
};

export { Icon, theme };
23 changes: 19 additions & 4 deletions src/atoms/typography/Icon/Icon.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ import React from 'react';
export default (asStory) => {
asStory('ATOMS/TYPOGRAPHY/Icon', module, (story, { Icon }) => {
story
.add('with default modifiers', () => (
<React.Fragment>
.add('all icons', () => (
<div style={{ display: 'flex', alignItems: 'center' }}>
<Icon name="ChevronDown" />
</React.Fragment>
<Icon name="Check" />
</div>
))
.add('with custom color', () => (
<div style={{ display: 'flex', alignItems: 'center' }}>
<Icon name="Check" color="primary" />
<Icon name="Check" color="green" />
<Icon name="Check" color="blue" />
</div>
))
.add('with custom sizes', () => (
<div style={{ display: 'flex', alignItems: 'center' }}>
<Icon name="Check" size="xs" />
<Icon name="Check" size="sm" />
<Icon name="Check" size="md" />
<Icon name="Check" size="lg" />
</div>
));
});
};

3 changes: 3 additions & 0 deletions src/atoms/typography/Icon/glyphs/Check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions src/atoms/typography/Icon/glyphs/ChevronDown.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/atoms/typography/Icon/glyphs/ChevronDown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src/atoms/typography/Icon/glyphs/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
export { ChevronDown } from './ChevronDown';
// @flow
// eslint-disable-next-line no-unused-vars
import React from 'react';

import Check from './Check.svg';
import ChevronDown from './ChevronDown.svg';

export {
ChevronDown,
Check,
};

2 changes: 2 additions & 0 deletions src/atoms/typography/Icon/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// @flow

export { Icon, theme } from './Icon';
21 changes: 18 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,17 @@ babel-plugin-flow-react-proptypes@^23.0.0:
babel-traverse "^6.25.0"
babel-types "^6.25.0"

babel-plugin-inline-react-svg@^0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/babel-plugin-inline-react-svg/-/babel-plugin-inline-react-svg-0.5.2.tgz#f4c9ea5384e8d08a7a4f96a19f22a5eab0ddf3a9"
dependencies:
babel-template "^6.15.0"
babel-traverse "^6.15.0"
babylon "^6.10.0"
lodash.isplainobject "^4.0.6"
resolve-from "^2.0.0"
svgo "^0.7.0"

babel-plugin-istanbul@^4.1.5:
version "4.1.6"
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.6.tgz#36c59b2192efce81c5b378321b74175add1c9a45"
Expand Down Expand Up @@ -1670,7 +1681,7 @@ babel-standalone@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-standalone/-/babel-standalone-6.26.0.tgz#15fb3d35f2c456695815ebf1ed96fe7f015b6886"

babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.25.0, babel-template@^6.26.0:
babel-template@^6.15.0, babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.25.0, babel-template@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02"
dependencies:
Expand All @@ -1680,7 +1691,7 @@ babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.25.0, babel-te
babylon "^6.18.0"
lodash "^4.17.4"

babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1, babel-traverse@^6.25.0, babel-traverse@^6.26.0:
babel-traverse@^6.15.0, babel-traverse@^6.18.0, babel-traverse@^6.23.1, babel-traverse@^6.24.1, babel-traverse@^6.25.0, babel-traverse@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee"
dependencies:
Expand All @@ -1707,7 +1718,7 @@ [email protected]:
version "7.0.0-beta.31"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.31.tgz#7ec10f81e0e456fd0f855ad60fa30c2ac454283f"

babylon@^6.17.0, babylon@^6.18.0:
babylon@^6.10.0, babylon@^6.17.0, babylon@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"

Expand Down Expand Up @@ -7904,6 +7915,10 @@ resolve-from@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"

resolve-from@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57"

resolve-from@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
Expand Down

0 comments on commit f8637e2

Please sign in to comment.