fix: force the smart icon for client side loading to prevent potential issues

This commit is contained in:
Mahyar Khanbolooki
2025-08-21 22:10:01 +03:30
parent cacfb17ec6
commit 92150cf86c
+38 -31
View File
@@ -1,25 +1,22 @@
'use client';
'use client'
import React from "react";
import * as Iconsax from "iconsax-react";
import { SmartIconType } from "@/types/iconType";
import React, { Suspense, lazy, ComponentType } from 'react'
import { SmartIconType } from '@/types/iconType'
type IconsaxIconProps = {
size?: number;
color?: string;
className?: string;
variant?: string;
};
type IconComponentType = React.FC<IconsaxIconProps>;
size?: number
color?: string
className?: string
variant?: string
}
export interface SmartIconProps {
icon?: SmartIconType;
name?: string;
size?: number;
color?: string;
className?: string;
variant?: string;
icon?: SmartIconType
name?: string
size?: number
color?: string
className?: string
variant?: string
}
export const SmartIcon: React.FC<SmartIconProps> = ({
@@ -28,22 +25,32 @@ export const SmartIcon: React.FC<SmartIconProps> = ({
size,
color,
className,
variant,
variant
}) => {
const iconName = (icon?.Name || name || "").charAt(0).toUpperCase() + (icon?.Name || name || "").slice(1);
const iconName =
(icon?.Name || name || '').charAt(0).toUpperCase() +
(icon?.Name || name || '').slice(1)
if (!iconName) return null;
if (!iconName) return null
const IconComponent = Iconsax[iconName as keyof typeof Iconsax] as IconComponentType | undefined;
if (!IconComponent) return null;
// Lazy-load icon dynamically with proper type cast
const IconComponent = lazy(() =>
import('iconsax-react').then(module => {
const Component = module[
iconName as keyof typeof module
] as ComponentType<IconsaxIconProps>
return { default: Component }
})
)
return (
<IconComponent
variant={icon?.Variant ?? variant ?? 'lineat'}
size={icon?.Size ?? size ?? 20}
color={icon?.Color ?? color ?? "currentColor"}
className={icon?.ClassName ?? className}
/>
);
};
<Suspense fallback={null}>
<IconComponent
variant={icon?.Variant ?? variant ?? 'linear'}
size={icon?.Size ?? size ?? 20}
color={icon?.Color ?? color ?? 'currentColor'}
className={icon?.ClassName ?? className}
/>
</Suspense>
)
}