label
className
import { Checkbox } from 'mycrumbs-uikit'; <Checkbox label="Accept terms and conditions" />
const [isChecked, setIsChecked] = useState(false); <Checkbox label="Subscribe to newsletter" checked={isChecked} onChange={(e) => setIsChecked(e.target.checked)} />
<Checkbox label="Custom styled checkbox" className="text-purple-500 focus:ring-purple-400" />
<Checkbox label="Cannot change this option" disabled />
<Checkbox label="This field is required" required />
<form onSubmit={handleSubmit}> <div className="space-y-4"> <Checkbox name="terms" label="I agree to the terms" required /> <Checkbox name="marketing" label="Send me marketing emails" /> <button type="submit">Submit</button> </div> </form>
import type { ComponentProps } from 'react'; import { forwardRef, useId } from 'react'; interface CheckboxProps extends Omit<ComponentProps<'input'>, 'prefix'> { label?: string; className?: string; } export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>( function CheckBox({ label, className = '', ...props }, ref) { const id = useId(); return ( <div className="flex items-center"> <input ref={ref} className={cn( 'text-brand focus:ring-brand-500 mr-2 cursor-pointer rounded border-gray-300 transition duration-200', className )} type="checkbox" id={id} {...props} /> <label className="inline-block whitespace-nowrap text-sm text-gray-800 dark:text-gray-200" htmlFor={id} > {label} </label> </div> ); } );