New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-gradient-path

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-gradient-path

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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

Keywords

FAQs

Package last updated on 26 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc