Modal.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <!-- This example requires Tailwind CSS v2.0+ -->
  2. <template>
  3. <TransitionRoot as="template" :show="open">
  4. <Dialog as="div" class="relative z-10" @close="open = false">
  5. <TransitionChild
  6. as="template"
  7. enter="ease-out duration-300"
  8. enter-from="opacity-0"
  9. enter-to="opacity-100"
  10. leave="ease-in duration-200"
  11. leave-from="opacity-100"
  12. leave-to="opacity-0"
  13. >
  14. <div class="fixed inset-0 bg-grey-500 bg-opacity-75 transition-opacity" />
  15. </TransitionChild>
  16. <div class="fixed z-10 inset-0 overflow-y-auto">
  17. <div
  18. class="flex items-end sm:items-center justify-center min-h-full p-4 text-center sm:p-0"
  19. >
  20. <TransitionChild
  21. as="template"
  22. enter="ease-out duration-300"
  23. enter-from="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
  24. enter-to="opacity-100 translate-y-0 sm:scale-100"
  25. leave="ease-in duration-200"
  26. leave-from="opacity-100 translate-y-0 sm:scale-100"
  27. leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
  28. >
  29. <DialogPanel
  30. class="relative bg-white rounded-lg px-4 pt-5 pb-4 text-left shadow-xl transform transition-all sm:my-8 sm:w-full sm:p-6"
  31. :class="maxWidth ? maxWidth : 'sm:max-w-lg'"
  32. >
  33. <div class="mt-3 text-center sm:mt-0 sm:text-left">
  34. <DialogTitle
  35. as="h2"
  36. class="text-2xl leading-tight font-medium text-grey-900 border-b-2 border-grey-100 pb-4"
  37. >
  38. <slot name="title"></slot>
  39. </DialogTitle>
  40. <div class="mt-2">
  41. <slot name="content"></slot>
  42. </div>
  43. </div>
  44. </DialogPanel>
  45. </TransitionChild>
  46. </div>
  47. </div>
  48. </Dialog>
  49. </TransitionRoot>
  50. </template>
  51. <script>
  52. import { Dialog, DialogPanel, DialogTitle, TransitionChild, TransitionRoot } from '@headlessui/vue'
  53. export default {
  54. props: ['open', 'maxWidth'],
  55. components: {
  56. Dialog,
  57. DialogPanel,
  58. DialogTitle,
  59. TransitionChild,
  60. TransitionRoot,
  61. },
  62. }
  63. </script>