Skip to content

Commit

Permalink
fix(modal): fix slot scope definition
Browse files Browse the repository at this point in the history
  • Loading branch information
adenvt committed Mar 6, 2024
1 parent 394437a commit e0d5ae4
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/components/modal/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
data-testid="modal-header"
class="modal__header"
:class="headerClass">
<slot name="header">
<slot
name="header"
:close="close">
<Heading
v-if="title"
class="modal__title"
Expand Down Expand Up @@ -78,7 +80,9 @@
data-testid="modal-full-header"
class="modal--full__header__title"
:class="headerClass">
<slot name="header">
<slot
name="header"
:close="close">
<Heading
v-if="title"
class="modal__title"
Expand All @@ -89,12 +93,16 @@
</div>
</div><!-- /header -->
<div :class="bodyClass">
<slot name="body">
<slot
name="body"
:close="close">
{{ text }}
</slot>
</div><!-- /body -->
</div><!-- /content -->
<slot v-else>
<slot
v-else
:close="close">
{{ text }}
</slot>
</div>
Expand Down Expand Up @@ -247,21 +255,23 @@ const classNames = computed(() => {
return result
})
function close (event: Event): void {
function close (): void {
const event = new CustomEvent('close')
emit('close', event)
if (!event.defaultPrevented)
model.value = false
}
function closeOnBackdrop (event: Event): void {
function closeOnBackdrop (): void {
if (!props.noCloseOnBackdrop)
close(event)
close()
}
onKeyStroke('Escape', (event) => {
onKeyStroke('Escape', () => {
if (!props.noCloseOnEsc)
close(event)
close()
}, { eventName: 'keydown' })
watch(model, (value) => {
Expand All @@ -272,11 +282,15 @@ watch(model, (value) => {
}
})
interface SlotScope {
close (): void,
}
defineSlots<{
'header'(): VNode[],
'body'(): VNode[],
'footer'(): VNode[],
'default'(): VNode[],
'header'(props: SlotScope): VNode[],
'body'(props: SlotScope): VNode[],
'footer'(props: SlotScope): VNode[],
'default'(props: SlotScope): VNode[],
}>()
</script>

Expand Down

0 comments on commit e0d5ae4

Please sign in to comment.