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:
getElementoptionsFullscreenable 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
getElementA 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.
statusFullscreenable instance. See the How methods affect status section for more information.elementgetElement. Can't be accessed until the DOM is available.errorundefined before the fullscreen or exit methods throw an error, and the error (Error) after any error is thrown.setGetElement(newGetElement)getElementgetElement (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:
readyfullscreenedexitederrored
Fullscreenable's status is pretty easy to predict:
- After the instance is constructed,
statuswill beready. - When the
fullscreenorentermethods are called,statuswill befullscreenedif the method is successful anderroredif it isn't. - When the
exitmethod is called,statuswill beexitedif the method is successful anderroredif 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.getElementsetGetElementset<Property> methodsstatus, element, errorfullscreen, enter, exitstop methodable