DisableInteraction.tsx 1007 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React, { forwardRef } from 'react'
  2. import { cn } from 'ui'
  3. interface DisableInteractionProps extends React.HTMLAttributes<HTMLDivElement> {
  4. disabled?: boolean
  5. }
  6. /**
  7. * DisableInteraction component
  8. *
  9. * A utility component that wraps content and prevents all user interactions when disabled
  10. * including clicking, hovering, and text selection.
  11. *
  12. * @example
  13. * <DisableInteraction disabled={isDisabled}>
  14. * <YourContent />
  15. * </DisableInteraction>
  16. */
  17. export const DisableInteraction = forwardRef<HTMLDivElement, DisableInteractionProps>(
  18. ({ disabled, style, className, ...props }, ref) => (
  19. <div
  20. ref={ref}
  21. {...props}
  22. className={cn(disabled && 'opacity-50 pointer-events-none', className)}
  23. style={{
  24. ...(disabled && {
  25. userSelect: 'none',
  26. WebkitUserSelect: 'none',
  27. MozUserSelect: 'none',
  28. msUserSelect: 'none',
  29. }),
  30. ...style,
  31. }}
  32. />
  33. )
  34. )
  35. DisableInteraction.displayName = 'DisableInteraction'