MCPcopy Index your code
hub / github.com/gregberge/svgr

github.com/gregberge/svgr @v8.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v8.1.0 ↗ · + Follow
187 symbols 476 edges 104 files 0 documented · 0% updated 4mo agov8.1.0 · 2023-08-15★ 11,046121 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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 is an universal tool to transform SVG into React components.

SVGR takes a raw SVG and transforms it into a ready-to-use React component.

Docs

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

Quicklinks to some of the most-visited pages:

Example

Take a 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"
>

  <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

Get an optimized React component

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:

Learn more about supporting SVGR.

Contributing

Check out the contributing guidelines

License

Licensed under the MIT License, Copyright © 2017-present Greg Bergé.

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.

Extension points exported contracts — how you extend this code

Options (Interface)
(no doc)
packages/babel-plugin-remove-jsx-attribute/src/index.ts
Value (Interface)
(no doc)
packages/babel-plugin-replace-jsx-attribute-value/src/index.ts
Context (Interface)
(no doc)
packages/babel-plugin-transform-svg-component/src/variables.ts
Options (Interface)
(no doc)
packages/rollup/src/index.ts
Attribute (Interface)
(no doc)
packages/babel-plugin-add-jsx-attribute/src/index.ts
Config (Interface)
(no doc)
packages/core/src/config.ts
Options (Interface)
(no doc)
packages/babel-plugin-svg-em-dimensions/src/index.ts
Options (Interface)
(no doc)
packages/cli/src/index.ts

Core symbols most depended-on inside this repo

transform
called by 12
packages/core/src/transform.ts
transformFilename
called by 9
packages/cli/src/util.ts
expandState
called by 8
packages/core/src/state.ts
getOrCreateImport
called by 6
packages/babel-plugin-transform-svg-component/src/variables.ts
svgr
called by 6
website/src/components/playground/modules/svgr.js
getPlugins
called by 5
packages/core/src/plugins.ts
formatExportName
called by 5
packages/cli/src/util.ts
createProperty
called by 4
packages/babel-plugin-transform-svg-component/src/variables.ts

Shape

Function 161
Interface 26

Languages

TypeScript100%

Modules by API surface

packages/cli/src/dirCommand.ts11 symbols
packages/cli/src/index.ts10 symbols
packages/babel-plugin-transform-svg-component/src/variables.ts9 symbols
packages/babel-plugin-svg-dynamic-title/src/index.ts8 symbols
packages/babel-plugin-add-jsx-attribute/src/index.ts7 symbols
website/src/components/playground/Query.js6 symbols
packages/cli/src/util.ts6 symbols
packages/babel-plugin-transform-svg-component/src/types.ts6 symbols
packages/babel-plugin-transform-react-native-svg/src/index.ts6 symbols
packages/hast-util-to-babel-ast/src/util.ts5 symbols
packages/core/src/plugins.ts5 symbols
packages/babel-preset/src/index.ts5 symbols

Dependencies from manifests, versioned

@babel/core7.21.3 · 1×
@babel/plugin-transform-react-constant-elements7.21.3 · 1×
@babel/preset-env7.20.2 · 1×
@babel/preset-react7.18.6 · 1×
@babel/preset-typescript7.21.0 · 1×
@babel/types7.21.3 · 1×
@rollup/plugin-json6.0.0 · 1×
@rollup/pluginutils5.0.2 · 1×
@svgr/babel-plugin-add-jsx-attributeworkspace:* · 1×
@svgr/babel-plugin-remove-jsx-attributeworkspace:* · 1×
@svgr/babel-plugin-remove-jsx-empty-expressionworkspace:* · 1×
@svgr/babel-plugin-replace-jsx-attribute-valueworkspace:* · 1×

For agents

$ claude mcp add svgr \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact