npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@farmfe/plugin-icons

v0.0.7

Published

Access thousands of icons as components **on-demand** universally.

Downloads

87

Readme

@farmfe/plugin-icons

Access thousands of icons as components on-demand universally.

Features

  • 🌏 Universal
    • 🤹 Any icon sets - ~150 popular sets with over 200,000 icons, logos, emojis, etc. Powered by Iconify.
    • 🚀 Major frameworks - Vanilla, Web Components, React, Vue 3, Solid, Svelte, and more. Contribute.
    • 🍱 Any combinations of them!
  • ☁️ On-demand - Only bundle the icons you really use, while having all the options.
  • 🌈 Stylable - Change size, color, or even add animations as you would with styles and classes.
  • 📥 Custom icons - load your custom icons to get universal integrations at ease.
  • 🦾 TypeScript support.
  • 🔍 Browse Icons

Usage

Import icons names with the convention ~icons/{collection}/{icon} and use them directly as components.

React
import IconAccessibility from '~icons/carbon/accessibility'
import IconAccountBox from '~icons/mdi/account-box'

function App() {
  return (
    <div>
      <IconAccessibility />
      <IconAccountBox style={{ fontSize: '2em', color: 'red' }} />
    </div>
  )
}
Vue
<script setup>
import IconAccessibility from '~icons/carbon/accessibility'
import IconAccountBox from '~icons/mdi/account-box'
</script>

<template>
  <icon-accessibility/>
  <icon-account-box style="font-size: 2em; color: red"/>
</template>

Install

Plugin

npm i -D @farmfe/plugin-icons

Icons Data

We use Iconify as the icons data source (supports 100+ iconsets).

You have two ways to install them:

Install Full Collection
npm i -D @iconify/json

@iconify/json (~120MB) includes all the iconsets from Iconify so you can install once and use any of them as you want (only the icons you actually use will be bundle into the production build).

Install by Icon Set

If you only want to use a few of the icon sets and don't want to download the entire collection, you can also install them individually with @iconify-json/[collection-id]. For example, to install Material Design Icons, you can do:

npm i -D @iconify-json/mdi

To boost your workflow, it's also possible to let unplugin-icons handle that installation by enabling the autoInstall option.

Icons({
  // experimental
  autoInstall: true,
})

It will install the icon set when you import them. The right package manager will be auto-detected (npm, yarn or pnpm).

Configuration

Create a farm.config.js configuration file and import the plugin:

import { defineConfig } from '@farmfe/core';
import Icons from '@farmfe/plugin-plugin';

export default defineConfig({
  plugins: [
      ["@farmfe/plugin-icons", {
      /**
       * zie of zooming icon
       * @type {float}
       * @default 1.2
       */
      scale: 1.2,
      /**
       * @description Whether to automatically install the required dependencies
       * @type {boolean}
       * @default true
       */
      autoInstall: true,
      /**
       * @description The compiler used by the plugin
       * @type {string}
       * @default "jsx"
       * @enum ["jsx", "vue","react","preact","solid","svelte"]
       */
      compiler: "jsx",
      /**
       * @description The default style to apply to the svg element
       * @type {object}
       * @default {}
       */
      defaultStyle: {},
      /**
       * @description The default class to apply to the svg element
       * @type {string}
       */
      defaultClass: "",
      /**
       * @description Custom icon collection, support local svg and remote svg
       * @type {string}
       * @uses [iconname] to replace the icon name
       * @example
       *  import icon from "~icons/local/icon.svg"
       *  import icon from "~icons/remote/icon.svg"
       */
      customCollections: {
        local: './src/assets',
        remote: "https://cdn.simpleicons.org/[iconname]/"
      }
    }],
  ],
});

Use RAW compiler from query params

From v0.13.2 you can also use raw compiler to access the svg icon and use it on your html templates, just add raw to the icon query param.

For example, using vue3:

<script setup lang='ts'>
import RawMdiAlarmOff from '~icons/mdi/alarm-off?raw&width=4em&height=4em'
import RawMdiAlarmOff2 from '~icons/mdi/alarm-off?raw&width=1em&height=1em'
</script>

<template>
  <!-- raw example -->
  <pre>
    import RawMdiAlarmOff from '~icons/mdi/alarm-off?raw&width=4em&height=4em'
    {{ RawMdiAlarmOff }}
    import RawMdiAlarmOff2 from '~icons/mdi/alarm-off?raw&width=1em&height=1em'
    {{ RawMdiAlarmOff2 }}
  </pre>
  <!-- svg example -->
  <span v-html="RawMdiAlarmOff" />
  <span v-html="RawMdiAlarmOff2" />
</template>

Custom Icons

you can now load your own icons!


Icons({
  customCollections: {
    'my-other-icons': "https://example.com/icons/[iconname].svg",
    // a helper to load icons from the file system
    // files under `./assets/icons` with `.svg` extension will be loaded as it's file name
    'my-yet-other-icons': './assets/icons',
  },
})

Then use as

import IconAccount from '~icons/my-icons/account'
import IconFoo from '~icons/my-other-icons/foo'
import IconBar from '~icons/my-yet-other-icons/bar'

Icon customizer

you can also customize each icon using query params when importing them.

you can use query params to apply to individual icons:

<script setup lang='ts'>
import MdiAlarmOff from 'virtual:icons/mdi/alarm-off?width=4em&height=4em'
import MdiAlarmOff2 from 'virtual:icons/mdi/alarm-off?width=1em&height=1em'
</script>

<template>
  <!-- width=4em and height=4em -->
  <mdi-alarm-off />
  <!-- width=4em and height=4em -->
  <MdiAlarmOff />
  <!-- width=1em and height=1em -->
  <MdiAlarmOff2 />
</template>