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

react-gradient-path

v1.0.0

Published

A small library to have any gradient follow along any SVG path written in TypeScript and wrapped in a React component.

Downloads

76

Readme

React Gradient Path

A small library to have any gradient follow along any SVG path written in TypeScript and wrapped in a React component.

This library is inspired of the work of Patrick Cason.

Which in turn is inspired of the work of the great Mike Bostock.

We opted to use svgPathProperties to avoid the need for manipulating DOM elements directly.

Installation

npm install --save react-gradient-path

Example

import {createRoot} from 'react-dom/client';
import GradientPath from 'react-gradient-path';

const color = [
    {color: '#C6FFDD', pos: 0},
    {color: '#FBD786', pos: 0.25},
    {color: '#F7797D', pos: 0.5},
    {color: '#6DD5ED', pos: 0.75},
    {color: '#C6FFDD', pos: 1},
];

const App = () => (
    <svg width="300" height="200" viewBox="0 0 100 100">
        <GradientPath
            d="M24.3,30 C11.4,30,5,43.3,5,50 s6.4,20,19.3,20 c19.3,0,32.1-40,51.4-40 C88.6,30,95,43.3,95,50 s-6.4,20-19.3,20 C56.4,70,43.6,30,24.3,30z"
            width={10}
            segments={100}
            samples={10}
            fill={color}
        />
    </svg>
);

createRoot(document.getElementById('root')!).render(<App />);

A note about antialiasing

As Mike Bostock mentioned in his example:

This example uses a thin stroke in addition to filling the segments. This avoids antialiasing artifacts due to most web browsers not implementing full-scene antialiasing.

This is true and unavoidable. In both his example and in Gradient Path, you may notice small gaps between the edges of each segment. Don't worry, your glasses are working just fine.

To fix this you can add a very subtle stroke the same color as the fill, like this:

<GradientPath
    d="M24.3,30 C11.4,30,5,43.3,5,50 s6.4,20,19.3,20 c19.3,0,32.1-40,51.4-40 C88.6,30,95,43.3,95,50 s-6.4,20-19.3,20 C56.4,70,43.6,30,24.3,30z"
    width={10}
    segments={100}
    samples={10}
    strokeWidth={0.5}
    stroke={color}
    fill={color}
/>

Contributing

  1. npm install - installs all dev dependencies
  2. npm start - starts example app preview on http://localhost:3000

Fork and PR at will!

Acknowledgements

Mike Bostock @cereallarceny