حقل نص
حقل إدخال أصلي يُعرض على الخادم ولا يشحن أي JavaScript. الأنواع ترفض حقلًا بلا اسم.
server - 0 KB
حقل نص
server - 0 KBحقل إدخال أصلي يُعرض على الخادم ولا يشحن أي JavaScript. الأنواع ترفض حقلًا بلا اسم.
جرّبه
size
invalid
fullWidth
الشيفرة
input.tsx
import { Input } from 'topclassui/input'
<div className="grid max-w-sm gap-1">
<label htmlFor="input-playground" className="text-sm font-medium text-body">Email</label>
<Input id="input-playground" name="email" type="email" autoComplete="email" />
</div>خارج Field يحتاج Input إلى id أو aria-label أو aria-labelledby: الأنواع ترفض حقلًا بلا تسمية.
كل الحالات، بدون تمرير الفأرة
6 حالاتأو استورده من الحزمة
topclassui/input
import { Input } from 'topclassui/input'ثبّت مرة واحدة:npm i topclassui@beta zod
أمثلة
- لـ
maxLengthقيمة افتراضية حسب النوع: 512 للنص، و254 للبريد، و32 للهاتف، و2048 للرابط، و256 للبحث وكلمة المرور. مرّر رقمك، أوmaxLength={null}لإلغاء الحد. - الرقم والتاريخ ومربع الاختيار بلا حد للأحرف: الرقم تحدّه القيم الدنيا والعليا والخطوة.
- يحتفظ بعرضه الخاص،
--tc-input-width، ويقلّ في صف ضيّق.fullWidthيملأ الحاوية؛ وبجانب Button أعطِ Input الصنفflex-1. size="custom"لا يضيف أي صنف للحجم، فأصنافك أنت تحدد الارتفاع والحشو وحجم الخط.- الحاوية التي تقص محتواها (
overflow-hidden) تحتاج حشوًا بمقدار 4px، وإلا قطعت حلقة التركيز.
labelled
We never share it
labelled.tsx
import { Input } from 'topclassui/input'
/** Outside a Field: a label points at the id, and aria-describedby ties the hint on. */
export default function Demo() {
return (
<div className="grid max-w-sm gap-1">
<label htmlFor="demo-email" className="text-sm font-medium text-body">Email</label>
<Input
id="demo-email"
name="email"
type="email"
autoComplete="email"
required
fullWidth
aria-describedby="demo-email-hint"
/>
<span id="demo-email-hint" className="text-xs text-muted">We never share it</span>
</div>
)
}
types
types.tsx
import { Input } from 'topclassui/input'
/** Each text type takes its own default cap; a number or a date takes none at all. */
export default function Demo() {
return (
<div className="grid max-w-sm gap-3">
<Input fullWidth type="email" autoComplete="email" placeholder="you@example.com" aria-label="Email" />
<Input fullWidth type="password" autoComplete="current-password" placeholder="Password" aria-label="Password" />
<Input fullWidth type="search" placeholder="Search" aria-label="Search" />
<Input fullWidth type="tel" autoComplete="tel" placeholder="+962 7 9000 0000" aria-label="Phone" />
<Input fullWidth type="url" placeholder="https://example.com" aria-label="Website" />
<Input fullWidth type="number" min={0} max={120} step={1} placeholder="Age" aria-label="Age" />
<Input fullWidth type="date" aria-label="Start date" />
<Input fullWidth maxLength={6} placeholder="Six characters" aria-label="Short code" />
<Input fullWidth maxLength={null} placeholder="No cap" aria-label="Uncapped" />
</div>
)
}
sizes
sizes.tsx
import { Input } from 'topclassui/input'
export default function Demo() {
return (
<div className="flex flex-wrap items-center gap-3">
<Input size="xs" placeholder="Extra small" aria-label="Extra small" />
<Input size="sm" placeholder="Small" aria-label="Small" />
<Input placeholder="Medium" aria-label="Medium" />
<Input size="lg" placeholder="Large" aria-label="Large" />
<Input size="xl" placeholder="Extra large" aria-label="Extra large" />
</div>
)
}
full-width
full-width.tsx
import { Input } from 'topclassui/input'
export default function Demo() {
return (
<div className="grid max-w-md justify-items-start gap-3">
<Input fullWidth placeholder="Fills its container" aria-label="Full width" />
<Input placeholder="Keeps its own width" aria-label="Own width" />
</div>
)
}
row
row.tsx
import { Button } from 'topclassui/button'
import { Input } from 'topclassui/input'
/** A grid form sizes its track to the content, so only an input that can shrink fits a phone. */
export default function Demo() {
return (
<form className="grid gap-4">
<div data-row="own" className="flex gap-2">
<Input name="first" placeholder="First name" aria-label="First name" />
<Input name="last" placeholder="Last name" aria-label="Last name" />
</div>
<div data-row="grow" className="flex gap-2">
<Input name="city" className="flex-1" placeholder="City" aria-label="City" />
<Input name="postcode" className="flex-1" placeholder="Postcode" aria-label="Postcode" />
</div>
<div data-row="alone">
<Input name="phone" type="tel" placeholder="+962 7 9000 0000" aria-label="Phone" />
</div>
{/* flex-1 makes the field the one that gives way, so the Button keeps its whole label. */}
<div data-row="action" className="flex gap-2">
<Input name="invite" type="email" className="flex-1" placeholder="name@company.com" aria-label="Invite by email" />
<Button>Send invite</Button>
</div>
</form>
)
}
custom-size
custom-size.tsx
import { Input } from 'topclassui/input'
/** custom emits no height, padding or type step, so the caller's own classes set them. */
export default function Demo() {
return (
<div className="flex flex-wrap items-center gap-3">
<Input placeholder="On the scale" aria-label="On the scale" />
<Input size="custom" className="h-14 px-5 text-lg" placeholder="Your own size" aria-label="Your own size" />
</div>
)
}
skeleton
skeleton.tsx
import { InputSkeleton } from 'topclassui/input'
/** Its own width at each size, as the field has, and the whole column with fullWidth. */
export default function Demo() {
return (
<div className="grid max-w-sm gap-3">
<InputSkeleton size="sm" />
<InputSkeleton />
<InputSkeleton size="lg" />
<InputSkeleton fullWidth />
</div>
)
}
بالعربية، من اليمين إلى اليسار
rtl.tsx
import { Input } from 'topclassui/input'
export default function Demo() {
return (
<div dir="rtl" lang="ar" className="grid max-w-sm gap-3">
<label htmlFor="demo-name-ar" className="text-sm font-medium text-body">الاسم</label>
<Input id="demo-name-ar" fullWidth placeholder="اكتب اسمك" />
<Input type="email" fullWidth defaultValue="omar@example.com" aria-label="البريد الإلكتروني" />
<Input type="number" fullWidth defaultValue="-1234.5" aria-label="الرصيد" />
<Input invalid fullWidth defaultValue="٠٧٩" aria-label="رقم الهاتف" />
</div>
)
}
الخصائص
لوحة المفاتيح وإمكانية الوصول
- الاسم مطلوب: تسمية
<label htmlFor>تشير إلىid، أوaria-label، أوaria-labelledby. invalidيضبط aria-invalid، ويتحوّل الإطار إلى لون الخطر ويزداد سمكًا، فلا يعتمد الخطأ على اللون وحده.- على شاشة اللمس لا يقل النص عن 16px، كي لا يكبّر iOS الصفحة عند التركيز.
من اليمين إلى اليسار
يبدأ النص من اليمين. حقول البريد والأرقام والهاتف والروابط تبقى من اليسار إلى اليمين، في جهة النموذج.
الخادم والمتصفح
يُعرض على الخادم ولا يرسل أي JavaScript.
الملفات: index.tsx.
على الشارة: server - 0 KB.