NavigationIconButton.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { ComponentProps, forwardRef, ReactNode } from 'react'
  2. import { Button, cn } from 'ui'
  3. export const NavigationIconButton = forwardRef<
  4. HTMLButtonElement,
  5. Omit<
  6. ComponentProps<typeof Button>,
  7. // omit other icon props to avoid confusion
  8. // using `icon` instead as there is only 1 use case for this component
  9. 'iconRight' | 'iconLeft'
  10. > & {
  11. rightText?: ReactNode
  12. }
  13. >(({ icon, rightText, ...props }, ref) => {
  14. return (
  15. <Button
  16. ref={ref}
  17. type="text"
  18. size="tiny"
  19. {...props}
  20. className={cn(
  21. 'h-10 [&>span]:relative [&>span]:items-center [&>span]:gap-3 [&>span]:flex [&>span]:w-full [&>span]:h-full p-0',
  22. props.className
  23. )}
  24. >
  25. <div className="absolute left-2 text-foreground-lighter">{icon}</div>
  26. <span
  27. className={cn(
  28. 'absolute left-10 md:left-7 md:group-data-[state=expanded]:left-10',
  29. 'opacity-100 md:opacity-0 md:group-data-[state=expanded]:opacity-100',
  30. 'w-40 text-sm flex flex-col items-center',
  31. 'transition-all'
  32. )}
  33. >
  34. <span className="w-full text-left text-foreground-light truncate">{props.children}</span>
  35. </span>
  36. {rightText && (
  37. <div
  38. className={cn(
  39. 'absolute right-2 flex items-center',
  40. 'opacity-100 md:opacity-0 transition-all',
  41. 'md:group-data-[state=expanded]:opacity-100 '
  42. )}
  43. >
  44. {rightText}
  45. </div>
  46. )}
  47. </Button>
  48. )
  49. })
  50. NavigationIconButton.displayName = 'NavigationIconButton'