Files
overleaf-cep/services/web/frontend/js/shared/components/material-icon.tsx
Alf Eaton 5b2e541186 Memoize some editor React components (#28963)
GitOrigin-RevId: 6440df9ac3ef1bf1839dff07eb2f55b52b581d3e
2025-10-15 08:05:48 +00:00

57 lines
1.1 KiB
TypeScript

import classNames from 'classnames'
import React, { memo } from 'react'
import unfilledIconTypes from '../../../fonts/material-symbols/unfilled-symbols.mjs'
export type AvailableUnfilledIcon = (typeof unfilledIconTypes)[number]
type BaseIconProps = React.ComponentProps<'i'> & {
accessibilityLabel?: string
modifier?: string
size?: '2x'
}
type FilledIconProps = BaseIconProps & {
type: string
unfilled?: false
}
type UnfilledIconProps = BaseIconProps & {
type: AvailableUnfilledIcon
unfilled: true
}
export type IconProps = FilledIconProps | UnfilledIconProps
function MaterialIcon({
type,
className,
accessibilityLabel,
modifier,
size,
unfilled,
...rest
}: IconProps) {
const iconClassName = classNames('material-symbols', className, modifier, {
[`size-${size}`]: size,
unfilled,
})
return (
<>
<span
className={iconClassName}
aria-hidden="true"
translate="no"
{...rest}
>
{type}
</span>
{accessibilityLabel && (
<span className="visually-hidden">{accessibilityLabel}</span>
)}
</>
)
}
export default memo(MaterialIcon)