Advertisement
Guest User

Modal

a guest
Jan 28th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <template>
  2. <SlideYUpTransition :duration="animationDuration">
  3. <div class="modal fade"
  4. @click.self="closeModal"
  5. :class="[{'show d-block': show}, {'d-none': !show}, {'modal-mini': type === 'mini'}]"
  6. v-show="show"
  7. tabindex="-1"
  8. role="dialog"
  9. :aria-hidden="!show">
  10. <div class="modal-dialog modal-dialog-centered"
  11. :class="[{'modal-notice': type === 'notice'}, modalClasses]">
  12. <div class="modal-content" :class="[gradient ? `bg-gradient-${gradient}` : '',modalContentClasses]">
  13. <div class="modal-header" :class="[headerClasses]" v-if="$slots.header">
  14. <slot name="header"></slot>
  15. <slot name="close-button">
  16. <button type="button"
  17. class="close"
  18. v-if="showClose"
  19. @click="closeModal"
  20. data-dismiss="modal"
  21. aria-label="Close">
  22. <span :aria-hidden="!show">×</span>
  23. </button>
  24. </slot>
  25. </div>
  26. <div class="modal-body" :class="bodyClasses">
  27. <slot></slot>
  28. </div>
  29. <div class="modal-footer" :class="footerClasses" v-if="$slots.footer">
  30. <slot name="footer"></slot>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </SlideYUpTransition>
  36. </template>
  37. <script>
  38. import { SlideYUpTransition } from "vue2-transitions";
  39.  
  40. export default {
  41. name: "modal",
  42. components: {
  43. SlideYUpTransition
  44. },
  45. props: {
  46. show: Boolean,
  47. showClose: {
  48. type: Boolean,
  49. default: true
  50. },
  51. type: {
  52. type: String,
  53. default: "",
  54. validator(value) {
  55. let acceptedValues = ["", "notice", "mini"];
  56. return acceptedValues.indexOf(value) !== -1;
  57. },
  58. description: 'Modal type (notice|mini|"") '
  59. },
  60. modalClasses: {
  61. type: [Object, String],
  62. description: "Modal dialog css classes"
  63. },
  64. modalContentClasses: {
  65. type: [Object, String],
  66. description: "Modal dialog content css classes"
  67. },
  68. gradient: {
  69. type: String,
  70. description: "Modal gradient type (danger, primary etc)"
  71. },
  72. headerClasses: {
  73. type: [Object, String],
  74. description: "Modal Header css classes"
  75. },
  76. bodyClasses: {
  77. type: [Object, String],
  78. description: "Modal Body css classes"
  79. },
  80. footerClasses: {
  81. type: [Object, String],
  82. description: "Modal Footer css classes"
  83. },
  84. animationDuration: {
  85. type: Number,
  86. default: 500,
  87. description: "Modal transition duration"
  88. }
  89. },
  90. methods: {
  91. closeModal() {
  92. this.$emit("update:show", false);
  93. this.$emit("close");
  94. }
  95. },
  96. watch: {
  97. show(val) {
  98. let documentClasses = document.body.classList;
  99. if (val) {
  100. documentClasses.add("modal-open");
  101. } else {
  102. documentClasses.remove("modal-open");
  103. }
  104. }
  105. }
  106. };
  107. </script>
  108. <style>
  109. .modal.show {
  110. background-color: rgba(0, 0, 0, 0.3);
  111. }
  112. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement