Skip to content

Announcement

The Announcement component is a flexible notification bar that can be displayed at the top of your webpage. It's perfect for displaying important messages, alerts, or promotional content to your users.

Features

  • Multiple types: info, success, warning, and error
  • Fully responsive design
  • Auto-dismissal after a specified duration
  • Optional close button
  • Smooth animations
  • Customizable colors and content
  • Pushes page content down when displayed

Installation

typescript
import { Announcement } from './path-to/announcement';

Basic Usage

typescript
// Initialize with default settings
const announcement = new Announcement({
  tracker: yourTrackerInstance,
  title: 'New Feature!',
  message: 'Check out our latest update',
  type: 'info',
  autoShow: true
});

Configuration Options

OptionTypeDefaultDescription
trackerSystemTrackerRequiredThe tracker instance for analytics
titlestring''The title of the announcement
messagestring''The main message content
type`'info''success''warning'
themeColorstring'#3b82f6'Custom color for 'info' type announcements
linkUrlstring'https://rojastudio.xyz'URL for the optional link
linkTextstring'Más información'Text for the optional link
autoShowbooleantrueWhether to show the announcement automatically
durationnumber0Auto-hide after milliseconds (0 = don't auto-hide)
dismissiblebooleantrueWhether to show close button
pushBodybooleantrueWhether to push page content down

Methods

show()

Manually display the announcement.

typescript
announcement.show();

hide()

Manually hide the announcement.

typescript
announcement.hide();

Examples

Success Message

typescript
new Announcement({
  tracker: yourTrackerInstance,
  title: 'Success!',
  message: 'Your changes have been saved.',
  type: 'success',
  duration: 5000 // Auto-hide after 5 seconds
});
typescript
new Announcement({
  tracker: yourTrackerInstance,
  title: 'Error',
  message: 'Something went wrong. Please try again.',
  type: 'error',
  linkUrl: '/help',
  linkText: 'Get Help',
  dismissible: false // Force users to acknowledge the error
});

Styling

The component includes default styles but can be customized using the following CSS classes:

  • .pt-announcement - Main container
  • .pt-announcement.visible - When announcement is visible
  • .pt-announcement-inner - Inner content wrapper
  • .pt-announcement-text - Text container
  • .pt-announcement-close - Close button

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)
  • IE11+ (with polyfills)