Skip to content

Commit

Permalink
Merge pull request #48 from alampros/develop
Browse files Browse the repository at this point in the history
Fix typescript types
  • Loading branch information
alampros authored Apr 2, 2019
2 parents 0b661a0 + f99bb57 commit 7c5bf83
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist/*
node_modules/
www/public/
storybook-static/
!.storybook/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.7.0",
"description": "React component to draw confetti for your party.",
"main": "dist/react-confetti.min.js",
"types": "dist/types/",
"types": "dist/types/ReactConfetti.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/alampros/react-confetti.git"
Expand Down
4 changes: 2 additions & 2 deletions stories/index.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const PointConfetti = (passedProps) => {

storiesOf('With Size Hook', module)
.addDecorator(withKnobs)
.add('Props', () => (
.add('Knobs', () => (
<SizedConfetti
run={boolean('Run', true)}
recycle={boolean('Recycle', true)}
Expand Down Expand Up @@ -98,6 +98,6 @@ storiesOf('With Size Hook', module)
/>
))

storiesOf('Default')
storiesOf('Default', module)
.addDecorator(withInfo)
.add('Default', () => <ReactConfetti />)
46 changes: 46 additions & 0 deletions stories/snow.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
import { useWindowSize } from 'react-use'
import { storiesOf } from '@storybook/react'
import { randomInt } from '../src/utils'

import ReactConfetti from '../src/ReactConfetti'

const SizedConfetti = (passedProps) => {
const { width, height } = useWindowSize()
return (
<ReactConfetti
width={width}
height={height}
{...passedProps}
/>
)
}

function drawSnowflake(ctx) {
const numPoints = this.numPoints || (randomInt(3, 4) * 2)
this.numPoints = numPoints
const innerRadius = this.radius * 0.2
const outerRadius = this.radius * 0.8
ctx.beginPath()
ctx.moveTo(0, 0 - outerRadius)

for(let n = 1; n < numPoints * 2; n++) {
const radius = n % 2 === 0 ? outerRadius : innerRadius
const x = radius * Math.sin((n * Math.PI) / numPoints)
const y = -1 * radius * Math.cos((n * Math.PI) / numPoints)
ctx.lineTo(x, y)
}
ctx.fill()
ctx.stroke()
ctx.closePath()
}

storiesOf('With Size Hook', module)
.add('Snow', () => (
<SizedConfetti
drawShape={drawSnowflake}
colors={['#AEE1FF', '#CBDDF8']}
gravity={0.03}
wind={0.01}
/>
))
42 changes: 42 additions & 0 deletions stories/stars.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react'
import { useWindowSize } from 'react-use'
import { storiesOf } from '@storybook/react'
import { randomInt } from '../src/utils'

import ReactConfetti from '../src/ReactConfetti'

const SizedConfetti = (passedProps) => {
const { width, height } = useWindowSize()
return (
<ReactConfetti
width={width}
height={height}
{...passedProps}
/>
)
}

function drawStar(ctx) {
const numPoints = this.numPoints || randomInt(4, 6)
this.numPoints = numPoints
const outerRadius = this.w
const innerRadius = outerRadius / 2
ctx.beginPath()
ctx.moveTo(0, 0 - outerRadius)

for(let n = 1; n < numPoints * 2; n++) {
const radius = n % 2 === 0 ? outerRadius : innerRadius
const x = radius * Math.sin((n * Math.PI) / numPoints)
const y = -1 * radius * Math.cos((n * Math.PI) / numPoints)
ctx.lineTo(x, y)
}
ctx.fill()
ctx.closePath()
}

storiesOf('With Size Hook', module)
.add('Stars', () => (
<SizedConfetti
drawShape={drawStar}
/>
))

0 comments on commit 7c5bf83

Please sign in to comment.