Hiswe / gulp-svg-symbols

Convert svg files to symbols
https://www.npmjs.com/package/gulp-svg-symbols
MIT License
169 stars 18 forks source link

TEMPLATE – react #53

Open Hiswe opened 6 years ago

Hiswe commented 6 years ago

I think I should be able to provide a template for generating React components.

Right now it's easy to make a component referencing the svg-symbols:

import React  from 'react';
import classNames from 'classnames';
import PropTypes  from 'prop-types';

const BASE_CLASS = `svg-icon`

export function Icon( props ) {
  const { svgId, className, ...other } = props
  const COMP_CLASS = classNames( BASE_CLASS, `icon-${ svgId }`, className )
  return (
    <svg
      role="img"
      className={ COMP_CLASS }
      {...other}
    >
      <use xlinkHref={`#icon-${ svgId }`}></use>
    </svg>
  )
}

Icon.propTypes = {
  svgId: PropTypes.string.isRequired,
}

export default Icon

But we should be able to include the whole SVG for an icon into the DOM. This will allow us to have a more granular styling.