Components
- AccordionNew
- Alert
- Alert DialogNew
- AutocompleteNew
- AvatarNew
- Badge
- Breadcrumb
- Button
- CalendarNew
- CardNew
- Checkbox
- Checkbox GroupNew
- CollapsibleNew
- ComboboxNew
- CommandNew
- Context MenuNew
- Date PickerNew
- DialogNew
- DrawerNew
- EmptyNew
- FieldNew
- FieldsetNew
- FormNew
- FrameNew
- GroupNew
- Input
- Input GroupNew
- KbdNew
- Label
- MenuNew
- MeterNew
- Number Field
- OTP FieldNew
- Pagination
- PopoverNew
- Preview CardNew
- Progress
- Radio Group
- Scroll AreaNew
- Select
- Separator
- SheetNew
- SkeletonNew
- Slider
- Spinner
- StepperNew
- Switch
- Table
- TabsNew
- Textarea
- ToastNew
- ToggleNew
- Toggle GroupNew
- ToolbarNew
- Tooltip
Checkbox
A control allowing the user to toggle between checked and not checked.
import { Checkbox } from "mako-ui/components/checkbox";
import { Label } from "mako-ui/components/label";
export default function Particle() {
return (
<Label>
<Checkbox />
Accept terms and conditions
</Label>
);
}
Usage
import { Checkbox } from "mako-ui/components/checkbox"<Checkbox />API Reference
Checkbox
A checkbox with a built-in indicator (checkmark and indeterminate icons).
Examples
For accessible labelling and validation, prefer using the Field component to wrap checkboxes. See the related example: Checkbox field.
Disabled
import { Checkbox } from "mako-ui/components/checkbox";
import { Label } from "mako-ui/components/label";
export default function Particle() {
return (
<Label>
<Checkbox defaultChecked disabled />
Accept terms and conditions
</Label>
);
}
With Description
By clicking this checkbox, you agree to the terms and conditions.
import { Checkbox } from "mako-ui/components/checkbox";
import { Label } from "mako-ui/components/label";
import { useId } from "react";
export default function Particle() {
const id = useId();
return (
<div className="flex items-start gap-2">
<Checkbox defaultChecked id={id} />
<div className="flex flex-col gap-1">
<Label htmlFor={id}>Accept terms and conditions</Label>
<p className="text-muted-foreground text-xs">
By clicking this checkbox, you agree to the terms and conditions.
</p>
</div>
</div>
);
}
Card Style
import { Checkbox } from "mako-ui/components/checkbox";
import { Label } from "mako-ui/components/label";
export default function Particle() {
return (
<Label className="flex items-start gap-2 rounded-lg border p-3 hover:bg-accent/50 has-data-checked:border-primary/48 has-data-checked:bg-accent/50">
<Checkbox defaultChecked />
<div className="flex flex-col gap-1">
<p>Enable notifications</p>
<p className="text-muted-foreground text-xs">
You can enable or disable notifications at any time.
</p>
</div>
</Label>
);
}
Form Integration
Field provides accessible labelling and validation for form controls. Use it with Form to submit values.
"use client";
import { Button } from "mako-ui/components/button";
import { Checkbox } from "mako-ui/components/checkbox";
import { Field, FieldLabel } from "mako-ui/components/field";
import { Form } from "mako-ui/components/form";
import type { FormEvent } from "react";
import { useState } from "react";
export default function Particle() {
const [loading, setLoading] = useState(false);
const onSubmit = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
setLoading(true);
await new Promise((r) => setTimeout(r, 800));
setLoading(false);
const accepted = formData.get("terms") === "yes";
alert(`Terms: ${accepted ? "accepted" : "declined"}`);
};
return (
<Form className="flex w-auto flex-col gap-4" onSubmit={onSubmit}>
<Field name="terms">
<FieldLabel>
<Checkbox defaultChecked value="yes" />
Accept terms and conditions
</FieldLabel>
</Field>
<Button loading={loading} type="submit">
Submit
</Button>
</Form>
);
}