Switch
<msc-switch /> is a web component designed in accordance with Material Design principles.
By simply wrapping an input[type=checkbox][switch] element within it, developers can instantly implement the corresponding user interface and interactions. This component plays a vital role in ensuring a unified appearance and consistent behavior across elements.
Let's see what can <msc-switch /> do ?
Basic Usage
<msc-switch /> is a web component. All we need to do is put the required script into your HTML document. Then follow <msc-switch />'s html structure and everything will be all set.
Required Script
Structure
Put <msc-switch /> into HTML document. It will have different functions and looks with attribute mutation.
<msc-switch /> dynamically adjusts its user interface and core functionality by strictly adhering to the attributes of the encapsulated input[type-checkbox][switch] element. Developers can leverage these capabilities and observe the corresponding behavioral shifts by modifying the standard disabled attribute directly on the input element.
JavaScript Instantiation
<msc-switch /> could also use JavaScript to create DOM element. Here comes some examples.
Style Customization
Developers could apply styles to decorate <msc-switch />'s looking.
Attribute
<msc-switch /> component exposes a curated set of attributes, enabling developers to dynamically adjust the user interface. This provides the flexibility to tailor the component’s appearance to seamlessly adapt to any given context.
appearance
The appearance of <msc-switch /> can be customized using the appearance attribute. The component currently supports the following three options:
- none:Hides the icon display. This is the default setting.
- selectedonly:Displays the icon only when the <msc-switch /> is in the selected state.
- always:Displays the icon at all times, regardless of the selected state.
Propertiy
| Property Name | Type | Description |
|---|---|---|
appearance
|
String | Getter / Setter for appearance. The <msc-switch /> can be customized using this property. It supports three values—none, selectedonly, and always—aligning directly with the behavior of the corresponding attribute. The default value is none. |