Skip to main content

MediaPicker

A picker for image attachments — a thin wrapper around FilePickerShell that always uses kind='image' and adapts the button style based on the rendered image preview (the buttons switch between glass and glassDark to stay legible over the artwork).

import { MediaPicker } from '@eightshift/frontend-libs-tailwind/scripts';

<MediaPicker
onChange={({ id, url }) => setAttributes({ imageId: id, imageUrl: url })}
imageId={imageId}
imageUrl={imageUrl}
/>;

Highlighted props

PropTypeDescription
onChange(media) => voidRequired. Called with { id, url, ... } on select, or { id: undefined, url: undefined } on remove.
imageIdstringID of the currently selected image. Used when replacing to mark the current selection.
imageUrlstringURL of the currently selected image. Drives the preview.
allowedTypesstring[]Allowed MIME types. Defaults to ['image'].
noDeletebooleanHide the "Remove" button.
noUploadbooleanHide the "Upload" button in the empty state.
hiddenbooleanIf true, nothing is rendered.
classNamestringExtra classes for the picker wrapper.

Restricting to a single type

<MediaPicker
onChange={onChange}
imageId={imageId}
imageUrl={imageUrl}
allowedTypes={['image/svg+xml']}
/>

Read-only picker (no upload, no delete)

<MediaPicker
onChange={onChange}
imageId={imageId}
imageUrl={imageUrl}
noUpload
noDelete
/>
Note

For non-image media, reach for FileSelector with the matching kind instead.