-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from gorzelinski/confetti
Add confetti after subscription confirmation
- Loading branch information
Showing
13 changed files
with
788 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
design-system/components/confetti/__tests__/confetti.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { act, render, screen } from '@testing-library/react' | ||
import { Confetti } from '../confetti' | ||
import 'jest-canvas-mock' | ||
|
||
const text = { | ||
start: 'More confetti', | ||
stop: "That's enough", | ||
more: 'MORE!' | ||
} | ||
|
||
describe('Confetti', () => { | ||
it('renders correctly', () => { | ||
render(<Confetti start={text.start} stop={text.stop} more={text.more} />) | ||
|
||
const button = screen.getByRole('button') | ||
|
||
expect(button).toBeVisible() | ||
expect(button).toHaveTextContent(text.start) | ||
}) | ||
|
||
it('renders stop text after click', () => { | ||
render(<Confetti start={text.start} stop={text.stop} more={text.more} />) | ||
|
||
const button = screen.getByRole('button') | ||
act(() => { | ||
button.click() | ||
}) | ||
|
||
expect(button).toHaveTextContent(text.stop) | ||
}) | ||
|
||
it('renders more text after rage-clicking', () => { | ||
render(<Confetti start={text.start} stop={text.stop} more={text.more} />) | ||
|
||
const button = screen.getByRole('button') | ||
for (let i = 0; i < 12; i++) { | ||
act(() => { | ||
button.click() | ||
}) | ||
} | ||
|
||
expect(button).toHaveTextContent(text.more) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use client' | ||
import { useState } from 'react' | ||
import ConfettiComponent from 'react-confetti' | ||
import { useDocumentDimensions } from '@/hooks' | ||
import { ConfettiProps } from './confetti.types' | ||
import { Button } from '../../elements' | ||
|
||
export const Confetti = ({ start, stop, more }: ConfettiProps) => { | ||
const { width, height } = useDocumentDimensions() | ||
const [recycle, setRecycle] = useState(false) | ||
const [clicks, setClicks] = useState(0) | ||
const [numberOfPieces, setNumberOfPieces] = useState(200) | ||
|
||
return ( | ||
<> | ||
<ConfettiComponent | ||
width={width} | ||
height={height} | ||
recycle={recycle} | ||
numberOfPieces={numberOfPieces} | ||
colors={['#0466c8', '#47a3ff', '#ffbe0a', '#157f1f', '#c92c4e']} | ||
/> | ||
<Button | ||
onClick={() => { | ||
setRecycle(!recycle) | ||
setClicks(clicks + 1) | ||
|
||
if (clicks > 11) { | ||
setNumberOfPieces(1000) | ||
setClicks(-1) | ||
return | ||
} | ||
|
||
setNumberOfPieces(200) | ||
}} | ||
> | ||
{clicks > 11 ? more : recycle ? stop : start} | ||
</Button> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type ConfettiProps = { | ||
start: string | ||
stop: string | ||
more: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Confetti } from './confetti' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ export { | |
Avatar, | ||
Callout, | ||
Code, | ||
Confetti, | ||
Image, | ||
LanguageSwitch, | ||
LinkOrA, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useState, useEffect } from 'react' | ||
|
||
export function useDocumentDimensions() { | ||
const [documentDimensions, setDocumentDimensions] = useState({ | ||
width: 0, | ||
height: 0 | ||
}) | ||
|
||
useEffect(() => { | ||
setDocumentDimensions({ | ||
width: document.body.clientWidth, | ||
height: document.body.clientHeight | ||
}) | ||
|
||
const handleResize = () => { | ||
setDocumentDimensions({ | ||
width: document.body.clientWidth, | ||
height: document.body.clientHeight | ||
}) | ||
} | ||
|
||
window.addEventListener('resize', handleResize) | ||
return () => { | ||
window.removeEventListener('resize', handleResize) | ||
} | ||
}, []) | ||
|
||
return documentDimensions | ||
} |
Oops, something went wrong.