simple-ad-component
Version:
31 lines (30 loc) • 1.43 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
export const Ad = ({ imageUrl, targetUrl, altText = 'Advertisement', width = 'auto', height = 250, className = '', onImpression, onClick }) => {
useEffect(() => {
onImpression?.();
}, [onImpression]);
const handleClick = (e) => {
onClick?.();
window.open(targetUrl, '_blank', 'noopener,noreferrer');
};
return (_jsx("div", { className: className, style: {
display: 'inline-block',
overflow: 'hidden',
width: typeof width === 'number' ? `${width}px` : width,
height: typeof height === 'number' ? `${height}px` : height
}, children: _jsx("button", { onClick: handleClick, style: {
width: '100%',
height: '100%',
padding: 0,
border: 'none',
cursor: 'pointer',
background: 'none',
transition: 'transform 0.2s ease-in-out',
objectFit: 'contain',
}, onMouseOver: (e) => (e.currentTarget.style.transform = 'scale(1.02)'), onMouseOut: (e) => (e.currentTarget.style.transform = 'scale(1)'), children: _jsx("img", { src: imageUrl, alt: altText, style: {
width: '100%',
height: '100%',
objectFit: 'cover',
}, loading: "lazy" }) }) }));
};