fix: force the smart icon for client side loading to prevent potential issues
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user