Skip to Content
🎉 Coral x Panda has been released 🎉 Read the Migration Guide

AppBanner

An AppBanner is a molecule meant for use above the Header element to signpost people to download the Octopus App.

Basic Usage

import { AppBanner, AppBannerBody, AppBannerButton } from '@krakentech/coral-molecules'; <AppBanner open={true}> <AppBannerBody title="Octopus Energy App" content="GET - On the App Store" /> <AppBannerButton title="View" href="https://octopus.energy/app" /> </AppBanner>

Usage With State

The open prop is set to false by default, and should be set to true under the following circumstances:

  • If the customers userAgent matches either iPhone or Android (the two mobile operating systems that we support)
  • The customer has not previously dismissed the notice within the time-frame agreed with the global and regional marketing team

A full example of integration may look like this:

import { useEffect, useState } from 'react'; import { AppBanner as CoralAppBanner, AppBannerButton, AppBannerBody } from '@krakentech/coral-molecules'; export const AppBanner = () => { let [open, setOpen] = useState(false); let [content, setContent] = useState(''); let [href, setHref] = useState(''); let isMobileUA = false; let previouslyDismissed = false; useEffect(() => { // Android if (navigator.userAgent.match(/Android/i)) { setContent('GET - On the Play Store'); setHref( 'https://play.google.com/store/apps/details?id=energy.octopus.octopusenergy.android' ); isMobileUA = true; } // iOS else if (navigator.userAgent.match(/iPhone/i)) { setContent('GET - On the App Store'); setHref('https://apps.apple.com/{region}/app/octopus-energy/{id}'); isMobileUA = true; } const previouslyDismissedCookie = document.cookie.replace( /(?:(?:^|.*;\s*)octopus-app-banner-dismissed\s*\=\s*([^;]*).*$)|^.*$/, '$1' ); if (previouslyDismissedCookie !== '') { previouslyDismissed = true; } if (isMobileUA && !previouslyDismissed) { setOpen(true); } }, []); const onClose = () => { setOpen(false); let expiryDate = new Date(); expiryDate.setDate(expiryDate.getDate() + 90); document.cookie = `octopus-app-banner-dismissed=true; expires=${expiryDate}; path=/`; }; return ( <CoralAppBanner open={open} onClose={onClose}> <CoralAppBannerBody title="Octopus Energy App" content={content} /> <CoralAppBannerButton title="View" href={href} /> </CoralAppBanner> ); };

Full API

NameTypeDefault
onClose() => void
openResponsiveVariant<boolean>

Should the App Banner be visible? This should be based on wether the userAgent matches either iPhone or Android; and if the customer has not previously dismissed the notice.

false
childrenReactNode
Last updated on