A Callout Component for Astro

A reusable Astro info box with info, note and warning variants, an optional title, social links and a members section with links per person.

Article Created Updated Also in German: Eine Callout-Komponente für Astro

Reviewed by adrian on

While writing a few posts for my old site, I kept needing the same block. A coloured box with an icon, an optional title and a few social links to the band or project in question. A classic case for a small MDX component, and the longer I worked on it, the more it could do:

  • three variants: info, note, warning;
  • an optional title;
  • inline Markdown in the body via <slot />;
  • up to five social icons (YouTube, TikTok, Facebook, Instagram, Website);
  • a members section with name, role and any number of links per person.

In the post on embedding YouTube I used it to link the band right under the video, and below that the singer with her own channels.

Props

src/components/Callout.astro, frontmatter:

---
type SocialKey = 'youtube' | 'tiktok' | 'facebook' | 'instagram' | 'website';

interface MemberLink {
    social: SocialKey;
    href: string;
}
interface Member {
    name: string;
    role?: string;
    links: MemberLink[];
}

interface Props {
    type?: 'info' | 'note' | 'warning';
    title?: string;
    youtube?: string;
    tiktok?: string;
    facebook?: string;
    instagram?: string;
    website?: string;
    membersTitle?: string;
    members?: Member[];
}

const {
    type = 'info',
    title,
    youtube,
    tiktok,
    facebook,
    instagram,
    website,
    membersTitle,
    members = [],
} = Astro.props;
---

The SVG icons (info, note, warning and the social icons) sit as string constants in the same file and are rendered with set:html. Inline SVG was nicer here than another icon package: one build step and a few kilobytes less.

Rendering

<aside class={`callout callout-${type}`}>
    <span class="callout-icon" set:html={icons[type]} />
    <div class="callout-body">
        {title && <p class="callout-title">{title}</p>}
        <slot />
        {
            socials.length > 0 && (
                <ul class="callout-socials">
                    {socials.map((s) => (
                        <li>
                            <a
                                href={s.href}
                                target="_blank"
                                rel="noopener noreferrer"
                                aria-label={s.label}
                                title={s.label}
                                set:html={socialIcons[s.key]}
                            />
                        </li>
                    ))}
                </ul>
            )
        }
        {
            members.length > 0 && (
                <div class="callout-members">
                    {membersTitle && <p class="callout-members-title">{membersTitle}</p>}
                    <ul>
                        {members.map((m) => (
                            <li>
                                <div class="callout-member-text">
                                    <span class="callout-member-name">{m.name}</span>
                                    {m.role && <span class="callout-member-role">{m.role}</span>}
                                </div>
                                {m.links.length > 0 && (
                                    <ul class="callout-member-links">
                                        {m.links.map((l) => (
                                            <li>
                                                <a
                                                    href={l.href}
                                                    target="_blank"
                                                    rel="noopener noreferrer"
                                                    title={socialLabels[l.social]}
                                                    set:html={socialIcons[l.social]}
                                                />
                                            </li>
                                        ))}
                                    </ul>
                                )}
                            </li>
                        ))}
                    </ul>
                </div>
            )
        }
    </div>
</aside>

Three details mattered to me:

  • <slot /> before the lists. The body text stays in the reading flow, socials and members sit below. It still reads sensibly with JavaScript off and no icons rendered.
  • rel="noopener noreferrer" on every external link. It guards against window.opener hijacking and keeps outbound profile links from weakening my site-wide Referrer-Policy: no-referrer.
  • aria-label and title. The icons have no visible label, so screen readers and hover tooltips get a readable name.

Usage

The original post showed each variant as a live box. In MDX:

import Callout from '~/components/Callout.astro';

<Callout>Quick note without a title.</Callout>

<Callout type="warning" title="Heads up">
    Run `astro check` before deploying.
</Callout>

info was the default coloured box, warning a box in warning colours, and note a neutral grey for asides.

The five social props appear as a row of icons under the body. The order is fixed; empty values are skipped.

<Callout
    type="info"
    title="My project"
    website="https://example.com"
    youtube="https://www.youtube.com/@example"
>
    Where the interesting stuff happens.
</Callout>

members takes an array of { name, role?, links }. Each member gets a small card of their own with name, role and an icon row; membersTitle is an optional heading above them. The demo in the post was the box for OZONE Band from Phuket. It had four band links in the top row and a "Band members" heading. Below that came the singer Nene Royal with her role and five links of her own. More members are just more objects in the array.

MDX trap: keep JSX expressions on one line

My first attempt spread the members array over several lines:

members={[
{ name: "…", links: [{ social: "tiktok", href: "…" }] }
]}

@astrojs/mdx parses this with acorn via micromark-util-events-to-acorn. A multi-line JSX expression with nested object literals reliably threw Could not parse expression with acorn. The fix was to put the array on one line. Ugly but stable:

members={[{ name: "…", links: [{ social: "tiktok", href: "…" }] }]}

If the line gets too long, move the array into the frontmatter of an .astro wrapper that imports the component. For a one-off post the inline form is fine.

Styling

  • Left border with a matching accent background: the classic callout look, which holds up across themes and colour schemes.
  • Members section with a dashed border-top: separates band links from personal links without a second background.
  • Inline SVG icons with currentColor: they take the text colour and switch to accent and white on hover. No images, no web font latency.
  • Roles small and dimmed (opacity: 0.8, 0.78rem): the order of attention is name, then role, then icons.

Size and extension

The component came to about 270 lines in one file: props, inline SVGs, render logic and scoped styles. No icon package, no slot stack, no React. In MDX <Callout> is as unobtrusive as a Markdown blockquote.

Another platform such as Mastodon or Bluesky takes two lines: an SVG string in socialIcons and an entry in the SocialKey union and the props. The architecture is deliberately flat: no plugin system, no registry, just a few ifs.

Based on

  • A Callout component for Astro: info boxes with socials and band members (raw/2026/2026-04-25/a-callout-component-for-astro-info-boxes-with-socials-and-band-members.md) [post]

More on this

Topic

  • Static Website A website made of finished HTML files that are built once and then served unchanged. No server code, no database.

Uses

  • Astro Tool for building websites from content such as Markdown. Ships plain HTML by default and only loads JavaScript where it is needed.

Mentioned

  • A GDPR-Compliant YouTube Embed An Astro component that loads YouTube only after a click: show once, agree and remember, or just the link. No cookie, no request to Google before consent.

Show in the graph view