"use client"; import "./components/ui/tidal.css"; import { useId, useMemo, useState } from "react"; import { TidalAnalyticsDashboardTemplate, type TidalAnalyticsDashboardAction } from "./components/ui/analytics-dashboard-template"; import type { TidalStatsGridMetric } from "./components/ui/stats-grid"; import type { TidalLineChartPoint } from "./components/ui/line-chart"; import type { TidalActivityFeedGroup, TidalActivityFeedItem } from "./components/ui/activity-feed"; import "./components/ui/stats-grid.css"; import "./components/ui/line-chart.css"; import "./components/ui/activity-feed.css"; import "./components/ui/analytics-dashboard-template.css"; function tidalExampleAvatarDataUri(seed: unknown) { const text = String(seed).replace(/[^a-z0-9]/gi, "").slice(-2) || "UI"; const palette = ["#333333", "#555555", "#777777", "#999999", "#bbbbbb"]; const color = palette[Array.from(text).reduce((sum, character) => sum + character.charCodeAt(0), 0) % palette.length]; const svg = ``; return `data:image/svg+xml,${encodeURIComponent(svg)}`; } function tidalExampleImageDataUri(label: string) { const safeLabel = label.replace(/[<>&]/g, "").slice(0, 28) || "Sample image"; const svg = `${safeLabel}`; return `data:image/svg+xml,${encodeURIComponent(svg)}`; } const tidalExampleStyles = ".tidal-scope .analytics-demo-footer,\n.tidal-scope .analytics-demo-footer > div {\n min-width: 0;\n}\n\n.tidal-scope .analytics-demo-footer {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 14px;\n padding: 12px 2px 2px;\n border-top: 1px solid var(--t-border);\n}\n\n.tidal-scope .analytics-demo-footer > div {\n display: grid;\n gap: 3px;\n}\n\n.tidal-scope .analytics-demo-footer strong,\n.tidal-scope .analytics-demo-footer span,\n.tidal-scope .analytics-demo-footer output {\n min-width: 0;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .analytics-demo-footer strong,\n.tidal-scope .analytics-demo-footer output {\n color: var(--t-ink);\n font-weight: 680;\n}\n\n.tidal-scope .analytics-demo-footer > div:focus-visible {\n outline: 2px solid var(--t-accent);\n outline-offset: 3px;\n}\n\n@container tidal-analytics-template (max-width: 620px) {\n .tidal-scope .analytics-demo-footer {\n align-items: flex-start;\n flex-direction: column;\n }\n}"; type RangeId = "7d" | "30d" | "90d"; type ActivityFilter = "all" | "unread"; const RANGE_DATA: Record< RangeId, { label: string; visits: number; conversion: string; active: number; returnRate: string; points: readonly TidalLineChartPoint[]; } > = { "7d": { label: "Last 7 days", visits: 1842, conversion: "6.8%", active: 312, returnRate: "41%", points: [ { id: "7-mon", label: "Oct 8", value: 218, displayValue: "218 visits", }, { id: "7-tue", label: "Oct 9", value: 246, displayValue: "246 visits", }, { id: "7-wed", label: "Oct 10", value: 231, displayValue: "231 visits", }, { id: "7-thu", label: "Oct 11", value: 275, displayValue: "275 visits", }, { id: "7-fri", label: "Oct 12", value: 292, displayValue: "292 visits", }, { id: "7-sat", label: "Oct 13", value: 264, displayValue: "264 visits", }, { id: "7-sun", label: "Oct 14", value: 316, displayValue: "316 visits", }, ], }, "30d": { label: "Last 30 days", visits: 7284, conversion: "6.4%", active: 894, returnRate: "38%", points: [ { id: "30-w1", label: "Week 1", value: 1510, displayValue: "1,510 visits", }, { id: "30-w2", label: "Week 2", value: 1748, displayValue: "1,748 visits", }, { id: "30-w3", label: "Week 3", value: 1882, displayValue: "1,882 visits", }, { id: "30-w4", label: "Week 4", value: 2144, displayValue: "2,144 visits", }, ], }, "90d": { label: "Last 90 days", visits: 20418, conversion: "6.1%", active: 2406, returnRate: "36%", points: [ { id: "90-aug", label: "August", value: 6128, displayValue: "6,128 visits", }, { id: "90-sep", label: "September", value: 6714, displayValue: "6,714 visits", }, { id: "90-oct", label: "October", value: 7576, displayValue: "7,576 visits", }, ], }, }; const INITIAL_ACTIVITY: readonly TidalActivityFeedItem[] = [ { id: "report-opened", title: "Mina opened the sample performance report", dateTime: "2026-10-14T09:40:00-05:00", timeLabel: "9:40 AM", description: "The local report note was viewed from this fictional dashboard.", category: "Report", context: "Performance overview", unread: true, actor: { name: "Mina Cole", detail: "Fictional analyst", avatarSrc: tidalExampleAvatarDataUri("01"), }, }, { id: "segment-reviewed", title: "Jon reviewed the returning visitor sample", dateTime: "2026-10-14T08:18:00-05:00", timeLabel: "8:18 AM", description: "The displayed segment remains part of the local sample data.", category: "Segment", context: "Returning visitors", unread: false, actor: { name: "Jon Bell", detail: "Fictional researcher", avatarSrc: tidalExampleAvatarDataUri("02"), }, }, ] as const; export function AnalyticsDashboardTemplateDemo() { const generatedId = useId().replace(/:/g, ""); const chartId = `${generatedId}-traffic-chart`; const activityId = `${generatedId}-activity`; const reportNoteId = `${generatedId}-report-note`; const [range, setRange] = useState("7d"); const [selectedPointId, setSelectedPointId] = useState( RANGE_DATA["7d"].points[0].id, ); const [activityFilter, setActivityFilter] = useState("all"); const [sampleAdded, setSampleAdded] = useState(false); const [message, setMessage] = useState("Showing the last 7 days."); const data = RANGE_DATA[range]; const activity = useMemo(() => { if (!sampleAdded) return INITIAL_ACTIVITY; return [ { id: "sample-visit", title: "A sample visit was added locally", dateTime: "2026-10-14T10:05:00-05:00", timeLabel: "10:05 AM", description: "This fictional event exists only until the preview reloads.", category: "Visit", context: data.label, unread: true, actor: { name: "Inez Park", detail: "Fictional teammate", avatarSrc: tidalExampleAvatarDataUri("03"), }, }, ...INITIAL_ACTIVITY, ]; }, [data.label, sampleAdded]); const visibleActivity = activity.filter( (item) => activityFilter === "all" || item.unread, ); const activityGroups: readonly TidalActivityFeedGroup[] = [ { id: "today", label: "Today", items: visibleActivity.map((item) => ({ ...item, destination: { href: `#${reportNoteId}`, label: `Open local report note for ${String(item.title)}`, linkProps: { onClick: () => setMessage(`${String(item.title)} opened the local report note.`), }, }, })), }, ]; const metrics: readonly TidalStatsGridMetric[] = [ { id: "visits", label: "Visits", value: (data.visits + (sampleAdded ? 1 : 0)).toLocaleString(), valueKey: `${range}-${sampleAdded}`, comparison: "vs. prior sample", trend: "positive", detail: data.label, href: `#${chartId}`, }, { id: "conversion", label: "Conversion", value: data.conversion, valueKey: range, comparison: "sample rate", trend: "neutral", detail: "Fictional conversion", href: `#${chartId}`, }, { id: "active", label: "Active visitors", value: data.active.toLocaleString(), valueKey: range, comparison: "current sample", trend: "positive", href: `#${activityId}`, }, { id: "returning", label: "Returning", value: data.returnRate, valueKey: range, comparison: "sample share", trend: "neutral", href: `#${activityId}`, }, ]; const actions: readonly TidalAnalyticsDashboardAction[] = [ { id: "report-note", kind: "link", href: `#${reportNoteId}`, label: "Report note", linkProps: { onClick: () => setMessage("The local report note is open below."), }, }, { id: "add-event", kind: "button", label: "Add sample event", emphasis: "primary", onAction: () => { if (sampleAdded) { setMessage("The sample event is already visible."); return; } setSampleAdded(true); setActivityFilter("all"); setMessage("One fictional event was added locally."); }, }, ]; return ( ({ value, label: RANGE_DATA[value].label, })), onValueChange: (value) => { const nextRange = value as RangeId; setRange(nextRange); setSelectedPointId(RANGE_DATA[nextRange].points[0].id); setMessage(`Showing ${RANGE_DATA[nextRange].label.toLowerCase()}.`); }, }} actions={actions} stats={{ title: "Performance", eyebrow: null, description: "Four measures for the selected reporting range.", metrics, }} chart={{ id: chartId, title: "Visits over time", eyebrow: null, description: "Use the native previous and next controls to inspect an exact point.", points: data.points, selectedId: selectedPointId, onSelectedChange: (point) => { setSelectedPointId(point.id); setMessage(`${point.label}: ${point.displayValue}.`); }, yAxisLabel: "Visits", formatAxisValue: (value) => Math.round(value).toLocaleString(), tableLabel: "View supplied visit data", }} activity={{ id: activityId, title: "Recent activity", eyebrow: null, description: "Events associated with this report.", groups: activityGroups, filter: { value: activityFilter, label: "Filter recent activity", options: [ { id: "all", label: "All", count: activity.length }, { id: "unread", label: "Unread", count: activity.filter((item) => item.unread).length, }, ], onValueChange: (value) => { setActivityFilter(value as ActivityFilter); setMessage(`Showing ${value} sample activity.`); }, }, emptyMessage: "No sample activity matches this view.", }} footer={ Report note This note follows the selected activity. {message} Sample data. Changes stay in this preview. } /> ); } export default function AgentExample() { return ( ); }