Skip to content

Commit

Permalink
Merge pull request #59 from alampros/develop
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
alampros authored Jul 11, 2019
2 parents e324de2 + 41c7dd0 commit a058c6d
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 153 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"commitizen": "^3.0.7",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^6",
"eslint-config-standard": "^12.0.0",
"eslint-config-standard": "^13.0.0",
"eslint-config-standard-react": "^7.0.2",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-node": "^9.0.1",
Expand Down
3 changes: 3 additions & 0 deletions src/Circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export default class Circle implements ICircle {
this.y = init.y
this.radius = init.radius
}

x: number

y: number

radius: number
}
6 changes: 6 additions & 0 deletions src/Confetti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,21 @@ export class Confetti {
this.options = opts
this.update()
}

canvas: HTMLCanvasElement

context: CanvasRenderingContext2D

_options!: IConfettiOptions

generator: ParticleGenerator

rafId?: number

get options(): Partial<IConfettiOptions> {
return this._options
}

set options(opts: Partial<IConfettiOptions>) {
const lastRunState = this._options && this._options.run
const lastRecycleState = this._options && this._options.recycle
Expand Down
15 changes: 15 additions & 0 deletions src/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,36 @@ export default class Particle {
this.rotateY = randomRange(0, 1)
this.rotationDirection = randomRange(0, 1) ? RotationDirection.Positive : RotationDirection.Negative
}

context: CanvasRenderingContext2D

radius: number

x: number

y: number

w: number

h: number

vx: number

vy: number

shape: ParticleShape

angle: number

angularSpin: number

color: string

// Actually used as scaleY to simulate rotation cheaply
rotateY: number

rotationDirection: RotationDirection

getOptions: () => IConfettiOptions

update() {
Expand Down
11 changes: 11 additions & 0 deletions src/ParticleGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ export default class ParticleGenerator implements IParticleGenerator {
this.context = ctx
this.getOptions = getOptions
}

canvas: HTMLCanvasElement

context: CanvasRenderingContext2D

getOptions: () => IConfettiOptions

x: number = 0

y: number = 0

w: number = 0

h: number = 0

lastNumberOfPieces: number = 0

tweenInitTime: number = Date.now()

particles: Particle[] = []

particlesGenerated: number = 0

removeParticleAt = (i: number) => {
Expand Down
2 changes: 2 additions & 0 deletions src/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class Point implements IPoint {
this.x = init.x
this.y = init.y
}

x: number

y: number
}
5 changes: 4 additions & 1 deletion src/ReactConfetti.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ReactConfetti extends Component<Props> {
}

canvas: React.RefObject<HTMLCanvasElement> = React.createRef()

confetti?: Confetti

componentDidMount() {
Expand All @@ -26,12 +27,14 @@ export class ReactConfetti extends Component<Props> {
this.confetti = new Confetti(this.canvas.current, opts)
}
}

componentWillReceiveProps(nextProps: Props) {
const confettiOptions = extractCanvasProps(nextProps)[0]
if(this.confetti) {
this.confetti.options = confettiOptions as IConfettiOptions
}
}

componentWillUnmount() {
if(this.confetti) {
this.confetti.stop()
Expand All @@ -40,7 +43,7 @@ export class ReactConfetti extends Component<Props> {
}

render() {
const [ confettiOptions, passedProps ] = extractCanvasProps(this.props)
const [confettiOptions, passedProps] = extractCanvasProps(this.props)
const canvasStyles = {
zIndex: 2,
position: 'absolute' as 'absolute',
Expand Down
Loading

0 comments on commit a058c6d

Please sign in to comment.