SideBar.vue 925 B

1234567891011121314151617181920212223
  1. <template>
  2. <div v-if="store.isRendered" ref="sideBarEl" class="w-screen h-screen fixed top-0 left-0 z-10">
  3. <div @click="store.hide" :class="store.isVisible ? 'bg-opacity-50' : 'bg-opacity-0'" class="w-full h-full bg-black animate__animated animate__faster animate__fadeIn duration-500" />
  4. <div :class="store.isVisible ? 'animate__animated animate__faster animate__slideInLeft' : 'animate__animated animate__faster animate__slideOutLeft'" class="absolute top-0 w-3/4 h-full bg-stone-900" :style="`left: -${translateTo}px`"></div>
  5. </div>
  6. </template>
  7. <script setup lang="ts">
  8. import { useSideBar } from '~/store/useSideBar';
  9. import { useSwipe } from '@vueuse/core'
  10. const store = useSideBar()
  11. const sideBarEl = ref(null)
  12. const translateTo = ref(null)
  13. const {direction} = useSwipe(sideBarEl, {
  14. onSwipeEnd() {
  15. if (direction.value === 'left')
  16. store.hide()
  17. }
  18. })
  19. </script>
  20. style