File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments