@nuvler/cli 0.5.17 → 0.5.19
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.map +1 -1
- package/dist/commands/theme/create.js +1 -1
- package/dist/nuvler.js +10 -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/interaction-colors.ts +49 -0
- package/dist/templates/nuvler-default/src/kit-composition.ts +15 -0
- package/dist/templates/nuvler-default/src/not-found.tsx +288 -21
- package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +24 -12
- package/dist/templates/nuvler-default/src/server-shell.tsx +21 -3
- package/dist/templates/nuvler-default/src/theme-component.tsx +100 -27
- package/dist/templates/nuvler-default/src/theme.css +599 -210
- 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 +3 -3
- 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
- package/preview-host/vendor/theme-runtime/default-theme.tsx +15 -6
|
@@ -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.24",
|
|
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.9"
|
|
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,49 @@
|
|
|
1
|
+
import type { ThemeSiteColors } from "@nuvler/theme-sdk";
|
|
2
|
+
|
|
3
|
+
/** Keep existing tokens as defaults; isolate component overrides from other surfaces. */
|
|
4
|
+
export function interactionColorVariables(colors: ThemeSiteColors) {
|
|
5
|
+
const surface = colors.surface ?? "#ffffff";
|
|
6
|
+
const text = colors.text;
|
|
7
|
+
return {
|
|
8
|
+
"--mobile-menu-text":
|
|
9
|
+
colors.mobileMenuText ?? colors.headerText ?? text,
|
|
10
|
+
"--mobile-menu-hover": `color-mix(in srgb, ${colors.mobileMenuText ?? colors.headerText ?? text}, transparent 88%)`,
|
|
11
|
+
"--search-toggle-background": colors.searchButtonBackground ?? "transparent",
|
|
12
|
+
"--search-toggle-text":
|
|
13
|
+
colors.searchButtonText ?? colors.headerText ?? text,
|
|
14
|
+
"--search-toggle-hover": colors.searchButtonBackground
|
|
15
|
+
? `color-mix(in srgb, ${colors.searchButtonBackground}, ${colors.searchButtonText ?? "#ffffff"} 12%)`
|
|
16
|
+
: (colors.surfaceAlt ?? "#f4f7f3"),
|
|
17
|
+
"--search-background": colors.searchBackground ?? surface,
|
|
18
|
+
"--search-text": colors.searchText ?? text,
|
|
19
|
+
"--search-button-background":
|
|
20
|
+
colors.searchButtonBackground ?? colors.secondary,
|
|
21
|
+
"--search-button-text": colors.searchButtonText ?? "#ffffff",
|
|
22
|
+
"--search-muted": colors.searchText
|
|
23
|
+
? `color-mix(in srgb, ${colors.searchText}, transparent 25%)`
|
|
24
|
+
: (colors.textMuted ?? "#657068"),
|
|
25
|
+
"--search-hover":
|
|
26
|
+
colors.searchBackground || colors.searchText
|
|
27
|
+
? `color-mix(in srgb, ${colors.searchBackground ?? surface}, ${colors.searchText ?? text} 8%)`
|
|
28
|
+
: (colors.surfaceAlt ?? "#f4f7f3"),
|
|
29
|
+
"--cart-close-background":
|
|
30
|
+
colors.cartBackground || colors.cartText
|
|
31
|
+
? `color-mix(in srgb, ${colors.cartText ?? text}, ${colors.cartBackground ?? surface} 95%)`
|
|
32
|
+
: colors.background,
|
|
33
|
+
"--search-border":
|
|
34
|
+
colors.searchBackground || colors.searchText
|
|
35
|
+
? `color-mix(in srgb, ${colors.searchText ?? text}, transparent 80%)`
|
|
36
|
+
: (colors.border ?? "#dce3dc"),
|
|
37
|
+
"--cart-button-background": colors.cartButtonBackground ?? surface,
|
|
38
|
+
"--cart-button-text": colors.cartButtonText ?? text,
|
|
39
|
+
"--cart-background": colors.cartBackground ?? surface,
|
|
40
|
+
"--cart-text": colors.cartText ?? text,
|
|
41
|
+
"--cart-muted": colors.cartText
|
|
42
|
+
? `color-mix(in srgb, ${colors.cartText}, transparent 25%)`
|
|
43
|
+
: (colors.textMuted ?? "#657068"),
|
|
44
|
+
"--cart-border":
|
|
45
|
+
colors.cartBackground || colors.cartText
|
|
46
|
+
? `color-mix(in srgb, ${colors.cartText ?? text}, transparent 80%)`
|
|
47
|
+
: (colors.border ?? "#dce3dc"),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
kitCompositionText as groupedCompositionText,
|
|
3
|
+
type ThemeCartItem,
|
|
4
|
+
} from "@nuvler/theme-sdk";
|
|
5
|
+
|
|
6
|
+
/** The default theme displays legacy kit choices without a generated prefix. */
|
|
7
|
+
export function kitCompositionText(
|
|
8
|
+
item: Pick<ThemeCartItem, "kitSize" | "kitGroups" | "composition">,
|
|
9
|
+
): string {
|
|
10
|
+
if (item.kitGroups?.length) return groupedCompositionText(item);
|
|
11
|
+
if (!item.kitSize) return "";
|
|
12
|
+
return (item.composition ?? [])
|
|
13
|
+
.map((part) => `${part.name}: ${part.quantity}`)
|
|
14
|
+
.join("; ");
|
|
15
|
+
}
|
|
@@ -1,16 +1,188 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
notFoundCopy,
|
|
6
|
+
type NotFoundProps,
|
|
7
|
+
type ThemeNotFoundResource,
|
|
8
|
+
type ThemeProduct,
|
|
9
|
+
} from "@nuvler/theme-sdk";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
import { ProductGrid } from "./products.js";
|
|
12
|
+
import type { ThemeImageComponent } from "./shared.js";
|
|
13
|
+
|
|
14
|
+
export interface NotFoundShortcut {
|
|
15
|
+
label: string;
|
|
16
|
+
href: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Props do 404 do tema padrão. Os campos extras são opcionais: sem eles
|
|
21
|
+
* (ex.: fallback local do storefront) a página continua completa, só sem
|
|
22
|
+
* atalhos e sugestões.
|
|
23
|
+
*/
|
|
24
|
+
export interface NuvlerNotFoundProps extends NotFoundProps {
|
|
25
|
+
/** Produtos exibidos em "Talvez você goste destes" (produto/categoria). */
|
|
26
|
+
suggestions?: ThemeProduct[];
|
|
27
|
+
/** Busca usada para sugerir itens parecidos com o slug acessado. */
|
|
28
|
+
searchProducts?: (query: string) => Promise<ThemeProduct[]>;
|
|
29
|
+
/** Links de "Ou vá direto para" no 404 genérico. */
|
|
30
|
+
shortcuts?: NotFoundShortcut[];
|
|
31
|
+
showPrices?: boolean;
|
|
32
|
+
ImageComponent?: ThemeImageComponent;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const SUGGESTION_LIMIT = 4;
|
|
36
|
+
|
|
37
|
+
/** Títulos e textos com a voz do tema; o SDK fornece o rótulo neutro. */
|
|
38
|
+
const THEME_COPY: Record<
|
|
39
|
+
ThemeNotFoundResource,
|
|
40
|
+
{ title: string; description: string }
|
|
41
|
+
> = {
|
|
42
|
+
page: {
|
|
43
|
+
title: "Essa página se perdeu nas nuvens",
|
|
44
|
+
description:
|
|
45
|
+
"O endereço pode ter mudado, sido removido ou digitado errado. Mas calma, a gente te ajuda a voltar pro caminho.",
|
|
46
|
+
},
|
|
47
|
+
product: {
|
|
48
|
+
title: "Procuramos por todo canto e esse produto não apareceu",
|
|
49
|
+
description:
|
|
50
|
+
"Ele pode ter esgotado, saído do catálogo ou o link mudou. Que tal buscar algo parecido?",
|
|
51
|
+
},
|
|
52
|
+
category: {
|
|
53
|
+
title: "Essa categoria saiu da vitrine",
|
|
54
|
+
description:
|
|
55
|
+
"Ela pode ter sido renomeada ou removida. Busque o que você procura ou veja todos os produtos.",
|
|
56
|
+
},
|
|
57
|
+
post: {
|
|
58
|
+
title: "Esse artigo voou para longe",
|
|
59
|
+
description:
|
|
60
|
+
"Ele pode ter sido removido ou o link mudou. Os outros conteúdos do blog continuam por aqui.",
|
|
61
|
+
},
|
|
62
|
+
service: {
|
|
63
|
+
title: "Esse serviço não está mais por aqui",
|
|
64
|
+
description:
|
|
65
|
+
"Ele pode ter sido atualizado ou mudado de endereço. Confira os serviços disponíveis.",
|
|
66
|
+
},
|
|
67
|
+
case: {
|
|
68
|
+
title: "Esse case não está mais por aqui",
|
|
69
|
+
description:
|
|
70
|
+
"Ele pode ter sido removido ou ainda não foi publicado. Veja os outros cases.",
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** "camiseta-azul-p" -> "camiseta azul" para buscar itens parecidos. */
|
|
75
|
+
function searchTermsFromPath(pathname?: string): string {
|
|
76
|
+
const slug = pathname?.split("/").filter(Boolean).at(-1) ?? "";
|
|
77
|
+
let decoded = slug;
|
|
78
|
+
try {
|
|
79
|
+
decoded = decodeURIComponent(slug);
|
|
80
|
+
} catch {
|
|
81
|
+
// Mantém o slug bruto quando a URL vem malformada.
|
|
82
|
+
}
|
|
83
|
+
return decoded
|
|
84
|
+
.split(/[-_\s]+/)
|
|
85
|
+
.filter((word) => word.length >= 3 && !/^\d+$/.test(word))
|
|
86
|
+
.slice(0, 3)
|
|
87
|
+
.join(" ");
|
|
11
88
|
}
|
|
12
89
|
|
|
13
|
-
|
|
90
|
+
function CloudIllustration({ variant }: { variant: "lost" | "search" }) {
|
|
91
|
+
return (
|
|
92
|
+
<svg
|
|
93
|
+
className="nuvler-not-found-illustration"
|
|
94
|
+
viewBox="0 0 280 200"
|
|
95
|
+
aria-hidden="true"
|
|
96
|
+
>
|
|
97
|
+
<path
|
|
98
|
+
className="nf-cloud"
|
|
99
|
+
d="M74 172h128c30 0 52-21 52-48 0-26-20-46-46-47-6-32-33-55-66-55-27 0-50 16-59 40-4-1-8-1-12-1-30 0-53 24-53 54 0 32 24 57 56 57Z"
|
|
100
|
+
/>
|
|
101
|
+
<ellipse className="nf-eye" cx="118" cy="114" rx="7" ry="9" />
|
|
102
|
+
<ellipse className="nf-eye" cx="160" cy="114" rx="7" ry="9" />
|
|
103
|
+
<circle className="nf-eye-shine" cx="120.5" cy="110" r="2.4" />
|
|
104
|
+
<circle className="nf-eye-shine" cx="162.5" cy="110" r="2.4" />
|
|
105
|
+
<ellipse className="nf-cheek" cx="100" cy="134" rx="10" ry="5.5" />
|
|
106
|
+
<ellipse className="nf-cheek" cx="178" cy="134" rx="10" ry="5.5" />
|
|
107
|
+
{variant === "lost" ? (
|
|
108
|
+
<>
|
|
109
|
+
<path className="nf-mouth" d="M128 141q11-8 22 0" />
|
|
110
|
+
<path
|
|
111
|
+
className="nf-accent-stroke"
|
|
112
|
+
d="M222 26c0-11 9-18 19-18s19 7 19 17c0 13-17 14-17 28"
|
|
113
|
+
/>
|
|
114
|
+
<circle className="nf-accent-fill" cx="243" cy="68" r="5.5" />
|
|
115
|
+
</>
|
|
116
|
+
) : (
|
|
117
|
+
<>
|
|
118
|
+
<path className="nf-mouth" d="M128 139h22" />
|
|
119
|
+
<circle className="nf-lens" cx="232" cy="46" r="24" />
|
|
120
|
+
<path className="nf-lens-shine" d="M220 36a14 14 0 0 1 12-6" />
|
|
121
|
+
<path className="nf-accent-stroke" d="M215 64l-18 22" />
|
|
122
|
+
</>
|
|
123
|
+
)}
|
|
124
|
+
</svg>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function HomeIcon() {
|
|
129
|
+
return (
|
|
130
|
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
131
|
+
<path d="M4 11.5 12 5l8 6.5V20a1 1 0 0 1-1 1h-4.5v-6h-5v6H5a1 1 0 0 1-1-1z" />
|
|
132
|
+
</svg>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function BackIcon() {
|
|
137
|
+
return (
|
|
138
|
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
139
|
+
<path d="m14.5 6-6 6 6 6" />
|
|
140
|
+
</svg>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function SearchIcon() {
|
|
145
|
+
return (
|
|
146
|
+
<svg viewBox="0 0 24 24" aria-hidden="true">
|
|
147
|
+
<circle cx="11" cy="11" r="7" />
|
|
148
|
+
<path d="m16.5 16.5 4 4" />
|
|
149
|
+
</svg>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function NotFound({
|
|
154
|
+
homeHref = "/",
|
|
155
|
+
resource = "page",
|
|
156
|
+
pathname,
|
|
157
|
+
suggestions = [],
|
|
158
|
+
searchProducts,
|
|
159
|
+
shortcuts = [],
|
|
160
|
+
showPrices = true,
|
|
161
|
+
ImageComponent,
|
|
162
|
+
}: NuvlerNotFoundProps) {
|
|
163
|
+
const label = notFoundCopy(resource, homeHref);
|
|
164
|
+
const copy = THEME_COPY[resource] ?? THEME_COPY.page;
|
|
165
|
+
const isCatalog = resource === "product" || resource === "category";
|
|
166
|
+
|
|
167
|
+
const [related, setRelated] = useState<ThemeProduct[] | null>(null);
|
|
168
|
+
const terms = isCatalog ? searchTermsFromPath(pathname) : "";
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (!terms || !searchProducts) return;
|
|
171
|
+
let cancelled = false;
|
|
172
|
+
searchProducts(terms)
|
|
173
|
+
.then((items) => {
|
|
174
|
+
if (!cancelled && items.length)
|
|
175
|
+
setRelated(items.slice(0, SUGGESTION_LIMIT));
|
|
176
|
+
})
|
|
177
|
+
.catch(() => {
|
|
178
|
+
// Sem sugestões relacionadas: mantém as sugestões gerais.
|
|
179
|
+
});
|
|
180
|
+
return () => {
|
|
181
|
+
cancelled = true;
|
|
182
|
+
};
|
|
183
|
+
}, [terms, searchProducts]);
|
|
184
|
+
const products = related ?? suggestions.slice(0, SUGGESTION_LIMIT);
|
|
185
|
+
|
|
14
186
|
const goBack = () => {
|
|
15
187
|
if (window.history.length > 1) {
|
|
16
188
|
window.history.back();
|
|
@@ -19,18 +191,113 @@ export function NotFound({ homeHref = "/" }: NotFoundProps) {
|
|
|
19
191
|
window.location.assign(homeHref);
|
|
20
192
|
};
|
|
21
193
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
194
|
+
if (isCatalog)
|
|
195
|
+
return (
|
|
196
|
+
<main
|
|
197
|
+
className="nuvler-not-found nuvler-not-found-catalog"
|
|
198
|
+
data-not-found-resource={resource}
|
|
199
|
+
>
|
|
200
|
+
<div className="store-container">
|
|
201
|
+
<section className="nuvler-not-found-card">
|
|
202
|
+
<div className="nuvler-not-found-art">
|
|
203
|
+
<CloudIllustration variant="search" />
|
|
204
|
+
</div>
|
|
205
|
+
<div className="nuvler-not-found-body">
|
|
206
|
+
<span className="nuvler-not-found-eyebrow">
|
|
207
|
+
Erro 404 · {label.title}
|
|
208
|
+
</span>
|
|
209
|
+
<h1>{copy.title}</h1>
|
|
210
|
+
<p>{copy.description}</p>
|
|
211
|
+
<form
|
|
212
|
+
className="nuvler-not-found-search"
|
|
213
|
+
action="/produtos"
|
|
214
|
+
method="get"
|
|
215
|
+
role="search"
|
|
216
|
+
>
|
|
217
|
+
<label>
|
|
218
|
+
<SearchIcon />
|
|
219
|
+
<span className="nuvler-not-found-sr">Buscar na loja</span>
|
|
220
|
+
<input
|
|
221
|
+
name="busca"
|
|
222
|
+
type="search"
|
|
223
|
+
placeholder="Buscar na loja..."
|
|
224
|
+
autoComplete="off"
|
|
225
|
+
/>
|
|
226
|
+
</label>
|
|
227
|
+
<button className="button button-primary" type="submit">
|
|
228
|
+
Buscar
|
|
229
|
+
</button>
|
|
230
|
+
</form>
|
|
231
|
+
<div className="nuvler-not-found-links">
|
|
232
|
+
<a className="is-primary" href={label.action.href}>
|
|
233
|
+
{label.action.label} →
|
|
234
|
+
</a>
|
|
235
|
+
<a href={homeHref}>Voltar à loja</a>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
</section>
|
|
239
|
+
{products.length > 0 && (
|
|
240
|
+
<section className="nuvler-not-found-suggestions">
|
|
241
|
+
<header>
|
|
242
|
+
<h2>Talvez você goste destes</h2>
|
|
243
|
+
<a href={label.action.href}>Ver mais</a>
|
|
244
|
+
</header>
|
|
245
|
+
<ProductGrid
|
|
246
|
+
products={products}
|
|
247
|
+
columns={4}
|
|
248
|
+
showPrices={showPrices}
|
|
249
|
+
showDescription={false}
|
|
250
|
+
ImageComponent={ImageComponent}
|
|
251
|
+
/>
|
|
252
|
+
</section>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
</main>
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
const specific = resource !== "page";
|
|
259
|
+
return (
|
|
260
|
+
<main
|
|
261
|
+
className="nuvler-not-found nuvler-not-found-page"
|
|
262
|
+
data-not-found-resource={resource}
|
|
263
|
+
>
|
|
264
|
+
<span className="nuvler-not-found-puff puff-a" aria-hidden="true" />
|
|
265
|
+
<span className="nuvler-not-found-puff puff-b" aria-hidden="true" />
|
|
266
|
+
<span className="nuvler-not-found-puff puff-c" aria-hidden="true" />
|
|
267
|
+
<div className="nuvler-not-found-content">
|
|
268
|
+
<CloudIllustration variant="lost" />
|
|
269
|
+
<span className="nuvler-not-found-eyebrow">
|
|
270
|
+
{specific ? `Erro 404 · ${label.title}` : "Erro 404"}
|
|
271
|
+
</span>
|
|
272
|
+
<h1>{copy.title}</h1>
|
|
273
|
+
<p>{copy.description}</p>
|
|
274
|
+
<div className="nuvler-not-found-actions">
|
|
275
|
+
<a className="button button-primary" href={label.action.href}>
|
|
276
|
+
{!specific && <HomeIcon />}
|
|
277
|
+
{label.action.label}
|
|
278
|
+
</a>
|
|
279
|
+
<button
|
|
280
|
+
className="button nuvler-not-found-ghost"
|
|
281
|
+
type="button"
|
|
282
|
+
onClick={goBack}
|
|
283
|
+
>
|
|
284
|
+
<BackIcon />
|
|
285
|
+
Voltar à página anterior
|
|
286
|
+
</button>
|
|
287
|
+
</div>
|
|
288
|
+
{shortcuts.length > 0 && (
|
|
289
|
+
<nav className="nuvler-not-found-shortcuts" aria-label="Atalhos">
|
|
290
|
+
<span>Ou vá direto para</span>
|
|
291
|
+
<ul>
|
|
292
|
+
{shortcuts.map((shortcut) => (
|
|
293
|
+
<li key={shortcut.href}>
|
|
294
|
+
<a href={shortcut.href}>{shortcut.label}</a>
|
|
295
|
+
</li>
|
|
296
|
+
))}
|
|
297
|
+
</ul>
|
|
298
|
+
</nav>
|
|
299
|
+
)}
|
|
33
300
|
</div>
|
|
34
|
-
</
|
|
35
|
-
|
|
301
|
+
</main>
|
|
302
|
+
);
|
|
36
303
|
}
|