Skip to content

Commit fd53211

Browse files
committed
refactor: use overlay-provider theme
1 parent 48ee64e commit fd53211

File tree

12 files changed

+52
-52
lines changed

12 files changed

+52
-52
lines changed

docs/app/app.config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ export default defineAppConfig({
44
expand: true,
55
duration: 5000
66
},
7-
overlay: {
8-
class: 'origin-top transition-transform duration-600',
9-
style: {
10-
'--overlay-value': 'calc(var(--overlay-count) - var(--overlay-index) - 1)',
11-
'scale': 'calc(100% - 5% * var(--overlay-value))',
12-
'transform': 'translateY(calc(-1.25rem * var(--overlay-value)))'
13-
}
14-
},
157
theme: {
168
radius: 0.25,
179
blackAsPrimary: false

docs/app/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ provide('navigation', mappedNavigation)
4949
</script>
5050

5151
<template>
52-
<UApp :toaster="appConfig.toaster" :overlay="appConfig.overlay">
52+
<UApp :toaster="appConfig.toaster" :overlay="{ stacked: true }">
5353
<NuxtLoadingIndicator color="var(--ui-primary)" :height="2" />
5454

5555
<template v-if="!route.path.startsWith('/examples')">

docs/app/assets/css/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ html[data-module="ui"] .ui-pro-only {
3636
/* For better modals stacking visual experience */
3737
@keyframes light-slide-in-from-bottom {
3838
from {
39-
transform: translateY(60%);
39+
transform: translateY(20%);
4040
opacity: 0;
4141
}
4242

@@ -53,7 +53,7 @@ html[data-module="ui"] .ui-pro-only {
5353
}
5454

5555
to {
56-
transform: translateY(60%);
56+
transform: translateY(20%);
5757
opacity: 0;
5858
}
5959
}

docs/app/components/content/examples/modal/StackingModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function onClick() {
1515
<template>
1616
<UModal
1717
title="A Modal"
18-
:ui="{ footer: 'justify-end', content: 'data-[state=open]:animate-[light-slide-in-from-bottom_600ms_ease-out] data-[state=closed]:animate-[light-slide-out-to-bottom_600ms_ease-in]' }"
18+
:ui="{ footer: 'justify-end', content: 'data-[state=open]:animate-[light-slide-in-from-bottom_200ms_ease-out] data-[state=closed]:animate-[light-slide-out-to-bottom_200ms_ease-in]' }"
1919
>
2020
<template #footer>
2121
<UButton label="Another Modal" variant="subtle" color="neutral" @click="onClick" />

docs/content/3.components/modal.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -357,33 +357,10 @@ name: 'modal-stacking-example'
357357
---
358358
::
359359

360-
The demo above is slow intentionally to demonstrate the stacking effect.
361-
362-
To achieve this visual effect, a custom configuration for the overlay is required:
363-
364-
```ts
365-
{
366-
overlay: {
367-
class: 'origin-top transition-transform duration-600',
368-
style: {
369-
'--overlay-value': 'calc(var(--overlay-count) - var(--overlay-index) - 1)',
370-
'scale': 'calc(100% - 5% * var(--overlay-value))',
371-
'transform': 'translateY(calc(-1.25rem * var(--overlay-value)))'
372-
}
373-
}
374-
}
375-
```
376-
377360
::note
378-
This configuration is the one used in the demo above but you can customize it to your needs. Nuxt UI only provides the CSS variables by default.
361+
You must enable the `stacked` variant though the App component's `overlay` prop to use this feature.
379362
::
380363

381-
Then, you'll have to provide this configuration to the `App` component:
382-
383-
```vue-html
384-
<UApp :overlay="appConfig.overlay">
385-
```
386-
387364
### With footer slot
388365

389366
Use the `#footer` slot to add content after the Modal's body.

playground/app/app.config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ export default defineAppConfig({
44
expand: true,
55
duration: 5000
66
},
7-
overlay: {
8-
class: 'origin-top transition-transform duration-100',
9-
style: {
10-
'--overlay-value': 'calc(var(--overlay-count) - var(--overlay-index) - 1)',
11-
'scale': 'calc(100% - 5% * var(--overlay-value))',
12-
'transform': 'translateY(calc(-1.25rem * var(--overlay-value)))'
13-
}
14-
},
157
ui: {
168
colors: {
179
primary: 'green',

playground/app/app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ useHead({
9191

9292
<template>
9393
<template v-if="!$route.path.startsWith('/__nuxt_ui__')">
94-
<UApp :toaster="appConfig.toaster" :overlay="appConfig.overlay">
94+
<UApp :toaster="appConfig.toaster" :overlay="{ stacked: true }">
9595
<div class="h-screen w-screen overflow-hidden flex flex-col lg:flex-row min-h-0 bg-default" data-vaul-drawer-wrapper>
9696
<UNavigationMenu :items="items" orientation="vertical" class="hidden lg:flex border-e border-default overflow-y-auto w-48 p-4" />
9797
<UNavigationMenu :items="items" orientation="horizontal" class="lg:hidden border-b border-default [&>div]:min-w-min overflow-x-auto" />

src/runtime/components/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
22
import type { ConfigProviderProps, TooltipProviderProps } from 'reka-ui'
3-
import type { ToasterProps, Locale, Messages } from '../types'
3+
import type { ToasterProps, Locale, Messages, OverlayProviderProps } from '../types'
44
55
export interface AppProps<T extends Messages = Messages> extends Omit<ConfigProviderProps, 'useId' | 'dir' | 'locale'> {
66
tooltip?: TooltipProviderProps
77
toaster?: ToasterProps | null
8-
overlay?: Record<string, any>
8+
overlay?: OverlayProviderProps
99
locale?: Locale<T>
1010
portal?: string | HTMLElement
1111
}

src/runtime/components/OverlayProvider.vue

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1+
<script lang="ts">
2+
import type { AppConfig } from '@nuxt/schema'
3+
import theme from '#build/ui/overlay-provider'
4+
import type { ComponentConfig } from '../types/utils'
5+
6+
type OverlayProvider = ComponentConfig<typeof theme, AppConfig, 'overlayProvider'>
7+
8+
export interface OverlayProviderProps {
9+
/**
10+
* Allow the overlay to nicely stack on top of each other.
11+
* @defaultValue false
12+
*/
13+
stacked?: boolean
14+
class?: any
15+
ui?: OverlayProvider['slots']
16+
}
17+
</script>
18+
119
<script setup lang="ts">
220
import { computed } from 'vue'
321
import { useOverlay, type Overlay } from '../composables/useOverlay'
22+
import { useAppConfig } from '#imports'
23+
import { tv } from '../utils/tv'
424
5-
defineOptions({
6-
inheritAttrs: false
25+
const props = withDefaults(defineProps<OverlayProviderProps>(), {
26+
stacked: false
727
})
828
29+
const appConfig = useAppConfig() as OverlayProvider['AppConfig']
30+
31+
const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.overlayProvider || {}) })({
32+
stacked: props.stacked
33+
}))
34+
935
const { overlays, unmount, close } = useOverlay()
1036
1137
const mountedOverlays = computed(() => overlays.filter((overlay: Overlay) => overlay.isMounted))
@@ -29,13 +55,12 @@ const onClose = (id: symbol, value: any) => {
2955
v-model:open="overlay.isOpen"
3056
:overlay="index === 0 ? true : false"
3157
:content="{
32-
...$attrs,
3358
style: {
3459
'--overlay-count': mountedOverlays.length,
35-
'--overlay-index': index,
36-
...($attrs as any).style
60+
'--overlay-index': index
3761
}
3862
}"
63+
:class="ui.base({ class: [props.ui?.base, props.class] })"
3964
@close="(value:any) => onClose(overlay.id, value)"
4065
@after:leave="onAfterLeave(overlay.id)"
4166
/>

src/runtime/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ export * from '../components/Tree.vue'
5555
export * from './form'
5656
export * from './locale'
5757
export * from './utils'
58+
export * from '../components/OverlayProvider.vue'

0 commit comments

Comments
 (0)