Components
Checkbox
Checkbox
A control that allows the user to toggle between checked and not checked.
Installation
npx @udecode/plate-ui@latest add checkbox
Examples
import React from 'react';
import { cn, withRef } from '@udecode/cn';
import { PlateElement } from '@udecode/plate-common/react';
import {
useTodoListElement,
useTodoListElementState,
} from '@udecode/plate-list/react';
import { Checkbox } from './checkbox';
export const TodoListElement = withRef<typeof PlateElement>(
({ children, className, ...props }, ref) => {
const { element } = props;
const state = useTodoListElementState({ element });
const { checkboxProps } = useTodoListElement(state);
return (
<PlateElement
className={cn('flex flex-row py-1', className)}
ref={ref}
{...props}
>
<div
className="mr-1.5 flex select-none items-center justify-center"
contentEditable={false}
>
<Checkbox {...checkboxProps} />
</div>
<span
className={cn(
'flex-1 focus:outline-none',
state.checked && 'text-muted-foreground line-through'
)}
contentEditable={!state.readOnly}
suppressContentEditableWarning
>
{children}
</span>
</PlateElement>
);
}
);