Guides

Composing blocks

How every block exposes its children, and how your config reaches them.

Blocks are built from other blocks. A Header holds buttons, a Tabs block holds a row of tab buttons, a CallToAction holds a headline and actions. Every block exposes those children the same way, so once you know the pattern you can configure any of them.

A prop with no suffix configures one child (closeButton, headline) or a list of them (actions, items). A prop ending in Config is a layer: settings merged into many children at once (defaultItemConfig, activeItemConfig). The API reference on each block’s page links both kinds to the child block’s own props.

Turning children on and off

An optional child renders when you set its prop, and not otherwise. There are no show… switches. A child that renders by default is hidden by passing false.

No actions

With actions

presence
---
import CallToActionBlock from '@alfadormx/blocks/composite/CallToAction.astro';
import ContentCarouselBlock from '@alfadormx/blocks/composite/ContentCarousel.astro';

const slides = [
  {
    src: 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&h=600&fit=crop',
    alt: 'Mountain landscape',
  },
  {
    src: 'https://images.unsplash.com/photo-1469474968028-56623f02e42e?w=800&h=600&fit=crop',
    alt: 'Forest path',
  },
];
---

<div class="flex flex-col gap-6">
  <div data-doc-example="no-actions">
    <CallToActionBlock headline={{ title: 'No actions', htmlTag: 'h3' }} />
  </div>
  <div data-doc-example="with-actions">
    <CallToActionBlock
      headline={{ title: 'With actions', htmlTag: 'h3' }}
      actions={[{ label: 'Get started' }]}
    />
  </div>
  <div class="border border-border rounded-lg overflow-hidden" data-doc-example="no-arrows">
    <ContentCarouselBlock items={slides} prevButton={false} nextButton={false} />
  </div>
</div>

Styling many children at once

A default…Config layer applies to every child in the list, in every state. A state layer such as activeItemConfig, selectedItemConfig or highlightedTierConfig sits on top of it and applies only while the child is in that state. Set the shared look once, then only what changes.

Overview panel.

layers
---
import TabsBlock from '@alfadormx/blocks/composite/Tabs.astro';
---

<TabsBlock
  items={[{ label: 'Overview' }, { label: 'API' }, { label: 'Examples' }]}
  defaultItemConfig={{ variant: 'ghost', intent: 'neutral' }}
  activeItemConfig={{ variant: 'solid', intent: 'primary' }}
>
  <p slot="panel-0">Overview panel.</p>
  <p slot="panel-1">API panel.</p>
  <p slot="panel-2">Examples panel.</p>
</TabsBlock>

Who wins

Each child is built from these layers, later ones overriding earlier ones:

  1. the block’s own internal defaults;
  2. the default…Config layer;
  3. the state layer, while the child is in that state;
  4. the child’s own entry (items[n], closeButton, …).

The child’s own entry always wins, so anything you set on it applies in every state. To style a child only while it is active or selected, use the state layer instead. Below, the second tab’s underline stays whether it is active or not.

Settings that identify a single element, such as id, name and anchorId, can’t go in a layer. Set them on the child’s own entry.

Overview panel.

order
---
import TabsBlock from '@alfadormx/blocks/composite/Tabs.astro';
---

<TabsBlock
  items={[{ label: 'Overview' }, { label: 'Pinned', class: 'underline' }]}
  defaultItemConfig={{ variant: 'ghost', intent: 'neutral' }}
  activeItemConfig={{ variant: 'solid', intent: 'primary' }}
>
  <p slot="panel-0">Overview panel.</p>
  <p slot="panel-1">Pinned panel.</p>
</TabsBlock>

Overriding classes

Classes you pass are added to a block’s defaults, never swapped for them. When your class and a default belong to the same group, yours wins: shadow-none removes a default shadow-xl, rounded-none removes a default rounded-md. Use the opposite utility to cancel a default; you never need !.

Flat card

classes
---
import CallToActionBlock from '@alfadormx/blocks/composite/CallToAction.astro';
---

<CallToActionBlock
  headline={{ title: 'Flat card', htmlTag: 'h3' }}
  container={{ content: { class: 'shadow-none rounded-none' } }}
/>