0.0.7 • Published 3 years ago

bannery v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Bannery

A really easy-to-use component for generating fully customized banners. You can take advantage of it in order to show, for example, a cookie consent banner or even to announce an upcoming event.

⭐️ Features

  • Options from external source
  • Markdown support
  • Start/End date
  • One-time display
  • Callbacks
  • CSS customization
  • Custom CSS animation

⚙️ Usage

Install

npm -i bannery
// or
yarn add bannery

ES Module

import Bannery from 'bannery';

import 'bannery/dist/style.css';
import 'bannery/dist/theme.css'; // or use "css" option

Bannery({ url: 'https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/example.json' });

CDN

Alternatively, you can include it via jsDelivr CDN:

UMD:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/theme.css">

<script src="https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/bannery.umd.js"></script>
<script>
  Bannery({ url: 'https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/example.json' });
</script>

ES module:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/theme.css">

<script type="module">
  import Bannery from "https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/bannery.es.js";

  Bannery({
    url: "https://cdn.jsdelivr.net/gh/embedmode/bannery/dist/example.json"
  });
</script>

Parameters

  • External source options will be deep-merged with passed by parameter.
AttributeTypeDefaultDescription
keystringBanner identity. It will be used as DOM element id, part of cookie name and passed as a query string for data requests
urlstringProvide an external options source. Must return a valid JSON body.
optionsobjectsee belowLocal options
hooks.onOptionsfunctionAfter getting and merging options, you can use this hook to modify them
hooks.onOpenfunctionSets banner to show or hide
hooks.onPrimaryfunctionTriggers when primary button is clicked. Native event passed
hooks.onSecondaryfunctionTriggers when secondary button is clicked. Native event passed

Options

example.json

KeyTypeDefaultDescription
enabledbooleantrueFirst thing checked in order to display our banner
titlestringSupport markdown without html, only rendered if exists
descriptionstringSupport markdown without html, only rendered if exists
positionstringbottomtop|bottom Banner display position
display.startDatedateBanner will be shown if current date is later than startDate, regardless of endDate
display.endDatedateBanner will be shown if current date is before endDate, regardless of startDate
display.modestringcookie|session Enables one-time banner display, storing a value in cookies or sessionStorage
buttons.primaryLinkstringPrimary button link, usually used as a confirm button
buttons.primaryTextstringPrimary button text, usually used as a confirm button as well
buttons.secondaryTextstringSecondary button text, normally used as a close button
themeClassstringbannery-default-themeRoot element class name used as a theme class name
cssstringcss string injected as a style tag
animationstringcss animation class name

🌐 Browser support

IE / EdgeFirefoxChromeSafari
Edge>= 52>= 59>= 11

🙌 Contributing

To learn how to setup a development environment and for contribution guidelines, see CONTRIBUTING.md.

🚧 Development

yarn install

// Compiles and hot-reloads for development
yarn serve

// Lints and fixes files
yarn lint

// Compiles and minifies for production
yarn build

📜 Changelog

We use GitHub releases.

🔐 Security

To report a security vulnerability, please use the Tidelift security contact.

📄 License

This project is licensed under the terms of the MIT license.