garage44.eu/jeroen/midas

logclone: git clone https://garage44.eu/jeroen/midas.git

.. /web/src/components/fullscreen.tsx

raw

import m from '@garage44/mithril'

// The page follows the browser's own leaving of full screen (Esc, a back gesture).
document.addEventListener('fullscreenchange', () => m.redraw())

/**
 * Full screen and back, for a phone's browser bars. A browser that cannot
 * (Safari on an iPhone gives it only to videos) shows no button.
 */
export function fullscreenButton(): m.Vnode | null {
    if (!document.fullscreenEnabled) return null
    const on = !!document.fullscreenElement
    return (
        <button
            type="button"
            class="frame__icon"
            title={on ? 'Leave full screen' : 'Full screen'}
            aria-label={on ? 'Leave full screen' : 'Full screen'}
            onclick={() => void (on ? document.exitFullscreen() : document.documentElement.requestFullscreen()).catch(() => {})}
        >
            <svg viewBox="0 0 16 16" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
                {on ? <path d="M6 2.5V6H2.5M10 2.5V6h3.5M6 13.5V10H2.5M10 13.5V10h3.5" /> : <path d="M2.5 6V2.5H6M13.5 6V2.5H10M2.5 10v3.5H6M13.5 10v3.5H10" />}
            </svg>
        </button>
    )
}