Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Animating the sidenav icons

Marcus Farrell23ccf6a5a673
diff --git a/apps/web/ui/layout/sidebar/help-button.tsx b/apps/web/ui/layout/sidebar/help-button.tsx
index e0c37d2076..fc52d575c1 100644
--- a/apps/web/ui/layout/sidebar/help-button.tsx
+++ b/apps/web/ui/layout/sidebar/help-button.tsx
@@ -1,15 +1,22 @@
-import { CircleQuestion } from "@dub/ui";
+"use client";
+
import { cn } from "@dub/utils";
+import { useState } from "react";
+import { CircleQuestion } from "./icons/circle-question";
-export async function HelpButton({
+export function HelpButton({
variant = "default",
}: {
variant?: "default" | "secondary";
}) {
+ const [hovered, setHovered] = useState(false);
+
return (
<a
href="https://dub.co/contact/support"
target="_blank"
+ onPointerEnter={() => setHovered(true)}
+ onPointerLeave={() => setHovered(false)}
className={cn(
"shrink-0 items-center justify-center rounded-lg",
variant === "secondary"
@@ -17,7 +24,11 @@ export async function HelpButton({
: "text-content-default hover:bg-bg-inverted/5 flex size-11",
)}
>
- <CircleQuestion className="size-5" strokeWidth={2} />
+ <CircleQuestion
+ className="size-5"
+ strokeWidth={2}
+ data-hovered={hovered}
+ />
</a>
);
}
diff --git a/apps/web/ui/layout/sidebar/icons/circle-question.tsx b/apps/web/ui/layout/sidebar/icons/circle-question.tsx
new file mode 100644
index 0000000000..9c416f6530
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/circle-question.tsx
@@ -0,0 +1,95 @@
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import {
+ clearStyles,
+ easeInOut,
+ easeOutBack,
+ useIconAnimation,
+} from "./use-icon-animation";
+
+const DURATION = 900;
+
+// Trace the hook of the question mark (0 → TRACE_END), then the dot lands
+// with a little bounce, carrying the momentum of the stroke (→ 1).
+const TRACE_END = 0.5;
+
+function frame(svg: SVGSVGElement, t: number) {
+ const hook = svg.querySelector<SVGPathElement>("[data-hook]")!;
+ const dot = svg.querySelector<SVGPathElement>("[data-dot]")!;
+
+ // pathLength="1" on the hook makes a dash of 1 cover it exactly, so the
+ // offset is the fraction still hidden. The dash is only applied while
+ // animating: leaving it on at rest nicks the end of the stroke.
+ hook.style.strokeDasharray = "1";
+
+ if (t < TRACE_END) {
+ hook.style.strokeDashoffset = String(1 - easeInOut(t / TRACE_END));
+ dot.style.opacity = "0";
+ dot.style.transform = "scale(0)";
+ } else {
+ hook.style.strokeDashoffset = "0";
+ const k = easeOutBack((t - TRACE_END) / (1 - TRACE_END));
+ // Overshoots past 1 on the way in, then settles: pushed down by the
+ // stroke arriving from above, scaled up past full size, and back.
+ dot.style.opacity = "1";
+ dot.style.transform = `translateY(${(k - 1) * 1.25}px) scale(${k})`;
+ }
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(svg.querySelectorAll("[data-hook]"), [
+ "strokeDasharray",
+ "strokeDashoffset",
+ ]);
+ clearStyles(svg.querySelectorAll("[data-dot]"), ["opacity", "transform"]);
+}
+
+export function CircleQuestion({
+ "data-hovered": hovered,
+ className,
+ ...rest
+}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
+ const play = useIconAnimation(DURATION, frame, reset);
+
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ ref={hovered ? play : null}
+ className={cn("overflow-visible", className)}
+ {...rest}
+ >
+ <g fill="currentColor">
+ <circle
+ cx="9"
+ cy="9"
+ fill="none"
+ r="7.25"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ data-hook
+ d="M6.925,6.619c.388-1.057,1.294-1.492,2.18-1.492,.895,0,1.818,.638,1.818,1.808,0,1.784-1.816,1.468-2.096,3.065"
+ pathLength={1}
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ data-dot
+ d="M8.791,13.567c-.552,0-1-.449-1-1s.448-1,1-1,1,.449,1,1-.448,1-1,1Z"
+ fill="currentColor"
+ stroke="none"
+ className="[transform-box:fill-box] [transform-origin:center]"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/icons/compass.tsx b/apps/web/ui/layout/sidebar/icons/compass.tsx
index 4561136d4b..9ab5feecbf 100644
--- a/apps/web/ui/layout/sidebar/icons/compass.tsx
+++ b/apps/web/ui/layout/sidebar/icons/compass.tsx
@@ -1,28 +1,49 @@
-import { SVGProps, useEffect, useRef } from "react";
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import {
+ clearStyles,
+ easeInOut,
+ easeOut,
+ useIconAnimation,
+} from "./use-icon-animation";
+
+const DURATION = 550;
+
+// Needle swings wide one way, back past center, then settles. Each segment
+// is [end offset (0..1), target angle in degrees, easing].
+const SWING: [number, number, (t: number) => number][] = [
+ [0.45, 48, easeInOut],
+ [0.8, -18, easeInOut],
+ [1, 0, easeOut],
+];
+
+function needleAngle(t: number) {
+ let from = 0;
+ let segStart = 0;
+ for (const [end, to, ease] of SWING) {
+ if (t < end)
+ return from + (to - from) * ease((t - segStart) / (end - segStart));
+ from = to;
+ segStart = end;
+ }
+ return 0;
+}
+
+function frame(svg: SVGSVGElement, t: number) {
+ svg.querySelector<SVGPathElement>("[data-needle]")!.style.transform =
+ `rotate(${needleAngle(t)}deg)`;
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(svg.querySelectorAll("[data-needle]"), ["transform"]);
+}
export function Compass({
"data-hovered": hovered,
+ className,
...rest
}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
- const ref = useRef<SVGPathElement>(null);
-
- useEffect(() => {
- if (!ref.current) return;
-
- if (hovered) {
- ref.current.animate(
- [
- { transform: "rotate(0)" },
- { transform: "rotate(20deg)" },
- { transform: "rotate(-20deg)" },
- { transform: "rotate(0)" },
- ],
- {
- duration: 300,
- },
- );
- }
- }, [hovered]);
+ const play = useIconAnimation(DURATION, frame, reset);
return (
<svg
@@ -30,11 +51,13 @@ export function Compass({
width="18"
viewBox="0 0 18 18"
xmlns="http://www.w3.org/2000/svg"
+ ref={hovered ? play : null}
+ className={cn("overflow-visible", className)}
{...rest}
>
<g fill="currentColor">
<path
- ref={ref}
+ data-needle
d="M12.536,5.464l-1.806,4.214c-.202,.472-.578,.848-1.05,1.05l-4.214,1.806,1.806-4.214c.202-.472,.578-.848,1.05-1.05l4.214-1.806Z"
fill="none"
stroke="currentColor"
diff --git a/apps/web/ui/layout/sidebar/icons/connected-dots4.tsx b/apps/web/ui/layout/sidebar/icons/connected-dots4.tsx
index 7100c9a547..ab91ee54bd 100644
--- a/apps/web/ui/layout/sidebar/icons/connected-dots4.tsx
+++ b/apps/web/ui/layout/sidebar/icons/connected-dots4.tsx
@@ -1,23 +1,39 @@
-import { SVGProps, useEffect, useRef } from "react";
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import { clearStyles, pulse, useIconAnimation } from "./use-icon-animation";
+
+// Each circle pulses for PULSE ms; the next one starts STAGGER ms after the
+// previous, clockwise from the top.
+const PULSE = 380;
+const STAGGER = 90;
+const DURATION = PULSE + STAGGER * 3;
+
+const GROW = 0.3;
+const STROKE_WIDTH = 1.5;
+
+const dots = (svg: SVGSVGElement) =>
+ svg.querySelectorAll<SVGCircleElement>("[data-dot]");
+
+function frame(svg: SVGSVGElement, t: number) {
+ const elapsed = t * DURATION;
+ dots(svg).forEach((dot, i) => {
+ const scale = 1 + GROW * pulse((elapsed - i * STAGGER) / PULSE);
+ dot.style.transform = `scale(${scale})`;
+ // Keep the stroke visually constant while the circle scales.
+ dot.style.strokeWidth = String(STROKE_WIDTH / scale);
+ });
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(dots(svg), ["transform", "strokeWidth"]);
+}
export function ConnectedDots4({
"data-hovered": hovered,
+ className,
...rest
}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
- const ref = useRef<SVGSVGElement>(null);
-
- useEffect(() => {
- if (!ref.current) return;
-
- if (hovered) {
- ref.current.animate(
- [{ transform: "rotate(0)" }, { transform: "rotate(180deg)" }],
- {
- duration: 300,
- },
- );
- }
- }, [hovered]);
+ const play = useIconAnimation(DURATION, frame, reset);
return (
<svg
@@ -25,93 +41,49 @@ export function ConnectedDots4({
width="18"
viewBox="0 0 18 18"
xmlns="http://www.w3.org/2000/svg"
- ref={ref}
+ ref={hovered ? play : null}
+ className={cn("overflow-visible", className)}
{...rest}
>
- <g fill="currentColor">
- <line
- fill="none"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
- x1="4.664"
- x2="7.586"
- y1="7.586"
- y2="4.664"
- />
- <line
- fill="none"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
- x1="10.414"
- x2="13.336"
- y1="4.664"
- y2="7.586"
- />
- <line
- fill="none"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
- x1="13.336"
- x2="10.414"
- y1="10.414"
- y2="13.336"
- />
- <line
- fill="none"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
- x1="7.586"
- x2="4.664"
- y1="13.336"
- y2="10.414"
- />
+ <g
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={STROKE_WIDTH}
+ >
+ <line x1="4.664" x2="7.586" y1="7.586" y2="4.664" />
+ <line x1="10.414" x2="13.336" y1="4.664" y2="7.586" />
+ <line x1="13.336" x2="10.414" y1="10.414" y2="13.336" />
+ <line x1="7.586" x2="4.664" y1="13.336" y2="10.414" />
+ {/* Each circle scales from the point nearest the icon's center. */}
<circle
+ data-dot
cx="9"
cy="3.25"
- fill="none"
r="2"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
+ className="[transform-box:fill-box] [transform-origin:50%_100%]"
/>
<circle
- cx="3.25"
+ data-dot
+ cx="14.75"
cy="9"
- fill="none"
r="2"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
+ className="[transform-box:fill-box] [transform-origin:0%_50%]"
/>
<circle
+ data-dot
cx="9"
cy="14.75"
- fill="none"
r="2"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
+ className="[transform-box:fill-box] [transform-origin:50%_0%]"
/>
<circle
- cx="14.75"
+ data-dot
+ cx="3.25"
cy="9"
- fill="none"
r="2"
- stroke="currentColor"
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth="1.5"
+ className="[transform-box:fill-box] [transform-origin:100%_50%]"
/>
</g>
</svg>
diff --git a/apps/web/ui/layout/sidebar/icons/gift.tsx b/apps/web/ui/layout/sidebar/icons/gift.tsx
new file mode 100644
index 0000000000..024b7cc352
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/gift.tsx
@@ -0,0 +1,80 @@
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import { clearStyles, easeInOut, useIconAnimation } from "./use-icon-animation";
+
+const DURATION = 850;
+
+// Lift to open (0 → LIFT_END), hold still (→ HOLD_END), then close (→ 1).
+const LIFT_END = 0.42;
+const HOLD_END = 0.66;
+
+// How far open (0..1) the gift is at a given point in the timeline.
+function openAmount(t: number) {
+ if (t < LIFT_END) return easeInOut(t / LIFT_END);
+ if (t < HOLD_END) return 1;
+ return 1 - easeInOut((t - HOLD_END) / (1 - HOLD_END));
+}
+
+// Lid (bow + ribbon band) lifts and tilts; box tilts the opposite way so the
+// two halves read as separating.
+const lidTransform = (k: number) =>
+ `translate(${-0.5 * k}px, ${-3.75 * k}px) rotate(${-16 * k}deg)`;
+const boxTransform = (k: number) =>
+ `translate(${0.5 * k}px, ${0.75 * k}px) rotate(${6 * k}deg)`;
+
+function frame(svg: SVGSVGElement, t: number) {
+ const k = openAmount(t);
+ svg.querySelector<SVGGElement>("[data-lid]")!.style.transform =
+ lidTransform(k);
+ svg.querySelector<SVGGElement>("[data-box]")!.style.transform =
+ boxTransform(k);
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(svg.querySelectorAll("[data-lid],[data-box]"), ["transform"]);
+}
+
+export function Gift({
+ "data-hovered": hovered,
+ className,
+ ...rest
+}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
+ const play = useIconAnimation(DURATION, frame, reset);
+
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ ref={hovered ? play : null}
+ className={cn("overflow-visible", className)}
+ {...rest}
+ >
+ <g
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ >
+ <g
+ data-box
+ className="[transform-box:fill-box] [transform-origin:0%_100%]"
+ >
+ <path d="M9 8.25V16.25" />
+ <path d="M14.25 14.25V8.25H3.75V14.25C3.75 15.355 4.645 16.25 5.75 16.25H12.25C13.355 16.25 14.25 15.355 14.25 14.25Z" />
+ </g>
+ <g
+ data-lid
+ className="[transform-box:fill-box] [transform-origin:100%_100%]"
+ >
+ <path d="M9 5.25V8.25" />
+ <path d="M3.75 3.5C3.75 2.534 4.534 1.75 5.5 1.75C8.089 1.75 9 5.25 9 5.25H5.5C4.534 5.25 3.75 4.466 3.75 3.5Z" />
+ <path d="M12.5 5.25H9C9 5.25 9.911 1.75 12.5 1.75C13.466 1.75 14.25 2.534 14.25 3.5C14.25 4.466 13.466 5.25 12.5 5.25Z" />
+ <path d="M15.25 5.25H2.75C2.19772 5.25 1.75 5.69772 1.75 6.25V7.25C1.75 7.80228 2.19772 8.25 2.75 8.25H15.25C15.8023 8.25 16.25 7.80228 16.25 7.25V6.25C16.25 5.69772 15.8023 5.25 15.25 5.25Z" />
+ </g>
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/icons/grid.tsx b/apps/web/ui/layout/sidebar/icons/grid.tsx
new file mode 100644
index 0000000000..bd0edd90ee
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/grid.tsx
@@ -0,0 +1,98 @@
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import { clearStyles, pulse, useIconAnimation } from "./use-icon-animation";
+
+// Each square pulses for PULSE ms; the next starts STAGGER ms after the
+// previous, clockwise from the top-left.
+const PULSE = 380;
+const STAGGER = 90;
+const DURATION = PULSE + STAGGER * 3;
+
+const GROW = 0.2;
+const STROKE_WIDTH = 1.5;
+
+const squares = (svg: SVGSVGElement) =>
+ svg.querySelectorAll<SVGRectElement>("[data-square]");
+
+function frame(svg: SVGSVGElement, t: number) {
+ const elapsed = t * DURATION;
+ squares(svg).forEach((square, i) => {
+ const scale = 1 + GROW * pulse((elapsed - i * STAGGER) / PULSE);
+ square.style.transform = `scale(${scale})`;
+ // Keep the stroke visually constant while the square scales.
+ square.style.strokeWidth = String(STROKE_WIDTH / scale);
+ });
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(squares(svg), ["transform", "strokeWidth"]);
+}
+
+export function GridIcon({
+ "data-hovered": hovered,
+ className,
+ ...rest
+}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
+ const play = useIconAnimation(DURATION, frame, reset);
+
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ ref={hovered ? play : null}
+ className={cn(
+ "overflow-visible [&_rect]:[transform-box:fill-box] [&_rect]:[transform-origin:center]",
+ className,
+ )}
+ {...rest}
+ >
+ <g
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={STROKE_WIDTH}
+ >
+ {/* DOM order is clockwise from the top-left. */}
+ <rect
+ data-square
+ height="4.5"
+ width="4.5"
+ rx="1"
+ ry="1"
+ x="2.75"
+ y="2.75"
+ />
+ <rect
+ data-square
+ height="4.5"
+ width="4.5"
+ rx="1"
+ ry="1"
+ x="10.75"
+ y="2.75"
+ />
+ <rect
+ data-square
+ height="4.5"
+ width="4.5"
+ rx="1"
+ ry="1"
+ x="10.75"
+ y="10.75"
+ />
+ <rect
+ data-square
+ height="4.5"
+ width="4.5"
+ rx="1"
+ ry="1"
+ x="2.75"
+ y="10.75"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/icons/money-bills2.tsx b/apps/web/ui/layout/sidebar/icons/money-bills2.tsx
new file mode 100644
index 0000000000..e8c0c53fbc
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/money-bills2.tsx
@@ -0,0 +1,129 @@
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import {
+ clearStyles,
+ easeOut,
+ easeOutBack,
+ segment,
+ useIconAnimation,
+} from "./use-icon-animation";
+
+const DURATION = 900;
+
+// Timeline (fractions of DURATION): the bill fades in while sliding down
+// into place, then the center circle, the two small dots, and finally the
+// top line pop in, each with a slight overshoot.
+const BILL = [0, 0.35] as const;
+const CIRCLE = [0.28, 0.58] as const;
+const DOTS: [number, number][] = [
+ [0.44, 0.7],
+ [0.52, 0.78],
+];
+const LINE = [0.66, 1] as const;
+
+const BILL_DROP = 2;
+
+function frame(svg: SVGSVGElement, t: number) {
+ const bill = svg.querySelector<SVGRectElement>("[data-bill]")!;
+ const circle = svg.querySelector<SVGCircleElement>("[data-circle]")!;
+ const dots = svg.querySelectorAll<SVGCircleElement>("[data-dot]");
+ const line = svg.querySelector<SVGLineElement>("[data-line]")!;
+
+ const b = easeOut(segment(t, ...BILL));
+ bill.style.opacity = String(b);
+ bill.style.transform = `translateY(${(b - 1) * BILL_DROP}px)`;
+
+ circle.style.transform = `scale(${easeOutBack(segment(t, ...CIRCLE))})`;
+
+ dots.forEach((dot, i) => {
+ dot.style.transform = `scale(${easeOutBack(segment(t, DOTS[i][0], DOTS[i][1]))})`;
+ });
+
+ line.style.transform = `scale(${easeOutBack(segment(t, ...LINE))})`;
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(svg.querySelectorAll("[data-bill]"), ["opacity", "transform"]);
+ clearStyles(svg.querySelectorAll("[data-circle],[data-dot],[data-line]"), [
+ "transform",
+ ]);
+}
+
+export function MoneyBills2({
+ "data-hovered": hovered,
+ className,
+ ...rest
+}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
+ const play = useIconAnimation(DURATION, frame, reset);
+
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ ref={hovered ? play : null}
+ className={cn(
+ "overflow-visible [&_*]:[transform-box:fill-box] [&_*]:[transform-origin:center]",
+ className,
+ )}
+ {...rest}
+ >
+ <g fill="currentColor">
+ <rect
+ data-bill
+ height="10.5"
+ width="14.5"
+ fill="none"
+ rx="2"
+ ry="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="1.75"
+ y="4.75"
+ />
+ <circle
+ data-circle
+ cx="9"
+ cy="10"
+ fill="none"
+ r="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <circle
+ data-dot
+ cx="4.25"
+ cy="10"
+ fill="currentColor"
+ r=".75"
+ stroke="none"
+ />
+ <circle
+ data-dot
+ cx="13.75"
+ cy="10"
+ fill="currentColor"
+ r=".75"
+ stroke="none"
+ />
+ <line
+ data-line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="3.75"
+ x2="14.25"
+ y1="1.75"
+ y2="1.75"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/icons/msgs.tsx b/apps/web/ui/layout/sidebar/icons/msgs.tsx
new file mode 100644
index 0000000000..2e610ea4f3
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/msgs.tsx
@@ -0,0 +1,70 @@
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import { clearStyles, useIconAnimation } from "./use-icon-animation";
+
+const DURATION = 600;
+
+// Each bubble wags around its pointed corner: a decaying sine, a couple of
+// cycles, the right bubble trailing the left slightly.
+const AMPLITUDE_DEG = 7;
+const CYCLES = 2;
+const RIGHT_DELAY = 0.12;
+
+function wag(t: number) {
+ if (t <= 0 || t >= 1) return 0;
+ const decay = (1 - t) ** 2;
+ return AMPLITUDE_DEG * decay * Math.sin(t * CYCLES * 2 * Math.PI);
+}
+
+function frame(svg: SVGSVGElement, t: number) {
+ const left = svg.querySelector<SVGPathElement>("[data-left]")!;
+ const right = svg.querySelector<SVGPathElement>("[data-right]")!;
+
+ left.style.transform = `rotate(${wag(t)}deg)`;
+ right.style.transform = `rotate(${-wag(t - RIGHT_DELAY)}deg)`;
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(svg.querySelectorAll("[data-left],[data-right]"), ["transform"]);
+}
+
+export function Msgs({
+ "data-hovered": hovered,
+ className,
+ ...rest
+}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
+ const play = useIconAnimation(DURATION, frame, reset);
+
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ ref={hovered ? play : null}
+ className={cn("overflow-visible", className)}
+ {...rest}
+ >
+ <g
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ >
+ {/* Left bubble: its tail points to the bottom-left. */}
+ <path
+ data-left
+ d="M12.337,4.767c-1.095-1.806-3.074-3.017-5.34-3.017C3.547,1.75,.75,4.547,.75,7.998c0,1.136,.308,2.199,.839,3.117,.37,.695-.045,2.337-.839,3.13,1.077,.058,2.497-.428,3.13-.839,.421,.243,1.09,.566,1.964,.731,.112,.021,.232,.017,.346,.032"
+ className="[transform-box:fill-box] [transform-origin:0%_100%]"
+ />
+ {/* Right bubble: its tail points to the bottom-right. */}
+ <path
+ data-right
+ d="M12.75,7.246c2.485,0,4.5,2.015,4.5,4.5,0,.819-.222,1.584-.604,2.246-.267,.5,.033,1.683,.604,2.255-.776,.042-1.798-.309-2.255-.604-.303,.175-.785,.407-1.415,.527-.269,.051-.547,.078-.831,.078-2.486,0-4.5-2.015-4.5-4.5,0-2.486,2.015-4.5,4.5-4.5Z"
+ className="[transform-box:fill-box] [transform-origin:100%_100%]"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/icons/square-user-sparkle2.tsx b/apps/web/ui/layout/sidebar/icons/square-user-sparkle2.tsx
new file mode 100644
index 0000000000..f9259d8df8
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/square-user-sparkle2.tsx
@@ -0,0 +1,102 @@
+import { cn } from "@dub/utils";
+import { SVGProps } from "react";
+import {
+ clearStyles,
+ easeOut,
+ easeOutBack,
+ segment,
+ useIconAnimation,
+} from "./use-icon-animation";
+
+const DURATION = 900;
+
+// Timeline (fractions of DURATION): the body rises in, the head drops in
+// with a small bounce, and the sparkle pops in last.
+const BODY = [0, 0.38] as const;
+const HEAD = [0.18, 0.62] as const;
+const STAR = [0.62, 1] as const;
+
+function frame(svg: SVGSVGElement, t: number) {
+ const body = svg.querySelector<SVGPathElement>("[data-body]")!;
+ const head = svg.querySelector<SVGCircleElement>("[data-head]")!;
+ const star = svg.querySelector<SVGPathElement>("[data-star]")!;
+
+ const b = easeOut(segment(t, ...BODY));
+ body.style.opacity = String(b);
+ body.style.transform = `scaleY(${b})`;
+
+ // Overshoots past 1, so the head lands slightly low and springs back up.
+ const h = easeOutBack(segment(t, ...HEAD));
+ head.style.opacity = h > 0 ? "1" : "0";
+ head.style.transform = `translateY(${(h - 1) * 1.5}px) scale(${h})`;
+
+ const s = easeOutBack(segment(t, ...STAR));
+ star.style.transform = `scale(${s})`;
+}
+
+function reset(svg: SVGSVGElement) {
+ clearStyles(svg.querySelectorAll("[data-body],[data-head],[data-star]"), [
+ "opacity",
+ "transform",
+ ]);
+}
+
+export function SquareUserSparkle2({
+ "data-hovered": hovered,
+ className,
+ ...rest
+}: { "data-hovered"?: boolean } & SVGProps<SVGSVGElement>) {
+ const play = useIconAnimation(DURATION, frame, reset);
+
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ ref={hovered ? play : null}
+ className={cn("overflow-visible", className)}
+ {...rest}
+ >
+ <g fill="currentColor">
+ <path
+ d="M10.266,2.75H4.75c-1.105,0-2,.896-2,2V13.25c0,1.104,.895,2,2,2H13.25c1.105,0,2-.896,2-2V7.688"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ data-body
+ d="M5.126,15.25c.444-1.725,2.01-3,3.874-3s3.43,1.275,3.874,3"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ className="[transform-box:fill-box] [transform-origin:50%_100%]"
+ />
+ <circle
+ data-head
+ cx="9"
+ cy="7.75"
+ fill="none"
+ r="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ className="[transform-box:fill-box] [transform-origin:center]"
+ />
+ <path
+ data-star
+ d="M17.589,2.388l-1.515-.506-.505-1.515c-.164-.49-.975-.49-1.139,0l-.505,1.515-1.515,.506c-.245,.081-.41,.311-.41,.569s.165,.488,.41,.569l1.515,.506,.505,1.515c.082,.245,.312,.41,.57,.41s.487-.165,.57-.41l.505-1.515,1.515-.506c.245-.081,.41-.311,.41-.569s-.165-.487-.41-.569h0Z"
+ fill="currentColor"
+ stroke="none"
+ className="[transform-box:fill-box] [transform-origin:center]"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/icons/use-icon-animation.ts b/apps/web/ui/layout/sidebar/icons/use-icon-animation.ts
new file mode 100644
index 0000000000..3bd2689bd1
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/icons/use-icon-animation.ts
@@ -0,0 +1,81 @@
+import { cubicBezier } from "motion";
+import { useCallback, useRef } from "react";
+
+export const easeInOut = cubicBezier(0.645, 0.045, 0.355, 1);
+export const easeOut = cubicBezier(0.215, 0.61, 0.355, 1);
+export const easeOutBack = cubicBezier(0.34, 1.56, 0.64, 1);
+
+/** 0 → 1 → 0 over [0, 1], eased both ways. 0 outside the window. */
+export function pulse(t: number) {
+ if (t <= 0 || t >= 1) return 0;
+ return t < 0.5 ? easeInOut(t * 2) : easeInOut((1 - t) * 2);
+}
+
+/** Progress of a sub-window [from, to] of the timeline, clamped to [0, 1]. */
+export function segment(t: number, from: number, to: number) {
+ return Math.min(Math.max((t - from) / (to - from), 0), 1);
+}
+
+export function prefersReducedMotion() {
+ return (
+ typeof window !== "undefined" &&
+ window.matchMedia("(prefers-reduced-motion: reduce)").matches
+ );
+}
+
+/**
+ * Drives a hover animation for a sidebar icon with requestAnimationFrame.
+ *
+ * Returns a ref callback: attach it to the `<svg>` only while hovered
+ * (`ref={hovered ? play : null}`) so React invokes it on each hover start.
+ * A hover that lands while a run is in progress is ignored, so quickly
+ * hovering out and back in doesn't restart the animation midway.
+ *
+ * Styles are set directly per frame rather than via the Web Animations API,
+ * which promotes the animated elements to a compositor layer and softens
+ * their strokes. `frame` receives progress in [0, 1); `reset` runs once the
+ * animation finishes and must clear every inline style `frame` set, so the
+ * rest state renders exactly like the static icon.
+ */
+export function useIconAnimation(
+ duration: number,
+ frame: (svg: SVGSVGElement, t: number) => void,
+ reset: (svg: SVGSVGElement) => void,
+) {
+ const frameRef = useRef<number | null>(null);
+
+ return useCallback(
+ (svg: SVGSVGElement | null) => {
+ if (!svg || prefersReducedMotion()) return;
+ if (frameRef.current !== null) return;
+
+ const start = performance.now();
+
+ const tick = (now: number) => {
+ const t = (now - start) / duration;
+
+ if (t >= 1 || !svg.isConnected) {
+ reset(svg);
+ frameRef.current = null;
+ return;
+ }
+
+ frame(svg, t);
+ frameRef.current = requestAnimationFrame(tick);
+ };
+
+ frameRef.current = requestAnimationFrame(tick);
+ },
+ [duration, frame, reset],
+ );
+}
+
+/** Clears every inline style previously set on the given elements. */
+export function clearStyles(
+ elements: Iterable<SVGElement>,
+ props: (keyof CSSStyleDeclaration & string)[],
+) {
+ for (const el of elements) {
+ for (const prop of props) el.style[prop as any] = "";
+ }
+}
diff --git a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
index cb3630207e..00013de811 100644
--- a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
@@ -16,14 +16,9 @@ import {
ColorPalette2,
Gauge6,
Gear2,
- Gift,
- GridIcon,
- MoneyBills2,
- Msgs,
Nodes4,
ShieldCheck,
Shop,
- SquareUserSparkle2,
Trophy,
UserCheck,
UserPlus,
@@ -33,10 +28,15 @@ import {
import { cn } from "@dub/utils";
import Link from "next/link";
import { useParams, usePathname } from "next/navigation";
-import { ReactNode, useMemo } from "react";
+import { ReactNode, useMemo, useState } from "react";
import { CursorRays } from "./icons/cursor-rays";
+import { Gift } from "./icons/gift";
+import { GridIcon } from "./icons/grid";
import { Hyperlink } from "./icons/hyperlink";
import { LinesY } from "./icons/lines-y";
+import { MoneyBills2 } from "./icons/money-bills2";
+import { Msgs } from "./icons/msgs";
+import { SquareUserSparkle2 } from "./icons/square-user-sparkle2";
import { User } from "./icons/user";
import { PartnerProgramDropdown } from "./partner-program-dropdown";
import { PayoutStats } from "./payout-stats";
@@ -405,17 +405,20 @@ export function PartnersSidebarNav({
const referralsActive =
pathname === "/referrals" || pathname.startsWith("/referrals/");
+ const [referralsHovered, setReferralsHovered] = useState(false);
const composedToolContent = (
<div className="flex flex-col items-center gap-3">
<Link
href="/referrals"
+ onPointerEnter={() => setReferralsHovered(true)}
+ onPointerLeave={() => setReferralsHovered(false)}
className={cn(
"text-content-default flex size-11 shrink-0 items-center justify-center rounded-lg",
referralsActive ? "bg-white" : "hover:bg-bg-inverted/5",
)}
>
- <Gift className="size-5" />
+ <Gift className="size-5" data-hovered={referralsHovered} />
</Link>
{toolContent}
</div>
diff --git a/apps/web/ui/layout/sidebar/refer-button.tsx b/apps/web/ui/layout/sidebar/refer-button.tsx
index a80d65c848..2d68b4ca43 100644
--- a/apps/web/ui/layout/sidebar/refer-button.tsx
+++ b/apps/web/ui/layout/sidebar/refer-button.tsx
@@ -1,12 +1,12 @@
"use client";
import { useLocalStorage, useMediaQuery } from "@dub/ui";
-import { Gift } from "@dub/ui/icons";
import { cn } from "@dub/utils/src";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { AffiliateProgramPopup } from "./affiliate-program-popup";
+import { Gift } from "./icons/gift";
export function ReferButton({
affiliatePopupEnabled = false,
@@ -15,18 +15,21 @@ export function ReferButton({
}) {
const { width } = useMediaQuery();
const [linkRef, setLinkRef] = useState<HTMLAnchorElement | null>(null);
+ const [hovered, setHovered] = useState(false);
return (
<>
<Link
ref={affiliatePopupEnabled ? setLinkRef : undefined}
href="/account/settings/referrals"
+ onPointerEnter={() => setHovered(true)}
+ onPointerLeave={() => setHovered(false)}
className={cn(
"animate-fade-in hover:bg-bg-inverted/5 active:bg-bg-inverted/10 flex size-11 shrink-0 items-center justify-center rounded-lg transition-colors duration-150",
"outline-none focus-visible:ring-2 focus-visible:ring-black/50",
)}
>
- <Gift className="text-content-default size-5" />
+ <Gift className="text-content-default size-5" data-hovered={hovered} />
</Link>
{affiliatePopupEnabled && width && width >= 768 && (
<AffiliateProgramPopupWrapper referenceElement={linkRef} />