index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* istanbul ignore file */
  2. import { getCurrentInstance } from 'vue'
  3. const AFTER_APPEAR = 'after-appear'
  4. const AFTER_ENTER = 'after-enter'
  5. const AFTER_LEAVE = 'after-leave'
  6. const APPEAR = 'appear'
  7. const APPEAR_CANCELLED = 'appear-cancelled'
  8. const BEFORE_ENTER = 'before-enter'
  9. const BEFORE_LEAVE = 'before-leave'
  10. const ENTER = 'enter'
  11. const ENTER_CANCELLED = 'enter-cancelled'
  12. const LEAVE = 'leave'
  13. const LEAVE_CANCELLED = 'leave-cancelled'
  14. export const useTransitionFallthroughEmits = [
  15. AFTER_APPEAR,
  16. AFTER_ENTER,
  17. AFTER_LEAVE,
  18. APPEAR,
  19. APPEAR_CANCELLED,
  20. BEFORE_ENTER,
  21. BEFORE_LEAVE,
  22. ENTER,
  23. ENTER_CANCELLED,
  24. LEAVE,
  25. LEAVE_CANCELLED,
  26. ] as const
  27. // Sometimes we want to delegate the transition emitted event
  28. // we have to right the function locally, which is not a good
  29. // approach to this, so we created this hook for the event
  30. // fallthrough
  31. /**
  32. * NOTE:
  33. * This is only a delegator for delegating transition callbacks.
  34. * Use this at your need.
  35. */
  36. /**
  37. * Simple usage
  38. *
  39. * In your setups:
  40. *
  41. * setup() {
  42. * const fallthroughMethods = useTransitionFallthrough()
  43. * return fallthrough
  44. * }
  45. *
  46. * In your template:
  47. *
  48. * <template>
  49. * <transition name="whatever" v-bind="fallthrough">
  50. * <slot />
  51. * </transition>
  52. * </template>
  53. *
  54. */
  55. export const useTransitionFallthrough = () => {
  56. const { emit } = getCurrentInstance()!
  57. return {
  58. onAfterAppear: () => {
  59. emit(AFTER_APPEAR)
  60. },
  61. onAfterEnter: () => {
  62. emit(AFTER_ENTER)
  63. },
  64. onAfterLeave: () => {
  65. emit(AFTER_LEAVE)
  66. },
  67. onAppearCancelled: () => {
  68. emit(APPEAR_CANCELLED)
  69. },
  70. onBeforeEnter: () => {
  71. emit(BEFORE_ENTER)
  72. },
  73. onBeforeLeave: () => {
  74. emit(BEFORE_LEAVE)
  75. },
  76. onEnter: () => {
  77. emit(ENTER)
  78. },
  79. onEnterCancelled: () => {
  80. emit(ENTER_CANCELLED)
  81. },
  82. onLeave: () => {
  83. emit(LEAVE)
  84. },
  85. onLeaveCancelled: () => {
  86. emit(LEAVE_CANCELLED)
  87. },
  88. }
  89. }