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-animation

v1.0.6

Published

A highly customizable, animated gradient background component for React applications.

Downloads

182

Readme

react-gradient-animation

npm version npm downloads license

A highly customizable, animated gradient background component for React applications.

Table of Contents

Installation

npm install react-gradient-animation

Or with Yarn:

yarn add react-gradient-animation

Usage

To use react-gradient-animation, wrap the GradientBackground component within a container that has a set width and height and a position: relative style.

import React from "react";
import { GradientBackground } from "react-gradient-animation";

function App() {
  return (
    <div style={{ position: "relative", width: "100%", height: "500px" }}>
      <GradientBackground
        count={20}
        size={{ min: 500, max: 700, pulse: 0.3 }}
        speed={{ x: { min: 0.5, max: 2 }, y: { min: 0.5, max: 2 } }}
        colors={{
          background: "#1e1e1e",
          particles: ["#ff007f", "#7f00ff", "#00ffff"],
        }}
        blending="overlay"
        opacity={{ center: 0.5, edge: 0 }}
        skew={-2}
        shapes={["c", "s", "t"]}
        style={{ opacity: 0.8 }}
      />
      {/* Other content */}
    </div>
  );
}

export default App;

Props

| Prop | Type | Default Value | Description | | -------------------- | ------------------------------------ | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | | count | number | 12 | The number of particles (shapes) to animate. | | size | SizeConfig | { min: 1000, max: 1200, pulse: 0.5 } | Configuration for the size of the particles. Includes min, max, and pulse values. | | speed | SpeedConfig | { x: { min: 0.6, max: 3 }, y: { min: 0.6, max: 3 } } | Configuration for the movement speed of particles along the x and y axes. | | colors | ColorsConfig | { background: 'transparent', particles: ['#ff681c', '#87ddfe', '#231efe'] } | Colors for the background and particles. | | blending | GlobalCompositeOperation or 'none' | 'overlay' | The global composite operation to use for blending particles. | | opacity | OpacityConfig | { center: 0.45, edge: 0 } | Opacity settings for particles. | | skew | number | -1.5 | The skew angle in degrees for the canvas transformation. | | shapes | ShapeType[] | ['c'] | An array of shape types for the particles. | | className | string | '' | Additional CSS classes to apply to the canvas element. | | translateYcorrection | boolean | true | Adjusts the vertical translation to compensate for the skew transformation. | | style | CSSProperties | {} | Inline styles to apply to the canvas element. |

Type Definitions

SizeConfig

interface SizeConfig {
  min: number;
  max: number;
  pulse: number;
}

SpeedAxisConfig

interface SpeedAxisConfig {
  min: number;
  max: number;
}

SpeedConfig

interface SpeedConfig {
  x: SpeedAxisConfig;
  y: SpeedAxisConfig;
}

ColorsConfig

interface ColorsConfig {
  background: string;
  particles: string[];
}

OpacityConfig

interface OpacityConfig {
  center: number;
  edge: number;
}

ShapeType

type ShapeType = "c" | "s" | "t"; // 'c' for circle, 's' for square, 't' for triangle

Examples

Basic Usage

import React from "react";
import { GradientBackground } from "react-gradient-animation";

function BasicExample() {
  return (
    <div style={{ position: "relative", height: "400px" }}>
      <GradientBackground />
      {/* Your content here */}
    </div>
  );
}

export default BasicExample;

Custom Configuration

import React from "react";
import { GradientBackground } from "react-gradient-animation";

function CustomExample() {
  return (
    <div style={{ position: "relative", width: "100%", height: "600px" }}>
      <GradientBackground
        count={15}
        size={{ min: 800, max: 1000, pulse: 0.4 }}
        speed={{ x: { min: 1, max: 2 }, y: { min: 1, max: 2 } }}
        colors={{
          background: "#0d0d0d",
          particles: ["#ff6347", "#1e90ff", "#32cd32"],
        }}
        blending="screen"
        opacity={{ center: 0.6, edge: 0 }}
        skew={-3}
        shapes={["c", "t"]}
        style={{ opacity: 0.9 }}
      />
      {/* Your content here */}
    </div>
  );
}

export default CustomExample;

Usage Notes

  • Container Requirements: The GradientBackground component should be placed within a container that has:
    • A set width and height.
    • position: relative style to ensure the canvas overlays correctly.
  • Styling: You can pass custom styles via the style prop or use the className prop to apply CSS classes.
  • Shapes: Mix and match different shapes by passing an array to the shapes prop. The particles will cycle through the provided shapes.
  • Performance Considerations: Higher values for count and larger size ranges may impact performance on lower-end devices. Adjust the speed and pulse values to optimize animation smoothness.

Contributing

Contributions are welcome! Please open an issue or pull request for any bugs, improvements, or feature requests.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

License

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

What's Included

  • Component: GradientBackground React component.
  • Type Definitions: Fully typed with TypeScript for better developer experience.
  • Customization: Highly customizable with various props to adjust the animation to your needs.

Dependencies

  • React: react is a peer dependency. Ensure it is installed in your project.

Happy coding!