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​

The props type is exported as BoolProps, and the variant union as BoolVariant ("radio" | "radio-button" | "switch" | "checkbox").

PropTypeDefaultDescription
valueboolean—Controlled value
defaultValueboolean—Initial 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' | 'medium' | 'small'—Component size
classNamestring—CSS class
styleCSSProperties—Inline style
onChange(value: boolean) => void—Change handler
childrenReactNode—Label text (for switch / checkbox variants)

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 the Form field component, which handles value binding automatically:
<form.AppField name="isActive">
{(field) => <field.Bool label="Active" />}
</form.AppField>