<template> <div class="modal-backdrop"> <div class="modal"> <slot name="header"> </slot> <slot name="body"> </slot> <slot name="footer"> </slot> </div> </div> </template>
<script> export default { name: 'modal', methods: { close() { this.$emit('close'); }, }, }; </script> <template> <div class="modal-backdrop"> <div class="modal"> <header class="modal-header"> <slot name="header"> This is the default tile! <button type="button" class="btn-close" @click="close" > x </button> </slot> </header> <section class="modal-body"> <slot name="body"> I'm the default body! </slot> </section> <footer class="modal-footer"> <slot name="footer"> I'm the default footer! <button type="button" class="btn-green" @click="close" > Close me! </button> </slot> </footer> </div> </div> </template> <style> .modal-backdrop { position: fixed; top: 0; bottom: 0; left: 0; right: 0; background-color: rgba(0, 0, 0, 0.3); display: flex; justify-content: center; align-items: center; } .modal { background: #FFFFFF; box-shadow: 2px 2px 20px 1px; overflow-x: auto; display: flex; flex-direction: column; } .modal-header, .modal-footer { padding: 15px; display: flex; } .modal-header { border-bottom: 1px solid #eeeeee; color: #4AAE9B; justify-content: space-between; } .modal-footer { border-top: 1px solid #eeeeee; justify-content: flex-end; } .modal-body { position: relative; padding: 20px 10px; } .btn-close { border: none; font-size: 20px; padding: 20px; cursor: pointer; font-weight: bold; color: #4AAE9B; background: transparent; } .btn-green { color: white; background: #4AAE9B; border: 1px solid #4AAE9B; border-radius: 2px; } </style>
<template> <transition name="modal-fade"> <div class="modal-backdrop"> <div class="modal"> ... </div> </div> </transition> </template>
<style> .modal-fade-enter, .modal-fade-leave-active { opacity: 0; } .modal-fade-enter-active, .modal-fade-leave-active { transition: opacity .5s ease } </style>
<script> export default { name: 'modal', methods: { close() { this.$emit('close'); }, }, }; </script> <template> <transition name="modal-fade"> <div class="modal-backdrop"> <div class="modal" role="dialog" aria-labelledby="modalTitle" aria-describedby="modalDescription" > <header class="modal-header" id="modalTitle" > <slot name="header"> This is the default tile! <button type="button" class="btn-close" @click="close" aria-label="Close modal" > x </button> </slot> </header> <section class="modal-body" id="modalDescription" > <slot name="body"> I'm the default body! </slot> </section> <footer class="modal-footer"> <slot name="footer"> I'm the default footer! <button type="button" class="btn-green" @click="close" aria-label="Close modal" > Close me! </button> </slot> </footer> </div> </div> </transition> </template> <style> .modal-backdrop { position: fixed; top: 0; bottom: 0; left: 0; right: 0; background-color: rgba(0, 0, 0, 0.3); display: flex; justify-content: center; align-items: center; } .modal { background: #FFFFFF; box-shadow: 2px 2px 20px 1px; overflow-x: auto; display: flex; flex-direction: column; } .modal-header, .modal-footer { padding: 15px; display: flex; } .modal-header { border-bottom: 1px solid #eeeeee; color: #4AAE9B; justify-content: space-between; } .modal-footer { border-top: 1px solid #eeeeee; justify-content: flex-end; } .modal-body { position: relative; padding: 20px 10px; } .btn-close { border: none; font-size: 20px; padding: 20px; cursor: pointer; font-weight: bold; color: #4AAE9B; background: transparent; } .btn-green { color: white; background: #4AAE9B; border: 1px solid #4AAE9B; border-radius: 2px; } </style>
<script> import modal from './components/modal.vue'; export default { name: 'app', components: { modal, }, data () { return { isModalVisible: false, }; }, methods: { showModal() { this.isModalVisible = true; }, closeModal() { this.isModalVisible = false; } }, }; </script> <template> <div id="app"> <button type="button" class="btn" @click="showModal" > Open Modal! </button> <modal v-show="isModalVisible" @close="closeModal" /> </div> </template>
Source: https://habr.com/ru/post/349306/
All Articles