mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 20:19:34 +01:00
feat(Modal): open programmatically (#78)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
18
playground/components/ModalProgrammaticExample.vue
Normal file
18
playground/components/ModalProgrammaticExample.vue
Normal file
@@ -0,0 +1,18 @@
|
||||
<script lang="ts" setup>
|
||||
const modal = useModal()
|
||||
|
||||
defineProps<{
|
||||
count: number
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UModal title="This modal was opened programmatically">
|
||||
<template #footer>
|
||||
<div class="flex w-full justify-between">
|
||||
<p>Count: {{ count }}</p>
|
||||
<UButton color="gray" label="Close" @click="modal.close()" />
|
||||
</div>
|
||||
</template>
|
||||
</UModal>
|
||||
</template>
|
||||
@@ -1,5 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { LazyModalProgrammaticExample } from '#components'
|
||||
|
||||
const open = ref(false)
|
||||
|
||||
const modal = useModal()
|
||||
const count = ref(0)
|
||||
const openModal = () => {
|
||||
count.value++
|
||||
modal.open(LazyModalProgrammaticExample, {
|
||||
description: 'And you can even provide a description !',
|
||||
count: count.value
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -49,5 +61,7 @@ const open = ref(false)
|
||||
<UModal title="Modal with custom close button" description="The `close` prop inherits from the Button props." :close="{ color: 'primary', variant: 'solid', size: 'xs' }" :ui="{ close: 'top-3.5 rounded-full' }">
|
||||
<UButton label="Open with custom close button" color="gray" />
|
||||
</UModal>
|
||||
|
||||
<UButton label="Open programmatically" color="white" @click="openModal" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user