Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for teleports to body (#1642)
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
196 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
const showModal = ref(false) | ||
</script> | ||
|
||
<template> | ||
<button class="modal-button" @click="showModal = true">Show Modal</button> | ||
|
||
<Teleport to="body"> | ||
<Transition name="modal"> | ||
<div v-show="showModal" class="modal-mask"> | ||
<div class="modal-container"> | ||
<p>Hello from the modal!</p> | ||
<div class="model-footer"> | ||
<button class="modal-button" @click="showModal = false"> | ||
Close | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</Transition> | ||
</Teleport> | ||
</template> | ||
|
||
<style scoped> | ||
.modal-mask { | ||
position: fixed; | ||
z-index: 200; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
transition: opacity 0.3s ease; | ||
} | ||
.modal-container { | ||
width: 300px; | ||
margin: auto; | ||
padding: 20px 30px; | ||
background-color: var(--vp-c-bg); | ||
border-radius: 2px; | ||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33); | ||
transition: all 0.3s ease; | ||
} | ||
.model-footer { | ||
margin-top: 8px; | ||
text-align: right; | ||
} | ||
.modal-button { | ||
padding: 4px 8px; | ||
border-radius: 4px; | ||
border-color: var(--vp-button-alt-border); | ||
color: var(--vp-button-alt-text); | ||
background-color: var(--vp-button-alt-bg); | ||
} | ||
.modal-button:hover { | ||
border-color: var(--vp-button-alt-hover-border); | ||
color: var(--vp-button-alt-hover-text); | ||
background-color: var(--vp-button-alt-hover-bg); | ||
} | ||
.modal-enter-from, | ||
.modal-leave-to { | ||
opacity: 0; | ||
} | ||
.modal-enter-from .modal-container, | ||
.modal-leave-to .modal-container { | ||
transform: scale(1.1); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
// entry for SSR | ||
import { createApp } from './index.js' | ||
import { renderToString } from 'vue/server-renderer' | ||
import type { SSGContext } from '../shared.js' | ||
|
||
export async function render(path: string) { | ||
const { app, router } = await createApp() | ||
await router.go(path) | ||
return renderToString(app) | ||
const ctx: SSGContext = { content: '' } | ||
ctx.content = await renderToString(app, ctx) | ||
return ctx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters