Checkbox

General


Checkbox
Used for selecting multiple values from several options.

Show Code
import React from "react";
import Checkbox from "pocko-ui/Checkbox";
 
return (
  <div className="mt-4">
      <Checkbox
        id="demo1"
        name="demo1name"
        value="123"
        label="Label"
        onChange={(arg1: any, arg2: any) => {
            console.log(arg1, arg2);
        }}
      />
 
      <Checkbox
        id="demo1.1"
        name="demo1.1name"
        value="123"
        label="Label"
        onChange={(arg1: any, arg2: any) => {
            console.log(arg1, arg2);
        }}
        checked
      />
 
      <Checkbox
        id="demo1.2"
        name="demo1.2name"
        value="123"
        label="Label"
        onChange={(arg1: any, arg2: any) => {
            console.log(arg1, arg2);
        }}
        disabled
      />
  </div>
);

No spacing


Show Code
import React from "react";
import Checkbox from "pocko-ui/Checkbox";
 
return (
  <div className="mt-4">
      <Checkbox
        id="demo1"
        name="demo1name"
        value="123"
        label="Label"
        onChange={(arg1: any, arg2: any) => {
            console.log(arg1, arg2);
        }}
        wrapperClassName="m-0"
      />
 
      <Checkbox
        id="demo1.1"
        name="demo1.1name"
        value="123"
        label="Label"
        onChange={(arg1: any, arg2: any) => {
            console.log(arg1, arg2);
        }}
        wrapperClassName="m-0"
        checked
      />
  </div>
);

Using contentRef to Control the Checkbox Component


Show Code
import React from "react";
import Checkbox from "pocko-ui/Checkbox";
 
const checkboxRef = useRef<any>(null);
 
// Function to set the checkbox to checked
const handleSetCheckbox = () => {
  checkboxRef.current.set(true); // Set checkbox to checked
};
 
// Function to clear the checkbox (set it to unchecked)
const handleClearCheckbox = () => {
  checkboxRef.current.clear(); // Clear checkbox (set it to unchecked)
};
 
return (
  <div className="mt-4">
      <Checkbox
        contentRef={checkboxRef} // useRef
        value="checkbox1"
        label="Control Checkbox Externally"
      />
 
      <button
        type="button"
        className="btn btn-sm btn-warning me-2"
        onClick={handleSetCheckbox}
      >
        Check Checkbox
      </button>
 
      <button
        type="button"
        className="btn btn-sm btn-danger text-dark"
        onClick={handleClearCheckbox}
      >
        Uncheck Checkbox
      </button>
  </div>
  );

API


Checkbox
import Checkbox from "pocko-ui/Checkbox";
PropertyTypeDefaultDescriptionRequired
contentRefReact.ForwardedRef-Allows external components to operate on the component instance through a ref (e.g., clearing or setting values).-
wrapperClassNamestring-Custom class name for the control wrapper.-
formCheckClassNamestring-Custom class name for the form check box.-
controlClassNamestring-Custom class name for the checkbox itself.-
itemSelectedClassNamestring-Custom class name for the selected item.-
valuestring | boolean-The value of the control. Can be a string or boolean.
labelReact.ReactNode | string-The label content on the left of the checkbox. It can be a string or React node.-
idstring | number | any-The id of the control, used to associate the label and input elements.-
namestring | any-The name attribute of the control.-
checkedboolean-Controls whether the checkbox is checked or not.-
disabledbooleanfalseDisables the checkbox. If set to true, the checkbox cannot be clicked.-
styleReact.CSSProperties-Custom styles for the checkbox.-
onChange(arg_1: any, arg_2: any) => void-Callback function triggered when the checkbox state changes. It returns the checked state and current value.-