Checkbox
A headless Checkbox component for ReactLynx. It supports controlled/uncontrolled checked state and indeterminate mode.Info
You can check the source code to understand how it works, and you're welcome to submit PRs to enhance its capabilities.
Basic Usage
The most basic usage of the <Checkbox>
Examples
Indeterminate State
The indeterminate state is used when a <Checkbox> represents a group of options where some, but not all, are selected
Structure
Component API
Checkbox
checkboxPropsiOSAndroid
Checkbox supports original view props to be directly spread in this prop.
checkediOSAndroid
Whether the Checkbox is checked. If this property is set, the Checkbox will be in controlled mode, meaning the defaultChecked property will take no effects.
classNameiOSAndroidHarmony
className
defaultCheckediOSAndroid
Determines whether the Checkbox is checked by default. Use this property means the Checkbox is uncontrolled.
disablediOSAndroid
Disables the Checkbox. The Checkbox cannot be interacted with.
indeterminateiOSAndroid
The indeterminate state of the Checkbox.
onChangeiOSAndroid
The callback function that is triggered when the state changes
styleiOSAndroidHarmony
style
childreniOSAndroid
children
State-based styling & rendering
This component exposes runtime states through one or both of the following channels. The table lists only the channels available for each state:
- UI variant class — when supported, a class like
ui-<state>is toggled on the corresponding component node for selectors such as.ui-<state> { ... }. - Render-prop field — when supported and
childrenis a function, the state is passed in viachildren({ <state>: boolean, ... })for runtime-driven rendering.
UI variants applied by Checkbox based on its render state.
| Class Name | Render Prop | Type | Description |
|---|---|---|---|
| ui-active | active | boolean | Whether the checkbox is currently being pressed (and not disabled). Applied when `status.active` is true. |
| ui-checked | checked | boolean | Whether the checkbox is currently checked. Applied when `status.checked` is true. |
| ui-disabled | disabled | boolean | Whether the checkbox is disabled. Applied when `status.disabled` is true. |
| ui-indeterminate | indeterminate | boolean | Whether the checkbox is in an indeterminate state. Applied when `status.indeterminate` is true. |
CheckboxIndicator
childreniOSAndroid
The indicator of the Checkbox. Only displays child nodes when checked or indeterminate is true. If you need to keep it displayed when checked or indeterminate is false, set forceMount to true.
classNameiOSAndroidHarmony
className
forceMountiOSAndroid
Force mount the children. If set to true, the children will always be mounted even when checked or indeterminate is false.
styleiOSAndroidHarmony
style
UI variants applied by CheckboxIndicator.
| Class Name | Description |
|---|---|
| ui-active | Whether the checkbox is currently being pressed (and not disabled). Applied when `status.active` is true. |
| ui-checked | Whether the checkbox is currently checked. Applied when `status.checked` is true. |
| ui-disabled | Whether the checkbox is disabled. Applied when `status.disabled` is true. |
| ui-indeterminate | Whether the checkbox is in an indeterminate state. Applied when `status.indeterminate` is true. |