forked from Weaverse/aspen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hero.tsx
101 lines (95 loc) · 2.64 KB
/
hero.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
import type {
ComponentLoaderArgs,
HydrogenComponentProps,
HydrogenComponentSchema,
} from '@weaverse/hydrogen';
import {forwardRef} from 'react';
import type {SeoCollectionContentQuery} from 'storefrontapi.generated';
import {Hero} from '~/components/Hero';
import {HOMEPAGE_SEO_QUERY} from '~/data/queries';
type HeroSectionData = {
collectionHandle: string;
height: 'full';
top: boolean;
loading: HTMLImageElement['loading'];
};
let HeroSection = forwardRef<
HTMLElement,
HydrogenComponentProps<Awaited<ReturnType<typeof loader>>> & HeroSectionData
>((props, ref) => {
let {loaderData, height, loading, top, collectionHandle, ...rest} = props;
if (loaderData) {
return (
<section ref={ref} {...rest}>
<Hero height={height} loading={loading} top={top} {...loaderData} />
</section>
);
}
return <section ref={ref} {...rest} />;
});
export default HeroSection;
export let loader = async (args: ComponentLoaderArgs<HeroSectionData>) => {
let {weaverse, data} = args;
let {hero} = await weaverse.storefront.query<SeoCollectionContentQuery>(
HOMEPAGE_SEO_QUERY,
{
variables: {handle: data.collectionHandle || 'frontpage'},
},
);
return hero;
};
export let schema: HydrogenComponentSchema = {
type: 'hero',
title: 'Hero',
inspector: [
{
group: 'Hero',
inputs: [
{
type: 'collection',
name: 'collectionHandle',
label: 'Preview',
defaultValue: 'frontpage',
},
{
type: 'toggle-group',
name: 'loading',
label: 'Background image loading',
defaultValue: 'eager',
configs: {
options: [
{label: 'Eager', value: 'eager'},
{
label: 'Lazy',
value: 'lazy',
},
],
},
helpText:
'Learn more about <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading" target="_blank" rel="noopener noreferrer">image loading strategies</a>.',
},
{
type: 'select',
name: 'height',
label: 'Height',
configs: {
options: [
{label: 'Auto', value: 'auto'},
{label: 'Fullscreen', value: 'full'},
],
},
defaultValue: 'auto',
},
{
type: 'switch',
name: 'top',
label: 'Top',
defaultValue: true,
helpText:
'Push the hero to the top of the page by adding a negative margin.',
},
],
},
],
toolbar: ['general-settings', ['duplicate', 'delete']],
};