Components
FileItem
Unstable: an attachment or an upload, its name with real progress and a cancel button, a success mark, or a red edge, a written reason and a retry button. Import it from @nizivo/react/unstable/file-item.
Examples
Basic
Three states of one upload: under way, done, and failed with its reason.
import type { JSX } from 'react';
import { FileItem } from '@nizivo/react/unstable/file-item';
export function FileItemExample(): JSX.Element {
return (
<div style={{ display: 'grid', gap: 12, maxInlineSize: 420 }}>
<FileItem
name="autumn-lookbook.pdf"
status="uploading"
progress={62}
detail="2.4 of 3.9 MB · 62%"
/>
<FileItem name="autumn-lookbook.pdf" status="done" detail="3.9 MB · Uploaded" />
<FileItem
name="autumn-lookbook.pdf"
status="error"
detail="Upload failed — file is over 20 MB"
/>
</div>
);
}
Import
import { FileItem } from '@nizivo/react/unstable/file-item';
// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css and @nizivo/react/css/progress-bar.css
import '@nizivo/react/css/file-item.css';Static or interactive
Server. No client JavaScript: its buttons call onCancel and onRetry.
How to choose.
States
status is uploading (a ProgressBar named "Uploading
autumn-lookbook.pdf", with progress from 0 to 100, and a cancel button), done (a success mark
read as "Uploaded") or error (a red edge, the reason in detail and a retry button). Each button
is named after the file. detail is the line under the name: the sizes, the percentage, or why it
failed.
Props
Server component Renders data-slot="file-item" with the class nz-file-item. Props: FileItemProps. Source: src/unstable/file-item/file-item.tsx.
| Name | Type | Default | Description |
|---|---|---|---|
detail | ReactNode | – | The line under the name: "2.4 of 3.9 MB · 62%", "3.9 MB · Uploaded", or why it failed. |
icon | ReactNode | – | Replaces the file-text mark, for example an image thumbnail. |
labels | Partial<FileItemLabels> | – | |
locale | string | 'en-US' | BCP 47 tag for the progress value. |
namerequired | string | – | The file's name: "autumn-lookbook.pdf". |
onCancel | () => void | – | |
onRetry | () => void | – | |
progress | number | – | While uploading, from 0 to 100. |
render | RenderProp<Record<string, never>> | – | Must render a |
statusrequired | FileItemStatus"uploading""done""error" | – |
- Also takes every attribute of
<div>exceptchildren. (Omit<ComponentPropsWithRef<"div">, "children">)
render takes an element, or, in client code, a function of the props and no state.
Other exports
FileItemLabelstypeimport type { FileItemLabels } from '@nizivo/react/unstable/file-item'FileItem's own strings (§16.4): serialisable, English defaults.
Name Type Default Description cancelrequiredstring'Cancel upload of {name}'donerequiredstring'Uploaded'Read after a done file's name, for the success mark.
progressrequiredstring'Uploading {name}'The progress bar's name:
{name}is the file's.retryrequiredstring'Retry upload of {name}'FileItemPropstypeimport type { FileItemProps } from '@nizivo/react/unstable/file-item'The props of
FileItem, listed above.FileItemStatustypeimport type { FileItemStatus } from '@nizivo/react/unstable/file-item'Where the upload is: uploading, done or failed.
type FileItemStatus = "uploading" | "done" | "error"
Data attributes and slots
Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.
| Slot | Rendered by | Data attributes |
|---|---|---|
file-item.nz-file-item | FileItemroot (takes render) |
|
file-item-action.nz-file-item-action | FileIteminner element (CSS only); interactive, focus: self | none |
file-item-detail.nz-file-item-detail | FileIteminner element (CSS only) | none |
file-item-name.nz-file-item-name | FileIteminner element (CSS only) | none |
CSS hooks
Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.
This stylesheet reads no public hook.
Layers: nz.components. Classes: .nz-file-item, .nz-file-item-action, .nz-file-item-detail, .nz-file-item-icon, .nz-file-item-mark, .nz-file-item-name, .nz-file-item-progress, .nz-file-item-text, .nz-progress-bar-track.
Tokens this stylesheet reads (25)
--nz-bg-brand-subtle, --nz-bg-critical-subtle, --nz-bg-surface, --nz-border-critical, --nz-border-subtle, --nz-border-width-default, --nz-font-body-s, --nz-font-label-m, --nz-icon-brand, --nz-icon-critical, --nz-icon-secondary, --nz-icon-success, --nz-radius-full, --nz-radius-lg, --nz-radius-sm, --nz-size-icon-md, --nz-space-1, --nz-space-1-5, --nz-space-10, --nz-space-3, --nz-space-4, --nz-space-6, --nz-text-critical, --nz-text-primary, --nz-text-secondary
Accessibility
These parts are interactive. Each gets the focus outline and touch-action rule from @nizivo/react/css/base.css (the nz.base layer), so the floor survives a restyle:
file-item-action: draws the focus outline itself on keyboard focus.
Keyboard
To be written.
Fieldset
A native fieldset and legend for related controls, such as a row of switches or checkboxes, with a shared description and error. Disabling it disables every control inside, with no client code.
FileUpload
A dropzone over a native file input, with a list of the chosen files. Before any JavaScript runs, a click or a drop chooses files and a plain form submits them; hydrated, it checks each file against accept and maxSize and shows the upload state your code reports for each one.