left-menu-button.tsx 1.6 KB

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