2022-12-04 17:17:02 +03:00
|
|
|
<script lang="ts" setup>
|
2023-08-03 18:05:58 +03:00
|
|
|
import { invoke } from '@vueuse/core'
|
|
|
|
|
2023-08-01 12:43:55 +03:00
|
|
|
const modelValue = defineModel<boolean>({ required: true })
|
2022-12-29 15:26:08 +03:00
|
|
|
const colorMode = useColorMode()
|
2022-12-04 17:17:02 +03:00
|
|
|
|
2023-01-12 20:52:52 +03:00
|
|
|
const userSettings = useUserSettings()
|
|
|
|
|
2023-08-03 18:05:58 +03:00
|
|
|
const drawerEl = ref<HTMLDivElement>()
|
|
|
|
|
2023-01-06 18:46:36 +03:00
|
|
|
function toggleVisible() {
|
2023-08-02 12:43:24 +03:00
|
|
|
modelValue.value = !modelValue.value
|
2022-12-04 17:17:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const buttonEl = ref<HTMLDivElement>()
|
2024-01-18 11:18:49 +03:00
|
|
|
/**
|
|
|
|
* Close the drop-down menu if the mouse click is not on the drop-down menu button when the drop-down menu is opened
|
|
|
|
* @param mouse
|
|
|
|
*/
|
2022-12-04 17:17:02 +03:00
|
|
|
function clickEvent(mouse: MouseEvent) {
|
|
|
|
if (mouse.target && !buttonEl.value?.children[0].contains(mouse.target as any)) {
|
2023-08-03 18:05:58 +03:00
|
|
|
if (modelValue.value) {
|
2022-12-04 17:17:02 +03:00
|
|
|
document.removeEventListener('click', clickEvent)
|
2023-08-01 12:43:55 +03:00
|
|
|
modelValue.value = false
|
2022-12-04 17:17:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-28 04:06:54 +03:00
|
|
|
function toggleDark() {
|
2022-12-29 15:26:08 +03:00
|
|
|
colorMode.preference = colorMode.value === 'dark' ? 'light' : 'dark'
|
2022-12-28 04:06:54 +03:00
|
|
|
}
|
|
|
|
|
2023-08-03 18:05:58 +03:00
|
|
|
watch(modelValue, (val) => {
|
2022-12-05 16:20:23 +03:00
|
|
|
if (val && typeof document !== 'undefined')
|
|
|
|
document.addEventListener('click', clickEvent)
|
|
|
|
})
|
2022-12-04 17:17:02 +03:00
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2022-12-05 16:20:23 +03:00
|
|
|
document.removeEventListener('click', clickEvent)
|
2022-12-04 17:17:02 +03:00
|
|
|
})
|
2023-08-03 18:05:58 +03:00
|
|
|
|
|
|
|
// Pull down to close
|
|
|
|
const { dragging, dragDistance } = invoke(() => {
|
|
|
|
const triggerDistance = 120
|
|
|
|
|
|
|
|
let scrollTop = 0
|
|
|
|
let beforeTouchPointY = 0
|
|
|
|
|
|
|
|
const dragDistance = ref(0)
|
|
|
|
const dragging = ref(false)
|
|
|
|
|
|
|
|
useEventListener(drawerEl, 'scroll', (e: Event) => {
|
|
|
|
scrollTop = (e.target as HTMLDivElement).scrollTop
|
|
|
|
|
|
|
|
// Prevent the page from scrolling when the drawer is being dragged.
|
|
|
|
if (dragDistance.value > 0)
|
|
|
|
(e.target as HTMLDivElement).scrollTop = 0
|
|
|
|
}, { passive: true })
|
|
|
|
|
|
|
|
useEventListener(drawerEl, 'touchstart', (e: TouchEvent) => {
|
|
|
|
if (!modelValue.value)
|
|
|
|
return
|
|
|
|
|
|
|
|
beforeTouchPointY = e.touches[0].pageY
|
|
|
|
dragDistance.value = 0
|
|
|
|
}, { passive: true })
|
|
|
|
|
|
|
|
useEventListener(drawerEl, 'touchmove', (e: TouchEvent) => {
|
|
|
|
if (!modelValue.value)
|
|
|
|
return
|
|
|
|
|
|
|
|
// Do not move the entire drawer when its contents are not scrolled to the top.
|
|
|
|
if (scrollTop > 0 && dragDistance.value <= 0) {
|
|
|
|
dragging.value = false
|
|
|
|
beforeTouchPointY = e.touches[0].pageY
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const { pageY } = e.touches[0]
|
|
|
|
|
|
|
|
// Calculate the drag distance.
|
|
|
|
dragDistance.value += pageY - beforeTouchPointY
|
|
|
|
if (dragDistance.value < 0)
|
|
|
|
dragDistance.value = 0
|
|
|
|
beforeTouchPointY = pageY
|
|
|
|
|
|
|
|
// Marked as dragging.
|
|
|
|
if (dragDistance.value > 1)
|
|
|
|
dragging.value = true
|
|
|
|
|
|
|
|
// Prevent the page from scrolling when the drawer is being dragged.
|
|
|
|
if (dragDistance.value > 0) {
|
|
|
|
if (e?.cancelable && e?.preventDefault)
|
|
|
|
e.preventDefault()
|
|
|
|
e?.stopPropagation()
|
|
|
|
}
|
|
|
|
}, { passive: true })
|
|
|
|
|
|
|
|
useEventListener(drawerEl, 'touchend', () => {
|
|
|
|
if (!modelValue.value)
|
|
|
|
return
|
|
|
|
|
|
|
|
if (dragDistance.value >= triggerDistance)
|
|
|
|
modelValue.value = false
|
|
|
|
|
|
|
|
dragging.value = false
|
|
|
|
// code
|
|
|
|
}, { passive: true })
|
|
|
|
|
|
|
|
return {
|
|
|
|
dragDistance,
|
|
|
|
dragging,
|
|
|
|
}
|
|
|
|
})
|
2022-12-04 17:17:02 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div ref="buttonEl" flex items-center static>
|
2023-01-06 18:46:36 +03:00
|
|
|
<slot :toggle-visible="toggleVisible" :show="modelValue" />
|
2022-12-04 17:17:02 +03:00
|
|
|
|
|
|
|
<!-- Drawer -->
|
|
|
|
<Transition
|
2023-08-03 18:05:58 +03:00
|
|
|
enter-active-class="transition duration-250 ease-out"
|
|
|
|
enter-from-class="opacity-0 children:(translate-y-full)"
|
|
|
|
enter-to-class="opacity-100 children:(translate-y-0)"
|
|
|
|
leave-active-class="transition duration-250 ease-in"
|
|
|
|
leave-from-class="opacity-100 children:(translate-y-0)"
|
|
|
|
leave-to-class="opacity-0 children:(translate-y-full)"
|
2022-12-04 17:17:02 +03:00
|
|
|
>
|
|
|
|
<div
|
2023-01-06 18:46:36 +03:00
|
|
|
v-show="modelValue"
|
2022-12-04 17:17:02 +03:00
|
|
|
absolute inset-x-0 top-auto bottom-full z-20 h-100vh
|
2022-12-05 16:20:23 +03:00
|
|
|
flex items-end of-y-scroll of-x-hidden scrollbar-hide overscroll-none
|
2022-12-04 17:17:02 +03:00
|
|
|
bg="black/50"
|
|
|
|
>
|
|
|
|
<!-- The style `scrollbar-hide overscroll-none overflow-y-scroll mb="-1px"` and `h="[calc(100%+0.5px)]"` is used to implement scroll locking, -->
|
|
|
|
<!-- corresponding to issue: #106, so please don't remove it. -->
|
|
|
|
<div absolute inset-0 opacity-0 h="[calc(100vh+0.5px)]" />
|
|
|
|
<div
|
2023-08-03 18:05:58 +03:00
|
|
|
ref="drawerEl"
|
|
|
|
:style="{
|
|
|
|
transform: dragging ? `translateY(${dragDistance}px)` : '',
|
|
|
|
}"
|
|
|
|
:class="{
|
|
|
|
'duration-0': dragging,
|
|
|
|
'duration-250': !dragging,
|
2024-01-18 11:18:49 +03:00
|
|
|
'backdrop-blur-md': !getPreferences(userSettings, 'optimizeForLowPerformanceDevice'),
|
2023-08-03 18:05:58 +03:00
|
|
|
}"
|
|
|
|
transition="transform ease-in"
|
2022-12-04 17:17:02 +03:00
|
|
|
flex-1 min-w-48 py-6 mb="-1px"
|
2022-12-05 16:20:23 +03:00
|
|
|
of-y-auto scrollbar-hide overscroll-none max-h="[calc(100vh-200px)]"
|
2024-01-18 11:18:49 +03:00
|
|
|
rounded-t-lg bg="white/85 dark:neutral-900/85" backdrop-filter
|
2022-12-04 17:17:02 +03:00
|
|
|
border-t-1 border-base
|
|
|
|
>
|
|
|
|
<!-- Nav -->
|
|
|
|
<NavSide />
|
|
|
|
|
|
|
|
<!-- Divider line -->
|
|
|
|
<div border="neutral-300 dark:neutral-700 t-1" m="x-3 y-2" />
|
|
|
|
|
|
|
|
<!-- Function menu -->
|
|
|
|
<div flex="~ col gap2">
|
|
|
|
<!-- Toggle Theme -->
|
|
|
|
<button
|
|
|
|
flex flex-row items-center
|
|
|
|
block px-5 py-2 focus-blue w-full
|
|
|
|
text-sm text-base capitalize text-left whitespace-nowrap
|
|
|
|
transition-colors duration-200 transform
|
|
|
|
hover="bg-gray-100 dark:(bg-gray-700 text-white)"
|
|
|
|
@click="toggleDark()"
|
|
|
|
>
|
2023-01-01 17:29:11 +03:00
|
|
|
<span class="i-ri:sun-line dark:i-ri:moon-line flex-shrink-0 text-xl me-4 !align-middle" />
|
2022-12-29 15:26:08 +03:00
|
|
|
{{ colorMode.value === 'light' ? $t('menu.toggle_theme.dark') : $t('menu.toggle_theme.light') }}
|
2022-12-04 17:17:02 +03:00
|
|
|
</button>
|
2023-01-11 17:00:41 +03:00
|
|
|
|
|
|
|
<!-- Zen Mode -->
|
|
|
|
<button
|
|
|
|
flex flex-row items-center
|
|
|
|
block px-5 py-2 focus-blue w-full
|
|
|
|
text-sm text-base capitalize text-left whitespace-nowrap
|
|
|
|
transition-colors duration-200 transform
|
|
|
|
hover="bg-gray-100 dark:(bg-gray-700 text-white)"
|
|
|
|
:aria-label="$t('nav.zen_mode')"
|
2023-04-23 13:21:33 +03:00
|
|
|
@click="togglePreferences('zenMode')"
|
2023-01-11 17:00:41 +03:00
|
|
|
>
|
2023-04-23 13:21:33 +03:00
|
|
|
<span :class="getPreferences(userSettings, 'zenMode') ? 'i-ri:layout-right-2-line' : 'i-ri:layout-right-line'" class="flex-shrink-0 text-xl me-4 !align-middle" />
|
2023-01-11 17:00:41 +03:00
|
|
|
{{ $t('nav.zen_mode') }}
|
|
|
|
</button>
|
2022-12-04 17:17:02 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
</template>
|