NavigationAnnouncement
Searchastronomic.dev# Announcement
To build your own announcement bar: one short message above the header, with a link, an optional countdown and a close button. For a ready layout, use AnnouncementText, AnnouncementAction, AnnouncementCountdown or AnnouncementSplit.
Interactive: inline script.
## Usage
```astro
import Announcement from "@astronomic/ui-pro/components/Announcement.astro";
```
## Examples
### A sale with a countdown
Astronomic's sample sale: the message, a Get the pass link, "Ends in" words that tick once a minute (the date with no script) and a close button. It sits above a sticky Navbar and scrolls away; the header sticks once it is past. Close it and reload the frame: it stays closed for the visit.
```astro
---
import Announcement from "@astronomic/ui-pro/components/Announcement.astro";
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Star from "../../logos/astronomic-star.svg";
// Times relative to the build, so the example never expires: the sale ends in 3 days.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const ends = new Date(now + 3 * day).toISOString();
const links = [
{ label: "Themes", href: "#themes" },
{ label: "UI", href: "#ui" },
{ label: "Learn", href: "#learn" },
];
const sections = ["Themes", "UI", "Learn"];
---
<!-- Scroll the frame: the bar scrolls away with the page and the header sticks once it is past. Close it, then reload: it stays closed. -->
<div>
<Announcement
text="Sample: the Themes Pass is $149 for a few more days"
href="#themes"
linkText="Get the pass"
starts={new Date(now - day).toISOString()}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
/>
<Navbar links={links} label="Astronomic" sticky>
<a slot="brand" href="#" class="inline-flex items-center gap-2 text-inherit no-underline">
<Star class="size-5 shrink-0" aria-hidden="true" />
Astronomic
</a>
</Navbar>
<div class="mx-auto grid max-w-prose gap-6 px-6 py-12">
{
sections.map((s) => (
<section id={s.toLowerCase()} class="grid min-h-48 content-end rounded-card bg-surface-2 p-6">
<h2 class="m-0 text-subhead">{s}</h2>
</section>
))
}
</div>
</div>
```
### After the end, swapped
Built between ends and expires with atEnd="swap": the build draws only the ended text, with no link and no end. A page left open past ends swaps the same way, at once and silently.
```astro
---
import Announcement from "@astronomic/ui-pro/components/Announcement.astro";
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Star from "../../logos/astronomic-star.svg";
// Built after the sale's end and before the bar expires: with atEnd="swap" the build draws the ended text only.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const links = [
{ label: "Themes", href: "#themes" },
{ label: "UI", href: "#ui" },
{ label: "Learn", href: "#learn" },
];
const sections = ["Themes", "UI", "Learn"];
---
<div>
<Announcement
text="Sample: the Themes Pass is $149 until the end of the sale"
href="#themes"
linkText="Get the pass"
ends={new Date(now - day).toISOString()}
expires={new Date(now + 3 * day).toISOString()}
atEnd="swap"
endedText="Sample: the sale has ended. The Themes Pass is still here at its usual price."
closable="visit"
timeZone="America/Los_Angeles"
/>
<Navbar links={links} label="Astronomic" sticky>
<a slot="brand" href="#" class="inline-flex items-center gap-2 text-inherit no-underline">
<Star class="size-5 shrink-0" aria-hidden="true" />
Astronomic
</a>
</Navbar>
<div class="mx-auto grid max-w-prose gap-6 px-6 py-12">
{
sections.map((s) => (
<section id={s.toLowerCase()} class="grid min-h-48 content-end rounded-card bg-surface-2 p-6">
<h2 class="m-0 text-subhead">{s}</h2>
</section>
))
}
</div>
</div>
```
## Props
### Announcement
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `text` | `string` | None | The message. One emphasis marker ("Sale ends *Dec 2*") is drawn as <em> only with emphasis; otherwise it is left out. Or put your own markup in the default slot. |
| `href` | `string` | None | The link: http(s), mailto:, tel:, a relative URL or a #fragment (any other scheme stops the build). With no linkText, the whole message is the link. |
| `linkText` | `string` | None | The link's words: a separate link after the message (the action box). |
| `shortText` | `string` | None | A short message for a narrow bar: below a 42rem bar it shows in place of text, from 42rem text shows. Both are in the HTML and CSS shows one, so a screen reader hears one. Same emphasis rule as text. With short words (this or shortLinkText), the end words (countdown or date) hide below 42rem too, so the short bar keeps one line; the icon shows at every width. Default: text at every width. |
| `shortLinkText` | `string` | None | Short words for the link or button on a narrow bar: below 42rem in place of linkText, from 42rem linkText. Default: linkText at every width. |
| `starts` | `string` | None | A UTC ISO time (2026-12-03T07:59:00Z: Z, seconds optional). Before it the bar does not show: not in the build, not before first paint. Any other form, or a date that does not exist (Feb 30), stops the build. |
| `expires` | `string` | None | A UTC ISO time. From it on the bar does not show. It may equal ends or come after it. Checked as starts is. |
| `ends` | `string` | None | A UTC ISO time: what the countdown counts to and the date names. atEnd runs then. After starts, at or before expires. Default: expires. Checked as starts is. |
| `messageKey` | `string` | None | What "the message changed" means. Default: a short hash of text, href, linkText, starts, expires, ends and endedText (and shortText and shortLinkText when set), so a new deadline or ended text shows the bar again. A new key shows the bar again to everyone who closed it. Required for a closable bar with its own message (default slot), its own action (action slot, without href and linkText) or its own end (end slot): slot markup is not hashed. |
| `closable` | `"off" \| "visit" \| "remember"` | `"remember"` | off: no close button. visit: closed for this tab's session. remember: closed until messageKey changes. |
| `endDisplay` | `"countdown" \| "date" \| "none"` | `"countdown"` | countdown: "Ends in 2d 14h 03m", once a minute (the date with no script). date: "Ends Dec 2". none: no end shown; the bar still expires. |
| `atEnd` | `"hide" \| "swap"` | `"hide"` | At ends: hide the bar, or swap the message, link and end for endedText. Applied at build time, before first paint and while the page is open. |
| `endedText` | `string` | None | The message after ends. Required with atEnd="swap". |
| `tone` | `"inverse" \| "accent" \| "band" \| "surface-2"` | `"inverse"` | The surface, one the kit already has, with its own text, link, button and focus colors. |
| `emphasis` | `boolean` | `false` | Draw the message's emphasis marker as <em>. |
| `linkAttrs` | `Record<`data-${string}` \| `aria-${string}`, string>` | None | Extra attributes on the link, such as a dialog trigger's data-* and aria-haspopup. data-* and aria-* only, names lowercased; needs href. An event handler, href, style, any other name, data-announcement-* (the bar's own hooks) or aria-hidden stops the build. |
| `arrow` | `boolean` | `true` | Draw an arrow (Lucide arrow-right) after the link's words. It moves a little on hover where motion is allowed. |
| `label` | `string` | `"Announcement"` | The region's name for screen readers. |
| `closeLabel` | `string` | `"Close announcement"` | The close button's name. |
| `countdownText` | `string` | `"Ends in {time}"` | The countdown's words; {time} is the time left. |
| `dateText` | `string` | `"Ends {date}"` | The date's words; {date} is the end date. |
| `timeZone` | `string` | `"UTC"` | The time zone the date and its screen reader words are written in. A sale that ends at 11:59 PM Pacific passes "America/Los_Angeles": in UTC that moment is already the next day. |
| `dateFormat` | `Intl.DateTimeFormatOptions` | `{ month: "short", day: "numeric" }` | How the date is written ("Dec 2"). |
| `now` | `string \| number \| Date` | None | The time the build checks starts, ends and expires against. Default: the build's own clock. For tests and previews. A string is checked as starts is. |
| `contentClass` | `string` | None | For recipes: the inner row (its width and padding). |
| `bodyClass` | `string` | None | For recipes: the box that holds the message, the action and the end, beside the close button. |
| `textClass` | `string` | None | For recipes: the message. |
| `actionClass` | `string` | None | For recipes: the action box. |
| `endClass` | `string` | None | For recipes: the end box. |
| `closeClass` | `string` | None | For recipes: the close button. |
| `class` | `string` | None | More classes on the bar, merged with cn(), so yours win on conflicts. |
| Slot | Description |
| --- | --- |
| `default` | Your own message markup in place of text. Then a closable bar needs messageKey. |
| `action` | Your own call to action (a Button in the bar's tone) in place of the linkText link. Then a closable bar needs messageKey. |
| `end` | Your own end display in place of the drawn one. Then a closable bar needs messageKey. |
| `icon` | A small decorative icon (a 1rem svg, such as a Lucide icon) before the message. It is hidden from screen readers. |
Any other attribute goes on the bar's <section>. One bar per page: a second one stops the build. Put it before the header, after the skip link.
## Accessibility
| Key | Action |
| --- | --- |
| Tab | Moves to the link, then to the close button |
| Enter / Space | On the close button, closes the bar |
- A region named by its label, before the header. Never an alert or a live region: it is in the page on load, so it is not read out on every page.
- The ticking words are hidden from screen readers; beside them a fixed text gives the end in full ("Ends December 2 at 11:59 PM PST"), and <time> holds the ISO value.
- The close button is a real button, the last stop in the bar, with a 44px hit area. With no script it is not shown, as it could do nothing, but its space is kept, so the text wraps the same before and after the script. During the close fade the bar is inert. After close, focus moves to the next control after the bar, such as the header's brand link.
- A bar someone closed, one before its start and one past its end never paints: a small script before it checks the clock and the stored key while the page loads.
- When ends or expires passes while the page is open, the bar swaps or hides at once (also after a tab comes back from the background), and focus inside it moves on as after a close.
- Links are underlined on hover and on keyboard focus (with the focus ring). The arrow after a link's words and the icon slot are hidden from screen readers.
- The close fades only where motion is allowed; with reduced motion or calm it goes at once.
Announcement
ProTo build your own announcement bar: one short message above the header, with a link, an optional countdown and a close button. For a ready layout, use AnnouncementText, AnnouncementAction, AnnouncementCountdown or AnnouncementSplit.
- File
- Announcement.astro
- Group
- Navigation
- Kind
- Interactive: inline script
- Examples
- 2
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
A sale with a countdown
Astronomic's sample sale: the message, a Get the pass link, "Ends in" words that tick once a minute (the date with no script) and a close button. It sits above a sticky Navbar and scrolls away; the header sticks once it is past. Close it and reload the frame: it stays closed for the visit.
This preview did not load.
examples/announcement/main.astro
---
import Announcement from "@astronomic/ui-pro/components/Announcement.astro";
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Star from "../../logos/astronomic-star.svg";
// Times relative to the build, so the example never expires: the sale ends in 3 days.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const ends = new Date(now + 3 * day).toISOString();
const links = [
{ label: "Themes", href: "#themes" },
{ label: "UI", href: "#ui" },
{ label: "Learn", href: "#learn" },
];
const sections = ["Themes", "UI", "Learn"];
---
<!-- Scroll the frame: the bar scrolls away with the page and the header sticks once it is past. Close it, then reload: it stays closed. -->
<div>
<Announcement
text="Sample: the Themes Pass is $149 for a few more days"
href="#themes"
linkText="Get the pass"
starts={new Date(now - day).toISOString()}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
/>
<Navbar links={links} label="Astronomic" sticky>
<a slot="brand" href="#" class="inline-flex items-center gap-2 text-inherit no-underline">
<Star class="size-5 shrink-0" aria-hidden="true" />
Astronomic
</a>
</Navbar>
<div class="mx-auto grid max-w-prose gap-6 px-6 py-12">
{
sections.map((s) => (
<section id={s.toLowerCase()} class="grid min-h-48 content-end rounded-card bg-surface-2 p-6">
<h2 class="m-0 text-subhead">{s}</h2>
</section>
))
}
</div>
</div>After the end, swapped
Built between ends and expires with atEnd="swap": the build draws only the ended text, with no link and no end. A page left open past ends swaps the same way, at once and silently.
This preview did not load.
examples/announcement/swap.astro
---
import Announcement from "@astronomic/ui-pro/components/Announcement.astro";
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Star from "../../logos/astronomic-star.svg";
// Built after the sale's end and before the bar expires: with atEnd="swap" the build draws the ended text only.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const links = [
{ label: "Themes", href: "#themes" },
{ label: "UI", href: "#ui" },
{ label: "Learn", href: "#learn" },
];
const sections = ["Themes", "UI", "Learn"];
---
<div>
<Announcement
text="Sample: the Themes Pass is $149 until the end of the sale"
href="#themes"
linkText="Get the pass"
ends={new Date(now - day).toISOString()}
expires={new Date(now + 3 * day).toISOString()}
atEnd="swap"
endedText="Sample: the sale has ended. The Themes Pass is still here at its usual price."
closable="visit"
timeZone="America/Los_Angeles"
/>
<Navbar links={links} label="Astronomic" sticky>
<a slot="brand" href="#" class="inline-flex items-center gap-2 text-inherit no-underline">
<Star class="size-5 shrink-0" aria-hidden="true" />
Astronomic
</a>
</Navbar>
<div class="mx-auto grid max-w-prose gap-6 px-6 py-12">
{
sections.map((s) => (
<section id={s.toLowerCase()} class="grid min-h-48 content-end rounded-card bg-surface-2 p-6">
<h2 class="m-0 text-subhead">{s}</h2>
</section>
))
}
</div>
</div>