Skip to content

Instantly share code, notes, and snippets.

@rudin
Last active November 9, 2016 16:36
Show Gist options
  • Save rudin/bf1c4098d40a91e939abf659ba941d21 to your computer and use it in GitHub Desktop.
Save rudin/bf1c4098d40a91e939abf659ba941d21 to your computer and use it in GitHub Desktop.
Rewritten (ES6) React Component for Icons using Inline SVG
// http://dmfrancisco.github.io/react-icons/
// http://www.rudinswagerman.nl/
/*
<Icon size="2rem" icon="my-icon" />
*/
import React from 'react';
const renderGraphic = icon => {
switch (icon) {
case 'my-icon':
return (
<g><path d="M7.41 7.84l4.59 4.58 4.59-4.58 1.41 1.41-6 6-6-6z"/></g>
);
case 'another-icon':
return (
<g><path d="M7.41 15.41l4.59-4.58 4.59 4.58 1.41-1.41-6-6-6 6z"/></g>
);
// Add more icons here
}
}
const styles = size => ({
fill: 'currentcolor',
verticalAlign: 'middle',
width: size,
height: size
});
export default ({icon, size, style}) => (
<svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet"
style={{...styles(size? size : 24), ...style}}>
{renderGraphic(icon)}
</svg>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment