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

@dv4all/icons

v1.0.2

Published

svg icons as web components

Downloads

16

Readme

Icons as web components

THIS LIBRARY IS USED TO TEST SVG ICONS AS WEB COMPONENTS.

This module contains SVG icons as web components. It is a part of @dv4all monorepo created to test web components implementation as NPM packages (modules), how LERNA works and how custom components can be applied with React (NextJS), Vue (NuxtJS), Webpack and HTML5.

This module is part of monorepo dv4all-wcp.

There are demos of each implementation in the demos folder of the monorepo.

Usage

  • install package from NPM
# install npm packages
npm install @dv4all/icons

HTML5 implementation

Import cjs version of the library () file in the header of html file. See demos/html-demo/icons.html for an example of implementation.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png" />
    <title>Icons - web components</title>
    <!--IMPORT @dv4all PACKAGES to register customElements -->
    <script src="node_modules/@dv4all/icons/lib/dv4icons.cjs.js"></script>
    <!-- END IMPORT CUSTOM COMPONENTS-->
    <!-- OPTIONAL: IMPORT CSS VARIABLES FOR CUSTOM STYLING OF COMPONENTS -->
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
    <!--EXAMPLE ICON CUSTOM WEB COMPONENT -->
    <dv4-icon-cancel-circle class="dv4-icon" title="My new title" />
  </body>
</html>

For more details see demos/html-demo.

NextJS implementation

NextJS supports SSR. On the server side customElements are not supported. You need to ensure that icons library is loaded only at the client side. I achieved this in the demo by dynamically importing web components in the app template in the React component life cycle method ComponentDidMount.

export default class MyApp extends App {
  // IMPORT web components on CLIENT SIDE
  // othewise NextJS will try to render it
  // on the server and it will faile with error
  // about customElements.define ... undefined
  componentDidMount() {
    console.log("MyApp.didMount...");
    import("@dv4all/icons").then(d => {
      console.log("imported dv4icons...", d);
    });
  }
  // ... OTHER CODE ...
}

For more details see demos/next-demo.

NuxtJS implementation

In the NuxtJS I added web components as plugins and set SSR flag to false. This was sufficient. Nuxt has also a component <client-only>...</client-only> that can be used to wrap markup that should only be rendered on the client side.

extract from nuxt.config.js

  // .... OTHER CODE
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    { src: '@/plugins/dv4-icons.js', ssr: false }
  ],
  // .... OTHER CODE

Content dv4-icons.js is simple import of npm package @dv4all/icons

// import NPM package
import "@dv4all/loaders";

For more details see demos/nuxt-demo

Icons

  • arrow-right: arrow-right svg icon as custom web component
  • backward: backward svg icon as custom web component
  • camera: camera svg icon as custom web component
  • cancel-circle: cancel-circle svg icon as custom web component
  • checkmark: checkmark svg icon as custom web component
  • circle-right: circle-right svg icon as custom web component
  • cog: cog svg icon as custom web component
  • cogs: cogs svg icon as custom web component
  • connection: connection svg icon as custom web component
  • cross: cross svg icon as custom web component
  • embed2: embed svg icon as custom web component
  • enter: enter svg icon as custom web component
  • equalizer: equalizer svg icon as custom web component
  • exit: exit svg icon as custom web component
  • flag: flag svg icon as custom web component
  • folder: folder svg icon as custom web component. One element for open and closed folder icons
  • forward: forward svg icon as custom web component.
  • home: home svg icon as custom web component.
  • image: image svg icon as custom web component.
  • info: info svg icon as custom web component.
  • key: key svg icon as custom web component.
  • map: map svg icon as custom web component.
  • menu: menu svg icon as custom web component.
  • mic: mic svg icon as custom web component.
  • next: next svg icon as custom web component.
  • notification: notification svg icon as custom web component.
  • paint-format: paint-format svg icon as custom web component.
  • paragraph: paragraph svg icon as custom web component.
  • pause: pause svg icon as custom web component.
  • pencil: pencil svg icon as custom web component.
  • phone: phone svg icon as custom web component.
  • pie-chart: pie-chart svg icon as custom web component.
  • play: play svg icon as custom web component.
  • previous: previous svg icon as custom web component.
  • share: share svg icon as custom web component.
  • stack: stack svg icon as custom web component.
  • star: star svg icon as custom web component.
  • stop: stop svg icon as custom web component.
  • switch: switch svg icon as custom web component.
  • tree: tree svg icon as custom web component.
  • trophy: trophy svg icon as custom web component.
  • video-camera: video-camera svg icon as custom web component.
  • warning: warning svg icon as custom web component.
  • wrench: wrench svg icon as custom web component.

This module is part of monorepo dv4all-wcp.