svg-componentify
Install
yarn add productboard-labs/svg-componentify -D
Idea
This tool seamlessly automate the work you have to do when you want from SVG file create React Component. At as a plus you will get optimized SVG structure.
From file like this:
<!-- Generator: Sketch 52.4 (67378) - http://www.bohemiancoding.com/sketch --> Icon / 12 / Feature 2 Created with Sketch.
You will get React Component like this:
/** * Copyright (c) 2018-present, ProductBoard, Inc. * All rights reserved. */ ;;; const Feature = <svg viewBox="0 0 16 16" className=> <path d="M15 0c.6 0 1 .4 1 1v14c0 .6-.4 1-1 1H1c-.6 0-1-.4-1-1V1c0-.6.4-1 1-1h14zm-1 14V2H2v12h12zM4 7h8v2H4V7zm0-3h8v2H4V4zm0 6h4v2H4v-2z" /> </svg>; ;
Configuration
⚠️ Currently there is not option to configure the transformator (#1) but you can always do a Fork, right. 💪 If you want this happen write us to to the issue, we will prioritize it.
Exported binary svg-componentify
has this possible configuration (via arguments)
--icon-path
(required) Where to look for SVG icons--export-path
(required) Where to export optimized icon React components--extension
(defaults toreact
)--suffix
(defaults totsx
)--only-staged
(defaults tofalse
) Transform only staged svg icons files--all
(defaults tofalse
) Process all files-v
,--version
to print actual version of the tool-f
,--force
force all prompts to its default value
Example