Skip to content

Commit 9d0986a

Browse files
committed
refactor: improve sidebar layout and CSS variable handling in DashboardLayout component
1 parent 82ce3c4 commit 9d0986a

File tree

1 file changed

+49
-25
lines changed

1 file changed

+49
-25
lines changed

services/frontend/src/components/DashboardLayout.vue

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,68 @@ const props = defineProps<Props>()
1313
// For now, defaulting to true.
1414
const defaultOpen = ref(true)
1515
16-
// Define sidebar width. The shadcn/ui example uses `calc(var(--spacing) * 72)`.
17-
// Assuming var(--spacing) is ~4px, this is 288px. Let's use 18rem (288px).
18-
// The shadcn-vue sidebar components should pick up this CSS variable.
16+
// Define sidebar width using the default values from the sidebar utils
17+
// The sidebar components expect these specific CSS variables
1918
const sidebarStyle = computed(() => ({
20-
'--sidebar-width': '18rem',
21-
// '--sidebar-width-mobile': '16rem', // Optional: if your AppSidebar handles mobile width
19+
'--sidebar-width': '16rem',
20+
'--sidebar-width-mobile': '18rem',
21+
'--sidebar-width-icon': '3rem',
2222
} as StyleValue))
2323
2424
// A simple ref for the SiteHeader, can be expanded later
2525
// For now, just using the title prop.
2626
</script>
2727

2828
<template>
29-
<div class="flex h-screen w-full overflow-hidden"> {/* Ensure full screen and no body scroll */}
30-
<SidebarProvider :default-open="defaultOpen" :style="sidebarStyle">
31-
<AppSidebar variant="inset" />
32-
<SidebarInset>
33-
<!-- SiteHeader equivalent -->
34-
<header class="sticky top-0 z-30 flex h-16 items-center justify-between gap-4 border-b bg-background px-4 sm:px-6">
35-
<div class="flex items-center gap-2">
36-
<SidebarTrigger class="-ml-1 lg:hidden" />
37-
<h1 class="text-lg font-semibold md:text-xl">{{ props.title }}</h1>
38-
</div>
39-
<!-- Add other header elements like user menu, search, etc. here if needed -->
40-
</header>
41-
42-
<!-- Main content area -->
43-
<main class="flex flex-1 flex-col overflow-auto p-4 pt-2 md:gap-4 md:p-6 md:pt-4">
44-
<slot />
45-
</main>
46-
</SidebarInset>
47-
</SidebarProvider>
48-
</div>
29+
<SidebarProvider :default-open="defaultOpen" :style="sidebarStyle">
30+
<AppSidebar variant="inset" />
31+
<SidebarInset>
32+
<!-- SiteHeader equivalent -->
33+
<header class="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12">
34+
<div class="flex items-center gap-2 px-4">
35+
<SidebarTrigger class="-ml-1" />
36+
<h1 class="text-lg font-semibold md:text-xl">{{ props.title }}</h1>
37+
</div>
38+
</header>
39+
40+
<!-- Content area -->
41+
<div class="flex flex-1 flex-col gap-4 p-4 pt-0">
42+
<slot />
43+
</div>
44+
</SidebarInset>
45+
</SidebarProvider>
4946
</template>
5047

5148
<style>
5249
/* Optional: Ensure body doesn't scroll if the layout is truly full-page */
5350
/* body {
5451
overflow: hidden;
5552
} */
53+
54+
/* Fix the sidebar layout by ensuring CSS variables work */
55+
.group\/sidebar-wrapper {
56+
display: flex;
57+
min-height: 100svh;
58+
width: 100%;
59+
}
60+
61+
/* Ensure the spacer div actually takes up space */
62+
.group\/sidebar-wrapper .group.peer [class*="w-[--sidebar-width]"] {
63+
width: var(--sidebar-width) !important;
64+
}
65+
66+
/* Force the main content to account for sidebar space */
67+
@media (min-width: 768px) {
68+
.group\/sidebar-wrapper:has([data-variant="inset"]) main {
69+
margin: 0.5rem;
70+
margin-left: 0;
71+
border-radius: 0.75rem;
72+
box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
73+
}
74+
75+
/* Ensure the sidebar spacer works */
76+
.group\/sidebar-wrapper .group.peer {
77+
flex-shrink: 0;
78+
}
79+
}
5680
</style>

0 commit comments

Comments
 (0)