left-menu-button.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. }
  12. function LeftMenuButtonIcon({
  13. svgIcon,
  14. icon,
  15. }: {
  16. svgIcon?: React.ReactElement | null
  17. icon?: string
  18. }) {
  19. if (svgIcon) {
  20. return <div className="material-symbols">{svgIcon}</div>
  21. } else if (icon) {
  22. return <MaterialIcon type={icon} />
  23. } else return null
  24. }
  25. export default function LeftMenuButton({
  26. children,
  27. svgIcon,
  28. onClick,
  29. icon,
  30. disabled = false,
  31. disabledAccesibilityText,
  32. type = 'button',
  33. href,
  34. }: PropsWithChildren<Props>) {
  35. if (disabled) {
  36. return (
  37. <div className="left-menu-button link-disabled">
  38. <LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
  39. <span>{children}</span>
  40. {disabledAccesibilityText ? (
  41. <span className="sr-only">{disabledAccesibilityText}</span>
  42. ) : null}
  43. </div>
  44. )
  45. }
  46. if (type === 'button') {
  47. return (
  48. <button onClick={onClick} className="left-menu-button">
  49. <LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
  50. <span>{children}</span>
  51. </button>
  52. )
  53. } else {
  54. return (
  55. <a
  56. href={href}
  57. target="_blank"
  58. rel="noreferrer"
  59. className="left-menu-button"
  60. >
  61. <LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
  62. <span>{children}</span>
  63. </a>
  64. )
  65. }
  66. }