AppShell
The frame of an app: a sidebar on the start side from 1024 px and in a sheet on smaller screens, a sticky header, and the page in <main>. Controls are compact unless density is comfortable. The embedded option drops the <header> and <main> landmarks and the skip link, for a shell inside a page that has its own. Without sidebar (a driver or partner app, a kiosk, a shop tablet screen) there is no sidebar column, no menu button and no sheet, and the header row shows at every width; the page centres its content with Container. The app draws its own logo and passes it in header. fill makes the shell as high as the screen and <main> a flex column with min-h-0: give the page box flex-1 min-h-0 and it takes the rest and scrolls inside its own regions (a till, a board, a calendar; the shell itself does not scroll). density="touch" gives finger-sized controls on a coarse pointer (44 to 48 px) and the compact sizes on a mouse.
import { AppShell } from "@percentsa/ui";Examples
Inbox
Payment received from Nakheel Co.
Invoice 1042 is due tomorrow
Huda commented on the Q3 report
Code
export function AppShellExample() {
const t = useT();
const [collapsed, setCollapsed] = useState(false);
const [search, setSearch] = useState(false);
return (
// clip-path: the blurred sticky header would paint over the rounded corners.
<div className="h-[30rem] w-full overflow-auto rounded-card border border-line [clip-path:inset(0_round_var(--p-radius-card))]">
<AppShell
embedded
mainId="app-shell-example-main"
className="min-h-full"
sidebar={
<Sidebar
sections={useSections()}
collapsed={collapsed}
onCollapsedChange={setCollapsed}
header={<SidebarLogo collapsed={collapsed} />}
footer={<User collapsed={collapsed} />}
/>
}
header={
<>
<Heading level={2} size={6} className="truncate">
{t("Inbox", "الوارد")}
</Heading>
<Button variant="secondary" size="sm" className="ms-auto" onClick={() => setSearch(true)}>
<Search aria-hidden />
{t("Search", "بحث")}
</Button>
</>
}
>
<div className="grid gap-3 p-4 lg:p-6">
{[
t("Payment received from Nakheel Co.", "وصلت دفعة من شركة نخيل"),
t("Invoice 1042 is due tomorrow", "تستحق الفاتورة 1042 غدًا"),
t("Huda commented on the Q3 report", "علّقت هدى على تقرير الربع الثالث"),
].map((line) => (
<div key={line} className="rounded-field border border-line bg-surface px-4 py-3">
<Text size="sm">{line}</Text>
</div>
))}
</div>
</AppShell>
<CommandPalette open={search} onOpenChange={setSearch} commands={useCommands()} />
</div>
);
}
/** Click an item: the current-page mark slides to it. */Today
Toyota Camry 2021
Hyundai Sonata 2019
Code
export function AppShellNoSidebarExample() {
const t = useT();
const lang = useLang();
return (
<div className="h-[28rem] w-full overflow-auto rounded-card border border-line [clip-path:inset(0_round_var(--p-radius-card))]">
<AppShell
embedded
density="comfortable"
mainId="app-shell-driver-main"
className="min-h-full"
header={
<>
{/* The app draws its own logo; AppShell only takes the node. */}
<Logo version={lang === "ar" ? "icon-ar" : "icon-en"} />
<span className="flex-1" />
<DropdownMenu
align="end"
trigger={
<Button variant="ghost" iconOnly aria-label={t("Account", "الحساب")}>
<Users aria-hidden />
</Button>
}
items={[
{ heading: t("Ahmed, driver", "أحمد السائق") },
{ label: t("Switch theme", "المظهر"), icon: <Moon /> },
"separator",
{ label: t("Sign out", "تسجيل الخروج"), icon: <LogOut />, danger: true },
]}
/>
</>
}
>
<Container size="sm" className="grid gap-3 py-4">
<Heading level={2} size={5}>
{t("Today", "اليوم")}
</Heading>
{[
[t("Toyota Camry 2021", "تويوتا كامري 2021"), t("Brake pads, 9:30", "تيل فرامل، 9:30")],
[t("Hyundai Sonata 2019", "هيونداي سوناتا 2019"), t("Oil change, 11:00", "تغيير زيت، 11:00")],
].map(([title, line]) => (
<Card key={title} title={title} description={line} density="compact" />
))}
</Container>
</AppShell>
</div>
);
}
function useSettingsGroups(current: string): SideNavGroup[] {
const t = useT();
const groups: SideNavGroup[] = [
{
label: t("Account", "الحساب"),
items: [
{ href: "#profile", label: t("Profile", "الملف الشخصي"), description: t("Name, photo and language", "الاسم والصورة واللغة"), icon: <UserRound /> },
{ href: "#security", label: t("Sign-in and security", "تسجيل الدخول والأمان"), description: t("Password and active sessions", "كلمة المرور والجلسات النشطة"), icon: <Shield /> },
{ href: "#keys", label: t("Access keys", "مفاتيح الوصول"), description: t("Keys for other apps", "مفاتيح للتطبيقات الأخرى"), icon: <KeyRound />, badge: 2 },
],
},
{
label: t("Workspace", "مساحة العمل"),
items: [
{ href: "#notifications", label: t("Notifications", "الإشعارات"), description: t("What we send you, and how", "ما نرسله إليك وكيف"), icon: <Bell /> },
{ href: "#billing", label: t("Plan and billing", "الباقة والفوترة"), description: t("Invoices and payment method", "الفواتير وطريقة الدفع"), icon: <CreditCard /> },
],
},
];
return groups.map((g) => ({ ...g, items: g.items.map((i) => ({ ...i, current: i.href === current })) }));
}
/** An area with many sections: the column on the start side, the section next to it. The app sets the column width (15rem here). Click an item: it becomes the current page. */Till
Catalog
- Catalog 1
- Catalog 2
- Catalog 3
- Catalog 4
- Catalog 5
- Catalog 6
- Catalog 7
- Catalog 8
- Catalog 9
- Catalog 10
- Catalog 11
- Catalog 12
- Catalog 13
- Catalog 14
- Catalog 15
- Catalog 16
- Catalog 17
- Catalog 18
- Catalog 19
- Catalog 20
- Catalog 21
- Catalog 22
- Catalog 23
- Catalog 24
Cart
- Cart 1
- Cart 2
- Cart 3
- Cart 4
- Cart 5
- Cart 6
- Cart 7
- Cart 8
- Cart 9
- Cart 10
- Cart 11
- Cart 12
- Cart 13
- Cart 14
- Cart 15
- Cart 16
- Cart 17
- Cart 18
- Cart 19
- Cart 20
- Cart 21
- Cart 22
- Cart 23
- Cart 24
Code
export function AppShellFillExample() {
const t = useT();
return (
<div className="h-[24rem] w-full overflow-hidden rounded-card border border-line [clip-path:inset(0_round_var(--p-radius-card))]">
<AppShell
embedded
fill
density="touch"
className="h-full"
header={
<>
<Heading level={2} size={6}>
{t("Till", "الصندوق")}
</Heading>
<span className="flex-1" />
<Button size="sm" variant="secondary">
{t("Hold", "تعليق")}
</Button>
</>
}
>
<div className="grid min-h-0 flex-1 grid-cols-2 gap-3 p-3">
{[t("Catalog", "الكتالوج"), t("Cart", "السلة")].map((title) => (
<section key={title} className="flex min-h-0 flex-col rounded-card border border-line">
<Heading level={3} size={6} className="border-b border-line p-3">
{title}
</Heading>
<ul className="min-h-0 flex-1 overflow-y-auto">
{Array.from({ length: 24 }, (_, i) => (
<li key={i} className="border-b border-line px-3 py-3 text-sm">
{title} {i + 1}
</li>
))}
</ul>
</section>
))}
</div>
</AppShell>
</div>
);
}