Skip to content

Commit

Permalink
feat(background): setup gradient background (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Shayne Preston <[email protected]>
  • Loading branch information
prests and Shayne Preston authored Nov 26, 2024
1 parent 08a1ffb commit 4e475f0
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 12 deletions.
189 changes: 189 additions & 0 deletions src/remix-app/components/background/AuroraBackground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import * as stylex from '@stylexjs/stylex';

import { tokens } from '../../themes/tokens.stylex';

const swayOne = stylex.keyframes({
'0%': {
transform: 'translate(0, 0) rotate(0deg) scale(1)',
},
'50%': {
transform: 'translate(20px, -10px) rotate(10deg) scale(1.1)',
},
'100%': {
transform: 'translate(0, 0) rotate(0deg) scale(1)',
},
});

const swayTwo = stylex.keyframes({
'0%': {
transform: 'translate(0, 0) rotate(0deg) scale(1)',
},
'50%': {
transform: 'translate(-15px, 20px) rotate(-10deg) scale(1.05)',
},
'100%': {
transform: 'translate(0, 0) rotate(0deg) scale(1)',
},
});

const swayThree = stylex.keyframes({
'0%': {
transform: 'translate(0, 0) rotate(0deg) scale(1)',
},
'50%': {
transform: 'translate(10px, -15px) rotate(5deg) scale(1.08)',
},
'100%': {
transform: 'translate(0, 0) rotate(0deg) scale(1)',
},
});

const swayFour = stylex.keyframes({
'0%': { transform: 'translate(0, 0) rotate(0deg) scale(1)' },
'50%': { transform: 'translate(-20px, -20px) rotate(-15deg) scale(1.1)' },
'100%': { transform: 'translate(0, 0) rotate(0deg) scale(1)' },
});

const styles = stylex.create({
auroraWrapper: {
backgroundColor: tokens.color_base_page_background,
position: 'fixed',
top: 0,
left: 0,
width: '100%',
height: '100%',
overflow: 'hidden',
zIndex: -1,
},
auroraSvg: {
width: '100%',
height: '100%',
},
ellipse: {
transformOrigin: 'center',
animationTimingFunction: 'ease-in-out',
animationIterationCount: 'infinite',
},
gradientOneStart: {
stopColor: tokens.color_gradient_one_background_start,
},
gradientOneEnd: {
stopColor: tokens.color_gradient_one_background_end,
},
gradientTwoStart: {
stopColor: tokens.color_gradient_two_background_start,
},
gradientTwoEnd: {
stopColor: tokens.color_gradient_two_background_end,
},
gradientThreeStart: {
stopColor: tokens.color_gradient_three_background_start,
},
gradientThreeEnd: {
stopColor: tokens.color_gradient_three_background_end,
},
gradientFourStart: {
stopColor: tokens.color_gradient_three_background_start,
},
gradientFourEnd: {
stopColor: tokens.color_gradient_three_background_end,
},
animationOne: {
animationName: swayOne,
animationDuration: '5s',
animationIterationCount: 'infinite',
animationTimingFunction: 'ease-in-out',
},
animationTwo: {
animationName: swayTwo,
animationDuration: '7s',
animationIterationCount: 'infinite',
animationTimingFunction: 'ease-in-out',
},
animationThree: {
animationName: swayThree,
animationDuration: '10s',
animationIterationCount: 'infinite',
animationTimingFunction: 'ease-in-out',
},
animationFour: {
animationName: swayFour,
animationDuration: '19s',
animationIterationCount: 'infinite',
animationTimingFunction: 'ease-in-out',
},
});

const AuroraBackground = () => {
return (
<div {...stylex.props(styles.auroraWrapper)}>
<svg {...stylex.props(styles.auroraSvg)} xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient id="gradient1" cx="50%" cy="50%" r="50%">
<stop {...stylex.props(styles.gradientOneStart)} offset="0%" />
<stop {...stylex.props(styles.gradientOneEnd)} offset="100%" />
</radialGradient>
<radialGradient id="gradient2" cx="50%" cy="50%" r="50%">
<stop {...stylex.props(styles.gradientTwoStart)} offset="0%" />
<stop {...stylex.props(styles.gradientTwoEnd)} offset="100%" />
</radialGradient>
<radialGradient id="gradient3" cx="50%" cy="50%" r="50%">
<stop {...stylex.props(styles.gradientThreeStart)} offset="0%" stopColor="#fad0c4" />
<stop {...stylex.props(styles.gradientThreeEnd)} offset="100%" stopColor="#ffd1ff" />
</radialGradient>
<radialGradient id="gradient4" cx="50%" cy="50%" r="50%">
<stop {...stylex.props(styles.gradientFourStart)} offset="0%" />
<stop {...stylex.props(styles.gradientFourEnd)} offset="100%" />
</radialGradient>
</defs>
<g filter="url(#blur)">
<ellipse
{...stylex.props(styles.ellipse, styles.animationOne)}
cx="20%"
cy="30%"
rx="15vw"
ry="25vh"
fill="url(#gradient1)"
/>
<ellipse
{...stylex.props(styles.ellipse, styles.animationTwo)}
cx="75%"
cy="80%"
rx="25vw"
ry="15vh"
fill="url(#gradient2)"
/>
<ellipse
{...stylex.props(styles.ellipse, styles.animationThree)}
cx="30%"
cy="90%"
rx="20vw"
ry="30vh"
fill="url(#gradient3)"
/>
<ellipse
{...stylex.props(styles.ellipse, styles.animationFour)}
cx="70%"
cy="30%"
rx="30vw"
ry="20vh"
fill="url(#gradient4)"
/>
<ellipse
{...stylex.props(styles.ellipse, styles.animationFour)}
cx="50%"
cy="50%"
rx="30vw"
ry="20vh"
fill="url(#gradient4)"
/>
</g>
<filter id="blur" colorInterpolationFilters="sRGB">
<feGaussianBlur stdDeviation="100" />
</filter>
</svg>
</div>
);
};

export default AuroraBackground;
12 changes: 4 additions & 8 deletions src/remix-app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react';
import * as stylex from '@stylexjs/stylex';

import AuroraBackground from './components/background/AuroraBackground';
import { useNonce } from './hooks/nonce';
import stylexStylesheet from './main.css?url';
import ThemeProvider from './themes/ThemeProvider';
import { LIGHT_MODE } from './themes/themes.constant';
import { tokens } from './themes/tokens.stylex';

import type { LinksFunction } from '@remix-run/node';

Expand All @@ -23,11 +23,6 @@ const styles = stylex.create({
display: 'flex',
flexDirection: 'column',
},
outlet: {
height: '100%',
width: '100%',
backgroundColor: tokens.color_page_background,
},
});

const App = () => {
Expand All @@ -46,9 +41,10 @@ const App = () => {

<body {...stylex.props(styles.body)}>
<ThemeProvider mode={theme}>
<main {...stylex.props(styles.outlet)}>
<>
<AuroraBackground />
<Outlet />
</main>
</>
</ThemeProvider>

<ScrollRestoration nonce={nonce ?? undefined} />
Expand Down
8 changes: 7 additions & 1 deletion src/remix-app/themes/dark-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import type { ThemeTokens } from './themes.types';

const darkTheme = stylex.createTheme<stylex.VarGroup<ThemeTokens>>(tokens, {
// Pages
color_page_background: stylex.types.color(blueGrey.bg700),
color_base_page_background: stylex.types.color(blueGrey.bg700),
color_gradient_one_background_start: stylex.types.color(orange.o600),
color_gradient_one_background_end: stylex.types.color(orange.o700),
color_gradient_two_background_start: stylex.types.color(orange.o600),
color_gradient_two_background_end: stylex.types.color(orange.o700),
color_gradient_three_background_start: stylex.types.color(blueGrey.bg600),
color_gradient_three_background_end: stylex.types.color(blueGrey.bg700),
/* ---------------------------- */
// Actions
color_action_text: stylex.types.color(orange.o300),
Expand Down
8 changes: 7 additions & 1 deletion src/remix-app/themes/light-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import type { ThemeTokens } from './themes.types';

const lightTheme = stylex.createTheme<stylex.VarGroup<ThemeTokens>>(tokens, {
// Pages
color_page_background: stylex.types.color(blueGrey.bg50),
color_base_page_background: stylex.types.color(blueGrey.bg50),
color_gradient_one_background_start: stylex.types.color(orange.o100),
color_gradient_one_background_end: stylex.types.color(orange.o200),
color_gradient_two_background_start: stylex.types.color(orange.o100),
color_gradient_two_background_end: stylex.types.color(orange.o200),
color_gradient_three_background_start: stylex.types.color(blueGrey.bg100),
color_gradient_three_background_end: stylex.types.color(blueGrey.bg200),
/* ---------------------------- */
// Actions
color_action_text: stylex.types.color(orange.o700),
Expand Down
8 changes: 7 additions & 1 deletion src/remix-app/themes/themes.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ type ThemeMode = typeof LIGHT_MODE | typeof DARK_MODE | undefined;

interface Tokens {
// Pages
color_page_background: Color;
color_base_page_background: Color;
color_gradient_one_background_start: Color;
color_gradient_one_background_end: Color;
color_gradient_two_background_start: Color;
color_gradient_two_background_end: Color;
color_gradient_three_background_start: Color;
color_gradient_three_background_end: Color;
/* ---------------------------- */
// Actions
color_action_text: Color;
Expand Down
8 changes: 7 additions & 1 deletion src/remix-app/themes/tokens.stylex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const DARK = '@media (prefers-color-scheme: dark)';

export const tokens = stylex.defineVars<Tokens>({
// Pages
color_page_background: stylex.types.color({ default: blueGrey.bg50, [DARK]: blueGrey.bg700 }),
color_base_page_background: stylex.types.color({ default: blueGrey.bg50, [DARK]: blueGrey.bg700 }),
color_gradient_one_background_start: stylex.types.color({ default: orange.o100, [DARK]: orange.o600 }),
color_gradient_one_background_end: stylex.types.color({ default: orange.o200, [DARK]: orange.o700 }),
color_gradient_two_background_start: stylex.types.color({ default: orange.o100, [DARK]: orange.o600 }),
color_gradient_two_background_end: stylex.types.color({ default: orange.o200, [DARK]: orange.o700 }),
color_gradient_three_background_start: stylex.types.color({ default: blueGrey.bg100, [DARK]: blueGrey.bg600 }),
color_gradient_three_background_end: stylex.types.color({ default: blueGrey.bg200, [DARK]: blueGrey.bg700 }),
/* ---------------------------- */
// Actions
color_action_text: stylex.types.color({ default: orange.o700, [DARK]: orange.o300 }),
Expand Down

0 comments on commit 4e475f0

Please sign in to comment.