Go to file
2021-12-01 23:00:58 +01:00
__fixtures__ feat(cli): allow all CLI options in config (#615) 2021-11-01 10:06:43 +01:00
.github feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
api chore: fix api 2021-11-29 14:49:21 +01:00
build feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
deprecated-packages/svgr feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
examples docs: configure mocha with SVGR 2021-12-01 22:28:56 +01:00
packages v6.1.0 2021-12-01 22:50:16 +01:00
public docs(website): upgrade & make it standalone 2019-12-24 10:39:20 +01:00
resources chore: upgrade website 2021-09-16 23:40:28 +02:00
website docs: fix typo Jest -> Mocha 2021-12-01 22:54:37 +01:00
.eslintignore feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
.eslintrc.json feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
.gitignore feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
.nvmrc chore(ci): use npm instead of yarn (#603) 2021-10-03 08:39:42 +02:00
.prettierignore feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
.prettierrc Prepare for publishing 2017-09-02 10:11:13 +00:00
babel.config.js feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
BACKERS.md docs: change amount of open collective 2019-04-22 17:58:23 +02:00
CHANGELOG.md v6.1.0 2021-12-01 22:50:16 +01:00
CODE_OF_CONDUCT.md chore: smooth-code -> gregberge 2019-12-24 10:57:52 +01:00
CONTRIBUTING.md feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
jest.config.js feat(typescript): add types everywhere (#611) 2021-10-31 09:49:38 +01:00
lerna.json v6.1.0 2021-12-01 22:50:16 +01:00
LICENSE chore: add license 2017-12-20 17:25:53 +01:00
package-lock.json chore: upgrade deps 2021-12-01 22:54:07 +01:00
package.json chore(deps): upgrade 2021-11-13 09:35:06 +01:00
README.md docs(readme): Fixing CRA link (#618) 2021-11-11 11:24:13 +01:00
tsconfig.json feat: support jsxRuntime (#613) 2021-11-01 08:39:18 +01:00

svgr

Transform SVGs into React components 🦁

License Donate npm package npm downloads CI Code Coverage

Try it out online!

Watch the talk at React Europe

SVGR transforms SVG into ready to use components. It is part of create-react-app and makes SVG integration into your React projects easy.

Docs

See the documentation at react-svgr.com for more information about using svgr!

Quicklinks to some of the most-visited pages:

Example

Take an icon.svg:

<?xml version="1.0" encoding="UTF-8"?>
<svg
  width="48px"
  height="1px"
  viewBox="0 0 48 1"
  version="1.1"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
>
  <!-- Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch -->
  <title>Rectangle 5</title>
  <desc>Created with Sketch.</desc>
  <defs></defs>
  <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
    <g
      id="19-Separator"
      transform="translate(-129.000000, -156.000000)"
      fill="#063855"
    >
      <g id="Controls/Settings" transform="translate(80.000000, 0.000000)">
        <g id="Content" transform="translate(0.000000, 64.000000)">
          <g id="Group" transform="translate(24.000000, 56.000000)">
            <g id="Group-2">
              <rect id="Rectangle-5" x="25" y="36" width="48" height="1"></rect>
            </g>
          </g>
        </g>
      </g>
    </g>
  </g>
</svg>

Run SVGR

npx @svgr/cli --icon --replace-attr-values "#063855=currentColor" icon.svg

Output

import * as React from 'react'

const SvgComponent = (props) => (
  <svg width="1em" height="1em" viewBox="0 0 48 1" {...props}>
    <path d="M0 0h48v1H0z" fill="currentColor" fillRule="evenodd" />
  </svg>
)

export default SvgComponent

Supporting SVGR

SVGR is a MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to the support of these awesome backers. If you'd like to join them, please consider:

Gold Sponsors

Gold Sponsors are those who have pledged $100/month and more to SVGR.

gold-sponsors

Contributing

Check out the contributing guidelines

License

Licensed under the MIT License, Copyright © 2017-present Smooth Code.

See LICENSE for more information.

Acknowledgements

This project has been popularized by Christopher Chedeau and it has been included in create-react-app thanks to Dan Abramov. We would like to thanks Sven Sauleau for his help and its intuition.