FileUpload
نمای کلیimport { FileFormatIcon, FileUploadArea, FileUploadCard, ImageUpload, ImageUploadShape } from '@nili/ui';این همان صفحهی نمای کلیِ خود کتابخانه است که زنده رندر میشود. زبان یا تم را از هدر عوض کنید، همراهش میآید.
ناحیهٔ بارگذاری
هدفِ رهاکردن فایل. onFiles یک آرایهٔ File میگیرد، چه فایل رها شده باشد چه از پنجرهٔ انتخاب آمده باشد، پس فقط یک مسیر کد برای مدیریت هست. زیرش یک input واقعی است، پس کاربر کیبورد و صفحهخوان هم انتخابگر را میگیرد.
import { FileUploadArea } from "@nili/ui"
export function Example() {
return (
<FileUploadArea
multiple
accept="image/*,application/pdf"
label="Upload files"
title="Choose a file or drag it here"
description="PNG, JPG or PDF, up to 10 MB."
onFiles={(files) => upload(files)}
/>
)
}حالتهای ناحیهٔ بارگذاری
invalid برای فایلی که رد شده — نوع اشتباه، حجم زیاد — و disabled وقتی سهمیه تمام شده یا فرم در حال ارسال است.
import { FileUploadArea } from "@nili/ui"
export function Example() {
return (
<>
<FileUploadArea label="Upload" onFiles={onFiles} />
<FileUploadArea label="Upload" invalid onFiles={onFiles} />
<FileUploadArea label="Upload" disabled onFiles={onFiles} />
</>
)
}کارت فایل
یک فایل بارگذاریشده: آیکون قالب، نام، حجم و وضعیتش. progress نوار را حرکت میدهد؛ onRetry همراه خطا ظاهر میشود و onRemove همیشه. هر دو به برچسب نیاز دارند، چون دکمهها آیکوناند.
import { FileUploadCard } from "@nili/ui"
export function Example() {
return (
<>
<FileUploadCard
fileName="annual-report.pdf"
fileSize="2.4 MB"
status="progress"
progress={62}
onRemove={cancel}
removeLabel="Cancel upload"
/>
<FileUploadCard
fileName="photo.png"
fileSize="840 KB"
status="success"
onRemove={remove}
removeLabel="Remove file"
/>
<FileUploadCard
fileName="archive.zip"
fileSize="18 MB"
status="error"
errorMessage="File is larger than 10 MB."
onRetry={retry}
retryLabel="Try again"
onRemove={remove}
removeLabel="Remove file"
/>
</>
)
}آیکون قالب فایل
آیکون از نام فایل درمیآید، پس فهرستی از بارگذاریهای متنوع خودش رنگ میگیرد. وقتی پسوند آن چیزی نیست که میخواهید نشان دهید، با color بازنویسیاش کنید.
import { FileFormatIcon } from "@nili/ui"
export function Example() {
return (
<>
<FileFormatIcon fileName="report.pdf" />
<FileFormatIcon fileName="sheet.xlsx" />
<FileFormatIcon fileName="photo.png" size="xs" />
<FileFormatIcon fileName="anything.bin" color="purple" />
</>
)
}بارگذاری تصویر
گونهٔ پیشنمایشمحور، برای آواتار، نشان شرکت یا کاور. shape قاب و برشی را که پیشنمایش تلویحاً میرساند تعیین میکند؛ alignment کنترلها را زیر تصویر یا کنارش میگذارد.
import { ImageUpload, Button } from "@nili/ui"
export function Example() {
return (
<>
<ImageUpload
shape="avatar"
label="Profile photo"
hint="JPG or PNG, at least 256×256."
onFiles={(files) => upload(files[0])}
actions={<Button size="xs" appearance="stroke">Choose file</Button>}
/>
<ImageUpload shape="16:9" alignment="horizontal" label="Cover" onFiles={onFiles} />
</>
)
}FileCard
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| status | progress | success | error | progress |
FileFormatIcon
extends Omit< ComponentPropsWithoutRef<'span'>, 'color' >
محورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| color | red | orange | yellow | green | teal | sky | blue | purple | pink | gray | gray | |
| size | md | xs | md |
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| fileName* | string | — |
FileProgress
داخلیFileProgressBar
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| status | progress | success | error | progress |
FileUploadArea
extends Omit< ComponentPropsWithoutRef<'label'>, 'onDrop' | 'onChange' | 'title' >
محورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| disabled | boolean | false | |
| invalid | boolean | false | |
| dragging | 'true' | 'false' | false |
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| onFiles* | (files: File[]) => void | — | |
| accept | string | — | |
| multiple | boolean | false | |
| title | ReactNode | Choose a file or drag it here | |
| description | ReactNode | — | |
| icon | ReactNode | — | |
| label | string | Upload file | Accessible name for the hidden file input. |
FileUploadCard
extends Omit< ComponentPropsWithoutRef<'div'>, 'children' >
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| fileName* | string | — | |
| fileSize | string | — | Pre-formatted — size formatting is a locale decision. |
| status | error | success | progress | progress | |
| progress | number | 0 | 0–100. Ignored unless `status` is `'progress'`. |
| errorMessage | ReactNode | — | |
| onRemove | () => void | — | |
| onRetry | () => void | — | |
| removeLabel | string | Remove | |
| retryLabel | string | Retry |
ImageUpload
extends Omit< ComponentPropsWithoutRef<'div'>, 'onChange' >
محورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| shape | avatar | company | square | 4:3 | 16:9 | square |
بقیهی پراپها
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| children | ReactNode | — | |
| aria-label | string | — | |
| alignment | vertical | horizontal | vertical | |
| src | string | — | Preview URL. Absent means the Figma "Empty" state. |
| onFiles* | (files: File[]) => void | — | |
| accept | string | image/* | |
| label | string | Upload image | |
| hint | ReactNode | — | |
| actions | ReactNode | — | |
| alt | string |
ImageUploadRoot
داخلیمحورهای واریانت — از تعریف cva کامپوننت
| پراپ | نوع | پیشفرض | توضیح |
|---|---|---|---|
| alignment | vertical | horizontal | vertical |