NavigationAnnouncementCountdown
Searchastronomic.dev# AnnouncementCountdown
For a sale with a deadline: the message, the time left as small boxes, and a link.
Interactive: inline script.
## Usage
```astro
import AnnouncementCountdown from "@astronomic/ui-pro/components/AnnouncementCountdown.astro";
```
## Examples
### A sale with the time left as boxes
The message, then the time left as three small boxes (days, hours, minutes) that change once a minute, then a link. The digits keep their width, so the row never moves. It sits above a sticky Navbar and scrolls away.
```astro
---
import AnnouncementCountdown from "@astronomic/ui-pro/components/AnnouncementCountdown.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"];
---
<!-- The boxes count down once a minute. Close it, then reload: it stays closed for the visit. -->
<div>
<AnnouncementCountdown
text="Sample: the Themes Pass is $149 until the sale ends."
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>
```
### With no script
What a visitor with no script sees, drawn with endDisplay="date" and closable="off": the end date in place of the boxes, no close button, and a link that works.
```astro
---
import AnnouncementCountdown from "@astronomic/ui-pro/components/AnnouncementCountdown.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 end date in place of the boxes, no close button, and a link that works. -->
<AnnouncementCountdown
text="Sample: the Themes Pass is $149 until the sale ends."
href="#themes"
linkText="Get the pass"
starts={starts}
expires={ends}
endDisplay="date"
closable="off"
timeZone="America/Los_Angeles"
/>
```
## Props
### AnnouncementCountdown
| 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 link'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 link'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. |
| 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 link 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 boxes are one group hidden from screen readers; the fixed end text beside them is read instead.
- The link stands alone, so it is a real 44px box on a touch screen.
AnnouncementCountdown
ProFor a sale with a deadline: the message, the time left as small boxes, and a link.
- File
- AnnouncementCountdown.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 the time left as boxes
The message, then the time left as three small boxes (days, hours, minutes) that change once a minute, then a link. The digits keep their width, so the row never moves. It sits above a sticky Navbar and scrolls away.
This preview did not load.
main.astro
examples/announcementcountdown/main.astro
---
import AnnouncementCountdown from "@astronomic/ui-pro/components/AnnouncementCountdown.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"];
---
<!-- The boxes count down once a minute. Close it, then reload: it stays closed for the visit. -->
<div>
<AnnouncementCountdown
text="Sample: the Themes Pass is $149 until the sale ends."
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>With no script
What a visitor with no script sees, drawn with endDisplay="date" and closable="off": the end date in place of the boxes, no close button, and a link that works.
This preview did not load.
no-script.astro
examples/announcementcountdown/no-script.astro
---
import AnnouncementCountdown from "@astronomic/ui-pro/components/AnnouncementCountdown.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 end date in place of the boxes, no close button, and a link that works. -->
<AnnouncementCountdown
text="Sample: the Themes Pass is $149 until the sale ends."
href="#themes"
linkText="Get the pass"
starts={starts}
expires={ends}
endDisplay="date"
closable="off"
timeZone="America/Los_Angeles"
/>Minimal · Light