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.

Add scroll fade to workspace dropdown

Tim Wilson04b193c15782
diff --git a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
index 65de3d160a..dc7b9a24ec 100644
--- a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
@@ -3,14 +3,19 @@
import useWorkspaces from "@/lib/swr/use-workspaces";
import { PlanProps, WorkspaceProps } from "@/lib/types";
import { ModalContext } from "@/ui/modals/modal-provider";
-import { BlurImage, getUserAvatarUrl, Popover } from "@dub/ui";
+import {
+ BlurImage,
+ getUserAvatarUrl,
+ Popover,
+ useScrollProgress,
+} from "@dub/ui";
import { Book2, Check2, Gear, Plus } from "@dub/ui/src/icons";
import { cn, DICEBEAR_AVATAR_URL } from "@dub/utils";
import { ChevronsUpDown } from "lucide-react";
import { useSession } from "next-auth/react";
import Link from "next/link";
import { useParams, usePathname } from "next/navigation";
-import { useCallback, useContext, useMemo, useState } from "react";
+import { useCallback, useContext, useMemo, useRef, useState } from "react";
export function WorkspaceDropdown() {
const { workspaces } = useWorkspaces();
@@ -141,6 +146,9 @@ function WorkspaceList({
};
const pathname = usePathname();
+ const scrollRef = useRef<HTMLDivElement>(null);
+ const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
+
const links = useMemo(
() => [
{ name: "Settings", icon: Gear, href: `/${slug}/settings` },
@@ -167,95 +175,108 @@ function WorkspaceList({
[domain, key, pathname, selected.slug],
);
+ console.log(scrollProgress);
+
return (
- <div className="relative max-h-72 w-full space-y-0.5 overflow-auto rounded-lg bg-white text-base sm:w-64 sm:text-sm">
- <div className="flex flex-col gap-0.5 border-b border-neutral-200 p-2">
- {links.map(({ name, icon: Icon, href, target }) => (
- <Link
- key={name}
- href={href}
- target={target}
- className="flex items-center gap-x-4 rounded-md px-2.5 py-2 transition-all duration-75 hover:bg-neutral-200/50 active:bg-neutral-200/80"
- onClick={() => setOpenPopover(false)}
- >
- <Icon className="size-4 text-neutral-500" />
- <span className="block truncate text-neutral-600">{name}</span>
- </Link>
- ))}
- </div>
- <div className="p-2">
- <div className="flex items-center justify-between pb-1">
- <p className="px-1 text-xs font-medium text-neutral-500">
- Workspaces
- </p>
- {workspaces.length > 0 && (
+ <div className="relative w-full">
+ <div
+ ref={scrollRef}
+ onScroll={updateScrollProgress}
+ className="relative max-h-80 w-full space-y-0.5 overflow-auto rounded-lg bg-white text-base sm:w-64 sm:text-sm"
+ >
+ <div className="flex flex-col gap-0.5 border-b border-neutral-200 p-2">
+ {links.map(({ name, icon: Icon, href, target }) => (
<Link
- href="/workspaces"
+ key={name}
+ href={href}
+ target={target}
+ className="flex items-center gap-x-4 rounded-md px-2.5 py-2 transition-all duration-75 hover:bg-neutral-200/50 active:bg-neutral-200/80"
onClick={() => setOpenPopover(false)}
- className="rounded-md px-2 py-1 text-xs text-neutral-500 transition-colors duration-75 hover:bg-neutral-200/50 hover:text-neutral-700 active:bg-neutral-200/80"
>
- View All
+ <Icon className="size-4 text-neutral-500" />
+ <span className="block truncate text-neutral-600">{name}</span>
</Link>
- )}
+ ))}
</div>
- <div className="flex flex-col gap-0.5">
- {workspaces.map(({ id, name, slug, logo, plan }) => {
- const isActive = selected.slug === slug;
- return (
+ <div className="p-2">
+ <div className="flex items-center justify-between pb-1">
+ <p className="px-1 text-xs font-medium text-neutral-500">
+ Workspaces
+ </p>
+ {workspaces.length > 0 && (
<Link
- key={slug}
- className={cn(
- "relative flex w-full items-center gap-x-2 rounded-md px-2 py-1.5 transition-all duration-75",
- "hover:bg-neutral-200/50 active:bg-neutral-200/80",
- isActive && "bg-neutral-200/50",
- )}
- href={href(slug)}
- shallow={false}
+ href="/workspaces"
onClick={() => setOpenPopover(false)}
+ className="rounded-md px-2 py-1 text-xs text-neutral-500 transition-colors duration-75 hover:bg-neutral-200/50 hover:text-neutral-700 active:bg-neutral-200/80"
>
- <BlurImage
- src={logo || `${DICEBEAR_AVATAR_URL}${name}`}
- width={28}
- height={28}
- alt={id}
- className="size-7 shrink-0 overflow-hidden rounded-full"
- />
- <div>
- <span className="block truncate text-sm leading-5 text-neutral-900 sm:max-w-[140px]">
- {name}
- </span>
- {slug !== "/" && (
- <div
- className={cn(
- "truncate text-xs capitalize leading-tight",
- getPlanColor(plan),
- )}
- >
- {plan}
- </div>
- )}
- </div>
- {selected.slug === slug ? (
- <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
- <Check2 className="size-4" aria-hidden="true" />
- </span>
- ) : null}
+ View All
</Link>
- );
- })}
- <button
- key="add"
- onClick={() => {
- setOpenPopover(false);
- setShowAddWorkspaceModal(true);
- }}
- className="group flex w-full cursor-pointer items-center gap-x-2 rounded-md p-2 text-neutral-700 transition-all duration-75 hover:bg-neutral-200/50 active:bg-neutral-200/80"
- >
- <Plus className="mx-1.5 size-4 text-neutral-500" />
- <span className="block truncate">Create new workspace</span>
- </button>
+ )}
+ </div>
+ <div className="flex flex-col gap-0.5">
+ {workspaces.map(({ id, name, slug, logo, plan }) => {
+ const isActive = selected.slug === slug;
+ return (
+ <Link
+ key={slug}
+ className={cn(
+ "relative flex w-full items-center gap-x-2 rounded-md px-2 py-1.5 transition-all duration-75",
+ "hover:bg-neutral-200/50 active:bg-neutral-200/80",
+ isActive && "bg-neutral-200/50",
+ )}
+ href={href(slug)}
+ shallow={false}
+ onClick={() => setOpenPopover(false)}
+ >
+ <BlurImage
+ src={logo || `${DICEBEAR_AVATAR_URL}${name}`}
+ width={28}
+ height={28}
+ alt={id}
+ className="size-7 shrink-0 overflow-hidden rounded-full"
+ />
+ <div>
+ <span className="block truncate text-sm leading-5 text-neutral-900 sm:max-w-[140px]">
+ {name}
+ </span>
+ {slug !== "/" && (
+ <div
+ className={cn(
+ "truncate text-xs capitalize leading-tight",
+ getPlanColor(plan),
+ )}
+ >
+ {plan}
+ </div>
+ )}
+ </div>
+ {selected.slug === slug ? (
+ <span className="absolute inset-y-0 right-0 flex items-center pr-3 text-black">
+ <Check2 className="size-4" aria-hidden="true" />
+ </span>
+ ) : null}
+ </Link>
+ );
+ })}
+ <button
+ key="add"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowAddWorkspaceModal(true);
+ }}
+ className="group flex w-full cursor-pointer items-center gap-x-2 rounded-md p-2 text-neutral-700 transition-all duration-75 hover:bg-neutral-200/50 active:bg-neutral-200/80"
+ >
+ <Plus className="mx-1.5 size-4 text-neutral-500" />
+ <span className="block truncate">Create new workspace</span>
+ </button>
+ </div>
</div>
</div>
+ {/* Bottom scroll fade */}
+ <div
+ className="pointer-events-none absolute -bottom-px left-0 h-16 w-full rounded-b-lg bg-gradient-to-t from-white sm:bottom-0"
+ style={{ opacity: 1 - Math.pow(scrollProgress, 2) }}
+ />
</div>
);
}