SaveButton

This is a save button component that can be used to save changes to a datasource.

Import
the javascript logo
import { SaveButton } from "@schukai/monster/source/components/datatable/save-button.mjs";
Source
the git logo
Package
the npm logo
Since
1.0.0

Introduction

The Save Button is a versatile web component. More than just a simple UI element, this component serves as a key element for managing and saving changes to data sources in various web applications. Whether you are developing a basic website or a complex enterprise-level application, this component is designed to improve user interaction and satisfaction by providing intuitive data-saving functionality.

Key Features

  • Dynamic interaction: Users can dynamically interact with the data source, making the web experience more intuitive and efficient.
  • Customizable appearance: Customize the appearance of the save button and badge to match the design of your brand or application, ensuring visual consistency.
  • Accessibility: Designed with accessibility in mind to ensure that all users can save data seamlessly, regardless of their browsing environment.
  • Visual feedback effect: Provides clear visual feedback, such as badges indicating unsaved changes, to enhance user interaction and responsiveness.
  • Programmatic Control: Offers programmatic methods for advanced use cases, allowing developers to trigger, enable, or disable the save functionality dynamically.

Improving the user experience

The Save Button goes beyond its traditional functionality to offer an enhanced and interactive user experience. Its integration with data sources, visual feedback effects, and dynamic interaction capabilities ensure that users can clearly see and control their changes, making the web environment more intuitive and user-friendly.

These improvements are supported by studies and feedback that highlight a significant boost in user engagement and satisfaction when intuitive save mechanisms are implemented.

Efficiency in the development process

Integrating the Save Button component into your development process is straightforward. Its compatibility with standard web technologies and ease of customization ensure seamless integration with your existing tools and libraries. Whether you're working on a small project or a large-scale application, the modular design of this component guarantees easy integration, streamlining your development process and enhancing productivity.

Simple Example

In this example, a simple data source is used and the value is adjusted after loading.

Javascript

import '@schukai/monster/source/components/datatable/save-button.mjs';

// simulate a data change
setTimeout(() => {
    const ds = document.querySelector('#myDataSource');
    ds.data = [];
}, 5000);

HTML

<monster-datasource-save-button data-monster-option-datasource-selector="#myDataSource"></monster-datasource-save-button>

<monster-datasource-rest id="myDataSource"
                         data-monster-option-features-autoInit="true"
                         data-monster-option-write-url="/assets/examples/countries.json"
                         data-monster-option-read-url="/assets/examples/countries.json?page=${page}"
></monster-datasource-rest>

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 means 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 made accessible for styling by being explicitly marked for export. These exported parts can be targeted and customized using CSS, allowing you to modify the appearance of the component without compromising its encapsulation.

Available Part Attributes

  • control: This part represents the entire control area of the save button, including the button and the badge. Use this to style the general layout and background of the control panel.
  • state-button: Represents the save button, allowing styling for various states such as "changed" or "disabled".
  • badge: Represents the badge indicating the number of unsaved changes.

Below is an example of how to use CSS part attributes to customize different parts of the component.


monster-datasource-save-button::part(state-button) {
    background-color: #4CAF50;
    color: white;
}
monster-datasource-save-button::part(badge) {
    background-color: red;
    color: white;
    border-radius: 50%;
}

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-save-button></monster-save-button>

JavaScript Initialization

const element = document.createElement('monster-save-button');
document.body.appendChild(element);

Exported

SaveButton

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
undefined
Template definitions
templates.main
string
undefined
Main template
datasource
object
undefined
The datasource
datasource.selector
string
undefined
The selector of the datasource
labels.button
string
undefined
The button label
classes
object
undefined
The classes
classes.bar
string
undefined
The bar class
classes.badge
string
undefined
The badge class
ignoreChanges
array
undefined
The ignore changes (regex)
data
array
undefined
The data
disabled
boolean
undefined
The disabled state
logLevel
string
undefined
The log level (off, debug)

  • 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]()
Returns
  • {symbol}
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]()
This method is responsible for assembling the component. It calls the parent's assemble method first, then initializes control references and event handlers. If the datasource.selector option is provided and is a string, it searches for the corresponding element in the DOM using that selector. If the selector matches exactly one element, it checks if the element is an instance of the Datasource class. If it is, the component's datasourceLinkedElementSymbol property is set to the element, and the component attaches an observer to the datasource's changes. The observer is a function that calls the handleDataSourceChanges method in the context of the component. Additionally, the component attaches an observer to itself, which also calls the handleDataSourceChanges method in the component's context.

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.