Bottom Tab Bar.
The phone version of App Rail: equal-width icon tabs along the bottom of the screen with an orange top bar on the active tab.
"use client";
import * as React from "react";
import { CodeIcon, EllipsisIcon, ListChecksIcon, MapIcon, SparklesIcon } from "lucide-react";
import { BottomTabBar, BottomTabBarItem } from "@/components/ui/bottom-tab-bar";
const tabs = [
{ label: "Map", icon: MapIcon },
{ label: "Programs", icon: CodeIcon },
{ label: "Jobs", icon: ListChecksIcon },
{ label: "AI", icon: SparklesIcon },
{ label: "More", icon: EllipsisIcon },
];
export default function BottomTabBarDemo() {
const [active, setActive] = React.useState("Map");
return (
<div className="flex h-[440px] w-full max-w-[375px] flex-col overflow-hidden rounded-lg border bg-background">
<div className="flex flex-1 flex-col gap-2 bg-grid p-5">
<span className="font-mono text-[10px] tracking-[0.2em] text-success uppercase">Testy</span>
<span className="font-display text-2xl font-medium tracking-tight">
{active}
<span className="text-primary">.</span>
</span>
</div>
<BottomTabBar aria-label="Sections">
{tabs.map((tab) => (
<BottomTabBarItem key={tab.label} isActive={active === tab.label} onClick={() => setActive(tab.label)}>
<tab.icon />
<span>{tab.label}</span>
</BottomTabBarItem>
))}
</BottomTabBar>
</div>
);
}Installation#
With the CLI
$npx lanterncn add bottom-tab-barThis also installs the Lantern theme and any Lantern UI components it depends on. The shadcn CLI works directly too: npx shadcn@latest add httptim/lantern-ui/bottom-tab-bar. See Installation if your project is not set up yet.
Manually
Install the dependencies
npm install radix-uiCopy the source into your project
components/ui/bottom-tab-bar.tsximport * as React from "react"; import { Slot } from "radix-ui"; import { cn } from "@/lib/utils"; /** * The phone version of AppRail: equal-width icon tabs along the bottom of the screen, * with room for the home indicator. Position it yourself, e.g. `fixed inset-x-0 bottom-0 md:hidden`. */ function BottomTabBar({ className, children, ...props }: React.ComponentProps<"nav">) { return ( <nav data-slot="bottom-tab-bar" className={cn("border-t bg-card pb-[max(env(safe-area-inset-bottom),0.5rem)]", className)} {...props} > <ul className="flex">{children}</ul> </nav> ); } /** One tab. Renders a button, or pass asChild for a link. Put an icon and a short label inside. */ function BottomTabBarItem({ className, isActive = false, asChild = false, type, ...props }: React.ComponentProps<"button"> & { isActive?: boolean; asChild?: boolean }) { const Comp = asChild ? Slot.Root : "button"; return ( <li className="flex min-w-0 flex-1"> <Comp data-slot="bottom-tab-bar-item" type={asChild ? type : (type ?? "button")} data-active={isActive || undefined} aria-current={isActive ? "page" : undefined} className={cn( "relative flex min-h-12 w-full min-w-0 cursor-pointer flex-col items-center justify-center gap-1 px-1 pt-2.5 pb-1 text-muted-foreground transition-colors outline-none", "before:absolute before:inset-x-3 before:top-0 before:h-0.5 before:bg-transparent data-[active]:text-primary data-[active]:before:bg-primary", "hover:text-foreground focus-visible:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-inset", "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-5", "[&>span]:max-w-full [&>span]:truncate [&>span]:font-mono [&>span]:text-[9px] [&>span]:leading-none [&>span]:tracking-[0.08em] [&>span]:uppercase", className, )} {...props} /> </li> ); } export { BottomTabBar, BottomTabBarItem };Update the import paths to match your project
The source imports
cnfrom@/lib/utils.
Usage#
import { BottomTabBar, BottomTabBarItem } from "@/components/ui/bottom-tab-bar";<BottomTabBar aria-label="Sections" className="fixed inset-x-0 bottom-0 md:hidden">
<BottomTabBarItem isActive>
<MapIcon />
<span>Map</span>
</BottomTabBarItem>
</BottomTabBar>Tabs are at least 48px tall and pad the bottom for the home indicator with env(safe-area-inset-bottom); add viewport-fit=cover to your viewport meta for that to apply. Keep it to five tabs and put the rest behind a More tab.
The bar does not position itself. Fix it to the bottom, or make it the last row of a full-height flex column as the App Shell block does, and leave room for it under the page content.