Interruptor Web Components
El componente Ignite UI for Web Components Switch es un componente de selección de elección binaria que se comporta de forma similar al componente switch de iOS.
Web Components Switch Example
Usage
At its core, the IgcSwitchComponent component allows for toggling between on/off states. The default styling is done according to the selection controls specification in the Material Design guidelines.
En primer lugar, debe instalar el Ignite UI for Web Components ejecutando el siguiente comando:
npm install igniteui-webcomponents
Entonces tendrás que importar elIgcSwitchComponent CSS necesario y su contenido, así:
import { defineComponents, IgcSwitchComponent } from "igniteui-webcomponents";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
defineComponents(IgcSwitchComponent);
Para una introducción completa al Ignite UI for Web Components, lee el tema Empezar.
La forma más sencilla de empezar a usar elIgcSwitchComponent uso es la siguiente:
<igc-switch></igc-switch>
[!WARNING] The
IgcSwitchComponentcomponent doesn't work with the standard<form>element. UseForminstead.
Examples
Label
Para proporcionar una etiqueta significativa para el cambio, simplemente coloque algo de texto entre las etiquetas de apertura y cierre:
<igc-switch>Label</igc-switch>
You can specify if the label should be positioned before or after the switch toggle by setting the labelPosition attribute of the switch. Allowed values are before and after(default):
<igc-switch label-position="before">Label</igc-switch>
El interruptor también puede estar etiquetado por elementos externos al interruptor. En este caso, el usuario tiene control total para colocar y diseñar la etiqueta de acuerdo con sus necesidades.
<span id="switch-label">Label</span>
<igc-switch aria-labelledby="switch-label"></igc-switch>
Checked
You can use the checked attribute to toggle on the switch.
<igc-switch checked></igc-switch>
Required
You can use the required attribute to mark the switch as required.
<igc-switch required></igc-switch>
Invalid
You can use the invalid attribute to mark the switch as invalid.
<igc-switch invalid></igc-switch>
Disabled
You can use the disabled attribute to disable the switch.
<igc-switch disabled></igc-switch>
Forms
You can use the name and value attributes when using the switch with Form.
<igc-switch name="wifi" value="enabled"></igc-switch>
Styling
ElIgcSwitchComponent componente expone varias partes CSS para darte control total sobre su estilo:
| Nombre | Descripción |
|---|---|
base |
El envoltorio base del switch. |
control |
El elemento de entrada del interruptor. |
thumb |
El indicador de posición del interruptor. |
label |
La etiqueta del interruptor. |
igc-switch::part(thumb) {
background-color: var(--ig-success-500);
box-shadow: none;
}
igc-switch::part(thumb checked) {
background-color: var(--ig-gray-50);
}
igc-switch::part(control checked) {
background-color: var(--ig-success-500);
}