Search the documentation

Type to search page titles, component names and descriptions.

    Data Display

    Attachments and media

    Files, galleries, thumbnails and the image viewer.

    import { LightboxThumb, Attachments, MediaGallery, Thumbnail } from 'faifo-design'

    Attachments lists the files of a record, MediaGallery shows its pictures and Thumbnail is the square object image used in rows and cards. lightbox is the image viewer island: zoom, pan, pinch and keyboard paging over a set of pictures.

    #When to use

    • Storage URLs and mutations stay in the application; the components render authorized results.
    • Use Thumbnail for objects and Avatar for people.

    #Examples

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

    #Attachments and media

    Storage URLs and mutations stay in the application; public components render authorized results.

    Restricted
    Permission required
    Delivery proof placeholder
    Delivery proof
    Show codeHide code
    import { Attachments, Badge, ContentCard, Grid, Inline, MediaGallery, Text, Thumbnail } from 'faifo-design'
    
    export const Example = () => (
      <Grid
        columns={2}
        items={[
          <Inline
            items={[
              <Thumbnail alt="Product without a photo" size="small" />,
              <Thumbnail alt="Product without a photo" />,
              <Thumbnail
                alt="Sample product illustration"
                size="large"
                fit="contain"
                src="data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 64 64%22%3E%3Crect width=%2264%22 height=%2264%22 fill=%22%23fff%22/%3E%3Ccircle cx=%2232%22 cy=%2237%22 r=%2220%22 fill=%22%23ec9a20%22/%3E%3Cpath d=%22M32 17Q33 5 46 9Q43 19 32 17%22 fill=%22%23387450%22/%3E%3C/svg%3E"
              />,
            ]}
          />,
          <ContentCard
            title="Orange juice 1L, cold pressed"
            href="#catalogue-card"
            media={<Thumbnail alt="" />}
            mediaPlacement="start"
            summary="OJ-1L · Drinks · Bottle"
            meta={
              <Inline
                align="between"
                items={[
                  <Text variant="headingLg" numeric>
                    45,000 ₫
                  </Text>,
                  <Badge label="Active" tone="positive" size="small" />,
                ]}
              />
            }
          />,
          <Attachments
            label="Order attachments"
            items={[
              { id: 'invoice', name: 'invoice-SO-1042.pdf', href: '/files/invoice', meta: '238 KB' },
              { id: 'contract', name: 'Restricted contract', redacted: true },
            ]}
          />,
          <MediaGallery
            label="Delivery media"
            items={[
              { id: 'restricted', alt: '', redacted: true, caption: 'Permission required' },
              {
                id: 'proof',
                alt: 'Delivery proof placeholder',
                src: 'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%22400%22 height=%22300%22%3E%3Crect width=%22400%22 height=%22300%22 fill=%22%23eef0fb%22/%3E%3Cpath d=%22M80 220l70-80 50 50 50-70 80 100%22 fill=%22none%22 stroke=%22%23566fd1%22 stroke-width=%2212%22/%3E%3C/svg%3E',
                caption: 'Delivery proof',
              },
            ]}
          />,
        ]}
      />
    )

    #Lightbox

    A Fancybox-style image viewer, also an island: thumbnails open a full-screen stage with zoom (buttons, wheel, click to toggle 2×), drag to pan, pinch on a touch screen, previous/next and a counter; Escape closes and returns focus to the thumbnail. `createLightbox` is the same viewer without thumbnails, for a view that renders its own.

    Show codeHide code
    import { createLightboxView } from 'faifo-design'
    // lightboxDemoConfig: a catalogue fixture, packages/faifo-design/src/interactions/lightbox/demo.ts
    
    export const Example = () => (
      createLightboxView({ id: 'demo-lightbox', config: lightboxDemoConfig }).view()
    )

    #API

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

    #createLightboxFunction

    function createLightbox(labels: LightboxLabels, id?: string): LightboxController
    ParameterType
    labelsrequiredLightboxLabels
    idstring | undefined
    ReturnsLightboxController

    #createLightboxViewFunction

    A thumbnail — or one per item — that opens the whole set in the viewer.

    function createLightboxView(props: LightboxIslandProps): IslandController
    ParameterType
    propsrequiredLightboxIslandProps
    ReturnsIslandController

    #lightboxFunction

    function lightbox(props: IslandProps): IslandController
    ParameterType
    propsrequiredIslandProps
    ReturnsIslandController

    #LightboxThumbComponent

    One thumbnail button, for a view that drives its own createLightbox controller.

    PropertyDescriptionTypeDefault
    itemrequired–LightboxItem–
    labelsrequired–Pick<LightboxLabels, 'open'>–
    size–'small' | 'medium' | 'large''medium'
    onOpenrequired–(trigger: EventTarget | null) => void–

    #AttachmentsComponent

    PropertyDescriptionTypeDefault
    labelrequired–string–
    itemsrequired–readonly AttachmentItem[]–
    loading–boolean–
    error–string | null–
    redactedLabel–string–

    #MediaGalleryComponent

    PropertyDescriptionTypeDefault
    labelrequired–string–
    itemsrequired–readonly MediaItem[]–
    emptyTitle–string'No media'
    redactedLabel–string'Media redacted'

    #ThumbnailComponent

    Square object media for list rows and ContentCard.leading; people use Avatar.

    PropertyDescriptionTypeDefault
    src–string | null–
    altrequiredUse an empty alt when adjacent product text already names the image.string–
    size–'small' | 'default' | 'large''default'
    fit–'cover' | 'contain''cover'

    #Types

    #LightboxConfig

    PropertyDescriptionTypeDefault
    itemsrequired–readonly LightboxItem[]–
    labelsrequired–LightboxLabels–
    thumbnailsfirst shows one thumbnail that opens the whole set; all shows one per item.'first' | 'all'–
    size–'small' | 'medium' | 'large'–

    #LightboxController

    The viewer without a trigger of its own: whatever renders thumbnails (a record's image field, the rows of a variant editor) calls open with the set to show and places layer() anywhere in its own view. attach wires the keyboard once, for the lifetime of the island that owns it.

    PropertyDescriptionTypeDefault
    openrequired–(items: readonly LightboxItem[], at: number, trigger: EventTarget | null) => void–
    closerequired–() => void–
    isOpenrequired–() => boolean–
    layerrequired–() => TemplateResult | null–
    attachrequired–(lifetime: AbortSignal) => void–

    #LightboxIslandProps

    PropertyDescriptionTypeDefault
    idrequired–string–
    configrequired–LightboxConfig–

    #LightboxItem

    PropertyDescriptionTypeDefault
    srcrequired–string–
    altrequired–string–
    thumbnailA smaller rendition for the trigger; the full src is used when omitted.string | null–
    caption–string | null–

    #LightboxLabels

    PropertyDescriptionTypeDefault
    openrequiredThe trigger's accessible name, {alt} interpolated.string–
    closerequired–string–
    previousrequired–string–
    nextrequired–string–
    zoomInrequired–string–
    zoomOutrequired–string–
    counterrequired{index} and {total} interpolated.string–
    emptyShown in place of a thumbnail when there are no items.string–

    #AttachmentItem

    PropertyDescriptionTypeDefault
    idrequired–string–
    namerequired–string–
    href–string–
    meta–JSXChild–
    redacted–boolean–

    #MediaItem

    PropertyDescriptionTypeDefault
    idrequired–string–
    src–string–
    altrequired–string–
    caption–JSXChild–
    href–string–
    redacted–boolean–

    #ThumbnailProps

    The properties of Thumbnail, 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.

    • attachments
    • attachment
    • media-gallery
    • media-item
    • thumbnail
    • lightbox
    • lightbox-thumbs
    • lightbox-thumb
    • lightbox-empty
    • lightbox-layer
    • lightbox-backdrop
    • lightbox-toolbar
    • lightbox-counter
    • lightbox-tool
    • lightbox-stage
    • lightbox-image
    • lightbox-nav
    • lightbox-caption