@nuvler/cli 0.5.16 → 0.5.18
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/dist/api/theme-context.js +2 -0
- package/dist/api/theme-context.js.map +1 -1
- package/dist/commands/theme/create.js +1 -1
- package/dist/nuvler.js +24 -1
- package/dist/nuvler.js.map +1 -1
- package/dist/templates/nuvler-atelier/package.json +2 -2
- package/dist/templates/nuvler-default/README.md +4 -4
- package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
- package/dist/templates/nuvler-default/package.json +2 -2
- package/dist/templates/nuvler-default/src/catalog-filters.tsx +169 -0
- package/dist/templates/nuvler-default/src/contact-form.tsx +172 -0
- package/dist/templates/nuvler-default/src/home-data.ts +30 -0
- package/dist/templates/nuvler-default/src/home.tsx +2 -196
- package/dist/templates/nuvler-default/src/interaction-colors.ts +49 -0
- package/dist/templates/nuvler-default/src/kit-composition.ts +15 -0
- package/dist/templates/nuvler-default/src/kit-group-selector.tsx +230 -0
- package/dist/templates/nuvler-default/src/kit-selection.ts +39 -0
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +420 -115
- package/dist/templates/nuvler-default/src/product-detail.tsx +141 -59
- package/dist/templates/nuvler-default/src/products.tsx +143 -12
- package/dist/templates/nuvler-default/src/server-shell.tsx +21 -3
- package/dist/templates/nuvler-default/src/theme-component.tsx +85 -24
- package/dist/templates/nuvler-default/src/theme.css +673 -6
- package/dist/templates/nuvler-default/src/whatsapp-message.ts +82 -0
- package/dist/templates/nuvler-default/test/catalog-filters.test.mjs +44 -0
- package/dist/templates/nuvler-default/test/interaction-colors.test.mjs +74 -0
- package/dist/templates/nuvler-default/test/kit-composition.test.mjs +28 -0
- package/dist/templates/nuvler-default/test/kit-detail.test.mjs +292 -0
- package/dist/templates/nuvler-default/test/whatsapp-message.test.mjs +126 -0
- package/dist/templates/starter/package.json +2 -2
- package/package.json +3 -3
- package/preview-host/package.json +1 -1
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@nuvler/theme-sdk": "^1.4.
|
|
16
|
+
"@nuvler/theme-sdk": "^1.4.8"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"react": "^19.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@nuvler/cli": "^0.5.
|
|
22
|
+
"@nuvler/cli": "^0.5.18",
|
|
23
23
|
"@types/react": "^19.0.0",
|
|
24
24
|
"react": "^19.0.0",
|
|
25
25
|
"typescript": "^5.9.0"
|
|
@@ -66,16 +66,16 @@ Para compilar, gerar o artefato ou publicar, execute na raiz do tooling:
|
|
|
66
66
|
```bash
|
|
67
67
|
npm run pack:cli
|
|
68
68
|
npm run pack:default
|
|
69
|
-
npm publish ./artifacts/nuvler-cli-0.5.13.tgz --access public
|
|
70
|
-
npm publish ./artifacts/nuvler-theme-default-1.1.7.tgz --access public
|
|
71
69
|
|
|
72
70
|
node packages/cli/dist/nuvler.js theme build --theme themes/nuvler-default
|
|
73
71
|
npm run pack:theme -- nuvler-default
|
|
74
72
|
node packages/cli/dist/nuvler.js theme publish --theme themes/nuvler-default --official
|
|
75
73
|
```
|
|
76
74
|
|
|
77
|
-
O pacote npm contém o renderer local e o CSS.
|
|
78
|
-
|
|
75
|
+
O pacote npm contém o renderer local e o CSS. As versões e a ordem de
|
|
76
|
+
publicação dos pacotes estão no [guia do monorepo](../../README.md#publicação-dos-pacotes-npm).
|
|
77
|
+
O artefato do Theme Registry é gerado separadamente como
|
|
78
|
+
`artifacts/nuvler-default-<versão>.nuvler-theme.tgz`.
|
|
79
79
|
|
|
80
80
|
Exemplo no App Router:
|
|
81
81
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuvler/theme-default",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.23",
|
|
4
4
|
"description": "Tema padrão oficial da Nuvler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"react": "^19.0.0"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@nuvler/theme-sdk": "^1.4.
|
|
68
|
+
"@nuvler/theme-sdk": "^1.4.8"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/react": "^19.0.0",
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useRef, useState, type ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
export function CatalogFilters({
|
|
6
|
+
children,
|
|
7
|
+
total,
|
|
8
|
+
activeCount,
|
|
9
|
+
resetHref,
|
|
10
|
+
}: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
total: number;
|
|
13
|
+
activeCount: number;
|
|
14
|
+
resetHref: string;
|
|
15
|
+
}) {
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
const panel = useRef<HTMLElement>(null);
|
|
18
|
+
const trigger = useRef<HTMLButtonElement>(null);
|
|
19
|
+
const close = useRef<HTMLButtonElement>(null);
|
|
20
|
+
const panelId = useId();
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!open) return;
|
|
24
|
+
const previous = document.body.style.overflow;
|
|
25
|
+
const opener = trigger.current;
|
|
26
|
+
document.body.style.overflow = "hidden";
|
|
27
|
+
const frame = requestAnimationFrame(() => close.current?.focus());
|
|
28
|
+
const desktop = window.matchMedia("(min-width: 801px)");
|
|
29
|
+
const resize = () => {
|
|
30
|
+
if (desktop.matches) setOpen(false);
|
|
31
|
+
};
|
|
32
|
+
desktop.addEventListener("change", resize);
|
|
33
|
+
return () => {
|
|
34
|
+
cancelAnimationFrame(frame);
|
|
35
|
+
document.body.style.overflow = previous;
|
|
36
|
+
desktop.removeEventListener("change", resize);
|
|
37
|
+
opener?.focus();
|
|
38
|
+
};
|
|
39
|
+
}, [open]);
|
|
40
|
+
|
|
41
|
+
function apply() {
|
|
42
|
+
const form =
|
|
43
|
+
panel.current?.querySelector<HTMLFormElement>(
|
|
44
|
+
".catalog-variant-filters",
|
|
45
|
+
) ??
|
|
46
|
+
panel.current?.querySelector<HTMLFormElement>(".catalog-filter-form");
|
|
47
|
+
if (!form) return;
|
|
48
|
+
const search = panel.current?.querySelector<HTMLInputElement>(
|
|
49
|
+
'input[type="search"][name="busca"]',
|
|
50
|
+
);
|
|
51
|
+
if (search && !form.contains(search)) {
|
|
52
|
+
let field = form.querySelector<HTMLInputElement>('input[name="busca"]');
|
|
53
|
+
if (!field) {
|
|
54
|
+
field = document.createElement("input");
|
|
55
|
+
field.type = "hidden";
|
|
56
|
+
field.name = "busca";
|
|
57
|
+
form.appendChild(field);
|
|
58
|
+
}
|
|
59
|
+
field.value = search.value;
|
|
60
|
+
}
|
|
61
|
+
form.requestSubmit();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div
|
|
66
|
+
className="catalog-filter-container"
|
|
67
|
+
data-filters-open={open || undefined}
|
|
68
|
+
>
|
|
69
|
+
<div className="catalog-mobile-toolbar">
|
|
70
|
+
<span>
|
|
71
|
+
{total} {total === 1 ? "produto" : "produtos"}
|
|
72
|
+
</span>
|
|
73
|
+
<button
|
|
74
|
+
ref={trigger}
|
|
75
|
+
type="button"
|
|
76
|
+
aria-expanded={open}
|
|
77
|
+
aria-controls={panelId}
|
|
78
|
+
onClick={() => setOpen(true)}
|
|
79
|
+
>
|
|
80
|
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
81
|
+
<path d="M4 7h16M4 17h16M8 4v6m8 4v6" />
|
|
82
|
+
</svg>
|
|
83
|
+
Filtros
|
|
84
|
+
{activeCount > 0 && (
|
|
85
|
+
<span className="catalog-filter-count">{activeCount}</span>
|
|
86
|
+
)}
|
|
87
|
+
</button>
|
|
88
|
+
</div>
|
|
89
|
+
{open && (
|
|
90
|
+
<div
|
|
91
|
+
className="catalog-filter-backdrop"
|
|
92
|
+
aria-hidden="true"
|
|
93
|
+
onClick={() => setOpen(false)}
|
|
94
|
+
/>
|
|
95
|
+
)}
|
|
96
|
+
<aside
|
|
97
|
+
ref={panel}
|
|
98
|
+
id={panelId}
|
|
99
|
+
className="category-filter catalog-filters"
|
|
100
|
+
role={open ? "dialog" : undefined}
|
|
101
|
+
aria-modal={open || undefined}
|
|
102
|
+
aria-label="Filtros do catálogo"
|
|
103
|
+
onSubmitCapture={(event) => {
|
|
104
|
+
if (
|
|
105
|
+
open &&
|
|
106
|
+
(event.target as HTMLFormElement).classList.contains(
|
|
107
|
+
"catalog-filter-form",
|
|
108
|
+
) &&
|
|
109
|
+
panel.current?.querySelector(".catalog-variant-filters")
|
|
110
|
+
) {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
apply();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setOpen(false);
|
|
117
|
+
}}
|
|
118
|
+
onClickCapture={(event) => {
|
|
119
|
+
if ((event.target as Element).closest("a[href]")) setOpen(false);
|
|
120
|
+
}}
|
|
121
|
+
onKeyDown={(event) => {
|
|
122
|
+
if (!open) return;
|
|
123
|
+
if (event.key === "Escape") {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
setOpen(false);
|
|
126
|
+
}
|
|
127
|
+
if (event.key !== "Tab") return;
|
|
128
|
+
const items = [
|
|
129
|
+
...(panel.current?.querySelectorAll<HTMLElement>(
|
|
130
|
+
'a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), [tabindex="0"]',
|
|
131
|
+
) ?? []),
|
|
132
|
+
].filter((item) => item.getClientRects().length > 0);
|
|
133
|
+
const first = items[0];
|
|
134
|
+
const last = items.at(-1);
|
|
135
|
+
if (event.shiftKey && document.activeElement === first) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
last?.focus();
|
|
138
|
+
} else if (!event.shiftKey && document.activeElement === last) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
first?.focus();
|
|
141
|
+
}
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<div className="catalog-filter-mobile-heading">
|
|
145
|
+
<strong>Filtrar produtos</strong>
|
|
146
|
+
<button
|
|
147
|
+
ref={close}
|
|
148
|
+
type="button"
|
|
149
|
+
aria-label="Fechar filtros"
|
|
150
|
+
onClick={() => setOpen(false)}
|
|
151
|
+
>
|
|
152
|
+
×
|
|
153
|
+
</button>
|
|
154
|
+
</div>
|
|
155
|
+
<div className="catalog-filter-body">{children}</div>
|
|
156
|
+
<div className="catalog-filter-mobile-actions">
|
|
157
|
+
<a href={resetHref}>Limpar</a>
|
|
158
|
+
<button
|
|
159
|
+
type="button"
|
|
160
|
+
className="button button-primary"
|
|
161
|
+
onClick={apply}
|
|
162
|
+
>
|
|
163
|
+
Ver resultados
|
|
164
|
+
</button>
|
|
165
|
+
</div>
|
|
166
|
+
</aside>
|
|
167
|
+
</div>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, type FormEvent } from "react";
|
|
4
|
+
import type { ThemeHomeSection, ThemeContactSubmissionInput } from "@nuvler/theme-sdk";
|
|
5
|
+
import { text, record, records } from "./home-data.js";
|
|
6
|
+
|
|
7
|
+
export function ContactForm({
|
|
8
|
+
section,
|
|
9
|
+
submitContact,
|
|
10
|
+
}: {
|
|
11
|
+
section: ThemeHomeSection;
|
|
12
|
+
submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown>;
|
|
13
|
+
}) {
|
|
14
|
+
const props = record(section.data, "props");
|
|
15
|
+
const configured = records(props, "fields");
|
|
16
|
+
const fields = configured;
|
|
17
|
+
const [status, setStatus] = useState<
|
|
18
|
+
"idle" | "sending" | "success" | "error"
|
|
19
|
+
>("idle");
|
|
20
|
+
const [error, setError] = useState("");
|
|
21
|
+
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
if (!submitContact) {
|
|
24
|
+
setStatus("error");
|
|
25
|
+
setError("O envio de contatos ainda não está disponível.");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const formElement = event.currentTarget;
|
|
29
|
+
const form = new FormData(formElement);
|
|
30
|
+
const values: ThemeContactSubmissionInput["values"] = {};
|
|
31
|
+
fields.forEach((field) => {
|
|
32
|
+
const key = text(field, "key");
|
|
33
|
+
if (!key) return;
|
|
34
|
+
if (text(field, "type") === "checkbox") {
|
|
35
|
+
values[key] = form.has(key);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const entries = form.getAll(key).map(String);
|
|
39
|
+
values[key] = entries.length > 1 ? entries : (entries[0] ?? "");
|
|
40
|
+
});
|
|
41
|
+
setStatus("sending");
|
|
42
|
+
setError("");
|
|
43
|
+
try {
|
|
44
|
+
await submitContact({
|
|
45
|
+
formKey: text(section.data, "componentKey", "contact-form"),
|
|
46
|
+
sectionId: section.id,
|
|
47
|
+
values,
|
|
48
|
+
pathname:
|
|
49
|
+
typeof window === "undefined" ? undefined : window.location.pathname,
|
|
50
|
+
});
|
|
51
|
+
formElement.reset();
|
|
52
|
+
setStatus("success");
|
|
53
|
+
} catch (cause) {
|
|
54
|
+
setStatus("error");
|
|
55
|
+
setError(
|
|
56
|
+
cause instanceof Error
|
|
57
|
+
? cause.message
|
|
58
|
+
: "Não foi possível enviar o contato.",
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return (
|
|
63
|
+
<section className="store-section theme-component-section contact-form-section">
|
|
64
|
+
<div className="store-container contact-form-layout">
|
|
65
|
+
<div className="contact-form-copy">
|
|
66
|
+
{text(props, "eyebrow") && <span>{text(props, "eyebrow")}</span>}
|
|
67
|
+
{text(props, "title") && <h2>{text(props, "title")}</h2>}
|
|
68
|
+
{text(props, "description") && <p>{text(props, "description")}</p>}
|
|
69
|
+
</div>
|
|
70
|
+
<form className="contact-form" onSubmit={(event) => void submit(event)}>
|
|
71
|
+
{fields.map((field) => {
|
|
72
|
+
const key = text(field, "key");
|
|
73
|
+
const type = text(field, "type", "text");
|
|
74
|
+
const label = text(field, "label", key);
|
|
75
|
+
const required = field.required === true;
|
|
76
|
+
if (!key) return null;
|
|
77
|
+
if (type === "checkbox")
|
|
78
|
+
return (
|
|
79
|
+
<label
|
|
80
|
+
className="contact-form-wide contact-form-checkbox"
|
|
81
|
+
key={key}
|
|
82
|
+
>
|
|
83
|
+
<input
|
|
84
|
+
name={key}
|
|
85
|
+
required={required}
|
|
86
|
+
type="checkbox"
|
|
87
|
+
value="true"
|
|
88
|
+
/>
|
|
89
|
+
<span>
|
|
90
|
+
{label}
|
|
91
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
92
|
+
</span>
|
|
93
|
+
</label>
|
|
94
|
+
);
|
|
95
|
+
if (type === "select")
|
|
96
|
+
return (
|
|
97
|
+
<label key={key}>
|
|
98
|
+
<span>
|
|
99
|
+
{label}
|
|
100
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
101
|
+
</span>
|
|
102
|
+
<select name={key} required={required}>
|
|
103
|
+
{records(field, "options").map((option) => (
|
|
104
|
+
<option
|
|
105
|
+
key={text(option, "value")}
|
|
106
|
+
value={text(option, "value")}
|
|
107
|
+
>
|
|
108
|
+
{text(option, "label", text(option, "value"))}
|
|
109
|
+
</option>
|
|
110
|
+
))}
|
|
111
|
+
</select>
|
|
112
|
+
</label>
|
|
113
|
+
);
|
|
114
|
+
return (
|
|
115
|
+
<label
|
|
116
|
+
className={type === "textarea" ? "contact-form-wide" : ""}
|
|
117
|
+
key={key}
|
|
118
|
+
>
|
|
119
|
+
<span>
|
|
120
|
+
{label}
|
|
121
|
+
{required && <small aria-hidden="true"> *</small>}
|
|
122
|
+
</span>
|
|
123
|
+
{type === "textarea" ? (
|
|
124
|
+
<textarea
|
|
125
|
+
name={key}
|
|
126
|
+
placeholder={text(field, "placeholder")}
|
|
127
|
+
required={required}
|
|
128
|
+
rows={5}
|
|
129
|
+
/>
|
|
130
|
+
) : (
|
|
131
|
+
<input
|
|
132
|
+
name={key}
|
|
133
|
+
placeholder={text(field, "placeholder")}
|
|
134
|
+
required={required}
|
|
135
|
+
type={
|
|
136
|
+
["email", "tel", "url", "number"].includes(type)
|
|
137
|
+
? type
|
|
138
|
+
: "text"
|
|
139
|
+
}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
142
|
+
</label>
|
|
143
|
+
);
|
|
144
|
+
})}
|
|
145
|
+
<div className="contact-form-wide">
|
|
146
|
+
<button
|
|
147
|
+
className="button button-primary"
|
|
148
|
+
disabled={status === "sending"}
|
|
149
|
+
type="submit"
|
|
150
|
+
>
|
|
151
|
+
{status === "sending" ? "" : text(props, "submitLabel")}
|
|
152
|
+
</button>
|
|
153
|
+
{status === "success" && text(props, "successMessage") && (
|
|
154
|
+
<p className="contact-form-feedback" role="status">
|
|
155
|
+
{text(props, "successMessage")}
|
|
156
|
+
</p>
|
|
157
|
+
)}
|
|
158
|
+
{status === "error" && (
|
|
159
|
+
<p
|
|
160
|
+
className="contact-form-feedback contact-form-error"
|
|
161
|
+
role="alert"
|
|
162
|
+
>
|
|
163
|
+
{error}
|
|
164
|
+
</p>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
</form>
|
|
168
|
+
</div>
|
|
169
|
+
</section>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function text(data: Record<string, unknown>, key: string, fallback = "") {
|
|
2
|
+
const value = data[key];
|
|
3
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export function record(
|
|
8
|
+
data: Record<string, unknown>,
|
|
9
|
+
key: string,
|
|
10
|
+
): Record<string, unknown> {
|
|
11
|
+
const value = data[key];
|
|
12
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
13
|
+
? (value as Record<string, unknown>)
|
|
14
|
+
: {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export function records(
|
|
19
|
+
data: Record<string, unknown>,
|
|
20
|
+
key: string,
|
|
21
|
+
): Record<string, unknown>[] {
|
|
22
|
+
const value = data[key];
|
|
23
|
+
return Array.isArray(value)
|
|
24
|
+
? value.filter(
|
|
25
|
+
(item): item is Record<string, unknown> =>
|
|
26
|
+
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
|
27
|
+
)
|
|
28
|
+
: [];
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ContactForm } from "./contact-form.js";
|
|
2
|
+
import { text, record, records } from "./home-data.js";
|
|
2
3
|
import type {
|
|
3
4
|
HomeProps,
|
|
4
|
-
ThemeContactSubmissionInput,
|
|
5
5
|
ThemeEditorialItem,
|
|
6
6
|
ThemeHomeSection,
|
|
7
7
|
ThemeImage,
|
|
@@ -18,11 +18,6 @@ import {
|
|
|
18
18
|
type ThemeImageComponent,
|
|
19
19
|
} from "./shared.js";
|
|
20
20
|
|
|
21
|
-
function text(data: Record<string, unknown>, key: string, fallback = "") {
|
|
22
|
-
const value = data[key];
|
|
23
|
-
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
function limit(data: Record<string, unknown>) {
|
|
27
22
|
const value = Number(data.limit);
|
|
28
23
|
return Number.isInteger(value) ? Math.min(12, Math.max(1, value)) : 6;
|
|
@@ -34,29 +29,6 @@ function brandsGridColumns(data: Record<string, unknown>) {
|
|
|
34
29
|
return Number.isInteger(value) ? Math.min(6, Math.max(1, value)) : 5;
|
|
35
30
|
}
|
|
36
31
|
|
|
37
|
-
function record(
|
|
38
|
-
data: Record<string, unknown>,
|
|
39
|
-
key: string,
|
|
40
|
-
): Record<string, unknown> {
|
|
41
|
-
const value = data[key];
|
|
42
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
43
|
-
? (value as Record<string, unknown>)
|
|
44
|
-
: {};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function records(
|
|
48
|
-
data: Record<string, unknown>,
|
|
49
|
-
key: string,
|
|
50
|
-
): Record<string, unknown>[] {
|
|
51
|
-
const value = data[key];
|
|
52
|
-
return Array.isArray(value)
|
|
53
|
-
? value.filter(
|
|
54
|
-
(item): item is Record<string, unknown> =>
|
|
55
|
-
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
|
56
|
-
)
|
|
57
|
-
: [];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
32
|
function productCategory(data: Record<string, unknown>) {
|
|
61
33
|
const value = text(data, "categorySlug").toLocaleLowerCase("pt-BR");
|
|
62
34
|
if (
|
|
@@ -352,172 +324,6 @@ function TextSection({
|
|
|
352
324
|
);
|
|
353
325
|
}
|
|
354
326
|
|
|
355
|
-
function ContactForm({
|
|
356
|
-
section,
|
|
357
|
-
submitContact,
|
|
358
|
-
}: {
|
|
359
|
-
section: ThemeHomeSection;
|
|
360
|
-
submitContact?: (submission: ThemeContactSubmissionInput) => Promise<unknown>;
|
|
361
|
-
}) {
|
|
362
|
-
const props = record(section.data, "props");
|
|
363
|
-
const configured = records(props, "fields");
|
|
364
|
-
const fields = configured;
|
|
365
|
-
const [status, setStatus] = useState<
|
|
366
|
-
"idle" | "sending" | "success" | "error"
|
|
367
|
-
>("idle");
|
|
368
|
-
const [error, setError] = useState("");
|
|
369
|
-
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
|
370
|
-
event.preventDefault();
|
|
371
|
-
if (!submitContact) {
|
|
372
|
-
setStatus("error");
|
|
373
|
-
setError("O envio de contatos ainda não está disponível.");
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
const formElement = event.currentTarget;
|
|
377
|
-
const form = new FormData(formElement);
|
|
378
|
-
const values: ThemeContactSubmissionInput["values"] = {};
|
|
379
|
-
fields.forEach((field) => {
|
|
380
|
-
const key = text(field, "key");
|
|
381
|
-
if (!key) return;
|
|
382
|
-
if (text(field, "type") === "checkbox") {
|
|
383
|
-
values[key] = form.has(key);
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
const entries = form.getAll(key).map(String);
|
|
387
|
-
values[key] = entries.length > 1 ? entries : (entries[0] ?? "");
|
|
388
|
-
});
|
|
389
|
-
setStatus("sending");
|
|
390
|
-
setError("");
|
|
391
|
-
try {
|
|
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
|
-
});
|
|
399
|
-
formElement.reset();
|
|
400
|
-
setStatus("success");
|
|
401
|
-
} catch (cause) {
|
|
402
|
-
setStatus("error");
|
|
403
|
-
setError(
|
|
404
|
-
cause instanceof Error
|
|
405
|
-
? cause.message
|
|
406
|
-
: "Não foi possível enviar o contato.",
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
};
|
|
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
327
|
function ThemeComponent({
|
|
522
328
|
section,
|
|
523
329
|
submitContact,
|