| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { forwardRef } from 'react'
- import classNames from 'classnames'
- import MaterialIcon from '@/shared/components/material-icon'
- import Button from './button'
- import type { IconButtonProps } from '@/shared/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
|