Created
July 13, 2021 20:04
-
-
Save mattmaribojoc/d63589ce3c85be7dbd9e71f512c35c7d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<template> | |
<button @click="open = true"> Open Popup </button> | |
<div class="popup" v-if='open'> | |
<div class="popup-content" ref="popup"> | |
Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis aliquid autem reiciendis eius accusamus sequi, ipsam corrupti vel laboriosam necessitatibus sit natus vero sint ullam! Omnis commodi eos accusantium illum? | |
</div> | |
</div> | |
</template> | |
<script setup> | |
import { ref } from 'vue' | |
import { onClickOutside } from '@vueuse/core' | |
const open = ref(false) // state of our popup | |
const popup = ref() // template ref | |
// whenever our popup exists, and we click anything BUT it | |
onClickOutside(popup, () => { | |
open.value = false | |
}) | |
</script> | |
<style scoped> | |
button { | |
border: none; | |
outline: none; | |
margin-right: 10px; | |
background-color: #2ecc71; | |
color: white; | |
padding: 5px 10px;; | |
} | |
.popup { | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100vw; | |
height: 100vh; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
background: rgba(0, 0, 0, 0.1); | |
} | |
.popup-content { | |
min-width: 300px; | |
padding: 20px; | |
width: 30%; | |
background: #fff; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment