@molecule/app-announcement-bar-svelte

Feature · announcement-bar · App (browser) · v1.1.2 · Apache-2.0

Persistent banner for announcements, promos, feature callouts, with dismiss + CTA

npm install @molecule/app-announcement-bar-svelte

npm · Source on GitHub

How it works

@molecule/app-announcement-bar-svelte is a ready-made announcement-bar feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

<script lang="ts">
  import { setMoleculeContext } from '@molecule/app-svelte'
  import { AnnouncementBar } from '@molecule/app-announcement-bar-svelte'

  setMoleculeContext({ i18n: i18nProvider })
</script>

<AnnouncementBar
  kind="promo"
  icon={'🎉'}
  action={{ label: 'Learn more', href: '/pricing' }}
  onDismiss={() => console.log('dismissed')}
  dataMolId="promo-bar"
>
  New Pro plan — 3 months free for early adopters.
</AnnouncementBar>

Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte announcement / promo bar.

Exports <AnnouncementBar> — persistent top-of-page banner with icon, message, optional action (link or button), and optional dismiss (×). Long-lived and prominent, unlike a Toast; carries an action slot + dismiss, unlike an Alert. It is the Svelte counterpart of @molecule/app-announcement-bar-react: same props (React names), same DOM for the same input, same ClassMap tokens and i18n keys.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

<script lang="ts">
  import { setMoleculeContext } from '@molecule/app-svelte'
  import { AnnouncementBar } from '@molecule/app-announcement-bar-svelte'

  setMoleculeContext({ i18n: i18nProvider })
</script>

<AnnouncementBar
  kind="promo"
  icon={'🎉'}
  action={{ label: 'Learn more', href: '/pricing' }}
  onDismiss={() => console.log('dismissed')}
  dataMolId="promo-bar"
>
  New Pro plan — 3 months free for early adopters.
</AnnouncementBar>

Type

feature

Installation

npm install @molecule/app-announcement-bar-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

AnnouncementBarProps

Props for AnnouncementBar — the same props (React names) as @molecule/app-announcement-bar-react.

interface AnnouncementBarProps {
  /** Primary message — the component's children snippet. */
  children: Snippet
  /** Optional leading icon — a snippet, or a plain string. */
  icon?: Snippet | string
  /** Optional call-to-action (link or button). */
  action?: {
    /** The action's label — a snippet, or a plain string. */
    label: Snippet | string
    /** Rendering as a link: the action is an `<a href>` instead of a `<button>`. */
    href?: string
    /**
     * Called when the action button is clicked (ignored when `href` is set).
     * React's DOM click handler receives the click event, so the callback may
     * take it.
     */
    onClick?: (event?: MouseEvent) => void
  }
  /** Semantic kind — emitted as `data-kind` on the root (style via CSS/`className`). Defaults to `'info'`. */
  kind?: AnnouncementKind
  /** Show a dismiss (×) button. Defaults to true. */
  dismissible?: boolean
  /** Called when the bar is dismissed. */
  onDismiss?: () => void
  /** Controlled visibility — when provided, overrides internal state. */
  visible?: boolean
  /** Extra classes. */
  className?: string
  /** `data-mol-id` for AI-agent selectors. */
  dataMolId?: string
}

Types

AnnouncementKind

Semantic kind, exposed as a data-kind attribute for per-kind styling (no built-in style change).

type AnnouncementKind = 'info' | 'success' | 'warning' | 'error' | 'promo'

Constants

AnnouncementBar

const AnnouncementBar: LegacyComponentType

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-svelte ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-svelte ^1.1.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte
  • @molecule/app-ui
  • @molecule/app-ui-svelte
  • svelte

kind is exposed as a data-kind attribute on the root — it does NOT change the bar's colors by itself; style per-kind via className or a [data-kind="…"] selector. Dismissal is uncontrolled by default (internal state; the bar stays hidden until remount) — pass visible to control it, e.g. to persist dismissal per user. dismissible defaults to true. There is no default data-mol-id; pass dataMolId so agents/E2E can target the bar. Node props are snippets (or plain strings). Translations come from the companion @molecule/app-locales-announcement-bar locale bond.

Translations

Translation strings are provided by @molecule/app-locales-announcement-bar.