Giter VIP home page Giter VIP logo

svelte-svg-transform's Introduction

🖍️svelte-svg-transform

Live Demo

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.

release version weekly download count primary language procentage workflow build status last commit badge licence badge


Install

npm install svelte-svg-transform

Usage

  • Import in your component and pass it your SVG
  • Import your Icon's raw markup
  • Pass the icon to the component and transform it using props
// 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

Props

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:

svg

Type: string (svg markup) Required

Accepts only raw svg markup that you want to transform.

width

Type: number Default: 20

Sets svg's width to desired pixels.

height

Type: number Default: Same as width

Sets svg's height to desired pixels, if not passed will use the same as width.

fill

Type: string

Override any hard-coded fill colors except none

stroke

Type: string

Override any hard-coded stroke colors except none

fillOpacity

Type: number Range: 0-1 Optional

Change svg's internal fill-opacity properties (except none) to any value you want.

strokeWidth

Type: number Optional

Change svg's internal stroke-width properties (except none) to any value you want.

strokeLineCap

Type: string Optional

Change svg's internal stroke-line-cap properties (except none) to any value you want.

strokeOpacity

Type: number Range: 0-1 Optional

Change svg's internal stroke-opacity properties (except none) to any value you want.

Licence

MIT

svelte-svg-transform's People

Contributors

bartektelec avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

svelte-svg-transform's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • chore(deps): update all dependencies (@sveltejs/adapter-static, @sveltejs/kit, @sveltejs/package, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, actions/configure-pages, actions/deploy-pages, actions/setup-node, actions/upload-pages-artifact, eslint, eslint-config-prettier, eslint-plugin-svelte, prettier, prettier-plugin-svelte, publint, svelte, svelte-check, typescript, vite, vitest)

Detected dependencies

github-actions
.github/workflows/npm-publish.yml
  • actions/checkout v4
  • actions/setup-node v3
  • actions/checkout v4
  • actions/setup-node v3
.github/workflows/publish-demo.yml
  • actions/checkout v4
  • actions/setup-node v3
  • actions/configure-pages v3
  • actions/upload-pages-artifact v2
  • actions/deploy-pages v2
npm
package.json
  • @sveltejs/adapter-static 2.0.3
  • @sveltejs/kit 1.25.0
  • @sveltejs/package 2.2.2
  • @typescript-eslint/eslint-plugin 6.7.0
  • @typescript-eslint/parser 6.7.0
  • eslint 8.49.0
  • eslint-config-prettier 9.0.0
  • eslint-plugin-svelte 2.33.1
  • prettier 3.0.3
  • prettier-plugin-svelte 3.0.3
  • publint 0.2.2
  • svelte 4.2.0
  • svelte-check 3.5.1
  • tslib 2.6.2
  • typescript 5.2.2
  • vite 4.4.9
  • vitest 0.34.4
  • svelte ^3.54.0 || ^4.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.