Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 928 Bytes

README.md

File metadata and controls

32 lines (24 loc) · 928 Bytes

SVGSON webpack loader

Converts svg+xml files to JSON. Based on svgson npm package. Can be used for rendering SVG via React components.

Installation

npm install svgson-loader --save-dev

We are writing React UI library with icon button which filling it's background color based on SVG 1.2 property "viewport-fill":

import vkIcon from 'svgson-loader!./icons/vk.svg';
import okIcon from 'svgson-loader!./icons/ok.svg';
import fbIcon from 'svgson-loader!./icons/fb.svg';

stories.add('Social buttons', () => (
	<div>
		<Button icon={vkIcon} />
		<Button icon={okIcon} />
		<Button icon={fbIcon} />
	</div>
));

So Button reads "viewport-fill" attribute inside JSON, applies backgroundColor property then generates React.createElement calls to render SVG.