Smart Form Input
A component for displaying a smart form input
Email
Email input
email-example.tsx
1"use client";23import { useState } from "react";4import { SmartFormInput } from "@/registry/ui";56export function SmartFormInputEmailExample() {7 const [email, setEmail] = useState("");89 return (10 <div className="w-2/3 md:w-3/4 flex justify-center items-center px-4">11 <SmartFormInput12 type="email"13 label="Email"14 value={email}15 onChange={setEmail}16 required17 />18 </div>19 );20}
Password
Password input
password-example.tsx
1"use client";23import { useState } from "react";4import { SmartFormInput } from "@/registry/ui";56export function SmartFormInputPasswordExample() {7 const [password, setPassword] = useState("");89 return (10 <div className="w-2/3 md:w-3/4 flex justify-center items-center px-4">11 <SmartFormInput12 type="password"13 label="Password"14 value={password}15 onChange={setPassword}16 required17 asyncValidate={async (password: string) => {18 const res = await fetch("/api/hibp", {19 method: "POST",20 body: JSON.stringify({ password }),21 });2223 const data = await res.json();2425 if (data.breached) {26 return "This password has been exposed in a data breach";27 }2829 return null;30 }}31 />32 </div>33 );34}
Custom Validation
Custom validation input
custom-validation-example.tsx
1"use client";23import { useState } from "react";4import { SmartFormInput } from "@/registry/ui";56export function SmartFormInputCustomValidationExample() {7 const [username, setUsername] = useState("");89 return (10 <div className="w-2/3 md:w-3/4 flex justify-center items-center px-4">11 <SmartFormInput12 label="Username"13 value={username}14 onChange={setUsername}15 validate={(val: string) => {16 if (val.length < 3) return "Must be at least 3 characters";17 if (!/^[a-z0-9_]+$/i.test(val)) return "Invalid characters";18 return null;19 }}20 />21 </div>22 );23}
Installation & source
Install via the shadcn CLI or copy the registry files manually.
bash
npx shadcn@latest add @tt-ui/smart-form-input
Props
| Name | Type | Default | Description |
|---|---|---|---|
| type | string | text | The type of the input |