| 
									
										
										
										
											2024-12-12 10:09:48 +08:00
										 |  |  | import { RiCheckLine } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  | import IndeterminateIcon from './assets/indeterminate-icon' | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type CheckboxProps = { | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  |   id?: string | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |   checked?: boolean | 
					
						
							|  |  |  |   onCheck?: () => void | 
					
						
							|  |  |  |   className?: string | 
					
						
							| 
									
										
										
										
											2024-06-20 15:48:38 +08:00
										 |  |  |   disabled?: boolean | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  |   indeterminate?: boolean | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  | const Checkbox = ({ | 
					
						
							|  |  |  |     id, | 
					
						
							|  |  |  |     checked, | 
					
						
							|  |  |  |     onCheck, | 
					
						
							|  |  |  |     className, | 
					
						
							|  |  |  |     disabled, | 
					
						
							|  |  |  |     indeterminate, | 
					
						
							|  |  |  | }: CheckboxProps) => { | 
					
						
							|  |  |  |   const checkClassName = (checked || indeterminate) | 
					
						
							|  |  |  |     ? 'bg-components-checkbox-bg text-components-checkbox-icon hover:bg-components-checkbox-bg-hover' | 
					
						
							|  |  |  |     : 'border border-components-checkbox-border bg-components-checkbox-bg-unchecked hover:bg-components-checkbox-bg-unchecked-hover hover:border-components-checkbox-border-hover' | 
					
						
							|  |  |  |   const disabledClassName = (checked || indeterminate) | 
					
						
							|  |  |  |     ? 'cursor-not-allowed bg-components-checkbox-bg-disabled-checked text-components-checkbox-icon-disabled hover:bg-components-checkbox-bg-disabled-checked' | 
					
						
							|  |  |  |     : 'cursor-not-allowed border-components-checkbox-border-disabled bg-components-checkbox-bg-disabled hover:border-components-checkbox-border-disabled hover:bg-components-checkbox-bg-disabled' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <div | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  |       id={id} | 
					
						
							| 
									
										
										
										
											2024-06-20 15:48:38 +08:00
										 |  |  |       className={cn( | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  |         'flex h-4 w-4 cursor-pointer items-center justify-center rounded-[4px] shadow-xs shadow-shadow-shadow-3', | 
					
						
							|  |  |  |         checkClassName, | 
					
						
							|  |  |  |         disabled && disabledClassName, | 
					
						
							| 
									
										
										
										
											2024-06-20 15:48:38 +08:00
										 |  |  |         className, | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |       onClick={() => { | 
					
						
							|  |  |  |         if (disabled) | 
					
						
							|  |  |  |           return | 
					
						
							|  |  |  |         onCheck?.() | 
					
						
							|  |  |  |       }} | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  |       data-testid={`checkbox-${id}`} | 
					
						
							| 
									
										
										
										
											2024-12-12 10:09:48 +08:00
										 |  |  |     > | 
					
						
							| 
									
										
										
										
											2025-04-18 15:54:22 +08:00
										 |  |  |       {!checked && indeterminate && <IndeterminateIcon />} | 
					
						
							|  |  |  |       {checked && <RiCheckLine className='h-3 w-3' data-testid={`check-icon-${id}`} />} | 
					
						
							| 
									
										
										
										
											2024-12-12 10:09:48 +08:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2023-06-16 21:47:51 +08:00
										 |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default Checkbox |