import React, { useEffect, useRef } from 'react'; import DSHideThisPage from '@scottish-government/design-system/dist/scripts/components/hide-this-page/hide-this-page'; import { HideThisPageProps } from './types'; import clsx from 'clsx'; const HideThisPage = ({ className, escapeUrl = 'https://www.bbc.co.uk/weather', ...props }: HideThisPageProps) => { const ref = useRef(null); useEffect(() => { /* istanbul ignore else */ if (ref.current) { new DSHideThisPage(ref.current).init(); const HIDE_THIS_PAGE_DIV_ID = 'hide-this-page-instruction'; if (!document.getElementById(HIDE_THIS_PAGE_DIV_ID)) { const htpDiv = document.createElement('div'); htpDiv.id = HIDE_THIS_PAGE_DIV_ID; htpDiv.classList.add('visually-hidden'); htpDiv.classList.add('ds_hide-page'); htpDiv.innerHTML = '
To leave the page quickly, press the escape key.
'; document.body.prepend(htpDiv); } document.body.classList.add('ds_has-hide-page'); } }, [ref]); return (Or press Esc key