import "./components/ui/tidal.css"; import { useEffect, useLayoutEffect, useRef, useState } from "react"; import { ArrowUpRight, Check } from "lucide-react"; import { TidalPasswordField } from "./components/ui/password-field"; import { TidalButton } from "./components/ui/tidal-button"; import "./components/ui/password-field.css"; const tidalExampleStyles = ".password-field-specimen {\n width: 100%;\n max-width: 690px;\n padding: 28px;\n border: 1px solid var(--t-border);\n border-radius: var(--t-radius-card);\n background: var(--t-surface);\n box-shadow:\n 0 24px 40px -28px #00000030,\n 0 2px 4px #00000007;\n container-type: inline-size;\n}\n.password-field-specimen > h3 {\n font-size: 29px;\n line-height: 1.08;\n letter-spacing: -1px;\n font-weight: 500;\n margin: 13px 0 26px;\n}\n.password-field-specimen > h3 > em {\n font-family: \"Instrument Serif\", serif;\n font-size: 1.2em;\n font-weight: 400;\n}\n.password-demo-frame {\n overflow: hidden;\n transition: height 420ms var(--t-ease-out);\n padding: 7px 0;\n}\n.password-demo-content {\n display: flow-root;\n}\n.password-demo-layout {\n display: block;\n width: min(100%, 480px);\n margin-inline: auto;\n}\n.password-demo-layout > form {\n min-width: 0;\n align-self: center;\n}\n.password-demo-actions {\n display: flex;\n flex-wrap: wrap;\n gap: 9px;\n margin-top: 24px;\n}\n.tidal-scope .password-demo-actions > .tidal-button {\n font-size: 11px;\n padding: 0 12px;\n flex: 1;\n min-width: 0;\n}\n.tidal-scope .password-demo-policy-note {\n font-size: 11px;\n line-height: 1.6;\n color: var(--t-muted);\n margin: 14px 0 0;\n}\n.password-demo-note {\n font-size: 11px;\n color: var(--t-muted);\n line-height: 1.7;\n margin: 16px 0 0;\n}\n.password-demo-complete {\n text-align: center;\n padding: 29px 23px;\n border: 1px solid var(--t-border);\n border-radius: 13px;\n background: var(--t-subtle);\n animation: password-demo-complete-in 420ms var(--t-ease-out) both;\n}\n.password-demo-complete-icon {\n display: grid;\n place-items: center;\n margin: 0 auto 24px;\n width: 54px;\n height: 54px;\n background: var(--t-ink);\n color: var(--t-surface);\n border-radius: 14px;\n transform: rotate(-5deg);\n animation: password-demo-check-in 420ms var(--t-ease-spring) both;\n}\n.password-demo-complete > .demo-eyebrow {\n display: block;\n font-size: 11px;\n}\n.password-demo-complete > h4 {\n font-size: 25px;\n letter-spacing: -0.8px;\n line-height: 1.2;\n font-weight: 500;\n margin: 13px 0;\n}\n.password-demo-complete > p {\n font-size: 11px;\n color: var(--t-muted);\n max-width: 330px;\n line-height: 1.8;\n margin: 0 auto 24px;\n}\n.password-demo-complete > .tidal-button {\n font-size: 11px;\n}\n@media (max-width: 480px) {\n .password-field-specimen {\n padding: 20px;\n }\n .password-demo-actions {\n gap: 7px;\n }\n .password-demo-complete {\n padding: 24px 17px;\n }\n .password-demo-complete > h4 {\n font-size: 22px;\n }\n}\n@keyframes password-demo-complete-in {\n from {\n opacity: 0;\n transform: translateY(8px);\n }\n to {\n opacity: 1;\n transform: none;\n }\n}\n@keyframes password-demo-check-in {\n from {\n opacity: 0;\n transform: scale(0.7) rotate(-15deg);\n }\n to {\n opacity: 1;\n transform: scale(1) rotate(-5deg);\n }\n}"; const sample = "paper river lantern"; export function PasswordFieldDemo() { const [value, setValue] = useState(""); const [revealed, setRevealed] = useState(false); const [phase, setPhase] = useState<"editing" | "checking" | "complete">( "editing", ); const [error, setError] = useState(""); const [height, setHeight] = useState(); const input = useRef(null); const success = useRef(null); const content = useRef(null); const timer = useRef | undefined>(undefined); const restore = useRef(false); const focusOwner = useRef(null); const requirements = [ { id: "length", label: "12 or more characters", met: Array.from(value).length >= 12, }, { id: "words", label: "At least 3 words", met: value.trim().split(/\s+/u).filter(Boolean).length >= 3, }, ]; const satisfied = requirements.filter((r) => r.met).length; useEffect(() => () => clearTimeout(timer.current), []); useLayoutEffect(() => { const active = document.activeElement; const canMoveFocus = active === document.body || active === focusOwner.current; if (phase === "complete" && canMoveFocus) { success.current?.focus({ preventScroll: true }); focusOwner.current = null; } else if (phase === "editing" && restore.current) { restore.current = false; if (canMoveFocus) input.current?.focus({ preventScroll: true }); focusOwner.current = null; } }, [phase]); useLayoutEffect(() => { const node = content.current; if (!node) return; const measure = () => { const parent = getComputedStyle(node.parentElement!); setHeight( node.offsetHeight + Number.parseFloat(parent.paddingTop) + Number.parseFloat(parent.paddingBottom), ); }; measure(); const observer = new ResizeObserver(measure); observer.observe(node); return () => observer.disconnect(); }, []); function reset() { clearTimeout(timer.current); focusOwner.current = document.activeElement instanceof HTMLElement ? document.activeElement : null; setValue(""); setRevealed(false); setError(""); restore.current = true; setPhase("editing"); if (phase === "editing") { restore.current = false; input.current?.focus({ preventScroll: true }); } } return (
{phase === "complete" ? (
SAMPLE CHECK COMPLETE

Ready for the next step.

Both sample requirements were met. This preview created no account and saved no password.

Try the sample again
) : ( <>
{ event.preventDefault(); if (satisfied !== 2) { setError( "Complete both sample requirements to continue.", ); input.current?.focus({ preventScroll: true }); return; } focusOwner.current = (event.nativeEvent as SubmitEvent).submitter instanceof HTMLElement ? (event.nativeEvent as SubmitEvent).submitter : document.activeElement instanceof HTMLElement ? document.activeElement : null; setError(""); setRevealed(false); setPhase("checking"); timer.current = setTimeout(() => { setValue(""); setPhase("complete"); }, 650); }} > { setValue(event.target.value); setError(""); }} revealed={revealed} onRevealedChange={setRevealed} autoComplete="off" required disabled={phase === "checking"} description="Use the provided fictional phrase to explore." error={error} requirements={requirements} requirementsLabel="Sample requirements" formatRequirementCount={(met, total) => `${met} of ${total} checks met` } />
{ if (phase === "checking") { reset(); return; } setValue(sample); setError(""); input.current?.focus({ preventScroll: true }); }} > {phase === "checking" ? "Cancel check" : "Use sample phrase"} Check sample

Illustrative requirements, not a password-strength rating.

)}

This form runs in your browser. No account is created and no password is saved.

); } export default function AgentExample() { return (
); }