ifixkart-admin/New admin panel/ikixkart-dashboard/components/ui/BlurHashImage.tsx
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- Backend: FastAPI app with all models, services, schemas, routes
- Admin Panel: Next.js dashboard with all modules
  (CRM, POS, repairs, warranties, billing, notifications, etc.)
- Ecommerce: storefront (submodule) + product catalog
- AI Agents: .agents/ skill library for Antigravity IDE
- Docs: architecture, billing, notification gateway markdown
- Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
2026-10-13 12:59:47 +05:30

59 lines
1.4 KiB
TypeScript

"use client";
import React, { useState, useEffect } from "react";
import Image, { ImageProps } from "next/image";
import { blurHashToDataURL } from "@/lib/blurhash";
export interface BlurHashImageProps extends Omit<ImageProps, "blurDataURL" | "placeholder"> {
blurHash?: string | null;
fallbackSrc?: string;
}
export function BlurHashImage({
src,
blurHash,
alt,
fallbackSrc = "/placeholder.png",
className = "",
style,
...restProps
}: BlurHashImageProps) {
const [imgSrc, setImgSrc] = useState<string>(typeof src === "string" ? src : "");
const [blurDataUrl, setBlurDataUrl] = useState<string>(() => blurHashToDataURL(blurHash));
const [hasError, setHasError] = useState(false);
useEffect(() => {
if (typeof src === "string") {
setImgSrc(src);
}
}, [src]);
useEffect(() => {
setBlurDataUrl(blurHashToDataURL(blurHash));
}, [blurHash]);
const handleError = (e: React.SyntheticEvent<HTMLImageElement, Event>) => {
if (!hasError && fallbackSrc) {
setHasError(true);
setImgSrc(fallbackSrc);
}
if (restProps.onError) {
restProps.onError(e);
}
};
return (
<Image
{...restProps}
src={imgSrc || fallbackSrc}
alt={alt || "Image"}
placeholder="blur"
blurDataURL={blurDataUrl}
onError={handleError}
className={className}
style={style}
/>
);
}
export default BlurHashImage;