2024-08-22 08:14:22 -04:00
|
|
|
import { forwardRef } from 'react'
|
2024-04-16 11:06:42 -04:00
|
|
|
import classNames from 'classnames'
|
2024-03-06 06:31:25 -05:00
|
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
|
|
import Button from './button'
|
|
|
|
import type { IconButtonProps } from '@/features/ui/components/types/icon-button-props'
|
|
|
|
|
2024-08-22 08:14:22 -04:00
|
|
|
const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
|
|
(
|
|
|
|
{ accessibilityLabel, icon, isLoading = false, size = 'default', ...props },
|
|
|
|
ref
|
|
|
|
) => {
|
|
|
|
const iconButtonClassName = `icon-button-${size}`
|
|
|
|
const iconSizeClassName = size === 'large' ? 'icon-large' : 'icon-small'
|
|
|
|
const materialIconClassName = classNames(iconSizeClassName, {
|
|
|
|
'button-content-hidden': isLoading,
|
|
|
|
})
|
2024-03-06 06:31:25 -05:00
|
|
|
|
2024-08-22 08:14:22 -04:00
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
className={iconButtonClassName}
|
|
|
|
isLoading={isLoading}
|
|
|
|
aria-label={accessibilityLabel}
|
|
|
|
{...props}
|
|
|
|
ref={ref}
|
|
|
|
>
|
|
|
|
<MaterialIcon className={materialIconClassName} type={icon} />
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
IconButton.displayName = 'IconButton'
|
|
|
|
|
|
|
|
export default IconButton
|