Skip to content

useImage ​

Manages the state for an image input backed by the media library. Identical API to useFile but defaults mediaType to 'image' and opens the media library in image mode.

File: vue/src/js/hooks/useImage.js
Props factory: makeImageProps


Usage ​

js
import { useImage, makeImageProps } from '@/hooks'

const props = defineProps({ ...makeImageProps() })
const {
  input,
  items,
  remainingItems,
  isDraggable,
  mediableActive,
  addLabel,
  deleteItem,
  deleteAll
} = useImage(props, context)

Props (via makeImageProps) ​

Extends makeInputProps and makeDraggableProps plus:

PropTypeDefaultDescription
mediaTypeString'image'Media type passed to the media library
nameStringrequiredField name — media library slot key
itemLabelStringt('Image')Label used in the add button
btnLabelStringt('fields.medias.btn-label')Add image button label
maxNumber1Maximum number of images
disabledBooleanfalseDisable the input
requiredBooleanfalseMark as required
hoverBooleanfalseEnable hover preview
isSlideBooleanfalseRender as a slideshow slot
indexNumber0Index in a multi-context media slot
mediaContextString''Media library context key (e.g. 'cover')
activeCropBooleantrueShow crop tool in the media library
widthMinNumber0Minimum accepted image width in px
heightMinNumber0Minimum accepted image height in px
noteString''Note text
fieldNoteString''Field-level note
filesizeMaxNumber0Maximum file size (0 = unlimited)
buttonOnTopBooleanfalseDisplay add button above the image list

Returns ​

Same as useFile:

NameTypeDescription
inputRef<Array>The current image list
itemsComputedRef<Array>Images from the media library store
remainingItemsComputedRef<Number>max - input.length
isDraggableComputedRef<Boolean>True when draggable and more than one image
mediableActiveRef<Boolean>Controls media library selection application
addLabelComputedRef<String>Localised add button label
deleteItem(index) => voidRemove image at index
deleteAll() => voidClear all images

See Also ​