forked from Weaverse/aspen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewsletter.tsx
228 lines (219 loc) · 6.12 KB
/
newsletter.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import type {
HydrogenComponentProps,
HydrogenComponentSchema,
} from '@weaverse/hydrogen';
import type {CSSProperties} from 'react';
import React, {forwardRef, useState} from 'react';
import clsx from 'clsx';
import {IconArrowInput} from '~/components';
type NewsLetterData = {
contentAlignment: string;
sectionHeight: string;
backgroundColor: string;
subheading: string;
heading: string;
buttonLabel: string;
buttonLink: string;
openInNewTab: boolean;
buttonStyle: string;
topPadding: string;
bottomPadding: string;
};
type NewsletterProps = HydrogenComponentProps & NewsLetterData;
let NewsLetter = forwardRef<HTMLElement, NewsletterProps>((props, ref) => {
let {
loaderData,
contentAlignment,
sectionHeight,
backgroundColor,
subheading,
heading,
buttonLabel,
buttonLink,
openInNewTab,
buttonStyle,
topPadding,
bottomPadding,
...rest
} = props;
let sectionStyle: CSSProperties = {
alignItems: `${contentAlignment}`,
'--section-height': `${sectionHeight}px`,
backgroundColor: `${backgroundColor}`,
paddingTop: `${topPadding}px`,
paddingBottom: `${bottomPadding}px`,
} as CSSProperties;
const [emailValue, setEmailValue] = useState('');
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setEmailValue(event.target.value);
};
const handleSubmit = () => {
// TODO: create an API route to handle the email submission
};
return (
<section
ref={ref}
{...rest}
className="w-full px-10 h-[var(--section-height)] flex flex-col justify-center sm-max:px-8"
style={sectionStyle}
>
<div className="text-center w-1/2 flex flex-col gap-5 sm-max:w-full">
{subheading && <p className="text-2xl font-medium">{subheading}</p>}
{heading && <p className="text-base font-normal">{heading}</p>}
<div className="flex w-full mt-3 gap-2 justify-center items-center">
<div className="flex justify-center items-center relative sm-max:w-4/5">
<input
type="text"
className="pr-8 pl-3 py-2 rounded border-2 border-solid border-gray-400 font-normal w-full"
placeholder="Enter your email"
value={emailValue}
onChange={handleInputChange}
/>
<IconArrowInput
className="absolute z-10 cursor-pointer right-2 !w-4 !h-4"
onClick={handleSubmit}
/>
</div>
{buttonLabel && (
<a
href={buttonLink}
target={openInNewTab ? '_blank' : ''}
className={clsx(
'flex cursor-pointer py-2 px-4 rounded sm-max:px-3',
buttonStyle,
)}
rel="noreferrer"
>
{buttonLabel}
</a>
)}
</div>
</div>
</section>
);
});
export default NewsLetter;
export let schema: HydrogenComponentSchema = {
type: 'news-letter',
title: 'News letter',
toolbar: ['general-settings', ['duplicate', 'delete']],
inspector: [
{
group: 'Text',
inputs: [
{
type: 'color',
name: 'backgroundColor',
label: 'Background color',
defaultValue: '#F7F7F7',
},
{
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: 'text',
name: 'subheading',
label: 'Subheading',
defaultValue: 'Subscribe to our Newsletter',
},
{
type: 'text',
name: 'heading',
label: 'Heading',
defaultValue: 'Subscribe and save more',
},
{
type: 'text',
label: 'Button label',
name: 'buttonLabel',
placeholder: 'Button label',
defaultValue: '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 hover:bg-white border-2 border-solid hover:border-gray-900 hover:text-black bg-black text-white',
},
{
type: 'range',
name: 'sectionHeight',
label: 'Section height',
defaultValue: 400,
configs: {
min: 300,
max: 700,
step: 10,
unit: 'px',
},
},
{
type: 'range',
name: 'topPadding',
label: 'Top padding',
defaultValue: 10,
configs: {
min: 0,
max: 100,
step: 1,
unit: 'px',
},
},
{
type: 'range',
name: 'bottomPadding',
label: 'Bottom padding',
defaultValue: 10,
configs: {
min: 0,
max: 100,
step: 1,
unit: 'px',
},
},
],
},
],
};