FullScreen

A beautiful FullScreen that can make your life easier and also looks good.

Import
the javascript logo
import { FullScreen } from "@schukai/monster/source/components/layout/full-screen.mjs";
Source
the git logo
Package
the npm logo
Since
4.10.0
Behold! A realm of pixels that shall transcend its mortal bounds into full-screen magnificence - just activate the sacred icon to witness this digital transformation!

Introduction

The monster-full-screen component provides a user-friendly way to toggle fullscreen mode on any HTML element. This component enhances user engagement by allowing immersive viewing experiences, particularly useful in media, data visualization, and presentation interfaces. Its integration supports a wide range of use cases, from basic interfaces to complex application layouts.

Key Features

  • Fullscreen toggle: Easily switch any target element in and out of fullscreen mode using a simple control interface.
  • Encapsulated control logic: The logic for managing fullscreen state is fully encapsulated within the component, requiring minimal configuration.
  • Customizable interface: The appearance of the toggle buttons can be customized through exported parts, ensuring it aligns with your application’s style.
  • Accessible by design: Designed with accessibility considerations, including appropriate role attributes and dynamic visual state changes.
  • Visual icon feedback: Clearly indicates whether fullscreen is active or not via intuitive SVG icons.

Improving the user experience

The monster-full-screen component improves user interaction by making fullscreen functionality available without additional scripting. It provides immediate visual feedback during state transitions and maintains a consistent control layout across devices and browsers.

These improvements simplify user navigation and support an immersive experience, especially in scenarios where content focus and distraction-free display are critical.

Efficiency in the development process

Integrating the monster-full-screen component is simple and effective. It works with standard HTML and JavaScript, does not require external dependencies, and adheres to Monster.js conventions. Developers can configure it declaratively via attributes and benefit from its modular design, which promotes reuse and maintainability across applications of any size.

Full Screen Simple

This example demonstrates the use of the monster-full-screen component to enable fullscreen mode for a specific content area. The component is positioned absolutely above the target container and configured to toggle fullscreen on the element with the ID #full-site-content. When the fullscreen icon is clicked, the entire content block—containing a message and any additional elements—expands to occupy the entire screen. This allows users to focus on the content without distractions from the rest of the page.

The data-monster-option-selector attribute is used to bind the fullscreen control to a specific DOM element. In this case, it references #full-site-content, making this the element that enters and exits fullscreen mode. The absolute positioning ensures the toggle button appears visually aligned with the intended layout.

Behold! A realm of pixels that shall transcend its mortal bounds into full-screen magnificence - just activate the sacred icon to witness this digital transformation!

Javascript

import '@schukai/monster/source/components/layout/full-screen.mjs';

HTML

<div id="full-site-content" style="position: relative;">
    Behold! A realm of pixels that shall transcend its mortal bounds into full-screen
    magnificence - just activate the sacred icon to witness this digital transformation!
    <monster-full-screen style="position: absolute;
    top: -60px;
    right: 120px;" data-monster-option-selector="#full-site-content"></monster-full-screen></div>

Stylesheet

/** no additional stylesheet is defined **/

Component Design

This component is implemented using the Shadow DOM, which provides a scoped encapsulation of its internal elements and styles. The use of a shadow root ensures that the internal structure remains unaffected by external styles or scripts.

Shadow DOM and Accessibility

The Shadow DOM encapsulation restricts direct access to the internal elements of the component. As a result, developers cannot modify or style these internal elements from outside. This encapsulation supports predictable behavior and protects the component from unintended external influences.

Customizing Through Exported Parts

To allow styling flexibility while maintaining encapsulation, the component exports certain internal elements via part attributes. These exported parts can be targeted using the ::part() CSS pseudo-element, making it possible to apply custom styles without modifying the component's internal template.

Available Part Attributes

  • control: The outer container element that wraps both fullscreen toggle buttons. Use this to style the control block layout or background.
  • fullscreen: The element that represents the “enter fullscreen” button. It is visible when the page is not in fullscreen mode.
  • fullscreen-exit: The element that represents the “exit fullscreen” button. It is shown only when the component is in fullscreen mode.

Below is an example of how to style these exported parts using CSS:


monster-full-screen::part(control) {
    background-color: #f8f8f8;
    padding: 0.5rem;
    display: flex;
    justify-content: center;
}

monster-full-screen::part(fullscreen) {
    color: green;
    cursor: pointer;
}

monster-full-screen::part(fullscreen-exit) {
    color: red;
    cursor: pointer;
}

Explanation of the Example

  • monster-full-screen::part(control): Applies background color, padding, and centers the control's content.
  • monster-full-screen::part(fullscreen): Styles the "enter fullscreen" icon with green color and cursor pointer.
  • monster-full-screen::part(fullscreen-exit): Styles the "exit fullscreen" icon with red color and cursor pointer.

Accessibility

This component follows web accessibility standards to ensure usability by all users, including those using assistive technologies. It includes support for semantic roles, keyboard interaction, and screen reader compatibility. The fullscreen toggle is activated via a button that responds to click events and reflects changes using visually distinct icons.

HTML Structure

<monster-full-screen></monster-full-screen>

JavaScript Initialization

const element = document.createElement('monster-full-screen');
document.body.appendChild(element);

Exported

FullScreen

Derived from

CustomElement

Options

The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomElement.

Option
Type
Default
Description
templates
object
Template definitions
templates.main
string
undefined
Main template
selector
string
:first-child
Selector for the control

  • since
  • deprecated

Properties and Attributes

The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomElement.

  • data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.
  • data-monster-option-[name]: Sets the value of the configuration option [name] for the collapse component when used as an HTML attribute.

Methods

The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomElement.

Static methods

[instanceSymbol]()
This method is called by the instanceof operator.
getCSSStyleSheet()
Returns
  • {CSSStyleSheet[]}
getTag()
Returns
  • {string}

Lifecycle methods

Lifecycle methods are called by the environment and are usually not intended to be called directly.

[assembleMethodSymbol]()
Returns
  • {Components.Layout.FullScreen

Events

This component does not fire any public events. It may fire events that are inherited from its parent classes.

The current width of the area is too small to display the content correctly.