feat(components): handle events in content prop

This commit is contained in:
Benjamin Canac
2025-03-20 12:39:57 +01:00
parent f4c417d9ef
commit 5dec0e16e2
11 changed files with 48 additions and 39 deletions

View File

@@ -1,10 +1,11 @@
<script lang="ts">
import type { DialogRootProps, DialogRootEmits, DialogContentProps } from 'reka-ui'
import type { DialogRootProps, DialogRootEmits, DialogContentProps, DialogContentEmits } from 'reka-ui'
import type { AppConfig } from '@nuxt/schema'
import _appConfig from '#build/app.config'
import theme from '#build/ui/modal'
import { tv } from '../utils/tv'
import type { ButtonProps } from '../types'
import type { EmitsToProps } from '../types/utils'
const appConfigModal = _appConfig as AppConfig & { ui: { modal: Partial<typeof theme> } }
@@ -14,7 +15,7 @@ export interface ModalProps extends DialogRootProps {
title?: string
description?: string
/** The content of the modal. */
content?: Omit<DialogContentProps, 'as' | 'asChild' | 'forceMount'>
content?: Omit<DialogContentProps, 'as' | 'asChild' | 'forceMount'> & Partial<EmitsToProps<DialogContentEmits>>
/**
* Render an overlay behind the modal.
* @defaultValue true
@@ -97,18 +98,20 @@ const appConfig = useAppConfig()
const rootProps = useForwardPropsEmits(reactivePick(props, 'open', 'defaultOpen', 'modal'), emits)
const contentProps = toRef(() => props.content)
const contentEvents = computed(() => {
const events = {
closeAutoFocus: (e: Event) => e.preventDefault()
}
if (!props.dismissible) {
return {
pointerDownOutside: (e: Event) => e.preventDefault(),
interactOutside: (e: Event) => e.preventDefault(),
escapeKeyDown: (e: Event) => e.preventDefault(),
closeAutoFocus: (e: Event) => e.preventDefault()
...events
}
}
return {
closeAutoFocus: (e: Event) => e.preventDefault()
}
return events
})
const ui = computed(() => modal({