refactor(ui): the phone uses the topbar crumbs; the sidebar sheet goes
This commit is contained in:
8 files changed
+20
-206
No files matched your search
@@ -1,25 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import NavMain from "@/components/NavMain.vue";
|
||||
import NavUser from "@/components/NavUser.vue";
|
||||
import TeamSwitcher from "@/components/TeamSwitcher.vue";
|
||||
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, useSidebar } from "@/components/ui/sidebar";
|
||||
|
||||
defineProps<{ hidden: string[] }>();
|
||||
|
||||
// Desktop navigation lives in the topbar; only the phone sheet remains.
|
||||
const { isMobile } = useSidebar();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Sidebar v-if="isMobile" class="h-dvh">
|
||||
<SidebarHeader>
|
||||
<TeamSwitcher />
|
||||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
<NavMain :hidden="hidden" />
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<NavUser />
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
</template>
|
||||
@@ -1,36 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
import { SidebarGroup, SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from "@/components/ui/sidebar";
|
||||
import { activeNavPath, navTree, type NavEntry } from "@/lib/nav";
|
||||
import { navIcons as icons } from "@/lib/nav-icons";
|
||||
|
||||
const props = defineProps<{ hidden: string[] }>();
|
||||
|
||||
const route = useRoute();
|
||||
const { isMobile, setOpenMobile } = useSidebar();
|
||||
const links = computed(() =>
|
||||
navTree(props.hidden).flatMap((node): NavEntry[] => (node.kind === "link" ? [node.entry] : [])),
|
||||
);
|
||||
const activePath = computed(() => activeNavPath(route.path));
|
||||
|
||||
watch(() => route.path, () => { if (isMobile.value) setOpenMobile(false); });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SidebarGroup>
|
||||
<nav aria-label="Sections">
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem v-for="entry in links" :key="entry.path">
|
||||
<SidebarMenuButton as-child :tooltip="entry.label" :is-active="activePath === entry.path" class="max-md:h-11">
|
||||
<RouterLink :to="entry.path" :aria-current="activePath === entry.path ? 'page' : undefined">
|
||||
<component :is="icons[entry.path]" v-if="icons[entry.path]" aria-hidden="true" />
|
||||
<span>{{ entry.label }}</span>
|
||||
</RouterLink>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</nav>
|
||||
</SidebarGroup>
|
||||
</template>
|
||||
@@ -1,54 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { ChevronsUpDown, LogOut, Palette, ScrollText, UserRound } from "@lucide/vue";
|
||||
|
||||
import { useAccountsStore } from "@/accounts/accounts";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from "@/components/ui/sidebar";
|
||||
|
||||
const accounts = useAccountsStore();
|
||||
const { isMobile } = useSidebar();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<SidebarMenuButton
|
||||
size="lg"
|
||||
aria-label="Operator menu"
|
||||
class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
||||
>
|
||||
<Avatar class="size-8 rounded-lg">
|
||||
<AvatarFallback class="rounded-lg">{{ accounts.status?.user?.display_name.slice(0, 1).toUpperCase() }}</AvatarFallback>
|
||||
</Avatar>
|
||||
<span class="flex-1 truncate text-left text-label font-medium">{{ accounts.status?.user?.display_name }}</span>
|
||||
<ChevronsUpDown class="ml-auto size-4" aria-hidden="true" />
|
||||
</SidebarMenuButton>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
class="w-(--reka-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
||||
:side="isMobile ? 'bottom' : 'right'"
|
||||
align="end"
|
||||
:side-offset="4"
|
||||
>
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem as-child><RouterLink to="/account"><UserRound />Your account</RouterLink></DropdownMenuItem>
|
||||
<DropdownMenuItem as-child><RouterLink to="/account/appearance"><Palette />Appearance</RouterLink></DropdownMenuItem>
|
||||
<DropdownMenuItem as-child><RouterLink to="/logs"><ScrollText />Logs</RouterLink></DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem @select="accounts.signOut"><LogOut />Sign out</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</template>
|
||||
@@ -1,76 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { Check, ChevronsUpDown } from "@lucide/vue";
|
||||
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, useSidebar } from "@/components/ui/sidebar";
|
||||
import { useOrgStore } from "@/stores/org";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { describeError } from "@/lib/api";
|
||||
|
||||
const orgStore = useOrgStore();
|
||||
const { homeOrg, memberOrgs, orgs } = storeToRefs(orgStore);
|
||||
const { isMobile } = useSidebar();
|
||||
const failed = ref("");
|
||||
|
||||
onMounted(() => void orgStore.loadOrg().catch((cause) => (failed.value = describeError(cause, errors.common.unknown))));
|
||||
|
||||
const choices = computed(() => orgs.value.filter((o) => memberOrgs.value.includes(o.id)));
|
||||
const active = computed(() => orgs.value.find((o) => o.id === homeOrg.value));
|
||||
const initial = (name: string) => name.slice(0, 1).toUpperCase();
|
||||
|
||||
async function choose(id: string): Promise<void> {
|
||||
if (id === homeOrg.value) return;
|
||||
failed.value = "";
|
||||
try {
|
||||
await orgStore.actInOrg(id);
|
||||
} catch (cause) {
|
||||
failed.value = describeError(cause, errors.common.unknown);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child :disabled="choices.length < 2">
|
||||
<SidebarMenuButton
|
||||
size="lg"
|
||||
:aria-label="`Organisation: ${active?.name ?? 'unavailable'}`"
|
||||
:title="failed || undefined"
|
||||
class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground disabled:opacity-100"
|
||||
>
|
||||
<div class="bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 items-center justify-center rounded-lg font-semibold">
|
||||
{{ active ? initial(active.name) : failed ? "!" : "…" }}
|
||||
</div>
|
||||
<div class="grid flex-1 text-left leading-tight">
|
||||
<span class="truncate text-label font-medium">{{ active?.name ?? (failed ? errors.components.org.unavailable : "Loading…") }}</span>
|
||||
</div>
|
||||
<ChevronsUpDown v-if="choices.length > 1" class="ml-auto" aria-hidden="true" />
|
||||
</SidebarMenuButton>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
class="w-(--reka-dropdown-menu-trigger-width) min-w-56 rounded-lg"
|
||||
align="start"
|
||||
:side="isMobile ? 'bottom' : 'right'"
|
||||
:side-offset="4"
|
||||
>
|
||||
<DropdownMenuLabel class="text-muted-foreground text-caption">Organisations</DropdownMenuLabel>
|
||||
<DropdownMenuItem v-for="o in choices" :key="o.id" class="gap-2 p-2" @select="choose(o.id)">
|
||||
<div class="flex size-6 items-center justify-center rounded-sm border text-caption">{{ initial(o.name) }}</div>
|
||||
{{ o.name }}
|
||||
<Check v-if="o.id === homeOrg" class="ml-auto" aria-label="Current" />
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</template>
|
||||
@@ -41,7 +41,7 @@ const hover = useHoverOpen();
|
||||
<DropdownMenu v-if="choices.length > 1" :open="hover.open.value" :modal="false" @update:open="hover.update">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="ghost" size="sm" class="gap-1 px-2" :aria-label="`Organisation: ${name}`" :title="failed || undefined" @pointerenter="hover.enterTrigger" @pointerleave="hover.leaveTrigger">
|
||||
<span class="max-w-40 truncate">{{ name }}</span>
|
||||
<span class="max-w-40 truncate max-sm:max-w-20">{{ name }}</span>
|
||||
<ChevronDown class="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
@@ -52,5 +52,5 @@ const hover = useHoverOpen();
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<span v-else class="max-w-40 truncate px-2 text-label font-medium" :title="failed || undefined" :aria-label="`Organisation: ${name}`">{{ name }}</span>
|
||||
<span v-else class="max-w-40 truncate px-2 text-label font-medium max-sm:max-w-20" :title="failed || undefined" :aria-label="`Organisation: ${name}`">{{ name }}</span>
|
||||
</template>
|
||||
@@ -6,25 +6,33 @@ import { onUnmounted, ref } from "vue";
|
||||
* is on the trigger, the menu's own close request is ignored, so a click on a
|
||||
* crumb the hover already opened does not snap it shut. Use with
|
||||
* `:modal="false"`: a modal menu blocks the pointer events this relies on.
|
||||
* Touch and pen pointers are ignored: a tap fires enter and leave around its
|
||||
* click, and the leave would shut the menu the click just opened.
|
||||
*/
|
||||
export function useHoverOpen(closeDelay = 150) {
|
||||
const open = ref(false);
|
||||
let overTrigger = false;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
function enter(): void {
|
||||
const mouse = (event?: PointerEvent) => !event || event.pointerType === "mouse";
|
||||
|
||||
function enter(event?: PointerEvent): void {
|
||||
if (!mouse(event)) return;
|
||||
clearTimeout(timer);
|
||||
open.value = true;
|
||||
}
|
||||
function leave(): void {
|
||||
function leave(event?: PointerEvent): void {
|
||||
if (!mouse(event)) return;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => (open.value = false), closeDelay);
|
||||
}
|
||||
function enterTrigger(): void {
|
||||
function enterTrigger(event: PointerEvent): void {
|
||||
if (!mouse(event)) return;
|
||||
overTrigger = true;
|
||||
enter();
|
||||
}
|
||||
function leaveTrigger(): void {
|
||||
function leaveTrigger(event: PointerEvent): void {
|
||||
if (!mouse(event)) return;
|
||||
overTrigger = false;
|
||||
leave();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user