Fullscreenable
Updated on August 22, 2024Source codeTests
Fullscreenable
is a class that enriches an element, allowing it to:
- Asynchronously enter and exit full screen
- Store a status (
ready
,fullscreened
,exited
, orerrored
) - Store any error that gets thrown while entering or exiting full screen
Construct a Fullscreenable
instance
The Fullscreenable
constructor accepts two parameters:
getElement
options
Fullscreenable
instance. See the Fullscreenable
constructor options section for more guidance.Fullscreenable
constructor options
Fullscreenable
's options
object currently does not accept any options.
State and methods
getElement
A copy of the getElement
function passed to the constructor.
If you assign a value directly to getElement
, a setter will pass the new value to setGetElement
.
status
Fullscreenable
instance. See the How methods affect status section for more information.element
getElement
. Can't be accessed until the DOM is available.error
undefined
before the fullscreen
or exit
methods throw an error, and the error (Error) after any error is thrown.setGetElement(newGetElement)
getElement
getElement
(Array)Fullscreenable
instancefullscreen()
element
.Fullscreenable
instanceenter()
fullscreen
.Fullscreenable
instanceexit()
Fullscreenable
instanceHow methods affect status
Each Fullscreenable
instance maintains a status
property that keeps you informed of what's going on internally. As mentioned above, the value of status
is a string, and that string can be one of the following:
ready
fullscreened
exited
errored
Fullscreenable
's status is pretty easy to predict:
- After the instance is constructed,
status
will beready
. - When the
fullscreen
orenter
methods are called,status
will befullscreened
if the method is successful anderrored
if it isn't. - When the
exit
method is called,status
will beexited
if the method is successful anderrored
if it isn't.
Using with TypeScript
The Fullscreenable
constructor accepts one generic type that you can use to enforce a type for the element returned by getElement
. By default, TypeScript will infer the element type from the initial getElement
function you pass to the constructor, but you can specify the type manually if needed.
const withInferredTypes = new Fullscreenable(() => document.querySelector('button'))
withInferredTypes.getElement = () => document.querySelector('input') // Type error
const withManualTypes = new Fullscreenable<HTMLInputElement | HTMLButtonElement>(() => document.querySelector('button'))
withManualTypes.getElement = () => document.querySelector('input') // No type error
API design compliance
options
object.options
object doesn't currently have any valid properties.getElement
setGetElement
set<Property>
methodsstatus
, element
, error
fullscreen
, enter
, exit
stop
methodable