Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat(ui): one hover card slides between module sidebar links

Sidwebworks0a2248d59c40
diff --git a/apps/erp/app/components/Layout/Navigation/CollapsibleSidebar.tsx b/apps/erp/app/components/Layout/Navigation/CollapsibleSidebar.tsx
index 2edec1e019..72f6ba6df3 100644
--- a/apps/erp/app/components/Layout/Navigation/CollapsibleSidebar.tsx
+++ b/apps/erp/app/components/Layout/Navigation/CollapsibleSidebar.tsx
@@ -126,6 +126,67 @@ export function useSidebarLocation(isInside: (pathname: string) => boolean) {
return pending && isInside(pending.pathname) ? pending : current;
}
+/**
+ * The scrolling list of links inside the module sidebar, with the same hover
+ * card the icon rail has: one card for the whole list, moved with a transform
+ * to the link under the pointer, so the highlight travels between links
+ * instead of each one fading its own. The active link keeps its own
+ * background. A link opts in with `data-nav-item`.
+ */
+export function SidebarLinks({ children }: PropsWithChildren) {
+ const listRef = useRef<HTMLDivElement>(null);
+ const hoverCardRef = useRef<HTMLSpanElement>(null);
+
+ // Written straight to the element: a hover must not re-render the list.
+ const moveHoverCard = (item: HTMLElement | null) => {
+ const card = hoverCardRef.current;
+ const list = listRef.current;
+ if (!card || !list) return;
+ if (!item) {
+ card.style.opacity = "0";
+ return;
+ }
+ const itemRect = item.getBoundingClientRect();
+ const listRect = list.getBoundingClientRect();
+ const left = itemRect.left - listRect.left + list.scrollLeft;
+ const top = itemRect.top - listRect.top + list.scrollTop;
+ // Entering the list: appear on the link rather than slide in from
+ // wherever the card was last.
+ card.style.transitionProperty = card.style.opacity === "1" ? "" : "opacity";
+ card.style.transform = `translate(${left}px, ${top}px)`;
+ card.style.width = `${itemRect.width}px`;
+ card.style.height = `${itemRect.height}px`;
+ card.style.opacity = "1";
+ };
+
+ return (
+ <div
+ ref={listRef}
+ className="relative overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent h-full w-full pb-8"
+ // The gaps between links are not links: the card stays where it is
+ // while the pointer crosses one, and only leaves with the pointer.
+ onPointerOver={(event) => {
+ if (event.pointerType !== "mouse") return;
+ const item = (event.target as HTMLElement).closest<HTMLElement>(
+ "[data-nav-item]"
+ );
+ if (item) moveHoverCard(item);
+ }}
+ // A press navigates, expands a link's views or starts a reorder: the
+ // row under the card is about to change or move.
+ onPointerDown={() => moveHoverCard(null)}
+ onPointerLeave={() => moveHoverCard(null)}
+ >
+ <span
+ ref={hoverCardRef}
+ aria-hidden
+ className="pointer-events-none absolute left-0 top-0 rounded-md bg-active/60 opacity-0 transition-[transform,opacity] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none"
+ />
+ {children}
+ </div>
+ );
+}
+
/**
* The one module sidebar, rendered by the app shell around every page. A
* module layout names its sub-navigation on its route handle (`sidebar`) and
diff --git a/apps/erp/app/components/Layout/Navigation/ContentSidebar.tsx b/apps/erp/app/components/Layout/Navigation/ContentSidebar.tsx
index ba6c6e3e51..5246bbadae 100644
--- a/apps/erp/app/components/Layout/Navigation/ContentSidebar.tsx
+++ b/apps/erp/app/components/Layout/Navigation/ContentSidebar.tsx
@@ -2,11 +2,11 @@
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
-import { Button, VStack } from "@carbon/react";
+import { Button, cn, VStack } from "@carbon/react";
import { Link } from "react-router";
import { useUrlParams } from "~/hooks";
import type { Route } from "~/types";
-import { useSidebarLocation } from "./CollapsibleSidebar";
+import { SidebarLinks, useSidebarLocation } from "./CollapsibleSidebar";
const ContentSidebar = ({ links }: { links: Route[] }) => {
const location = useSidebarLocation((pathname) =>
@@ -16,7 +16,7 @@ const ContentSidebar = ({ links }: { links: Route[] }) => {
const filter = params.get("q") ?? undefined;
return (
- <div className="overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent h-full w-full pb-8">
+ <SidebarLinks>
<VStack>
<VStack spacing={1} className="p-2">
{links.map((route) => {
@@ -28,7 +28,12 @@ const ContentSidebar = ({ links }: { links: Route[] }) => {
asChild
leftIcon={route.icon}
variant={isActive ? "active" : "ghost"}
- className="w-full justify-start"
+ data-nav-item=""
+ className={cn(
+ "w-full justify-start",
+ !isActive &&
+ "hover:bg-transparent hover:text-active-foreground"
+ )}
>
<Link
to={route.to + (route.q ? `?q=${route.q}` : "")}
@@ -41,7 +46,7 @@ const ContentSidebar = ({ links }: { links: Route[] }) => {
})}
</VStack>
</VStack>
- </div>
+ </SidebarLinks>
);
};
diff --git a/apps/erp/app/components/Layout/Navigation/GroupedContentSidebar.tsx b/apps/erp/app/components/Layout/Navigation/GroupedContentSidebar.tsx
index e9287410e9..528b1dec62 100644
--- a/apps/erp/app/components/Layout/Navigation/GroupedContentSidebar.tsx
+++ b/apps/erp/app/components/Layout/Navigation/GroupedContentSidebar.tsx
@@ -30,7 +30,7 @@ import { Link, useSubmit } from "react-router";
import { ConfirmDelete } from "~/components/Modals";
import type { RouteGroup } from "~/types";
import { path } from "~/utils/path";
-import { useSidebarLocation } from "./CollapsibleSidebar";
+import { SidebarLinks, useSidebarLocation } from "./CollapsibleSidebar";
type GroupedRoute = RouteGroup["routes"][number];
@@ -91,7 +91,7 @@ const GroupedContentSidebar = ({
return (
<>
- <div className="overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent h-full w-full pb-8">
+ <SidebarLinks>
<VStack>
{groups.map((group) => (
<VStack
@@ -122,7 +122,10 @@ const GroupedContentSidebar = ({
return (
<div className="w-full flex flex-col" key={route.name}>
- <div className="flex items-center gap-x-0.5 relative">
+ <div
+ className="flex items-center gap-x-0.5 relative"
+ data-nav-item=""
+ >
<Button
asChild
leftIcon={route.icon}
@@ -131,7 +134,7 @@ const GroupedContentSidebar = ({
"justify-start flex-grow truncate",
isActive
? "shadow-none dark:shadow-button-base"
- : "hover:bg-active hover:text-active-foreground hover:scale-100 focus-visible:scale-100"
+ : "hover:bg-transparent hover:text-active-foreground hover:scale-100 focus-visible:scale-100"
)}
>
<Link
@@ -176,7 +179,7 @@ const GroupedContentSidebar = ({
</VStack>
))}
</VStack>
- </div>
+ </SidebarLinks>
{selectedView && (
<ConfirmDelete
isOpen={!!selectedView}
@@ -253,7 +256,10 @@ const ViewsReorderGroup = ({
return (
<Reorder.Item key={view.to} value={view} className="w-full">
- <div className="group/view flex items-center relative">
+ <div
+ className="group/view flex items-center relative"
+ data-nav-item=""
+ >
<Button
asChild
variant={isViewActive ? "active" : "ghost"}
@@ -261,7 +267,7 @@ const ViewsReorderGroup = ({
"justify-start text-sm pl-7 pr-7 truncate flex-grow !shadow-none",
isViewActive
? "shadow-none border-active-foreground/30 dark:border-none dark:shadow-button-base"
- : "hover:bg-active hover:text-active-foreground"
+ : "hover:bg-transparent hover:text-active-foreground"
)}
>
<Link to={view.to} prefetch="intent">