Overlay Provider
Open and manage dialogs and other overlays from code.
Demos
Usage
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
This provider adds no visible container. Overlay components own their IPEX recipes, so the provider needs no visual variants or size configuration. Mount one provider in the application.
Programmatic behavior
Configure the component passed to useOverlay, rather than putting dialog behavior on the provider. The preview exposes title, description, fullscreen, backdrop dismissal, transition duration, and instance disposal. The provider can also wrap application content through its default slot.
const dialog = useOverlay().create(Dialog, {
props: {
title: 'Review changes',
closeOnBackdropClick: false,
duration: 180,
width: 'sm',
},
destroyOnClose: true,
})
const { result } = dialog.open({ description: 'Check the changes before continuing.' })
dialog.patch({ title: 'Updated review', fullscreen: true })
dialog.close()
await result
dialog.unmount()
open(props) applies props for that opening, patch(props) updates a mounted instance, and close() resolves its pending result. Use destroyOnClose: false when you want to retain the instance between openings; call unmount() when its owner is finished with it.
Installation
Complete the shared installation. Copy OverlayProvider.vue and index.ts into app/components/ui/overlay-provider/.
<script setup lang="ts">
import { Accordion as Primitive } from 'akaza-ui'
import { computed, useAttrs } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
accordionVariants,
resolveAccordionVariants,
type AccordionProps,
type AccordionSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AccordionProps>(), {
valueKey: undefined,
labelKey: undefined,
contentKey: undefined,
disabledKey: undefined,
type: undefined,
collapsible: true,
disabled: undefined,
orientation: undefined,
unmountOnHide: undefined,
as: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AccordionSlots>()
const attrs = useAttrs()
const styles = computed(() => accordionVariants(resolveAccordionVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'root' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, size: _size, ...native } = props
return native
})
</script>
<template>
<component :is="Primitive" v-bind="{ ...primitiveProps, ...attrs }" :ui="mergedUi">
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AccordionSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Composable
Import useOverlay from akaza-ui or the local overlay-provider folder. Call create(Component, options) to create an overlay instance. Set initial component props with options.props and choose whether to dispose it with options.destroyOnClose.
| Method | Description |
|---|---|
open(props) | Mount and open the component with props for this opening. Returns a handle with a result Promise. |
patch(props) | Update props on the mounted component. |
close() | Close the component and resolve the pending result. |
unmount() | Remove the instance when its owner no longer needs it. |
The provider has no visual variants. Configure appearance and behavior on the dialog, drawer, or other component you open.
Slots
Use the default slot for application content. Mount one OverlayProvider per application. Use the overlay component's props to configure each dialog, drawer, or popover.