Skip to content

Commit b61bd69

Browse files
committed
Add Icon component for icons
1 parent c2734ab commit b61bd69

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Diff for: client/common/Icon.jsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-disable global-require */
2+
import InlineSVG from 'react-inlinesvg';
3+
import PropTypes from 'prop-types';
4+
import React from 'react';
5+
import lodash from 'lodash';
6+
7+
const icons = {
8+
github: require('../images/github.svg'),
9+
google: require('../images/google.svg'),
10+
};
11+
12+
/*
13+
names will be an mirror-object of icon names:
14+
{
15+
github: 'github',
16+
...
17+
}
18+
*/
19+
const names = lodash.mapValues(icons, (value, key) => key);
20+
21+
22+
function Icon({ name, ...props }) {
23+
return (
24+
<InlineSVG src={icons[name]} {...props} />
25+
);
26+
}
27+
28+
Icon.names = names;
29+
30+
Icon.propTypes = {
31+
name: PropTypes.oneOf(Object.keys(names)).isRequired
32+
};
33+
34+
export default Icon;

Diff for: client/common/Icon.stories.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { select } from '@storybook/addon-knobs';
3+
4+
import Icon from './Icon';
5+
6+
export default {
7+
title: 'Common/Icon',
8+
component: Icon
9+
};
10+
11+
export const AllIcons = () => {
12+
const firstIconName = Object.keys(Icon.names)[0];
13+
14+
return (
15+
<Icon name={select('name', Icon.names, firstIconName)} />
16+
);
17+
};

0 commit comments

Comments
 (0)