Created
September 25, 2026 14:36
-
-
Save YuraSab/4e5ba3e53a131105f162716de9bc18e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/components/ui/Icon/Icon.tsx | |
| import * as LucideIcons from "lucide-react"; | |
| import { tv, type VariantProps } from "tailwind-variants"; | |
| export const iconVariants = tv({ | |
| base: "shrink-0 transition-colors", | |
| variants: { | |
| size: { | |
| xs: "size-3.5", // 14px | |
| sm: "size-4", // 16px | |
| md: "size-5", // 20px | |
| lg: "size-6", // 24px | |
| xl: "size-8", // 32px | |
| }, | |
| color: { | |
| primary: "text-blue-600", | |
| error: "text-red-600", | |
| success: "text-green-600", | |
| muted: "text-gray-400", | |
| current: "text-current", | |
| }, | |
| }, | |
| defaultVariants: { | |
| size: "sm", | |
| color: "current", | |
| }, | |
| }); | |
| export type IconName = keyof typeof LucideIcons; | |
| export interface IconProps extends VariantProps<typeof iconVariants> { | |
| name: IconName; | |
| className?: string; | |
| strokeWidth?: number; | |
| customSize?: number; | |
| } | |
| export const Icon = ({ | |
| name, | |
| size, | |
| color, | |
| className, | |
| strokeWidth = 2, | |
| customSize, | |
| }: IconProps) => { | |
| // Lucide types their exports as LucideIcon | |
| const IconComponent = LucideIcons[name] as LucideIcons.LucideIcon; | |
| return ( | |
| <IconComponent | |
| // кастомний розмір, передється прямо в lucide (width/height) | |
| size={customSize} | |
| className={iconVariants({ | |
| // виключаю дефолтний розмір (sm: "size-4"), якщо передано customSize, щоб уникнути конфлікти | |
| size: customSize ? undefined : size, | |
| color, | |
| className, | |
| })} | |
| strokeWidth={strokeWidth} | |
| /> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment