Skip to content

Instantly share code, notes, and snippets.

@carbonrobot
Last active February 27, 2019 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carbonrobot/4a9ef339e5a5ca6bd4fda7477f8bdac9 to your computer and use it in GitHub Desktop.
Save carbonrobot/4a9ef339e5a5ca6bd4fda7477f8bdac9 to your computer and use it in GitHub Desktop.
Icon options

Option 1

Pregenerate the exports in the index.js using a script

// ionic/index.js

import SvgIosAdd from './IosAdd';
import SvgIosAddCircle from './IosAddCircle';

export const IosAdd = ({icon, ...props}) => (
    <IconContext.Consumer>
        {(value) => {
            let newProps = Object.assign({}, value.props, props);
            newProps.fill = newProps.fill || 'currentcolor';
            newProps.stroke = newProps.stroke || 'currentcolor';
            return <SvgIosAdd {...props} />;
        }}
    </IconContext.Consumer>
)

export const IosAddCircle = ({icon, ...props}) => (
    <IconContext.Consumer>
        {(value) => {
            let newProps = Object.assign({}, value.props, props);
            newProps.fill = newProps.fill || 'currentcolor';
            newProps.stroke = newProps.stroke || 'currentcolor';
            return <SvgIosAddCircle {...props} />;
        }}
    </IconContext.Consumer>
)

Option 2

Use an Icon component and the SVG components directly

// icons/index.js
export const Icon = ({icon, ...props}) => (
    <IconContext.Consumer>
        {(value) => {
            let newProps = Object.assign({}, value.props, props);
            newProps.fill = newProps.fill || 'currentcolor';
            newProps.stroke = newProps.stroke || 'currentcolor';
            return React.createElement(icon, props);
        }}
    </IconContext.Consumer>
)

// yard-check.jsx

import { Icon } from '../icons';
import { IosAdd } from '../icons/ionic';

render(){
   <Icon icon={IosAdd} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment