left-menu-button.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { PropsWithChildren } from 'react'
  2. import Icon from '../../../shared/components/icon'
  3. type Props = {
  4. onClick?: () => void
  5. icon: {
  6. type: string
  7. fw?: boolean
  8. }
  9. disabled?: boolean
  10. disabledAccesibilityText?: string
  11. type?: 'button' | 'link'
  12. href?: string
  13. }
  14. export default function LeftMenuButton({
  15. children,
  16. onClick,
  17. icon,
  18. disabled = false,
  19. disabledAccesibilityText,
  20. type = 'button',
  21. href,
  22. }: PropsWithChildren<Props>) {
  23. if (disabled) {
  24. return (
  25. <div className="left-menu-button link-disabled">
  26. <Icon type={icon.type} fw={icon.fw} />
  27. <span>{children}</span>
  28. {disabledAccesibilityText ? (
  29. <span className="sr-only">{disabledAccesibilityText}</span>
  30. ) : null}
  31. </div>
  32. )
  33. }
  34. if (type === 'button') {
  35. return (
  36. <button onClick={onClick} className="left-menu-button">
  37. <Icon type={icon.type} fw={icon.fw} />
  38. <span>{children}</span>
  39. </button>
  40. )
  41. } else {
  42. return (
  43. <a
  44. href={href}
  45. target="_blank"
  46. rel="noreferrer"
  47. className="left-menu-button"
  48. >
  49. <Icon type={icon.type} fw={icon.fw} />
  50. <span>{children}</span>
  51. </a>
  52. )
  53. }
  54. }