NavigationAnnouncementText
Searchastronomic.dev# AnnouncementText
For a short notice above the header: one centered line with a link, and the end date or a countdown in words.
Interactive: inline script.
## Usage
```astro
import AnnouncementText from "@astronomic/ui-pro/components/AnnouncementText.astro";
```
## Examples
### A short notice
One centered line: an icon (the icon slot, here Lucide Rocket), the message, its link inline (underlined on hover, an arrow after its words), and the time left in words that tick once a minute (the date with no script). It sits above a sticky Navbar and scrolls away. Close it and reload the frame: it stays closed for the visit.
```astro
---
import AnnouncementText from "@astronomic/ui-pro/components/AnnouncementText.astro";
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Rocket from "@lucide/astro/icons/rocket";
import Star from "../../logos/astronomic-star.svg";
// Times relative to the build, so the example never expires.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const starts = new Date(now - day).toISOString();
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 and the header sticks once it is past. Close it, then reload: it stays closed for the visit. -->
<div>
<AnnouncementText
text="Sample: the Themes Pass is $149 for a few more days."
href="#themes"
linkText="See the pass"
starts={starts}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
>
<Rocket slot="icon" />
</AnnouncementText>
<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>
```
### A long message
The line wraps as text does and stays centered, with the end date after it; the close button keeps its place at the end, centered on the text, and the text never runs under it.
```astro
---
import AnnouncementText from "@astronomic/ui-pro/components/AnnouncementText.astro";
// Times relative to the build, so the example never expires.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const starts = new Date(now - day).toISOString();
const ends = new Date(now + 3 * day).toISOString();
---
<!-- A long message wraps as text does, centered; the close button keeps its place at the top end. -->
<AnnouncementText
text="Sample: the Astronomic docs moved to a new home this week, with one search across every theme, every part and every guide. The old links still work."
href="#themes"
linkText="Read the docs"
starts={starts}
expires={ends}
endDisplay="date"
closable="visit"
timeZone="America/Los_Angeles"
/>
```
## Props
### AnnouncementText
| 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). |
| `textClass` | `string` | None | For recipes: the message. |
| `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. |
| `icon` | A small decorative icon (a 1rem svg) before the message, hidden from screen readers. |
Any other attribute goes on the bar's <section>. One bar per page. 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.
- The message, its link and the end read in one line, in that order.
AnnouncementText
ProFor a short notice above the header: one centered line with a link, and the end date or a countdown in words.
- File
- AnnouncementText.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 short notice
One centered line: an icon (the icon slot, here Lucide Rocket), the message, its link inline (underlined on hover, an arrow after its words), and the time left in words that tick once a minute (the date with no script). It sits above a sticky Navbar and scrolls away. Close it and reload the frame: it stays closed for the visit.
This preview did not load.
examples/announcementtext/main.astro
---
import AnnouncementText from "@astronomic/ui-pro/components/AnnouncementText.astro";
import Navbar from "@astronomic-dev/ui/components/Navbar.astro";
import Rocket from "@lucide/astro/icons/rocket";
import Star from "../../logos/astronomic-star.svg";
// Times relative to the build, so the example never expires.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const starts = new Date(now - day).toISOString();
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 and the header sticks once it is past. Close it, then reload: it stays closed for the visit. -->
<div>
<AnnouncementText
text="Sample: the Themes Pass is $149 for a few more days."
href="#themes"
linkText="See the pass"
starts={starts}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
>
<Rocket slot="icon" />
</AnnouncementText>
<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>A long message
The line wraps as text does and stays centered, with the end date after it; the close button keeps its place at the end, centered on the text, and the text never runs under it.
This preview did not load.
examples/announcementtext/long.astro
---
import AnnouncementText from "@astronomic/ui-pro/components/AnnouncementText.astro";
// Times relative to the build, so the example never expires.
const now = Date.now();
const day = 24 * 60 * 60 * 1000;
const starts = new Date(now - day).toISOString();
const ends = new Date(now + 3 * day).toISOString();
---
<!-- A long message wraps as text does, centered; the close button keeps its place at the top end. -->
<AnnouncementText
text="Sample: the Astronomic docs moved to a new home this week, with one search across every theme, every part and every guide. The old links still work."
href="#themes"
linkText="Read the docs"
starts={starts}
expires={ends}
endDisplay="date"
closable="visit"
timeZone="America/Los_Angeles"
/>