Open History to see the last commit
1import { useNavigate, useSearch } from "@tanstack/react-router";
2import { type ReactNode, useEffect } from "react";
3import type { HighlightParam } from "@/components/tutorial";
4import { cn } from "@/lib/utils";
5
6export function HighlightWrapper({
7 highlightId,
8 children,
9}: {
10 highlightId: Exclude<HighlightParam, undefined>;
11 children: ReactNode;
12}) {
13 const searchParams = useSearch({ strict: false });
14 const navigate = useNavigate();
15
16 const isHighlighted =
17 searchParams.highlight && highlightId.startsWith(searchParams.highlight);
18
19 useEffect(() => {
20 if (!isHighlighted) return;
21
22 const timeout = setTimeout(() => {
23 navigate({
24 to: ".",
25 search: ({ highlight: _, ...old }) => ({ ...old }),
26 replace: true,
27 });
28 }, 1000);
29
30 return () => clearTimeout(timeout);
31 }, [isHighlighted, navigate]);
32
33 return (
34 <div
35 className={cn(
36 "outline outline-offset-4 transition-all ease-in-out rounded-sm",
37 isHighlighted
38 ? "bg-red-500/15 outline-red-500 dark:outline-destructive dark:bg-destructive/10 duration-300"
39 : "bg-red-500/0 outline-red-500/0 dark:outline-destructive/0 dark:bg-destructive/0 duration-1000",
40 )}
41 >
42 {children}
43 </div>
44 );
45}