overleaf-cep/services/web/frontend/js/features/ui/components/bootstrap-5/icon-button.tsx
Rebeka Dekany 3c154955b2 [web] Ensure buttons and links have discernible text on the editor page (#25005)
* Use OLIconButton for buttons lacking visible text

* Ensure correct ARIA attr for the Layout dropdown

* Add a tooltip to Layout button

* Add "Open dev tool" aria-label

* Add accessible names to the rail tab items

* Remove unused IconProps export

GitOrigin-RevId: 185937384cf5ec87b32238111d6621ac07789fb4
2025-04-25 08:05:16 +00:00

46 lines
1.2 KiB
TypeScript

import { forwardRef } from 'react'
import classNames from 'classnames'
import MaterialIcon from '@/shared/components/material-icon'
import Button from './button'
import type { IconButtonProps } from '@/features/ui/components/types/icon-button-props'
const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
(
{
accessibilityLabel,
icon,
isLoading = false,
size,
className,
unfilled,
...props
},
ref
) => {
const iconButtonClassName = classNames(className, {
'icon-button': !size,
'icon-button-small': size === 'sm',
'icon-button-large': size === 'lg',
})
const iconSizeClassName = size === 'lg' ? 'icon-large' : 'icon-small'
const materialIconClassName = classNames(iconSizeClassName, {
'button-content-hidden': isLoading,
unfilled,
})
return (
<Button
className={iconButtonClassName}
isLoading={isLoading}
aria-label={accessibilityLabel}
{...props}
ref={ref}
>
<MaterialIcon className={materialIconClassName} type={icon} />
</Button>
)
}
)
IconButton.displayName = 'IconButton'
export default IconButton