@nuvler/cli 0.5.9 → 0.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/api/theme-context.js.map +1 -1
- package/dist/commands/theme/create.js +1 -1
- package/dist/commands/theme/upgrade.js +2 -1
- package/dist/commands/theme/upgrade.js.map +1 -1
- package/dist/migrate/generator.js +21 -10
- package/dist/migrate/generator.js.map +1 -1
- package/dist/migrate/transformer.js +2 -1
- package/dist/migrate/transformer.js.map +1 -1
- package/dist/nuvler.js +118 -16
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-atelier/package.json +3 -3
- package/dist/templates/nuvler-atelier/src/definition.tsx +16 -8
- package/dist/templates/nuvler-atelier/src/theme.css +3 -0
- package/dist/templates/nuvler-atelier/src/theme.tsx +24 -4
- package/dist/templates/nuvler-default/README.md +2 -2
- package/dist/templates/nuvler-default/nuvler.theme.json +22 -4
- package/dist/templates/nuvler-default/package.json +6 -5
- package/dist/templates/nuvler-default/scripts/verify-release.mjs +34 -0
- package/dist/templates/nuvler-default/src/carousel-frame.tsx +125 -20
- package/dist/templates/nuvler-default/src/header-interactions.tsx +2 -2
- package/dist/templates/nuvler-default/src/header.tsx +1 -1
- package/dist/templates/nuvler-default/src/home.tsx +700 -76
- package/dist/templates/nuvler-default/src/mini-banners.tsx +45 -0
- package/dist/templates/nuvler-default/src/product-carousel.tsx +2 -2
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +7 -2
- package/dist/templates/nuvler-default/src/product-detail.tsx +3 -1
- package/dist/templates/nuvler-default/src/products.tsx +6 -5
- package/dist/templates/nuvler-default/src/shared.tsx +9 -1
- package/dist/templates/nuvler-default/src/theme-component.tsx +18 -4
- package/dist/templates/nuvler-default/src/theme.css +201 -7
- package/dist/templates/starter/package.json +2 -2
- package/dist/templates/starter/src/definition.tsx +5 -5
- package/dist/templates/starter/src/theme.tsx +2 -2
- package/package.json +3 -3
- package/preview-host/package.json +1 -1
- package/preview-host/src/fallback-context.json +1 -0
- package/preview-host/vendor/theme-runtime/default-theme.tsx +42 -6
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { useState, type FormEvent } from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
HomeProps,
|
|
4
|
+
ThemeContactSubmissionInput,
|
|
5
|
+
ThemeEditorialItem,
|
|
6
|
+
ThemeHomeSection,
|
|
7
|
+
ThemeImage,
|
|
8
|
+
ThemeSite,
|
|
9
|
+
} from "@nuvler/theme-sdk";
|
|
3
10
|
import { BannerCarousel, type ThemeBanner } from "./banner-carousel.js";
|
|
11
|
+
import { MiniBanners } from "./mini-banners.js";
|
|
4
12
|
import { ProductCarousel } from "./product-carousel.js";
|
|
13
|
+
import { BrandsCarouselFrame } from "./carousel-frame.js";
|
|
5
14
|
import { ProductGrid } from "./products.js";
|
|
6
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
categoryUrl,
|
|
17
|
+
ThemeImageView,
|
|
18
|
+
type ThemeImageComponent,
|
|
19
|
+
} from "./shared.js";
|
|
7
20
|
|
|
8
21
|
function text(data: Record<string, unknown>, key: string, fallback = "") {
|
|
9
22
|
const value = data[key];
|
|
@@ -15,21 +28,48 @@ function limit(data: Record<string, unknown>) {
|
|
|
15
28
|
return Number.isInteger(value) ? Math.min(12, Math.max(1, value)) : 6;
|
|
16
29
|
}
|
|
17
30
|
|
|
18
|
-
function
|
|
31
|
+
function brandsGridColumns(data: Record<string, unknown>) {
|
|
32
|
+
const value = Number(data.gridColumns);
|
|
33
|
+
|
|
34
|
+
return Number.isInteger(value) ? Math.min(6, Math.max(1, value)) : 5;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function record(
|
|
38
|
+
data: Record<string, unknown>,
|
|
39
|
+
key: string,
|
|
40
|
+
): Record<string, unknown> {
|
|
19
41
|
const value = data[key];
|
|
20
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
42
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
43
|
+
? (value as Record<string, unknown>)
|
|
44
|
+
: {};
|
|
21
45
|
}
|
|
22
46
|
|
|
23
|
-
function records(
|
|
47
|
+
function records(
|
|
48
|
+
data: Record<string, unknown>,
|
|
49
|
+
key: string,
|
|
50
|
+
): Record<string, unknown>[] {
|
|
24
51
|
const value = data[key];
|
|
25
52
|
return Array.isArray(value)
|
|
26
|
-
? value.filter(
|
|
53
|
+
? value.filter(
|
|
54
|
+
(item): item is Record<string, unknown> =>
|
|
55
|
+
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
|
56
|
+
)
|
|
27
57
|
: [];
|
|
28
58
|
}
|
|
29
59
|
|
|
30
60
|
function productCategory(data: Record<string, unknown>) {
|
|
31
61
|
const value = text(data, "categorySlug").toLocaleLowerCase("pt-BR");
|
|
32
|
-
if (
|
|
62
|
+
if (
|
|
63
|
+
[
|
|
64
|
+
"",
|
|
65
|
+
"all",
|
|
66
|
+
"todos",
|
|
67
|
+
"todas",
|
|
68
|
+
"all-categories",
|
|
69
|
+
"todas-as-categorias",
|
|
70
|
+
].includes(value)
|
|
71
|
+
)
|
|
72
|
+
return "";
|
|
33
73
|
return value;
|
|
34
74
|
}
|
|
35
75
|
|
|
@@ -45,16 +85,21 @@ function imageValue(value: unknown): ThemeImage | null {
|
|
|
45
85
|
};
|
|
46
86
|
}
|
|
47
87
|
|
|
48
|
-
function sectionImage(
|
|
88
|
+
function sectionImage(
|
|
89
|
+
data: Record<string, unknown>,
|
|
90
|
+
fallbackAlt: string,
|
|
91
|
+
): ThemeImage | null {
|
|
49
92
|
const enriched = imageValue(data.image);
|
|
50
93
|
if (enriched) return enriched;
|
|
51
94
|
const imageUrl = text(data, "imageUrl");
|
|
52
|
-
return imageUrl
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
95
|
+
return imageUrl
|
|
96
|
+
? {
|
|
97
|
+
url: imageUrl,
|
|
98
|
+
alt: text(data, "imageAlt", fallbackAlt),
|
|
99
|
+
width: null,
|
|
100
|
+
height: null,
|
|
101
|
+
}
|
|
102
|
+
: null;
|
|
58
103
|
}
|
|
59
104
|
|
|
60
105
|
function banners(data: Record<string, unknown>): ThemeBanner[] {
|
|
@@ -63,51 +108,263 @@ function banners(data: Record<string, unknown>): ThemeBanner[] {
|
|
|
63
108
|
if (!entry || typeof entry !== "object") return [];
|
|
64
109
|
const item = entry as Record<string, unknown>;
|
|
65
110
|
const image = imageValue(item.image);
|
|
66
|
-
const imageUrl =
|
|
111
|
+
const imageUrl =
|
|
112
|
+
image?.url || (typeof item.imageUrl === "string" ? item.imageUrl : "");
|
|
113
|
+
if (!imageUrl) return [];
|
|
114
|
+
return [
|
|
115
|
+
{
|
|
116
|
+
imageUrl,
|
|
117
|
+
image,
|
|
118
|
+
imageAlt: typeof item.imageAlt === "string" ? item.imageAlt : undefined,
|
|
119
|
+
mobileImageUrl:
|
|
120
|
+
typeof item.mobileImageUrl === "string"
|
|
121
|
+
? item.mobileImageUrl
|
|
122
|
+
: undefined,
|
|
123
|
+
mobileImage: imageValue(item.mobileImage),
|
|
124
|
+
mobileImageAlt:
|
|
125
|
+
typeof item.mobileImageAlt === "string"
|
|
126
|
+
? item.mobileImageAlt
|
|
127
|
+
: undefined,
|
|
128
|
+
title: typeof item.title === "string" ? item.title : undefined,
|
|
129
|
+
description:
|
|
130
|
+
typeof item.description === "string" ? item.description : undefined,
|
|
131
|
+
buttonLabel:
|
|
132
|
+
typeof item.buttonLabel === "string" ? item.buttonLabel : undefined,
|
|
133
|
+
buttonUrl:
|
|
134
|
+
typeof item.buttonUrl === "string" ? item.buttonUrl : undefined,
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function miniBanners(data: Record<string, unknown>) {
|
|
141
|
+
return records(data, "items").flatMap((item) => {
|
|
142
|
+
const image = imageValue(item.image);
|
|
143
|
+
const imageUrl = image?.url || text(item, "imageUrl");
|
|
67
144
|
if (!imageUrl) return [];
|
|
68
|
-
return [
|
|
145
|
+
return [
|
|
146
|
+
{
|
|
147
|
+
image,
|
|
148
|
+
imageUrl,
|
|
149
|
+
imageAlt: text(item, "imageAlt") || undefined,
|
|
150
|
+
title: text(item, "title") || undefined,
|
|
151
|
+
linkLabel: text(item, "linkLabel") || undefined,
|
|
152
|
+
link: text(item, "link") || undefined,
|
|
153
|
+
},
|
|
154
|
+
];
|
|
69
155
|
});
|
|
70
156
|
}
|
|
71
157
|
|
|
72
|
-
function Heading({
|
|
158
|
+
function Heading({
|
|
159
|
+
data,
|
|
160
|
+
href,
|
|
161
|
+
}: {
|
|
162
|
+
data: Record<string, unknown>;
|
|
163
|
+
href: string;
|
|
164
|
+
}) {
|
|
73
165
|
const eyebrow = text(data, "eyebrow");
|
|
74
166
|
const title = text(data, "title");
|
|
75
167
|
const actionLabel = text(data, "buttonLabel");
|
|
76
168
|
const actionHref = text(data, "buttonUrl", href);
|
|
77
169
|
if (!eyebrow && !title && !actionLabel) return null;
|
|
78
|
-
return
|
|
170
|
+
return (
|
|
171
|
+
<div className="section-heading">
|
|
172
|
+
<div>
|
|
173
|
+
{eyebrow && <span>{eyebrow}</span>}
|
|
174
|
+
{title && <h2>{title}</h2>}
|
|
175
|
+
</div>
|
|
176
|
+
{actionLabel && actionHref && <a href={actionHref}>{actionLabel}</a>}
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
79
179
|
}
|
|
80
180
|
|
|
81
|
-
function Hero({
|
|
181
|
+
function Hero({
|
|
182
|
+
section,
|
|
183
|
+
priority,
|
|
184
|
+
ImageComponent = ThemeImageView,
|
|
185
|
+
}: {
|
|
186
|
+
section: ThemeHomeSection;
|
|
187
|
+
priority: boolean;
|
|
188
|
+
ImageComponent?: ThemeImageComponent;
|
|
189
|
+
}) {
|
|
82
190
|
const title = text(section.data, "title");
|
|
83
191
|
const description = text(section.data, "description");
|
|
84
192
|
const eyebrow = text(section.data, "eyebrow");
|
|
85
193
|
const buttonLabel = text(section.data, "buttonLabel");
|
|
86
194
|
const buttonUrl = text(section.data, "buttonUrl");
|
|
87
195
|
const image = sectionImage(section.data, title);
|
|
88
|
-
const copy =
|
|
89
|
-
|
|
90
|
-
|
|
196
|
+
const copy = (
|
|
197
|
+
<div className="hero-copy">
|
|
198
|
+
{eyebrow && <span className="hero-eyebrow">{eyebrow}</span>}
|
|
199
|
+
{title && <h1>{title}</h1>}
|
|
200
|
+
{description && <p>{description}</p>}
|
|
201
|
+
{buttonLabel && buttonUrl && (
|
|
202
|
+
<div className="hero-actions">
|
|
203
|
+
<a className="button button-primary" href={buttonUrl}>
|
|
204
|
+
{buttonLabel}
|
|
205
|
+
</a>
|
|
206
|
+
</div>
|
|
207
|
+
)}
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
if (image)
|
|
211
|
+
return (
|
|
212
|
+
<section className="hero-section hero-section-image">
|
|
213
|
+
<ImageComponent
|
|
214
|
+
image={image}
|
|
215
|
+
fallbackAlt={title}
|
|
216
|
+
className="hero-background-image"
|
|
217
|
+
priority={priority}
|
|
218
|
+
sizes="100vw"
|
|
219
|
+
fallbackWidth={1600}
|
|
220
|
+
fallbackHeight={700}
|
|
221
|
+
/>
|
|
222
|
+
<div className="hero-background-overlay" aria-hidden="true" />
|
|
223
|
+
<div className="store-container hero-image-content">{copy}</div>
|
|
224
|
+
</section>
|
|
225
|
+
);
|
|
226
|
+
return (
|
|
227
|
+
<section className="hero-section">
|
|
228
|
+
<div className="store-container hero-grid">
|
|
229
|
+
{copy}
|
|
230
|
+
<div className="hero-art" aria-hidden="true">
|
|
231
|
+
<div className="hero-orbit hero-orbit-one" />
|
|
232
|
+
<div className="hero-orbit hero-orbit-two" />
|
|
233
|
+
<div className="hero-seven">7</div>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</section>
|
|
237
|
+
);
|
|
91
238
|
}
|
|
92
239
|
|
|
93
|
-
function EditorialGrid({
|
|
94
|
-
|
|
95
|
-
|
|
240
|
+
function EditorialGrid({
|
|
241
|
+
items,
|
|
242
|
+
basePath,
|
|
243
|
+
ImageComponent = ThemeImageView,
|
|
244
|
+
}: {
|
|
245
|
+
items: ThemeEditorialItem[];
|
|
246
|
+
basePath: string;
|
|
247
|
+
ImageComponent?: ThemeImageComponent;
|
|
248
|
+
}) {
|
|
249
|
+
if (!items.length)
|
|
250
|
+
return (
|
|
251
|
+
<div className="empty-state">
|
|
252
|
+
<span>7</span>
|
|
253
|
+
<h2>Nenhum conteúdo publicado</h2>
|
|
254
|
+
<p>As publicações aparecerão aqui quando estiverem disponíveis.</p>
|
|
255
|
+
</div>
|
|
256
|
+
);
|
|
257
|
+
return (
|
|
258
|
+
<div className="editorial-grid">
|
|
259
|
+
{items.map((item) => (
|
|
260
|
+
<article className="editorial-card" key={item.slug}>
|
|
261
|
+
<a className="editorial-card-image" href={`${basePath}/${item.slug}`}>
|
|
262
|
+
<ImageComponent
|
|
263
|
+
image={item.image || item.thumbnail || item.coverImage}
|
|
264
|
+
fallbackAlt={item.title}
|
|
265
|
+
sizes="(max-width: 720px) 92vw, 33vw"
|
|
266
|
+
fallbackWidth={720}
|
|
267
|
+
fallbackHeight={480}
|
|
268
|
+
/>
|
|
269
|
+
</a>
|
|
270
|
+
<div className="editorial-card-content">
|
|
271
|
+
{(item.category?.title || item.category?.name) && (
|
|
272
|
+
<span>{item.category.title || item.category.name}</span>
|
|
273
|
+
)}
|
|
274
|
+
<h2>
|
|
275
|
+
<a href={`${basePath}/${item.slug}`}>{item.title}</a>
|
|
276
|
+
</h2>
|
|
277
|
+
<p>{item.description}</p>
|
|
278
|
+
<a className="text-link" href={`${basePath}/${item.slug}`}>
|
|
279
|
+
Saiba mais <span>→</span>
|
|
280
|
+
</a>
|
|
281
|
+
</div>
|
|
282
|
+
</article>
|
|
283
|
+
))}
|
|
284
|
+
</div>
|
|
285
|
+
);
|
|
96
286
|
}
|
|
97
287
|
|
|
98
|
-
function TextSection({
|
|
288
|
+
function TextSection({
|
|
289
|
+
section,
|
|
290
|
+
ImageComponent = ThemeImageView,
|
|
291
|
+
}: {
|
|
292
|
+
section: ThemeHomeSection;
|
|
293
|
+
ImageComponent?: ThemeImageComponent;
|
|
294
|
+
}) {
|
|
99
295
|
const title = text(section.data, "title");
|
|
100
|
-
const description = text(
|
|
296
|
+
const description = text(
|
|
297
|
+
section.data,
|
|
298
|
+
"description",
|
|
299
|
+
text(section.data, "text"),
|
|
300
|
+
);
|
|
101
301
|
const image = sectionImage(section.data, title);
|
|
102
|
-
if (section.type === "image-text")
|
|
103
|
-
|
|
302
|
+
if (section.type === "image-text")
|
|
303
|
+
return (
|
|
304
|
+
<section className="store-section image-text-section">
|
|
305
|
+
<div
|
|
306
|
+
className="store-container image-text-layout"
|
|
307
|
+
data-position={
|
|
308
|
+
section.data.imagePosition === "right" ? "right" : "left"
|
|
309
|
+
}
|
|
310
|
+
>
|
|
311
|
+
{image && (
|
|
312
|
+
<div className="image-text-media">
|
|
313
|
+
<ImageComponent
|
|
314
|
+
image={image}
|
|
315
|
+
fallbackAlt={title}
|
|
316
|
+
sizes="(max-width: 900px) 100vw, 50vw"
|
|
317
|
+
fallbackWidth={800}
|
|
318
|
+
fallbackHeight={600}
|
|
319
|
+
/>
|
|
320
|
+
</div>
|
|
321
|
+
)}
|
|
322
|
+
<div className="image-text-copy">
|
|
323
|
+
{text(section.data, "eyebrow") && (
|
|
324
|
+
<span>{text(section.data, "eyebrow")}</span>
|
|
325
|
+
)}
|
|
326
|
+
{title && <h2>{title}</h2>}
|
|
327
|
+
{description && <p>{description}</p>}
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
</section>
|
|
331
|
+
);
|
|
332
|
+
return (
|
|
333
|
+
<section className="store-section editorial-section">
|
|
334
|
+
<div className="store-container editorial-content">
|
|
335
|
+
{text(section.data, "eyebrow") && (
|
|
336
|
+
<span>{text(section.data, "eyebrow")}</span>
|
|
337
|
+
)}
|
|
338
|
+
{title && <h2>{title}</h2>}
|
|
339
|
+
{description && <p>{description}</p>}
|
|
340
|
+
{section.type === "cta" &&
|
|
341
|
+
text(section.data, "buttonLabel") &&
|
|
342
|
+
text(section.data, "buttonUrl") && (
|
|
343
|
+
<a
|
|
344
|
+
className="button button-primary"
|
|
345
|
+
href={text(section.data, "buttonUrl")}
|
|
346
|
+
>
|
|
347
|
+
{text(section.data, "buttonLabel")}
|
|
348
|
+
</a>
|
|
349
|
+
)}
|
|
350
|
+
</div>
|
|
351
|
+
</section>
|
|
352
|
+
);
|
|
104
353
|
}
|
|
105
354
|
|
|
106
|
-
function ContactForm({
|
|
355
|
+
function ContactForm({
|
|
356
|
+
section,
|
|
357
|
+
submitContact,
|
|
358
|
+
}: {
|
|
359
|
+
section: ThemeHomeSection;
|
|
360
|
+
submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown>;
|
|
361
|
+
}) {
|
|
107
362
|
const props = record(section.data, "props");
|
|
108
363
|
const configured = records(props, "fields");
|
|
109
364
|
const fields = configured;
|
|
110
|
-
const [status, setStatus] = useState<
|
|
365
|
+
const [status, setStatus] = useState<
|
|
366
|
+
"idle" | "sending" | "success" | "error"
|
|
367
|
+
>("idle");
|
|
111
368
|
const [error, setError] = useState("");
|
|
112
369
|
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
113
370
|
event.preventDefault();
|
|
@@ -127,70 +384,437 @@ function ContactForm({ section, submitContact }: { section: ThemeHomeSection; su
|
|
|
127
384
|
return;
|
|
128
385
|
}
|
|
129
386
|
const entries = form.getAll(key).map(String);
|
|
130
|
-
values[key] = entries.length > 1 ? entries : entries[0] ?? "";
|
|
387
|
+
values[key] = entries.length > 1 ? entries : (entries[0] ?? "");
|
|
131
388
|
});
|
|
132
389
|
setStatus("sending");
|
|
133
390
|
setError("");
|
|
134
391
|
try {
|
|
135
|
-
await submitContact({
|
|
392
|
+
await submitContact({
|
|
393
|
+
formKey: text(section.data, "componentKey", "contact-form"),
|
|
394
|
+
sectionId: section.id,
|
|
395
|
+
values,
|
|
396
|
+
pathname:
|
|
397
|
+
typeof window === "undefined" ? undefined : window.location.pathname,
|
|
398
|
+
});
|
|
136
399
|
formElement.reset();
|
|
137
400
|
setStatus("success");
|
|
138
401
|
} catch (cause) {
|
|
139
402
|
setStatus("error");
|
|
140
|
-
setError(
|
|
403
|
+
setError(
|
|
404
|
+
cause instanceof Error
|
|
405
|
+
? cause.message
|
|
406
|
+
: "Não foi possível enviar o contato.",
|
|
407
|
+
);
|
|
141
408
|
}
|
|
142
409
|
};
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
410
|
+
return (
|
|
411
|
+
<section className="store-section theme-component-section contact-form-section">
|
|
412
|
+
<div className="store-container contact-form-layout">
|
|
413
|
+
<div className="contact-form-copy">
|
|
414
|
+
{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
|
|
415
|
+
{text(props, "title") && <h2>{text(props, "title")}</h2>}
|
|
416
|
+
{text(props, "description") && <p>{text(props, "description")}</p>}
|
|
417
|
+
</div>
|
|
418
|
+
<form className="contact-form" onSubmit={(event) => void submit(event)}>
|
|
419
|
+
{fields.map((field) => {
|
|
420
|
+
const key = text(field, "key");
|
|
421
|
+
const type = text(field, "type", "text");
|
|
422
|
+
const label = text(field, "label", key);
|
|
423
|
+
const required = field.required === true;
|
|
424
|
+
if (!key) return null;
|
|
425
|
+
if (type === "checkbox")
|
|
426
|
+
return (
|
|
427
|
+
<label
|
|
428
|
+
className="contact-form-wide contact-form-checkbox"
|
|
429
|
+
key={key}
|
|
430
|
+
>
|
|
431
|
+
<input
|
|
432
|
+
name={key}
|
|
433
|
+
required={required}
|
|
434
|
+
type="checkbox"
|
|
435
|
+
value="true"
|
|
436
|
+
/>
|
|
437
|
+
<span>
|
|
438
|
+
{label}
|
|
439
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
440
|
+
</span>
|
|
441
|
+
</label>
|
|
442
|
+
);
|
|
443
|
+
if (type === "select")
|
|
444
|
+
return (
|
|
445
|
+
<label key={key}>
|
|
446
|
+
<span>
|
|
447
|
+
{label}
|
|
448
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
449
|
+
</span>
|
|
450
|
+
<select name={key} required={required}>
|
|
451
|
+
{records(field, "options").map((option) => (
|
|
452
|
+
<option
|
|
453
|
+
key={text(option, "value")}
|
|
454
|
+
value={text(option, "value")}
|
|
455
|
+
>
|
|
456
|
+
{text(option, "label", text(option, "value"))}
|
|
457
|
+
</option>
|
|
458
|
+
))}
|
|
459
|
+
</select>
|
|
460
|
+
</label>
|
|
461
|
+
);
|
|
462
|
+
return (
|
|
463
|
+
<label
|
|
464
|
+
className={type === "textarea" ? "contact-form-wide" : ""}
|
|
465
|
+
key={key}
|
|
466
|
+
>
|
|
467
|
+
<span>
|
|
468
|
+
{label}
|
|
469
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
470
|
+
</span>
|
|
471
|
+
{type === "textarea" ? (
|
|
472
|
+
<textarea
|
|
473
|
+
name={key}
|
|
474
|
+
placeholder={text(field, "placeholder")}
|
|
475
|
+
required={required}
|
|
476
|
+
rows={5}
|
|
477
|
+
/>
|
|
478
|
+
) : (
|
|
479
|
+
<input
|
|
480
|
+
name={key}
|
|
481
|
+
placeholder={text(field, "placeholder")}
|
|
482
|
+
required={required}
|
|
483
|
+
type={
|
|
484
|
+
["email", "tel", "url", "number"].includes(type)
|
|
485
|
+
? type
|
|
486
|
+
: "text"
|
|
487
|
+
}
|
|
488
|
+
/>
|
|
489
|
+
)}
|
|
490
|
+
</label>
|
|
491
|
+
);
|
|
492
|
+
})}
|
|
493
|
+
<div className="contact-form-wide">
|
|
494
|
+
<button
|
|
495
|
+
className="button button-primary"
|
|
496
|
+
disabled={status === "sending"}
|
|
497
|
+
type="submit"
|
|
498
|
+
>
|
|
499
|
+
{status === "sending" ? "" : text(props, "submitLabel")}
|
|
500
|
+
</button>
|
|
501
|
+
{status === "success" && text(props, "successMessage") && (
|
|
502
|
+
<p className="contact-form-feedback" role="status">
|
|
503
|
+
{text(props, "successMessage")}
|
|
504
|
+
</p>
|
|
505
|
+
)}
|
|
506
|
+
{status === "error" && (
|
|
507
|
+
<p
|
|
508
|
+
className="contact-form-feedback contact-form-error"
|
|
509
|
+
role="alert"
|
|
510
|
+
>
|
|
511
|
+
{error}
|
|
512
|
+
</p>
|
|
513
|
+
)}
|
|
514
|
+
</div>
|
|
515
|
+
</form>
|
|
516
|
+
</div>
|
|
517
|
+
</section>
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function ThemeComponent({
|
|
522
|
+
section,
|
|
523
|
+
submitContact,
|
|
524
|
+
ImageComponent = ThemeImageView,
|
|
525
|
+
}: {
|
|
526
|
+
section: ThemeHomeSection;
|
|
527
|
+
submitContact?: HomeProps["submitContact"];
|
|
528
|
+
ImageComponent?: ThemeImageComponent;
|
|
529
|
+
}) {
|
|
156
530
|
const componentKey = text(section.data, "componentKey");
|
|
157
531
|
const props = record(section.data, "props");
|
|
158
|
-
if (componentKey === "contact-form" || componentKey.endsWith("-form"))
|
|
532
|
+
if (componentKey === "contact-form" || componentKey.endsWith("-form"))
|
|
533
|
+
return <ContactForm section={section} submitContact={submitContact} />;
|
|
159
534
|
if (componentKey === "benefits" || componentKey === "brands") {
|
|
160
535
|
const items = records(props, "items");
|
|
161
536
|
if (!items.length) return null;
|
|
162
537
|
const isBrands = componentKey === "brands";
|
|
163
|
-
|
|
538
|
+
const gridColumns = isBrands ? brandsGridColumns(props) : undefined;
|
|
539
|
+
const brandsLayout =
|
|
540
|
+
text(props, "layout", "grid") === "carousel" ? "carousel" : "grid";
|
|
541
|
+
|
|
542
|
+
const renderedItems = items.map((item, index) => {
|
|
543
|
+
const title = text(item, "title", text(item, "value"));
|
|
544
|
+
const image = sectionImage(item, title);
|
|
545
|
+
const href = text(item, "url");
|
|
546
|
+
const content = (
|
|
547
|
+
<>
|
|
548
|
+
{isBrands && image ? (
|
|
549
|
+
<ImageComponent
|
|
550
|
+
image={image}
|
|
551
|
+
fallbackAlt={title}
|
|
552
|
+
sizes="160px"
|
|
553
|
+
fallbackWidth={320}
|
|
554
|
+
fallbackHeight={160}
|
|
555
|
+
/>
|
|
556
|
+
) : null}
|
|
557
|
+
{!isBrands && (
|
|
558
|
+
<span className="home-benefit-index" aria-hidden="true">
|
|
559
|
+
{String(index + 1).padStart(2, "0")}
|
|
560
|
+
</span>
|
|
561
|
+
)}
|
|
562
|
+
{title && <strong>{title}</strong>}
|
|
563
|
+
{text(item, "description") && <p>{text(item, "description")}</p>}
|
|
564
|
+
</>
|
|
565
|
+
);
|
|
566
|
+
return href ? (
|
|
567
|
+
<a href={href} key={`${title}-${index}`}>
|
|
568
|
+
{content}
|
|
569
|
+
</a>
|
|
570
|
+
) : (
|
|
571
|
+
<article key={`${title}-${index}`}>{content}</article>
|
|
572
|
+
);
|
|
573
|
+
});
|
|
574
|
+
return (
|
|
575
|
+
<section className={`store-section home-${componentKey}-section`}>
|
|
576
|
+
<div className="store-container">
|
|
577
|
+
{(text(props, "eyebrow") || text(props, "title")) && (
|
|
578
|
+
<div className="section-heading">
|
|
579
|
+
<div>
|
|
580
|
+
{text(props, "eyebrow") && (
|
|
581
|
+
<span>{text(props, "eyebrow")}</span>
|
|
582
|
+
)}
|
|
583
|
+
{text(props, "title") && <h2>{text(props, "title")}</h2>}
|
|
584
|
+
</div>
|
|
585
|
+
</div>
|
|
586
|
+
)}
|
|
587
|
+
{isBrands && brandsLayout === "carousel" ? (
|
|
588
|
+
<BrandsCarouselFrame count={items.length}>
|
|
589
|
+
{renderedItems}
|
|
590
|
+
</BrandsCarouselFrame>
|
|
591
|
+
) : (
|
|
592
|
+
<div
|
|
593
|
+
className={isBrands ? "home-brands-grid" : "home-benefits-grid"}
|
|
594
|
+
data-columns={gridColumns}
|
|
595
|
+
>
|
|
596
|
+
{renderedItems}
|
|
597
|
+
</div>
|
|
598
|
+
)}
|
|
599
|
+
</div>
|
|
600
|
+
</section>
|
|
601
|
+
);
|
|
164
602
|
}
|
|
165
|
-
if (componentKey === "video")
|
|
603
|
+
if (componentKey === "video")
|
|
604
|
+
return (
|
|
605
|
+
<section
|
|
606
|
+
className="store-section theme-component-section"
|
|
607
|
+
data-component-key="video"
|
|
608
|
+
>
|
|
609
|
+
<div className="store-container">
|
|
610
|
+
{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
|
|
611
|
+
{text(props, "title") && <h2>{text(props, "title")}</h2>}
|
|
612
|
+
{text(props, "description") && <p>{text(props, "description")}</p>}
|
|
613
|
+
{text(props, "videoUrl") && (
|
|
614
|
+
<video
|
|
615
|
+
className="theme-component-video"
|
|
616
|
+
controls
|
|
617
|
+
playsInline
|
|
618
|
+
poster={text(props, "posterImageUrl") || undefined}
|
|
619
|
+
src={text(props, "videoUrl")}
|
|
620
|
+
/>
|
|
621
|
+
)}
|
|
622
|
+
</div>
|
|
623
|
+
</section>
|
|
624
|
+
);
|
|
166
625
|
const items = records(props, "items");
|
|
167
|
-
return
|
|
626
|
+
return (
|
|
627
|
+
<section
|
|
628
|
+
className="store-section theme-component-section"
|
|
629
|
+
data-component-key={componentKey || undefined}
|
|
630
|
+
>
|
|
631
|
+
<div className="store-container">
|
|
632
|
+
{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
|
|
633
|
+
{text(props, "title") && <h2>{text(props, "title")}</h2>}
|
|
634
|
+
{text(props, "description") && <p>{text(props, "description")}</p>}
|
|
635
|
+
{items.length > 0 && (
|
|
636
|
+
<div className="theme-component-items">
|
|
637
|
+
{items.map((item, index) => {
|
|
638
|
+
const itemTitle = text(
|
|
639
|
+
item,
|
|
640
|
+
"value",
|
|
641
|
+
text(item, "title", text(item, "question")),
|
|
642
|
+
);
|
|
643
|
+
return (
|
|
644
|
+
<article key={index}>
|
|
645
|
+
{itemTitle && <strong>{itemTitle}</strong>}
|
|
646
|
+
{text(item, "description", text(item, "answer")) && (
|
|
647
|
+
<p>{text(item, "description", text(item, "answer"))}</p>
|
|
648
|
+
)}
|
|
649
|
+
</article>
|
|
650
|
+
);
|
|
651
|
+
})}
|
|
652
|
+
</div>
|
|
653
|
+
)}
|
|
654
|
+
</div>
|
|
655
|
+
</section>
|
|
656
|
+
);
|
|
168
657
|
}
|
|
169
658
|
|
|
170
|
-
export function Home({
|
|
171
|
-
|
|
659
|
+
export function Home({
|
|
660
|
+
sections,
|
|
661
|
+
products,
|
|
662
|
+
posts,
|
|
663
|
+
services,
|
|
664
|
+
cases,
|
|
665
|
+
site,
|
|
666
|
+
submitContact,
|
|
667
|
+
ImageComponent = ThemeImageView,
|
|
668
|
+
}: HomeProps & { ImageComponent?: ThemeImageComponent }) {
|
|
669
|
+
const visible = [...sections]
|
|
670
|
+
.filter((section) => section.enabled)
|
|
671
|
+
.sort((a, b) => a.order - b.order);
|
|
172
672
|
const catalog = site.settings?.catalog;
|
|
173
|
-
return
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
673
|
+
return (
|
|
674
|
+
<>
|
|
675
|
+
{visible.map((section, index) => {
|
|
676
|
+
if (section.type === "hero")
|
|
677
|
+
return (
|
|
678
|
+
<Hero
|
|
679
|
+
key={section.id || index}
|
|
680
|
+
section={section}
|
|
681
|
+
priority={index === 0}
|
|
682
|
+
ImageComponent={ImageComponent}
|
|
683
|
+
/>
|
|
684
|
+
);
|
|
685
|
+
if (section.type === "banner-carousel")
|
|
686
|
+
return (
|
|
687
|
+
<section className="home-banner-section" key={section.id || index}>
|
|
688
|
+
<BannerCarousel
|
|
689
|
+
banners={banners(section.data)}
|
|
690
|
+
autoplay={section.data.autoplay !== false}
|
|
691
|
+
desktopHeight={
|
|
692
|
+
typeof section.data.desktopHeight === "number"
|
|
693
|
+
? section.data.desktopHeight
|
|
694
|
+
: undefined
|
|
695
|
+
}
|
|
696
|
+
mobileHeight={
|
|
697
|
+
typeof section.data.mobileHeight === "number"
|
|
698
|
+
? section.data.mobileHeight
|
|
699
|
+
: undefined
|
|
700
|
+
}
|
|
701
|
+
imageFit={
|
|
702
|
+
section.data.imageFit === "CONTAIN" ||
|
|
703
|
+
section.data.imageFit === "NATURAL"
|
|
704
|
+
? section.data.imageFit
|
|
705
|
+
: "COVER"
|
|
706
|
+
}
|
|
707
|
+
priority={index === 0}
|
|
708
|
+
ImageComponent={ImageComponent}
|
|
709
|
+
/>
|
|
710
|
+
</section>
|
|
711
|
+
);
|
|
712
|
+
if (section.type === "mini-banners")
|
|
713
|
+
return (
|
|
714
|
+
<MiniBanners
|
|
715
|
+
key={section.id || index}
|
|
716
|
+
layout={section.data.layout === "3x1" ? "3x1" : "2x1"}
|
|
717
|
+
items={miniBanners(section.data)}
|
|
718
|
+
ImageComponent={ImageComponent}
|
|
719
|
+
/>
|
|
720
|
+
);
|
|
721
|
+
if (section.type === "theme-component")
|
|
722
|
+
return (
|
|
723
|
+
<ThemeComponent
|
|
724
|
+
key={section.id || index}
|
|
725
|
+
section={section}
|
|
726
|
+
submitContact={submitContact}
|
|
727
|
+
ImageComponent={ImageComponent}
|
|
728
|
+
/>
|
|
729
|
+
);
|
|
730
|
+
if (["image-text", "rich-text", "cta"].includes(section.type))
|
|
731
|
+
return (
|
|
732
|
+
<TextSection
|
|
733
|
+
key={section.id || index}
|
|
734
|
+
section={section}
|
|
735
|
+
ImageComponent={ImageComponent}
|
|
736
|
+
/>
|
|
737
|
+
);
|
|
738
|
+
if (
|
|
739
|
+
section.type === "products-grid" ||
|
|
740
|
+
section.type === "products-carousel"
|
|
741
|
+
) {
|
|
742
|
+
const category = productCategory(section.data);
|
|
743
|
+
const items = products
|
|
744
|
+
.filter(
|
|
745
|
+
(product) =>
|
|
746
|
+
!category ||
|
|
747
|
+
product.categories.some(({ slug }) => slug === category) ||
|
|
748
|
+
product.categoryPath?.includes(category),
|
|
749
|
+
)
|
|
750
|
+
.slice(0, limit(section.data));
|
|
751
|
+
const matchingPath = category
|
|
752
|
+
? items.find((product) => product.categoryPath?.includes(category))
|
|
753
|
+
?.categoryPath
|
|
754
|
+
: undefined;
|
|
755
|
+
const categoryIndex = matchingPath?.indexOf(category) ?? -1;
|
|
756
|
+
const allProductsHref =
|
|
757
|
+
categoryIndex >= 0 && matchingPath
|
|
758
|
+
? categoryUrl(matchingPath.slice(0, categoryIndex + 1))
|
|
759
|
+
: category
|
|
760
|
+
? `/produtos?categoria=${encodeURIComponent(category)}`
|
|
761
|
+
: "/produtos";
|
|
762
|
+
const productsView =
|
|
763
|
+
section.type === "products-grid" ? (
|
|
764
|
+
<ProductGrid
|
|
765
|
+
products={items}
|
|
766
|
+
columns={catalog?.desktopColumns}
|
|
767
|
+
showPrices={catalog?.showPrices}
|
|
768
|
+
showCategory={catalog?.showCategory}
|
|
769
|
+
showDescription={catalog?.showDescription}
|
|
770
|
+
ImageComponent={ImageComponent}
|
|
771
|
+
/>
|
|
772
|
+
) : (
|
|
773
|
+
<ProductCarousel
|
|
774
|
+
products={items}
|
|
775
|
+
showPrices={catalog?.showPrices}
|
|
776
|
+
showCategory={catalog?.showCategory}
|
|
777
|
+
showDescription={catalog?.showDescription}
|
|
778
|
+
ImageComponent={ImageComponent}
|
|
779
|
+
/>
|
|
780
|
+
);
|
|
781
|
+
return (
|
|
782
|
+
<section
|
|
783
|
+
className="store-section home-products-section"
|
|
784
|
+
data-layout={
|
|
785
|
+
section.type === "products-carousel" ? "carousel" : "grid"
|
|
786
|
+
}
|
|
787
|
+
key={section.id || index}
|
|
788
|
+
>
|
|
789
|
+
<div className="store-container">
|
|
790
|
+
<Heading data={section.data} href={allProductsHref} />
|
|
791
|
+
{productsView}
|
|
792
|
+
</div>
|
|
793
|
+
</section>
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
const map =
|
|
797
|
+
section.type === "services-grid"
|
|
798
|
+
? { items: services, path: "/servicos" }
|
|
799
|
+
: section.type === "cases-grid"
|
|
800
|
+
? { items: cases, path: "/cases" }
|
|
801
|
+
: { items: posts, path: "/blog" };
|
|
802
|
+
return (
|
|
803
|
+
<section
|
|
804
|
+
className="store-section home-editorial-section"
|
|
805
|
+
key={section.id || index}
|
|
806
|
+
>
|
|
807
|
+
<div className="store-container">
|
|
808
|
+
<Heading data={section.data} href={map.path} />
|
|
809
|
+
<EditorialGrid
|
|
810
|
+
items={map.items.slice(0, limit(section.data))}
|
|
811
|
+
basePath={map.path}
|
|
812
|
+
ImageComponent={ImageComponent}
|
|
813
|
+
/>
|
|
814
|
+
</div>
|
|
815
|
+
</section>
|
|
816
|
+
);
|
|
817
|
+
})}
|
|
818
|
+
</>
|
|
819
|
+
);
|
|
196
820
|
}
|