Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVGR #72

Closed
3 tasks done
arcticicestudio opened this issue Dec 6, 2018 · 0 comments
Closed
3 tasks done

SVGR #72

arcticicestudio opened this issue Dec 6, 2018 · 0 comments

Comments

@arcticicestudio
Copy link
Contributor

arcticicestudio commented Dec 6, 2018

This issue documents the integration of SVGR which transforms SVG into ready to use React components. It is part of create-react-app and makes SVG integration into React projects easy.

Configuration

All configurations will be placed in a svgr.config.js file in the project root instead of passing them to the corresponding Gatsby plugin for the Webpack loader that is documented in the section below.

  • expandProps = end — ensure props are always spread ({...props}) last on the root <svg> element.
  • ext = jsx — use the JSX file extension for generated components.
  • icon = false — ensure the width and height props (hardcoded 1em value) are not added.
  • ref = true — export components using React's forwardRef API to reference the underlying component and allow access to the root SVG element which is necessary for animations.
  • svgo = false — all SVG files in this project are already optimized with SVGO using the included .svgo.yml configuration.

Webpack Loader

To directly import SVG's as React component the @svgr/webpack package will be used to simply integrate SVGR as Webpack plugin. It'll be added through the gatsby-plugin-svgr which adjusts the required Webpack configurations by adding the loader and removing the default .svg file loader.

Tasks

  • Install the required (dev) dependencies:
  • Implement the SVGR and SVGO configuration files.
  • Add gatsby-plugin-svgr to the Gatsby configuration.
@arcticicestudio arcticicestudio added this to the 0.3.0 milestone Dec 6, 2018
@arcticicestudio arcticicestudio self-assigned this Dec 6, 2018
arcticicestudio added a commit that referenced this issue Dec 6, 2018
arcticicestudio added a commit that referenced this issue Dec 6, 2018
All configurations for SVGR are set in the `svgr.config.js` file instead
of passing them to the corresponding Gatsby plugin for the Webpack
loader.

- `expandProps` = `end` - ensure props are always spread
  (`{...props}`) last on the root `<svg>` element.
- `ext` = `jsx` - use the JSX file extension for generated components.
- `icon` = `false` - ensure the `width` and `height` props (hardcoded
  `1em` value) are not added.
- `ref` = `true` - export components using React's `forwardRef` API to
  reference the underlying component and allow access to the root SVG
  element which is necessary for animations.
- `svgo` = `false` - all SVG files in this project are already
  optimized with SVGO using the included `.svgo.yml` configuration.

The configuration for SVGO is implemented in the `.svgo.yml` file that
is also placed in the project root and will be picked up by SVGO
automatically.

GH-72
@arcticicestudio arcticicestudio mentioned this issue Dec 6, 2018
Merged
@arcticicestudio arcticicestudio removed their assignment Dec 6, 2018
arcticicestudio added a commit that referenced this issue Dec 13, 2018
This commit adds some icons of the awesome "Eva Icons" (1) project and
the official Nord logo as SVG components. They are loaded with the SVGR
webpack loader added in #72.

References:
  (1) https://akveo.github.io/eva-icons

GH-64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant