Switch

General


Show Code
import React from "react";
import Switch from 'funda-ui/Switch';
 
export default () => {
 
    function handleChange(e, val) {
        console.log(e.target, val);
    }
 
    return (
        <>
 
		<Switch 
            label="Default switch"
            name="switch-name-1" 
            value="ok"
            onChange={handleChange} 
        />
 
        <Switch
            label="Checked switch"
            name="switch-name-2"
            value="ok"
            checked
        />
        <Switch
            label="Disabled switch"
            name="switch-name-3"
            value="ok"
            disabled
        />
 
        <Switch
            label='&nbsp;'
            name="switch-name-2"
            value="ok"
        />
 
        
 
        </>
    );
}

No spacing


Show Code
import React from "react";
import Switch from 'funda-ui/Switch';
 
export default () => {
 
 
    return (
        <>
 
            <Switch
                ...
                wrapperClassName="position-relative"
                ...
            />
 
             <Switch
                ...
                wrapperClassName=""
                ...
            />
 
        </>
    );
}

Asynchronous Usage


checked  |  unchecked
Show Code
import React, { useState } from "react";
import Switch from 'funda-ui/Switch';
 
export default () => {
 
    const [checked, setChecked] = useState<any>(null);
   
    function handleClick1(e: any) {
        e.preventDefault();
        setChecked(true);
    }
 
    function handleClick2(e: any) {
        e.preventDefault();
        setChecked(false);
    }  
 
    return (
        <>
 
            <a href="#" onClick={handleClick1}>checked</a>
            <a href="#" onClick={handleClick2}>unchecked</a>
            
            <Switch
                label='Label'
                name="switch-name-1" 
                value="ok"
                checked={checked}
            />
            
 
        </>
    )
}

API

Switch

import Switch from 'funda-ui/Switch';
PropertyTypeDefaultDescriptionRequired
refReact.ForwardedRef-It is the return element of this component.-
wrapperClassNamestringmb-3 position-relativeThe class name of the control wrapper.-
controlClassNamestringform-check-inputThe class name of the control.-
checkedbooleanfalseIs it selected.-
valuestring-Set a default value for this control. If unchecked, it will pass an empty value
labelstring | ReactNode-It is used to specify a label for an element of a form.
Support html tags
-
namestring-Name is not deprecated when used with form fields.-
disabledbooleanfalseWhether it is disabled-
requiredbooleanfalseWhen present, it specifies that a field must be filled out before submitting the form.-
onChangefunction-Call a function when the value of an HTML element is changed. It returns two callback values.
  1. The first is the Control Event (Event)
  2. The second is the value (Boolean)
-
onBlurfunction-Call a function when a user leaves an form field. It returns only one callback value which is the Control Event (Event)-
onFocusfunction-Call a function when an form field gets focus. It returns only one callback value which is the Control Event (Event)-

It accepts all props which this control support. Such as style, data-*, tabIndex, id, and so on.