React interruptor

    El componente Ignite UI for React Switch es un componente de selección de opciones binarias que se comporta de manera similar al componente switch en iOS.

    React Switch Example

    Usage

    En esencia, el componente IgrSwitch permite alternar entre estados de encendido y apagado. El estilo predeterminado se realiza de acuerdo con la especificación de controles de selección en las pautas de Material Design.

    Primero, debe instalar el paquete Ignite UI for React npm correspondiente ejecutando el siguiente comando:

    npm install igniteui-react
    

    Luego necesitarás importar IgrSwitch, su CSS necesario y registrar su módulo, así:

    import { IgrSwitchModule, IgrSwitch } from 'igniteui-react';
    import 'igniteui-webcomponents/themes/light/bootstrap.css';
    IgrSwitchModule.register();
    
    <IgrSwitch></IgrSwitch>
    

    [!WARNING] The IgrSwitch component doesn't work with the standard <form> element. Use IgrForm instead.

    Examples

    Label

    Para proporcionar una etiqueta significativa para el cambio, simplemente coloque algo de texto entre las etiquetas de apertura y cierre:

    <IgrSwitch><span>Label</span></IgrSwitch>
    

    Puede especificar si la etiqueta debe colocarse antes o después del interruptor configurando el atributo labelPosition del interruptor. Los valores permitidos son before y after (predeterminado):

    <IgrSwitch ariaLabelledby="switchLabel" labelPosition="Before" ><span id="switch-label">Label</span></IgrSwitch>
    

    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>
    <IgrSwitch ariaLabelledby="switchLabel"></IgrSwitch>
    

    Checked

    Puede utilizar el atributo checked para activar el interruptor.

    <IgrSwitch checked="true"></IgrSwitch>
    

    Required

    Puede utilizar el atributo required para marcar el cambio como requerido.

    <IgrSwitch required="true"></IgrSwitch>
    

    Invalid

    Puede utilizar el atributo invalid para marcar el cambio como no válido.

    Disabled

    Puede utilizar el atributo disabled para deshabilitar el interruptor.

    <IgrSwitch disabled="true"></IgrSwitch>
    

    Forms

    Puede utilizar los atributos name y value cuando utilice el modificador con IgrForm.

    <IgrSwitch name="wifi" value="enabled"></IgrSwitch>
    

    Styling

    El componente de cambio expone varias partes CSS (base, control, thumb y label) para brindarle control total sobre su estilo.

    igc-switch::part(control) {
      background: beige;
      border-radius: 0;
    }
    
    igc-switch::part(thumb) {
      background: olive;
      border-radius: 2px;
      box-shadow: none;
    }
    

    API References

    Additional Resources