Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { RiCheckLine } from '@remixicon/react'
  2. import cn from '@/utils/classnames'
  3. import IndeterminateIcon from './assets/indeterminate-icon'
  4. type CheckboxProps = {
  5. id?: string
  6. checked?: boolean
  7. onCheck?: () => void
  8. className?: string
  9. disabled?: boolean
  10. indeterminate?: boolean
  11. }
  12. const Checkbox = ({
  13. id,
  14. checked,
  15. onCheck,
  16. className,
  17. disabled,
  18. indeterminate,
  19. }: CheckboxProps) => {
  20. const checkClassName = (checked || indeterminate)
  21. ? 'bg-components-checkbox-bg text-components-checkbox-icon hover:bg-components-checkbox-bg-hover'
  22. : 'border border-components-checkbox-border bg-components-checkbox-bg-unchecked hover:bg-components-checkbox-bg-unchecked-hover hover:border-components-checkbox-border-hover'
  23. const disabledClassName = (checked || indeterminate)
  24. ? 'cursor-not-allowed bg-components-checkbox-bg-disabled-checked text-components-checkbox-icon-disabled hover:bg-components-checkbox-bg-disabled-checked'
  25. : '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'
  26. return (
  27. <div
  28. id={id}
  29. className={cn(
  30. 'flex h-4 w-4 cursor-pointer items-center justify-center rounded-[4px] shadow-xs shadow-shadow-shadow-3',
  31. checkClassName,
  32. disabled && disabledClassName,
  33. className,
  34. )}
  35. onClick={() => {
  36. if (disabled)
  37. return
  38. onCheck?.()
  39. }}
  40. data-testid={`checkbox-${id}`}
  41. >
  42. {!checked && indeterminate && <IndeterminateIcon />}
  43. {checked && <RiCheckLine className='h-3 w-3' data-testid={`check-icon-${id}`} />}
  44. </div>
  45. )
  46. }
  47. export default Checkbox