Skip to content
Likable Aurora @likable-hair/svelte 5

ActivableButton

Toggle button that stays pressed: every click flips active and then calls onclick, and the state is announced with aria-pressed. It is a Button with its own look for the two states (neutral when off, primary tint when on), so size, icon, loading, disabled and the other Button props work the same way. Buttons with text and no icon show a dot that lights up when active (dot={false} hides it); icon-only buttons, as in a text editor toolbar, need an aria-label. To drive active from outside (for example from the editor state), pass it without bind: and update it in onclick. Its state is exposed as data-active for app CSS.

import { ActivableButton } from '@likable-hair/svelte';

src/lib/components/composed/buttons/ActivableButton.svelte · Markdown for LLMs

Filters

Every click flips active (here with bind:active) and the dot lights up; the state is announced with aria-pressed. size and the other Button props work as usual.

Only active: true · Favorites: false

Code
<script lang="ts">
	import { ActivableButton } from '@likable-hair/svelte';

	let onlyActive = $state(true);
	let favorites = $state(false);
</script>

<div class="demo">
	<div class="row">
		<ActivableButton bind:active={onlyActive}>Only active</ActivableButton>
		<ActivableButton bind:active={favorites}>Favorites</ActivableButton>
		<ActivableButton size="sm" dot={false}>No dot</ActivableButton>
		<ActivableButton disabled>Disabled</ActivableButton>
	</div>
	<p>Only active: <strong>{onlyActive}</strong> · Favorites: <strong>{favorites}</strong></p>
</div>

<style>
	.demo {
		display: grid;
		gap: 12px;
	}

	.row {
		display: flex;
		flex-wrap: wrap;
		gap: 8px;
	}

	p {
		margin: 0;
		font-size: 13px;
	}
</style>

Toolbar

Icon-only toggles, as in a text editor, need an aria-label. Here active is driven from outside, without bind:: onclick updates the formatting state and the buttons follow it.

Sample text

Code
<script lang="ts">
	import { mdiFormatBold, mdiFormatItalic, mdiFormatUnderline, mdiStar } from '@mdi/js';
	import { ActivableButton } from '@likable-hair/svelte';

	let format = $state({ bold: true, italic: false, underline: false });
	let starred = $state(true);
</script>

<div class="row">
	<div class="toolbar" role="toolbar" aria-label="Formatting">
		<ActivableButton
			icon={mdiFormatBold}
			aria-label="Bold"
			size="sm"
			active={format.bold}
			onclick={() => (format.bold = !format.bold)}
		/>
		<ActivableButton
			icon={mdiFormatItalic}
			aria-label="Italic"
			size="sm"
			active={format.italic}
			onclick={() => (format.italic = !format.italic)}
		/>
		<ActivableButton
			icon={mdiFormatUnderline}
			aria-label="Underline"
			size="sm"
			active={format.underline}
			onclick={() => (format.underline = !format.underline)}
		/>
	</div>
	<ActivableButton icon={mdiStar} aria-label="Starred" bind:active={starred} />
	<p class:bold={format.bold} class:italic={format.italic} class:underline={format.underline}>
		Sample text
	</p>
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 16px;
	}

	.toolbar {
		display: flex;
		gap: 4px;
	}

	p {
		margin: 0;
	}

	.bold {
		font-weight: 700;
	}

	.italic {
		font-style: italic;
	}

	.underline {
		text-decoration: underline;
	}
</style>

Props

NameTypeDefaultDescription
active bindable booleanfalsePressed state. A click flips it before onclick runs.
dot booleantrueShows the state dot before the text. It appears only on buttons with text and no icon.

From Button

It accepts the props, snippets and events of Button, listed in the tables "From Button". Except variant, buttonType.

NameTypeDefaultDescription
size 'sm' | 'md' | 'lg''md'Height, padding and text size: sm 28px, md 34px, lg 40px.
type 'button' | 'submit' | 'reset''button'Native type. Defaults to button, so it never submits a form by accident. Ignored with href.
href stringRenders an <a> link to this URL instead of a <button>, with the same look.
target '_self' | '_blank' | '_parent' | '_top' | (string & {})Native target of the link (with href). With _blank, rel defaults to noopener noreferrer.
rel stringNative rel of the link (with href).
download string | booleanNative download of the link (with href).
loading booleanfalseShows a spinner in place of the icon (or before the text) and disables the button.
icon stringSVG path of the icon, for example from @mdi/js. With text it sits on the left; alone it makes the button square.
disabled booleanfalseNative disabled: the button gets neither focus nor events. A link (href) loses its href and gets aria-disabled.
buttonElement bindable HTMLButtonElement | HTMLAnchorElementThe native element: <button>, or <a> with href.
appendIcon stringSVG path of an icon after the text. When the button is wider than its content, it sits at the right edge.

It also accepts the native attributes and events of <button> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
dotSnippet{ active: boolean }Replaces the state dot.

From Button

NameParametersDescription
childrenButton label.
iconSnippetReplaces the icon with any content (an image, an avatar, a custom SVG). Without children it makes the button square, like icon.
loadingSnippetReplaces the loading spinner.
appendSnippetReplaces appendIcon with any content after the text (a chevron, a counter, a shortcut).

CSS variables

For a single instance, pass them as style props: <ActivableButton --activable-button-background="tomato">. The --activable-button-default-* defaults apply to the whole app: override them in :root or in a theme.

It also takes the variables of Button.

Per-instance variableDefault
--activable-button-background
--activable-button-default-background var(--global-color-surface-2)
--activable-button-color
--activable-button-default-color var(--global-color-text-2)
--activable-button-border-color
--activable-button-default-border-color var(--global-color-border)
--activable-button-hover-background
--activable-button-default-hover-background var(--global-color-surface-3)
--activable-button-hover-color
--activable-button-default-hover-color var(--global-color-text)
--activable-button-hover-border-color
--activable-button-default-hover-border-color var(--global-color-border-strong)
--activable-button-dot-color
--activable-button-default-dot-color var(--global-color-text-3)
--activable-button-active-background
--activable-button-default-active-background var(--global-color-primary-soft)
--activable-button-active-color
--activable-button-default-active-color var(--global-color-primary)
--activable-button-active-border-color
--activable-button-default-active-border-color color-mix(in oklab, var(--global-color-primary) 50%, transparent)
--activable-button-active-hover-background
--activable-button-default-active-hover-background color-mix(in oklab, var(--global-color-primary) 18%, transparent)
--activable-button-active-hover-color
--activable-button-default-active-hover-color var(--global-color-primary)
--activable-button-active-hover-border-color
--activable-button-default-active-hover-border-color var(--global-color-primary)
--activable-button-active-dot-color
--activable-button-default-active-dot-color var(--global-color-primary)
--activable-button-active-dot-box-shadow
--activable-button-default-active-dot-box-shadow 0 0 0 3px color-mix(in oklab, var(--global-color-primary) 25%, transparent)
--activable-button-dot-size
--activable-button-default-dot-size 7px