Deprecated as of Novemeber 2024. Please use New Library(B_Block v2.0)

Check Box Component

Check Box component that can be used to render a custom check box and receive input from the user.

Props

PropertyTypeDescription
classNamestringThe CSS class name of the element.
idanyThe unique identifier of the element.
labelstringThe text to display as the label for the element.
namestringThe name of the element.
disabledbooleanWhether the element is disabled or not.
onChange(event: ChangeEvent<HTMLInputElement>) => voidThe function to call when the value of the element changes.
modestringThe mode in which the element is displayed.
checkedbooleanWhether the element is checked or not (for checkboxes and radio buttons).
indeterminatebooleanWhether the element is in an indeterminate state or not (for checkboxes).

Usage

Here's an example of how to use the Check Box component:

Functional Component
App.tsx
import React, { useState } from 'react';
import { CheckBox } from 'gbs-fwk-buildingblock';
 
function App() {
  const [checked, setChecked] = useState(false);
 
  const handleCheck = (event: any) => {
    setChecked(event.checked);
  };
 
  return (
    <div>
      <CheckBox label="Check me" checked={checked} OnChange={handleCheck} />
      <p>Checked: {checked ? 'Yes' : 'No'}</p>
    </div>
  );
}
 
export default CheckBox;
Class Component
App.tsx
import React from 'react';
import { CheckBox } from 'gbs-fwk-buildingblock';
 
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { checked: false };
    this.handleCheck = this.handleCheck.bind(this);
  }
 
  handleCheck(event) {
    this.setState({ checked: event.checked });
  }
 
  render() {
    return (
      <div>
        <CheckBox
          label="Check me"
          checked={this.state.checked}
          OnChange={this.handleCheck}
        />
        <p>Checked: {this.state.checked ? 'Yes' : 'No'}</p>
      </div>
    );
  }
}
 
export default CheckBox;