forked from Weaverse/aspen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection-banner.tsx
164 lines (158 loc) · 4.49 KB
/
collection-banner.tsx
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import type {
HydrogenComponentProps,
HydrogenComponentSchema,
} from '@weaverse/hydrogen';
import type {CSSProperties} from 'react';
import {forwardRef} from 'react';
import {useLoaderData} from '@remix-run/react';
import clsx from 'clsx';
import type {CollectionDetailsQuery} from 'storefrontapi.generated';
interface CollectionBannerProps extends HydrogenComponentProps {
sectionHeightDesktop: number;
sectionHeightMobile: number;
enableBackground: boolean;
overlayOpacity: number;
enableOverlay: boolean;
contentPosition: string;
}
let CollectionBanner = forwardRef<HTMLElement, CollectionBannerProps>(
(props, ref) => {
let {
sectionHeightDesktop,
sectionHeightMobile,
enableBackground,
overlayOpacity,
enableOverlay,
contentPosition,
...rest
} = props;
let {collection} = useLoaderData<
CollectionDetailsQuery & {
collections: Array<{handle: string; title: string}>;
}
>();
let backgroundStyle: CSSProperties = {
'--header-height-desktop': `${sectionHeightDesktop}px`,
'--header-height-mobile': `${sectionHeightMobile}px`,
} as CSSProperties;
if (enableBackground) {
backgroundStyle.backgroundImage = `url('${collection?.image?.url}')`;
}
let overlayStyle: CSSProperties = {};
if (enableOverlay && enableBackground) {
overlayStyle = {
'--overlay-opacity': `${overlayOpacity}`,
} as CSSProperties;
}
let positionClass: {[key: string]: string} = {
'top left': 'items-start justify-start',
'top right': 'items-start justify-end',
'top center': 'items-start justify-center',
'center left': 'items-center justify-start',
'center center': 'items-center justify-center',
'center right': 'items-center justify-end',
'bottom left': 'items-end justify-start',
'bottom center': 'items-end justify-center',
'bottom right': 'items-end justify-end',
};
return (
<section
ref={ref}
{...rest}
style={backgroundStyle}
className={clsx(
'flex relative overflow-hidden bg-center bg-no-repeat bg-cover h-[var(--header-height-mobile)] sm:h-[var(--header-height-desktop)]',
positionClass[contentPosition],
)}
>
{enableOverlay && enableBackground && (
<div
className="absolute inset-0 z-1 bg-black bg-opacity-[var(--overlay-opacity)]"
style={overlayStyle}
></div>
)}
<div
className={clsx(
'text-center w-5/6 text-gray-700 z-2 relative',
enableBackground ? 'text-white' : 'text-gray-700',
)}
>
<h3 className="leading-tight font-medium">{collection?.title}</h3>
{collection?.description && (
<p className="mt-4 dark:text-gray-400 text-base md:text-sm">
{collection.description}
</p>
)}
</div>
</section>
);
},
);
export default CollectionBanner;
export let schema: HydrogenComponentSchema = {
type: 'collection-banner',
title: 'Collection banner',
toolbar: ['general-settings', ['duplicate', 'delete']],
enabledOn: {
pages: ['COLLECTION'],
},
inspector: [
{
group: 'Header',
inputs: [
{
type: 'switch',
name: 'enableBackground',
label: 'Enable background',
defaultValue: true,
},
{
type: 'range',
name: 'sectionHeightDesktop',
label: 'Section height desktop',
defaultValue: 450,
configs: {
min: 350,
max: 550,
step: 10,
},
},
{
type: 'range',
name: 'sectionHeightMobile',
label: 'Section height mobile',
defaultValue: 450,
configs: {
min: 350,
max: 550,
step: 10,
},
},
{
type: 'switch',
name: 'enableOverlay',
label: 'Enable overlay',
defaultValue: true,
},
{
type: 'range',
name: 'overlayOpacity',
label: 'Overlay opacity',
defaultValue: 0.5,
configs: {
min: 0.1,
max: 1,
step: 0.1,
},
condition: `enableOverlay.eq.true`,
},
{
type: 'position',
name: 'contentPosition',
label: 'Content position',
defaultValue: 'center center',
},
],
},
],
};