Checkbox Pro
scrollxui/checkbox-proFreeComponent
A customizable checkbox component with animated checkmark and indeterminate states.
Live preview
live · rendered by the registry
Rendered by scrollxui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://scrollxui.dev/registry/checkbox-pro.jsonSource
1'use client';2import * as React from 'react';3import { CheckIcon, MinusIcon } from 'lucide-react';4import { motion } from 'motion/react';5import { cn } from '@/lib/utils';67type CheckedState = boolean | 'indeterminate';89interface CheckboxProProps {10 className?: string;11 onCheckedChange?: (checked: CheckedState) => void;12 disabled?: boolean;13 defaultChecked?: CheckedState;14 checked?: CheckedState;15 id?: string;16 name?: string;17 value?: string;18 required?: boolean;19 asChild?: boolean;20 forceMount?: boolean;21 'aria-label'?: string;22 'aria-labelledby'?: string;23 'aria-describedby'?: string;24}2526function AsChild({27 asChild,28 children,29 ...props30}: {31 asChild?: boolean;32 children: React.ReactElement;33} & React.HTMLAttributes<HTMLElement>) {34 if (asChild && React.isValidElement(children)) {35 return React.cloneElement(children, {36 ...(children.props as Record<string, unknown>),37 ...props,38 className: cn(39 (children.props as { className?: string }).className,40 props.className,41 ),42 } as React.HTMLAttributes<HTMLElement>);43 }44 return children;45}4647function CheckboxPro({48 className,49 onCheckedChange,50 disabled = false,51 defaultChecked = false,52 checked: checkedProp,53 id,54 name,55 value,56 required = false,57 asChild = false,58 forceMount = false,59 'aria-label': ariaLabel,60 'aria-labelledby': ariaLabelledby,61 'aria-describedby': ariaDescribedby,62 children,63 ...props64}: CheckboxProProps &65 React.HTMLAttributes<HTMLButtonElement> & { children?: React.ReactElement }) {66 const [animationKey, setAnimationKey] = React.useState(0);67 const [internalChecked, setInternalChecked] =68 React.useState<CheckedState>(defaultChecked);69 const [isKeyboardUser, setIsKeyboardUser] = React.useState(false);70 const buttonRef = React.useRef<HTMLButtonElement>(null);7172 const isControlled = checkedProp !== undefined;73 const checked = isControlled ? checkedProp : internalChecked;74 const isIndeterminate = checked === 'indeterminate';75 const isChecked = checked === true;7677 const getDataState = (78 checked: CheckedState,79 ): 'checked' | 'unchecked' | 'indeterminate' => {80 if (checked === 'indeterminate') return 'indeterminate';81 return checked ? 'checked' : 'unchecked';82 };8384 const handleToggle = React.useCallback(() => {85 if (disabled) return;8687 let newChecked: CheckedState;8889 if (isIndeterminate) {90 newChecked = false;91 } else {92 newChecked = !isChecked;93 }9495// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from scrollxui
All 180 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | scrollxui | Components | Free | 4 deps | |
| Alert Dialogalert-dialog | scrollxui | Components | Free | 7 deps | |
| Animated Buttonanimated-button | scrollxui | Components | Free | 4 deps | |
| Animated Tabsanimated-tabs | scrollxui | Components | Free | 1 dep | |
| Animated Testimonialsanimated-testimonials | scrollxui | Components | Free | 2 deps | |
| Animated TextGenerateanimated-textgenerate | scrollxui | Components | Free | 3 deps | |
| Announcementannouncement | scrollxui | Components | Free | 5 deps | |
| Aspect Ratioaspect-ratio | scrollxui | Components | Free | 1 dep |
