Git Product home page Git Product logo

nuxt-icons's Introduction

nuxt-icons

Nuxt Icons

A module for Nuxt 3 that allows you to use your own SVG icons quickly and enjoyably.

playground-usage

Installation

  1. `npx nuxi@latest module add icons
  2. add nuxt-icons to modules, nuxt.config.ts:
export default defineNuxtConfig({
    modules: ['nuxt-icons']
})

Usage

  1. Create a icons folder in assets: assets/icons
  2. Drop your icons with the .svg extension into the icons folder
  3. In the project, use <nuxt-icon name="">, where name is the name of your svg icon from the folder

If you need to use the original color from the svg file (for example, if your icon has defs) you need to use the filled attribute:
<nuxt-icon name="mySuperIcon" filled />

Subfolders

If you would like to use some more complicated folder arrangement you will have to use paths from /icons

If you have a svg icon in nested directories such as:

๐Ÿ“icons
  โ””๐Ÿ“admin
  โ €โ €โ”” badge.svg
  โ””๐Ÿ“user
  โ €โ €โ”” badge.svg

then the icons's name will be based on its own path directory and filename. Therefore, the icon's name will be:

<nuxt-icon name="admin/badge"> and <nuxt-icon name="user/badge">

I don't like the basic styles that are assigned to the icons!

The styles that have been created for the icons look as follows:

width: 1em;
height: 1em;
margin-bottom: 0.125em;
vertical-align: middle;

You can easily change these styles using regular CSS for example in your index.vue file:

<style>
.nuxt-icon svg{
  margin-bottom: 0;
}
</style>

I would like to use icons from an icon pack available online

You can download icons in SVG format and put them in the /icons folder, or use another module that supports this natively: nuxt-icon

What this module does

The module retrieves all svg files from the assets/icons folder, overwrites the height and width from them to make them scalable, and using the <nuxt-icon> component allows them to be used. <nuxt-icon> injects the SVG code directly into <span>.

Features

  • Easy SVG icon management โœ…
  • HMR (You don't have to reset the project to reload the icons) โœ…
  • Ability to manipulate icons just like fonts, e.g. using color, font-size instead of fill,width,height โœ…
  • Ability to use the original color scheme for complex icons using the filled attribute โœ…
  • Icon only loads if used โœ…

Development

  • Run npm run dev:prepare to generate type stubs.
  • Use npm run dev to start playground in development mode.

Thoughts and ToDo's:

  • Automatic svg file optimization
  • Automatic icon scaling that have non-square dimensions to maintain their proportions (maybe with preserveAspectRatio)
  • Usable for previous nuxt versions (just use something like this)
  • If a lot of the same icons are used on the page create a separate svg sprite (significant improvement in performance)

A big thank you to @Diizzayy for his invaluable help in developing the project

nuxt-icons's People

Contributors

gitfoxcode avatar ghettoddos avatar danielroe avatar shba007 avatar tdekoning avatar pi0 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.