CommonRefetch.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { ref, watch } from 'vue'
  4. const props = defineProps<{
  5. refetch: boolean
  6. }>()
  7. defineOptions({ inheritAttrs: false })
  8. const refetching = ref(false)
  9. let timeout: number
  10. watch(
  11. () => props.refetch,
  12. (status) => {
  13. if (status) {
  14. timeout = window.setTimeout(() => {
  15. refetching.value = true
  16. }, 250)
  17. } else {
  18. window.clearTimeout(timeout)
  19. refetching.value = false
  20. }
  21. },
  22. )
  23. </script>
  24. <template>
  25. <Transition
  26. enter-active-class="transition-opacity duration-200"
  27. leave-active-class="transition-opacity duration-200"
  28. enter-from-class="opacity-0"
  29. leave-to-class="opacity-0"
  30. >
  31. <div
  32. v-if="refetching"
  33. v-bind="$attrs"
  34. class="absolute items-center justify-center"
  35. role="status"
  36. >
  37. <CommonIcon
  38. :label="__('Loading content')"
  39. name="loading"
  40. animation="spin"
  41. />
  42. </div>
  43. <div v-else v-bind="$attrs">
  44. <slot />
  45. </div>
  46. </Transition>
  47. </template>