Entity Card.
A selectable list card for turtles, sites or scripts: status dot, title, right-side tag, a meta line and an optional fuel bar. The selected card gets an orange border and block shadow.
"use client";
import * as React from "react";
import {
EntityCard,
EntityCardBar,
EntityCardDescription,
EntityCardHeader,
EntityCardList,
EntityCardMeta,
EntityCardTag,
EntityCardTitle,
} from "@/components/ui/entity-card";
import { StatusDot } from "@/components/ui/status-dot";
const turtles = [
{ name: "Testy", status: "online", tone: "online", job: "Strip mine 41/64", pos: "120 12 -352", fuel: 72 },
{ name: "Digger", status: "online", tone: "online", job: "Idle at home", pos: "118 64 -340", fuel: 91 },
{ name: "Builder-2", status: "busy", tone: "busy", job: "Build layer 3/10", pos: "140 70 -310", fuel: 44 },
{ name: "Farmhand", status: "offline", tone: "offline", job: "Last seen 2h ago", pos: "96 65 -300", fuel: 12 },
] as const;
export default function EntityCardDemo() {
const [selected, setSelected] = React.useState("Testy");
return (
<EntityCardList className="w-full max-w-[268px]" aria-label="Fleet">
{turtles.map((t) => (
<EntityCard key={t.name} selected={selected === t.name} onClick={() => setSelected(t.name)}>
<EntityCardHeader>
<StatusDot tone={t.tone} pulse={t.tone !== "offline"} />
<EntityCardTitle>{t.name}</EntityCardTitle>
<EntityCardTag>{t.status}</EntityCardTag>
</EntityCardHeader>
<EntityCardDescription>{t.job}</EntityCardDescription>
<EntityCardMeta>
<span>{t.pos}</span>
<span>Fuel {t.fuel}%</span>
</EntityCardMeta>
<EntityCardBar value={t.fuel} />
</EntityCard>
))}
</EntityCardList>
);
}Installation#
With the CLI
$npx lanterncn add entity-cardThis 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/entity-card. 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/entity-card.tsx"use client"; import * as React from "react"; import { Slot } from "radix-ui"; import { cn } from "@/lib/utils"; import { Progress } from "@/components/ui/progress"; /** A vertical stack of EntityCards. */ function EntityCardList({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="entity-card-list" className={cn("flex flex-col gap-2.5", className)} {...props} />; } /** * A selectable list card for turtles, sites or scripts. Renders a button (with aria-pressed * when `selected` is set), or pass asChild to render a link (aria-current when selected). */ function EntityCard({ className, selected, asChild = false, type, ...props }: React.ComponentProps<"button"> & { selected?: boolean; asChild?: boolean }) { const Comp = asChild ? Slot.Root : "button"; return ( <Comp data-slot="entity-card" data-selected={selected || undefined} type={asChild ? type : (type ?? "button")} aria-pressed={asChild ? undefined : selected} aria-current={asChild && selected ? "true" : undefined} className={cn( "flex w-full min-w-0 cursor-pointer flex-col gap-2 rounded-md border bg-card p-3 text-left text-foreground transition-[background-color,border-color,box-shadow] outline-none", "hover:border-input hover:bg-secondary/60 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background", "data-[selected]:border-primary data-[selected]:bg-secondary data-[selected]:shadow-[4px_4px_0_#3a2a1c]", "disabled:pointer-events-none disabled:opacity-50", className, )} {...props} /> ); } /** Top row: put a StatusDot, an EntityCardTitle and an EntityCardTag in it. */ function EntityCardHeader({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="entity-card-header" className={cn("flex min-w-0 items-center gap-2", className)} {...props} />; } function EntityCardTitle({ className, ...props }: React.ComponentProps<"span">) { return ( <span data-slot="entity-card-title" className={cn("min-w-0 truncate font-display text-[15px] leading-tight font-semibold tracking-tight", className)} {...props} /> ); } /** Mono uppercase text pushed to the right of the header. */ function EntityCardTag({ className, ...props }: React.ComponentProps<"span">) { return ( <span data-slot="entity-card-tag" className={cn( "ml-auto shrink-0 font-mono text-[10px] tracking-[0.12em] whitespace-nowrap text-muted-foreground uppercase", className, )} {...props} /> ); } function EntityCardDescription({ className, ...props }: React.ComponentProps<"span">) { return ( <span data-slot="entity-card-description" className={cn("truncate text-xs text-muted-foreground", className)} {...props} /> ); } /** Mono meta line. The last child is pushed to the right. */ function EntityCardMeta({ className, ...props }: React.ComponentProps<"span">) { return ( <span data-slot="entity-card-meta" className={cn( "flex min-w-0 items-center gap-2 font-mono text-[10px] tracking-[0.06em] text-muted-foreground uppercase tabular-nums *:truncate [&>*:last-child:not(:first-child)]:ml-auto [&>*:last-child:not(:first-child)]:shrink-0", className, )} {...props} /> ); } /** A thin green bar for fuel or storage. Turns red at or below `lowAt`. */ function EntityCardBar({ value, lowAt = 20, className, indicatorClassName, ...props }: React.ComponentProps<typeof Progress> & { value: number; lowAt?: number }) { return ( <Progress data-slot="entity-card-bar" value={value} size="sm" className={cn("h-[3px]", className)} indicatorClassName={cn(value <= lowAt ? "bg-destructive" : "bg-success", indicatorClassName)} {...props} /> ); } export { EntityCardList, EntityCard, EntityCardHeader, EntityCardTitle, EntityCardTag, EntityCardDescription, EntityCardMeta, EntityCardBar, };Update the import paths to match your project
The source imports
cnfrom@/lib/utilsand uses progress, status-dot.
Usage#
import {
EntityCardList,
EntityCard,
EntityCardHeader,
EntityCardTitle,
EntityCardTag,
EntityCardDescription,
EntityCardMeta,
EntityCardBar,
} from "@/components/ui/entity-card";<EntityCard selected onClick={() => select("testy")}>
<EntityCardHeader>
<StatusDot tone="online" />
<EntityCardTitle>Testy</EntityCardTitle>
<EntityCardTag>Online</EntityCardTag>
</EntityCardHeader>
<EntityCardDescription>Strip mine 41/64</EntityCardDescription>
<EntityCardMeta>
<span>120 12 -352</span>
<span>Fuel 72%</span>
</EntityCardMeta>
<EntityCardBar value={72} />
</EntityCard>The card is a button with aria-pressed when selected is set. With asChild it renders your link and marks the selected one with aria-current. Do not put other buttons inside it.
EntityCardMeta pushes its last child to the right. EntityCardBar is green and turns red at or below lowAt (20).
Examples#
As links
import { FileCodeIcon } from "lucide-react";
import {
EntityCard,
EntityCardDescription,
EntityCardHeader,
EntityCardList,
EntityCardTag,
EntityCardTitle,
} from "@/components/ui/entity-card";
const scripts = [
{ file: "strip_mine.lua", when: "AI, just now", tag: "New" },
{ file: "quarry_9x9.lua", when: "2 days ago" },
{ file: "farm_wheat.lua", when: "Last week" },
{ file: "sort_chests.lua", when: "Sep 12" },
];
export default function EntityCardLinks() {
return (
<nav aria-label="Programs" className="w-full max-w-[240px]">
<EntityCardList className="gap-1.5">
{scripts.map((s, i) => (
<EntityCard key={s.file} asChild selected={i === 0} className="gap-1 px-2.5 py-2">
<a href="#">
<EntityCardHeader>
<FileCodeIcon aria-hidden="true" className="size-3.5 shrink-0 text-muted-foreground" />
<EntityCardTitle className="font-mono text-xs font-normal tracking-normal">{s.file}</EntityCardTitle>
{s.tag && <EntityCardTag className="text-primary">{s.tag}</EntityCardTag>}
</EntityCardHeader>
<EntityCardDescription className="pl-5.5">{s.when}</EntityCardDescription>
</a>
</EntityCard>
))}
</EntityCardList>
</nav>
);
}