Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 1x 1x 1x | 'use client';
import { ButtonHTMLAttributes, forwardRef } from 'react';
import { Icon } from '@/components/ui/icons';
import { IconName } from '@/components/ui/icons/registry';
import { cn } from '@/lib/core';
/**
* IconButton Component Props
*/
export interface IconButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
/** Icon name from registry */
icon: IconName;
/** Button variant */
variant?: 'default' | 'primary' | 'ghost' | 'destructive';
/** Button size */
size?: 'sm' | 'md' | 'lg';
/** Accessibility label (required for screen readers) */
'aria-label': string;
/** Loading state */
loading?: boolean;
/** Icon size (defaults based on button size) */
iconSize?: number;
}
const sizeStyles = {
sm: 'w-11 h-11', // 44px - WCAG 2.5 minimum touch target
md: 'w-11 h-11', // 44px - WCAG 2.5 minimum touch target
lg: 'w-12 h-12' // 48px - comfortable touch target
};
const iconSizes = {
sm: 18,
md: 20,
lg: 22
};
const variantStyles = {
default: 'bg-white text-dark hover:bg-blue hover:text-white shadow-1',
primary: 'bg-blue text-white hover:bg-blue-dark shadow-1',
ghost: 'bg-transparent text-dark hover:bg-gray-100',
destructive: 'bg-red-500 text-white hover:bg-red-600 shadow-1'};
/**
* IconButton - Reusable icon-only button component
*
* Features:
* - Consistent sizing and styling
* - Built-in loading states
* - Accessibility support with required aria-label
* - Multiple variants and sizes
* - Smooth hover transitions
*
* @example
* ```tsx
* // Default variant
* <IconButton
* icon="eye"
* onClick={handleQuickView}
* aria-label="Quick view"
* />
*
* // Primary variant
* <IconButton
* icon="cart"
* variant="primary"
* onClick={handleAddToCart}
* aria-label="Add to cart"
* />
*
* // Large size with loading
* <IconButton
* icon="heart"
* size="lg"
* loading={isLoading}
* aria-label="Add to wishlist"
* />
* ```
*/
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
(
{
icon,
variant = 'default',
size = 'md',
'aria-label': ariaLabel,
loading = false,
iconSize,
className,
disabled,
...props
},
ref
) => {
const finalIconSize = iconSize || iconSizes[size];
const isDisabled = disabled || loading;
return (
<button
ref={ref}
type="button"
disabled={isDisabled}
aria-label={ariaLabel}
className={cn(
'flex items-center justify-center rounded-[5px] ease-out duration-200',
'focus:outline-none focus:ring-2 focus:ring-blue focus:ring-offset-2',
'disabled:opacity-50 disabled:cursor-not-allowed',
sizeStyles[size],
variantStyles[variant],
className
)}
{...props}
>
{loading ? (
<Icon name="reload" size={finalIconSize} className="fill-current animate-spin" />
) : (
<Icon name={icon} size={finalIconSize} className="fill-current" />
)}
</button>
);
}
);
IconButton.displayName = 'IconButton';
|