A customizable web component for displaying event banners on your website. Easy to integrate and fully responsive.
# Using npm
npm install event-banner
# Using yarn
yarn add event-banner
# Using pnpm
pnpm add event-banner
// Import the component
import 'event-banner';
// Use in your HTML
<event-banner>
<img slot="icon" src="icon.svg" alt="Icon">
<a slot="link">Your message here</a>
</event-banner>
<script type="module" src="https://cdn.jsdelivr.net/npm/event-banner@latest/src/event-banner.js"></script>
Attribute | Description | Default | Example |
---|---|---|---|
top |
Position from top (for fixed position) | "20%" |
"30%" , "20px" , "2rem"
|
width |
Banner width | "auto" |
"100%" , "500px"
|
fixed |
Fixed positioning | true |
"false" |
duration |
Auto-close duration in milliseconds. It will not automatically close if set 0 | 15000 |
"0" , "2000"
|
The component provides three slots for content customization:
-
icon
: For the banner icon (usually an image) -
link
: For the main content/message -
close
: For the close button (has a default implementation)
<event-banner style="background: sandybrown;">
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">
lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam...
</a>
</event-banner>
The component exposes several parts that can be styled from the outside:
/* Style the icon container */
#custom-parts-banner::part(icon-container) {
background: sandybrown;
padding: 4px;
border-radius: 4px;
}
/* Style the link container */
#custom-parts-banner::part(link-container) {
border: 2px solid salmon;
}
/* Style the close button container */
#custom-parts-banner::part(close-container) {
background: rgba(255, 255, 255, 0.1);
padding: 4px;
border-radius: 4px;
transition: background-color 0.3s;
}
<event-banner id="custom-parts-banner">
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">
lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam...
</a>
</event-banner>
<event-banner>
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">Your message here</a>
</event-banner>
<event-banner top="30">
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">Your message here</a>
</event-banner>
<event-banner fixed="false" width="100%">
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">
lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam...
</a>
</event-banner>
<event-banner>
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">
lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam...
</a>
<button slot="close" class="close-button">
<img src="./btn_close.svg" alt="close" style="width: 30px;height: 30px;" />
</button>
</event-banner>
<!-- Auto-close after 2 seconds -->
<event-banner duration="2000">
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">This banner will auto-close after 2 seconds</a>
</event-banner>
<!-- Disable auto-close -->
<event-banner duration="0">
<img src="./banner.svg" alt="Info icon" slot="icon" />
<a slot="link">This banner will not auto-close</a>
</event-banner>
The banner comes with a default dark theme:
- Dark background
- White text
- Responsive layout
- Smooth close animation
- Flexible width
- Optional fixed positioning