@choiceform/tailwindcss-svg-icon
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @choiceform/tailwindcss-svg-icon

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

654 kB

Total Files

7

Last publish

Collaborators

  • zhqjiang
  • spellforcezx
  • zuizeze
  • leonpm
  • wester
  • nightire
  • lixu19941116
  • fenyiwudian
  • smartepsh