tinkerers-labs

Slash Menu

AI chats

About

A message field that opens a command menu when a word starts with a slash, then spells out the chosen command's arguments and marks the one you are typing.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Slash Menu to your project and fits it to your theme.

Code

How Slash Menu is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client"

import * as React from "react"

import {
  parseSlashCommand,
  SlashMenu,
  type SlashCommand,
} from "@/components/ui/mischief-slash-menu"

const commands: SlashCommand[] = [
  {
    name: "translate",
    description: "Translate text into another language",
    args: ["language", "text"],
  },
  {
    name: "summarize",
    description: "Summarize the conversation so far",
    args: ["length"],
  },
  {
    name: "rename",
    description: "Rename a symbol across the project",
    args: ["from", "to"],
  },
  {
    name: "model",
    description: "Switch the model for this chat",
    args: ["name"],
  },
  { name: "clear", description: "Start a new conversation" },
]

export default function SlashMenuDemo() {
  const [text, setText] = React.useState("")
  const [result, setResult] = React.useState<string | null>(null)

  const submit = () => {
    const parsed = parseSlashCommand(text, commands)
    if (!text.trim()) return

    if (parsed) {
      const names = parsed.command.args ?? []
      const filled = names.map(
        (name, index) => `${name}: ${parsed.args[index] ?? "(missing)"}`
      )
      setResult(
        `Ran /${parsed.command.name}${filled.length ? ` with ${filled.join(", ")}` : ""}`
      )
    } else {
      setResult(`Sent: ${text.trim()}`)
    }
    setText("")
  }

  return (
    <div className="grid min-h-[19rem] w-full max-w-xl content-start gap-3">
      <SlashMenu
        commands={commands}
        placeholder="Type / for commands"
        rows={2}
        value={text}
        onKeyDown={(event) => {
          if (event.key !== "Enter" || event.shiftKey) return
          if (event.nativeEvent.isComposing) return
          event.preventDefault()
          submit()
        }}
        onValueChange={setText}
      />

      <p className="text-muted-foreground text-xs" role="status">
        {result ?? "Try /translate Spanish Where is the station?"}
      </p>

      <dl className="border-border grid grid-cols-[auto_minmax(0,1fr)] gap-x-4 gap-y-1.5 border-t pt-3 text-xs">
        {commands.map((command) => (
          <React.Fragment key={command.name}>
            <dt className="font-[family-name:var(--font-mono),monospace]">
              /{command.name}
            </dt>
            <dd className="text-muted-foreground">{command.description}</dd>
          </React.Fragment>
        ))}
      </dl>
    </div>
  )
}

More by tinkerers-labs

View all
  • Prompt Input

    Prompt Input

    11
  • Burst

    Burst

    4
  • Undo Button

    Undo Button

  • Tool Approval

    Tool Approval

  • Notification Stack

    Notification Stack

  • Swipe Actions

    Swipe Actions

  • Sparkline

    Sparkline

  • Ghost Text

    Ghost Text

More in AI chats

View all
  • Agent Chat

    Agent Chat

    21
  • AI Actions

    AI Actions

    372
  • AI Suggestions

    AI Suggestions

    27
  • Interactive LLM Token & Context Window Visualizer

    Interactive LLM Token & Context Window Visualizer

    30
  • AI SaaS Workflow Hero

    AI SaaS Workflow Hero

    36
  • Aquarium Prompt

    Aquarium Prompt

    219
  • Message Parts

    Message Parts

    10
  • AI Chat Composer

    AI Chat Composer

    21