UNPKG

@vela-ui/react

Version:

Vela UI React components

75 lines (72 loc) 2.11 kB
import { MinusIcon } from "./chunk-I3Q6AUZG.mjs"; import { CheckIcon } from "./chunk-6SWBNV6A.mjs"; import { focusRing } from "./chunk-2FWUIDJB.mjs"; // src/components/checkbox.tsx import { Checkbox as AriaCheckbox, composeRenderProps } from "react-aria-components"; import { tv } from "tailwind-variants"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; var checkboxVariants = tv({ base: "group relative flex items-center gap-2 text-sm transition", variants: { isDisabled: { true: "cursor-not-allowed opacity-50" } } }); var checkboxIndicatorVariants = tv({ extend: focusRing, base: "peer border-input dark:bg-input/30 flex shrink-0 items-center justify-center rounded-[4px] border shadow-xs transition-shadow [&_svg]:size-full", variants: { size: { sm: "size-4", md: "size-5 p-0.5", lg: "size-6 p-0.5" }, isSelected: { true: "bg-primary dark:bg-primary text-primary-foreground border-primary" }, isDisabled: { true: "cursor-not-allowed opacity-50" } }, defaultVariants: { size: "md" } }); function Checkbox({ className, children, indicatorClassName, size, ...props }) { return /* @__PURE__ */ jsx( AriaCheckbox, { className: composeRenderProps( className, (className2, renderProps) => checkboxVariants({ ...renderProps, className: className2 }) ), ...props, children: composeRenderProps(children, (children2, { isSelected, isIndeterminate, ...renderProps }) => /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx( "div", { "data-slot": "checkbox-indicator", className: checkboxIndicatorVariants({ isSelected: isSelected || isIndeterminate, size, ...renderProps, className: indicatorClassName }), children: isIndeterminate ? /* @__PURE__ */ jsx(MinusIcon, {}) : isSelected ? /* @__PURE__ */ jsx(CheckIcon, {}) : null } ), children2 ] })) } ); } export { Checkbox };