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

next-svg

v1.0.7

Published

This package lets you dynamic import your svg images as a Next.Js component as a parameter, with no problem at all.

Downloads

231

Readme

next-svg

Description

next-svg is a lightweight module that provides React component that is especially designed to simplify the integration of SVG images into Next.js applications. With next-svg, you can momentarily and in satisfactory way import and render SVG files, customize and manage their appearance properties like color, width, height.

What you need to know - put briefly

  • Install by running npm install next-svg.
  • Import the React component Svg from this module as the default import into a JSX/TSX file.
  • The only required prop is name (the filename without extension).
  • The SVG component searches for files located in the /public/svg directory. Ensure all your SVG files are placed there. If you wish to organize them into subdirectories, utilize the subdirectory prop.
  • Additional props are available to customize the SVG image further.

Why this package exist

SVGs are often poorly implemented, the written code lacks cleanliness and sufficient abstraction, and it struggles with dark mode compatibility and color customization. Picture having a multitude of icons or other SVG images and wanting to manage them in a rational manner to avoid getting lost in the process - not possible.

Installation

To install next-svg in your Next.js project, simply run:

npm i next-svg

or

yarn add next-svg

Usage

Import next-svg module in your React component file:

import Svg from 'next-svg';

Then, use the Svg component in your JSX/TSX file to render SVG images:

<Svg name="icon" />

Props

The Svg component accepts the following props:

  • name (required): The filename of the SVG image to render (no .svg extension needed).
  • subdirectory (optional): The subdirectory within the /public/svg/ directory where the SVG file is located.
  • className (optional): Additional CSS class names to apply to the container div.
  • color (optional): The fill color of the SVG image (accepts CSS values).
  • width (optional): The width of the SVG image (accepts CSS values).
  • height (optional): The height of the SVG image (accepts CSS values).
  • alt (required) Text to show when loading of an svg failed.

Example

import React from 'react';
import Svg from 'next-svg';

const MySvgComponent = () => {
  return (
      <Svg name="logo" subdirectory="icons" className="logo" color="blue" width={100} height={100} />
  );
};

export default MySvgComponent;

In this example, the file path is public/svg/icons/logo.svg. The SVG is rendered with a blue fill color and a width and height of 100 pixels. Div in which SVG file is placed gains all styles from className logo.

Roadmap

  • Develop functionality to enable users to configure the main folder for SVG files and other stuff.
  • Handling of runtime errors in case a file is not found
  • Optional mapper for icon names with 'name' as a rigid type
  • Provide illustrative examples and usage scenarios to assist users in implementing the feature.
  • Ensure compatibility with different project architectures, including Next.js projects.
  • Write comprehensive tests to validate the reliability and stability of the new feature.
  • Optimize performance and resource utilization to minimize overhead.
  • Addressing cases of app and src directories in Next.js

Contribution Guidelines

Contributions to the development of the custom SVG folder configuration feature are highly encouraged! If you wish to contribute, please adhere to the following guidelines:

Fork the repository and create a new branch for your changes.
Implement your changes following the project's coding standards and conventions.
Submit a pull request with a descriptive summary of the proposed changes and their rationale.
Engage in constructive discussions and address any feedback or suggestions from the maintainers.

Feedback and Support

Your feedback and suggestions regarding the custom SVG folder configuration feature are invaluable! If you have any questions or ideas, please don't hesitate to reach out. Your input will help shape the future development of this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.