A tiny library that makes it easier for you to add SVGs and tranform them in your svelte project.
You won't need to rename your .svg
files to .svelte
and manually edit them.
Independent from DOMParser, so it works just fine during server-side rendering.
npm install svelte-svg-transform
// important! include the ?raw at the end of your SVG import
import MyIcon from '../path/to/icon.svg?raw';
// component is default exported so you can call it whatever you want!
import SvgTransform from 'svelte-svg-transform';
<span class="text-red-500">
<SvgTransform
svg={MyIcon}
width={32}
strokeWidth={3}
stroke="currentColor"
/>
</span>;
// => outputs a 32px x 32px INLINE svg
// => with 3px thick stroke of same color as parent's text
The component exposes some props that make it easier to manipulate SVG type files. Make sure to pass your SVG's raw markup to the component like so:
import SvgIcon from 'svelte-svg-transform';
import MyIcon from '../path/to/icon.svg?raw';
<SvgIcon svg={MyIcon} />;
From there you can use these props on the component:
Type: string (svg markup)
Required
Accepts only raw svg markup that you want to transform.
Type: number
Default: 20
Sets svg's width to desired pixels.
Type: number
Default: Same as width
Sets svg's height to desired pixels, if not passed will use the same as width.
Type: string
Override any hard-coded fill colors except none
Type: string
Override any hard-coded stroke colors except none
Type: number
Range: 0-1
Optional
Change svg's internal fill-opacity properties (except none) to any value you want.
Type: number
Optional
Change svg's internal stroke-width properties (except none) to any value you want.
Type: string
Optional
Change svg's internal stroke-line-cap properties (except none) to any value you want.
Type: number
Range: 0-1
Optional
Change svg's internal stroke-opacity properties (except none) to any value you want.