TextArea
نمای کلیimport { TextArea, TextAreaResize } from '@nili/ui';این همان صفحهی نمای کلیِ خود کتابخانه است که زنده رندر میشود. زبان یا تم را از هدر عوض کنید، همراهش میآید.
برچسب، راهنما و خطا
وجود error است که فیلد را نامعتبر میکند، پس حاشیه و پیام هیچوقت با هم نمیجنگند — پرچم جداگانهای به نام invalid نیست که یادتان برود.
مارکداون پشتیبانی میشود.
لطفاً دستکم بیست نویسه بنویسید.
import { TextArea } from "@nili/ui"
export function Example() {
return (
<>
<TextArea
label="Description"
placeholder="Tell us a little about the project…"
hint="Markdown is supported."
rows={4}
/>
<TextArea
label="Description"
defaultValue="Too short"
error="Please write at least twenty characters."
rows={4}
/>
</>
)
}شمارندهٔ نویسه
showCount نسبت used / limit را زیر فیلد میگذارد. countLimit یک سقف نرم میگذارد بدون اینکه maxLength هم ست شود — maxLength سخت، انتهای یک پیست را بیصدا میبلعد، و این بدتر از آن است که به کاربر نشان دهید از حد گذشته.
import { TextArea } from "@nili/ui"
export function Example() {
const [value, setValue] = useState("")
return (
<>
{/* soft limit: typing past it is allowed, and shown */}
<TextArea
label="Bio"
showCount
countLimit={120}
value={value}
onChange={(e) => setValue(e.target.value)}
rows={3}
/>
{/* hard limit */}
<TextArea label="Tweet" showCount maxLength={280} rows={3} />
{/* custom format */}
<TextArea
label="Notes"
showCount
countLimit={200}
formatCount={(used, limit) => `${used} of ${limit}`}
rows={3}
/>
</>
)
}دستگیرههای تغییر اندازه
اینکه مرورگر کدام دستگیرهها را بدهد. vertical پیشفرض است؛ none برای فیلدی در چیدمانی تنگ که نباید از ریخت بیفتد.
import { TextArea } from "@nili/ui"
export function Example() {
return (
<>
<TextArea label="Vertical (default)" resize="vertical" rows={3} />
<TextArea label="Both axes" resize="both" rows={3} />
<TextArea label="Fixed" resize="none" rows={3} />
</>
)
}تغییر اندازهٔ خودکار
بهجای اسکرول، تا maxRows با محتوا رشد میکند. پیشفرض خاموش است: فیلدی که با هر کلید اندازهاش عوض شود همهچیزِ زیرش را جابهجا میکند، و این در فرم بلند آزاردهنده است.
import { TextArea } from "@nili/ui"
export function Example() {
return (
<TextArea
label="Message"
autoResize
maxRows={8}
rows={2}
placeholder="Type a few lines…"
/>
)
}TextArea
extends Omit< ComponentPropsWithoutRef<'textarea'>, 'size' >
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| disabled | boolean | — | |
| required | boolean | — | |
| readOnly | boolean | — | |
| checked | boolean | — | |
| defaultChecked | boolean | — | |
| placeholder | string | — | |
| value | string | — | |
| defaultValue | string | — | |
| name | string | — | |
| maxLength | number | — | |
| rows | number | 4 | |
| autoComplete | string | — | |
| aria-label | string | — | |
| label | ReactNode | — | |
| hint | ReactNode | — | |
| error | ReactNode | — | Validation message. Its presence is what marks the field invalid, so the border and the message can never disagree. |
| resize | none | vertical | both | vertical | Which handles the browser offers. |
| autoResize | boolean | false | Grow with the content instead of scrolling, up to `maxRows`. Off by default: a field that resizes on every keystroke moves everything below it, which is unpleasant in a long form. |
| maxRows | number | 10 | |
| showCount | boolean | false | Shows `used / limit` under the field. Pass a number to set the limit without also passing `maxLength` — see the note in the component about why those are different things. |
| countLimit | number | — | Soft limit for the counter. Defaults to `maxLength` when that is set. |
| formatCount | (used: string, limit: string) => string | — | Formats the counter, e.g. `` (used, limit) => `${used} of ${limit}` ``. |
| locale | string | — | BCP-47 tag driving the counter digits (`'fa'` → Persian). Defaults to the ambient locale from `NiliProvider`. |
| rootClassName | string | — | Wrapper class. Use `className` for the `<textarea>` itself. |
| fieldClassName | string | — | Class for the bordered field box. |
TextAreaControl
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| resize | none | vertical | both | vertical |
TextAreaCounter
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| over | 'true' | 'false' | false | |
| disabled | 'true' | 'false' | false |
TextAreaField
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| invalid | 'true' | 'false' | false |
TextAreaFooter
داخلیTextAreaGrip
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| disabled | 'true' | 'false' | false |