Skip to content

Checkbox

ECheckbox enables users to pick an option by ticking a checkbox to indicate their preference, and toggle between checked, unchecked, and optional indeterminate states. Demo Here

Import

jsx
import ECheckbox from "@components/Form/ECheckbox";

Usage

jsx
const CheckboxExample = () => {
    const [isChecked, setIsChecked] = useState(false);

    const toggleCheckbox = () => {
        setIsChecked((prevState) => !prevState);
    };

    return (
        <ECheckbox isChecked={isChecked} onChange={toggleCheckbox}>
            Checkbox
        </ECheckbox>
    );
};

export default CheckboxExample;

Props

For ECheckbox component, the following props are available:

PropTypeDefaultNote
idString-HTML id attribute.
disabledBooleanfalseDisables the ECheckbox content.
messageString-Adds a message below the checkbox.
isCheckedBoolean-If true, the element is checked.
trueValueString-Value of the checkbox if it's checked.
falseValueString-Value of the checkbox if it's unchecked.
classNameString-Overrides or extends the component's styles.
validateOnString"input"Triggers validation on @values: submit, input.
nameString-HTML name attribute.
rulesArray-Validation rules. For more info refer to Form Validation.
sizeString"md"The ECheckbox element has three predefined sizes: sm, md, lg.
indeterminateBooleanfalseDisplays a state separate from either checked or unchecked. It only controls the style.
trueIconObject-Displays a true icon when the checkbox is checked. More Info here.
falseIconObject-Displays a false icon when the checkbox is unchecked. More Info here.
colorString"primary"The given color is applied to the element - utility colors are supported (e.g primary or danger). you'll find a list of built-in classes on the src/styles/_vars.scsspage.
stateString-Validates the user-provided data against established criteria and performs display validation. States can be none if no validation is necessary, danger if the selected is valid, or success if it is acceptable.
squareBooleanfalseRemoves rounded corners of the element.
infoString-Adds an info to the checkbox.

Callback Functions

The ECheckbox component contains following callback functions.

FunctionDescription
onChangeControls the checked status of the element. function(event: React.SyntheticEvent, isChecked: Boolean) => void 👇

event: The event source of the callback.
isChecked: current value.

Children

The ECheckbox component provides a children props that enable you to customize the content.

ChildrenDescription
✔️Component's content.

COPYRIGHT