Skip to content

useModal ​

Manages modal open/close state, width, fullscreen toggle, and action callbacks. Used by the UeModal component and any component that wraps a Vuetify v-dialog.

File: vue/src/js/hooks/useModal.js
Props factories: makeModalProps, makeModalMediaProps


Usage ​

js
import { useModal, makeModalProps } from '@/hooks'

const props = defineProps({ ...makeModalProps() })
const { dialog, openModal, closeModal, toggleModal, modalWidth } = useModal(props, context)
html
<v-dialog v-model="dialog" :width="modalWidth">
  <slot />
  <template #actions>
    <v-btn @click="closeModal">Cancel</v-btn>
    <v-btn @click="confirmCallback?.()">Confirm</v-btn>
  </template>
</v-dialog>

Props (via makeModalProps) ​

PropTypeDefaultDescription
modelValueBoolean—External open state (v-model)
useModelValueBooleantrueWhen false, the modal manages its own internalOpen state
titleStringnullModal title
widthTypeString'md''xs' | 'sm' | 'md' | 'lg' | 'xl'
fullscreenBooleanfalseOpen in full screen
hasCloseButtonBooleanfalseShow ✕ button in title bar
hasFullscreenButtonBooleanfalseShow fullscreen toggle
hasTitleDividerBooleanfalseDivider below title
noDefaultBodyPaddingBooleanfalseRemove default body padding
noActionsBooleanfalseHide the actions footer
noCancelButtonBooleanfalseHide cancel button
noConfirmButtonBooleanfalseHide confirm button
descriptionStringnullDescription text
cancelTextString''Cancel button label
confirmTextString''Confirm button label
confirmCallbackFunction—Called on confirm click
rejectCallbackFunction—Called on cancel click
confirmClosingBooleantrueClose on confirm
rejectClosingBooleantrueClose on cancel
transitionString'bottom'Dialog transition type

Width presets ​

widthTypeWidth
xs320px
sm480px
md720px
lg1080px
xl1600px

Returns ​

NameTypeDescription
dialogComputedRef<Boolean>Two-way binding — reads modelValue (or internalOpen), writes via emit
fullRef<Boolean>Fullscreen toggle state
modalWidthComputedRef<String|null>Resolved pixel width string, or null in fullscreen
openModal() => BooleanSets dialog to true
closeModal() => BooleanSets dialog to false
toggleModal() => BooleanToggles dialog
emitModelValue(val) => voidEmits update:modelValue
emitOpened() => voidEmits opened event
clickOutside(event) => voidEmits click:outside event

makeModalMediaProps ​

A secondary props factory for modal wrappers that embed the media library:

PropTypeDefault
modalTitlePrefixStringt('media-library.title')
btnLabelSingleStringt('media-library.insert')
btnLabelUpdateStringt('media-library.update')
btnLabelMultiStringt('media-library.insert')

See Also ​