GithubHelp home page GithubHelp logo

rettend / icon-shadow Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 59 KB

A transform function to add a shadow to icons from UnoCSS Icons Preset

Home Page: https://www.npmjs.com/package/icon-shadow

License: MIT License

TypeScript 100.00%
unocss icon-shadow unocss-icon

icon-shadow's Introduction

icon-shadow

A transform function to add a shadow to icons from UnoCSS Icons Preset

Pros and Cons

  • ✅ Shows shadow behind transparent areas of the icon (modifies the svg path)

  • ✅ The shadow matches the icon color, and even works with gradients

  • ❌ You can use this with custom icon collections, so only for icons that you've saved locally

  • ❌ The color is not customizable

Install

npm i -D icon-shadow
yarn add -D icon-shadow
pnpm i -D icon-shadow

Usage

unocs.config.ts

Apply to all custom loaded icons:

import { defineConfig, presetIcons } from 'unocss'
import { insertShadow } from 'icon-shadow'

export default defineConfig({
  presets: [
    presetIcons({
      customizations: {
        transform(svg) {
          return insertShadow(svg, {
            dx: 0,
            dy: 0,
            stdDeviation: 2,
            opacity: 0.3,
            viewBoxScale: 1.5,
          })
        },
      },
    }),
  ],
})

Or load icons from a folder:

import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
import { defineConfig, presetIcons } from 'unocss'
import { insertShadow } from 'icon-shadow'

export default defineConfig({
  presets: [
    presetIcons({
      collections: {
        shadow: FileSystemIconLoader(
          './public',
          svg => insertShadow(svg, {
            dx: 0,
            dy: 0,
            stdDeviation: 1,
            opacity: 0.5,
            viewBoxScale: 1,
          }),
        ),
      },
    }),
  ],
})

Access them with <div class="i-shadow:svg-name" />, if the icon is named svgName.svg.

Note: you will need to install @iconify/utils as a dependency

I only created the insertShadow function which can be used to transform the svg string. 👍

License

MIT

icon-shadow's People

Contributors

rettend avatar

Stargazers

 avatar

Watchers

 avatar

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.