AI side panel
Docked page-assistant sidebar alongside a document that surfaces quick prompts, word-level diffs, one-click apply and undo.
pnpm dlx shadcn@latest add @haze/ai-side-panel---
import { Check, RotateCcw, Sparkles, Wand2 } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
id?: string;
docTitle?: string;
class?: string;
}
const {
id = "haze-ai-side-panel",
docTitle = "Q4 launch announcement",
class: className,
} = Astro.props;
---
<section aria-labelledby={`${id}-title`} data-haze-ai-side-panel class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto grid max-w-5xl overflow-hidden rounded-2xl border border-border bg-card lg:grid-cols-[minmax(0,1.25fr)_21rem]">
<article class="p-6 sm:p-8">
<p class="text-[0.6875rem]/4 font-medium tracking-wider text-muted-foreground uppercase">Document · Draft</p>
<h2 id={`${id}-title`} class="mt-2 text-2xl/8 font-semibold tracking-tight text-foreground">{docTitle}</h2>
<p class="mt-4 text-sm/7 text-pretty text-muted-foreground">
This release introduces native Astro islands for every marketing and dashboard section, eliminating redundant client frameworks.
</p>
<p
data-sp-target
class="mt-4 rounded-xl border border-frame bg-muted p-3.5 text-sm/7 text-pretty text-foreground transition-colors duration-200 data-[applied=true]:border-success-border data-[applied=true]:bg-success/10"
>
Teams can now install components directly into their codebase without having to worry about runtime overhead or vendor lock-in issues at all.
</p>
<p class="mt-4 text-sm/7 text-pretty text-muted-foreground">
Every entry ships with token-based dark styles, accessible keyboard patterns, and machine-readable Markdown docs for coding agents.
</p>
</article>
<aside aria-label="AI assistant side panel" class="flex flex-col justify-between border-t border-border bg-muted/40 p-4 lg:border-t-0 lg:border-l">
<div class="space-y-4">
<div class="flex items-center justify-between gap-2 border-b border-border pb-3">
<span class="inline-flex items-center gap-1.5 text-xs font-semibold text-foreground">
<Sparkles class="size-3.5 text-muted-foreground" aria-hidden="true" />
Page assistant
</span>
<span class="rounded-md border border-border bg-card px-2 py-0.5 text-[0.6875rem] text-muted-foreground">1 paragraph selected</span>
</div>
<div class="flex flex-wrap gap-1.5">
{
[
["tighten", "Tighten copy"],
["formal", "More formal"],
["active", "Active voice"],
].map(([key, label]) => (
<button
type="button"
data-sp-preset={key}
class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-lg border border-frame bg-field px-2.5 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:border-frame-strong hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75"
>
<Wand2 class="size-3 text-muted-foreground" aria-hidden="true" />
{label}
</button>
))
}
</div>
<div class="rounded-xl border border-border bg-card p-3.5">
<p class="text-[0.6875rem]/4 font-medium tracking-wider text-muted-foreground uppercase">Proposed diff</p>
<p data-sp-diff class="mt-2 text-xs/6 text-pretty text-foreground">
Teams install components directly into their codebase with <del class="rounded-sm bg-destructive/14 px-1 text-destructive">without having to worry about</del> <ins class="rounded-sm bg-success/14 px-1 text-success no-underline">zero</ins> runtime overhead or vendor lock-in.
</p>
<div class="mt-3 flex items-center gap-2">
<button type="button" data-sp-apply class="inline-flex h-8 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-primary px-3 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
<Check class="size-3.5" aria-hidden="true" />
Apply to page
</button>
<button type="button" data-sp-undo hidden class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-lg border border-frame bg-field px-2.5 text-xs font-medium text-foreground hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
<RotateCcw class="size-3.5" aria-hidden="true" />
Undo
</button>
</div>
</div>
</div>
<p data-sp-status role="status" class="mt-4 min-h-4 text-xs/4 text-muted-foreground"></p>
</aside>
</div>
</section>
<script>
function initSidePanels() {
document.querySelectorAll<HTMLElement>("[data-haze-ai-side-panel]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const target = root.querySelector<HTMLElement>("[data-sp-target]");
const diff = root.querySelector<HTMLElement>("[data-sp-diff]");
const applyBtn = root.querySelector<HTMLButtonElement>("[data-sp-apply]");
const undoBtn = root.querySelector<HTMLButtonElement>("[data-sp-undo]");
const status = root.querySelector<HTMLElement>("[data-sp-status]");
const original = target?.textContent?.trim() ?? "";
const proposals: Record<string, { text: string; preview: string }> = {
tighten: {
text: "Teams install components directly into their codebase with zero runtime overhead or vendor lock-in.",
preview: 'Teams install components directly into their codebase with <del class="rounded-sm bg-destructive/14 px-1 text-destructive">without having to worry about</del> <ins class="rounded-sm bg-success/14 px-1 text-success no-underline">zero</ins> runtime overhead or vendor lock-in.',
},
formal: {
text: "Engineering teams may install source components directly into their repository without runtime overhead or vendor lock-in.",
preview: '<ins class="rounded-sm bg-success/14 px-1 text-success no-underline">Engineering teams may install source components</ins> directly into their repository without runtime overhead or vendor lock-in.',
},
active: {
text: "Install every component directly into your repository and ship with zero runtime overhead or lock-in.",
preview: '<ins class="rounded-sm bg-success/14 px-1 text-success no-underline">Install every component directly into your repository</ins> and ship with zero runtime overhead or lock-in.',
},
};
let current = "tighten";
root.querySelectorAll<HTMLButtonElement>("[data-sp-preset]").forEach((btn) => {
btn.addEventListener("click", () => {
current = btn.dataset.spPreset ?? "tighten";
if (diff) diff.innerHTML = proposals[current].preview;
if (status) status.textContent = `Prepared "${btn.textContent?.trim()}" suggestion.`;
});
});
applyBtn?.addEventListener("click", () => {
if (!target) return;
target.textContent = proposals[current].text;
target.setAttribute("data-applied", "true");
if (undoBtn) undoBtn.hidden = false;
if (status) status.textContent = "Edit applied to document. Use Undo to revert.";
});
undoBtn?.addEventListener("click", () => {
if (!target) return;
target.textContent = original;
target.removeAttribute("data-applied");
undoBtn.hidden = true;
if (status) status.textContent = "Reverted paragraph to original text.";
});
});
}
initSidePanels();
document.addEventListener("astro:page-load", initSidePanels);
</script>When to use
- Pairing a document or canvas with an AI sidebar that proposes targeted edits
- Showing word-level insertions and deletions before applying changes to page text
When not to use
- Editing strictly inline inside a selection popover with ghost text; use ai-inline-edit
Installation
Add the Haze registry to components.json once, then install AI side panel with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/ai-side-panelnpx shadcn@latest add @haze/ai-side-panelyarn dlx shadcn@latest add @haze/ai-side-panelbunx --bun shadcn@latest add @haze/ai-side-panelFirst 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 | "haze-ai-side-panel" | Unique prefix for section heading IDs. |
| docTitle | string | "Q4 launch announcement" | Heading of the document pane. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across quick-action presets, Apply to page and Undo buttons
- EnterSpace
- Preview a rewrite preset, apply the diff to the document or undo it
Accessibility
- Proposed word-level changes use semantic del and ins elements in addition to status colors.
- Applying or undoing an edit updates the document paragraph in place and announces the change via role="status".
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 "AI side panel" with `npx shadcn@latest add @haze/ai-side-panel`. 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 AiSidePanel from "@/components/haze/blocks/ai-side-panel.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/ai-side-panel.md
Customize with real content
Adapt the Haze ai-side-panel block for our product. Replace the demo values of these props with our real content: id, docTitle, class. Keep the layout, the heading level rules and these accessibility details: Proposed word-level changes use semantic del and ins elements in addition to status colors. Applying or undoing an edit updates the document paragraph in place and announces the change via role="status". Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using ai-side-panel, check it fits: use it when pairing a document or canvas with an ai sidebar that proposes targeted edits; showing word-level insertions and deletions before applying changes to page text. Avoid it when editing strictly inline inside a selection popover with ghost text; use ai-inline-edit. Alternatives: @haze/drawer, @haze/ai-chat.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.