-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathhero-image.tsx
More file actions
147 lines (143 loc) · 4.28 KB
/
Copy pathhero-image.tsx
File metadata and controls
147 lines (143 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 { layoutInputs, Section } from "~/components/section";
import type { ThemeSettings } from "~/types/weaverse";
export interface HeroImageProps extends VariantProps<typeof variants> {}
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": "items-start justify-start [&_.paragraph]:text-left",
"top center": "items-center justify-start [&_.paragraph]:text-center",
"top right": "items-end justify-start [&_.paragraph]:text-right",
"center left": "items-start justify-center [&_.paragraph]:text-left",
"center center": "items-center justify-center [&_.paragraph]:text-center",
"center right": "items-end justify-center [&_.paragraph]:text-right",
"bottom left": "items-start justify-end [&_.paragraph]:text-left",
"bottom center": "items-center justify-end [&_.paragraph]:text-center",
"bottom right": "items-end justify-end [&_.paragraph]:text-right",
},
},
compoundVariants: [
{
height: "full",
enableTransparentHeader: true,
className: "h-screen-no-topbar",
},
{
height: "full",
enableTransparentHeader: false,
className: "h-screen-dynamic",
},
],
defaultVariants: {
height: "large",
contentPosition: "center center",
},
});
export default function HeroImage(props: HeroImageProps & SectionProps) {
const { children, height, contentPosition, ...rest } = props;
const { enableTransparentHeader } = useThemeSettings<ThemeSettings>();
return (
<Section
{...rest}
// Hero backgrounds are above the fold — eager + high-priority fetch
// so the LCP image isn't deferred by the default lazy loading.
loading="eager"
containerClassName={variants({
contentPosition,
height,
enableTransparentHeader,
})}
>
{children}
</Section>
);
}
export const 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"),
],
},
{
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. Describe a product, share announcements, or welcome customers to your store.",
color: "#ffffff",
},
],
},
});