overleaf/services/web/frontend/js/features/editor-left-menu/components/left-menu-button.tsx
M Fahru a30e934692 Migrate "help menu" in editor left menu to react
GitOrigin-RevId: 7ebbfa693205de1f57b1d54e25c46cfb1851acc8
2022-11-03 09:03:49 +00:00

57 lines
1.2 KiB
TypeScript

import { PropsWithChildren } from 'react'
import Icon from '../../../shared/components/icon'
type Props = {
onClick?: () => void
icon: {
type: string
fw?: boolean
}
disabled?: boolean
disabledAccesibilityText?: string
type?: 'button' | 'link'
href?: string
}
export default function LeftMenuButton({
children,
onClick,
icon,
disabled = false,
disabledAccesibilityText,
type = 'button',
href,
}: PropsWithChildren<Props>) {
if (disabled) {
return (
<div className="left-menu-button link-disabled">
<Icon type={icon.type} fw={icon.fw} />
<span>{children}</span>
{disabledAccesibilityText ? (
<span className="sr-only">{disabledAccesibilityText}</span>
) : null}
</div>
)
}
if (type === 'button') {
return (
<button onClick={onClick} className="left-menu-button">
<Icon type={icon.type} fw={icon.fw} />
<span>{children}</span>
</button>
)
} else {
return (
<a
href={href}
target="_blank"
rel="noreferrer"
className="left-menu-button"
>
<Icon type={icon.type} fw={icon.fw} />
<span>{children}</span>
</a>
)
}
}