ConfirmButton
A two-step confirmation button for destructive or high-impact actions such as delete or publish.
import { ConfirmButton } from "@schukai/monster/source/components/form/confirm-button.mjs";Introduction
The Monster ConfirmButton adds a deliberate second step before an action is executed. Use it when deleting, resetting or publishing should require a short confirmation without opening a separate dialog.
When to use ConfirmButton
- Use it for destructive actions: Deleting data or clearing state are the classic cases.
- Use it for high-impact workflows: Publishing or sending irreversible updates can also benefit from confirmation.
- Do not use it for every button: Too many confirmation steps make interfaces slower and less trustworthy.
Typical mistakes
Reserve the pattern for actions with real cost. When confirmation is used for low-risk commands, users learn to click through it automatically and the safety benefit disappears.
Simple Confirm Button
This is a simple example of using the ConfirmButton component. It demonstrates how to create a basic button with a confirmation dialog box. The user must click the button and confirm the action in the dialog box to proceed.
Actions (provided through the button's functionality) allow dynamic configuration for both confirmation and cancellation actions. The button can also be customized with various configuration options for actions, labels, and Popper settings.
Javascript
import "@schukai/monster/source/components/form/confirm-button.mjs";HTML
<monster-confirm-button>
<div>Should I proceed?</div>
<div slot="button">click me!</div>
<div slot="confirm">Yes</div>
<div slot="cancel">No</div>
</monster-confirm-button>Stylesheet
/** no additional stylesheet is defined **/Component Design
This component is built using the Shadow DOM, which allows it to encapsulate its internal structure and styling. By using a shadow root, the component's internal elements are isolated from the rest of the webpage, ensuring that external styles or scripts cannot accidentally modify its internal layout or behavior.
Shadow DOM and Accessibility
Since the component is encapsulated within a shadow root, direct access to its internal elements is restricted. This ensures that developers cannot manipulate or style these elements from outside the component. The Shadow DOM helps maintain consistency in the design and behavior of the component by preventing external interference.
Customizing Through Exported Parts
While the Shadow DOM restricts direct access to the component's internal structure, customization is still possible through exported parts. Specific parts of the component are explicitly marked for export, allowing developers to target and style these parts using CSS without compromising the component's encapsulation.
Available Part Attributes
control: Represents the entire control area of the confirm button, including the dialog container.button: Represents the main trigger button of the confirm component.popper: Represents the dialog container where confirmation messages are displayed.message: Represents the text area inside the dialog displaying the confirmation message.confirm: Represents the confirm button inside the dialog.cancel: Represents the cancel button inside the dialog.
Below is an example of how to use CSS part attributes to customize different parts of the ConfirmButton component.
monster-confirm-button::part(control) {
background-color: #f0f0f0;
padding: 15px;
}
monster-confirm-button::part(button) {
color: white;
background-color: #007bff;
border-radius: 5px;
}
monster-confirm-button::part(confirm) {
background-color: #28a745;
color: white;
}
monster-confirm-button::part(cancel) {
background-color: #dc3545;
color: white;
}
Explanation of the Example
monster-confirm-button::part(control): Styles the entire control area, providing background and padding.monster-confirm-button::part(button): Styles the main trigger button with a background color and border radius.monster-confirm-button::part(confirm): Styles the confirm button with a green background and white text.monster-confirm-button::part(cancel): Styles the cancel button with a red background and white text.
Accessibility
Accessibility is a key consideration in the design of this component. By following best practices for web accessibility, the component ensures that users of all abilities can interact with it effectively. This includes support for keyboard navigation, screen readers, and other assistive technologies to provide an inclusive user experience.
HTML Structure
<monster-confirm-button></monster-confirm-button>JavaScript Initialization
const element = document.createElement('monster-confirm-button');
document.body.appendChild(element);Exported
ConfirmButtonDerived from
PopperButtonOptions
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 PopperButton.
- 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 PopperButton.
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 PopperButton.
Behavioral methods
hideDialog()showConfirmButtonMessage(message,timeout)message{string}: messagetimeout{number}: timeout
- {ConfirmButton}
showDialog()- {ConfirmButton}
Structural methods
setConfirmButtonState(state,timeout)state{string}: statetimeout{number}: timeout
- {ConfirmButton}
Static methods
[instanceSymbol]()2.1.0- {symbol}
instanceof operator.getCSSStyleSheet()- {Array}
getTag()- {string}
Lifecycle methods
Lifecycle methods are called by the environment and are usually not intended to be called directly.
[assembleMethodSymbol]()- {PopperButton}
Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.