0.1.3 • Published 5 months ago

@choiceform/tailwindcss-svg-icon v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@choiceform/tailwindcss-svg-icon

License Tailwind CSS Badge

A Tailwind CSS plugin that allows you to use encoded SVG files as CSS data URLs.

capture

Installation

To install the tailwindcss-svg-icon plugin, you can use npm or yarn:

npm install @choiceform/tailwindcss-svg-icon --save-dev

Configuration

// tailwind.config.js
module.exports = {
  plugins: [
    require("tailwindcss-svg-icon")({
      // default options
      classPrefix: "icon",
      defaultSize: 1,
      unit: "rem",
    }),
  ],
};

// package.json
{
  "scripts": {
    ...
  },
  "iconSourcePath": "path/to/icons",
}

Usage

<div class="icon-[folder/iconName]" />

features

Auto completion

This plugin supports code completion in Visual Studio Code. It provides suggestions and auto-completion for your code as you type. This can greatly improve your productivity and help you write code more efficiently.

code-completion

Customize size

You can customize the default size of the icons by adjusting the defaultSize option. In the tailwind.config.js file, change the value of defaultSize to the size and unit you prefer.

Additionally, you can also use Tailwind CSS's classes to change the size of the icons.

size

<div className="icon-[sharp/mastodon] w-16 h-16" />

Support the currentColor feature for SVG.

By using the currentColor value for the fill or stroke property in your SVG, you can dynamically inherit the color from the parent element. This allows for easy customization and theming of SVG icons.

currentColor

Example usage:

<!-- SVG file -->
<svg
  xmlns="http://www.w3.org/2000/svg"
  viewBox="0 0 512 512"
  fill="currentColor"
>
  ...
</svg>
<!-- Component -->
<div class="icon-[folder/iconName] text-blue-500" />

In this example, the SVG icon will inherit the color blue-500 from the parent element's text color.

If the SVG does not have the currentColor property, it will render in its original color and cannot have its color changed using Tailwind CSS classes.

color

Supports Tailwindcss Handling Hover, Focus, and Other States

Handling

<div
  className="icon-[balloon-outline] 
  hover:icon-[balloon] hover:text-violet-500"
/>

Supports SVG animations

animation

Credits

This projects uses svgo

npm docs

License

MIT License © 2023 Choiceform

0.1.4

5 months ago

0.1.3

5 months ago

0.1.5

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago