• Stars
    star
    371
  • Rank 115,103 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 2 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React tsParticles official component

banner

react-particles

npm npm GitHub Sponsors

Official tsParticles ReactJS component

Slack Discord Telegram

tsParticles Product Hunt

Installation

npm install react-particles

or

yarn add react-particles

create-react-app

Starting from version 1.17.0 there are two official create-react-app templates:

  • cra-template-particles: Simple ReactJS template with full screen particles, using JavaScript
  • cra-template-particles-typescript: Simple ReactJS template with full screen particles, using TypeScript

You can simply install them using the create-react-app command like this:

$ create-react-app your_app --template particles

or

$ create-react-app your_app --template particles-typescript

How to use

Code

Examples:

Remote url

JavaScript support - url
import { useCallback } from "react";
import Particles from "react-particles";
//import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "tsparticles-slim"; // if you are going to use `loadSlim`, install the "tsparticles-slim" package too.

const App = () => {
    const particlesInit = useCallback(async engine => {
        console.log(engine);
        // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
        // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
        // starting from v2 you can add only the features you need reducing the bundle size
        //await loadFull(engine);
        await loadSlim(engine);
    }, []);

    const particlesLoaded = useCallback(async container => {
        await console.log(container);
    }, []);

    return (
        <Particles id="tsparticles" url="http://foo.bar/particles.json" init={particlesInit} loaded={particlesLoaded} />
    );
};
TypeScript support - url
import { useCallback } from "react";
import Particles from "react-particles";
import type { Container, Engine } from "tsparticles-engine";
//import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "tsparticles-slim"; // if you are going to use `loadSlim`, install the "tsparticles-slim" package too.

const App = () => {
    const particlesInit = useCallback(async (engine: Engine) => {
        console.log(engine);

        // you can initialize the tsParticles instance (engine) here, adding custom shapes or presets
        // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
        // starting from v2 you can add only the features you need reducing the bundle size
        //await loadFull(engine);
        await loadSlim(engine);
    }, []);

    const particlesLoaded = useCallback(async (container: Container | undefined) => {
        await console.log(container);
    }, []);

    return (
        <Particles id="tsparticles" url="http://foo.bar/particles.json" init={particlesInit} loaded={particlesLoaded} />
    );
};

Options object

JavaScript support - object
import { useCallback } from "react";
import Particles from "react-particles";
//import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "tsparticles-slim"; // if you are going to use `loadSlim`, install the "tsparticles-slim" package too.

const App = () => {
    const particlesInit = useCallback(async engine => {
        console.log(engine);
        // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
        // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
        // starting from v2 you can add only the features you need reducing the bundle size
        //await loadFull(engine);
        await loadSlim(engine);
    }, []);

    const particlesLoaded = useCallback(async container => {
        await console.log(container);
    }, []);

    return (
        <Particles
            id="tsparticles"
            init={particlesInit}
            loaded={particlesLoaded}
            options={{
                background: {
                    color: {
                        value: "#0d47a1",
                    },
                },
                fpsLimit: 120,
                interactivity: {
                    events: {
                        onClick: {
                            enable: true,
                            mode: "push",
                        },
                        onHover: {
                            enable: true,
                            mode: "repulse",
                        },
                        resize: true,
                    },
                    modes: {
                        push: {
                            quantity: 4,
                        },
                        repulse: {
                            distance: 200,
                            duration: 0.4,
                        },
                    },
                },
                particles: {
                    color: {
                        value: "#ffffff",
                    },
                    links: {
                        color: "#ffffff",
                        distance: 150,
                        enable: true,
                        opacity: 0.5,
                        width: 1,
                    },
                    move: {
                        direction: "none",
                        enable: true,
                        outModes: {
                            default: "bounce",
                        },
                        random: false,
                        speed: 6,
                        straight: false,
                    },
                    number: {
                        density: {
                            enable: true,
                            area: 800,
                        },
                        value: 80,
                    },
                    opacity: {
                        value: 0.5,
                    },
                    shape: {
                        type: "circle",
                    },
                    size: {
                        value: { min: 1, max: 5 },
                    },
                },
                detectRetina: true,
            }}
        />
    );
};
TypeScript support - object
import { useCallback } from "react";
import type { Container, Engine } from "tsparticles-engine";
import Particles from "react-particles";
//import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "tsparticles-slim"; // if you are going to use `loadSlim`, install the "tsparticles-slim" package too.

const App = () => {
    const particlesInit = useCallback(async (engine: Engine) => {
        console.log(engine);

        // you can initialize the tsParticles instance (engine) here, adding custom shapes or presets
        // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
        // starting from v2 you can add only the features you need reducing the bundle size
        //await loadFull(engine);
        await loadSlim(engine);
    }, []);

    const particlesLoaded = useCallback(async (container: Container | undefined) => {
        await console.log(container);
    }, []);
    return (
        <Particles
            id="tsparticles"
            init={particlesInit}
            loaded={particlesLoaded}
            options={{
                background: {
                    color: {
                        value: "#0d47a1",
                    },
                },
                fpsLimit: 120,
                interactivity: {
                    events: {
                        onClick: {
                            enable: true,
                            mode: "push",
                        },
                        onHover: {
                            enable: true,
                            mode: "repulse",
                        },
                        resize: true,
                    },
                    modes: {
                        push: {
                            quantity: 4,
                        },
                        repulse: {
                            distance: 200,
                            duration: 0.4,
                        },
                    },
                },
                particles: {
                    color: {
                        value: "#ffffff",
                    },
                    links: {
                        color: "#ffffff",
                        distance: 150,
                        enable: true,
                        opacity: 0.5,
                        width: 1,
                    },
                    move: {
                        direction: "none",
                        enable: true,
                        outModes: {
                            default: "bounce",
                        },
                        random: false,
                        speed: 6,
                        straight: false,
                    },
                    number: {
                        density: {
                            enable: true,
                            area: 800,
                        },
                        value: 80,
                    },
                    opacity: {
                        value: 0.5,
                    },
                    shape: {
                        type: "circle",
                    },
                    size: {
                        value: { min: 1, max: 5 },
                    },
                },
                detectRetina: true,
            }}
        />
    );
};

Props

Prop Type Definition
id string The id of the element.
width string The width of the canvas.
height string The height of the canvas.
options object The options of the particles instance.
url string The remote options url, called using an AJAX request
style object The style of the canvas element.
className string The class name of the canvas wrapper.
canvasClassName string the class name of the canvas.
container object The instance of the particles container
init function This function is called after the tsParticles instance initialization, the instance is the parameter and you can load custom presets or shapes here
loaded function This function is called when particles are correctly loaded in canvas, the current container is the parameter and you can customize it here

particles.json

Find all configuration options here.

You can find sample configurations here 📖

Demos

Preset demos can be found here

There's also a CodePen collection actively maintained and updated here

Report bugs and issues here

tsParticle Website

More Repositories

1

tsparticles

tsParticles - Easily create highly customizable JavaScript particles effects, confetti explosions and fireworks animations and use them as animated backgrounds for your website. Ready to use components available for React.js, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Inferno, Solid, Riot and Web Components.
TypeScript
7,510
star
2

404-templates

tsParticles Auth Template for Websites
JavaScript
154
star
3

vue3

Vue.js tsParticles official component
Vue
113
star
4

templates

tsParticles website templates collection
69
star
5

auth-template

tsParticles Auth Template for Websites
HTML
51
star
6

svelte

Svelte tsParticles official plugin
Svelte
41
star
7

astro

tsParticles Astro official component
Astro
34
star
8

angular

Angular tsParticles official component
TypeScript
31
star
9

react-demo

JavaScript
22
star
10

presets

tsParticles Official Presets Repository
Pug
16
star
11

vue2

tsParticles Official Vue 2 component library
Vue
16
star
12

vue3-auth-template

tsParticles VueJS 3.x Authentication Forms template
Vue
13
star
13

solid

Solid.js tsParticles official component
JavaScript
13
star
14

gatsby-landing-page-starter

tsParticles Simple Landing Page Starter for Gatsby Websites
JavaScript
13
star
15

confetti

tsParticles official confetti website
JavaScript
12
star
16

react-glass-auth-template

Glassmorphism React.js Auth Template with Javascript Particles using tsParticles
JavaScript
12
star
17

jquery

jQuery tsParticles official plugin
Pug
11
star
18

react-landing-page-template

React tsParticles Landing Page Template
JavaScript
10
star
19

vue-auth-template

tsParticles VueJS Authentication Forms template
Vue
9
star
20

svelte-auth-template

tsParticles Svelte Authentication Forms template
Svelte
9
star
21

react-auth-template

tsParticles ReactJS Authentication Forms template
JavaScript
8
star
22

landing-page-template

tsParticles Landing Page Template
HTML
8
star
23

typedoc-particles-theme

TypeDoc template with tsParticles as animated background
TypeScript
7
star
24

vue3-demo

tsParticles Vue.js 3.x demo for YouTube
Vue
7
star
25

angular-auth-template

Angular tsParticles Authentication Forms template
HTML
7
star
26

vanilla-demo

HTML
7
star
27

vue

tsParticles official Vue.js component library
Vue
7
star
28

preact

Preact.js tsParticles official component
JavaScript
6
star
29

webcomponents

Web Components tsParticles official component
TypeScript
6
star
30

glass-auth-template

Glassmorphism Auth Template with Javascript Particles using tsParticles
HTML
6
star
31

nuxt3-particles-demo

Nuxt3 Particles Demo
Vue
6
star
32

ember

tsParticles Official Ember.js component
TypeScript
6
star
33

website

tsParticles official website
HTML
6
star
34

utils

tsParticles Common Utils
TypeScript
5
star
35

riot

Riot.js tsParticles official component
JavaScript
5
star
36

inferno

Inferno.js tsParticles official component
TypeScript
5
star
37

wordpress

WordPress tsParticles official plugin
JavaScript
5
star
38

editor

tsParticles official editor
TypeScript
4
star
39

.github

tsParticles GitHub Profile
4
star
40

create-react-app-templates

Create React App CLI Templates using tsParticles
SCSS
4
star
41

lit

tsParticles Lit Official Component
JavaScript
4
star
42

storybook

tsParticles Storybook
JavaScript
4
star
43

particles.js

tsParticles particles.js compatibility library
TypeScript
4
star
44

cli

tsParticles CLI
TypeScript
4
star
45

nuxt2-particles-demo

Nuxt.js Particles Demo
Vue
3
star
46

qwik

Qwik tsParticles official component
TypeScript
2
star
47

stencil

tsParticles Stencil.js official component library
TypeScript
1
star
48

tsparticles.github.io

tsParticles GitHub Website
HTML
1
star