Package Exports
- react-confetti
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-confetti) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-confetti
Confetti without the cleanup. Demo
Based on a pen by @Gthibaud: http://codepen.io/Gthibaud/pen/BoaBZK
Install
npm i -S react-confetti
Use
import Confetti from 'react-confetti'
import React from 'react'
export default class MyComponent extends React.Component {
render() {
return (
<div>
<h1>My Component contents</h1>
<Confetti />
</div>
)
}
}
Dimensions and Aspect Ratio
In order to maintain the aspect ratio of the canvas, you need to update the width
and height
props of the component when the window resizes. react-dimensions is a library to help you do this. See the source for the docs for an example or implement like so:
import React from 'react'
import Confetti from 'react-confetti'
import Dimensions from 'react-dimensions'
export default Dimensions()(class MyComponent extends React.PureComponent {
render() {
return (
<Confetti
width={this.props.containerWidth}
height={this.props.containerHeight}
/>
)
}
})
Props
Property | Type | Default | Description |
---|---|---|---|
width |
Number or String |
'100%' |
Width of the <canvas> element. |
height |
Number or String |
'100%' |
Height of the <canvas> element. |
numberOfPieces |
Number |
200 | Number of confetti pieces at one time. |
friction |
Number |
0.99 | |
wind |
Number |
0 | |
gravity |
Number |
0.1 | |
colors |
Array of String |
['#f44336' '#e91e63' '#9c27b0' '#673ab7' '#3f51b5' '#2196f3' '#03a9f4' '#00bcd4' '#009688' '#4CAF50' '#8BC34A' '#CDDC39' '#FFEB3B' '#FFC107' '#FF9800' '#FF5722' '#795548'] |
All available Colors for the confetti pieces |
opacity |
Number |
1.0 |