Modal.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <div class="modal is-active">
  3. <div class="modal-background" @click="closeThisModal()" />
  4. <div
  5. :class="{
  6. 'modal-card': true,
  7. 'modal-wide': wide,
  8. 'modal-split': split
  9. }"
  10. >
  11. <header class="modal-card-head">
  12. <h2 class="modal-card-title is-marginless">
  13. {{ title }}
  14. </h2>
  15. <span class="delete material-icons" @click="closeThisModal()"
  16. >highlight_off</span
  17. >
  18. </header>
  19. <section class="modal-card-body">
  20. <slot name="body" />
  21. </section>
  22. <footer class="modal-card-foot" v-if="$slots['footer'] != null">
  23. <slot name="footer" />
  24. </footer>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import { mapActions } from "vuex";
  30. import keyboardShortcuts from "@/keyboardShortcuts";
  31. export default {
  32. props: {
  33. title: { type: String, default: "Modal" },
  34. wide: { type: Boolean, default: false },
  35. split: { type: Boolean, default: false }
  36. },
  37. emits: ["closed"],
  38. mounted() {
  39. this.type = this.toCamelCase(this.title);
  40. keyboardShortcuts.registerShortcut("closeModal", {
  41. keyCode: 27,
  42. shift: false,
  43. ctrl: false,
  44. handler: () => {
  45. this.closeThisModal();
  46. }
  47. });
  48. },
  49. methods: {
  50. toCamelCase: str =>
  51. str
  52. .toLowerCase()
  53. .replace(/[-_]+/g, " ")
  54. .replace(/[^\w\s]/g, "")
  55. .replace(/ (.)/g, $1 => $1.toUpperCase())
  56. .replace(/ /g, ""),
  57. closeThisModal() {
  58. this.$emit("closed");
  59. this.closeCurrentModal();
  60. },
  61. ...mapActions("modalVisibility", ["closeCurrentModal"])
  62. }
  63. };
  64. </script>
  65. <style lang="scss">
  66. .night-mode .modal .modal-card {
  67. .modal-card-head,
  68. .modal-card-foot {
  69. background-color: var(--dark-grey-3);
  70. border-color: var(--dark-grey-2);
  71. }
  72. .modal-card-body {
  73. background-color: var(--dark-grey-4) !important;
  74. }
  75. .modal-card-head .delete.material-icons,
  76. .modal-card-title {
  77. color: var(--white);
  78. }
  79. p,
  80. label,
  81. td,
  82. th {
  83. color: var(--light-grey-2) !important;
  84. }
  85. h1,
  86. h2,
  87. h3,
  88. h4,
  89. h5,
  90. h6 {
  91. color: var(--white) !important;
  92. }
  93. }
  94. .modal {
  95. display: flex;
  96. position: fixed;
  97. top: 0;
  98. bottom: 0;
  99. left: 0;
  100. right: 0;
  101. z-index: 1984;
  102. justify-content: center;
  103. align-items: center;
  104. .modal-background {
  105. position: absolute;
  106. top: 0;
  107. bottom: 0;
  108. left: 0;
  109. right: 0;
  110. background-color: rgba(10, 10, 10, 0.85);
  111. }
  112. .modal-card {
  113. display: flex;
  114. flex-direction: column;
  115. position: relative;
  116. width: 800px;
  117. max-width: calc(100% - 40px);
  118. max-height: calc(100vh - 40px);
  119. overflow: auto;
  120. margin: 0;
  121. font-size: 16px;
  122. &.modal-wide {
  123. width: 1300px;
  124. }
  125. &.modal-split {
  126. height: 100%;
  127. .modal-card-body {
  128. display: flex;
  129. flex-wrap: wrap;
  130. height: 100%;
  131. row-gap: 24px;
  132. .left-section,
  133. .right-section {
  134. flex-basis: 50%;
  135. max-height: 100%;
  136. overflow-y: auto;
  137. flex-grow: 1;
  138. .section {
  139. display: flex;
  140. flex-direction: column;
  141. flex-grow: 1;
  142. width: auto;
  143. padding: 15px !important;
  144. margin: 0 10px;
  145. }
  146. @media screen and (max-width: 1100px) {
  147. flex-basis: 100%;
  148. max-height: unset;
  149. }
  150. }
  151. }
  152. }
  153. .modal-card-head,
  154. .modal-card-foot {
  155. display: flex;
  156. flex-shrink: 0;
  157. position: relative;
  158. justify-content: flex-start;
  159. align-items: center;
  160. padding: 20px;
  161. background-color: var(--light-grey);
  162. }
  163. .modal-card-head {
  164. border-radius: 5px 5px 0 0;
  165. .modal-card-title {
  166. display: flex;
  167. flex: 1;
  168. margin: 0;
  169. font-size: 26px;
  170. font-weight: 600;
  171. }
  172. .delete.material-icons {
  173. font-size: 28px;
  174. cursor: pointer;
  175. &:hover,
  176. &:focus {
  177. filter: brightness(90%);
  178. }
  179. }
  180. }
  181. .modal-card-foot {
  182. border-radius: 0 0 5px 5px;
  183. overflow: initial;
  184. & > div {
  185. display: flex;
  186. flex-grow: 1;
  187. column-gap: 16px;
  188. }
  189. .right {
  190. display: flex;
  191. margin-left: auto;
  192. margin-right: 0;
  193. justify-content: flex-end;
  194. column-gap: 16px;
  195. }
  196. }
  197. .modal-card-body {
  198. flex: 1;
  199. flex-wrap: wrap;
  200. padding: 20px;
  201. overflow: auto;
  202. background-color: var(--white);
  203. }
  204. @media screen and (max-width: 650px) {
  205. max-height: 100vh;
  206. height: 100%;
  207. max-width: 100%;
  208. .modal-card-head,
  209. .modal-card-foot {
  210. border-radius: 0;
  211. }
  212. }
  213. }
  214. }
  215. </style>