"use client"; import "./components/ui/tidal.css"; import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type FormEvent, type InvalidEvent } from "react"; import { TidalMultiStepForm, type TidalMultiStepFormStep } from "./components/ui/multi-step-form"; import "./components/ui/multi-step-form.css"; const tidalExampleStyles = ".tidal-scope .multi-step-demo,\n.tidal-scope .multi-step-demo * {\n box-sizing: border-box;\n}\n\n.tidal-scope .multi-step-demo {\n width: 100%;\n min-width: 0;\n border: 1px solid var(--t-border);\n border-radius: 22px;\n background: var(--t-subtle);\n color: var(--t-ink);\n container: multi-step-demo / inline-size;\n}\n\n.tidal-scope .multi-step-demo-frame {\n min-width: 0;\n padding: 20px;\n}\n\n.tidal-scope .multi-step-demo-fields {\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n gap: 12px;\n min-width: 0;\n}\n\n.tidal-scope .multi-step-demo-fields > label {\n display: grid;\n min-width: 0;\n gap: 6px;\n color: var(--t-muted);\n font-size: 11px;\n font-weight: 650;\n line-height: 1.4;\n}\n\n.tidal-scope .multi-step-demo-fields > label > span,\n.tidal-scope .multi-step-demo-choice-group legend {\n color: var(--t-ink);\n font-size: 11px;\n font-weight: 700;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope\n .multi-step-demo-fields\n input:not([type=\"radio\"]):not([type=\"checkbox\"]),\n.tidal-scope .multi-step-demo-fields select {\n width: 100%;\n min-width: 0;\n min-height: 48px;\n padding: 10px 12px;\n border: 1px solid var(--t-border);\n border-radius: 10px;\n background: var(--t-surface);\n color: var(--t-ink);\n font: inherit;\n font-size: 16px;\n line-height: 1.4;\n transition:\n border-color 180ms,\n box-shadow 180ms,\n background 180ms;\n}\n\n.tidal-scope .multi-step-demo-fields input:focus-visible,\n.tidal-scope .multi-step-demo-fields select:focus-visible {\n border-color: var(--t-ink);\n outline: 2px solid var(--t-accent);\n outline-offset: 3px;\n box-shadow: inset 0 0 0 1px var(--t-surface);\n}\n\n.tidal-scope .multi-step-demo-fields small {\n color: var(--t-muted);\n font-size: 11px;\n font-weight: 520;\n line-height: 1.45;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .multi-step-demo-choice-group {\n display: grid;\n min-width: 0;\n grid-column: 1 / -1;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n gap: 8px;\n margin: 0;\n padding: 0;\n border: 0;\n}\n\n.tidal-scope .multi-step-demo-choice-group legend {\n grid-column: 1 / -1;\n margin-bottom: 2px;\n}\n\n.tidal-scope .multi-step-demo-choice-group label,\n.tidal-scope .multi-step-demo-check {\n position: relative;\n display: grid;\n min-width: 0;\n min-height: 70px;\n grid-template-columns: 44px minmax(0, 1fr);\n align-items: center;\n gap: 10px;\n padding: 9px 11px;\n border: 1px solid var(--t-border);\n border-radius: 12px;\n background: var(--t-surface);\n color: var(--t-ink);\n cursor: pointer;\n transition:\n border-color 180ms,\n background 180ms,\n transform 180ms var(--t-ease-out);\n}\n\n.tidal-scope .multi-step-demo-check {\n grid-column: 1 / -1;\n}\n\n.tidal-scope .multi-step-demo-choice-group label:has(input:checked),\n.tidal-scope .multi-step-demo-check:has(input:checked) {\n border-color: var(--t-ink);\n background: var(--t-wash);\n}\n\n.tidal-scope .multi-step-demo-choice-group input,\n.tidal-scope .multi-step-demo-check input {\n width: 44px;\n height: 44px;\n margin: 0;\n accent-color: var(--t-accent);\n cursor: pointer;\n}\n\n.tidal-scope .multi-step-demo-choice-group label > span,\n.tidal-scope .multi-step-demo-check > span {\n display: grid;\n min-width: 0;\n gap: 4px;\n}\n\n.tidal-scope .multi-step-demo-choice-group strong,\n.tidal-scope .multi-step-demo-check strong,\n.tidal-scope .multi-step-demo-choice-group small,\n.tidal-scope .multi-step-demo-check small {\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .multi-step-demo-choice-group strong,\n.tidal-scope .multi-step-demo-check strong {\n font-size: 11px;\n line-height: 1.35;\n}\n\n.tidal-scope .multi-step-demo-review {\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n gap: 1px;\n margin: 0;\n overflow: hidden;\n border: 1px solid var(--t-border);\n border-radius: 14px;\n background: var(--t-border);\n}\n\n.tidal-scope .multi-step-demo-review > div {\n min-width: 0;\n min-height: 76px;\n padding: 14px;\n background: var(--t-surface);\n}\n\n.tidal-scope .multi-step-demo-review dt {\n color: var(--t-muted);\n font-size: 11px;\n font-weight: 680;\n line-height: 1.35;\n}\n\n.tidal-scope .multi-step-demo-review dd {\n margin: 7px 0 0;\n color: var(--t-ink);\n font-size: 12px;\n font-weight: 640;\n line-height: 1.35;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .multi-step-demo-footer {\n display: flex;\n min-width: 0;\n align-items: center;\n justify-content: center;\n gap: 9px;\n}\n\n.tidal-scope .multi-step-demo-footer > span {\n min-width: 0;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .multi-step-demo-footer button,\n.tidal-scope .multi-step-demo-complete button {\n min-width: 44px;\n min-height: 44px;\n padding: 9px 13px;\n border: 1px solid currentColor;\n border-radius: 10px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 11px;\n font-weight: 680;\n line-height: 1.35;\n cursor: pointer;\n}\n\n.tidal-scope .multi-step-demo-footer button:focus-visible,\n.tidal-scope .multi-step-demo-complete button:focus-visible,\n.tidal-scope .multi-step-demo-complete h3:focus-visible {\n outline: 2px solid currentColor;\n outline-offset: 3px;\n}\n\n.tidal-scope .multi-step-demo-complete {\n display: grid;\n min-height: 370px;\n place-items: center;\n align-content: center;\n gap: 10px;\n text-align: center;\n background:\n linear-gradient(var(--t-border) 1px, transparent 1px),\n linear-gradient(90deg, var(--t-border) 1px, transparent 1px),\n var(--t-subtle);\n background-size: 24px 24px;\n}\n\n.tidal-scope .multi-step-demo-complete-mark {\n display: grid;\n width: 58px;\n height: 58px;\n place-items: center;\n border-radius: 18px;\n background: var(--t-ink);\n color: var(--t-surface);\n font-size: 21px;\n animation: multi-step-demo-mark-in 420ms var(--t-ease-spring) both;\n}\n\n.tidal-scope .multi-step-demo-complete > span {\n margin-top: 6px;\n color: var(--t-muted);\n font-size: 11px;\n font-weight: 700;\n letter-spacing: 0.1em;\n text-transform: uppercase;\n}\n\n.tidal-scope .multi-step-demo-complete h3 {\n max-width: 18ch;\n margin: 0;\n font-size: clamp(28px, 7cqi, 48px);\n font-weight: 530;\n letter-spacing: -0.055em;\n line-height: 1;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .multi-step-demo-complete p {\n max-width: 54ch;\n margin: 0;\n color: var(--t-muted);\n font-size: 11px;\n line-height: 1.55;\n overflow-wrap: anywhere;\n}\n\n@container multi-step-demo (max-width: 640px) {\n .tidal-scope .multi-step-demo {\n border-radius: 18px;\n }\n\n .tidal-scope .multi-step-demo-frame {\n padding: 8px;\n }\n\n .tidal-scope .multi-step-demo-fields,\n .tidal-scope .multi-step-demo-choice-group {\n grid-template-columns: minmax(0, 1fr);\n }\n\n .tidal-scope .multi-step-demo-choice-group legend,\n .tidal-scope .multi-step-demo-check {\n grid-column: 1;\n }\n\n .tidal-scope .multi-step-demo-review {\n grid-template-columns: minmax(0, 1fr);\n }\n\n .tidal-scope .multi-step-demo-review > div {\n min-height: 62px;\n }\n\n .tidal-scope .multi-step-demo-footer {\n flex-direction: column;\n }\n}\n\n@container multi-step-demo (max-width: 390px) {\n .tidal-scope .multi-step-demo-complete {\n min-height: 340px;\n padding: 22px 14px;\n }\n}\n\n@media (hover: none) and (pointer: coarse) {\n .tidal-scope .multi-step-demo-footer button,\n .tidal-scope .multi-step-demo-complete button {\n font-size: 16px;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .tidal-scope .multi-step-demo-choice-group label,\n .tidal-scope .multi-step-demo-check {\n transition: none;\n }\n\n .tidal-scope .multi-step-demo-complete-mark {\n animation: none;\n }\n}\n\n@keyframes multi-step-demo-mark-in {\n from {\n opacity: 0;\n transform: scale(0.72) rotate(-10deg);\n }\n to {\n opacity: 1;\n transform: none;\n }\n}"; type StepId = "workspace" | "preferences" | "review"; type Visibility = "private" | "team"; export function MultiStepFormDemo() { const generatedId = useId().replace(/:/g, ""); const [step, setStep] = useState("workspace"); const [workspaceName, setWorkspaceName] = useState("Northstar studio"); const [teamSize, setTeamSize] = useState("6-15"); const [visibility, setVisibility] = useState("team"); const [weeklySummary, setWeeklySummary] = useState(true); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); const [complete, setComplete] = useState(false); const [message, setMessage] = useState( "This setup preview uses local React state only.", ); const timerRef = useRef(null); const continueRef = useRef(null); const completionSourceRef = useRef(null); const nameRef = useRef(null); const completeHeadingRef = useRef(null); const resetFocusPending = useRef(false); const formName = `multi-step-demo-${generatedId}`; useEffect( () => () => { if (timerRef.current !== null) window.clearTimeout(timerRef.current); }, [], ); useLayoutEffect(() => { if (!complete) return; const activeElement = document.activeElement; if ( activeElement === completionSourceRef.current || activeElement === document.body ) { completeHeadingRef.current?.focus({ preventScroll: true }); } completionSourceRef.current = null; }, [complete]); useLayoutEffect(() => { if (!resetFocusPending.current || complete || step !== "workspace") return; resetFocusPending.current = false; nameRef.current?.focus({ preventScroll: true }); }, [complete, step]); const steps = useMemo( () => [ { id: "workspace", label: "Workspace", title: "Name the sample workspace", description: "Use a clear label and a fictional team-size range for this local setup preview.", complete: step !== "workspace", content: (
), }, { id: "preferences", label: "Preferences", title: "Choose local preview defaults", description: "These controls change only the review shown in this browser preview.", complete: step === "review", content: (
Sample workspace access
), }, { id: "review", label: "Review", title: "Review the local setup", description: "Finish to show a local completion state. No workspace or account is created.", content: (
Workspace
{workspaceName || "Not provided"}
Team size
{teamSize} people
Access
{visibility === "team" ? "Team sample" : "Private sample"}
Summary
{weeklySummary ? "Shown locally" : "Hidden"}
), }, ], [step, teamSize, visibility, weeklySummary, workspaceName], ); function handleInvalid(event: InvalidEvent) { const control = event.target as HTMLInputElement | HTMLSelectElement; if (control.name === "workspaceName") { setError( "Enter at least three characters for the sample workspace name.", ); } else { setError("Complete the required field before continuing."); } } function finish(event: FormEvent) { event.preventDefault(); if (busy) return; completionSourceRef.current = ((event.nativeEvent as SubmitEvent).submitter as HTMLElement | null) ?? (document.activeElement as HTMLElement | null); setBusy(true); setError(""); setMessage("Checking the local sample setup…"); timerRef.current = window.setTimeout(() => { timerRef.current = null; setBusy(false); setComplete(true); setMessage( "Sample setup complete in local preview state. Nothing was created or saved.", ); }, 600); } function cancelCheck() { if (timerRef.current !== null) window.clearTimeout(timerRef.current); timerRef.current = null; setBusy(false); setMessage("Local completion check cancelled. No setup was created."); requestAnimationFrame(() => continueRef.current?.focus({ preventScroll: true }), ); } function reset() { if (timerRef.current !== null) window.clearTimeout(timerRef.current); timerRef.current = null; resetFocusPending.current = true; setWorkspaceName("Northstar studio"); setTeamSize("6-15"); setVisibility("team"); setWeeklySummary(true); setError(""); setBusy(false); setStep("workspace"); setComplete(false); setMessage("Local sample reset. No saved setup exists."); completionSourceRef.current = null; } if (complete) { return (
Local preview

Sample setup complete

{message}

); } return (
{ setError(""); setStep(next as StepId); setMessage(`Moved to the ${next} step in local preview state.`); }} onFinalSubmit={finish} onInvalid={handleInvalid} onInput={() => setError("")} error={error || null} busy={busy} persistentFields={ <> } continueButtonRef={continueRef} footer={
{message} {busy ? ( ) : null}
} />
); } export default function AgentExample() { return (
); }