37 lines
835 B
TypeScript
37 lines
835 B
TypeScript
import React, { forwardRef } from 'react';
|
|
import { Button, ButtonProps } from './Button';
|
|
import { Icon } from './Icon';
|
|
|
|
export interface IconButtonProps extends Omit<ButtonProps, 'children' | 'icon'> {
|
|
icon: any;
|
|
title?: string;
|
|
intent?: 'primary' | 'success' | 'warning' | 'critical' | 'telemetry' | 'low' | 'high';
|
|
}
|
|
|
|
export const IconButton = forwardRef<HTMLButtonElement | HTMLAnchorElement, IconButtonProps>(({
|
|
icon,
|
|
title,
|
|
size = 'md',
|
|
intent,
|
|
...props
|
|
}, ref) => {
|
|
const iconSizeMap = {
|
|
sm: 3,
|
|
md: 4,
|
|
lg: 5
|
|
} as const;
|
|
|
|
return (
|
|
<Button
|
|
ref={ref}
|
|
size={size}
|
|
{...props}
|
|
>
|
|
<Icon icon={icon} size={iconSizeMap[size]} intent={intent} />
|
|
{title && <span className="sr-only">{title}</span>}
|
|
</Button>
|
|
);
|
|
});
|
|
|
|
IconButton.displayName = 'IconButton';
|