Skip to content
Get started

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.

Server component, no client JSUnstable

Examples

Basic

Three states of one upload: under way, done, and failed with its reason.

autumn-lookbook.pdf
2.4 of 3.9 MB · 62%
autumn-lookbook.pdf3.9 MB · UploadedUploaded
autumn-lookbook.pdfUpload failed — file is over 20 MB
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.

NameTypeDefaultDescription
detailReactNode–

The line under the name: "2.4 of 3.9 MB · 62%", "3.9 MB · Uploaded", or why it failed.

iconReactNode–

Replaces the file-text mark, for example an image thumbnail.

labelsPartial<FileItemLabels>–
localestring'en-US'

BCP 47 tag for the progress value.

namerequiredstring–

The file's name: "autumn-lookbook.pdf".

onCancel() => void–
onRetry() => void–
progressnumber–

While uploading, from 0 to 100.

renderRenderProp<Record<string, never>>–

Must render a <div>.

statusrequiredFileItemStatus
"uploading""done""error"
–
  • Also takes every attribute of <div> except children. (Omit<ComponentPropsWithRef<"div">, "children">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

FileItemLabels type

import type { FileItemLabels } from '@nizivo/react/unstable/file-item'

FileItem's own strings (§16.4): serialisable, English defaults.

NameTypeDefaultDescription
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}'
FileItemProps type

import type { FileItemProps } from '@nizivo/react/unstable/file-item'

The props of FileItem, listed above.

FileItemStatus type

import 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.

SlotRendered byData attributes
file-item
.nz-file-item
FileItem
root (takes render)
  • data-tone: "uploading""done""error"
    The tone prop; values in each component manifest
file-item-action
.nz-file-item-action
FileItem
inner element (CSS only); interactive, focus: self
none
file-item-detail
.nz-file-item-detail
FileItem
inner element (CSS only)
none
file-item-name
.nz-file-item-name
FileItem
inner 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.

On this page