2022-10-27 12:19:50 -04:00
|
|
|
import { PropsWithChildren } from 'react'
|
|
|
|
import Icon from '../../../shared/components/icon'
|
2024-10-11 05:22:38 -04:00
|
|
|
import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
|
|
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
2022-10-27 12:19:50 -04:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onClick?: () => void
|
2024-10-11 05:22:38 -04:00
|
|
|
icon?: {
|
2022-10-27 12:19:50 -04:00
|
|
|
type: string
|
|
|
|
fw?: boolean
|
|
|
|
}
|
2024-10-11 05:22:38 -04:00
|
|
|
svgIcon?: React.ReactElement | null
|
2022-10-27 12:19:50 -04:00
|
|
|
disabled?: boolean
|
|
|
|
disabledAccesibilityText?: string
|
2022-10-24 16:33:13 -04:00
|
|
|
type?: 'button' | 'link'
|
|
|
|
href?: string
|
2022-10-27 12:19:50 -04:00
|
|
|
}
|
|
|
|
|
2024-10-11 05:22:38 -04:00
|
|
|
function LeftMenuButtonIcon({
|
|
|
|
svgIcon,
|
|
|
|
icon,
|
|
|
|
}: {
|
|
|
|
svgIcon?: React.ReactElement | null
|
|
|
|
icon?: { type: string; fw?: boolean }
|
|
|
|
}) {
|
|
|
|
if (svgIcon) {
|
|
|
|
return <div className="material-symbols">{svgIcon}</div>
|
|
|
|
} else if (icon) {
|
|
|
|
return (
|
|
|
|
<BootstrapVersionSwitcher
|
|
|
|
bs3={<Icon type={icon.type} fw={icon.fw ?? false} />}
|
|
|
|
bs5={<MaterialIcon type={icon.type} />}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
} else return null
|
|
|
|
}
|
|
|
|
|
2022-10-27 12:19:50 -04:00
|
|
|
export default function LeftMenuButton({
|
|
|
|
children,
|
2024-10-11 05:22:38 -04:00
|
|
|
svgIcon,
|
2022-10-27 12:19:50 -04:00
|
|
|
onClick,
|
|
|
|
icon,
|
|
|
|
disabled = false,
|
|
|
|
disabledAccesibilityText,
|
2022-10-24 16:33:13 -04:00
|
|
|
type = 'button',
|
|
|
|
href,
|
2022-10-27 12:19:50 -04:00
|
|
|
}: PropsWithChildren<Props>) {
|
|
|
|
if (disabled) {
|
|
|
|
return (
|
|
|
|
<div className="left-menu-button link-disabled">
|
2024-10-11 05:22:38 -04:00
|
|
|
<LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
|
2022-10-27 12:19:50 -04:00
|
|
|
<span>{children}</span>
|
|
|
|
{disabledAccesibilityText ? (
|
|
|
|
<span className="sr-only">{disabledAccesibilityText}</span>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-10-24 16:33:13 -04:00
|
|
|
if (type === 'button') {
|
|
|
|
return (
|
|
|
|
<button onClick={onClick} className="left-menu-button">
|
2024-10-11 05:22:38 -04:00
|
|
|
<LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
|
2022-10-24 16:33:13 -04:00
|
|
|
<span>{children}</span>
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
href={href}
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
className="left-menu-button"
|
|
|
|
>
|
2024-10-11 05:22:38 -04:00
|
|
|
<LeftMenuButtonIcon svgIcon={svgIcon} icon={icon} />
|
2022-10-24 16:33:13 -04:00
|
|
|
<span>{children}</span>
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
2022-10-27 12:19:50 -04:00
|
|
|
}
|