رافع الملفات واجهة البرمجة
الخصائص والفتحات والنصوص والتنسيق في رافع الملفات من slotsmith.
الفتحات
في FileUploader عدد 13 من الفتحات. مرّر بديلًا لأي منها في components، وكل فتحة لا تمرّرها تبقى على بديلها الافتراضي. فتحات العناصر تستقبل خصائص DOM فيناسبها عنصر المكتبة كما هو، وفتحات الأدوات تستقبل خصائص مسمّاة وتحتاج عادة إلى بضعة أسطر من المحوّل.
| الاسم | النوع | الخصائص التي تستقبلها | البديل الافتراضي | سمات data-* |
|---|---|---|---|---|
Root | <element> | خصائص DOM: | مصدر البديل |
|
Dropzone | <element> | خصائص DOM: | مصدر البديل |
|
Input | <element> | خصائص DOM: | مصدر البديل | — |
Icon | {widget} |
| مصدر البديل |
|
Empty | {widget} |
| مصدر البديل | — |
Trigger | {widget} |
| مصدر البديل | — |
List | <element> | خصائص DOM:
| مصدر البديل | — |
Item | <element> | خصائص DOM: | مصدر البديل |
|
Thumbnail | {widget} |
| مصدر البديل | — |
ItemMeta | {widget} |
| مصدر البديل | — |
Progress | {widget} |
| مصدر البديل |
|
Action | {widget} |
| مصدر البديل |
|
Rejections | {widget} |
| مصدر البديل | — |
الخصائص
كل خصائص FileUploader مجمّعة كما في توثيق المكتبة. الحالة المتحكَّم بها تأتي أزواجًا: مرّر القيمة مع معالج تغييرها، أو القيمة الابتدائية وحدها لتبقى الحالة داخل المكوّن.
| الاسم | النوع | الافتراضي | الوصف |
|---|---|---|---|
| Selection | |||
accept | string | | — | |
multiple | boolean |
| Allow more than one file. Defaults to |
max | number | — | How many items the list may hold in total. |
max | number | — | |
min | number | — | |
validate | ( | — | Your own rule. Return a message to refuse the file, or nothing to allow it. |
disabled | boolean | — | Nothing can be picked, dropped or removed. |
| Value | |||
value | UploadItem< | — | Controlled items. |
on | ( | — | Called with the new items after every change. |
default | InitialValue< | — | Where an uncontrolled uploader starts: items, files or URLs. |
on | ( | — | Convenience for picker mode: the picked files, whenever they change. |
on | ( | — | Convenience for upload mode: the stored URLs, whenever they change. |
name | string | — | The form field name. A plain HTML form then submits every item under it: a file picked in the browser as the file, as |
| Uploading | |||
upload | UploadFn< | — | Sends one file. Omit it and nothing is ever uploaded — the component becomes a picker and items stay |
auto | boolean | true | Start uploading as soon as files are picked. Defaults to |
concurrency | number | 3 | How many uploads may run at once. Defaults to |
on | ( | — | Called for each file that finished uploading. |
on | ( | — | Called when an upload fails. |
on | ( | — | Called with the files the constraints turned away. |
| Rendering | |||
variant | FileUploaderVariant | dropzone | How the component is laid out. Defaults to |
components | Partial< | — | Replace any part; the rest fall back to |
labels | Partial< | — | Override any text. Wins over |
locale | LocaleInput | the provider's | The language: a locale object, or the tag of one given to |
validation | Partial< | — | Wording for rejection messages. |
slot | FileUploaderSlotProps | — | Extra DOM props for the element parts. |
preview | boolean | | — | Object-URL previews for images. |
hide | boolean | — | Hide the item list, e.g. when you render the files yourself. |
children | ReactNode | — | Rendered inside the drop zone, under the title. |
capture | boolean | — | Swallow drops that miss the drop zone, so the browser doesn't open the file. |
virtual | FileUploaderVirtualOptions | — | Renders only the items in view, for batches of hundreds: pass the virtualizer hook ( |
تُمرَّر أي خاصية أخرى إلى العنصر الجذر <div>.
النصوص واللغات
كل نص يعرضه FileUploader أو يعلنه، مع قيمته الافتراضية بالإنجليزية. مرّر labels لتغيير بعضها في مكوّن واحد، أو locale لتحويل كل النصوص إلى لغة أخرى. العرض أدناه يفعل الأمرين.
| المفتاح | النوع | الافتراضي بالإنجليزية | الوصف |
|---|---|---|---|
title | ReactNode | "Drag and drop, | The drop zone's headline. |
hint | ( | hint(يطبع | The line under it; the default names the limits. |
drop | ReactNode | "Drop to add" | While a file is over the zone. |
browse | ReactNode | "Browse" | The browse button. |
dropzone | string | "Add files" | Accessible name of the drop zone. |
remove | string | "Remove file" | |
retry | string | "Retry upload" | |
cancel | string | "Cancel upload" | |
progress | ( | progress(يطبع | Accessible name of an item's progress bar. |
ready | ReactNode | "Ready" | Status wording per item state. |
uploading | ReactNode | "Uploading…" | |
done | ReactNode | "Uploaded" | |
failed | ReactNode | "Failed" | |
preview | ( | preview(يطبع | Accessible name for a preview. |
dismiss | string | "Dismiss" | Dismisses the rejection list. |
rejected | ( | rejectedTitle(يطبع | Announced when files are refused. |
رسائل التحقق
رسائل الملفات التي ترفضها القيود، وهي قسم ثانٍ من النصوص. مرّر validationLabels لتغيير بعضها في مكوّن واحد، وحزمة locale تترجمها مع بقية النصوص.
| المفتاح | النوع | الافتراضي بالإنجليزية | الوصف |
|---|---|---|---|
wrong | ( | wrongType(يطبع | A file that matches none of the |
too | ( | tooLarge(يطبع | A file over |
too | ( | tooSmall(يطبع | A file under |
too | ( | tooMany(يطبع | A file past |
import { FileUploader } from "slotsmith/file-uploader";
import { de } from "slotsmith/locales/de";
export default function Labels() {
return (
<FileUploader
multiple
accept="image/*"
maxSize={2 * 1024 * 1024}
// Every string in German, the rejection messages included, from the ready-made pack…
locale={de}
// …except these, replaced for this uploader only. `labels` covers the parts' text,
labels={{ title: "Belege hierher ziehen", browse: "Belege auswählen" }}
// and `validationLabels` the messages for refused files.
validationLabels={{ wrongType: (name) => `${name}: bitte nur Bilder` }}
/>
);
}حزم اللغات الجاهزة ودعم الكتابة من اليمين إلى اليسار واللغة على مستوى التطبيق موضّحة في صفحة اللغات.
التنسيق
أسماء الأصناف التي تضعها البدائل الافتراضية في FileUploader على عناصرها، والمتغيرات التي يقرؤها ملف تنسيقه. اضبط متغيرًا على المكوّن أو على أي عنصر يحيط به لتغيير مظهره، واستهدف الصنف فقط لما لا يغطيه متغير.
| الصنف | الفتحة |
|---|---|
.sfu | |
.sfu__actions | — |
.sfu__error | — |
.sfu__compact | — |
.sfu__hint | — |
.sfu__input | |
.sfu__icon | |
.sfu__copy | |
.sfu__title | — |
.sfu__browse | |
.sfu__thumb | |
.sfu__thumb-img | — |
.sfu__meta | |
.sfu__name | — |
.sfu__sub | — |
.sfu__progress | |
.sfu__progress-bar | — |
.sfu__action | |
.sfu__rejections | |
.sfu__zone | |
.sfu__list | |
.sfu__item |
| المتغير | الطبقة |
|---|---|
--sfu-accent | هذا المكوّن |
--sfu-bg | هذا المكوّن |
--sfu-border | هذا المكوّن |
--sfu-danger | هذا المكوّن |
--sfu-font-size | هذا المكوّن |
--sfu-gap | هذا المكوّن |
--sfu-hover | هذا المكوّن |
--sfu-muted | هذا المكوّن |
--sfu-radius | هذا المكوّن |
--sfu-surface | هذا المكوّن |
--sfu-text | هذا المكوّن |
--sfu-tile-size | هذا المكوّن |
--ss-accent | مشترك بين كل المكوّنات |
--ss-border | مشترك بين كل المكوّنات |
--ss-danger | مشترك بين كل المكوّنات |
--ss-font-size | مشترك بين كل المكوّنات |
--ss-hover | مشترك بين كل المكوّنات |
--ss-muted | مشترك بين كل المكوّنات |
--ss-radius | مشترك بين كل المكوّنات |
--ss-surface | مشترك بين كل المكوّنات |
--ss-text | مشترك بين كل المكوّنات |
تنتقل كل المتغيرات إلى قيمها الداكنة تحت .dark, [data-theme="dark"]، على الصفحة أو على أي عنصر يحيط بالمكوّن.