Skip to content

Commit

Permalink
feat: add new login background
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Dec 3, 2024
1 parent ba39fab commit 6f367c2
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
60 changes: 60 additions & 0 deletions src/client/components/DotPatternBackground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useEffect, useRef } from 'react';

export const DotPatternBackground: React.FC = React.memo(() => {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const mouseMoveEvent = (e: MouseEvent) => {
if (!containerRef.current) {
return;
}

const scale = window.visualViewport?.scale;
// disable mouse movement on viewport zoom - causes page to slow down
if (scale === 1) {
const targetX = e.clientX;
const targetY = e.clientY;

containerRef.current.style.setProperty('--mouseX', `${targetX}px`);
containerRef.current.style.setProperty('--mouseY', `${targetY}px`);
}
};

document.addEventListener('mousemove', mouseMoveEvent);

return () => {
document.removeEventListener('mousemove', mouseMoveEvent);
};
});

return (
<div ref={containerRef} className="fixed left-0 top-0 -z-50">
<div className="sticky left-0 top-0 h-screen w-screen overflow-hidden">
<div className="bg-muted-foreground/15 absolute inset-0 -z-10" />
<div className="bg-gradient-radial from-muted-foreground/40 absolute left-[--mouseX] top-[--mouseY] -z-10 h-56 w-56 -translate-x-1/2 -translate-y-1/2 rounded-full from-0% to-transparent to-90% blur-md" />
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
<defs>
<pattern
id="dotted-pattern"
width="16"
height="16"
patternUnits="userSpaceOnUse"
>
<circle cx="2" cy="2" r="1" fill="black" />
</pattern>
<mask id="dots-mask">
<rect width="100%" height="100%" fill="white" />
<rect width="100%" height="100%" fill="url(#dotted-pattern)" />
</mask>
</defs>
<rect
width="100%"
height="100%"
fill="hsl(var(--background))"
mask="url(#dots-mask)"
/>
</svg>
</div>
</div>
);
});
DotPatternBackground.displayName = 'DotPatternBackground';
9 changes: 8 additions & 1 deletion src/client/public/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/client/routes/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useEventWithLoading } from '@/hooks/useEvent';
import { LuGithub, LuLayers } from 'react-icons/lu';
import { compact } from 'lodash-es';
import { toast } from 'sonner';
import { DotPatternBackground } from '@/components/DotPatternBackground';
import { useTheme } from '@/store/settings';

export const Route = createFileRoute('/login')({
validateSearch: z.object({
Expand All @@ -31,6 +33,7 @@ function LoginComponent() {
const navigate = useNavigate();
const { t } = useTranslation();
const search = Route.useSearch();
const theme = useTheme();

const { loginWithPassword, loginWithEmail, loginWithOAuth } = useAuth();

Expand Down Expand Up @@ -155,7 +158,9 @@ function LoginComponent() {
]);

return (
<div className="flex h-full w-full items-center justify-center dark:bg-gray-900">
<div className="flex h-full w-full items-center justify-center">
{theme === 'dark' && <DotPatternBackground />}

<div className="w-80 -translate-y-1/4">
<div className="text-center">
<img className="m-auto h-24 w-24" src="/icon.svg" />
Expand Down
16 changes: 16 additions & 0 deletions src/client/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ export function useColorSchema() {

return colorScheme;
}

export function useTheme(): 'light' | 'dark' {
const theme = useSettingsStore((state) => {
if (state.colorScheme === 'system') {
return typeof window !== 'undefined'
? window?.matchMedia('(prefers-color-scheme: dark)')?.matches
? 'dark'
: 'light'
: 'light';
} else {
return state.colorScheme;
}
});

return theme;
}
3 changes: 3 additions & 0 deletions src/client/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ module.exports = {
},
},
extend: {
backgroundImage: {
'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))',
},
colors: {
gray: colors.neutral,
border: 'hsl(var(--border))',
Expand Down

0 comments on commit 6f367c2

Please sign in to comment.