Checkbox component is used to create interactive checkbox inputs with customizable styling and validation support. It's ideal for optional selections, agreements, settings, and multiple choice lists.tsx
import { Checkbox } from "@arkyn/components";
name property.tsx
<Checkbox name="basic-checkbox" />
sm, md and lg, offering different dimensions to suit your layout needs.tsx
<Checkbox name="checkbox-sm" label="Small checkbox" size="sm" /><Checkbox name="checkbox-md" label="Medium checkbox" size="md" /><Checkbox name="checkbox-lg" label="Large checkbox" size="lg" />
tsx
<Checkbox name="terms" label="I accept the terms and conditions" />
tsx
<Checkbox name="option1" label="Option 1" orientation="horizontal" /><Checkbox name="option2" label="Option 2" orientation="horizontal" />
tsx
<Checkbox name="option1" label="Option 1" /><Checkbox name="option2" label="Option 2" />
tsx
<Checkbox name="option1" label="Option 1" orientation="vertical" /><Checkbox name="option2" label="Option 2" orientation="vertical" />
tsx
<Checkbox name="remember-me" label="Remember me" defaultChecked={true} />
tsx
<Checkboxname="disabled-unchecked"label="Disabled option (unchecked)"disabled/><Checkboxname="disabled-checked"label="Disabled option (checked)"disableddefaultChecked/>
errorMessage property, it will take precedence over messages from the form provider.tsx
<Checkboxname="invalid-terms"label="I accept the terms and conditions"errorMessage="You must accept the terms"showAsterisk/>
value property to define a specific value when the checkbox is checked.tsx
<Checkboxname="subscription-basic"label="Basic Plan"value="basic"onCheck={(value) => alert("Selected plan:" + value)}/>
onCheck callback provides the checkbox value when checked or an empty string when unchecked:tsx
function handleCheckboxChange(value: string) {// value: string - value defined in the value prop or "checked" if not specified// For unchecked checkbox, value will be an empty string ""if (value) {alert("Checkbox checked with value:" + value); // "subscribeNewsletter"} else {alert("Checkbox unchecked"); // ""}}<Checkboxname="newsletter"label="Receive newsletter"value="subscribeNewsletter"onCheck={handleCheckboxChange}/>;
tsx
const [isPremium, setIsPremium] = useState(true);<Checkboxname="controlled-premium"label="Premium features"checked={isPremium}onCheck={(value) => setIsPremium(!!value)}/>;
name - string (required)
Field name for form manipulation and identificationlabel - string
Label text to be displayed next to the checkboxerrorMessage - string
Error message to display below the checkboxshowAsterisk - boolean
Whether to display an asterisk in the label for required fieldssize - "sm" | "md" | "lg" (default: "md")
Checkbox size variantorientation - "horizontal" | "horizontalReverse" | "vertical" (default: "horizontal")
Orientation of the checkbox and labelvalue - string (default: "checked")
Optional value to be used when the checkbox is checkedchecked - boolean
Controlled checked state of the checkboxdefaultChecked - boolean (default: false)
Default checked state for uncontrolled useonCheck - (value: string) => void
Callback function called when the checkbox state changes, receives the value or empty string<button> are also supported, except type, name, defaultValue, value, onChange, onSelect and onClick which are controlled by the component.checked for controlled state and defaultChecked for uncontrolledonCheck callback receives string (value or "") instead of boolean