import type {
HydrogenComponent,
HydrogenComponentProps,
} from '@weaverse/hydrogen';
import { createSchema } from '@weaverse/hydrogen';
type HeroBannerProps = HydrogenComponentProps<{
featuredProducts: any[];
}> & {
heading: string;
subheading?: string;
backgroundImage?: string;
textColor?: string;
};
function HeroBanner({
heading,
subheading,
backgroundImage,
textColor = '#ffffff',
loaderData,
}: HeroBannerProps) {
const { featuredProducts } = loaderData || {};
return (
<div
className="hero-banner"
style={{
backgroundImage: `url(${backgroundImage})`,
color: textColor,
}}
>
<h1>{heading}</h1>
{subheading && <p>{subheading}</p>}
{featuredProducts?.length > 0 && (
<div className="featured-products">
{featuredProducts.map(product => (
<div key={product.id}>{product.title}</div>
))}
</div>
)}
</div>
);
}
let schema = createSchema({
type: 'hero-banner',
title: 'Hero Banner',
settings: [
{
group: 'Content',
inputs: [
{
type: 'text',
name: 'heading',
label: 'Heading',
defaultValue: 'Welcome to our store',
},
{
type: 'text',
name: 'subheading',
label: 'Subheading',
},
],
},
{
group: 'Styling',
inputs: [
{
type: 'image',
name: 'backgroundImage',
label: 'Background Image',
},
{
type: 'color',
name: 'textColor',
label: 'Text Color',
defaultValue: '#ffffff',
},
],
},
],
});
async function loader({ data, weaverse }) {
// Fetch featured products
const products = await weaverse.storefront.query('FEATURED_PRODUCTS_QUERY');
return {
featuredProducts: products?.data?.products?.nodes || [],
};
}
HeroBanner.defaultProps = {
heading: 'Welcome to our store',
};
export default HeroBanner;
export { schema, loader };