💄 redesign authenticated sidebar shell
Browse files at this commit3ad313e39057234d66a400b9c9b3e5cd9f29efb6Parent: 40d23c9- style
- 💄 redesign authenticated sidebar shell
4 changed files +195 -58
- src/components/layout/app-shell.tsx +65 -25
- src/components/layout/side-nav.tsx +8 -5
- src/components/layout/sidebar-account.tsx +89 -0
- src/index.css +33 -28
src/components/layout/app-shell.tsxmodified+65 -25
| @@ -1,10 +1,11 @@ | ||
| 1 | 1 | import type { ParentProps } from "solid-js"; |
| 2 | -import { useLocation } from "@tanstack/solid-router"; | |
| 3 | -import { Show } from "solid-js"; | |
| 2 | +import { Link, useLocation, useNavigate } from "@tanstack/solid-router"; | |
| 3 | +import { Show, createSignal } from "solid-js"; | |
| 4 | 4 | import { NavBar } from "@/components/layout/nav-bar"; |
| 5 | 5 | import { SideNav } from "@/components/layout/side-nav"; |
| 6 | +import { SidebarAccount } from "@/components/layout/sidebar-account"; | |
| 6 | 7 | import { Button } from "@/components/ui/button"; |
| 7 | -import { IconChevronLeft, IconChevronRight } from "@/components/ui/icons"; | |
| 8 | +import { IconChevronLeft, IconChevronRight, IconMenu } from "@/components/ui/icons"; | |
| 8 | 9 | import { useAuth } from "@/stores/auth-context"; |
| 9 | 10 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 10 | 11 | import { cn } from "@/lib/cn"; |
| @@ -16,68 +17,107 @@ export function AppShell(props: ParentProps) { | ||
| 16 | 17 | const auth = useAuth(); |
| 17 | 18 | const prefs = usePreferences(); |
| 18 | 19 | const t = useT(); |
| 20 | + const navigate = useNavigate(); | |
| 21 | + const [mobileOpen, setMobileOpen] = createSignal(false); | |
| 19 | 22 | const collapsed = () => prefs.sidebarCollapsed(); |
| 20 | 23 | const location = useLocation(); |
| 21 | 24 | const wide = () => location().pathname.startsWith("/exam-room/"); |
| 25 | + const logout = async () => { | |
| 26 | + await auth.logout(); | |
| 27 | + void navigate({ to: "/login" }); | |
| 28 | + }; | |
| 22 | 29 | |
| 23 | 30 | return ( |
| 24 | - <div class="min-h-screen"> | |
| 25 | - <NavBar /> | |
| 31 | + <div class="min-h-screen bg-background text-foreground"> | |
| 32 | + <Show when={!auth.user()}> | |
| 33 | + <NavBar /> | |
| 34 | + </Show> | |
| 35 | + <Show when={auth.user()}> | |
| 36 | + <Button | |
| 37 | + type="button" | |
| 38 | + variant="outline" | |
| 39 | + size="sm" | |
| 40 | + class="fixed left-3 top-3 z-40 h-10 w-10 rounded-xl bg-background/90 px-0 shadow-sm backdrop-blur lg:hidden" | |
| 41 | + aria-label={t("nav.menu")} | |
| 42 | + onClick={() => setMobileOpen(true)} | |
| 43 | + > | |
| 44 | + <IconMenu class="h-5 w-5" /> | |
| 45 | + </Button> | |
| 46 | + </Show> | |
| 26 | 47 | <div class="flex w-full"> |
| 27 | 48 | <Show when={auth.user()}> |
| 28 | 49 | <aside |
| 29 | 50 | class={cn( |
| 30 | - "sticky top-14 z-30 hidden h-[calc(100vh-3.5rem)] shrink-0 border-r border-border/70 bg-sidebar/95 shadow-[inset_-1px_0_0_hsl(var(--border)/0.35)] backdrop-blur lg:flex lg:flex-col", | |
| 51 | + "sticky top-0 z-30 hidden h-screen shrink-0 border-r border-border/80 bg-sidebar shadow-[inset_-1px_0_0_hsl(var(--border)/0.45)] lg:flex lg:flex-col", | |
| 31 | 52 | collapsed() ? SIDEBAR_COLLAPSED : SIDEBAR_EXPANDED, |
| 32 | 53 | )} |
| 33 | 54 | > |
| 34 | 55 | <div |
| 35 | 56 | class={cn( |
| 36 | - "flex h-14 shrink-0 items-center border-b border-border/70", | |
| 57 | + "flex h-16 shrink-0 items-center gap-2 border-b border-border/70", | |
| 37 | 58 | collapsed() ? "justify-center px-2" : "px-3", |
| 38 | 59 | )} |
| 39 | 60 | > |
| 61 | + <Link to="/" class={cn("flex min-w-0 flex-1 items-center gap-2", collapsed() && "hidden")}> | |
| 62 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-primary text-sm font-black text-primary-foreground shadow-sm"> | |
| 63 | + H | |
| 64 | + </span> | |
| 65 | + <span class="truncate font-display text-lg font-semibold tracking-tight">{t("app.name")}</span> | |
| 66 | + </Link> | |
| 40 | 67 | <Button |
| 41 | 68 | type="button" |
| 42 | 69 | variant="ghost" |
| 43 | 70 | size="sm" |
| 44 | 71 | class={cn( |
| 45 | - "h-9 rounded-lg text-muted-foreground hover:bg-muted/60 hover:text-foreground", | |
| 46 | - collapsed() ? "w-9 justify-center px-0" : "w-full justify-between px-3", | |
| 72 | + "h-9 rounded-xl text-muted-foreground hover:bg-muted/70 hover:text-foreground", | |
| 73 | + collapsed() ? "w-9 justify-center px-0" : "w-9 shrink-0 justify-center px-0", | |
| 47 | 74 | )} |
| 48 | 75 | aria-label={collapsed() ? t("nav.expand") : t("nav.collapse")} |
| 49 | 76 | title={collapsed() ? t("nav.expand") : t("nav.collapse")} |
| 50 | 77 | onClick={() => prefs.toggleSidebar()} |
| 51 | 78 | > |
| 52 | - <Show when={!collapsed()}> | |
| 53 | - <span class="text-xs font-medium">{t("nav.collapse")}</span> | |
| 54 | - </Show> | |
| 55 | 79 | <Show when={collapsed()} fallback={<IconChevronLeft class="h-4 w-4 shrink-0" />}> |
| 56 | 80 | <IconChevronRight class="h-4 w-4 shrink-0" /> |
| 57 | 81 | </Show> |
| 58 | 82 | </Button> |
| 59 | 83 | </div> |
| 60 | 84 | |
| 61 | - {/* Nav fills remaining height; guide is pinned above footer inside SideNav */} | |
| 62 | - <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden pt-3 pb-1"> | |
| 85 | + <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden py-4"> | |
| 63 | 86 | <SideNav collapsed={collapsed()} /> |
| 64 | 87 | </div> |
| 65 | 88 | |
| 66 | - <div | |
| 67 | - class={cn( | |
| 68 | - "shrink-0 border-t border-border", | |
| 69 | - collapsed() ? "hidden" : "flex items-center justify-center px-3 py-2", | |
| 70 | - )} | |
| 71 | - > | |
| 72 | - <p class="text-center text-[11px] leading-relaxed text-muted-foreground"> | |
| 73 | - {t("app.workspace")} | |
| 74 | - </p> | |
| 75 | - </div> | |
| 89 | + <SidebarAccount collapsed={collapsed()} onLogout={logout} /> | |
| 76 | 90 | </aside> |
| 77 | 91 | </Show> |
| 78 | 92 | |
| 93 | + <Show when={mobileOpen() && auth.user()}> | |
| 94 | + <div class="fixed inset-0 z-50 lg:hidden"> | |
| 95 | + <button | |
| 96 | + type="button" | |
| 97 | + class="absolute inset-0 bg-black/60 backdrop-blur-sm" | |
| 98 | + aria-label={t("nav.close")} | |
| 99 | + onClick={() => setMobileOpen(false)} | |
| 100 | + /> | |
| 101 | + <aside class="absolute inset-y-0 left-0 flex w-72 max-w-[85vw] flex-col border-r border-border bg-sidebar shadow-soft"> | |
| 102 | + <div class="flex h-16 shrink-0 items-center justify-between border-b border-border px-4"> | |
| 103 | + <Link to="/" class="flex items-center gap-2" onClick={() => setMobileOpen(false)}> | |
| 104 | + <span class="flex h-9 w-9 items-center justify-center rounded-xl bg-primary text-sm font-black text-primary-foreground">H</span> | |
| 105 | + <span class="font-display text-lg font-semibold">{t("app.name")}</span> | |
| 106 | + </Link> | |
| 107 | + <Button type="button" variant="ghost" size="sm" onClick={() => setMobileOpen(false)}> | |
| 108 | + {t("nav.close")} | |
| 109 | + </Button> | |
| 110 | + </div> | |
| 111 | + <div class="min-h-0 flex-1 overflow-y-auto py-4"> | |
| 112 | + <SideNav onNavigate={() => setMobileOpen(false)} /> | |
| 113 | + </div> | |
| 114 | + <SidebarAccount onLogout={logout} /> | |
| 115 | + </aside> | |
| 116 | + </div> | |
| 117 | + </Show> | |
| 118 | + | |
| 79 | 119 | <main class="min-w-0 flex-1"> |
| 80 | - <div class={cn("mx-auto w-full px-4 py-6 sm:px-6 lg:px-8 lg:py-8", wide() ? "max-w-none" : "max-w-[1200px]") }> | |
| 120 | + <div class={cn("mx-auto w-full px-4 py-6 sm:px-6 lg:px-8 lg:py-5", wide() ? "max-w-none" : "max-w-[1200px]") }> | |
| 81 | 121 | {props.children} |
| 82 | 122 | </div> |
| 83 | 123 | </main> |
src/components/layout/side-nav.tsxmodified+8 -5
| @@ -63,18 +63,21 @@ function NavLink(props: { | ||
| 63 | 63 | title={t(props.item.labelKey)} |
| 64 | 64 | aria-current={active() ? "page" : undefined} |
| 65 | 65 | class={cn( |
| 66 | - "group relative flex h-10 w-full items-center rounded-lg text-sm font-medium outline-none", | |
| 66 | + "group relative flex h-10 w-full items-center rounded-xl text-sm font-medium outline-none", | |
| 67 | 67 | "transition-all duration-150", |
| 68 | 68 | props.collapsed ? "justify-center px-0" : "gap-2 px-2", |
| 69 | 69 | active() |
| 70 | - ? "bg-primary/10 text-primary shadow-sm ring-1 ring-primary/15" | |
| 71 | - : "text-sidebar-foreground/80 hover:bg-muted/60 hover:text-foreground", | |
| 70 | + ? "bg-primary/10 text-primary shadow-sm ring-1 ring-primary/20" | |
| 71 | + : "text-sidebar-foreground/75 hover:bg-muted/70 hover:text-foreground", | |
| 72 | 72 | )} |
| 73 | 73 | > |
| 74 | + <Show when={active() && !props.collapsed}> | |
| 75 | + <span class="absolute left-0 top-1/2 h-5 w-0.5 -translate-y-1/2 rounded-full bg-primary" /> | |
| 76 | + </Show> | |
| 74 | 77 | <span |
| 75 | 78 | class={cn( |
| 76 | - "inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md transition-colors", | |
| 77 | - active() ? "bg-primary text-primary-foreground shadow-sm" : "text-muted-foreground group-hover:bg-background/50 group-hover:text-foreground", | |
| 79 | + "inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors", | |
| 80 | + active() ? "bg-primary text-primary-foreground shadow-sm" : "text-muted-foreground group-hover:bg-background/60 group-hover:text-foreground", | |
| 78 | 81 | )} |
| 79 | 82 | > |
| 80 | 83 | <props.item.Icon class="h-4 w-4" /> |
src/components/layout/sidebar-account.tsxadded+89 -0
| @@ -0,0 +1,89 @@ | ||
| 1 | +import { useNavigate } from "@tanstack/solid-router"; | |
| 2 | +import { Show } from "solid-js"; | |
| 3 | +import type { User } from "@/api/types"; | |
| 4 | +import type { MessageKey } from "@/i18n/messages"; | |
| 5 | +import { | |
| 6 | + DropdownMenu, | |
| 7 | + DropdownMenuContent, | |
| 8 | + DropdownMenuItem, | |
| 9 | + DropdownMenuSeparator, | |
| 10 | + DropdownMenuTrigger, | |
| 11 | +} from "@/components/ui/dropdown-menu"; | |
| 12 | +import { IconChevronRight, IconGlobe, IconLogout, IconMoon, IconSun } from "@/components/ui/icons"; | |
| 13 | +import { useAuth } from "@/stores/auth-context"; | |
| 14 | +import { usePreferences, useT } from "@/stores/preferences-context"; | |
| 15 | +import { cn } from "@/lib/cn"; | |
| 16 | + | |
| 17 | +function initials(value: string) { | |
| 18 | + const parts = value.trim().split(/\s+/).filter(Boolean); | |
| 19 | + if (parts.length === 0) return "H"; | |
| 20 | + if (parts.length === 1) return parts[0]!.slice(0, 2).toLocaleUpperCase("tr-TR"); | |
| 21 | + return `${parts[0]![0] ?? ""}${parts[1]![0] ?? ""}`.toLocaleUpperCase("tr-TR"); | |
| 22 | +} | |
| 23 | + | |
| 24 | +function displayName(user: User) { | |
| 25 | + return [user.name, user.surname].filter(Boolean).join(" ").trim() || user.username; | |
| 26 | +} | |
| 27 | + | |
| 28 | +export function SidebarAccount(props: { collapsed?: boolean; onLogout: () => void | Promise<void> }) { | |
| 29 | + const auth = useAuth(); | |
| 30 | + const prefs = usePreferences(); | |
| 31 | + const t = useT(); | |
| 32 | + const navigate = useNavigate(); | |
| 33 | + | |
| 34 | + return ( | |
| 35 | + <Show when={auth.user()}> | |
| 36 | + {(u) => { | |
| 37 | + const name = () => displayName(u()); | |
| 38 | + return ( | |
| 39 | + <div class={cn("shrink-0 border-t border-border/80 p-3", props.collapsed && "px-2")}> | |
| 40 | + <DropdownMenu placement="right-end" gutter={8}> | |
| 41 | + <DropdownMenuTrigger | |
| 42 | + class={cn( | |
| 43 | + "flex w-full items-center rounded-xl border border-border/80 bg-muted/35 text-left outline-none transition-colors", | |
| 44 | + "hover:bg-muted/60 focus-visible:ring-2 focus-visible:ring-ring data-[expanded]:bg-muted/70", | |
| 45 | + props.collapsed ? "h-11 justify-center px-0" : "gap-3 p-2", | |
| 46 | + )} | |
| 47 | + aria-label={t("nav.account")} | |
| 48 | + > | |
| 49 | + <span class="flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-primary text-xs font-bold text-primary-foreground"> | |
| 50 | + {initials(name())} | |
| 51 | + </span> | |
| 52 | + <Show when={!props.collapsed}> | |
| 53 | + <span class="min-w-0 flex-1"> | |
| 54 | + <span class="block truncate text-sm font-semibold">{name()}</span> | |
| 55 | + <span class="block truncate text-xs text-muted-foreground">{t(`role.${u().role}` as MessageKey)}</span> | |
| 56 | + </span> | |
| 57 | + <IconChevronRight class="h-4 w-4 text-muted-foreground" /> | |
| 58 | + </Show> | |
| 59 | + </DropdownMenuTrigger> | |
| 60 | + | |
| 61 | + <DropdownMenuContent class="w-52 rounded-xl border-border/80 bg-popover p-1.5 shadow-soft"> | |
| 62 | + <DropdownMenuItem class="rounded-lg" onSelect={() => void navigate({ to: "/profile" })}> | |
| 63 | + <span>{t("profile.edit")}</span> | |
| 64 | + </DropdownMenuItem> | |
| 65 | + <DropdownMenuItem class="rounded-lg" onSelect={() => prefs.toggleTheme()}> | |
| 66 | + <Show when={prefs.theme() === "dark"} fallback={<IconSun class="h-4 w-4 shrink-0" />}> | |
| 67 | + <IconMoon class="h-4 w-4 shrink-0" /> | |
| 68 | + </Show> | |
| 69 | + <span class="min-w-0 flex-1">{t("theme.toggle")}</span> | |
| 70 | + <span class="text-xs text-muted-foreground">{prefs.theme() === "dark" ? t("theme.dark") : t("theme.light")}</span> | |
| 71 | + </DropdownMenuItem> | |
| 72 | + <DropdownMenuItem class="rounded-lg" onSelect={() => prefs.setLocale(prefs.locale() === "tr" ? "en" : "tr")}> | |
| 73 | + <IconGlobe class="h-4 w-4 shrink-0" /> | |
| 74 | + <span class="min-w-0 flex-1">{t("lang.label")}</span> | |
| 75 | + <span class="text-xs text-muted-foreground">{prefs.locale() === "tr" ? "TR" : "EN"}</span> | |
| 76 | + </DropdownMenuItem> | |
| 77 | + <DropdownMenuSeparator /> | |
| 78 | + <DropdownMenuItem destructive class="rounded-lg" onSelect={() => void props.onLogout()}> | |
| 79 | + <IconLogout class="h-4 w-4 shrink-0" /> | |
| 80 | + <span>{t("nav.logout")}</span> | |
| 81 | + </DropdownMenuItem> | |
| 82 | + </DropdownMenuContent> | |
| 83 | + </DropdownMenu> | |
| 84 | + </div> | |
| 85 | + ); | |
| 86 | + }} | |
| 87 | + </Show> | |
| 88 | + ); | |
| 89 | +} |
src/index.cssmodified+33 -28
| @@ -38,34 +38,34 @@ | ||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | [data-kb-theme="dark"] { |
| 41 | - --background: 168 28% 7%; | |
| 42 | - --foreground: 150 20% 96%; | |
| 43 | - --card: 168 24% 10%; | |
| 44 | - --card-foreground: 150 20% 96%; | |
| 45 | - --popover: 168 24% 10%; | |
| 46 | - --popover-foreground: 150 20% 96%; | |
| 47 | - --primary: 158 65% 48%; | |
| 48 | - --primary-foreground: 168 40% 8%; | |
| 49 | - --secondary: 168 18% 16%; | |
| 50 | - --secondary-foreground: 150 15% 92%; | |
| 51 | - --muted: 168 16% 14%; | |
| 52 | - --muted-foreground: 160 10% 62%; | |
| 53 | - --accent: 168 22% 16%; | |
| 54 | - --accent-foreground: 158 60% 70%; | |
| 55 | - --destructive: 0 62% 45%; | |
| 41 | + --background: 220 9% 6%; | |
| 42 | + --foreground: 220 12% 92%; | |
| 43 | + --card: 220 8% 9%; | |
| 44 | + --card-foreground: 220 12% 92%; | |
| 45 | + --popover: 220 8% 11%; | |
| 46 | + --popover-foreground: 220 12% 92%; | |
| 47 | + --primary: 220 88% 62%; | |
| 48 | + --primary-foreground: 220 20% 98%; | |
| 49 | + --secondary: 220 7% 15%; | |
| 50 | + --secondary-foreground: 220 10% 88%; | |
| 51 | + --muted: 220 7% 13%; | |
| 52 | + --muted-foreground: 220 7% 62%; | |
| 53 | + --accent: 220 9% 17%; | |
| 54 | + --accent-foreground: 220 15% 96%; | |
| 55 | + --destructive: 0 70% 58%; | |
| 56 | 56 | --destructive-foreground: 0 0% 98%; |
| 57 | - --border: 168 14% 18%; | |
| 58 | - --input: 168 14% 18%; | |
| 59 | - --ring: 158 65% 48%; | |
| 60 | - --success: 152 55% 45%; | |
| 61 | - --warning: 38 90% 55%; | |
| 57 | + --border: 220 8% 18%; | |
| 58 | + --input: 220 8% 18%; | |
| 59 | + --ring: 220 88% 62%; | |
| 60 | + --success: 128 48% 55%; | |
| 61 | + --warning: 38 90% 56%; | |
| 62 | 62 | --info: 210 80% 60%; |
| 63 | - --surface-elevated: 168 22% 12%; | |
| 64 | - --sidebar: 168 30% 8%; | |
| 65 | - --sidebar-foreground: 150 15% 90%; | |
| 66 | - --hero-from: 168 30% 12%; | |
| 67 | - --hero-to: 190 25% 12%; | |
| 68 | - --glow: 158 65% 40%; | |
| 63 | + --surface-elevated: 220 8% 12%; | |
| 64 | + --sidebar: 220 10% 4%; | |
| 65 | + --sidebar-foreground: 220 10% 86%; | |
| 66 | + --hero-from: 220 10% 13%; | |
| 67 | + --hero-to: 220 8% 10%; | |
| 68 | + --glow: 220 88% 54%; | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | * { |
| @@ -79,8 +79,8 @@ | ||
| 79 | 79 | body { |
| 80 | 80 | @apply min-h-screen bg-background font-sans text-foreground antialiased; |
| 81 | 81 | background-image: |
| 82 | - radial-gradient(ellipse 80% 50% at 10% -10%, hsl(var(--glow) / 0.12), transparent), | |
| 83 | - radial-gradient(ellipse 60% 40% at 100% 0%, hsl(var(--info) / 0.06), transparent); | |
| 82 | + radial-gradient(ellipse 80% 50% at 10% -10%, hsl(var(--glow) / 0.10), transparent), | |
| 83 | + radial-gradient(ellipse 60% 40% at 100% 0%, hsl(var(--info) / 0.05), transparent); | |
| 84 | 84 | background-attachment: fixed; |
| 85 | 85 | } |
| 86 | 86 | |
| @@ -98,6 +98,11 @@ | ||
| 98 | 98 | @apply rounded-lg border bg-card text-card-foreground shadow-sm; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | + [data-kb-theme="dark"] .surface-card { | |
| 102 | + @apply shadow-none; | |
| 103 | + background: linear-gradient(180deg, hsl(var(--card) / 0.98), hsl(var(--card) / 0.92)); | |
| 104 | + } | |
| 105 | + | |
| 101 | 106 | .hero-panel { |
| 102 | 107 | background: linear-gradient(135deg, hsl(var(--hero-from)), hsl(var(--hero-to))); |
| 103 | 108 | } |