The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update active states + add animations
Tim Wilson79d92e250966
diff --git a/apps/web/ui/layout/sidebar/icons/cursor-rays.tsx b/apps/web/ui/layout/sidebar/icons/cursor-rays.tsxnew file mode 100644index 0000000000..6624c349ec--- /dev/null+++ b/apps/web/ui/layout/sidebar/icons/cursor-rays.tsx@@ -0,0 +1,136 @@+import { cn } from "@dub/utils";+import { SVGProps, useEffect, useRef } from "react";++export function CursorRays({+ isActive,+ className,+ ...rest+}: { isActive: boolean } & SVGProps<SVGSVGElement>) {+ const cursorRef = useRef<SVGGElement>(null);+ const raysRef = useRef<SVGGElement>(null);++ useEffect(() => {+ if (!raysRef.current || !cursorRef.current) return;++ if (isActive) {+ raysRef.current.animate(+ [+ { transform: "scale(1)", opacity: 1 },+ { transform: "scale(1.15)", opacity: 1 },+ { transform: "scale(1.3)", opacity: 0 },+ { transform: "scale(1)", opacity: 0 },+ { transform: "scale(1)", opacity: 1 },+ ],+ {+ duration: 500,+ },+ );++ cursorRef.current.animate(+ [+ { transform: "translate(0, 0)" },+ { transform: "translate(1px, 1px)" },+ { transform: "translate(0, 0)" },+ ],+ {+ duration: 500,+ },+ );+ }+ }, [isActive]);++ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ className={cn("overflow-visible", className)}+ {...rest}+ >+ <g fill="currentColor">+ <g ref={cursorRef}>+ <path+ d="M8.095,7.778l7.314,2.51c.222,.076,.226,.388,.007,.47l-3.279,1.233c-.067,.025-.121,.079-.146,.146l-1.233,3.279c-.083,.219-.394,.215-.47-.007l-2.51-7.314c-.068-.197,.121-.385,.318-.318Z"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="12.031"+ x2="16.243"+ y1="12.031"+ y2="16.243"+ />+ </g>+ <g+ ref={raysRef}+ className="[transform-box:fill-box] [transform-origin:center] [&_*]:[vector-effect:non-scaling-stroke]"+ >+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="7.75"+ x2="7.75"+ y1="1.75"+ y2="3.75"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="11.993"+ x2="10.578"+ y1="3.507"+ y2="4.922"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="3.507"+ x2="4.922"+ y1="11.993"+ y2="10.578"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="1.75"+ x2="3.75"+ y1="7.75"+ y2="7.75"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="3.507"+ x2="4.922"+ y1="3.507"+ y2="4.922"+ />+ </g>+ </g>+ </svg>+ );+}diff --git a/apps/web/ui/layout/sidebar/icons/hyperlink.tsx b/apps/web/ui/layout/sidebar/icons/hyperlink.tsxnew file mode 100644index 0000000000..07da83df95--- /dev/null+++ b/apps/web/ui/layout/sidebar/icons/hyperlink.tsx@@ -0,0 +1,48 @@+import { SVGProps, useEffect, useRef } from "react";++export function Hyperlink({+ isActive,+ ...rest+}: { isActive: boolean } & SVGProps<SVGSVGElement>) {+ const ref = useRef<SVGSVGElement>(null);++ useEffect(() => {+ if (!ref.current) return;++ if (isActive) {+ ref.current.animate(+ [+ { transform: "rotate(0deg)" },+ { transform: "rotate(10deg)" },+ { transform: "rotate(-10deg)" },+ { transform: "rotate(0deg)" },+ ],+ {+ duration: 300,+ },+ );+ }+ }, [isActive]);++ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ ref={ref}+ {...rest}+ >+ <g fill="currentColor">+ <path+ d="M12.188,16.484c-1.097,0-2.192-.417-3.026-1.252l-2.175-2.175c-1.671-1.671-1.671-4.39,0-6.061,.356-.356,.753-.637,1.19-.846,.371-.18,.82-.021,1,.354,.179,.374,.021,.821-.354,1-.283,.135-.541,.318-.766,.543-1.096,1.096-1.096,2.863-.01,3.95l2.175,2.175c1.086,1.085,2.853,1.086,3.939,0,1.096-1.096,1.096-2.863,.01-3.949l-.931-.931c-.293-.293-.293-.768,0-1.061s.768-.293,1.061,0l.931,.931c1.671,1.671,1.671,4.389,0,6.06-.842,.842-1.944,1.262-3.044,1.262Z"+ fill="currentColor"+ />+ <path+ d="M9.501,11.923c-.28,0-.548-.157-.677-.427-.179-.374-.021-.821,.354-1,.283-.135,.541-.318,.766-.543,1.096-1.096,1.096-2.863,.01-3.95l-2.175-2.175c-1.085-1.085-2.853-1.086-3.939,0-1.096,1.096-1.096,2.863-.01,3.949l.931,.931c.293,.293,.293,.768,0,1.061s-.768,.293-1.061,0l-.931-.931c-1.671-1.671-1.671-4.389,0-6.06,1.682-1.681,4.4-1.682,6.07-.01l2.175,2.175c1.671,1.671,1.671,4.39,0,6.061-.356,.356-.753,.637-1.19,.846-.104,.05-.214,.073-.323,.073Z"+ fill="currentColor"+ />+ </g>+ </svg>+ );+}diff --git a/apps/web/ui/layout/sidebar/icons/lines-y.tsx b/apps/web/ui/layout/sidebar/icons/lines-y.tsxnew file mode 100644index 0000000000..52f290bc04--- /dev/null+++ b/apps/web/ui/layout/sidebar/icons/lines-y.tsx@@ -0,0 +1,100 @@+import { cn } from "@dub/utils";+import { SVGProps, useEffect, useRef } from "react";++const SCALES = [0.3, 1.5, 1.75, 0.75];++export function LinesY({+ isActive,+ className,+ ...rest+}: { isActive: boolean } & SVGProps<SVGSVGElement>) {+ const line1Ref = useRef<SVGLineElement>(null);+ const line2Ref = useRef<SVGLineElement>(null);+ const line3Ref = useRef<SVGLineElement>(null);+ const line4Ref = useRef<SVGLineElement>(null);++ useEffect(() => {+ if (!isActive) return;++ [line1Ref, line2Ref, line3Ref, line4Ref].forEach((ref, idx) => {+ if (!ref.current) return;++ ref.current.animate(+ [+ { transform: "scaleY(1)" },+ { transform: `scaleY(${SCALES[idx]})` },+ { transform: "scaleY(1)" },+ ],+ {+ delay: idx * 50,+ duration: 400,+ },+ );+ });+ }, [isActive]);++ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ className={cn(+ "[&_line]:origin-bottom [&_line]:[transform-box:stroke-box]",+ className,+ )}+ {...rest}+ >+ <g fill="currentColor">+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="2.75"+ x2="2.75"+ y1="2.75"+ y2="15.25"+ ref={line1Ref}+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="7"+ x2="7"+ y1="7.75"+ y2="15.25"+ ref={line2Ref}+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="11"+ x2="11"+ y1="11.75"+ y2="15.25"+ ref={line3Ref}+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="15.25"+ x2="15.25"+ y1="4.75"+ y2="15.25"+ ref={line4Ref}+ />+ </g>+ </svg>+ );+}diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsxindex 08ebc49208..91f544f89c 100644--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx@@ -1,9 +1,11 @@import { Wordmark } from "@dub/ui";-import { CursorRays, Hyperlink, LinesY } from "@dub/ui/src";import { cn } from "@dub/utils";import Link from "next/link";import { useParams, usePathname } from "next/navigation";import { ReactNode, Suspense, useMemo } from "react";+import { CursorRays } from "./icons/cursor-rays";+import { Hyperlink } from "./icons/hyperlink";+import { LinesY } from "./icons/lines-y";import UserDropdown from "./user-dropdown";import { WorkspaceDropdown } from "./workspace-dropdown";@@ -43,12 +45,17 @@ export function SidebarNav({ toolContent }: { toolContent?: ReactNode }) {<Linkkey={href}href={href}+ data-active={isActive}className={cn(- "flex items-center gap-2.5 rounded-md p-2 text-sm text-neutral-600 transition-colors duration-75 hover:bg-neutral-200/50 active:bg-neutral-200/80",- isActive && "bg-neutral-200/50",+ "group flex items-center gap-2.5 rounded-md p-2 text-sm text-neutral-600 transition-[color,font-weight] duration-75 hover:bg-neutral-200/50 active:bg-neutral-200/80",+ isActive &&+ "bg-blue-100/50 font-medium text-blue-600 hover:bg-blue-100/80 active:bg-blue-100",)}>- <Icon className="size-4 text-gray-500" />+ <Icon+ className="size-4 text-neutral-500 transition-colors duration-75 group-data-[active=true]:text-blue-600"+ isActive={isActive}+ />{name}</Link>);