From d1f357d5c6a2c53365bc6bffa36d7fa06e2fa044 Mon Sep 17 00:00:00 2001 From: t0rbik Date: Tue, 26 Nov 2024 16:58:49 +0100 Subject: [PATCH 1/3] animated background navigation --- src/components/layout/LeftNav.tsx | 57 +++++++++++++++---- .../providers/FramerMotionProvider.tsx | 10 +--- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/components/layout/LeftNav.tsx b/src/components/layout/LeftNav.tsx index 84d96151..b423cfac 100644 --- a/src/components/layout/LeftNav.tsx +++ b/src/components/layout/LeftNav.tsx @@ -1,12 +1,26 @@ -import { cn } from "@/utils/cn"; -import { Link, useMatchRoute } from "@tanstack/react-router"; +import { HTMLAttributes, Ref, forwardRef } from "react"; +import { useMatchRoute, createLink } from "@tanstack/react-router"; +import { motion, MotionProps } from "framer-motion"; +import { cn } from "@/utils/cn"; import { routeTitleToPathMapping, RouteTitle, } from "@/components/layout/Header"; import { useSentinel } from "@/lib/queries/sentinel/useSentinel"; +const MotionLinkForwardRef = forwardRef( + ( + props: MotionProps & HTMLAttributes, + ref: Ref, + ) => { + return ; + }, +); +MotionLinkForwardRef.displayName = "MotionLinkForwardRef"; + +const MotionLink = createLink(MotionLinkForwardRef); + export function LeftNav() { const matchRoute = useMatchRoute(); const { data: isSentinel } = useSentinel(); @@ -16,17 +30,17 @@ export function LeftNav() { Navigation

{Object.keys(routeTitleToPathMapping).map((item) => ( - @@ -36,19 +50,29 @@ export function LeftNav() { className="h-7 w-7 invert dark:filter-none" alt={`${item} icon`} /> - + + {matchRoute({ + to: routeTitleToPathMapping[item as RouteTitle].to, + fuzzy: true, + }) ? ( + + ) : null} + ))} {isSentinel && ( - @@ -58,7 +82,16 @@ export function LeftNav() { className="h-7 w-7 invert dark:filter-none" alt="Sentinel icon" /> - + {matchRoute({ + to: "/sentinel", + fuzzy: true, + }) ? ( + + ) : null} + )} ); diff --git a/src/components/providers/FramerMotionProvider.tsx b/src/components/providers/FramerMotionProvider.tsx index b42b9499..01a9f6a2 100644 --- a/src/components/providers/FramerMotionProvider.tsx +++ b/src/components/providers/FramerMotionProvider.tsx @@ -1,6 +1,6 @@ -import { LazyMotion, domAnimation } from "framer-motion"; +import { LazyMotion, domMax } from "framer-motion"; -// NOTE: Reduced bundle size, +// NOTE: Possible to reduce bundle size, // see: https://www.framer.com/motion/guide-reduce-bundle-size/ export const FramerMotionProvider = ({ @@ -8,9 +8,5 @@ export const FramerMotionProvider = ({ }: { children: React.ReactNode; }) => { - return ( - - {children} - - ); + return {children}; }; From 75d6235282aee5f9c8f5ea1b4add374184f7fb48 Mon Sep 17 00:00:00 2001 From: t0rbik Date: Tue, 26 Nov 2024 17:07:41 +0100 Subject: [PATCH 2/3] adjust for reduced motion --- src/components/layout/LeftNav.tsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/layout/LeftNav.tsx b/src/components/layout/LeftNav.tsx index b423cfac..3783a016 100644 --- a/src/components/layout/LeftNav.tsx +++ b/src/components/layout/LeftNav.tsx @@ -1,6 +1,6 @@ import { HTMLAttributes, Ref, forwardRef } from "react"; import { useMatchRoute, createLink } from "@tanstack/react-router"; -import { motion, MotionProps } from "framer-motion"; +import { motion, MotionProps, useReducedMotion } from "framer-motion"; import { cn } from "@/utils/cn"; import { @@ -23,6 +23,7 @@ const MotionLink = createLink(MotionLinkForwardRef); export function LeftNav() { const matchRoute = useMatchRoute(); + const isReducedMotion = useReducedMotion(); const { data: isSentinel } = useSentinel(); return (