ActionsButton
Searchastronomic.dev# Button
For the main action on a page or in a form, and for links that should look like one.
Static: no JavaScript.
## Usage
```astro
import Button from "@astronomic-dev/ui/components/Button.astro";
```
## Examples
### Variants
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
---
<div class="flex flex-wrap items-center gap-3">
<Button>Start a project</Button>
<Button variant="secondary">See our work</Button>
<Button variant="ghost">Read the journal</Button>
</div>
```
### Sizes
sm, md and lg. Use one size per row of buttons.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
---
<div class="flex flex-wrap items-center gap-3">
<Button size="sm">Small</Button>
<Button>Medium</Button>
<Button size="lg">Large</Button>
</div>
```
### Links and disabled
With href, a Button renders a link. A disabled link drops its `href`.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
---
<div class="flex flex-wrap items-center gap-3">
<Button href="#work">See our work</Button>
<Button href="#rates" variant="secondary">See our rates</Button>
<Button href="#closed" disabled>Booking closed</Button>
<Button type="submit" variant="secondary" disabled>Send</Button>
</div>
```
### Icon tile
iconTile={ArrowRight} puts your icon in a round tile at the end of a fully round pill, in the button's own colors inverted. The icon turns on hover and focus when motion is allowed.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
// Your own icon component: Lucide's, or an SVG component of your own.
import ArrowRight from "@lucide/astro/icons/arrow-right";
---
<!-- iconTile: a round tile with your icon at the end of the pill. The tile takes the button's colors, inverted. -->
<div class="flex flex-wrap items-center gap-3">
<Button href="#start" iconTile={ArrowRight}>Start a project</Button>
<Button href="#work" variant="secondary" iconTile={ArrowRight}>See our work</Button>
<Button href="#journal" variant="ghost" iconTile={ArrowRight}>Read the journal</Button>
</div>
```
### Sliding arrow
tileMotion="slide": on hover and keyboard focus the icon slides out of its tile and a copy slides in from the other side. Still under reduced motion or the theme's calm setting.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import ArrowRight from "@lucide/astro/icons/arrow-right";
---
<!-- tileMotion="slide": on hover or keyboard focus the arrow slides out of its tile and a copy slides in. With reduced motion or the theme's calm setting nothing moves. -->
<div class="flex flex-wrap items-center gap-3">
<Button href="#quote" iconTile={ArrowRight} tileMotion="slide">Get a free quote</Button>
<Button href="#work" variant="secondary" iconTile={ArrowRight} tileMotion="slide">See recent projects</Button>
<Button href="#areas" variant="ghost" iconTile={ArrowRight} tileMotion="slide">Areas we serve</Button>
</div>
```
### Square corners
--ui-radius-pill sets the pill's corners (fully round by default). The tile's corners follow: the pill's radius less the tile's 6px inset, so they run parallel. Here 10px gives the tile 4px.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import ArrowRight from "@lucide/astro/icons/arrow-right";
---
<!--
--ui-radius-pill: a theme sets it in its tokens (here a wrapper sets it, to show that it reaches the buttons inside).
The pill takes 10px corners and its tile 4px: the pill's radius less the tile's 6px inset, so the corners run parallel.
-->
<div class="flex flex-wrap items-center gap-3 [--ui-radius-pill:0.625rem]">
<Button href="#quote" iconTile={ArrowRight} tileMotion="slide">Get a free quote</Button>
<Button href="#work" variant="secondary" iconTile={ArrowRight} tileMotion="slide">See recent projects</Button>
<Button href="#call" size="lg" iconTile={ArrowRight}>Call (555) 010-0142</Button>
</div>
```
### Rolling label
roll rolls the label up on hover and keyboard focus, and the same words roll in from below. It stays still under reduced motion or the theme's calm setting. For a nav link, see "Rolling links" in the kit README.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import ArrowRight from "@lucide/astro/icons/arrow-right";
---
<!-- roll: hover or tab to a button and its label rolls up. With reduced motion or the theme's calm setting it stays still. -->
<div class="flex flex-wrap items-center gap-3">
<Button href="#start" roll>Start a project</Button>
<Button href="#work" variant="secondary" roll>See our work</Button>
<Button href="#contact" roll iconTile={ArrowRight}>Get in touch</Button>
</div>
```
### On the dark panel
tone="inverse" with iconTile and roll on Panel tone="inverse": the tile inverts with the button.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import Panel from "@astronomic-dev/ui/components/Panel.astro";
import ArrowRight from "@lucide/astro/icons/arrow-right";
---
<!-- On the dark panel: tone="inverse". The tile inverts with the button, and Panel gives the focus ring. -->
<Panel tone="inverse" as="div">
<div class="flex flex-wrap items-center gap-3 px-6">
<Button tone="inverse" href="#start" roll iconTile={ArrowRight}>Start a project</Button>
<Button tone="inverse" variant="secondary" href="#services" roll iconTile={ArrowRight}>See the services</Button>
</div>
</Panel>
```
### On the accent
tone="accent" on the accent surface (surface-accent, as GuaranteeStrip and EmergencyBanner): the primary is an accent-fg fill with accent text, the secondary an accent-fg outline. Put focus-on-accent on the surface for the focus ring.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import ArrowRight from "@lucide/astro/icons/arrow-right";
---
<!-- On the accent surface: tone="accent". The surface gives the focus ring (focus-on-accent). -->
<div class="surface-accent focus-on-accent flex flex-wrap items-center gap-3 rounded-card p-6">
<Button tone="accent" href="#quote" iconTile={ArrowRight}>Get a free estimate</Button>
<Button tone="accent" variant="secondary" href="#services">See the services</Button>
<Button tone="accent" variant="ghost" href="#area">Towns we serve</Button>
</div>
```
## Props
### Button
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `"primary" \| "secondary" \| "ghost"` | `"primary"` | The look. Use one primary button per view. |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding and type size. |
| `tone` | `"page" \| "image" \| "band" \| "cta" \| "inverse" \| "accent"` | `"page"` | Where the button sits. `image` on an image under a scrim: `scrim-fg` colors that read on any picture; put `focus-on-image` on an ancestor for the focus ring, as the Hero does. `band` on a bar that moves onto the band when a preset sets `--ui-band` (the Navbar's actions): inverted there, the page colors otherwise. `cta` on the CTA band (the band, else the accent): inverted against it; put `focus-on-cta` on the band. `inverse` on the inverse surface (Panel `tone="inverse"`): inverted against it; Panel gives the focus ring. `accent` on the accent surface (`surface-accent`): inverted against it; put `focus-on-accent` on the surface. |
| `iconTile` | `IconComponent` | None | Your icon component (Lucide's, or your own SVG component), in a tile at the end of the pill. The pill takes `--ui-radius-pill`'s corners (fully round by default) and is at least 44px tall; the tile's corners are the pill's less its 6px inset, and the tile is the inverted pair of the button's colors. The icon is decoration, hidden from a screen reader, and moves on hover and focus when motion is allowed (`tileMotion`). |
| `tileMotion` | `"turn" \| "slide"` | `"turn"` | How the tile's icon moves on hover and keyboard focus: `turn` turns it -45°; `slide` moves it out past the tile's end while a copy of it, hidden from a screen reader, moves in from the start. Still under reduced motion or the theme's calm setting. Used with `iconTile`. |
| `roll` | `boolean` | `false` | On hover and keyboard focus, the label rolls up and the same words roll in from below; the label is read once. Off under reduced motion, the theme's calm setting, and on a disabled button. Use plain words: the copy is drawn from the label's text. |
| `href` | `string` | None | Renders a link (`<a>`) instead of a `<button>`. |
| `type` | `"button" \| "submit" \| "reset"` | `"button"` | The button type. Not used with `href`. |
| `disabled` | `boolean` | `false` | Disables the button. A disabled link drops its `href`. |
| `class` | `string` | None | More classes, merged with `cn()`, so yours win on conflicts. |
| Slot | Description |
| --- | --- |
| `default` | The label. |
Any other attribute goes on the <button> or <a>.
## Accessibility
- Renders a native <button>, or an <a> when href is set, so keys and roles come from the browser.
- A disabled link loses its href and gets aria-disabled, so it cannot be focused or followed.
- Every variant shows the same accent focus ring on keyboard focus.
- An icon-only button has no text, so give it an aria-label.
- iconTile's icon is decoration: the label names the button. With tileMotion="slide" its copy is hidden from a screen reader too.
- roll draws the copy of the label with empty alt text, so a screen reader reads the label once. Nothing moves for a reader who asks for reduced motion.
Button
FreeFor the main action on a page or in a form, and for links that should look like one.
- File
- Button.astro
- Group
- Actions
- Kind
- Static: no JavaScript
- Examples
- 9
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Variants
Sizes
sm, md and lg. Use one size per row of buttons.
Links and disabled
With href, a Button renders a link. A disabled link drops its `href`.
Icon tile
iconTile={ArrowRight} puts your icon in a round tile at the end of a fully round pill, in the button's own colors inverted. The icon turns on hover and focus when motion is allowed.
Sliding arrow
tileMotion="slide": on hover and keyboard focus the icon slides out of its tile and a copy slides in from the other side. Still under reduced motion or the theme's calm setting.
Square corners
--ui-radius-pill sets the pill's corners (fully round by default). The tile's corners follow: the pill's radius less the tile's 6px inset, so they run parallel. Here 10px gives the tile 4px.
Rolling label
roll rolls the label up on hover and keyboard focus, and the same words roll in from below. It stays still under reduced motion or the theme's calm setting. For a nav link, see "Rolling links" in the kit README.
On the dark panel
tone="inverse" with iconTile and roll on Panel tone="inverse": the tile inverts with the button.
On the accent
tone="accent" on the accent surface (surface-accent, as GuaranteeStrip and EmergencyBanner): the primary is an accent-fg fill with accent text, the secondary an accent-fg outline. Put focus-on-accent on the surface for the focus ring.