录制演示
源码
/* App shell — free block published by UI Stacks (public page source).
Kept verbatim: the author publishes this block free, in full, at https://uistacks.dev/blocks/app-shell
See replica/README.md for provenance. */
"use client";
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { ChevronRight, CircleDollarSign, Home, Inbox, Menu, Plus, Search, X, type LucideIcon } from "lucide-react";
import { Avatar } from "../components/avatar";
import { StatCard } from "../components/stat-card";
import { Button } from "../components/button";
/* ── Sample data: replace with your own ─────────────────────── */
const APP = { workspace: "UI Stacks", name: "Stacks CRM" };
const ME = { name: "Olivia Bennett", role: "Operations lead", src: "/avatars/olivia-bennett.png" };
const PEOPLE = {
emma: { name: "Emma Collins", src: "/avatars/emma-collins.png" },
jamal: { name: "Jamal Carter", src: "/avatars/jamal-carter.png" },
marcus: { name: "Marcus Reed", src: "/avatars/marcus-reed.png" },
sofia: { name: "Sofia Alvarez", src: "/avatars/sofia-alvarez.png" },
};
type Person = keyof typeof PEOPLE;
type Stage = "Lead" | "Qualified" | "Proposal";
/** The chance a deal in each stage closes; the weighted forecast is value × odds. */
const ODDS: Record<Stage, number> = { Lead: 0.1, Qualified: 0.3, Proposal: 0.6 };
type Deal = { id: string; company: string; topic: string; stage: Stage; value: number; close: string; owner: Person };
/** Open deals: $246k in all, $96.8k weighted. */
const DEALS: Deal[] = [
{ id: "DEAL-207", company: "Notion", topic: "Annual café plan", stage: "Proposal", value: 96_000, close: "Nov 12", owner: "jamal" },
{ id: "DEAL-218", company: "Uber", topic: "Driver hub coffee carts", stage: "Qualified", value: 54_000, close: "Nov 18", owner: "marcus" },
{ id: "DEAL-203", company: "Stripe", topic: "Launch week pop-up", stage: "Proposal", value: 18_000, close: "Nov 20", owner: "sofia" },
{ id: "DEAL-231", company: "Netflix", topic: "Office coffee, 3 floors", stage: "Lead", value: 38_000, close: "Nov 21", owner: "emma" },
{ id: "DEAL-214", company: "Figma", topic: "Weekly team breakfast", stage: "Qualified", value: 22_000, close: "Nov 25", owner: "emma" },
{ id: "DEAL-229", company: "Airbnb", topic: "Host summit catering", stage: "Lead", value: 12_000, close: "Dec 2", owner: "jamal" },
{ id: "DEAL-226", company: "Spotify", topic: "Holiday party drinks", stage: "Lead", value: 6000, close: "Dec 9", owner: "sofia" },
];
/** What New deal adds, in turn. */
const NEW_DEALS: Omit<Deal, "id">[] = [
{ company: "Zoom", topic: "Lobby coffee bar", stage: "Lead", value: 15_000, close: "Dec 4", owner: "sofia" },
{ company: "Dropbox", topic: "Friday pastries", stage: "Lead", value: 8000, close: "Dec 9", owner: "sofia" },
{ company: "Linear", topic: "Team offsite drinks", stage: "Lead", value: 11_000, close: "Dec 11", owner: "sofia" },
];
type Mention = { id: string; who: Person; deal: string; text: string; time: string };
const MENTIONS: Mention[] = [
{ id: "m1", who: "jamal", deal: "DEAL-207", text: "Notion wants to sign before Thanksgiving. Can you approve a 5% renewal discount?", time: "12m" },
{ id: "m2", who: "emma", deal: "DEAL-214", text: "Figma asked for oat milk on every floor, so I updated the quote.", time: "48m" },
{ id: "m3", who: "marcus", deal: "DEAL-218", text: "Uber confirmed four carts for the driver hubs. Sending the proposal today.", time: "2h" },
];
/** Week labels for the stat sparklines: the 12 weeks up to Nov 9, 2026. */
const WEEKS = ["Aug 24", "Aug 31", "Sep 7", "Sep 14", "Sep 21", "Sep 28", "Oct 5", "Oct 12", "Oct 19", "Oct 26", "Nov 2", "Nov 9"];
/* ── Company logos (real brand marks; trademarks belong to their owners) ── */
/** Logos that fill the whole tile, like their app icons. */
const LOGO_FULL: Record<string, ReactNode> = {
Uber: (
<svg viewBox="0 0 400 400" aria-hidden className="size-full">
<path d="M0 0h400v400H0z" />
<path d="M109.9 173.9v30.3c0 10.1-4.5 14.3-15 14.3s-15-4.2-15-14.3v-31.6h-10c-.9 0-1.3.4-1.3 1.3v30.7c0 16.9 10.8 22.8 26.4 22.8 15.6 0 26.4-5.9 26.4-22.8v-32.1h-10.1c-.9.1-1.4.5-1.4 1.4z" fill="#fff" />
<path d="M256.4 181.3c.8 0 1.2-.3 1.5-.9l2.9-7.2c.2-.4 0-.7-.4-.7h-40.7c-3.8 0-5.2 1.2-5.2 3.8v47c0 2.2 1.1 3.2 4 3.2h37.9c.8 0 1.2-.3 1.5-.9l2.9-7.2c.2-.4 0-.7-.4-.7h-34.7v-9.6c0-3.3 1.8-4.8 6.7-4.8h15.1c.8 0 1.2-.3 1.5-.9l2.8-7c.2-.4 0-.7-.4-.7h-25.7v-13.5h30.7z" fill="#fff" />
<path d="M184.7 198.1c4.4-2.3 6.2-6.7 6.2-11.8 0-11.9-9.7-13.7-19.8-13.7h-23c-3.8 0-5.2 1.2-5.2 3.8v47c0 2.2 1.1 3.2 4 3.2h28.3c10.7 0 18.3-4.1 18.3-14.9.1-6.6-2.7-12-8.8-13.6zm-30.5-16.9H172c6 0 7.6 2.2 7.6 6.9s-1.7 6.9-7.6 6.9h-17.8v-13.8zm19.9 36.6h-19.9v-9.9c0-3.3 1.8-4.8 6.7-4.8h13.2c6.3 0 8.1 2.4 8.1 7.4.1 5-1.7 7.3-8.1 7.3z" fill="#fff" />
<path d="M331.3 225.6l-12.1-20.8c6-1.5 10.9-5.5 10.9-15.6 0-13.1-8.1-16.6-21.5-16.6h-23.1c-3.8 0-5.2 1.2-5.2 3.8v48.9c0 .9.4 1.3 1.3 1.3h9.9v-15.7c0-3.3 1.8-4.8 6.7-4.8h9.9l10.9 19.7c.3.6.7.9 1.5.9h10.3c.7-.2.7-.8.5-1.1zm-21.1-28h-18.8v-16.3h18.8c7 0 8.6 2.7 8.6 8.2 0 5.4-1.6 8.1-8.6 8.1z" fill="#fff" />
</svg>
),
Stripe: (
<svg viewBox="0 0 24 24" aria-hidden className="size-full bg-[#635bff] p-[22%]" fill="#fff">
<path d="M13.976 9.15c-2.172-.806-3.356-1.426-3.356-2.409 0-.831.683-1.305 1.901-1.305 2.227 0 4.515.858 6.09 1.631l.89-5.494C18.252.975 15.697 0 12.165 0 9.667 0 7.589.654 6.104 1.872 4.56 3.147 3.757 4.992 3.757 7.218c0 4.039 2.467 5.76 6.476 7.219 2.585.92 3.445 1.574 3.445 2.583 0 .98-.84 1.545-2.354 1.545-1.875 0-4.965-.921-6.99-2.109l-.9 5.555C5.175 22.99 8.385 24 11.714 24c2.641 0 4.843-.624 6.328-1.813 1.664-1.305 2.525-3.236 2.525-5.732 0-4.128-2.524-5.851-6.594-7.305h.003z" />
</svg>
),
};
/** Logos centred on a white tile. */
const LOGO_MARK: Record<string, ReactNode> = {
Notion: (
<svg viewBox="13.38 3.2 485.44 505.7" aria-hidden className="size-full">
<path d="m186.84 13.95c-79.06 5.85-146.27 11.23-149.43 11.86-8.86 1.58-16.92 7.59-20.71 15.5l-3.32 6.96.32 165.88.47 165.88 5.06 10.28c2.85 5.69 22.14 32.26 43.17 59.61 41.59 53.92 44.59 56.93 60.4 58.51 4.59.47 39.06-1.11 76.38-3.32 37.48-2.37 97.56-6.01 133.62-8.06 154.01-9.35 146.1-8.56 154.95-16.15 11.07-9.17 10.28 5.85 10.75-195.76.32-170.94.16-182.16-2.37-187.38-3-5.85-8.38-9.96-78.59-59.3-46.96-32.89-50.28-34.63-71.32-34.95-8.69-.31-80.48 4.43-159.38 10.44z" fill="#fff" />
<path d="m186.84 13.95c-79.06 5.85-146.27 11.23-149.43 11.86-8.86 1.58-16.92 7.59-20.71 15.5l-3.32 6.96.32 165.88.47 165.88 5.06 10.28c2.85 5.69 22.14 32.26 43.17 59.61 41.59 53.92 44.59 56.93 60.4 58.51 4.59.47 39.06-1.11 76.38-3.32 37.48-2.37 97.56-6.01 133.62-8.06 154.01-9.35 146.1-8.56 154.95-16.15 11.07-9.17 10.28 5.85 10.75-195.76.32-170.94.16-182.16-2.37-187.38-3-5.85-8.38-9.96-78.59-59.3-46.96-32.89-50.28-34.63-71.32-34.95-8.69-.31-80.48 4.43-159.38 10.44zm177.73 21.66c6.64 3 55.19 36.84 62.3 43.33 1.9 1.9 2.53 3.48 1.58 4.43-2.21 1.9-302.66 19.77-311.35 18.5-3.95-.63-9.8-3-13.12-5.22-13.76-9.33-47.91-37.32-47.91-39.37 0-5.38-1.11-5.38 132.83-15.02 25.62-1.74 67.68-4.9 93.3-6.96 55.49-4.43 72.1-4.27 82.37.31zm95.51 86.5c2.21 2.21 4.11 6.48 4.74 10.59.47 3.8.79 74.64.47 157.18-.47 141.68-.63 150.54-3.32 154.65-1.58 2.53-4.74 5.22-7.12 6.01-6.63 2.69-321.46 20.56-327.94 18.66-3-.79-7.12-3.32-9.33-5.53l-3.8-4.11-.47-152.75c-.32-107.21 0-154.65 1.27-158.92.95-3.16 3.32-6.96 5.38-8.22 2.85-1.9 21.51-3.48 85.71-7.27 45.07-2.53 114.8-6.8 154.81-9.17 95.17-5.86 94.86-5.86 99.6-1.12z" fill="#000" />
<path d="m375.48 174.45c-17.08 1.11-32.26 2.69-34 3.64-5.22 2.69-8.38 7.12-9.01 12.18-.47 5.22 1.11 5.85 18.18 7.91l7.43.95v67.52c0 40.16-.63 66.73-1.42 65.94-.79-.95-23.24-35.1-49.97-75.9-26.72-40.95-48.86-74.64-49.18-74.95-.32-.32-17.71.63-38.58 2.06-25.62 1.74-39.69 3.32-42.54 4.9-4.59 2.37-9.65 10.75-9.65 16.29 0 3.32 6.01 5.06 18.66 5.06h6.64v194.18l-10.75 3.32c-8.38 2.53-11.23 4.11-12.65 7.27-2.53 5.38-2.37 10.28.16 10.28.95 0 18.82-1.11 39.37-2.37 40.64-2.37 45.22-3.48 49.49-11.86 1.27-2.53 2.37-5.22 2.37-6.01 0-.63-5.53-2.53-12.18-4.11-6.8-1.58-13.6-3.16-15.02-3.48-2.69-.79-2.85-5.69-2.85-73.69v-72.9l48.07 75.43c50.44 79.06 56.77 88.08 64.52 92.03 9.65 5.06 34.16 1.58 46.49-6.48l3.8-2.37.32-107.84.47-108 8.38-1.58c9.96-1.9 14.55-6.48 14.55-14.39 0-5.06-.32-5.38-5.06-5.22-2.83.13-19.12 1.08-36.04 2.19z" fill="#000" />
</svg>
),
Figma: (
<svg viewBox="1.466 2.199 285.068 427.602" fill="none" aria-hidden className="size-full">
<path d="M144 216c0-39.359 31.907-71.267 71.267-71.267 39.359 0 71.267 31.908 71.267 71.267 0 39.36-31.908 71.267-71.267 71.267C175.907 287.267 144 255.36 144 216z" fill="#1abcfe" />
<path d="M1.466 358.534c0-39.359 31.907-71.267 71.267-71.267H144v71.267c0 39.36-31.907 71.267-71.267 71.267S1.466 397.894 1.466 358.534z" fill="#0acf83" />
<path d="M144 2.2v142.533h71.267c39.36 0 71.267-31.907 71.267-71.267S254.627 2.2 215.267 2.2z" fill="#ff7262" />
<path d="M1.466 73.466c0 39.36 31.907 71.267 71.267 71.267H144V2.199H72.733c-39.36 0-71.267 31.908-71.267 71.267z" fill="#f24e1e" />
<path d="M1.466 216c0 39.36 31.907 71.267 71.267 71.267H144V144.733H72.733c-39.36 0-71.267 31.908-71.267 71.267z" fill="#a259ff" />
</svg>
),
Netflix: (
<svg viewBox="0 0 24 24" aria-hidden className="size-full" fill="#e50914">
<path d="M5.398 0v.006c3.028 8.556 5.37 15.175 8.348 23.596 2.344.058 4.85.398 4.854.398-2.8-7.924-5.923-16.747-8.487-24zm8.489 0v9.63L18.6 22.951c-.043-7.86-.004-15.913.002-22.95zM5.398 1.05V24c1.873-.225 2.81-.312 4.715-.398v-9.22z" />
</svg>
),
Airbnb: (
<svg viewBox="0 0 1991.3 2143.2" aria-hidden className="size-full" fill="#ff385c">
<path d="m1851.6 1735.6c-15 111.6-90.1 208.1-195.2 251-51.5 21.4-107.3 27.9-163.1 21.4-53.6-6.4-107.3-23.6-163-55.7-77.2-43-154.5-109.4-244.6-208.1 141.6-173.8 227.4-332.5 259.6-474.1 15-66.5 17.2-126.6 10.7-182.4-8.6-53.6-27.9-103-57.9-145.9-66.5-96.5-178.1-152.3-302.5-152.3s-236 57.9-302.5 152.3c-30 42.9-49.3 92.3-57.9 145.9-8.6 55.8-6.4 118 10.7 182.4 32.2 141.6 120.1 302.5 259.6 476.2-88 98.7-167.3 165.2-244.6 208.1-55.8 32.2-109.4 49.4-163 55.8-55.3 6.2-111.2-1.2-163-21.4-105.1-42.9-180.2-139.5-195.2-251-6.4-53.6-2.1-107.2 19.3-167.3 6.4-21.5 17.2-42.9 27.9-68.6 15-34.3 32.2-70.8 49.3-107.3l2.2-4.3c148-319.7 306.8-645.8 472-963.3l6.4-12.9c17.2-32.1 34.3-66.5 51.5-98.7 17.2-34.3 36.5-66.5 60.1-94.4 45.1-51.5 105.1-79.4 171.6-79.4s126.6 27.9 171.6 79.4c23.6 27.9 42.9 60.1 60.1 94.4 17.2 32.2 34.3 66.5 51.5 98.6l6.5 12.9c163 319.6 321.8 645.7 469.8 965.4v2.1c17.2 34.3 32.2 73 49.3 107.3 10.7 25.8 21.5 47.2 27.9 68.6 17.1 55.9 23.5 109.5 14.9 165.3zm-856-100.9c-115.8-145.9-190.9-283.2-216.7-399-10.7-49.4-12.9-92.3-6.4-130.9 4.3-34.3 17.2-64.4 34.3-90.1 40.8-57.9 109.4-94.4 188.8-94.4s150.2 34.4 188.8 94.4c17.2 25.8 30 55.8 34.3 90.1 6.4 38.6 4.3 83.7-6.4 130.9-25.7 113.7-100.8 251-216.7 399zm967.6-111.5c-10.7-25.7-21.5-53.6-32.2-77.2-17.2-38.6-34.3-75.1-49.4-109.4l-2.1-2.1c-148-321.8-306.8-647.9-474.1-969.7l-6.4-12.9c-17.2-32.2-34.3-66.5-51.5-100.8-21.5-38.6-42.9-79.4-77.2-118-68.7-85.9-167.4-133.1-272.5-133.1-107.3 0-203.8 47.2-274.7 128.7-32.2 38.6-55.8 79.4-77.2 118-17.2 34.3-34.3 68.6-51.5 100.8l-6.4 12.8c-165.2 321.8-326.1 647.9-474.1 969.7l-2.1 4.3c-15 34.3-32.2 70.8-49.4 109.4-11.5 25.4-22.2 51.2-32.2 77.2-27.9 79.4-36.5 154.5-25.8 231.7 23.6 160.9 130.9 296.1 278.9 356.1 55.8 23.6 113.7 34.3 173.8 34.3 17.2 0 38.6-2.1 55.8-4.3 70.8-8.6 143.7-32.1 214.5-72.9 88-49.3 171.6-120.1 266-223.1 94.4 103 180.2 173.8 266 223.1 70.8 40.8 143.7 64.3 214.5 72.9 17.2 2.2 38.6 4.3 55.8 4.3 60.1 0 120.1-10.7 173.8-34.3 150.2-60.1 255.3-197.4 278.9-356.1 17.2-75 8.6-150-19.2-229.4z" />
</svg>
),
Spotify: (
<svg viewBox="0 0 24 24" aria-hidden className="size-full" fill="#1ed760">
<path d="M12 0C5.4 0 0 5.4 0 12s5.4 12 12 12 12-5.4 12-12S18.66 0 12 0zm5.521 17.34c-.24.359-.66.48-1.021.24-2.82-1.74-6.36-2.101-10.561-1.141-.418.122-.779-.179-.899-.539-.12-.421.18-.78.54-.9 4.56-1.021 8.52-.6 11.64 1.32.42.18.479.659.301 1.02zm1.44-3.3c-.301.42-.841.6-1.262.3-3.239-1.98-8.159-2.58-11.939-1.38-.479.12-1.02-.12-1.14-.6-.12-.48.12-1.021.6-1.141C9.6 9.9 15 10.561 18.72 12.84c.361.181.54.78.241 1.2zm.12-3.36C15.24 8.4 8.82 8.16 5.16 9.301c-.6.179-1.2-.181-1.38-.721-.18-.601.18-1.2.72-1.381 4.26-1.26 11.28-1.02 15.721 1.621.539.3.719 1.02.419 1.56-.299.421-1.02.599-1.559.3z" />
</svg>
),
Zoom: (
<svg viewBox="0 0 24 24" aria-hidden className="size-full" fill="#0b5cff">
<path d="M5.033 14.649H.743a.74.74 0 0 1-.686-.458.74.74 0 0 1 .16-.808L3.19 10.41H1.06A1.06 1.06 0 0 1 0 9.35h3.957c.301 0 .57.18.686.458a.74.74 0 0 1-.161.808L1.51 13.59h2.464c.585 0 1.06.475 1.06 1.06zM24 11.338c0-1.14-.927-2.066-2.066-2.066-.61 0-1.158.265-1.537.686a2.061 2.061 0 0 0-1.536-.686c-1.14 0-2.066.926-2.066 2.066v3.311a1.06 1.06 0 0 0 1.06-1.06v-2.251a1.004 1.004 0 0 1 2.013 0v2.251c0 .586.474 1.06 1.06 1.06v-3.311a1.004 1.004 0 0 1 2.012 0v2.251c0 .586.475 1.06 1.06 1.06zM16.265 12a2.728 2.728 0 1 1-5.457 0 2.728 2.728 0 0 1 5.457 0zm-1.06 0a1.669 1.669 0 1 0-3.338 0 1.669 1.669 0 0 0 3.338 0zm-4.82 0a2.728 2.728 0 1 1-5.458 0 2.728 2.728 0 0 1 5.457 0zm-1.06 0a1.669 1.669 0 1 0-3.338 0 1.669 1.669 0 0 0 3.338 0z" />
</svg>
),
Dropbox: (
<svg viewBox="0 0 24 24" aria-hidden className="size-full" fill="#0061ff">
<path d="M6 1.807L0 5.629l6 3.822 6.001-3.822L6 1.807zM18 1.807l-6 3.822 6 3.822 6-3.822-6-3.822zM0 13.274l6 3.822 6.001-3.822L6 9.452l-6 3.822zM18 9.452l-6 3.822 6 3.822 6-3.822-6-3.822zM6 18.371l6.001 3.822 6-3.822-6-3.822L6 18.371z" />
</svg>
),
Linear: (
<svg viewBox="0 0 24 24" aria-hidden className="size-full" fill="#5e6ad2">
<path d="M2.886 4.18A11.982 11.982 0 0 1 11.99 0C18.624 0 24 5.376 24 12.009c0 3.64-1.62 6.903-4.18 9.105L2.887 4.18ZM1.817 5.626l16.556 16.556c-.524.33-1.075.62-1.65.866L.951 7.277c.247-.575.537-1.126.866-1.65ZM.322 9.163l14.515 14.515c-.71.172-1.443.282-2.195.322L0 11.358a12 12 0 0 1 .322-2.195Zm-.17 4.862 9.823 9.824a12.02 12.02 0 0 1-9.824-9.824Z" />
</svg>
),
};
/** A company's logo on a 32 px rounded white tile; its initial when there is no logo. */
function CompanyLogo({ name }: { name: string }) {
const full = LOGO_FULL[name];
const mark = LOGO_MARK[name];
return (
<span aria-hidden className="grid size-8 shrink-0 place-items-center overflow-hidden rounded-[10px] bg-white text-[13px] font-medium text-black/70 shadow-[inset_0_0_0_1px_rgb(0_0_0/0.08)]">
{full ?? (mark ? <span className="grid size-5 place-items-center">{mark}</span> : name.charAt(0))}
</span>
);
}
/* ── Helpers ────────────────────────────────────────────────── */
/** Seeded random numbers, so the server and the browser draw the same lines. */
function seeded(seed: number) {
let s = seed >>> 0;
return () => {
s = (s + 0x6d2b79f5) >>> 0;
let t = s;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
/** A calm climb from `from` × end to `end` over the 12 weeks, with a little seeded wobble. */
function climb(seed: number, end: number, from: number) {
const r = seeded(seed);
const n = WEEKS.length;
return Array.from({ length: n }, (_, i) => (i === n - 1 ? end : Math.round(end * (from + ((1 - from) * i) / (n - 1)) * (0.98 + 0.04 * r()))));
}
/** "Nov 12" → a number that sorts by date (Nov and Dec 2026 only in this sample). */
const closeOrder = (close: string) => (close.startsWith("Dec") ? 1200 : 1100) + Number(close.split(" ")[1]);
const usd = (v: number) => v.toLocaleString("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 });
const kUsd = (v: number) => `$${Math.round(v / 1000)}k`;
const ring = "outline-none focus-visible:ring-2 focus-visible:ring-[var(--select)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--bg)]";
const icon = { size: 20, strokeWidth: 1.5 } as const;
type Page = "home" | "deals" | "inbox";
const NAV: { id: Page; label: string; icon: LucideIcon }[] = [
{ id: "home", label: "Home", icon: Home },
{ id: "deals", label: "Deals", icon: CircleDollarSign },
{ id: "inbox", label: "Inbox", icon: Inbox },
];
/* ── Pieces ─────────────────────────────────────────────────── */
function SearchField({ id, value, onChange }: { id: string; value: string; onChange: (v: string) => void }) {
return (
<div className="relative">
<label htmlFor={id} className="sr-only">
Search deals
</label>
<Search size={16} strokeWidth={1.5} aria-hidden className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-fg-subtle" />
<input
id={id}
type="search"
value={value}
onChange={(e) => onChange(e.target.value)}
placeholder="Search deals"
autoComplete="off"
className={`h-9 w-full rounded-full bg-surface pl-9 pr-3 text-[14px] text-fg shadow-[var(--shadow-control)] placeholder:text-fg-subtle [&::-webkit-search-cancel-button]:hidden ${ring}`}
/>
</div>
);
}
function NavList({ page, counts, onPick, tall = false }: { page: Page; counts: Record<Page, number | undefined>; onPick: (p: Page) => void; tall?: boolean }) {
return (
<ul className="flex flex-col gap-0.5">
{NAV.map((n) => {
const on = n.id === page;
return (
<li key={n.id}>
<button
type="button"
data-nav={n.id}
aria-current={on ? "page" : undefined}
onClick={() => onPick(n.id)}
className={`flex w-full items-center gap-2.5 rounded-[10px] px-2 text-left text-[14px] transition-colors ${tall ? "h-10" : "h-9"} ${ring} ${
on ? "bg-subtle text-fg" : "text-fg-muted hover:bg-subtle hover:text-fg"
}`}
>
<n.icon {...icon} aria-hidden />
<span className="flex-1 truncate">{n.label}</span>
{counts[n.id] !== undefined && <span className="text-[12px] tabular-nums text-fg-muted">{counts[n.id]}</span>}
</button>
</li>
);
})}
</ul>
);
}
function Card({ title, sub, action, children }: { title: string; sub: string; action?: ReactNode; children: ReactNode }) {
const id = useId();
return (
<section aria-labelledby={id} className="flex min-w-0 flex-col gap-3 rounded-[20px] bg-surface p-5 shadow-[var(--shadow-card)]">
<header className="flex items-start gap-3">
<div className="min-w-0 flex-1">
<h2 id={id} className="text-[15px] font-medium leading-5 text-fg">
{title}
</h2>
<p className="mt-0.5 truncate text-[13px] leading-5 text-fg-muted">{sub}</p>
</div>
{action}
</header>
{children}
</section>
);
}
function DealRows({ deals, query }: { deals: Deal[]; query: string }) {
if (!deals.length) return <p className="py-6 text-center text-[13px] leading-5 text-fg-muted">No deals match “{query}”. Try a company or a deal number.</p>;
return (
<ul className="-mx-1 flex flex-col">
{deals.map((d, i) => (
<motion.li
key={d.id}
layout="position"
initial={false}
className={`flex items-center gap-3 px-1 py-2.5 ${i ? "border-t border-border" : ""}`}
>
<CompanyLogo name={d.company} />
<span className="min-w-0 flex-1">
<span className="block truncate text-[14px] leading-5 text-fg">
<span className="font-medium">{d.company}</span>
<span className="text-fg-muted"> · {d.topic}</span>
</span>
<span className="block truncate text-[12px] leading-4 text-fg-muted tabular-nums">
{d.id} · {d.stage} · {PEOPLE[d.owner].name}
</span>
</span>
<span className="shrink-0 text-right">
<span className="block text-[14px] font-medium leading-5 text-fg tabular-nums">{kUsd(d.value)}</span>
<span className="block text-[12px] leading-4 text-fg-muted tabular-nums">
<span className="sr-only">Closes </span>
{d.close}
</span>
</span>
</motion.li>
))}
</ul>
);
}
/* ── The block ──────────────────────────────────────────────── */
/**
* The app frame: a sidebar with search, navigation and your profile, a breadcrumb header with the page's actions and
* a scrolling main area. Under 1024 px of room the sidebar folds into a slim header with a menu.
*/
export default function AppShellBlock({ className = "" }: { className?: string }) {
const reduce = useReducedMotion();
const uid = useId();
const [page, setPage] = useState<Page>("home");
const [deals, setDeals] = useState(DEALS);
const [added, setAdded] = useState(0);
const [unread, setUnread] = useState<string[]>(MENTIONS.map((m) => m.id));
const [query, setQuery] = useState("");
const [menu, setMenu] = useState(false);
const [said, setSaid] = useState("");
const menuButton = useRef<HTMLButtonElement>(null);
const menuPanel = useRef<HTMLDivElement>(null);
const label = NAV.find((n) => n.id === page)!.label;
const q = query.trim().toLowerCase();
const matches = deals.filter((d) => !q || `${d.company} ${d.topic} ${d.id} ${PEOPLE[d.owner].name}`.toLowerCase().includes(q));
const pipeline = deals.reduce((a, d) => a + d.value, 0);
const weighted = deals.reduce((a, d) => a + d.value * ODDS[d.stage], 0);
const soon = matches.slice(0, 5);
const go = (p: Page) => {
setPage(p);
setSaid(`${NAV.find((n) => n.id === p)!.label} open`);
};
const search = (v: string) => {
setQuery(v);
if (page === "inbox" && v.trim()) setPage("deals");
};
const newDeal = () => {
const d = NEW_DEALS[added % NEW_DEALS.length];
const id = `DEAL-${232 + added}`;
setDeals((xs) => [...xs, { ...d, id }].sort((a, b) => closeOrder(a.close) - closeOrder(b.close)));
setAdded((n) => n + 1);
setQuery("");
setSaid(`${d.company} · ${d.topic} added as a lead, ${kUsd(d.value)}`);
};
const markAllRead = () => {
setUnread([]);
setSaid("All mentions marked read");
};
// The menu (narrow layout): focus the open page on open; Escape or a click outside closes it.
useEffect(() => {
if (!menu) return;
menuPanel.current?.querySelector<HTMLElement>(`[data-nav="${CSS.escape(page)}"]`)?.focus();
const close = (back: boolean) => {
setMenu(false);
if (back) menuButton.current?.focus();
};
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") close(true);
};
const onDown = (e: PointerEvent) => {
const t = e.target as Node;
if (!menuPanel.current?.contains(t) && !menuButton.current?.contains(t)) close(false);
};
document.addEventListener("keydown", onKey);
document.addEventListener("pointerdown", onDown);
return () => {
document.removeEventListener("keydown", onKey);
document.removeEventListener("pointerdown", onDown);
};
// Only when the menu opens or closes; the page is read once on open.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [menu]);
const counts: Record<Page, number | undefined> = { home: undefined, deals: deals.length, inbox: unread.length || undefined };
const actions =
page === "inbox" ? (
<Button variant="secondary" size="sm" onClick={markAllRead} disabled={!unread.length}>
Mark all read
</Button>
) : (
<Button variant="primary" size="sm" leadingIcon={<Plus size={16} strokeWidth={1.5} />} onClick={newDeal}>
New deal
</Button>
);
const body =
page === "home" ? (
<div className="flex flex-col gap-4">
<div className="grid grid-cols-1 gap-4 @min-[480px]:grid-cols-2">
<StatCard label="Open pipeline" value={pipeline} format={usd} delta={8.4} comparison="vs last month" data={climb(3, pipeline, 0.74)} labels={WEEKS} />
<StatCard label="Weighted forecast" value={weighted} format={usd} delta={5.1} comparison="vs last month" data={climb(5, weighted, 0.8)} labels={WEEKS} />
</div>
<Card
title="Closing soon"
sub={q ? `${matches.length} of ${deals.length} deals match` : `Next ${soon.length} of ${deals.length} open deals · ${kUsd(soon.reduce((a, d) => a + d.value, 0))}`}
action={
<Button variant="secondary" size="sm" onClick={() => go("deals")}>
View all
</Button>
}
>
<DealRows deals={soon} query={query} />
</Card>
</div>
) : page === "deals" ? (
<Card title="Open deals" sub={q ? `${matches.length} of ${deals.length} match “${query.trim()}”` : `${deals.length} deals · ${kUsd(pipeline)} in the pipeline`}>
<DealRows deals={matches} query={query} />
</Card>
) : (
<Card title="Mentions" sub={unread.length ? `${unread.length} unread` : "You’re all caught up"}>
<ul className="-mx-1 flex flex-col">
{MENTIONS.map((m, i) => {
const isNew = unread.includes(m.id);
return (
<li key={m.id} className={i ? "border-t border-border" : ""}>
<button
type="button"
onClick={() => {
if (!isNew) return;
setUnread((u) => u.filter((x) => x !== m.id));
setSaid(`Marked read: ${PEOPLE[m.who].name} on ${m.deal}`);
}}
aria-label={`${PEOPLE[m.who].name} on ${m.deal}: ${m.text}${isNew ? ". Unread, press to mark read" : ""}`}
className={`flex w-full items-start gap-3 rounded-[12px] px-1 py-3 text-left ${ring}`}
>
<Avatar name={PEOPLE[m.who].name} src={PEOPLE[m.who].src} size="sm" />
<span className="min-w-0 flex-1">
<span className="flex items-center gap-2 text-[14px] leading-5">
<span className="truncate font-medium text-fg">{PEOPLE[m.who].name}</span>
<span className="shrink-0 text-fg-muted tabular-nums">{m.deal}</span>
<span className="ml-auto shrink-0 text-[12px] text-fg-muted tabular-nums">{m.time}</span>
</span>
<span className={`mt-0.5 block text-[13px] leading-5 ${isNew ? "text-fg" : "text-fg-muted"}`}>{m.text}</span>
</span>
<span aria-hidden className={`mt-2 size-1.5 shrink-0 rounded-full ${isNew ? "bg-select" : "bg-transparent"}`} />
</button>
</li>
);
})}
</ul>
</Card>
);
return (
<div className={"@container h-full w-full min-w-0 " + className}>
<div className="relative flex h-full min-h-[560px] overflow-hidden rounded-[20px] bg-bg text-fg shadow-[var(--shadow-card)]">
{/* Sidebar: 1024 px of room and up. */}
<aside aria-label={`${APP.name} sidebar`} className="hidden w-[240px] shrink-0 flex-col border-r border-border px-3 pb-3 pt-4 @min-[1024px]:flex">
<div className="flex h-10 items-center gap-2.5 px-2">
<WorkspaceMark />
<span className="min-w-0 flex-1">
<span className="block truncate text-[14px] font-medium leading-5">{APP.workspace}</span>
<span className="block truncate text-[12px] leading-4 text-fg-muted">{APP.name}</span>
</span>
</div>
<div className="mt-3">
<SearchField id={`${uid}-search`} value={query} onChange={search} />
</div>
<nav aria-label={APP.name} className="mt-4">
<NavList page={page} counts={counts} onPick={go} />
</nav>
<div className="mt-auto flex items-center gap-2.5 px-2 pt-3">
<Avatar name={ME.name} src={ME.src} size="sm" status="online" />
<span className="min-w-0 flex-1">
<span className="block truncate text-[14px] font-medium leading-5">{ME.name}</span>
<span className="block truncate text-[12px] leading-4 text-fg-muted">{ME.role}</span>
</span>
</div>
</aside>
<div className="flex min-w-0 flex-1 flex-col">
{/* Narrow header: under 1024 px. */}
<header className="flex h-14 shrink-0 items-center gap-2.5 border-b border-border px-4 @min-[1024px]:hidden">
<WorkspaceMark />
<div className="min-w-0 flex-1">
<p className="truncate text-[14px] font-medium leading-5">{label}</p>
<p className="truncate text-[12px] leading-4 text-fg-muted">
{APP.workspace} · {APP.name}
</p>
</div>
<div className="hidden shrink-0 @min-[480px]:block">{actions}</div>
<button
ref={menuButton}
type="button"
aria-label="Menu"
aria-expanded={menu}
aria-controls={`${uid}-menu`}
onClick={() => setMenu((m) => !m)}
className={`grid size-9 shrink-0 place-items-center rounded-full transition-colors hover:bg-subtle hover:text-fg ${menu ? "bg-subtle text-fg" : "text-fg-muted"} ${ring}`}
>
{menu ? <X {...icon} aria-hidden /> : <Menu {...icon} aria-hidden />}
</button>
</header>
{/* Wide header: breadcrumb and actions. */}
<header className="hidden h-14 shrink-0 items-center gap-3 border-b border-border px-6 @min-[1024px]:flex">
<nav aria-label="Breadcrumb" className="min-w-0 flex-1">
<ol className="flex min-w-0 items-center gap-1.5 text-[14px]">
<li className="flex min-w-0 items-center gap-1.5">
<button type="button" onClick={() => go("home")} className={`truncate rounded-[6px] text-fg-muted transition-colors hover:text-fg ${ring}`}>
{APP.name}
</button>
</li>
<li className="flex min-w-0 items-center gap-1.5">
<ChevronRight size={16} strokeWidth={1.5} aria-hidden className="shrink-0 text-fg-subtle" />
<span aria-current="page" className="truncate font-medium text-fg">
{label}
</span>
</li>
</ol>
</nav>
<div className="flex shrink-0 items-center gap-2">{actions}</div>
</header>
<main aria-label={label} className="min-h-0 flex-1 overflow-y-auto p-4 @min-[720px]:p-6">
<div className="mb-4 @min-[480px]:hidden">{actions}</div>
<AnimatePresence mode="wait" initial={false}>
<motion.div key={page} initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} transition={{ duration: reduce ? 0 : 0.16, ease: [0.22, 1, 0.36, 1] }}>
{body}
</motion.div>
</AnimatePresence>
</main>
</div>
<AnimatePresence>
{menu && (
<motion.div
ref={menuPanel}
id={`${uid}-menu`}
initial={reduce ? { opacity: 0 } : { opacity: 0, y: -6 }}
animate={{ opacity: 1, y: 0 }}
exit={reduce ? { opacity: 0 } : { opacity: 0, y: -6 }}
transition={{ duration: reduce ? 0 : 0.18 }}
className="absolute inset-x-3 top-[60px] z-20 flex max-h-[calc(100%-72px)] flex-col gap-3 overflow-y-auto rounded-[16px] bg-raised p-2 shadow-[var(--shadow-overlay)] @min-[1024px]:hidden"
>
<div className="px-1 pt-1">
<SearchField id={`${uid}-search-menu`} value={query} onChange={search} />
</div>
<nav aria-label={APP.name}>
<NavList
page={page}
counts={counts}
tall
onPick={(p) => {
go(p);
setMenu(false);
menuButton.current?.focus();
}}
/>
</nav>
<div className="flex items-center gap-2.5 border-t border-border px-2 pb-1 pt-3">
<Avatar name={ME.name} src={ME.src} size="sm" status="online" />
<span className="min-w-0 flex-1">
<span className="block truncate text-[14px] font-medium leading-5">{ME.name}</span>
<span className="block truncate text-[12px] leading-4 text-fg-muted">{ME.role}</span>
</span>
</div>
</motion.div>
)}
</AnimatePresence>
</div>
<span role="status" aria-live="polite" className="sr-only">
{said}
</span>
</div>
);
}
/** The workspace logo: the UI Stacks mark. Swap in your own. */
function WorkspaceMark() {
return (
<svg width={24} height={24} viewBox="0 0 24 24" fill="none" aria-hidden className="shrink-0 text-fg">
<path
d="M4.37852 14.1429L14.3785 19.1429L17.2357 17.7143V19.619L12.4738 22L2.94995 17.2381V14.8571L4.37852 14.1429ZM6.28328 8.90476L16.2833 13.9048L19.1404 12.4762V14.381L14.3785 16.7619L4.85471 12V9.61905L6.28328 8.90476ZM11.5214 2L21.0452 6.7619V9.14286L16.2833 11.5238L6.75947 6.7619V4.38095L11.5214 2Z"
fill="currentColor"
/>
</svg>
);
}
使用说明
把 TSX 加入 React 项目,并安装组件引用的依赖。页面样式依赖 Tailwind CSS 与 主题变量。
包依赖 · lucide-react、motion、react
共享源码 · avatar.tsx、button.tsx、stat-card.tsx