forked from Weaverse/aspen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.tsx
210 lines (204 loc) · 5.62 KB
/
map.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import type {
HydrogenComponentProps,
HydrogenComponentSchema,
} from '@weaverse/hydrogen';
import type {CSSProperties} from 'react';
import {forwardRef} from 'react';
import clsx from 'clsx';
import {IconMapBlank} from '~/components';
interface MapProps extends HydrogenComponentProps {
heading: string;
textColor: string;
contentAlignment: string;
descriptionText: string;
address: string;
buttonLabel: string;
buttonLink: string;
openInNewTab: boolean;
sectionHeight: string;
buttonStyle: string;
}
let Map = forwardRef<HTMLElement, MapProps>((props, ref) => {
let {
heading,
textColor,
contentAlignment,
descriptionText,
address,
buttonLabel,
buttonLink,
openInNewTab,
sectionHeight,
buttonStyle,
...rest
} = props;
let sectionStyle: CSSProperties = {
'--section-height': `${sectionHeight}px`,
justifyContent: `${contentAlignment}`,
} as CSSProperties;
return (
<section
ref={ref}
{...rest}
className="flex relative p-10 overflow-hidden h-[var(--section-height)]"
style={sectionStyle}
>
<div className="absolute inset-0">
{address ? (
<iframe
className="w-full h-full object-cover"
title="map"
src={`https://maps.google.com/maps?t=m&q=${address}&ie=UTF8&&output=embed`}
></iframe>
) : (
<div className="absolute inset-0 flex items-center justify-center bg-gray-200">
<IconMapBlank
viewBox="0 0 230 230"
className="!w-56 !h-56 opacity-20"
/>
</div>
)}
</div>
<div className="relative bg-white rounded-3xl p-8 border-2 border-solid border-gray-200 h-fit w-80">
<div className="z-10 flex flex-col gap-6">
{heading && (
<p className="text-2xl font-bold" style={{color: textColor}}>
{heading}
</p>
)}
{address && (
<p className="text-sm font-normal" style={{color: textColor}}>
{address}
</p>
)}
{descriptionText && (
<p className="text-sm font-normal" style={{color: textColor}}>
{descriptionText}
</p>
)}
{buttonLabel && (
<a
href={buttonLink}
target={openInNewTab ? '_blank' : ''}
className={clsx(
'px-4 py-3 w-fit cursor-pointer rounded inline-block',
buttonStyle,
)}
rel="noreferrer"
>
{buttonLabel}
</a>
)}
</div>
</div>
</section>
);
});
export default Map;
export let schema: HydrogenComponentSchema = {
type: 'map',
title: 'Map',
toolbar: ['general-settings', ['duplicate', 'delete']],
inspector: [
{
group: 'Map',
inputs: [
{
type: 'text',
name: 'heading',
label: 'Heading',
defaultValue: 'Our store address',
},
{
type: 'color',
name: 'textColor',
label: 'Text color',
defaultValue: '#333333',
},
{
type: 'toggle-group',
label: 'Content alignment',
name: 'contentAlignment',
configs: {
options: [
{label: 'Left', value: 'flex-start'},
{label: 'Center', value: 'center'},
{label: 'Right', value: 'flex-end'},
],
},
defaultValue: 'center',
},
{
type: 'map-autocomplete',
name: 'address',
label: 'Map address',
defaultValue: 'San Francisco, CA',
},
{
type: 'textarea',
label: 'Description text',
name: 'descriptionText',
defaultValue:
'Pair large text with an image to tell a story, explain a detail about your product, or describe a new promotion.',
},
{
type: 'text',
label: 'Button label',
name: 'buttonLabel',
placeholder: 'Button label',
defaultValue: 'Optional button',
},
{
type: 'text',
label: 'Button link',
name: 'buttonLink',
placeholder: 'Button link',
},
{
type: 'switch',
name: 'openInNewTab',
label: 'Open in new tab',
defaultValue: true,
},
{
type: 'toggle-group',
label: 'Button style',
name: 'buttonStyle',
configs: {
options: [
{
label: '1',
value:
'transition hover:bg-white border-2 border-solid hover:border-gray-900 hover:text-black bg-black text-white',
},
{
label: '2',
value:
'transition bg-white border-2 border-solid border-gray-900 text-black hover:bg-black hover:text-white',
},
{
label: '3',
value:
'transition hover:bg-white border-2 border-solid border-white hover:text-black bg-gray-200 text-white',
},
],
},
defaultValue:
'transition bg-white border-2 border-solid border-gray-900 text-black hover:bg-black hover:text-white',
},
{
type: 'range',
name: 'sectionHeight',
label: 'Section height',
defaultValue: 500,
configs: {
min: 400,
max: 900,
step: 10,
unit: 'px',
},
},
],
},
],
};