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

svgmagic

v1.1.8

Published

SVGMagic, dynamic SVG loader with theme support for utility classes called in just one little line.

Downloads

275

Readme

svgMagic

GitHub Actions Workflow Status GitHub Release NPM Version NPM Downloads NPM Unpacked Size

svgMagic, SVGMAGIC, svgm, or SVGM is a dynamic svg management package designed for Next.js applications. It allows developers and designers to easily load and manage svg's, making them instantly available in the development environment without manual imports or pre-specifications.

Visit our website for more in depth documentation and example animations at https://svgmagic.dev

Features

  • Dynamic Loading: Automatically load .svg files from a specified directory.
  • Easy Integration: No need to predefine or manually import svg's.
  • TailwindCSS Compatibility: Style svg's using TailwindCSS classes.
  • Optimized for Next.js: Seamlessly integrate with Next.js applications.

Installation

Use your preffered package manager to install the package. https://github.com/brohvis/svgmagic https://www.npmjs.com/package/svgmagic https://github.com/brohvis/svgmagic/pkgs/npm/svgmagic

pnpm i svgmagic
npm i svgmagic
yarn add svgmagic

Ensure SVGR is Installed

SVGM uses SVGR to transform svg into React components. SVGR is a peer dependency and should be installed automatically. If not, you can install it manually:

npm install @svgr/webpack

Configure SVGR in Next.js

Add the following configuration to your next.config.js to enable SVGR:

// next.config.js
module.exports = {
  webpack(config) {
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    });

    return config;
  },
};

Usage

To use SVGM in your Next.js project, follow these next steps:

  1. Run the Install Script: SVGM includes an install script to scaffold the necessary files and directories. Run the following command after installing the package:

    svgm-setup

    This script will:

    • Create a default or configurable svgm directory under src.
    • Optionally copy sample .svg's into this directory.
    • Create the SVGM.tsx component file in this directory.

    Note: This setup is required because require.context is a webpack feature not available to npm packages. Once locally scaffolded, it works like a charm!

  2. Import and Use SVGM Component:

    // Example usage in a Next.js page
    import SVGM from '../components/svgm/SVGM';
    
    const ExamplePage = () => (
      <div>
        <SVGM kind="apple" className="h-8 w-8 text-black" />
      </div>
    );
    
    export default ExamplePage;

Changing the Default Path and Installing Sample svg's

During setup, you can choose whether to install sample .svg's and change the default path for the svgm directory. The sample .svg's are sourced from company websites and are up-to-date as of May 15, 2024.

Adding SVGM to MDX

To use SVGM with MDX components in a setup like Contentlayer, update your mdx-components.js file:

// src/components/mdx-components.js
import SVGM from './SVGM';

const components = {
  SVGM,
  // other MDX components...
};

export default components;

Adding New svg's

  1. Naming Convention:

    • Place your .svg files in the /svgm directory.
    • Use concise and descriptive filenames. The name of the .svg file will be used to call the svg code in your components.
  2. Replace Fill Colors:

    • Open the .svg file in an editor.
    • Replace desired fill colors with "currentColor" using camel case.

    Example:

    <!-- Original -->
    <svg fill="#000000" ...>
       
    <!-- Updated -->
    <svg fill="currentColor" ...>

    This allows you to style the .svg's using CSS classes.

Contributing

PR's and issues welcome!

License

SVGM is licensed under the MIT License.

Visit Us

For more information, and a detailed demonstration and documentation using Next.js, visit SVG Magic.


Release Notes for v1.1

Title: SVGM v1.1 - Latest Release

Tags: svg, svgm, tailwindsvg, nextsvg, svgmagic

Release Notes:

  • README.md enhancements

Thank you for using SVGM! We look forward to your feedback and contributions. https://svgmagic.dev