@nuvler/cli 0.5.10 → 0.5.12

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.
@@ -1,10 +1,22 @@
1
1
  import { useState, type FormEvent } from "react";
2
- import type { HomeProps, ThemeContactSubmissionInput, ThemeEditorialItem, ThemeHomeSection, ThemeImage, ThemeSite } from "@nuvler/theme-sdk";
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";
4
11
  import { MiniBanners } from "./mini-banners.js";
5
12
  import { ProductCarousel } from "./product-carousel.js";
13
+ import { BrandsCarouselFrame } from "./carousel-frame.js";
6
14
  import { ProductGrid } from "./products.js";
7
- import { categoryUrl, ThemeImageView, type ThemeImageComponent } from "./shared.js";
15
+ import {
16
+ categoryUrl,
17
+ ThemeImageView,
18
+ type ThemeImageComponent,
19
+ } from "./shared.js";
8
20
 
9
21
  function text(data: Record<string, unknown>, key: string, fallback = "") {
10
22
  const value = data[key];
@@ -16,21 +28,48 @@ function limit(data: Record<string, unknown>) {
16
28
  return Number.isInteger(value) ? Math.min(12, Math.max(1, value)) : 6;
17
29
  }
18
30
 
19
- function record(data: Record<string, unknown>, key: string): Record<string, unknown> {
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> {
20
41
  const value = data[key];
21
- return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
42
+ return value && typeof value === "object" && !Array.isArray(value)
43
+ ? (value as Record<string, unknown>)
44
+ : {};
22
45
  }
23
46
 
24
- function records(data: Record<string, unknown>, key: string): Record<string, unknown>[] {
47
+ function records(
48
+ data: Record<string, unknown>,
49
+ key: string,
50
+ ): Record<string, unknown>[] {
25
51
  const value = data[key];
26
52
  return Array.isArray(value)
27
- ? value.filter((item): item is Record<string, unknown> => Boolean(item) && typeof item === "object" && !Array.isArray(item))
53
+ ? value.filter(
54
+ (item): item is Record<string, unknown> =>
55
+ Boolean(item) && typeof item === "object" && !Array.isArray(item),
56
+ )
28
57
  : [];
29
58
  }
30
59
 
31
60
  function productCategory(data: Record<string, unknown>) {
32
61
  const value = text(data, "categorySlug").toLocaleLowerCase("pt-BR");
33
- if (["", "all", "todos", "todas", "all-categories", "todas-as-categorias"].includes(value)) return "";
62
+ if (
63
+ [
64
+ "",
65
+ "all",
66
+ "todos",
67
+ "todas",
68
+ "all-categories",
69
+ "todas-as-categorias",
70
+ ].includes(value)
71
+ )
72
+ return "";
34
73
  return value;
35
74
  }
36
75
 
@@ -46,16 +85,21 @@ function imageValue(value: unknown): ThemeImage | null {
46
85
  };
47
86
  }
48
87
 
49
- function sectionImage(data: Record<string, unknown>, fallbackAlt: string): ThemeImage | null {
88
+ function sectionImage(
89
+ data: Record<string, unknown>,
90
+ fallbackAlt: string,
91
+ ): ThemeImage | null {
50
92
  const enriched = imageValue(data.image);
51
93
  if (enriched) return enriched;
52
94
  const imageUrl = text(data, "imageUrl");
53
- return imageUrl ? {
54
- url: imageUrl,
55
- alt: text(data, "imageAlt", fallbackAlt),
56
- width: null,
57
- height: null,
58
- } : null;
95
+ return imageUrl
96
+ ? {
97
+ url: imageUrl,
98
+ alt: text(data, "imageAlt", fallbackAlt),
99
+ width: null,
100
+ height: null,
101
+ }
102
+ : null;
59
103
  }
60
104
 
61
105
  function banners(data: Record<string, unknown>): ThemeBanner[] {
@@ -64,9 +108,32 @@ function banners(data: Record<string, unknown>): ThemeBanner[] {
64
108
  if (!entry || typeof entry !== "object") return [];
65
109
  const item = entry as Record<string, unknown>;
66
110
  const image = imageValue(item.image);
67
- const imageUrl = image?.url || (typeof item.imageUrl === "string" ? item.imageUrl : "");
111
+ const imageUrl =
112
+ image?.url || (typeof item.imageUrl === "string" ? item.imageUrl : "");
68
113
  if (!imageUrl) return [];
69
- return [{ imageUrl, image, imageAlt: typeof item.imageAlt === "string" ? item.imageAlt : undefined, mobileImageUrl: typeof item.mobileImageUrl === "string" ? item.mobileImageUrl : undefined, mobileImage: imageValue(item.mobileImage), mobileImageAlt: typeof item.mobileImageAlt === "string" ? item.mobileImageAlt : undefined, title: typeof item.title === "string" ? item.title : undefined, description: typeof item.description === "string" ? item.description : undefined, buttonLabel: typeof item.buttonLabel === "string" ? item.buttonLabel : undefined, buttonUrl: typeof item.buttonUrl === "string" ? item.buttonUrl : undefined }];
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
+ ];
70
137
  });
71
138
  }
72
139
 
@@ -75,49 +142,229 @@ function miniBanners(data: Record<string, unknown>) {
75
142
  const image = imageValue(item.image);
76
143
  const imageUrl = image?.url || text(item, "imageUrl");
77
144
  if (!imageUrl) return [];
78
- return [{ image, imageUrl, imageAlt: text(item, "imageAlt") || undefined, title: text(item, "title") || undefined, link: text(item, "link") || undefined }];
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
+ ];
79
155
  });
80
156
  }
81
157
 
82
- function Heading({ data, href }: { data: Record<string, unknown>; href: string }) {
158
+ function Heading({
159
+ data,
160
+ href,
161
+ }: {
162
+ data: Record<string, unknown>;
163
+ href: string;
164
+ }) {
83
165
  const eyebrow = text(data, "eyebrow");
84
166
  const title = text(data, "title");
85
167
  const actionLabel = text(data, "buttonLabel");
86
168
  const actionHref = text(data, "buttonUrl", href);
87
169
  if (!eyebrow && !title && !actionLabel) return null;
88
- return <div className="section-heading"><div>{eyebrow && <span>{eyebrow}</span>}{title && <h2>{title}</h2>}</div>{actionLabel && actionHref && <a href={actionHref}>{actionLabel}</a>}</div>;
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
+ );
89
179
  }
90
180
 
91
- function Hero({ section, priority, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; priority: boolean; ImageComponent?: ThemeImageComponent }) {
181
+ function Hero({
182
+ section,
183
+ priority,
184
+ ImageComponent = ThemeImageView,
185
+ }: {
186
+ section: ThemeHomeSection;
187
+ priority: boolean;
188
+ ImageComponent?: ThemeImageComponent;
189
+ }) {
92
190
  const title = text(section.data, "title");
93
191
  const description = text(section.data, "description");
94
192
  const eyebrow = text(section.data, "eyebrow");
95
193
  const buttonLabel = text(section.data, "buttonLabel");
96
194
  const buttonUrl = text(section.data, "buttonUrl");
97
195
  const image = sectionImage(section.data, title);
98
- const copy = <div className="hero-copy">{eyebrow && <span className="hero-eyebrow">{eyebrow}</span>}{title && <h1>{title}</h1>}{description && <p>{description}</p>}{buttonLabel && buttonUrl && <div className="hero-actions"><a className="button button-primary" href={buttonUrl}>{buttonLabel}</a></div>}</div>;
99
- if (image) return <section className="hero-section hero-section-image"><ImageComponent image={image} fallbackAlt={title} className="hero-background-image" priority={priority} sizes="100vw" fallbackWidth={1600} fallbackHeight={700} /><div className="hero-background-overlay" aria-hidden="true" /><div className="store-container hero-image-content">{copy}</div></section>;
100
- return <section className="hero-section"><div className="store-container hero-grid">{copy}<div className="hero-art" aria-hidden="true"><div className="hero-orbit hero-orbit-one" /><div className="hero-orbit hero-orbit-two" /><div className="hero-seven">7</div></div></div></section>;
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
+ );
101
238
  }
102
239
 
103
- function EditorialGrid({ items, basePath, ImageComponent = ThemeImageView }: { items: ThemeEditorialItem[]; basePath: string; ImageComponent?: ThemeImageComponent }) {
104
- if (!items.length) return <div className="empty-state"><span>7</span><h2>Nenhum conteúdo publicado</h2><p>As publicações aparecerão aqui quando estiverem disponíveis.</p></div>;
105
- return <div className="editorial-grid">{items.map((item) => <article className="editorial-card" key={item.slug}><a className="editorial-card-image" href={`${basePath}/${item.slug}`}><ImageComponent image={item.image || item.thumbnail || item.coverImage} fallbackAlt={item.title} sizes="(max-width: 720px) 92vw, 33vw" fallbackWidth={720} fallbackHeight={480} /></a><div className="editorial-card-content">{(item.category?.title || item.category?.name) && <span>{item.category.title || item.category.name}</span>}<h2><a href={`${basePath}/${item.slug}`}>{item.title}</a></h2><p>{item.description}</p><a className="text-link" href={`${basePath}/${item.slug}`}>Saiba mais <span>→</span></a></div></article>)}</div>;
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
+ );
106
286
  }
107
287
 
108
- function TextSection({ section, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; ImageComponent?: ThemeImageComponent }) {
288
+ function TextSection({
289
+ section,
290
+ ImageComponent = ThemeImageView,
291
+ }: {
292
+ section: ThemeHomeSection;
293
+ ImageComponent?: ThemeImageComponent;
294
+ }) {
109
295
  const title = text(section.data, "title");
110
- const description = text(section.data, "description", text(section.data, "text"));
296
+ const description = text(
297
+ section.data,
298
+ "description",
299
+ text(section.data, "text"),
300
+ );
111
301
  const image = sectionImage(section.data, title);
112
- if (section.type === "image-text") return <section className="store-section image-text-section"><div className="store-container image-text-layout" data-position={section.data.imagePosition === "right" ? "right" : "left"}>{image && <div className="image-text-media"><ImageComponent image={image} fallbackAlt={title} sizes="(max-width: 900px) 100vw, 50vw" fallbackWidth={800} fallbackHeight={600} /></div>}<div className="image-text-copy">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}{title && <h2>{title}</h2>}{description && <p>{description}</p>}</div></div></section>;
113
- return <section className="store-section editorial-section"><div className="store-container editorial-content">{text(section.data, "eyebrow") && <span>{text(section.data, "eyebrow")}</span>}{title && <h2>{title}</h2>}{description && <p>{description}</p>}{section.type === "cta" && text(section.data, "buttonLabel") && text(section.data, "buttonUrl") && <a className="button button-primary" href={text(section.data, "buttonUrl")}>{text(section.data, "buttonLabel")}</a>}</div></section>;
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
+ );
114
353
  }
115
354
 
116
- function ContactForm({ section, submitContact }: { section: ThemeHomeSection; submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown> }) {
355
+ function ContactForm({
356
+ section,
357
+ submitContact,
358
+ }: {
359
+ section: ThemeHomeSection;
360
+ submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown>;
361
+ }) {
117
362
  const props = record(section.data, "props");
118
363
  const configured = records(props, "fields");
119
364
  const fields = configured;
120
- const [status, setStatus] = useState<"idle" | "sending" | "success" | "error">("idle");
365
+ const [status, setStatus] = useState<
366
+ "idle" | "sending" | "success" | "error"
367
+ >("idle");
121
368
  const [error, setError] = useState("");
122
369
  const submit = async (event: FormEvent<HTMLFormElement>) => {
123
370
  event.preventDefault();
@@ -137,71 +384,437 @@ function ContactForm({ section, submitContact }: { section: ThemeHomeSection; su
137
384
  return;
138
385
  }
139
386
  const entries = form.getAll(key).map(String);
140
- values[key] = entries.length > 1 ? entries : entries[0] ?? "";
387
+ values[key] = entries.length > 1 ? entries : (entries[0] ?? "");
141
388
  });
142
389
  setStatus("sending");
143
390
  setError("");
144
391
  try {
145
- await submitContact({ formKey: text(section.data, "componentKey", "contact-form"), sectionId: section.id, values, pathname: typeof window === "undefined" ? undefined : window.location.pathname });
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
+ });
146
399
  formElement.reset();
147
400
  setStatus("success");
148
401
  } catch (cause) {
149
402
  setStatus("error");
150
- setError(cause instanceof Error ? cause.message : "Não foi possível enviar o contato.");
403
+ setError(
404
+ cause instanceof Error
405
+ ? cause.message
406
+ : "Não foi possível enviar o contato.",
407
+ );
151
408
  }
152
409
  };
153
- return <section className="store-section theme-component-section contact-form-section"><div className="store-container contact-form-layout"><div className="contact-form-copy">{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}{text(props, "title") && <h2>{text(props, "title")}</h2>}{text(props, "description") && <p>{text(props, "description")}</p>}</div><form className="contact-form" onSubmit={(event) => void submit(event)}>{fields.map((field) => {
154
- const key = text(field, "key");
155
- const type = text(field, "type", "text");
156
- const label = text(field, "label", key);
157
- const required = field.required === true;
158
- if (!key) return null;
159
- if (type === "checkbox") return <label className="contact-form-wide contact-form-checkbox" key={key}><input name={key} required={required} type="checkbox" value="true" /><span>{label}{required && <small aria-hidden="true"> *</small>}</span></label>;
160
- if (type === "select") return <label key={key}><span>{label}{required && <small aria-hidden="true"> *</small>}</span><select name={key} required={required}>{records(field, "options").map((option) => <option key={text(option, "value")} value={text(option, "value")}>{text(option, "label", text(option, "value"))}</option>)}</select></label>;
161
- return <label className={type === "textarea" ? "contact-form-wide" : ""} key={key}><span>{label}{required && <small aria-hidden="true"> *</small>}</span>{type === "textarea" ? <textarea name={key} placeholder={text(field, "placeholder")} required={required} rows={5} /> : <input name={key} placeholder={text(field, "placeholder")} required={required} type={["email", "tel", "url", "number"].includes(type) ? type : "text"} />}</label>;
162
- })}<div className="contact-form-wide"><button className="button button-primary" disabled={status === "sending"} type="submit">{status === "sending" ? "" : text(props, "submitLabel")}</button>{status === "success" && text(props, "successMessage") && <p className="contact-form-feedback" role="status">{text(props, "successMessage")}</p>}{status === "error" && <p className="contact-form-feedback contact-form-error" role="alert">{error}</p>}</div></form></div></section>;
163
- }
164
-
165
- function ThemeComponent({ section, submitContact, ImageComponent = ThemeImageView }: { section: ThemeHomeSection; submitContact?: HomeProps["submitContact"]; ImageComponent?: ThemeImageComponent }) {
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
+ }) {
166
530
  const componentKey = text(section.data, "componentKey");
167
531
  const props = record(section.data, "props");
168
- if (componentKey === "contact-form" || componentKey.endsWith("-form")) return <ContactForm section={section} submitContact={submitContact} />;
532
+ if (componentKey === "contact-form" || componentKey.endsWith("-form"))
533
+ return <ContactForm section={section} submitContact={submitContact} />;
169
534
  if (componentKey === "benefits" || componentKey === "brands") {
170
535
  const items = records(props, "items");
171
536
  if (!items.length) return null;
172
537
  const isBrands = componentKey === "brands";
173
- return <section className={`store-section home-${componentKey}-section`}><div className="store-container">{(text(props, "eyebrow") || text(props, "title")) && <div className="section-heading"><div>{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}{text(props, "title") && <h2>{text(props, "title")}</h2>}</div></div>}<div className={isBrands ? "home-brands-grid" : "home-benefits-grid"}>{items.map((item, index) => { const title = text(item, "title", text(item, "value")); const image = imageValue(item.image); const href = text(item, "url"); const content = <>{isBrands && image ? <ImageComponent image={image} fallbackAlt={title} sizes="160px" fallbackWidth={320} fallbackHeight={160} /> : null}{!isBrands && <span className="home-benefit-index" aria-hidden="true">{String(index + 1).padStart(2, "0")}</span>}{title && <strong>{title}</strong>}{text(item, "description") && <p>{text(item, "description")}</p>}</>; return href ? <a href={href} key={`${title}-${index}`}>{content}</a> : <article key={`${title}-${index}`}>{content}</article>; })}</div></div></section>;
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
+ );
174
602
  }
175
- if (componentKey === "video") return <section className="store-section theme-component-section" data-component-key="video"><div className="store-container">{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}{text(props, "title") && <h2>{text(props, "title")}</h2>}{text(props, "description") && <p>{text(props, "description")}</p>}{text(props, "videoUrl") && <video className="theme-component-video" controls playsInline poster={text(props, "posterImageUrl") || undefined} src={text(props, "videoUrl")} />}</div></section>;
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
+ );
176
625
  const items = records(props, "items");
177
- return <section className="store-section theme-component-section" data-component-key={componentKey || undefined}><div className="store-container">{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}{text(props, "title") && <h2>{text(props, "title")}</h2>}{text(props, "description") && <p>{text(props, "description")}</p>}{items.length > 0 && <div className="theme-component-items">{items.map((item, index) => { const itemTitle = text(item, "value", text(item, "title", text(item, "question"))); return <article key={index}>{itemTitle && <strong>{itemTitle}</strong>}{text(item, "description", text(item, "answer")) && <p>{text(item, "description", text(item, "answer"))}</p>}</article>; })}</div>}</div></section>;
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
+ );
178
657
  }
179
658
 
180
- export function Home({ sections, products, posts, services, cases, site, submitContact, ImageComponent = ThemeImageView }: HomeProps & { ImageComponent?: ThemeImageComponent }) {
181
- const visible = [...sections].filter((section) => section.enabled).sort((a, b) => a.order - b.order);
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);
182
672
  const catalog = site.settings?.catalog;
183
- return <>{visible.map((section, index) => {
184
- if (section.type === "hero") return <Hero key={section.id || index} section={section} priority={index === 0} ImageComponent={ImageComponent} />;
185
- if (section.type === "banner-carousel") return <section className="home-banner-section" key={section.id || index}><BannerCarousel banners={banners(section.data)} autoplay={section.data.autoplay !== false} desktopHeight={typeof section.data.desktopHeight === "number" ? section.data.desktopHeight : undefined} mobileHeight={typeof section.data.mobileHeight === "number" ? section.data.mobileHeight : undefined} imageFit={section.data.imageFit === "CONTAIN" || section.data.imageFit === "NATURAL" ? section.data.imageFit : "COVER"} priority={index === 0} ImageComponent={ImageComponent} /></section>;
186
- if (section.type === "mini-banners") return <MiniBanners key={section.id || index} layout={section.data.layout === "3x1" ? "3x1" : "2x1"} items={miniBanners(section.data)} ImageComponent={ImageComponent} />;
187
- if (section.type === "theme-component") return <ThemeComponent key={section.id || index} section={section} submitContact={submitContact} ImageComponent={ImageComponent} />;
188
- if (["image-text", "rich-text", "cta"].includes(section.type)) return <TextSection key={section.id || index} section={section} ImageComponent={ImageComponent} />;
189
- if (section.type === "products-grid" || section.type === "products-carousel") {
190
- const category = productCategory(section.data);
191
- const items = products.filter((product) => !category || product.categories.some(({ slug }) => slug === category) || product.categoryPath?.includes(category)).slice(0, limit(section.data));
192
- const matchingPath = category
193
- ? items.find((product) => product.categoryPath?.includes(category))?.categoryPath
194
- : undefined;
195
- const categoryIndex = matchingPath?.indexOf(category) ?? -1;
196
- const allProductsHref = categoryIndex >= 0 && matchingPath
197
- ? categoryUrl(matchingPath.slice(0, categoryIndex + 1))
198
- : category ? `/produtos?categoria=${encodeURIComponent(category)}` : "/produtos";
199
- const productsView = section.type === "products-grid"
200
- ? <ProductGrid products={items} columns={catalog?.desktopColumns} showPrices={catalog?.showPrices} showCategory={catalog?.showCategory} showDescription={catalog?.showDescription} ImageComponent={ImageComponent} />
201
- : <ProductCarousel products={items} showPrices={catalog?.showPrices} showCategory={catalog?.showCategory} showDescription={catalog?.showDescription} ImageComponent={ImageComponent} />;
202
- return <section className="store-section home-products-section" data-layout={section.type === "products-carousel" ? "carousel" : "grid"} key={section.id || index}><div className="store-container"><Heading data={section.data} href={allProductsHref} />{productsView}</div></section>;
203
- }
204
- const map = section.type === "services-grid" ? { items: services, path: "/servicos" } : section.type === "cases-grid" ? { items: cases, path: "/cases" } : { items: posts, path: "/blog" };
205
- return <section className="store-section home-editorial-section" key={section.id || index}><div className="store-container"><Heading data={section.data} href={map.path} /><EditorialGrid items={map.items.slice(0, limit(section.data))} basePath={map.path} ImageComponent={ImageComponent} /></div></section>;
206
- })}</>;
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
+ );
207
820
  }