IconButton
An icon-only action with a required accessible name.
Ready
Source
<script lang="ts">
import 'portal-bits/styles.css';
import 'portal-bits/tokens.css';
import type { Snippet } from 'svelte';
let { children }: { children: Snippet } = $props();
</script>
{@render children()}
<script lang="ts">
import IconButtonExample from './IconButtonExample.svelte';
</script>
<IconButtonExample variant={"secondary"} size={40} disabled={false} />
<script lang="ts">
import { IconButton } from 'portal-bits';
let {
variant = 'secondary',
size = 40,
disabled = false,
}: {
variant?: 'primary' | 'secondary' | 'green';
size?: 32 | 40 | 48;
disabled?: boolean;
} = $props();
let added = $state(false);
</script>
<div class="stack">
<IconButton label="Add item" {variant} {size} {disabled} onclick={() => (added = !added)}>
<svg
width={size === 32 ? 16 : 18}
height={size === 32 ? 16 : 18}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"><path d="M5 12h14" /><path d="M12 5v14" /></svg
>
</IconButton>
<p role="status">{added ? 'Added' : 'Ready'}</p>
</div>
<style>
.stack {
display: grid;
justify-items: center;
gap: 12px;
}
p {
margin: 0;
color: var(--portal-muted);
font-size: 13px;
line-height: 20px;
}
</style>
API reference
These tables list the props and snippets that IconButton declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.
Props
| Name | Type | Default | Required | Binding | Description |
|---|---|---|---|---|---|
label | string | None | Yes | One-way | The accessible name. It is set as `aria-label` because the button has no visible text. |
class | string | "" | No | One-way | Extra classes, added after the component classes. |
Forwarded attributes
- Every Button prop: `variant`, `size`, `href`, `type`, `disabled`, `children`, native attributes, and handlers. `variant` and `size` keep their Button defaults.
No data attributes are documented as stable.
Limits
- The type accepts `variant="quiet"`, but quiet is inline text and the gallery does not offer it here.
- Supply the icon as `children`. The component does not render an icon itself.