// app/sections/hero-image.tsx
import {
createSchema,
IMAGES_PLACEHOLDERS,
useThemeSettings,
} from "@weaverse/hydrogen";
import type { VariantProps } from "class-variance-authority";
import { cva } from "class-variance-authority";
import { backgroundInputs } from "~/components/background-image";
import { overlayInputs } from "~/components/overlay";
import type { SectionProps } from "~/components/section";
import { Section, layoutInputs } from "~/components/section";
// Define variants using CVA
const variants = cva("flex flex-col [&_.paragraph]:mx-[unset]", {
variants: {
height: {
small: "min-h-[40vh] lg:min-h-[50vh]",
medium: "min-h-[50vh] lg:min-h-[60vh]",
large: "min-h-[70vh] lg:min-h-[80vh]",
full: "",
},
enableTransparentHeader: {
true: "",
false: "",
},
contentPosition: {
"top left": "justify-start items-start [&_.paragraph]:[text-align:left]",
"top center": "justify-start items-center [&_.paragraph]:[text-align:center]",
"top right": "justify-start items-end [&_.paragraph]:[text-align:right]",
"center left": "justify-center items-start [&_.paragraph]:[text-align:left]",
"center center": "justify-center items-center [&_.paragraph]:[text-align:center]",
"center right": "justify-center items-end [&_.paragraph]:[text-align:right]",
"bottom left": "justify-end items-start [&_.paragraph]:[text-align:left]",
"bottom center": "justify-end items-center [&_.paragraph]:[text-align:center]",
"bottom right": "justify-end items-end [&_.paragraph]:[text-align:right]",
},
},
compoundVariants: [
{
height: "full",
enableTransparentHeader: true,
className: "h-screen",
},
{
height: "full",
enableTransparentHeader: false,
className: "h-screen-no-nav",
},
],
defaultVariants: {
height: "large",
contentPosition: "center center",
},
});
export interface HeroImageProps extends VariantProps<typeof variants> {}
function HeroImage(props: HeroImageProps & SectionProps) {
const { children, height, contentPosition, ...rest } = props;
const { enableTransparentHeader } = useThemeSettings();
return (
<Section
{...rest}
containerClassName={variants({
contentPosition,
height,
enableTransparentHeader,
})}
>
{children}
</Section>
);
}
export default HeroImage;
export let schema = createSchema({
type: "hero-image",
title: "Hero image",
settings: [
{
group: "Layout",
inputs: [
{
type: "select",
name: "height",
label: "Section height",
configs: {
options: [
{ value: "small", label: "Small" },
{ value: "medium", label: "Medium" },
{ value: "large", label: "Large" },
{ value: "full", label: "Fullscreen" },
],
},
},
{
type: "position",
name: "contentPosition",
label: "Content position",
defaultValue: "center center",
},
...layoutInputs.filter(
(inp) => inp.name !== "divider" && inp.name !== "borderRadius",
),
],
},
{
group: "Background",
inputs: [
...backgroundInputs.filter(
(inp) =>
inp.name !== "backgroundFor" && inp.name !== "backgroundColor",
),
],
},
{ group: "Overlay", inputs: overlayInputs },
],
childTypes: ["subheading", "heading", "paragraph", "button"],
presets: {
height: "large",
contentPosition: "center center",
backgroundImage: IMAGES_PLACEHOLDERS.banner_1,
backgroundFit: "cover",
enableOverlay: true,
overlayOpacity: 40,
children: [
{
type: "subheading",
content: "Subheading",
color: "#ffffff",
},
{
type: "heading",
content: "Hero image with text overlay",
as: "h2",
color: "#ffffff",
size: "default",
},
{
type: "paragraph",
content:
"Use this text to share information about your brand with your customers.",
color: "#ffffff",
},
],
},
});