|
| 1 | +import { Typography } from '@equinor/eds-core-react'; |
| 2 | +import { Meta, StoryFn } from '@storybook/react-vite'; |
| 3 | + |
| 4 | +import { Button } from '../Button/Button'; |
| 5 | +import { SeasonalColorsMap } from './utils/seasonalColors'; |
| 6 | +import { Confetti } from './Confetti'; |
| 7 | +import { |
| 8 | + CONFETTI_DEFAULT_COLORS, |
| 9 | + CONFETTI_DEFAULT_SHAPES, |
| 10 | +} from './Confetti.constants'; |
| 11 | +import { ConfettiProps } from './Confetti.types'; |
| 12 | +import { spacings } from 'src/atoms'; |
| 13 | +import { |
| 14 | + ConfettiProvider, |
| 15 | + useConfetti, |
| 16 | +} from 'src/providers/ConfettiProvider/ConfettiProvider'; |
| 17 | + |
| 18 | +import styled from 'styled-components'; |
| 19 | + |
| 20 | +const meta: Meta<typeof Confetti> = { |
| 21 | + title: 'Molecules/Confetti', |
| 22 | + component: Confetti, |
| 23 | + parameters: { |
| 24 | + layout: 'fullscreen', |
| 25 | + }, |
| 26 | + decorators: [ |
| 27 | + (Story) => ( |
| 28 | + <ConfettiProvider> |
| 29 | + <Story /> |
| 30 | + </ConfettiProvider> |
| 31 | + ), |
| 32 | + ], |
| 33 | + argTypes: { |
| 34 | + mode: { |
| 35 | + control: { type: 'radio' }, |
| 36 | + options: ['shower', 'boom'], |
| 37 | + }, |
| 38 | + shapes: { |
| 39 | + control: { type: 'check' }, |
| 40 | + options: CONFETTI_DEFAULT_SHAPES, |
| 41 | + }, |
| 42 | + colors: { |
| 43 | + control: { type: 'check' }, |
| 44 | + options: CONFETTI_DEFAULT_COLORS, |
| 45 | + }, |
| 46 | + effectCount: { |
| 47 | + if: { arg: 'mode', eq: 'boom' }, |
| 48 | + }, |
| 49 | + duration: { |
| 50 | + if: { arg: 'mode', eq: 'shower' }, |
| 51 | + control: { type: 'number' }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + args: { |
| 55 | + shapeSize: 12, |
| 56 | + mode: 'boom', |
| 57 | + shapes: CONFETTI_DEFAULT_SHAPES, |
| 58 | + colors: CONFETTI_DEFAULT_COLORS, |
| 59 | + effectCount: Infinity, |
| 60 | + }, |
| 61 | +}; |
| 62 | + |
| 63 | +export default meta; |
| 64 | + |
| 65 | +const Container = styled.div` |
| 66 | + width: 980px; |
| 67 | + height: 480px; |
| 68 | + position: relative; |
| 69 | + overflow: hidden; |
| 70 | +`; |
| 71 | + |
| 72 | +export const Boom: StoryFn = (props: ConfettiProps) => { |
| 73 | + return ( |
| 74 | + <Container> |
| 75 | + <Confetti {...props} mode="boom" /> |
| 76 | + </Container> |
| 77 | + ); |
| 78 | +}; |
| 79 | + |
| 80 | +export const Shower: StoryFn = (props: ConfettiProps) => { |
| 81 | + return ( |
| 82 | + <Container> |
| 83 | + <Confetti {...props} mode="shower" /> |
| 84 | + </Container> |
| 85 | + ); |
| 86 | +}; |
| 87 | + |
| 88 | +const ButtonTriggeredContainer = styled.div` |
| 89 | + width: 100%; |
| 90 | + padding: ${spacings.medium}; |
| 91 | + display: flex; |
| 92 | + flex-direction: column; |
| 93 | + align-items: center; |
| 94 | + gap: ${spacings.medium}; |
| 95 | +`; |
| 96 | + |
| 97 | +export const TriggerConfetti: StoryFn = () => { |
| 98 | + const { boom, shower } = useConfetti(); |
| 99 | + |
| 100 | + return ( |
| 101 | + <ButtonTriggeredContainer> |
| 102 | + <Typography> |
| 103 | + Click the buttons below to trigger the boom and shower confetti effects |
| 104 | + </Typography> |
| 105 | + <div style={{ display: 'flex', gap: spacings.medium }}> |
| 106 | + <Button onClick={() => boom()}>Boom 🎉</Button> |
| 107 | + <Button onClick={() => shower()}>Shower 🌧️</Button> |
| 108 | + </div> |
| 109 | + </ButtonTriggeredContainer> |
| 110 | + ); |
| 111 | +}; |
| 112 | + |
| 113 | +export const SeasonalColorsExample: StoryFn = () => { |
| 114 | + const christmasColors = SeasonalColorsMap['christmas'].colors; |
| 115 | + |
| 116 | + return ( |
| 117 | + <Container> |
| 118 | + <Confetti mode="shower" colors={christmasColors} /> |
| 119 | + </Container> |
| 120 | + ); |
| 121 | +}; |
0 commit comments