mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-06 07:39:02 +02:00
9b10da6eaf
GitOrigin-RevId: 9f251969ed0f88a32f8bf706a6320c4c81c6d000
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import OLTooltip from '@/shared/components/ol/ol-tooltip'
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
import classNames from 'classnames'
|
|
import { ComponentProps, forwardRef, ReactElement } from 'react'
|
|
import { NavLink } from 'react-bootstrap'
|
|
import { RailElement } from '@/features/ide-react/util/rail-types'
|
|
|
|
const RailTab = forwardRef<
|
|
HTMLButtonElement,
|
|
{
|
|
icon: RailElement['icon']
|
|
eventKey?: string
|
|
open: boolean
|
|
indicator?: ReactElement
|
|
title: string
|
|
} & ComponentProps<'button'>
|
|
>(({ icon, className, eventKey, open, indicator, title, ...props }, ref) => {
|
|
return (
|
|
<OLTooltip
|
|
id={`rail-tab-tooltip-${eventKey}`}
|
|
description={title}
|
|
overlayProps={{ delay: 0, placement: 'right' }}
|
|
>
|
|
<NavLink
|
|
{...props}
|
|
ref={ref}
|
|
eventKey={eventKey}
|
|
className={classNames('ide-rail-tab-link', className, {
|
|
'open-rail': open,
|
|
})}
|
|
as="button"
|
|
>
|
|
<RailTabIcon icon={icon} title={title} open={open} />
|
|
{indicator}
|
|
</NavLink>
|
|
</OLTooltip>
|
|
)
|
|
})
|
|
|
|
const RailTabIcon = ({
|
|
icon,
|
|
title,
|
|
open,
|
|
}: {
|
|
icon: RailElement['icon']
|
|
title: string
|
|
open: boolean
|
|
}) => {
|
|
if (typeof icon === 'string') {
|
|
return open ? (
|
|
<MaterialIcon
|
|
type={icon}
|
|
className="ide-rail-tab-link-icon"
|
|
accessibilityLabel={title}
|
|
/>
|
|
) : (
|
|
<MaterialIcon
|
|
type={icon}
|
|
className="ide-rail-tab-link-icon"
|
|
unfilled
|
|
accessibilityLabel={title}
|
|
/>
|
|
)
|
|
} else {
|
|
const Component = icon
|
|
return <Component open={open} title={title} />
|
|
}
|
|
}
|
|
|
|
RailTab.displayName = 'RailTab'
|
|
|
|
export default RailTab
|