ModalWindow.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class='modal_window__overlay' :class='{"modal_window--show": showModal}' @click.self='hideModal'>
  3. <div class='modal_window' :class='{"modal_window--show": showModal}' v-on:hideModal='hideModal'>
  4. <slot></slot>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. name: 'ModalWindow',
  11. props: ['value'],
  12. data () {
  13. return {
  14. showModal: this.value
  15. }
  16. },
  17. methods: {
  18. hideModal () {
  19. this.showModal = false;
  20. this.$emit('input', this.showModal)
  21. }
  22. },
  23. mounted () {
  24. this.$watch('value', function(newVal) {
  25. this.showModal = newVal;
  26. });
  27. }
  28. }
  29. </script>
  30. <style lang='scss' scoped>
  31. @import '../assets/scss/variables.scss';
  32. .modal_window__overlay {
  33. width: 100%;
  34. height: 100%;
  35. background-color: rgba(0, 0, 0, 0.5);
  36. display: flex;
  37. align-items: center;
  38. justify-content: center;
  39. position: absolute;
  40. top: 0;
  41. left: 0;
  42. opacity: 0;
  43. pointer-events: none;
  44. transition: opacity 0.3s;
  45. @at-root #{&}--show {
  46. opacity: 1;
  47. pointer-events: all;
  48. transition: opacity 0.3s;
  49. }
  50. }
  51. .modal_window {
  52. width: 20rem;
  53. background-color: #fff;
  54. margin-top: -3rem;
  55. opacity: 0;
  56. border: 0.125rem solid $color__gray--darkest;
  57. pointer-events: none;
  58. transition: margin-top 0.3s, opacity 0.3s;
  59. @at-root #{&}--show {
  60. margin-top: 0;
  61. opacity: 1;
  62. pointer-events: all;
  63. transition: all 0.3s;
  64. }
  65. }
  66. </style>