Primitives
Button
A button or link with sizes, variants, intents, and icon slots.
Basic buttons
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button label="Click Here" />
<Button
label="Subscribe Now"
icon={{ name: 'heroicons:arrow-top-right-on-square' }}
iconPosition="right"
/>
<Button icon={{ name: 'heroicons:plus' }} />
</div>Sizes
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap items-center gap-4">
<Button label="Extra Small" size="xs" />
<Button label="Small" size="sm" />
<Button label="Medium" size="md" />
<Button label="Large" size="lg" />
<Button label="Extra Large" size="xl" />
</div>Vertical orientation
The orientation prop stacks the icon or image above the label. It has no literal default: without it, a button resolves to vertical only when a subtitle is set. An explicit value always wins.
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap items-start gap-4">
<Button orientation="vertical" icon={{ name: 'heroicons:cube' }} label="Extra Small" size="xs" />
<Button orientation="vertical" icon={{ name: 'heroicons:cube' }} label="Small" size="sm" />
<Button orientation="vertical" icon={{ name: 'heroicons:cube' }} label="Medium" size="md" />
<Button orientation="vertical" icon={{ name: 'heroicons:cube' }} label="Large" size="lg" />
<Button orientation="vertical" icon={{ name: 'heroicons:cube' }} label="Extra Large" size="xl" />
</div>With images
icon and image occupy the same media slot and are mutually exclusive; when both are supplied the image wins. iconPosition positions whichever medium is present. image.alt is required at runtime — the Image primitive throws without it.
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap items-start gap-4">
<Button
label="Horizontal Image"
image={{
src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4',
alt: 'Mountain landscape',
width: 64,
height: 64,
}}
/>
<Button
orientation="vertical"
label="Vertical Image"
image={{
src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4',
alt: 'Mountain landscape',
width: 64,
height: 64,
}}
/>
<Button
label="Image Right"
iconPosition="right"
image={{
src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4',
alt: 'Mountain landscape',
width: 64,
height: 64,
}}
/>
<Button
image={{
src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4',
alt: 'Mountain landscape',
width: 64,
height: 64,
}}
/>
</div>Image sizing
imageSize is a Tailwind class governing the rendered box, while image.width / image.height / image.aspectRatio govern what the optimizer generates. Both are needed — supply dimensions or an aspectRatio, or the optimizer logs an error. Note that image.layout of 'cover' or 'contained' makes the Image wrapper w-full h-full, which will fill the button.
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap items-start gap-4">
<Button
orientation="vertical"
label="Default Size"
image={{
src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4',
alt: 'Mountain landscape',
width: 96,
height: 96,
}}
/>
<Button
orientation="vertical"
label="Explicit Override"
imageSize="size-12"
image={{
src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4',
alt: 'Mountain landscape',
width: 96,
height: 96,
}}
/>
</div>Variants
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button label="Solid" variant="solid" />
<Button label="Outline" variant="outline" />
<Button label="Ghost" variant="ghost" />
<Button label="Link" variant="link" />
</div>Intent colors (solid)
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button label="Primary" intent="primary" />
<Button label="Secondary" intent="secondary" />
<Button label="Tertiary" intent="tertiary" />
<Button label="Accent" intent="accent" />
<Button label="Success" intent="success" />
<Button label="Warning" intent="warning" />
<Button label="Error" intent="error" />
<Button label="Neutral" intent="neutral" />
</div>Intent colors (outline)
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button label="Primary" variant="outline" intent="primary" />
<Button label="Secondary" variant="outline" intent="secondary" />
<Button label="Tertiary" variant="outline" intent="tertiary" />
<Button label="Accent" variant="outline" intent="accent" />
<Button label="Success" variant="outline" intent="success" />
<Button label="Warning" variant="outline" intent="warning" />
<Button label="Error" variant="outline" intent="error" />
<Button label="Neutral" variant="outline" intent="neutral" />
</div>With icons
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button label="Left Icon" icon={{ name: 'heroicons:arrow-left' }} iconPosition="left" />
<Button label="Right Icon" icon={{ name: 'heroicons:arrow-right' }} iconPosition="right" />
<Button
label="Download"
icon={{ name: 'heroicons:arrow-down-tray' }}
iconPosition="left"
intent="success"
/>
<Button
label="External Link"
icon={{ name: 'heroicons:arrow-top-right-on-square' }}
iconPosition="right"
intent="secondary"
/>
</div>Icon only
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-col gap-4">
<div class="flex flex-wrap items-center gap-4">
<Button icon={{ name: 'heroicons:plus' }} size="xs" />
<Button icon={{ name: 'heroicons:plus' }} size="sm" />
<Button icon={{ name: 'heroicons:plus' }} size="md" />
<Button icon={{ name: 'heroicons:plus' }} size="lg" />
<Button icon={{ name: 'heroicons:plus' }} size="xl" />
</div>
<div class="flex flex-wrap gap-4">
<Button icon={{ name: 'heroicons:pencil' }} variant="outline" />
<Button icon={{ name: 'heroicons:trash' }} variant="outline" intent="error" />
<Button icon={{ name: 'heroicons:check' }} variant="ghost" intent="success" />
<Button icon={{ name: 'heroicons:x-mark' }} variant="ghost" intent="error" />
</div>
</div>Promotional buttons (with subtitle)
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button
label="Subscribe Now"
subtitle="Get access to Premium Features for FREE for a year!"
icon={{ name: 'heroicons:arrow-top-right-on-square' }}
iconPosition="right"
size="lg"
/>
<Button
label="Start Free Trial"
subtitle="No credit card required"
icon={{ name: 'heroicons:rocket-launch' }}
iconPosition="left"
size="lg"
intent="accent"
/>
</div>Customized icon
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button
label="Start Free Trial"
subtitle="No credit card required"
icon={{
name: 'heroicons:rocket-launch',
class: 'p-1 rounded-md bg-background text-accent ',
}}
iconPosition="left"
size="lg"
intent="accent"
/>
</div>Shapes
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-col gap-4">
<div class="flex flex-wrap gap-4">
<Button label="Rounded" shape="rounded" />
<Button label="Square" shape="square" />
<Button label="Pill" shape="pill" />
</div>
<div class="flex flex-wrap items-center gap-4">
<Button icon={{ name: 'heroicons:plus' }} shape="rounded" />
<Button icon={{ name: 'heroicons:plus' }} shape="square" />
<Button icon={{ name: 'heroicons:plus' }} shape="pill" />
</div>
</div>Width options
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="space-y-4">
<Button label="Auto Width (Default)" width="auto" />
<Button label="Full Width" width="full" />
</div>States
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button label="Normal" />
<Button label="Disabled" disabled />
<Button label="Disabled Outline" variant="outline" disabled />
</div>As links
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
---
<div class="flex flex-wrap gap-4">
<Button label="Internal Link" href="/colors" />
<Button
label="External Link"
href="https://astro.build"
target="_blank"
icon={{ name: 'heroicons:arrow-top-right-on-square' }}
iconPosition="right"
/>
</div>Spreading an item config
A nav item can be spread onto a Button as is. Its children are not rendered.
---
import Button from '@alfadormx/blocks/primitives/Button.astro';
import type { NavigationTreeItem } from '@alfadormx/blocks/types/navigationtree';
const menuItem: NavigationTreeItem = {
label: 'Products',
children: [{ label: 'Laptops', href: '/products/laptops' }],
};
---
<div class="flex flex-wrap gap-4">
<Button {...menuItem} />
</div>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | — | HTML `id` attribute applied to the rendered `<button>` or `<a>` element. |
| label | string | — | Main text label displayed inside the button. |
| subtitle | string | — | Secondary text rendered below the label; enables the promotional (subtitle) layout. |
| orientation | 'horizontal' | 'vertical' | — | Arrangement of the icon or image relative to the label. No literal default: when omitted it resolves to 'vertical' if `subtitle` is set, otherwise 'horizontal'. An explicit value always wins, including 'horizontal' together with `subtitle`. |
| icon | IconConfig | — | Icon configuration (name, class, aria-label) rendered alongside the label. |
| image | ImageProps | — | Image configuration rendered through the Image primitive, in the same media slot as `icon`. Mutually exclusive with `icon` — when both are set the image wins. `alt` is required at runtime; the Image primitive throws without it. |
| iconPosition | 'left' | 'right' | 'left' | Position of the icon or image relative to the label (default: 'left'). |
| iconSize | string | — | Explicit icon size class, overriding the size-derived default icon size. |
| imageSize | string | — | Explicit image size class, overriding the size-derived default (xs: 'size-3', sm: 'size-4', md: 'size-5', lg: 'size-6', xl: 'size-7'). |
| as | 'summary' | — | Renders the button as the `<summary>` of a `<details>` it is the first child of, so it toggles that disclosure natively. `href`, `target` and `align` are ignored. |
| href | string | — | URL that, when set, renders the button as an `<a>` element instead of a `<button>`. |
| target | '_blank' | '_self' | '_self' | Anchor `target` attribute used when `href` is set (default: '_self'). |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Size of the button, controlling padding and text scale (default: 'md'). |
| variant | 'solid' | 'outline' | 'ghost' | 'link' | 'solid' | Visual style of the button (default: 'solid'). |
| intent | 'primary' | 'secondary' | 'tertiary' | 'accent' | 'success' | 'warning' | 'error' | 'neutral' | 'primary' | Semantic color intent applied to the chosen variant (default: 'primary'). |
| shape | 'rounded' | 'square' | 'pill' | 'rounded' | Corner shape of the button (default: 'rounded'). |
| width | 'auto' | 'full' | 'auto' | Width behavior of the button; 'full' stretches it to fill its container (default: 'auto'). |
| disabled | boolean | false | Disables the button and applies disabled styling (default: false). |
| class | string | '' | Additional custom classes merged onto the button/anchor element (default: ''). |
| labelClass | string | '' | Additional custom classes applied to the label span (default: ''). |
| subtitleClass | string | '' | Additional custom classes applied to the subtitle span (default: ''). |
| iconClass | string | '' | Additional custom classes applied to the icon wrapper. |
| align | 'left' | 'center' | 'right' | — | Horizontal alignment of the button within its wrapping container. |