Giter VIP home page Giter VIP logo

vue-confetti-explosion's Introduction

vue-confetti-explosion

This library is the Vue 3 port of svelte-confetti-explosion which in turn is ported from the @reonomy/react-confetti-explosion package.

confetti-large-edit

Installing

# pnpm
pnpm add vue-confetti-explosion

# npm
npm install vue-confetti-explosion

# yarn
yarn add vue-confetti-explosion

Usage

Basic usage:

<script setup>
  import ConfettiExplosion from "vue-confetti-explosion";
</script>

<template>
  <ConfettiExplosion />
</template>

Customizing behavior with options:

<ConfettiExplosion :particleCount="200" :force="0.3" />

Props

There's tons of options available for this package. All of them are already documented within the code itself, so you'll never have to leave the code editor.

particleCount

Number of confetti particles to create.

type: number

Default value: 150

Example:

<ConfettiExplosion :particleCount="200" />

particleSize

Size of the confetti particles in pixels

type: number

Default value: 12

Example:

<ConfettiExplosion :particleSize="20" />

duration

Duration of the animation in milliseconds

type: number

Default value: 3500

Example:

<ConfettiExplosion :duration="5000" />

colors

Colors to use for the confetti particles. Pass string array of colors. Can use hex colors, named colors, CSS Variables, literally anything valid in plain CSS.

type: Array<string>

Default value: ['#FFC700', '#FF0000', '#2E3191', '#41BBC7']

Example:

<ConfettiExplosion :colors=['var(--yellow)', 'var(--red)', '#2E3191', '#41BBC7']
/>

force

Force of the confetti particles. Between 0 and 1. 0 is no force, 1 is maximum force. Will error out if you pass a value outside of this range.

type: number

Default value: 0.5

Example:

<ConfettiExplosion :force="0.3" />

stageHeight

Height of the stage in pixels. Confetti will only fall within this height.

type: number

Default value: 800

Example:

<ConfettiExplosion :stageHeight="500" />

stageWidth

Width of the stage in pixels. Confetti will only fall within this width.

type: number

Default value: 1600

Example:

<ConfettiExplosion :stageWidth="500" />

shouldDestroyAfterDone

Whether or not destroy all confetti nodes after the duration period has passed. By default it destroys all nodes, to free up memory.

type: boolean

Default value: true

Example:

<ConfettiExplosion :shouldDestroyAfterDone="false" />

## Style Props

This is Svelte specific, still not implemented for this Vue 3 component

You can specify two style props on the component: --x and --y. These will shift the confetti particles on the x and y axis. by how much you specify, These can be in px, em, rem, vh, vw, literally any valid CSS unit.

USAGE:

<ConfettiExplosion --x="10px" --y="10px" />

Examples

<script setup>
  import { nextTick, ref } from "vue";
  import ConfettiExplosion from "vue-confetti-explosion";

  const visible = ref(false);

  const explode = async () => {
    visible.value = false;
    await nextTick();
    visible.value = true;
  };
</script>

<template>
  <div>
    <button @click="explode">Show confetti</button>
    <ConfettiExplosion v-if="visible" />
  </div>
</template>

Potential gotchas

  • Your container must be overflow: visible in order to allow elements to fully spread across area.
  • If your floorHeight is too small, particles may visibly land on the floor instead of disappearing off-screen.

Performance

This library functions by creating 2 DOM nodes for every single confetti. By default, if the particlesCount is set to 150, it will create 300 nodes. This is a lot of nodes. For most devices, these many nodes are not a big issue, but I recommend checking your target devices' performance if you choose to go with a higher number, like 400 or 500.

Also, after the specified duration, all the confetti DOM nodes will be destroyed. This is to free up memory. If you wish to keep them around, set shouldDestroyAfterDone to false.

License

MIT License © Valgeir Björnsson

vue-confetti-explosion's People

Contributors

plfort avatar valgeirb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-confetti-explosion's Issues

Cannot read properties of undefined (reading 'isVisible')

Weirdly I get the error - Cannot read properties of undefined (reading 'isVisible')

when I try to use the component. my code is as follows

  <confetti-explosion
    v-if="parseFloat(totalPrice) >= 40"
    :colors="['#ff1e5f', '#6543fe']"
  />

Might also be worth mentioning that I'm using it as a Nuxt plugin like so...

import Vue from "vue"
import ConfettiExplosion from "vue-confetti-explosion"

Vue.use(ConfettiExplosion)

Any idea why? ChatGPT seems to think this...

Based on the code you provided, the isVisible variable is defined within the setup() function using the ref() function, but it's not exported as a part of the component's public API. Therefore, other parts of the component that are outside the setup() function cannot access isVisible, resulting in the error you're seeing.

To fix this, you can add isVisible to the component's return statement so that it's included in the public API:

Just wanted to say thanks!

This package is awesome! Very easy to get it up and running and works great with Vue3 + Nuxt3. thank you!

Typescript 4.8.4 shows an error in IDE

Using the basic setup:

<script lang="ts" setup>
  import ConfettiExplosion from "vue-confetti-explosion";
</script>

<template>
  <ConfettiExplosion />
</template>

I get the following usage error on template: (it was working fine until today)

Type '{}' is not assignable to type 'ComponentProps'.
Type '{}' is missing the following properties from type '{ props: { particleCount: { type: NumberConstructor; default: number; }; particleSize: { type: NumberConstructor; default: number; }; duration: { type: NumberConstructor; default: number; }; ... 4 more ...; shouldDestroyAfterDone: { ...; }; }; setup(props: any): { ...; }; }': props, setup ts(2322)

Relevant dependencies:

vue: 3.2.41
typescript: 4.8.4

One last thing: the project compiles correctly, the above error appears only in IDE (VS Code with Volar extension)

event only fires once

Hi Valgeir,

Ik have tried to implement this in a Laravel/Inertia/Vue3 environment using exactly the example code you provided, But using a button to fire the event does not work. It only fires (or 'explodes' if you will) upon mounting the component. Here are my dependencies:

{ "private": true, "scripts": { "dev": "npm run development", "development": "mix", "watch": "mix watch", "watch-poll": "mix watch -- --watch-options-poll=1000", "hot": "mix watch --hot", "prod": "npm run production", "production": "mix --production" }, "devDependencies": { "@inertiajs/inertia": "^0.11.0", "@inertiajs/inertia-vue3": "^0.6.0", "@inertiajs/progress": "^0.2.6", "@tailwindcss/forms": "^0.4.1", "@tailwindcss/typography": "^0.5.2", "@vue/compiler-sfc": "^3.2.31", "autoprefixer": "^10.4.2", "axios": "^0.21", "laravel-mix": "^6.0.43", "lodash": "^4.17.19", "postcss": "^8.4.8", "postcss-import": "^12.0.1", "tailwindcss": "^3.0.23", "vue": "^3.2.31", "vue-loader": "^16.1.2" }, "dependencies": { "@babel/polyfill": "^7.12.1", "@headlessui/vue": "^1.5.0", "@heroicons/vue": "^1.0.6", "@inertiajs/progress": "^0.2.7", "@inertiajs/server": "^0.1.0", "@vue/server-renderer": "^3.2.31", "animated-scroll-to": "^2.2.0", "aos": "^3.0.0-beta.6", "canvas-confetti": "^1.5.1", "laravel-vue-i18n": "^1.2.0", "moment": "^2.29.1", "swiper": "^8.0.7", "vue-confetti-explosion": "^1.0.1", "vue-cookie-next": "^1.3.0", "vuex": "^4.0.2", "webpack-node-externals": "^3.0.0" } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.