Code intelligence bento
A code excerpt with its matching line marked, beside two color image placeholders for the reference trace and match index.
pnpm dlx shadcn@latest add @haze/bento-code-intelligence---
import { FileCode, Search } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import BentoTile from "../ui/bento-tile.astro";
import Collapsible from "../ui/collapsible.astro";
import SectionHeading from "../ui/section-heading.astro";
interface Props {
id?: string;
title?: string;
description?: string;
headingLevel?: 1 | 2 | 3;
file?: string;
firstLine?: number;
lines?: { code: string; match?: boolean }[];
explanation?: string;
class?: string;
}
const {
id = "bento-code-intelligence", title = "Follow a change across the codebase", headingLevel = 2,
description = "Find the line a change touches, then see every file that depends on it.",
file = "src/billing/renewal.ts", firstLine = 18,
lines = [
{ code: "export function nextRenewal(plan: Plan) {" },
{ code: " const cycle = getBillingCycle(plan);", match: true },
{ code: " return cycle.nextDate;" },
{ code: "}" },
],
explanation = "The trace resolves getBillingCycle to the exported function in billing/cycle.ts. Calls through an aliased import resolve to the same definition.",
class: className,
} = Astro.props;
const tileHeading = ({ 1: 2, 2: 3, 3: 4 } as const)[headingLevel];
---
<section aria-labelledby={`${id}-title`} class={cn("bg-background px-5 py-14 sm:px-8 sm:py-20", className)}>
<div class="mx-auto grid max-w-6xl gap-7 sm:gap-10">
<SectionHeading id={`${id}-title`} title={title} description={description} headingLevel={headingLevel} />
<div data-bento-grid class="grid min-w-0 gap-3 md:grid-cols-[minmax(0,1.5fr)_minmax(0,1fr)] md:gap-4">
<BentoTile title="Matched source" headingLevel={tileHeading} class="md:row-span-2"
visualClass="flex-1" bodyClass="flex-1 content-start">
<div slot="visual" aria-hidden="true" class="min-h-44 sm:min-h-56"></div>
<figure class="min-w-0 overflow-hidden rounded-lg border border-border bg-muted/40">
<figcaption class="flex min-w-0 items-center gap-2.5 border-b border-border px-3 py-2.5 font-mono text-xs/5 wrap-anywhere text-muted-foreground sm:px-4">
<FileCode aria-hidden="true" class="size-4 shrink-0 text-muted-foreground" />{file}
</figcaption>
{lines.length ? (
<ol role="list" start={firstLine} class="grid py-1.5 font-mono text-xs/5 sm:text-sm/6">
{lines.map(({ code, match }, index) => (
<li id={`${id}-line-${index + 1}`} tabindex={match ? -1 : undefined}
class={cn("grid min-w-0 scroll-mt-6 grid-cols-[auto_minmax(0,1fr)_auto] gap-2 px-3 py-1.5 target:bg-accent focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring motion-safe:transition-colors motion-safe:duration-150 motion-safe:ease-snappy sm:px-4", match && "bg-muted")}>
<span aria-hidden="true" class="tabular-nums text-muted-foreground">{firstLine + index}</span>
<span class="min-w-0"><span class="sr-only">Line {firstLine + index}{match ? ", match" : ""}. </span><code class="whitespace-pre-wrap wrap-anywhere">{code}</code></span>
{match && <Search class="mt-1 size-3.5 text-muted-foreground" aria-hidden="true" />}
</li>
))}
</ol>
) : <p class="px-4 py-3 text-sm/5 text-muted-foreground">No source lines.</p>}
</figure>
{explanation && <Collapsible title="How the match was resolved" class="rounded-lg bg-muted/40"><p class="wrap-anywhere">{explanation}</p></Collapsible>}
</BentoTile>
<BentoTile title="Reference trace" headingLevel={tileHeading} visualClass="flex-1 bg-foreground/6">
<div slot="visual" aria-hidden="true" class="min-h-44 sm:min-h-56"></div>
</BentoTile>
<BentoTile title="Match index" headingLevel={tileHeading} visualClass="flex-1 bg-foreground/6">
<div slot="visual" aria-hidden="true" class="min-h-44 sm:min-h-56"></div>
</BentoTile>
</div>
</div>
</section>When to use
- A developer feature shows a real code excerpt next to room for product imagery.
- Readers should see which line of a short excerpt a feature acts on.
When not to use
- Users need to search or edit a repository within the preview.
Installation
Add the Haze registry to components.json once, then install Code intelligence bento with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/bento-code-intelligencenpx shadcn@latest add @haze/bento-code-intelligenceyarn dlx shadcn@latest add @haze/bento-code-intelligencebunx --bun shadcn@latest add @haze/bento-code-intelligenceFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | bento-code-intelligence | Unique prefix for the heading and line anchors. |
| title | string | – | Title of the code story. |
| description | string | – | Lead text about the trace. |
| headingLevel | 1 | 2 | 3 | 2 | Heading level for the section. |
| file | string | – | Visible path to the file in the excerpt. |
| firstLine | number | 18 | Starting line number of the excerpt. |
| lines | { code: string; match?: boolean }[] | – | Source lines and the ones to highlight as matches. |
| explanation | string | – | Optional explanation of how the match was resolved. |
| class | string | – | Classes on the section. |
Keyboard interactions
- EnterSpace
- Expand or collapse the explanation of the match.
Accessibility
- Image placeholders are flat, decorative fields that screen readers skip.
- Matching lines are announced as matches in text, and code wraps on narrow screens.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI block "Code intelligence bento" with `npx shadcn@latest add @haze/bento-code-intelligence`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import BentoCodeIntelligence from "@/components/haze/blocks/bento-code-intelligence.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/blocks/bento-code-intelligence.md
Customize with real content
Adapt the Haze bento-code-intelligence block for our product. Replace the demo values of these props with our real content: id, title, description, headingLevel, file, firstLine, lines, explanation, class. Keep the layout, the heading level rules and these accessibility details: Image placeholders are flat, decorative fields that screen readers skip. Matching lines are announced as matches in text, and code wraps on narrow screens. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using bento-code-intelligence, check it fits: use it when a developer feature shows a real code excerpt next to room for product imagery.; readers should see which line of a short excerpt a feature acts on.. Avoid it when users need to search or edit a repository within the preview.. Alternatives: @haze/bento-developer-tools, @haze/code-block, @haze/file-tree.
Dependencies
- npm: @lucide/astro
- @haze/bento-tile
- @haze/collapsible
- @haze/section-heading
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.