Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox'
import type * as React from 'react'
import { cn } from '../lib/utils'
import { CheckIcon, MinusIcon } from '../spree/icons'
function Checkbox({
className,
checked,
defaultChecked,
onCheckedChange,
indeterminate,
disabled,
name,
...props
}: Omit<React.ComponentProps<typeof CheckboxPrimitive.Root>, 'children' | 'onCheckedChange'> & {
onCheckedChange?: (checked: boolean) => void
}) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
checked={checked}
defaultChecked={defaultChecked}
onCheckedChange={onCheckedChange ? (next) => onCheckedChange(next) : undefined}
indeterminate={indeterminate}
disabled={disabled}
name={name}
className={cn(
'peer relative inline-block size-4 shrink-0 cursor-pointer rounded-[4px] border border-border shadow-xs bg-card align-[-3px] outline-none transition-[color,background-color,border-color,box-shadow] duration-100 ease-out',
// The 16px box is the right *visual* size in a dense table, but on its
// own it is a 16px target — under the 24px WCAG 2.2 asks for, on the
// control every bulk action starts from. A pseudo-element extends the
// pressable area to 34px without taking layout space, so column widths
// and row height are unchanged. `z-1` keeps it above the row-click
// bridge, which would otherwise swallow presses in the padded margin
// and navigate instead of selecting.
"before:absolute before:inset-[-9px] before:z-1 before:content-['']",
'focus:border-blue-500 focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--ring)_15%,transparent)]',
'disabled:cursor-not-allowed disabled:bg-muted disabled:text-muted-foreground',
'aria-invalid:border-destructive aria-invalid:ring-destructive/20',
'data-[checked]:border-blue-500 data-[checked]:bg-blue-500 data-[checked]:text-white',
'data-[indeterminate]:border-blue-500 data-[indeterminate]:bg-blue-500 data-[indeterminate]:text-white',
'dark:aria-invalid:ring-destructive/40 dark:data-[checked]:bg-blue-500',
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator
keepMounted
data-slot="checkbox-indicator"
className="absolute inset-0 flex items-center justify-center text-current transition-none data-[unchecked]:hidden"
>
{indeterminate ? <MinusIcon className="size-3.5" /> : <CheckIcon className="size-3.5" />}
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
}
export { Checkbox }