Actions

The Action component provides a flexible row of action buttons for AI responses with common actions like retry, like, dislike, copy, and share.

Hello, how are you?

I am fine, thank you!

Installation

pnpm dlx shadcn-svelte@latest add https://svelte-ai-elements.vercel.app/r/action.json

If you prefer using jsrepo, please install via the command below:

pnpm dlx jsrepo add @ai/elements/ai-elements/action

Usage

Usage with AI SDK

Build a simple chat UI where the user can copy or regenerate the most recent message.

Add the following component to your frontend:

+page.svelte

Add the following route to your backend:

api/chat/+server.ts

Features

  • Row of composable action buttons with consistent styling
  • Support for custom actions with tooltips
  • State management for toggle actions (like, dislike, favorite)
  • Keyboard accessible with proper ARIA labels
  • Clipboard and Web Share API integration
  • TypeScript support with proper type definitions
  • Consistent with design system styling

Examples

This is a response from an assistant. Try hovering over this message to see the actions appear!

Props

Actions

PropTypeDefaultDescription
childrenSnippet-Child Action components to render
classstring-Additional CSS classes to apply to the container
...restPropsHTMLAttributes<HTMLDivElement>-All other div props are supported

Action

PropTypeDefaultDescription
tooltipstring-Tooltip text to display on hover
labelstring-Accessible label for screen readers (falls back to tooltip if not provided)
childrenSnippet-Icon or content to render inside the button
classstring-Additional CSS classes to apply to the button
variant'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link''ghost'Visual style variant of the button
size'default' | 'sm' | 'lg' | 'icon''sm'Size of the button
onclick(event: MouseEvent) => void-Click event handler
disabledboolean-Whether the button is disabled
...restPropsHTMLButtonAttributes | HTMLAnchorAttributes-All other button/anchor props are supported (href for links)