Files
archie/ui/astryx-reference/ShellFrame.tsx
T
sam a0d14090ef feat: add astryx design reference prototype
- scaffold a React/Vite reference app under ui/astryx-reference with shell, composer, runs, and area pages
- wire @astryxdesign packages, a neutral-derived theme, and reference dev/build scripts
- document the astryx workflow in ui/AGENTS.md
2026-11-19 17:36:22 +11:00

236 lines
7.1 KiB
TypeScript

import { useEffect, useMemo, useState, type ReactNode } from "react";
import { AppShell } from "@astryxdesign/core/AppShell";
import { Badge } from "@astryxdesign/core/Badge";
import { Button } from "@astryxdesign/core/Button";
import { CommandPalette } from "@astryxdesign/core/CommandPalette";
import { DropdownMenu } from "@astryxdesign/core/DropdownMenu";
import { HStack, Stack } from "@astryxdesign/core/Stack";
import { Icon } from "@astryxdesign/core/Icon";
import { Layout, LayoutContent, LayoutFooter } from "@astryxdesign/core/Layout";
import { useMediaQuery } from "@astryxdesign/core/hooks";
import { SideNav, SideNavItem, SideNavSection } from "@astryxdesign/core/SideNav";
import { Text } from "@astryxdesign/core/Text";
import { TextInput } from "@astryxdesign/core/TextInput";
import { TopNav } from "@astryxdesign/core/TopNav";
import { createStaticSource } from "@astryxdesign/core/Typeahead";
import {
BellAlertIcon,
ChatBubbleLeftRightIcon,
ChartBarSquareIcon,
CheckBadgeIcon,
MagnifyingGlassIcon,
QueueListIcon,
ShieldCheckIcon,
} from "@heroicons/react/24/outline";
import wordmark from "../../assets/brand/archie-wordmark.svg?url";
import darkWordmark from "../../assets/brand/archie-wordmark-dark.svg?url";
export type Area = "Composer" | "Runs" | "Events" | "Governance" | "Reports";
type ShellFrameProps = {
activeArea: Area;
pendingCount: number;
onNavigate: (area: Area) => void;
dock?: ReactNode;
children: ReactNode;
};
const navigation = [
{
title: "Work",
items: [
{ label: "Composer", icon: ChatBubbleLeftRightIcon },
{ label: "Runs", icon: QueueListIcon },
{ label: "Events", icon: BellAlertIcon },
],
},
{
title: "Control",
items: [
{ label: "Governance", icon: ShieldCheckIcon },
{ label: "Reports", icon: ChartBarSquareIcon },
],
},
] satisfies Array<{
title: string;
items: Array<{ label: Area; icon: typeof ChatBubbleLeftRightIcon }>;
}>;
type Command = {
id: "composer" | "runs" | "events" | "governance" | "reports";
label: string;
};
const commands: Command[] = [
{ id: "composer", label: "Composer" },
{ id: "runs", label: "Runs" },
{ id: "events", label: "Events" },
{ id: "governance", label: "Governance" },
{ id: "reports", label: "Reports" },
];
export function ShellFrame({
activeArea,
pendingCount,
onNavigate,
dock,
children,
}: ShellFrameProps) {
const [isPaletteOpen, setIsPaletteOpen] = useState(false);
const [isMobileNavOpen, setIsMobileNavOpen] = useState(false);
const source = useMemo(() => createStaticSource(commands), []);
const hasInlineNavigation = useMediaQuery("(min-width: 768px)");
const prefersDark = useMediaQuery("(prefers-color-scheme: dark)");
useEffect(() => {
function openPalette(event: KeyboardEvent) {
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
event.preventDefault();
setIsPaletteOpen(true);
}
}
window.addEventListener("keydown", openPalette);
return () => window.removeEventListener("keydown", openPalette);
}, []);
useEffect(() => {
setIsMobileNavOpen(false);
}, [activeArea]);
function renderNavigation() {
return (
<SideNav
collapsible
resizable={{ defaultWidth: 224, minWidth: 200, maxWidth: 320 }}
>
{navigation.map((section) => (
<SideNavSection key={section.title} title={section.title}>
{section.items.map((item) => (
<SideNavItem
key={item.label}
label={item.label}
icon={item.icon}
isSelected={activeArea === item.label}
onClick={() => navigate(item.label)}
endContent={
item.label === "Runs" && pendingCount > 0 ? (
<Badge variant="warning" label={pendingCount} />
) : undefined
}
/>
))}
</SideNavSection>
))}
</SideNav>
);
}
function navigate(area: Area) {
setIsMobileNavOpen(false);
onNavigate(area);
window.setTimeout(() => setIsMobileNavOpen(false), 0);
}
function chooseCommand(value: Command) {
setIsPaletteOpen(false);
navigate(
value.id === "composer"
? "Composer"
: value.id === "runs"
? "Runs"
: value.id === "events"
? "Events"
: value.id === "governance"
? "Governance"
: "Reports",
);
}
return (
<>
<AppShell
contentPadding={0}
topNav={
<TopNav
label="Archie workspace"
heading={
<img
src={prefersDark ? darkWordmark : wordmark}
alt="Archie"
width={88}
height={24}
/>
}
startContent={
<DropdownMenu
button={{ label: "CatlowTech", variant: "ghost", size: "sm" }}
items={[
{ label: "CatlowTech", endContent: <Badge variant="neutral" label="Instance" /> },
{ type: "divider" },
{ label: "Instance settings", onClick: () => navigate("Governance") },
]}
/>
}
endContent={
<HStack gap={1} vAlign="center">
{hasInlineNavigation && (
<Stack onClick={() => setIsPaletteOpen(true)}>
<TextInput
label="Jump to"
isLabelHidden
size="sm"
width={240}
startIcon={MagnifyingGlassIcon}
placeholder="Jump to…"
value=""
onChange={() => setIsPaletteOpen(true)}
/>
</Stack>
)}
<Button
label="Approvals"
size="sm"
variant="ghost"
icon={<Icon icon={CheckBadgeIcon} size="sm" />}
endContent={pendingCount > 0 ? <Badge variant="warning" label={pendingCount} /> : undefined}
onClick={() => navigate("Runs")}
/>
</HStack>
}
/>
}
sideNav={renderNavigation()}
mobileNav={{
breakpoint: "md",
isOpen: isMobileNavOpen,
onOpenChange: setIsMobileNavOpen,
}}
>
<Layout
height="fill"
padding={0}
content={<LayoutContent padding={0}>{children}</LayoutContent>}
footer={
dock ? (
<LayoutFooter hasDivider label="Composer">
{dock}
</LayoutFooter>
) : undefined
}
/>
</AppShell>
<CommandPalette
label="Jump to"
isOpen={isPaletteOpen}
onOpenChange={setIsPaletteOpen}
searchSource={source}
onValueChange={(value) => {
const command = commands.find((candidate) => candidate.id === value);
if (command) chooseCommand(command);
}}
/>
</>
);
}