34 lines
846 B
TypeScript
34 lines
846 B
TypeScript
import React from 'react';
|
|
import { clsx } from 'clsx';
|
|
import { twMerge } from 'tailwind-merge';
|
|
import { Button, ButtonProps } from './Button';
|
|
|
|
export interface IconButtonProps extends Omit<ButtonProps, 'size'> {
|
|
'aria-label': string;
|
|
size?: 'sm' | 'md' | 'lg';
|
|
icon: React.ReactNode;
|
|
}
|
|
|
|
export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
({ icon, 'aria-label': ariaLabel, size = 'md', className, ...props }, ref) => {
|
|
const sizeClasses = {
|
|
sm: 'p-1.5 text-xs',
|
|
md: 'p-2 text-sm',
|
|
lg: 'p-2.5 text-base',
|
|
};
|
|
|
|
return (
|
|
<Button
|
|
ref={ref}
|
|
size="icon"
|
|
aria-label={ariaLabel}
|
|
className={twMerge(clsx(sizeClasses[size], className))}
|
|
{...props}
|
|
>
|
|
{icon}
|
|
</Button>
|
|
);
|
|
}
|
|
);
|
|
|
|
IconButton.displayName = 'IconButton';
|