Skip to main content

CheckBox Component

The CheckBox component is a versatile and customizable checkbox input designed for React Native applications. It combines functionality with flexibility, allowing developers to create interactive checkbox elements that can be easily integrated into forms, settings pages, or any part of the app requiring user confirmation or selection.

Key features include:

  • Customizable appearance (size, colors, styles)
  • Optional label with custom styling
  • Error message display capability
  • Accessibility support
  • Controlled and uncontrolled usage
  • Disable functionality

This component is built using React Native's core components and integrates with the Feather icon set for the checkmark, making it a lightweight yet powerful addition to any React Native project.

Props

PropTypeDefaultDescription
noMarginbooleanfalseIf true, removes the bottom margin of the checkbox container.
checkedStatusboolean-Controls the checked state of the checkbox.
valueboolean-Alternative prop to control the checked state.
containerStyleObject-Custom styles for the outermost container.
boxStyleObject-Custom styles for the checkbox box.
onValueChangeFunction-Callback function called when the checkbox state changes.
labelstring-Text label displayed next to the checkbox.
smallbooleanfalseIf true, renders a smaller checkbox.
activeColorstring'#212121'Color of the checkbox when checked.
labelStylesObject-Custom styles for the label text.
disablebooleanfalseIf true, disables the checkbox.
testIdstring-Test ID for the component.
errorstring-Error message to display below the label.

Usage

import { CheckBox } from "@appmaker-xyz/ui";

function MyComponent() {
const [isChecked, setIsChecked] = useState(false);

return (
<CheckBox
label="Accept terms and conditions"
checkedStatus={isChecked}
onValueChange={(newValue) => setIsChecked(newValue)}
activeColor="#007AFF"
error={isChecked ? null : "You must accept the terms to continue"}
/>
);
}

Styling

The component uses a combination of inline styles and a StyleSheet object for its appearance. You can customize the look by passing custom styles through the containerStyle, boxStyle, and labelStyles props.

Notes

  • The component uses both checkedStatus and value props to determine the checked state, with checkedStatus taking precedence.
  • The checkbox state is controlled internally but can also be controlled externally through the checkedStatus or value props.
  • Error messages are displayed in red below the label when the error prop is provided.