"use client"; import "./components/ui/tidal.css"; import { useId, useState, type ReactNode } from "react"; import { TidalPhoneInput, type TidalPhonePasteRequest, type TidalPhoneValue } from "./components/ui/phone-input"; import "./components/ui/phone-input.css"; const tidalExampleStyles = ".tidal-scope .phone-input-demo,\n.tidal-scope .phone-input-demo * {\n box-sizing: border-box;\n}\n\n.tidal-scope .phone-input-demo {\n container: phone-input-demo / inline-size;\n display: grid;\n width: min(100%, 680px);\n min-width: 0;\n gap: 16px;\n color: var(--t-ink);\n}\n\n.tidal-scope .phone-input-demo-actions {\n display: flex;\n flex-wrap: wrap;\n gap: 9px;\n}\n\n.tidal-scope .phone-input-demo-actions button {\n display: inline-flex;\n min-width: 128px;\n min-height: 44px;\n align-items: center;\n justify-content: center;\n padding: 9px 14px;\n border: 1px solid var(--t-border);\n border-radius: var(--t-radius-control);\n background: var(--t-surface);\n color: var(--t-ink);\n font: inherit;\n font-size: 12px;\n font-weight: 700;\n cursor: pointer;\n transition:\n color 140ms,\n background-color 140ms,\n border-color 140ms,\n transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .phone-input-demo-actions button[type=\"submit\"] {\n border-color: var(--t-ink);\n background: var(--t-ink);\n color: var(--t-surface);\n}\n\n.tidal-scope .phone-input-demo-actions button:hover {\n border-color: var(--t-ink);\n}\n\n.tidal-scope .phone-input-demo-actions button[type=\"reset\"]:hover {\n background: var(--t-ink);\n color: var(--t-surface);\n}\n\n.tidal-scope .phone-input-demo-actions button:active {\n transform: scale(0.98);\n}\n\n.tidal-scope .phone-input-demo-actions button:focus-visible {\n outline: 2px solid var(--t-accent);\n outline-offset: 3px;\n}\n\n.tidal-scope .phone-input-demo-status,\n.tidal-scope .phone-input-demo-note {\n min-width: 0;\n margin: 0;\n color: var(--t-muted);\n font-size: 11px;\n line-height: 1.5;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .phone-input-demo-note {\n padding-block-start: 10px;\n border-block-start: 1px solid var(--t-border);\n}\n\n@container phone-input-demo (max-width: 360px) {\n .tidal-scope .phone-input-demo-actions {\n display: grid;\n grid-template-columns: minmax(0, 1fr);\n }\n\n .tidal-scope .phone-input-demo-actions button {\n width: 100%;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .tidal-scope .phone-input-demo-actions button {\n transition: none;\n }\n\n .tidal-scope .phone-input-demo-actions button:active {\n transform: none;\n }\n}"; const COUNTRIES = [ { code: "US", label: "United States", dialCode: "+1" }, { code: "CA", label: "Canada", dialCode: "+1" }, { code: "GB", label: "United Kingdom", dialCode: "+44" }, { code: "AU", label: "Australia", dialCode: "+61" }, ] as const; const INITIAL_VALUE: TidalPhoneValue = { country: "US", number: "202 555 0147", extension: "204", }; function parseSamplePaste({ text, value, countries, }: TidalPhonePasteRequest): TidalPhoneValue | null { const trimmed = text.trim().replace(/^tel:/i, ""); if (!trimmed) return null; const extensionMatch = trimmed.match(/(?:ext\.?|x)\s*([0-9]+)\s*$/i); const withoutExtension = extensionMatch ? trimmed.slice(0, extensionMatch.index).trim() : trimmed; const currentCountry = countries.find( (country) => country.code === value.country, ); const prefixedCountry = (currentCountry && withoutExtension.startsWith(currentCountry.dialCode) ? currentCountry : countries .filter((candidate) => withoutExtension.startsWith(candidate.dialCode), ) .sort((a, b) => b.dialCode.length - a.dialCode.length)[0]) ?? undefined; const country = prefixedCountry ?? currentCountry; const number = prefixedCountry ? withoutExtension.slice(prefixedCountry.dialCode.length).trim() : withoutExtension; return { country: country?.code ?? value.country, number, extension: extensionMatch?.[1] ?? value.extension, }; } export function PhoneInputDemo() { const generatedId = useId().replace(/:/g, ""); const [value, setValue] = useState(INITIAL_VALUE); const [error, setError] = useState(null); const [status, setStatus] = useState( "Edit the sample number or paste a number with an extension.", ); return (
{ event.preventDefault(); const formData = new FormData(event.currentTarget); setError(null); setStatus( `Prepared ${String(formData.get("contact-country"))} ${String(formData.get("contact-phone"))}${formData.get("contact-extension") ? ` extension ${String(formData.get("contact-extension"))}` : ""} locally.`, ); }} onReset={(event) => { if (event.defaultPrevented) return; setValue(INITIAL_VALUE); setError(null); setStatus("Sample phone details reset."); }} > { setValue(next); setError(null); setStatus( field === "country" ? "Country context updated." : "Sample phone details updated.", ); }} parsePaste={parseSamplePaste} form={generatedId} countryName="contact-country" numberName="contact-phone" extensionName="contact-extension" required numberInputProps={{ placeholder: "202 555 0147", onInvalid: (event: import("react").InvalidEvent) => { event.preventDefault(); setError("Enter a phone number for this local sample."); setStatus("Check the phone number."); event.currentTarget.focus({ preventScroll: true }); }, }} />

{status}

Sample data. Paste handling uses this preview’s local adapter.

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