hx-modal.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <transition name="hx-modal">
  3. <div class="hx-modal__mask" @mousedown="$emit('close')" tabindex="1" @keydown.esc="$emit('close')">
  4. <div class="hx-modal__wrapper" >
  5. <div class="hx-modal__container" @mousedown.stop>
  6. <div class="hx-modal__header">
  7. <slot name="header"/>
  8. <button
  9. class="hx-modal__close-button"
  10. @click="$emit('close')">X
  11. </button>
  12. </div>
  13. <div class="hx-modal__body">
  14. <slot name="body"/>
  15. </div>
  16. <div class="hx-modal__footer">
  17. <slot name="footer"/>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </transition>
  23. </template>
  24. <script>
  25. export default {
  26. mounted () {
  27. this.$el.focus()
  28. }
  29. }
  30. </script>
  31. <style lang="css" >
  32. .hx-modal__mask {
  33. outline:none;
  34. position: fixed;
  35. z-index: 9998;
  36. top: 0;
  37. left: 0;
  38. width: 100%;
  39. height: 100%;
  40. background-color: rgba(0, 0, 0, 0.5);
  41. display: table;
  42. transition: opacity var(--transition-speed) ease;
  43. }
  44. .hx-modal__wrapper {
  45. display: table-cell;
  46. vertical-align: middle;
  47. }
  48. .hx-modal__container {
  49. width: 50%;
  50. margin: 0 auto;
  51. padding: 10px 15px;
  52. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
  53. transition: all var(--transition-speed) ease;
  54. font-family: Helvetica, Arial, sans-serif;
  55. }
  56. .hx-modal__header {
  57. display:flex;
  58. justify-content:space-between;
  59. align-items:center;
  60. margin-top: 0;
  61. }
  62. .hx-modal__header h3,
  63. .hx-modal__header h4
  64. {
  65. margin:0;
  66. }
  67. .hx-modal__body {
  68. margin: 0 0;
  69. padding: 20px 0;
  70. }
  71. .hx-modal__footer {
  72. display:flex;
  73. width:100%;
  74. justify-content: space-between;
  75. align-items: center;
  76. text-align:right;
  77. flex-basis:40px;
  78. }
  79. .hx-modal__close-button {
  80. border:none;
  81. font-weight:bold;
  82. font-size:1em;
  83. outline:none;
  84. padding:6px 8px;
  85. margin-bottom:10px;
  86. }
  87. /*
  88. * The following styles are auto-applied to elements with
  89. * transition="modal" when their visibility is toggled
  90. * by Vue.js.
  91. *
  92. * You can easily play with the modal transition by editing
  93. * these styles.
  94. */
  95. .hx-modal-enter {
  96. opacity: 0;
  97. }
  98. .hx-modal-leave-active {
  99. opacity: 0;
  100. }
  101. .hx-modal-enter .hx-modal__container,
  102. .hx-modal-leave-active .hx-modal__container {
  103. -webkit-transform: scale(1.1);
  104. transform: scale(1.1);
  105. }
  106. </style>