Search the documentation

Type to search page titles, component names and descriptions.

    Data Entry

    Upload

    File inputs, drop zones and image grids.

    import { DropZone, FileUpload, ImageDropZone } from 'faifo-design'

    FileUpload is a native file input with the design system's frame. DropZone adds a drop target and a list of chosen files; ImageDropZone is the image-only surface with thumbnails and inline actions.

    #When to use

    • The native input owns submission. The application owns transport, storage and the URLs of stored files.
    • Use ImageDropZone when the files are pictures the reader arranges.

    #Examples

    Each example is a specimen of the package catalogue, rendered on the server exactly as shown in its code.

    #File upload and drop zone

    Native file input owns submission; the application owns transport and storage.

    Product photo
    Drop images here or click to choose · Up to 10 files
    • Jacket front.jpg
      Jacket front.jpg: Uploaded
    • Jacket back with detachable hood and adjustable storm cuffs.jpg
      Uploading Jacket back with detachable hood and adjustable storm cuffs.jpg
    • Collar detail.jpg
      Uploading Collar detail.jpg
    • Side zip.jpg
      Side zip.jpg: Connection interrupted. Try again.
    Choose or drop images. Up to six files. Changes stay in this demo.
    Choose or drop images. Up to six files. Changes stay in this demo.
    • Jacket front.jpg
      Jacket front.jpg: Uploaded
    Show codeHide code
    import { renderIsland, trustedMarkup } from '@ketvietlab/ketjs-view'
    import { DropZone, Field, FileUpload, ImageDropZone, Stack } from 'faifo-design'
    // disabledPictureGridDemo: a catalogue fixture, packages/faifo-design/src/catalogue/picture-grid-demo.tsx
    // pictureGridDemo: a catalogue fixture, packages/faifo-design/src/catalogue/picture-grid-demo.tsx
    
    export const Example = () => (
      <Stack
        items={[
          <Field
            id="catalogue-product-photo"
            name="product-photo"
            label="Product photo"
            layout="inline"
            control={
              <ImageDropZone
                label="Product photo"
                picker={
                  <label data-ui="image-drop-picker">
                    <input
                      id="catalogue-product-photo"
                      type="file"
                      accept="image/*"
                      aria-label="Choose product photo"
                    />
                    <span>Choose or drop photo</span>
                  </label>
                }
              />
            }
          />,
          <FileUpload id="invoice" name="invoice" label="Invoice" accept="application/pdf" />,
          <DropZone
            id="photos"
            name="photos"
            label="Delivery photos"
            accept="image/*"
            multiple
            preview={null}
            status="Drop images here or click to choose · Up to 10 files"
          />,
          trustedMarkup(
            renderIsland('design-system.picture-grid-demo', pictureGridDemo, {
              id: 'catalogue-gallery',
            }),
          ),
          trustedMarkup(
            renderIsland('design-system.picture-grid-demo', pictureGridDemo, {
              id: 'catalogue-gallery-empty',
              empty: true,
            }),
          ),
          disabledPictureGridDemo(),
        ]}
      />
    )

    #Contract

    #Picture-grid uploads

    Use <DropZone variant="picture-grid" id="gallery" name="photos" label="Gallery" multiple /> to show an image field as a responsive list of cards with a native picker. The default accept is image/*. Pass span="full" when the field should take a whole form row. The default DropZone frame, ImageDropZone and FileUpload keep their existing APIs.

    • Supply items as a controlled array of DropZonePictureItem. id must be unique and stay stable through upload, retry and replacement. name is the visible filename and names each action. Use thumbnailSrc for the card and previewSrc for the full image. An available URL can fill either slot. For local files, the host supplies and releases any object URLs. An item without an image URL shows the image symbol.
    • onFiles(files) receives an accepted batch from the picker or drop. The picker clears so the same file can be chosen again. Without onFiles, the input retains its FileList for native multipart submission. Accepted batches emit bubbling input and change events in native form mode. Server rendering includes the input, thumbnails and status. Mount the view through KetJS for drag handling, validation and callback actions.
    • maxItems counts saved, pending and failed items. A batch that exceeds the remaining capacity or fails accept validation is rejected together and announced. Omit multiple to accept at most one file per selection. At capacity the picker remains focusable for its limit notice. required applies to the native input while items is empty. A host using onFiles validates upload completion and saved state in its own save flow.
    • onPreview(item, trigger) can open a host viewer. The default opens a named image dialog and returns focus when it closes. onReplace(item) requests the host's replacement flow, onRemove(item) requests removal, and onRetry(item) appears on failed items. Activating a focused Retry button moves focus to its card as the action restarts. The host publishes new items after handling the action. If onRemove or onRetry removes the card asynchronously, return a promise that resolves after the list update so focus can move to a neighboring action or the Add picker. disabled disables the whole field. disabledActions disables selected actions for one item, for example while a request is pending.
    • An uploading item uses a progress value from 0 to 100 when available. Leave it undefined for an indeterminate indicator. Set status to done for explicit completion, or error with an optional error message. Omit the status for a saved thumbnail without a status label. Pass localized labels and the host's localized error text. Item action labels and uploading support the {name} placeholder.

    The catalogue's File upload and drop zone specimen includes editable, empty and disabled galleries. Its file and retry interactions use local demonstration state.

    #API

    Generated from the package source. A property without a description has none in the source yet.

    #DropZoneComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    accept–string–
    multiple–boolean–
    required–boolean–
    disabled–boolean–
    help–string | null–
    error–string | null–
    issues–readonly FieldIssue[]–
    status–JSXChild–
    span–'half' | 'full'–
    items–readonly DropZonePictureItem[]–
    maxItems–number–
    labels–Partial<DropZonePictureLabels>–
    onFiles–(files: File[]) => void–
    onPreview–(item: DropZonePictureItem, trigger: HTMLButtonElement) => void–
    onReplace–(item: DropZonePictureItem) => void–
    onRemove–(item: DropZonePictureItem) => void | Promise<void>–
    onRetry–(item: DropZonePictureItem) => void–
    variant–'picture-grid'–
    previewnull reserves a square image frame before an image is selected.{ src: string; alt: string } | null–
    draggingThe application drag runtime owns this state and upload transport.boolean–

    #FileUploadComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    labelrequired–string–
    accept–string–
    multiple–boolean–
    required–boolean–
    disabled–boolean–
    help–string | null–
    error–string | null–
    issues–readonly FieldIssue[]–
    status–JSXChild–
    span–'half' | 'full'–

    #ImageDropZoneComponent

    Image-only upload surface. The record adapter owns commands and file events; this component owns the thumbnail, hidden native picker and inline actions.

    PropertyDescriptionTypeDefault
    labelrequired–string–
    viewer–JSXChild | null–
    picker–JSXChild–
    actions–JSXChild–
    help–string | null–
    error–string | null–
    busy–boolean–
    dragging–boolean–

    #Types

    #DropZonePictureAction

    type DropZonePictureAction = 'preview' | 'replace' | 'remove' | 'retry'

    #DropZonePictureItem

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    thumbnailSrc–string–
    previewSrc–string–
    status–'uploading' | 'done' | 'error'–
    progress–number–
    error–string–
    disabledActions–readonly DropZonePictureAction[]–

    #DropZonePictureLabels

    PropertyDescriptionTypeDefault
    addrequired–string–
    fullrequired–string–
    limitrequired–string–
    invalidTyperequired–string–
    previewrequiredItem labels accept a {name} placeholder.string–
    replacerequired–string–
    removerequired–string–
    retryrequired–string–
    uploadingrequired–string–
    pendingrequired–string–
    donerequired–string–
    failedrequired–string–
    closerequired–string–

    #DropZoneProps

    The properties of DropZone, listed above.

    #FileUploadProps

    The properties of FileUpload, listed above.

    #Hooks

    The data-ui values these components render. Select them in tests and behaviour; their look belongs to the design system. See Contract.

    • file-upload
    • drop-zone
    • upload-preview
    • upload-caption
    • upload-status
    • picture-grid
    • picture-grid-items
    • picture-grid-item
    • picture-grid-thumbnail
    • picture-grid-name
    • picture-grid-actions
    • picture-grid-status
    • picture-grid-add
    • picture-grid-validation
    • picture-grid-preview
    • image-drop-zone
    • image-drop-preview
    • image-drop-actions
    • image-drop-picker
    • image-drop-help
    • image-drop-error