Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💄 Cleanup SVG, add support for color override, storybook color controls #942

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/molecules/Waves/WaveStatic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { FC, useEffect, useState } from 'react';
import { NoiseSvg } from './NoiseSvg'; // Assuming it's another SVG file
import { WaveStaticSvg } from './WaveStaticSvg'; // Assuming it's an SVG file

export const WaveStatic: FC = () => {
interface WaveStaticProps {
gradientColors?: string[];
}

export const WaveStatic: FC<WaveStaticProps> = ({ gradientColors }) => {
const [viewBox, setViewBox] = useState(
`0 0 ${window.innerWidth} ${window.innerHeight - 64}`
);
Expand All @@ -29,7 +33,7 @@ export const WaveStatic: FC = () => {
xmlns="http://www.w3.org/2000/svg"
>
{/* Render the WaveStaticSvg */}
<WaveStaticSvg viewBox={viewBox} />
<WaveStaticSvg viewBox={viewBox} gradientColors={gradientColors} />

{/* Render the NoiseSvg with blend mode "multiply" */}
<g style={{ filter: 'grayscale(1)', mixBlendMode: 'color-burn' }}>
Expand Down
157 changes: 33 additions & 124 deletions src/molecules/Waves/WaveStaticSvg.tsx

Large diffs are not rendered by default.

42 changes: 20 additions & 22 deletions src/molecules/Waves/Waves.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
import { Meta, StoryFn } from '@storybook/react';

import { Waves, WavesProps } from 'src/molecules/Waves/Waves';

const meta: Meta<typeof Waves> = {
import { Waves } from 'src/molecules/Waves/Waves';
export interface WaveStoryProps {
gradientColors?: string[];
color1: string;
color2: string;
}
const meta: Meta<WaveStoryProps> = {
title: 'Molecules/Waves',
component: Waves,
argTypes: {
waveIntervalDist: {
control: { type: 'range', min: 1, max: 10, step: 0.25 },
name: 'Wave Interval Distance (rem)',
},
waveDelay: {
control: { type: 'range', min: 0, max: 5, step: 0.2 },
name: 'Wave Animation Delay (s)',
gradientColors: {
table: { disable: true }, // Hide gradientColors array from the controls
},
numWaves: {
control: { type: 'range', min: 1, max: 30, step: 1 },
name: 'Number of Waves',
color1: {
control: { type: 'color' },
name: 'Top Color',
},
heightFromBottom: {
control: { type: 'range', min: 0, max: 1200, step: 10 },
name: 'Wave container position (px)',
color2: {
control: { type: 'color' },
name: 'Bottom Color',
},
},
args: {
waveIntervalDist: 3,
waveDelay: 0.75,
numWaves: 10,
heightFromBottom: 600,
color1: '#77d9dd', // Default for Gradient Color 1
color2: '#407577', // Default for Gradient Color 2
},
};

export default meta;

export const Primary: StoryFn<WavesProps> = (args) => {
return <Waves {...args} />;
export const Primary: StoryFn<WaveStoryProps> = ({ color1, color2 }) => {
const gradientColors = [color1, color2]; // Combine individual colors into gradientColors array
return <Waves gradientColors={gradientColors} />;
};
7 changes: 0 additions & 7 deletions src/molecules/Waves/Waves.styles.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import styled from 'styled-components';

export const Container = styled.div`
--topGradientColor: #77d9dd;
--bottomGradientColor: #407577;
height: calc(100vh - 64px);
width: 100%;
overflow: hidden;
position: relative;
background: linear-gradient(
180deg,
var(--bottomGradientColor) 0%,
var(--topGradientColor) 100%
);
> svg {
position: absolute;
z-index: 0;
Expand Down
21 changes: 21 additions & 0 deletions src/molecules/Waves/Waves.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ test('renders expected amount of svgs', () => {
expect(container.children[0].children[0].childNodes.length).toBe(2);
});

test('renders expected gradient colors', () => {
const gradientColors = ['#ff7f50', '#1e90ff'];
const { container } = render(<Waves gradientColors={gradientColors} />);

expect(container).toBeInTheDocument();

const svgElement = container.querySelector('svg');
expect(svgElement).toBeInTheDocument();

const linearGradient = svgElement?.querySelector('linearGradient');
expect(linearGradient).toBeInTheDocument();

const gradientStops = linearGradient?.querySelectorAll('stop');
expect(gradientStops?.length).toBe(gradientColors.length);

gradientColors.forEach((color, index) => {
const stop = gradientStops?.[index];
expect(stop).toHaveAttribute('stop-color', color);
});
});

test('resize actually resizes', async () => {
const { container } = render(<Waves />);
const randomWidth = faker.number.int({ min: 100, max: 1920 });
Expand Down
8 changes: 6 additions & 2 deletions src/molecules/Waves/Waves.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { FC } from 'react';
import { Container } from './Waves.styles';
import { WaveStatic } from './WaveStatic';

export const Waves: FC = () => (
export interface WaveProps {
gradientColors?: string[];
}

export const Waves: FC<WaveProps> = ({ gradientColors }) => (
<Container>
<WaveStatic />
<WaveStatic gradientColors={gradientColors} />
</Container>
);
Loading