feat(Slideover): open programmatically (#1465)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Eugen Istoc
2024-03-21 12:48:35 -04:00
committed by GitHub
parent b0ecac563c
commit e7697595c8
10 changed files with 173 additions and 1 deletions

View File

@@ -23,6 +23,7 @@
</template>
</UNotifications>
<UModals />
<USlideovers />
</div>
</template>

View File

@@ -0,0 +1,30 @@
<script lang="ts" setup>
const props = defineProps({
count: {
type: Number,
default: 0
}
})
const emits = defineEmits<{
close: [];
}>()
</script>
<template>
<USlideover>
<UCard class="flex flex-col flex-1" :ui="{ body: { base: 'flex-1' }, ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }">
<template #header>
<div class="flex items-center justify-between">
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white">
Opened programmatically: {{ props.count }} times
</h3>
<UButton color="gray" variant="ghost" icon="i-heroicons-x-mark-20-solid" class="-my-1" @click="emits('close')" />
</div>
</template>
<Placeholder class="h-full" />
</UCard>
</USlideover>
</template>

View File

@@ -0,0 +1,16 @@
<script setup lang="ts">
import { SlideoverExampleComponent } from '#components'
const slideover = useSlideover()
const count = ref(0)
function openSlideover () {
count.value += 1
slideover.open(SlideoverExampleComponent, {
count: count.value,
onClose: slideover.close
})
}
</script>
<template>
<UButton label="Reveal slideover" @click="openSlideover" />
</template>

View File

@@ -33,7 +33,7 @@ Set the `transition` prop to `false` to disable it.
### Prevent close
Use the `prevent-close` prop to disable the outside click alongside the `esc` keyboard shortcut. A `close-prevented` event will be emitted when the user tries to close the modal.
Use the `prevent-close` prop to disable the outside click alongside the `esc` keyboard shortcut. A `close-prevented` event will be emitted when the user tries to close the slideover.
:component-example{component="slideover-example-prevent-close"}
@@ -53,6 +53,24 @@ defineShortcuts({
</script>
```
### Control programmatically
First of all, add the `USlideovers` component to your app, preferably inside `app.vue`.
```vue [app.vue]
<template>
<div>
<UContainer>
<NuxtPage />
</UContainer>
<USlideovers />
</div>
</template>
```
Then, you can use the `useSlideover` composable to control your slideovers within your app.
:component-example{component="slideover-example-composable"}
## Props
:component-props