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
Thumbnailfor objects andAvatarfor 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.
Orange juice 1L, cold pressed
OJ-1L · Drinks · Bottle
- invoice-SO-1042.pdf238 KB
- Restricted contract
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| Parameter | Type |
|---|---|
labelsrequired | LightboxLabels |
id | string | undefined |
| Returns | LightboxController |
#createLightboxViewFunction
A thumbnail — or one per item — that opens the whole set in the viewer.
function createLightboxView(props: LightboxIslandProps): IslandController| Parameter | Type |
|---|---|
propsrequired | LightboxIslandProps |
| Returns | IslandController |
#lightboxFunction
function lightbox(props: IslandProps): IslandController| Parameter | Type |
|---|---|
propsrequired | IslandProps |
| Returns | IslandController |
#LightboxThumbComponent
One thumbnail button, for a view that drives its own createLightbox controller.
| Property | Description | Type | Default |
|---|---|---|---|
itemrequired | – | LightboxItem | – |
labelsrequired | – | Pick<LightboxLabels, 'open'> | – |
size | – | 'small' | 'medium' | 'large' | 'medium' |
onOpenrequired | – | (trigger: EventTarget | null) => void | – |
#AttachmentsComponent
| Property | Description | Type | Default |
|---|---|---|---|
labelrequired | – | string | – |
itemsrequired | – | readonly AttachmentItem[] | – |
loading | – | boolean | – |
error | – | string | null | – |
redactedLabel | – | string | – |
#MediaGalleryComponent
| Property | Description | Type | Default |
|---|---|---|---|
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.
| Property | Description | Type | Default |
|---|---|---|---|
src | – | string | null | – |
altrequired | Use an empty alt when adjacent product text already names the image. | string | – |
size | – | 'small' | 'default' | 'large' | 'default' |
fit | – | 'cover' | 'contain' | 'cover' |
#Types
#LightboxConfig
| Property | Description | Type | Default |
|---|---|---|---|
itemsrequired | – | readonly LightboxItem[] | – |
labelsrequired | – | LightboxLabels | – |
thumbnails | first 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.
| Property | Description | Type | Default |
|---|---|---|---|
openrequired | – | (items: readonly LightboxItem[], at: number, trigger: EventTarget | null) => void | – |
closerequired | – | () => void | – |
isOpenrequired | – | () => boolean | – |
layerrequired | – | () => TemplateResult | null | – |
attachrequired | – | (lifetime: AbortSignal) => void | – |
#LightboxIslandProps
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
configrequired | – | LightboxConfig | – |
#LightboxItem
| Property | Description | Type | Default |
|---|---|---|---|
srcrequired | – | string | – |
altrequired | – | string | – |
thumbnail | A smaller rendition for the trigger; the full src is used when omitted. | string | null | – |
caption | – | string | null | – |
#LightboxLabels
| Property | Description | Type | Default |
|---|---|---|---|
openrequired | The trigger's accessible name, {alt} interpolated. | string | – |
closerequired | – | string | – |
previousrequired | – | string | – |
nextrequired | – | string | – |
zoomInrequired | – | string | – |
zoomOutrequired | – | string | – |
counterrequired | {index} and {total} interpolated. | string | – |
empty | Shown in place of a thumbnail when there are no items. | string | – |
#AttachmentItem
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
namerequired | – | string | – |
href | – | string | – |
meta | – | JSXChild | – |
redacted | – | boolean | – |
#MediaItem
| Property | Description | Type | Default |
|---|---|---|---|
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.
attachmentsattachmentmedia-gallerymedia-itemthumbnaillightboxlightbox-thumbslightbox-thumblightbox-emptylightbox-layerlightbox-backdroplightbox-toolbarlightbox-counterlightbox-toollightbox-stagelightbox-imagelightbox-navlightbox-caption