Last active
November 9, 2016 16:36
-
-
Save rudin/bf1c4098d40a91e939abf659ba941d21 to your computer and use it in GitHub Desktop.
Rewritten (ES6) React Component for Icons using Inline SVG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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