left-menu-button.tsx 1.9 KB

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