NavigationAnnouncementAction
Searchastronomic.dev# AnnouncementAction
For a sale or launch with one clear action: the message and a small button, side by side when there is room.
Interactive: inline script.
## Usage
```astro
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.astro";
```
## Examples
### A sale with one button
The message and the time left at the start, a small Button in the bar's tone at the end, then the close button. Below a 42rem bar the button drops under the message. It sits above a sticky Navbar and scrolls away.
```astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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.
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"];
---
<!-- Narrow the frame below 42rem: the button drops under the message. Close it, then reload: it stays closed for the visit. -->
<div>
<AnnouncementAction
text="Sample: the Themes Pass is $149 for a few more days."
href="#themes"
linkText="Get the pass"
starts={starts}
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>
```
### Centered
align="center": the message, the time left and the button together in the middle; the close button stays at the end.
```astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- align="center": the message, the time left and the button sit together in the middle; the close button stays at the end. -->
<AnnouncementAction
align="center"
text="Sample: every theme, now and in the future, for $149."
href="#themes"
linkText="Get the pass"
starts={starts}
ends={ends}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
/>
```
### Short words on a narrow bar
shortText and shortLinkText: below a 42rem bar the short message and the short button show in one row with the close button (wrapping at the start when they do not fit), and the end words hide (the icon stays); from 42rem the long words and the time left. Resize the frame to see both.
```astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- shortText and shortLinkText: the short words below a 42rem bar (one row: message, button, close; no end words), the long words from 42rem. -->
<AnnouncementAction
align="center"
emphasis
text="*Sample sale.* Every theme, now and in the future, for $149."
shortText="*Sample sale*"
href="#themes"
linkText="Get the pass – Save $50"
shortLinkText="$50 off the pass"
starts={starts}
ends={ends}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
textClass="[&_em]:not-italic [&_em]:font-semibold"
/>
```
### A long message
The message takes the room it needs and wraps; the button keeps its size at the end, and drops under the message on a narrow bar.
```astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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 takes the room it needs; the button stays at the end, and drops under the message on a narrow bar. -->
<AnnouncementAction
text="Sample: every Astronomic theme, every Pro part and every update after today, for one price on as many sites as you build. The Themes Pass is $149 for a few more days."
href="#themes"
linkText="Get the pass"
starts={starts}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
/>
```
### Your own action
The action slot holds any component in place of the drawn button: here a Button that would open a waitlist form. href and linkText are left out, and the bar names its messageKey, as the slot is not hashed.
```astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- Your own action in the action slot: here a button that would open a waitlist form. href and linkText are left out; the bar names its key, as the slot is not hashed. -->
<AnnouncementAction
text="Sample: launch pricing is coming. The waitlist hears first."
messageKey="waitlist-1"
starts={starts}
expires={ends}
endDisplay="none"
closable="visit"
>
<Button slot="action" type="button" size="sm" tone="inverse" class="tap-area">Join the waitlist</Button>
</AnnouncementAction>
```
### With no script
What a visitor with no script sees, drawn with endDisplay="date" and closable="off": the end date in place of the countdown, no close button (it could do nothing), and a button that is a plain link, so it works.
```astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- What a visitor with no script sees, drawn with endDisplay="date" and closable="off": the date in place of the countdown, no close button, and a button that works. -->
<AnnouncementAction
text="Sample: the Themes Pass is $149 for a few more days."
href="#themes"
linkText="Get the pass"
starts={starts}
expires={ends}
endDisplay="date"
closable="off"
timeZone="America/Los_Angeles"
/>
```
## Props
### AnnouncementAction
| 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 | Required unless the action slot holds your own action. The button's address: http(s), mailto:, tel:, a relative URL or a #fragment (any other scheme stops the build). |
| `linkText` | `string` | None | Required unless the action slot holds your own action. The button's words. |
| `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. |
| `align` | `"start" \| "center"` | None | start (the default): the message at the start and the button at the end. center: from a 42rem bar, the message, the end words and the button together in the middle of the bar; the close button stays at the end, with the same space kept at the start so the group sits in the true middle. Below 42rem both are at the start, so wrapped lines never sit off the middle beside the close button. |
| Slot | Description |
| --- | --- |
| `default` | Your own message markup in place of text. Then a closable bar needs messageKey. |
| `action` | Your own action (any component, such as a waitlist Button) in place of the button drawn from href and linkText, which are then not used. A closable bar with it needs messageKey (your action is not hashed). |
| `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 button is a link styled as a small Button, with a 44px hit area on a touch screen. Tab goes from it to the close button.
AnnouncementAction
ProFor a sale or launch with one clear action: the message and a small button, side by side when there is room.
- File
- AnnouncementAction.astro
- Group
- Navigation
- Kind
- Interactive: inline script
- Examples
- 6
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
A sale with one button
The message and the time left at the start, a small Button in the bar's tone at the end, then the close button. Below a 42rem bar the button drops under the message. It sits above a sticky Navbar and scrolls away.
This preview did not load.
examples/announcementaction/main.astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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.
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"];
---
<!-- Narrow the frame below 42rem: the button drops under the message. Close it, then reload: it stays closed for the visit. -->
<div>
<AnnouncementAction
text="Sample: the Themes Pass is $149 for a few more days."
href="#themes"
linkText="Get the pass"
starts={starts}
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>Centered
align="center": the message, the time left and the button together in the middle; the close button stays at the end.
This preview did not load.
examples/announcementaction/centered.astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- align="center": the message, the time left and the button sit together in the middle; the close button stays at the end. -->
<AnnouncementAction
align="center"
text="Sample: every theme, now and in the future, for $149."
href="#themes"
linkText="Get the pass"
starts={starts}
ends={ends}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
/>Short words on a narrow bar
shortText and shortLinkText: below a 42rem bar the short message and the short button show in one row with the close button (wrapping at the start when they do not fit), and the end words hide (the icon stays); from 42rem the long words and the time left. Resize the frame to see both.
This preview did not load.
examples/announcementaction/short.astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- shortText and shortLinkText: the short words below a 42rem bar (one row: message, button, close; no end words), the long words from 42rem. -->
<AnnouncementAction
align="center"
emphasis
text="*Sample sale.* Every theme, now and in the future, for $149."
shortText="*Sample sale*"
href="#themes"
linkText="Get the pass – Save $50"
shortLinkText="$50 off the pass"
starts={starts}
ends={ends}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
textClass="[&_em]:not-italic [&_em]:font-semibold"
/>A long message
The message takes the room it needs and wraps; the button keeps its size at the end, and drops under the message on a narrow bar.
This preview did not load.
examples/announcementaction/long.astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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 takes the room it needs; the button stays at the end, and drops under the message on a narrow bar. -->
<AnnouncementAction
text="Sample: every Astronomic theme, every Pro part and every update after today, for one price on as many sites as you build. The Themes Pass is $149 for a few more days."
href="#themes"
linkText="Get the pass"
starts={starts}
expires={ends}
closable="visit"
timeZone="America/Los_Angeles"
/>Your own action
The action slot holds any component in place of the drawn button: here a Button that would open a waitlist form. href and linkText are left out, and the bar names its messageKey, as the slot is not hashed.
This preview did not load.
examples/announcementaction/own-action.astro
---
import Button from "@astronomic-dev/ui/components/Button.astro";
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- Your own action in the action slot: here a button that would open a waitlist form. href and linkText are left out; the bar names its key, as the slot is not hashed. -->
<AnnouncementAction
text="Sample: launch pricing is coming. The waitlist hears first."
messageKey="waitlist-1"
starts={starts}
expires={ends}
endDisplay="none"
closable="visit"
>
<Button slot="action" type="button" size="sm" tone="inverse" class="tap-area">Join the waitlist</Button>
</AnnouncementAction>With no script
What a visitor with no script sees, drawn with endDisplay="date" and closable="off": the end date in place of the countdown, no close button (it could do nothing), and a button that is a plain link, so it works.
This preview did not load.
examples/announcementaction/no-script.astro
---
import AnnouncementAction from "@astronomic/ui-pro/components/AnnouncementAction.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();
---
<!-- What a visitor with no script sees, drawn with endDisplay="date" and closable="off": the date in place of the countdown, no close button, and a button that works. -->
<AnnouncementAction
text="Sample: the Themes Pass is $149 for a few more days."
href="#themes"
linkText="Get the pass"
starts={starts}
expires={ends}
endDisplay="date"
closable="off"
timeZone="America/Los_Angeles"
/>