Skip to content
AI Interfaces block

Inline AI Action Menu

The actions offered on a selection, each saying whether it rewrites in place or opens a draft beside it.

151 linesNo dependenciesAdded 9 Sept 2026Updated 10 Sept 2026
  • ai
  • inline
  • actions
  • selection
  • editor

What's included

  • components/ai-action-menu.tsx
  • No runtime dependencies

Works with

  • React
  • Next.js
  • Tailwind CSS
  • TypeScript

npx hoverlab add ai-action-menu

Or over MCP, from your editor's agent — no account needed.

License

Free to read, copy and install, for personal and non-commercial projects. Shipping it in client work or a paid product needs Pro ($79 once). The source lands in your repo and stops being ours — no attribution, nothing to upgrade.

Was this useful?

Start a page with this section — add more, order them, and leave with the page source.

Preview

Do something with the selection

Every row says where the result lands. An AI action that silently replaces the paragraph someone spent ten minutes on is the fastest way to have the feature turned off.

Rendered live in your current theme — this is the same component whose source is below, not a screenshot of it.

Source

components/ai-action-menu.tsx
'use client'

/**
 * <AiActionMenu> — The actions offered on a selection, each saying whether it rewrites in place or opens a draft beside it.
 *
 * The layout problem is not which actions to offer. It is that two of them
 * overwrite the reader's work and two do not, and nothing in a conventional
 * action menu distinguishes them until after the click.
 *
 * The obvious wrong answer is an icon list. An AI action that silently
 * replaces the paragraph someone spent ten minutes on is the fastest route
 * to the feature being switched off permanently, and an icon cannot carry
 * "this replaces your text".
 *
 * So every row states where the result lands, and the badge reduces that to
 * one word: in place, draft, read only. The two destructive rows also
 * promise that one undo restores the original exactly — which is a real
 * implementation constraint this component is documenting, not decoration.
 * If your undo cannot do that, do not offer the in-place actions.
 *
 * The ordering runs from most invasive to least, so the reader meets the
 * consequential ones while they are still reading carefully.
 *
 * Rows are `<button>`s with `aria-pressed` rather than menu items with click
 * handlers on divs: they are operable, so they must be keyboard-reachable
 * and announce their state. In a real editor this panel should also be a
 * `role="menu"` with roving focus if it opens on selection — the scaffold's
 * list semantics are correct for a persistent panel, not for a popup.
 *
 * The demo selects the first row, which is the most common action and also
 * the most invasive, which is the pairing this block exists to make visible.
 */

import * as React from 'react'

type Tone = 'neutral' | 'positive' | 'warning' | 'critical'

export interface AiActionMenuRow {
  id: string
  label: string
  detail?: string
  tone?: Tone
  /** What the badge says. Falls back to the tone name when absent. */
  status?: string
}

export interface AiActionMenuProps {
  heading?: string
  intro?: string
  rows?: AiActionMenuRow[]
  className?: string
}

/*
  Tones as complete utility classes, never assembled from fragments.
  Tailwind scans source text, so `text-${tone}-foreground` produces no
  class at all — the same failure as an undefined token, and just as
  invisible in review.
*/
const TONE_CLASS: Record<Tone, string> = {
  neutral: 'bg-muted text-muted-foreground',
  positive: 'bg-primary/10 text-primary',
  warning: 'bg-accent text-accent-foreground',
  critical: 'bg-destructive/10 text-destructive',
}

const ROWS: AiActionMenuRow[] = [
  { id: "row-1", label: "Rewrite for clarity", detail: "Replaces the selection. One undo puts it back exactly.", tone: "warning", status: "in place" },
  { id: "row-2", label: "Shorten to one sentence", detail: "Replaces the selection. Undo restores the original wording.", tone: "warning", status: "in place" },
  { id: "row-3", label: "Suggest three alternatives", detail: "Opens beside the text. Nothing changes until one is picked.", tone: "positive", status: "draft" },
  { id: "row-4", label: "Explain this passage", detail: "Read-only. Never touches the document.", tone: "positive", status: "read only" },
]

export function AiActionMenu({
  heading = "Do something with the selection",
  intro = "Every row says where the result lands. An AI action that silently replaces the paragraph someone spent ten minutes on is the fastest way to have the feature turned off.",
  rows = ROWS,
  className,
}: AiActionMenuProps) {
  /*
    Per-instance prefix for every id this block emits.

    The literals these replaced were a latent duplicate the moment the
    block appeared twice on one document, and `aria-labelledby` on a
    duplicated id resolves to the first match -- so the second copy was
    labelled by the first copy's heading. Client component, so `useId` is
    the right tool.
  */
  const uid = React.useId()

  const [selected, setSelected] = React.useState<string | null>(rows[0]?.id ?? null)

  return (
    <section
      aria-labelledby={`${uid}-ai-action-menu-heading`}
      className={`w-full bg-background px-6 py-16 ${className ?? ''}`}
    >
      <div className="mx-auto max-w-3xl">
        <h2
          id={`${uid}-ai-action-menu-heading`}
          className="text-2xl font-semibold tracking-tight text-foreground"
        >
          {heading}
        </h2>
        <p className="mt-2 text-sm text-muted-foreground">{intro}</p>

        <ul className="mt-8 divide-y divide-border overflow-hidden rounded-xl border border-border bg-card">
          {rows.map((row) => {
            const isSelected = row.id === selected
            return (
              <li key={row.id}>
                {/*
                  A button, not a div with onClick. The row is operable, so
                  it has to be reachable by keyboard and announce its
                  selected state — aria-pressed is what carries that.
                */}
                <button
                  type="button"
                  aria-pressed={isSelected}
                  onClick={() => setSelected(row.id)}
                  className={`flex w-full items-center justify-between gap-4 px-5 py-4 text-start transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset ${
                    isSelected ? 'bg-muted/40' : ''
                  }`}
                >
                  <span className="min-w-0">
                    <span className="block truncate text-sm font-medium text-foreground">
                      {row.label}
                    </span>
                    {row.detail ? (
                      <span className="mt-0.5 block text-sm text-muted-foreground">
                        {row.detail}
                      </span>
                    ) : null}
                  </span>
                  <span
                    className={`shrink-0 rounded-full px-2.5 py-1 text-xs font-medium ${
                      TONE_CLASS[row.tone ?? 'neutral']
                    }`}
                  >
                    {row.status ?? row.tone ?? 'neutral'}
                  </span>
                </button>
              </li>
            )
          })}
        </ul>
      </div>
    </section>
  )
}

Before you paste

  • Styling is Tailwind utility classes on semantic tokens (bg-card, text-muted-foreground) — it inherits your theme instead of overriding it.
  • Nothing to install. No component library, no icon package.
  • Every prop has a default, so it renders standalone before you wire it up.

Where it goes

Drop it at components/ai-action-menu.tsx and import it where you need the section:

import { AiActionMenu } from '@/components/ai-action-menu'

Customize

1 of this block’s props are simple enough to drive from here. Change them and the block below re-renders — it is the same component whose source is above, not a mock of it. Everything else it accepts is in the table underneath.

Props

Read out of the component’s own type and signature, so this cannot drift from the source below. Every prop has a default — the component renders standalone before you pass it anything.

PropTypeDefault
headingstring"Do something with the selection"
introstring—
rowsAiActionMenuRow[]ROWS
classNamestring—

Not using React?

The same block rendered once to markup, wrapped as a file your framework compiles. Tailwind classes are framework-agnostic, so the design transfers intact — the behaviour does not.

This block is interactive. The markup below is its initial state with the event handlers stripped — you will need to re-wire the behaviour in your framework.

ai-action-menu.html
<!--
  Inline AI Action Menu — markup from the Hoverlab catalog.

  This is the block rendered once to HTML and wrapped as a component
  file. It is not a port of the React source: the Tailwind classes carry
  the design, which is the part that took the work, and they are the same
  in every framework.

  This block is interactive in React and the handlers are NOT here.
  Buttons, toggles and menus render in their initial state and do
  nothing until you wire them up.
-->
<section aria-labelledby="_R_0_-ai-action-menu-heading" class="w-full bg-background px-6 py-16 ">
  <div class="mx-auto max-w-3xl">
    <h2 id="_R_0_-ai-action-menu-heading" class="text-2xl font-semibold tracking-tight text-foreground">Do something with the selection</h2>
    <p class="mt-2 text-sm text-muted-foreground">Every row says where the result lands. An AI action that silently replaces the paragraph someone spent ten minutes on is the fastest way to have the feature turned off.</p>
    <ul class="mt-8 divide-y divide-border overflow-hidden rounded-xl border border-border bg-card">
      <li>
        <button type="button" aria-pressed="true" class="flex w-full items-center justify-between gap-4 px-5 py-4 text-start transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset bg-muted/40">
          <span class="min-w-0">
            <span class="block truncate text-sm font-medium text-foreground">Rewrite for clarity</span>
            <span class="mt-0.5 block text-sm text-muted-foreground">Replaces the selection. One undo puts it back exactly.</span>
          </span>
          <span class="shrink-0 rounded-full px-2.5 py-1 text-xs font-medium bg-accent text-accent-foreground">in place</span>
        </button>
      </li>
      <li>
        <button type="button" aria-pressed="false" class="flex w-full items-center justify-between gap-4 px-5 py-4 text-start transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset ">
          <span class="min-w-0">
            <span class="block truncate text-sm font-medium text-foreground">Shorten to one sentence</span>
            <span class="mt-0.5 block text-sm text-muted-foreground">Replaces the selection. Undo restores the original wording.</span>
          </span>
          <span class="shrink-0 rounded-full px-2.5 py-1 text-xs font-medium bg-accent text-accent-foreground">in place</span>
        </button>
      </li>
      <li>
        <button type="button" aria-pressed="false" class="flex w-full items-center justify-between gap-4 px-5 py-4 text-start transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset ">
          <span class="min-w-0">
            <span class="block truncate text-sm font-medium text-foreground">Suggest three alternatives</span>
            <span class="mt-0.5 block text-sm text-muted-foreground">Opens beside the text. Nothing changes until one is picked.</span>
          </span>
          <span class="shrink-0 rounded-full px-2.5 py-1 text-xs font-medium bg-primary/10 text-primary">draft</span>
        </button>
      </li>
      <li>
        <button type="button" aria-pressed="false" class="flex w-full items-center justify-between gap-4 px-5 py-4 text-start transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset ">
          <span class="min-w-0">
            <span class="block truncate text-sm font-medium text-foreground">Explain this passage</span>
            <span class="mt-0.5 block text-sm text-muted-foreground">Read-only. Never touches the document.</span>
          </span>
          <span class="shrink-0 rounded-full px-2.5 py-1 text-xs font-medium bg-primary/10 text-primary">read only</span>
        </button>
      </li>
    </ul>
  </div>
</section>
  • This is rendered HTML, not a translation of the React source. The Tailwind classes carry the design and work in any framework.
  • It is one frame: the component in its initial state, with no props applied beyond the defaults.
  • This block is interactive in React — toggles, menus or form state. None of that survives here; the markup is the closed/default state and the handlers are gone. Re-wire them in your own framework.
  • Requires Tailwind, and the design tokens the classes reference (bg-card, text-muted-foreground, and so on). The template ZIPs ship a globals.css that defines them.

What each framework gets across the whole catalog — effects convert properly; this rung is markup.

For AI

The component, its props, the design tokens it expects and the command that installs it — as one prompt. Paste it into Claude, Cursor, v0 or ChatGPT and what they build around it will match the rest of the catalog instead of inventing its own system.

See the prompt

Used in these pages

Want the whole screen instead of this one section? Open a page and copy it entire.

5 more blocks in Inline AI Actions

All of them free to read, copy and install — no account, no locked tiles, no watermarked preview. The whole catalog is open, and so are the API and the CLI.

Browse Inline AI Actions

Shipping one commercially

Copying the code is free. Putting it in client work or a paid product is what Pro is for — the licence, not the access.

  • A commercial licence for everything in the catalog
  • Unlimited bundle exports, in Vue, Svelte and Tailwind
  • One payment — no subscription, nothing to renew
Pro — $79 once

More Inline AI Actions blocks

View category
Open the full page for this block

Selection Action Toolbar

Highlight a passage and hand it to the model. Positioned from the range rect relative to its container, raised by selectionchange so Shift-Arrow works, and every button prevents the mousedown that would collapse the selection.

Inline AI Actions251 lines1 dep
Open the full page for this block

Ghost Text Completion

Copilot-style completion in a plain textarea: a transparent-caret field over a metric-matched mirror, Tab to accept, Escape that actually sticks, and the suggestion announced rather than left as invisible grey text.

Inline AI Actions206 lines1 dep
Open the full page for this block

Agent-Adjusted Inspector

The model edits real properties and every change is attributed and reversible — per-property provenance in words, per-property revert, and sliders whose aria-valuetext carries the unit.

Inline AI Actions381 lines1 dep
Open the full page for this block

Unprompted Insight Cards

Findings the agent surfaced on its own, paged one at a time, each stating its magnitude rather than its direction, dismissible, and carrying a sparkline that is also a sentence for anyone who cannot see it.

Inline AI Actions284 lines1 dep
Open the full page for this block

Editor Slash Menu

The "/" menu inside a document: focus never leaves the editor, every row names what it acts on, and Escape cleans up the trigger text it inserted instead of leaving you to backspace it.

Inline AI Actions343 lines1 dep