Message
A single notification message element, typically rendered inside the notify container.
import { Message } from "@schukai/monster/source/components/notify/message.mjs";Introduction
The Monster Message component is the individual notification unit inside a notify stack. Use it when one specific success, warning, info or error message should be presented with clear visual priority.
When to use Message
- Use it for one explicit notification: Each message should communicate one clear outcome or status.
- Use it inside a notification system: The component is strongest as part of a managed notify container.
- Do not use it as a page banner replacement everywhere: Persistent layout messages often want a different pattern.
Message
In this example, a message is displayed within the context of a notification container. For more details about the container, visit the notification container page.
Javascript
import '@schukai/monster/source/components/notify/notify.mjs';
const notify = document.querySelector('monster-notify');
notify.push(`This is a message`);<script type="module">import '@schukai/monster/source/components/notify/notify.mjs';
const notify = document.querySelector('#uh8Oh');
notify.push(`This is a message`);</script>HTML
<div>
<monster-notify></monster-notify>
</div>Stylesheet
/** no additional stylesheet is defined **/Component Design
The Message component is a child element of the Notify component, designed to display individual notification messages. It uses the Shadow DOM to encapsulate its structure and styling, ensuring isolation and consistency across different environments.
Each message consists of a content area and an optional close button, both of which can be styled and customized using exported parts and CSS variables.
Shadow DOM and Accessibility
The use of the Shadow DOM ensures that the internal structure of the Message component is isolated from external styles or scripts. This prevents unintended interference and maintains design integrity.
Accessibility is prioritized in the component's design. The close button is keyboard-navigable and provides semantic attributes to support screen readers and assistive technologies.
Customizing Through Exported Parts
The Message component allows customization of specific areas through exported parts. These parts enable developers to style the content and close button independently, while keeping the internal structure encapsulated.
Available Part Attributes
control: The main container for the message.message: The area that holds the entire message content and controls.content: The specific part for the message's textual content.remove: The close button for dismissing the message.
Example of customizing the message using CSS:
monster-notify-message::part(control) {
background-color: #f9f9f9;
padding: 12px;
border-radius: 8px;
}
monster-notify-message::part(content) {
font-size: 14px;
color: #333;
}
monster-notify-message::part(remove) {
width: 18px;
height: 18px;
background-color: #ff5555;
border-radius: 50%;
}
CSS Variables
The Message component provides a variety of CSS variables for flexible customization. These variables allow developers to adjust the design and appearance of the component without modifying its internal structure.
--monster-bg-color-primary-1: Sets the background color of the message.--monster-color-primary-1: Sets the text color of the message content and close button.--monster-z-index-modal-overlay: Adjusts the stacking order of the close button.
Example of using CSS variables to customize the design:
monster-notify-message {
--monster-bg-color-primary-1: #fffaf0;
--monster-color-primary-1: #444444;
--monster-z-index-modal-overlay: 1050;
}
Accessibility
The Message component supports accessibility through semantic structure and focusable controls. The close button is designed to be both keyboard and mouse accessible, and the content area supports text selection to enhance usability for all users.
HTML Structure
<monster-message></monster-message>JavaScript Initialization
const element = document.createElement('monster-message');
document.body.appendChild(element);Exported
MessageDerived from
CustomElementOptions
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.
- 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
getCSSStyleSheet()- {CSSStyleSheet[]}
getTag()- {string}
Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()- {Monster.Components.Notify.Message}
[initMethodSymbol]()connectedCallback()- {void}
disconnectedCallback()- {void}
Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.