Skip to content

Commit 857142d

Browse files
mariush2Copilot
andauthored
feat: Side sheet (#1232)
* feat: Side sheet * fix: Bad import * test: Adding tests for SideSheet * fix: Copilot feedback * fix: Stateful SideSheet test * fix: Required -> NonNullable * fix: SideSheet modal with scrim test * test: Fix test coverage on Confetti component when there is a seasonal event * docs: Update JSDoc for getSeasonalColors * Update src/molecules/Confetti/Confetti.utils.jsdom.test.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 48db43e commit 857142d

11 files changed

Lines changed: 650 additions & 16 deletions

File tree

src/molecules/Confetti/Confetti.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { FC, useCallback, useEffect, useRef } from 'react';
22

33
import { createConfetti } from './utils/createConfetti';
4-
import { getSeasonalColors } from './utils/seasonalColors';
5-
import {
6-
CONFETTI_DEFAULT_COLORS,
7-
CONFETTI_DEFAULT_SHAPES,
8-
} from './Confetti.constants';
4+
import { CONFETTI_DEFAULT_SHAPES } from './Confetti.constants';
95
import { Canvas } from './Confetti.styles';
106
import { ConfettiProps, Particle } from './Confetti.types';
7+
import { getDefaultColors } from 'src/molecules/Confetti/utils/getDefaultColors';
118

129
/**
1310
* @param mode 'boom' | 'shower' - Confetti effect mode.
@@ -31,9 +28,7 @@ export const Confetti: FC<ConfettiProps> = (props) => {
3128
} = props;
3229

3330
const colors =
34-
props.colors && props.colors.length
35-
? props.colors
36-
: getSeasonalColors() || CONFETTI_DEFAULT_COLORS;
31+
props.colors && props.colors.length ? props.colors : getDefaultColors();
3732
const shapes =
3833
props.shapes && props.shapes.length
3934
? props.shapes

src/molecules/Confetti/Confetti.utils.jsdom.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createParticle } from './utils/createParticle';
2+
import { getDefaultColors } from './utils/getDefaultColors';
23
import { getSeasonalEvent } from './utils/getSeasonalEvent';
34
import { getSeasonalColors, SeasonalColorsMap } from './utils/seasonalColors';
45
import {
@@ -7,6 +8,9 @@ import {
78
randomNumBetween,
89
replaceOpacity,
910
} from './utils/utils';
11+
import { CONFETTI_DEFAULT_COLORS } from './Confetti.constants';
12+
13+
import { test } from 'vitest';
1014

1115
test('randomNumBetween generates numbers within the specified range', () => {
1216
const min = 5;
@@ -156,3 +160,9 @@ test('getSeasonalColors returns easter colors 2 days before Easter Sunday', () =
156160

157161
expect(colors).toEqual(easterColors);
158162
});
163+
164+
test("getDefaultColors returns default colors if it isn't a special day", () => {
165+
expect(getDefaultColors(new Date('2024-01-15'))).toEqual(
166+
CONFETTI_DEFAULT_COLORS
167+
);
168+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { CONFETTI_DEFAULT_COLORS } from '../Confetti.constants';
2+
import { getSeasonalColors } from './seasonalColors';
3+
4+
export function getDefaultColors(date = new Date()) {
5+
const seasonalColors = getSeasonalColors(date);
6+
if (seasonalColors) {
7+
return seasonalColors;
8+
}
9+
return CONFETTI_DEFAULT_COLORS;
10+
}

src/molecules/Confetti/utils/seasonalColors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ export const SeasonalColorsMap: Record<SeasonalEvent, SeasonalPalette> = {
9393

9494
/**
9595
* Returns a color palette for a given date
96-
* Defaults to today.
9796
* Returns null if no seasonal event is detected.
9897
*/
99-
export function getSeasonalColors(date = new Date()): string[] | null {
98+
export function getSeasonalColors(date: Date): string[] | null {
10099
const event = getSeasonalEvent(date);
101100
return event ? SeasonalColorsMap[event].colors : null;
102101
}

0 commit comments

Comments
 (0)