Buttons

Action button

Runs a task and says how it went: working, then done or failed, in the button itself. The button keeps its size through every state.

Installation

npx sinaui add action-button

Examples

Send and confirm

Press it: a spinner while it works, then a tick.

<script lang="ts">
	import ActionButton from '#lib/ui/ActionButton.svelte';

	const send = () => new Promise((resolve) => setTimeout(resolve, 1200));
</script>

<ActionButton action={send} done="Sent">Send to the copyists</ActionButton>

When it fails

This one fails the first time. It says so in red, then goes back so you can try again. With pending, words sit beside the spinner while it works.

<script lang="ts">
	import ActionButton from '#lib/ui/ActionButton.svelte';

	// Fails the first time, works after: press it twice.
	let tries = 0;
	const save = () =>
		new Promise((resolve, reject) =>
			setTimeout(() => (++tries === 1 ? reject(new Error('Offline')) : resolve(null)), 1000)
		);
</script>

<ActionButton
	action={save}
	pending="Saving…"
	done="Saved"
	failed="Couldn’t save"
	variant="secondary">Save the translation</ActionButton
>

Props

PropTypeDefault
action() => Promise | void (required)
pendingstring: words beside the spinner
donestring'Done'
failedstring'Didn’t work'
onerror(error) => void
variant'primary' | 'secondary' | 'ghost''primary'
size'sm' | 'md' | 'lg''md'

Keyboard

KeyDoes
Enter SpaceRun it

Accessibility

  • Working, done and failed are each announced; failure is announced straight away.
  • While it works, presses are ignored, so a task never runs twice.
  • With reduced motion, labels fade without sliding.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme