WIP - bottom drawer width fix
This commit is contained in:
@@ -1,13 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Toaster } from 'vue-sonner'
|
import { Toaster } from 'vue-sonner'
|
||||||
import BottomDrawer from '@/components/BottomDrawer.vue'
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Toaster position="top-right" :duration="4000" richColors />
|
<Toaster position="top-right" :duration="4000" richColors />
|
||||||
<NuxtPage />
|
<NuxtPage />
|
||||||
<BottomDrawer />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import { useSoftphone } from '~/composables/useSoftphone'
|
|||||||
const isDrawerOpen = useState<boolean>('bottomDrawerOpen', () => false)
|
const isDrawerOpen = useState<boolean>('bottomDrawerOpen', () => false)
|
||||||
const activeTab = useState<string>('bottomDrawerTab', () => 'softphone')
|
const activeTab = useState<string>('bottomDrawerTab', () => 'softphone')
|
||||||
const drawerHeight = useState<number>('bottomDrawerHeight', () => 240)
|
const drawerHeight = useState<number>('bottomDrawerHeight', () => 240)
|
||||||
|
const props = defineProps<{
|
||||||
|
bounds?: { left: number; width: number }
|
||||||
|
}>()
|
||||||
|
|
||||||
const softphone = useSoftphone()
|
const softphone = useSoftphone()
|
||||||
|
|
||||||
@@ -190,7 +193,14 @@ onBeforeUnmount(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="pointer-events-none fixed inset-x-0 bottom-0 z-30 flex justify-center px-2">
|
<div
|
||||||
|
class="pointer-events-none fixed bottom-0 z-30 flex justify-center px-2"
|
||||||
|
:style="{
|
||||||
|
left: props.bounds?.left ? `${props.bounds.left}px` : '0',
|
||||||
|
width: props.bounds?.width ? `${props.bounds.width}px` : '100vw',
|
||||||
|
right: props.bounds?.width ? 'auto' : '0',
|
||||||
|
}"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
class="pointer-events-auto w-full border border-border bg-background shadow-xl transition-all duration-200"
|
class="pointer-events-auto w-full border border-border bg-background shadow-xl transition-all duration-200"
|
||||||
:style="{ height: `${isDrawerOpen ? drawerHeight : collapsedHeight}px` }"
|
:style="{ height: `${isDrawerOpen ? drawerHeight : collapsedHeight}px` }"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||||
import AppSidebar from '@/components/AppSidebar.vue'
|
import AppSidebar from '@/components/AppSidebar.vue'
|
||||||
import BottomDrawer from '@/components/BottomDrawer.vue'
|
import BottomDrawer from '@/components/BottomDrawer.vue'
|
||||||
import {
|
import {
|
||||||
@@ -15,6 +15,9 @@ import { SidebarInset, SidebarProvider, SidebarTrigger } from '@/components/ui/s
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { breadcrumbs: customBreadcrumbs } = useBreadcrumbs()
|
const { breadcrumbs: customBreadcrumbs } = useBreadcrumbs()
|
||||||
|
const drawerBounds = useState('bottomDrawerBounds', () => ({ left: 0, width: 0 }))
|
||||||
|
const insetRef = ref<any>(null)
|
||||||
|
let resizeObserver: ResizeObserver | null = null
|
||||||
|
|
||||||
const breadcrumbs = computed(() => {
|
const breadcrumbs = computed(() => {
|
||||||
// If custom breadcrumbs are set by the page, use those
|
// If custom breadcrumbs are set by the page, use those
|
||||||
@@ -30,12 +33,47 @@ const breadcrumbs = computed(() => {
|
|||||||
isLast: index === paths.length - 1,
|
isLast: index === paths.length - 1,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const resolveInsetEl = (): HTMLElement | null => {
|
||||||
|
const maybeComponent = insetRef.value as any
|
||||||
|
if (!maybeComponent) return null
|
||||||
|
return maybeComponent.$el ? maybeComponent.$el as HTMLElement : (maybeComponent as HTMLElement)
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateBounds = () => {
|
||||||
|
const el = resolveInsetEl()
|
||||||
|
if (!el || typeof el.getBoundingClientRect !== 'function') return
|
||||||
|
const rect = el.getBoundingClientRect()
|
||||||
|
drawerBounds.value = {
|
||||||
|
left: rect.left,
|
||||||
|
width: rect.width,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
updateBounds()
|
||||||
|
const el = resolveInsetEl()
|
||||||
|
if (el && 'ResizeObserver' in window) {
|
||||||
|
resizeObserver = new ResizeObserver(updateBounds)
|
||||||
|
resizeObserver.observe(el)
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', updateBounds)
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
const el = resolveInsetEl()
|
||||||
|
if (resizeObserver && el) {
|
||||||
|
resizeObserver.unobserve(el)
|
||||||
|
}
|
||||||
|
resizeObserver = null
|
||||||
|
window.removeEventListener('resize', updateBounds)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
<AppSidebar />
|
<AppSidebar />
|
||||||
<SidebarInset class="flex flex-col">
|
<SidebarInset ref="insetRef" class="relative flex flex-col">
|
||||||
<header
|
<header
|
||||||
class="relative z-10 flex h-16 shrink-0 items-center gap-2 bg-background transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12 border-b shadow-md"
|
class="relative z-10 flex h-16 shrink-0 items-center gap-2 bg-background transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-12 border-b shadow-md"
|
||||||
>
|
>
|
||||||
@@ -73,7 +111,8 @@ const breadcrumbs = computed(() => {
|
|||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Keep BottomDrawer bound to the inset width so it aligns with the sidebar layout -->
|
||||||
|
<BottomDrawer :bounds="drawerBounds" />
|
||||||
</SidebarInset>
|
</SidebarInset>
|
||||||
</SidebarProvider>
|
</SidebarProvider>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user