Skip to main content

Bool

A boolean value display and input component with multiple visual variants.

VEF-specific component. Not part of Ant Design.

When to Use

  • Display or edit a boolean (true/false) value in a form or table.
  • When you want to switch between radio, radio-button, switch, or checkbox presentation without changing the data model.

Basic Usage

import { Bool } from '@vef-framework-react/components';

export default function Demo() {
return (
<Bool
value={true}
onChange={(val) => console.log(val)}
/>
);
}

Default variant is "switch".

Variants

import { Bool, Space } from '@vef-framework-react/components';
import { useState } from 'react';

export default function Demo() {
const [val, setVal] = useState(true);

return (
<Space direction="vertical">
<Bool variant="switch" value={val} onChange={setVal} />
<Bool variant="radio" value={val} onChange={setVal} />
<Bool variant="radio-button" value={val} onChange={setVal} />
<Bool variant="checkbox" value={val} onChange={setVal}>
Enable feature
</Bool>
</Space>
);
}

Custom Labels

<Bool
variant="radio"
value={true}
trueLabel="Yes"
falseLabel="No"
onChange={(val) => console.log(val)}
/>

Read-only Display

// Disabled + no onChange = display-only
<Bool value={record.isActive} disabled />

API

PropTypeDefaultDescription
valuebooleanControlled value
defaultValuebooleanInitial value (uncontrolled)
variant'switch' | 'radio' | 'radio-button' | 'checkbox''switch'Visual variant
trueLabelReactNode'是'Label for true state
falseLabelReactNode'否'Label for false state
disabledbooleanfalseDisable interaction
size'large' | 'middle' | 'small'Component size
classNamestringCSS class
styleCSSPropertiesInline style
onChange(value: boolean) => voidChange handler
childrenReactNodeLabel text (for checkbox variant)

Variant Behavior

VariantTrue StateFalse State
switchSwitch on, shows trueLabel insideSwitch off, shows falseLabel inside
radioFirst radio selectedSecond radio selected
radio-buttonFirst button activeSecond button active
checkboxCheckedUnchecked

Best Practices

  • Use variant="switch" for settings toggles.
  • Use variant="radio" or variant="radio-button" in forms where both options should be visible.
  • Use variant="checkbox" with children for inline consent or feature flags.
  • In forms, use form.Field.Bool which handles value binding automatically.