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>(
|
|
|
|
(
|
2024-10-09 08:13:50 -04:00
|
|
|
{ accessibilityLabel, icon, isLoading = false, size, className, ...props },
|
2024-08-22 08:14:22 -04:00
|
|
|
ref
|
|
|
|
) => {
|
2024-10-09 08:13:50 -04:00
|
|
|
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'
|
2024-08-22 08:14:22 -04:00
|
|
|
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
|