fast-switch
An implementation of a switch as a form-connected web-component.
Setup
Basic setup
import {
provideFASTDesignSystem,
fastSwitch
} from "@microsoft/fast-components";
provideFASTDesignSystem()
.register(
fastSwitch()
);
Customizing the Indicator
import {
provideFASTDesignSystem,
fastSwitch
} from "@microsoft/fast-components";
provideFASTDesignSystem()
.register(
fastSwitch({
switch: `...your switch indicator...`
})
);
Usage
Live Editor
<fast-switch> Theme <span slot="checked-message">Dark</span> <span slot="unchecked-message">Light</span> </fast-switch>
Result
Loading...
Create your own design
import {
Switch,
SwitchOptions,
switchTemplate as template,
} from "@microsoft/fast-foundation";
import { switchStyles as styles } from "./my-switch.styles";
export const mySwitch = Switch.compose<SwitchOptions>({
baseName: "switch",
template,
styles,
switch: `...default switch indicator...`,
});
API
class: Switch
Superclass
Name | Module | Package |
---|---|---|
FormAssociatedSwitch | /src/switch/switch.form-associated.js |
Fields
Name | Privacy | Type | Default | Description | Inherited From |
---|---|---|---|---|---|
readOnly | public | boolean | When true, the control will be immutable by user interaction. See readonly HTML attribute for more information. | ||
proxy | FormAssociatedSwitch | ||||
$presentation | public | ComponentPresentation or null | A property which resolves the ComponentPresentation instance for the current component. | FoundationElement | |
template | public | ElementViewTemplate or void or null | Sets the template of the element instance. When undefined, the element will attempt to resolve the template from the associated presentation or custom element definition. | FoundationElement | |
styles | public | ElementStyles or void or null | Sets the default styles for the element instance. When undefined, the element will attempt to resolve default styles from the associated presentation or custom element definition. | FoundationElement |
Methods
Name | Privacy | Description | Parameters | Return | Inherited From |
---|---|---|---|---|---|
templateChanged | protected | void | FoundationElement | ||
stylesChanged | protected | void | FoundationElement |
Events
Name | Type | Description | Inherited From |
---|---|---|---|
change | Emits a custom change event when the checked state changes |
Attributes
Name | Field | Inherited From |
---|---|---|
readonly | readOnly |
CSS Parts
Name | Description |
---|---|
label | The label |
switch | The element representing the switch, which wraps the indicator |
status-message | The wrapper for the status messages |
checked-message | The checked message |
unchecked-message | The unchecked message |
Slots
Name | Description |
---|---|
The deafult slot for the label | |
checked-message | The message when in a checked state |
unchecked-message | The message when in an unchecked state |