SideBar.vue 948 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-70' : 'bg-opacity-0'"
  4. class="w-full h-full bg-black animate__animated animate__faster animate__fadeIn duration-500" />
  5. <div :class="store.isVisible ? 'animate__animated animate__faster animate__slideInLeft' : 'animate__animated animate__faster animate__slideOutLeft'"
  6. class="absolute top-0 w-3/4 h-full bg-background-100" :style="`left: -${translateTo}px`"></div>
  7. </div>
  8. </template>
  9. <script setup lang="ts">
  10. import { useSideBar } from '~/store/useSideBar';
  11. import { useSwipe } from '@vueuse/core'
  12. const store = useSideBar()
  13. const sideBarEl = ref(null)
  14. const translateTo = ref(null)
  15. const { direction } = useSwipe(sideBarEl, {
  16. onSwipeEnd() {
  17. if (direction.value === 'left')
  18. store.hide()
  19. }
  20. })
  21. </script>