InputWithAddons.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { forwardRef, InputHTMLAttributes, ReactNode } from 'react'
  2. import { cn } from 'ui'
  3. export interface InputWithAddonsProps extends InputHTMLAttributes<HTMLInputElement> {
  4. leading?: ReactNode
  5. trailing?: ReactNode
  6. containerClassName?: string
  7. }
  8. export const InputWithAddons = forwardRef<HTMLInputElement, InputWithAddonsProps>(
  9. ({ leading, trailing, containerClassName, className, ...props }, ref) => {
  10. return (
  11. <div
  12. className={cn(
  13. 'group border-input ring-offset-background flex h-10 w-full rounded-sm border bg-transparent text-sm overflow-hidden',
  14. 'focus-within:ring-ring focus-within:outline-hidden focus-within:ring-2 focus-within:ring-offset-2',
  15. containerClassName
  16. )}
  17. >
  18. {leading ? (
  19. <div className="border-input px-2 flex items-center justify-center">{leading}</div>
  20. ) : null}
  21. <input
  22. className={cn(
  23. 'bg-transparent w-full px-0 py-2 focus:outline-hidden border-0 placeholder:text-foreground-lighter ',
  24. 'disabled:cursor-not-allowed disabled:opacity-50 text-[0.75rem]',
  25. className
  26. )}
  27. ref={ref}
  28. {...props}
  29. />
  30. {trailing ? (
  31. <div className="border-input bg-muted/50 border-l px-3 py-2 flex items-center justify-center">
  32. {trailing}
  33. </div>
  34. ) : null}
  35. </div>
  36. )
  37. }
  38. )
  39. InputWithAddons.displayName = 'InputWithAddons'