VdomTransitionGroup.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <script setup lang="ts">
  2. import { ref } from 'vue'
  3. import VaporExpandingItem from '../../transition-group/components/VaporExpandingItem.vue'
  4. const items = ref(
  5. [...Array(2)].map((_, i) => ({
  6. id: i + 1,
  7. isOpened: false,
  8. })),
  9. )
  10. function toggleExpansion() {
  11. items.value[0].isOpened = !items.value[0].isOpened
  12. }
  13. </script>
  14. <template>
  15. <div class="trans-group-vapor-component-move">
  16. <button @click="toggleExpansion">toggle expansion of first element</button>
  17. <div>
  18. <transition-group name="group" tag="div" class="item-wrapper">
  19. <VaporExpandingItem
  20. v-for="i in items"
  21. :key="`${i.id}-${i.isOpened ? 'true' : 'false'}`"
  22. :id="i.id"
  23. :is-opened="i.isOpened"
  24. />
  25. </transition-group>
  26. </div>
  27. </div>
  28. </template>
  29. <style>
  30. .item-wrapper {
  31. display: flex;
  32. flex-wrap: wrap;
  33. gap: 5px;
  34. width: 430px;
  35. }
  36. .group-move,
  37. .group-enter-active,
  38. .group-leave-active {
  39. transition: all 50ms cubic-bezier(0.55, 0, 0.1, 1);
  40. }
  41. .group-leave-active {
  42. position: absolute;
  43. }
  44. </style>