ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

SVG to JSX

by scitech ALL

Converts raw SVG in an open Sublime buffer to valid JSX

Labels svg, jsx, react

Details

Installs

  • Total 1K
  • Win 589
  • Mac 451
  • Linux 184
May 13 May 12 May 11 May 10 May 9 May 8 May 7 May 6 May 5 May 4 May 3 May 2 May 1 Apr 30 Apr 29 Apr 28 Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Convert SVG to JSX

This plugin replaces SVG attributes with their JSX-valid equivalents and deletes common JSX-invalid attribute strings.

When is this useful?

  • If you're working on a React project with a lot of manual SVG manipulation.
  • If you're tired of repetitive find + replacing on the SVG assets pasted from Sketch or Illustrator.

Example

Say you have some SVG output from your graphics editor that you'd like to include in a React component. Using the markup directly will raise errors:

Error: language “jsx” is not supported
function Box() {
  return (
    <svg width="115px" height="125px" viewBox="0 0 115 125" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <rect id="Rectangle" stroke="none" fill="#D8D8D8" fill-rule="evenodd" x="0" y="0" width="115" height="125"></rect>
    </svg>
  )
}

This plugin, accessible from the right-click menu and the main menu, will remove invalid properties and correct the casing of valid properties so you can use the SVG in a component's render method without errors:

Error: language “jsx” is not supported
function Box() {
  return (
    <svg width="115px" height="125px" viewBox="0 0 115 125" version="1.1">
      <rect id="Rectangle" stroke="none" fill="#D8D8D8" fillRule="evenodd" x="0" y="0" width="115" height="125"></rect>
    </svg>
  )
}

For complex illustrations with several distinct components to be animated, this can be quite useful!

When is this not useful?