left-menu-button.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { PropsWithChildren } from 'react'
  2. import MaterialIcon from '@/shared/components/material-icon'
  3. type Props = {
  4. onClick?: () => void
  5. icon?: string
  6. svgIcon?: React.ReactElement | null
  7. disabled?: boolean
  8. disabledAccesibilityText?: string
  9. type?: 'button' | 'link'
  10. href?: string
  11. translate?: React.HTMLAttributes<HTMLElement>['translate']
  12. }
  13. function LeftMenuButtonIcon({
  14. svgIcon,
  15. icon,
  16. }: {
  17. svgIcon?: React.ReactElement | null
  18. icon?: string
  19. }) {
  20. if (svgIcon) {
  21. return <div className="material-symbols">{svgIcon}</div>
  22. } else if (icon) {
  23. return <MaterialIcon type={icon} />
  24. } else return null
  25. }
  26. export default function LeftMenuButton({
  27. children,
  28. svgIcon,
  29. onClick,
  30. icon,
  31. disabled = false,
  32. disabledAccesibilityText,
  33. type = 'button',
  34. href,
  35. translate,
  36. }: PropsWithChildren<Props>) {
  37. if (disabled) {
  38. return (
  39. <div className="left-menu-button link-disabled">
  40. <LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
  41. <span translate={translate}>{children}</span>
  42. {disabledAccesibilityText ? (
  43. <span className="visually-hidden">{disabledAccesibilityText}</span>
  44. ) : null}
  45. </div>
  46. )
  47. }
  48. if (type === 'button') {
  49. return (
  50. <button onClick={onClick} className="left-menu-button">
  51. <LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
  52. <span translate={translate}>{children}</span>
  53. </button>
  54. )
  55. } else {
  56. return (
  57. <a
  58. href={href}
  59. target="_blank"
  60. rel="noreferrer"
  61. className="left-menu-button"
  62. >
  63. <LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
  64. <span translate={translate}>{children}</span>
  65. </a>
  66. )
  67. }
  68. }