@hszrdm/create-commerce 1.1.0 → 1.3.0
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/package.json +2 -2
- package/src/cli.mjs +5 -2
- package/templates/backend/.env.example +45 -0
- package/templates/backend/package.json +1 -1
- package/templates/storefront/README.md +14 -1
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +43 -9
- package/templates/storefront/src/app/account/page.tsx +12 -1
- package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
- package/templates/storefront/src/app/blog/[slug]/page.tsx +36 -0
- package/templates/storefront/src/app/blog/page.tsx +25 -0
- package/templates/storefront/src/app/contact/page.tsx +25 -0
- package/templates/storefront/src/app/core-ux.css +244 -0
- package/templates/storefront/src/app/customer-capabilities.css +60 -0
- package/templates/storefront/src/app/knowledge-base/[slug]/page.tsx +35 -0
- package/templates/storefront/src/app/knowledge-base/page.tsx +25 -0
- package/templates/storefront/src/app/layout.tsx +40 -12
- package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
- package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
- package/templates/storefront/src/app/pages/[slug]/page.tsx +35 -0
- package/templates/storefront/src/app/quote-request/page.tsx +20 -0
- package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
- package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
- package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
- package/templates/storefront/src/components/account-wishlist.tsx +95 -0
- package/templates/storefront/src/components/add-to-cart.tsx +110 -15
- package/templates/storefront/src/components/back-to-top.tsx +26 -0
- package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
- package/templates/storefront/src/components/cart-view.tsx +72 -16
- package/templates/storefront/src/components/cms-content.tsx +75 -0
- package/templates/storefront/src/components/form-ux.tsx +47 -0
- package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
- package/templates/storefront/src/components/lead-form.tsx +203 -0
- package/templates/storefront/src/components/newsletter-action.tsx +66 -0
- package/templates/storefront/src/components/newsletter-signup.tsx +107 -0
- package/templates/storefront/src/components/product-gallery.tsx +64 -0
- package/templates/storefront/src/components/product-reviews.tsx +150 -0
- package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
- package/templates/storefront/src/components/quote-request-form.tsx +212 -0
- package/templates/storefront/src/components/share-button.tsx +63 -0
- package/templates/storefront/src/components/storefront-header.tsx +72 -18
- package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
- package/templates/storefront/src/components/toast-provider.tsx +92 -0
- package/templates/storefront/src/components/variant-price-display.tsx +31 -0
- package/templates/storefront/src/components/wishlist-button.tsx +88 -0
- package/templates/storefront/src/lib/core/account.ts +3 -0
- package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
- package/templates/storefront/src/lib/core/cms.ts +71 -11
- package/templates/storefront/src/lib/core/form-ux.ts +57 -0
- package/templates/storefront/src/lib/core/newsletter.ts +53 -0
- package/templates/storefront/src/lib/core/reviews.ts +40 -0
- package/templates/storefront/src/lib/core/share.ts +57 -0
- package/templates/storefront/src/lib/core/wishlist.ts +88 -0
- package/templates/storefront/src/lib/storefront-routes.ts +33 -0
- package/templates/storefront/src/proxy.ts +25 -28
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Metadata } from "next"
|
|
2
|
+
import { notFound } from "next/navigation"
|
|
3
|
+
import { Breadcrumbs } from "@/components/breadcrumbs"
|
|
4
|
+
import { CmsEntryBody, CmsEntryMeta } from "@/components/cms-content"
|
|
5
|
+
import { cmsEntrySeo, getKnowledgeBaseEntry } from "@/lib/core/cms"
|
|
6
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
7
|
+
import { STOREFRONT_ROUTES, medusaLocale } from "@/lib/storefront-routes"
|
|
8
|
+
|
|
9
|
+
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
|
10
|
+
const { slug } = await params
|
|
11
|
+
const locale = await requestStorefrontLocale()
|
|
12
|
+
const result = await getKnowledgeBaseEntry(slug, { locale: medusaLocale(locale) }).catch(() => null)
|
|
13
|
+
return result ? cmsEntrySeo(result.entry) : {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default async function KnowledgeBaseEntryPage({ params }: { params: Promise<{ slug: string }> }) {
|
|
17
|
+
const { slug } = await params
|
|
18
|
+
const locale = await requestStorefrontLocale()
|
|
19
|
+
const english = locale === "en"
|
|
20
|
+
const result = await getKnowledgeBaseEntry(slug, { locale: medusaLocale(locale) }).catch(() => null)
|
|
21
|
+
if (!result) notFound()
|
|
22
|
+
const entry = result.entry
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<article className="stack page-section cms-detail">
|
|
26
|
+
<Breadcrumbs items={[{ label: english ? "Knowledge base" : "Tudástár", href: STOREFRONT_ROUTES[locale].knowledgeBase }, { label: entry.title }]} label={english ? "Breadcrumb" : "Morzsanavigáció"} />
|
|
27
|
+
<header className="stack-sm">
|
|
28
|
+
<CmsEntryMeta entry={entry} locale={locale} />
|
|
29
|
+
<h1>{entry.title}</h1>
|
|
30
|
+
{entry.excerpt ? <p className="lead">{entry.excerpt}</p> : null}
|
|
31
|
+
</header>
|
|
32
|
+
<CmsEntryBody entry={entry} />
|
|
33
|
+
</article>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CmsEntryCard } from "@/components/cms-content"
|
|
2
|
+
import { listKnowledgeBaseEntries } from "@/lib/core/cms"
|
|
3
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
4
|
+
import { knowledgeBasePath, medusaLocale } from "@/lib/storefront-routes"
|
|
5
|
+
|
|
6
|
+
export default async function KnowledgeBasePage() {
|
|
7
|
+
const locale = await requestStorefrontLocale()
|
|
8
|
+
const english = locale === "en"
|
|
9
|
+
const { entries } = await listKnowledgeBaseEntries({ locale: medusaLocale(locale), limit: 100 }).catch(() => ({ entries: [] }))
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className="stack page-section">
|
|
13
|
+
<header className="stack-sm">
|
|
14
|
+
<p className="eyebrow">{english ? "Help center" : "Segítség"}</p>
|
|
15
|
+
<h1>{english ? "Knowledge base" : "Tudástár"}</h1>
|
|
16
|
+
<p className="muted">{english ? "Answers, guides and practical information." : "Válaszok, útmutatók és gyakorlati információk."}</p>
|
|
17
|
+
</header>
|
|
18
|
+
{entries.length ? (
|
|
19
|
+
<div className="cms-grid">
|
|
20
|
+
{entries.map((entry) => <CmsEntryCard key={entry.id} entry={entry} href={knowledgeBasePath(locale, entry.slug)} locale={locale} />)}
|
|
21
|
+
</div>
|
|
22
|
+
) : <div className="empty-state">{english ? "No knowledge-base entries yet." : "Még nincs publikált tudástár-bejegyzés."}</div>}
|
|
23
|
+
</div>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import "./globals.css"
|
|
2
|
+
import "./core-ux.css"
|
|
3
|
+
import "./customer-capabilities.css"
|
|
2
4
|
import type { Metadata } from "next"
|
|
3
5
|
import Link from "next/link"
|
|
6
|
+
import { AccessibilityPreferencesControl, AccessibilityPreferencesProvider } from "@/components/accessibility-preferences"
|
|
4
7
|
import { AnalyticsGate } from "@/components/analytics"
|
|
5
8
|
import { CartProvider } from "@/components/cart-provider"
|
|
6
9
|
import { ConsentBanner } from "@/components/consent-banner"
|
|
10
|
+
import { NewsletterSignup } from "@/components/newsletter-signup"
|
|
7
11
|
import { StorefrontHeader } from "@/components/storefront-header"
|
|
12
|
+
import { ToastProvider } from "@/components/toast-provider"
|
|
8
13
|
import { getCoreConfig } from "@/lib/core/client"
|
|
9
14
|
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
10
15
|
import { STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
@@ -43,23 +48,46 @@ export default async function RootLayout({ children }: Readonly<{ children: Reac
|
|
|
43
48
|
requestStorefrontLocale(),
|
|
44
49
|
])
|
|
45
50
|
const routes = STOREFRONT_ROUTES[locale]
|
|
51
|
+
const en = locale === "en"
|
|
46
52
|
|
|
47
53
|
return (
|
|
48
54
|
<html lang={locale}>
|
|
49
55
|
<head><script dangerouslySetInnerHTML={{ __html: consentDefaultScript }} /></head>
|
|
50
56
|
<body>
|
|
51
|
-
<
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
<AccessibilityPreferencesProvider>
|
|
58
|
+
<ToastProvider locale={locale}>
|
|
59
|
+
<CartProvider config={config}>
|
|
60
|
+
<a className="skip-link" href="#main-content">
|
|
61
|
+
{en ? "Skip to content" : "Ugrás a tartalomhoz"}
|
|
62
|
+
</a>
|
|
63
|
+
<StorefrontHeader config={config} />
|
|
64
|
+
<main id="main-content" className="shell main" tabIndex={-1}>{children}</main>
|
|
65
|
+
<footer className="footer">
|
|
66
|
+
<div className="shell footer-newsletter-shell">
|
|
67
|
+
<NewsletterSignup locale={locale} />
|
|
68
|
+
</div>
|
|
69
|
+
<div className="shell footer-inner">
|
|
70
|
+
<div>
|
|
71
|
+
<strong>{config.store.name}</strong>
|
|
72
|
+
<p className="muted small">Powered by HSZRDM Commerce</p>
|
|
73
|
+
</div>
|
|
74
|
+
<nav className="footer-nav" aria-label={en ? "Footer navigation" : "Lábléc navigáció"}>
|
|
75
|
+
<Link href={routes.products}>{en ? "Products" : "Termékek"}</Link>
|
|
76
|
+
<Link href={routes.blog}>{en ? "Blog" : "Blog"}</Link>
|
|
77
|
+
<Link href={routes.knowledgeBase}>{en ? "Knowledge base" : "Tudástár"}</Link>
|
|
78
|
+
<Link href={routes.quoteRequest}>{en ? "Request a quote" : "Ajánlatkérés"}</Link>
|
|
79
|
+
<Link href={routes.contact}>{en ? "Contact" : "Kapcsolat"}</Link>
|
|
80
|
+
<Link href={routes.account}>{en ? "Account" : "Fiókom"}</Link>
|
|
81
|
+
<Link href={routes.legal}>{en ? "Legal documents" : "Jogi dokumentumok"}</Link>
|
|
82
|
+
</nav>
|
|
83
|
+
<AccessibilityPreferencesControl locale={locale} />
|
|
84
|
+
</div>
|
|
85
|
+
</footer>
|
|
86
|
+
<AnalyticsGate analytics={config.analytics} />
|
|
87
|
+
<ConsentBanner enabled={config.features.analytics} />
|
|
88
|
+
</CartProvider>
|
|
89
|
+
</ToastProvider>
|
|
90
|
+
</AccessibilityPreferencesProvider>
|
|
63
91
|
</body>
|
|
64
92
|
</html>
|
|
65
93
|
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NewsletterAction } from "@/components/newsletter-action"
|
|
2
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
3
|
+
|
|
4
|
+
type PageProps = {
|
|
5
|
+
searchParams: Promise<Record<string, string | string[] | undefined>>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default async function NewsletterConfirmPage({ searchParams }: PageProps) {
|
|
9
|
+
const [params, locale] = await Promise.all([searchParams, requestStorefrontLocale()])
|
|
10
|
+
const rawToken = params.token
|
|
11
|
+
const token = Array.isArray(rawToken) ? rawToken[0] || "" : rawToken || ""
|
|
12
|
+
const language = String(locale).startsWith("en") ? "en" : "hu"
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div className="page-section narrow-page">
|
|
16
|
+
<NewsletterAction action="confirm" token={token} locale={language} />
|
|
17
|
+
</div>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NewsletterAction } from "@/components/newsletter-action"
|
|
2
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
3
|
+
|
|
4
|
+
type PageProps = {
|
|
5
|
+
searchParams: Promise<Record<string, string | string[] | undefined>>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default async function NewsletterUnsubscribePage({ searchParams }: PageProps) {
|
|
9
|
+
const [params, locale] = await Promise.all([searchParams, requestStorefrontLocale()])
|
|
10
|
+
const rawToken = params.token
|
|
11
|
+
const token = Array.isArray(rawToken) ? rawToken[0] || "" : rawToken || ""
|
|
12
|
+
const language = String(locale).startsWith("en") ? "en" : "hu"
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div className="page-section narrow-page">
|
|
16
|
+
<NewsletterAction action="unsubscribe" token={token} locale={language} />
|
|
17
|
+
</div>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Metadata } from "next"
|
|
2
|
+
import { notFound } from "next/navigation"
|
|
3
|
+
import { Breadcrumbs } from "@/components/breadcrumbs"
|
|
4
|
+
import { CmsEntryBody } from "@/components/cms-content"
|
|
5
|
+
import { cmsEntrySeo, getCmsPage } from "@/lib/core/cms"
|
|
6
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
7
|
+
import { STOREFRONT_ROUTES, medusaLocale } from "@/lib/storefront-routes"
|
|
8
|
+
|
|
9
|
+
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
|
10
|
+
const { slug } = await params
|
|
11
|
+
const locale = await requestStorefrontLocale()
|
|
12
|
+
const result = await getCmsPage(slug, { locale: medusaLocale(locale) }).catch(() => null)
|
|
13
|
+
return result ? cmsEntrySeo(result.entry) : {}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default async function CmsPage({ params }: { params: Promise<{ slug: string }> }) {
|
|
17
|
+
const { slug } = await params
|
|
18
|
+
const locale = await requestStorefrontLocale()
|
|
19
|
+
const english = locale === "en"
|
|
20
|
+
const result = await getCmsPage(slug, { locale: medusaLocale(locale) }).catch(() => null)
|
|
21
|
+
if (!result) notFound()
|
|
22
|
+
const entry = result.entry
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<article className="stack page-section cms-detail">
|
|
26
|
+
<Breadcrumbs items={[{ label: english ? "Pages" : "Oldalak", href: STOREFRONT_ROUTES[locale].home }, { label: entry.title }]} label={english ? "Breadcrumb" : "Morzsanavigáció"} />
|
|
27
|
+
<header className="stack-sm">
|
|
28
|
+
<h1>{entry.title}</h1>
|
|
29
|
+
{entry.excerpt ? <p className="lead">{entry.excerpt}</p> : null}
|
|
30
|
+
{entry.featured_image_url ? <img className="cms-hero-image" src={entry.featured_image_url} alt={entry.featured_image_alt || entry.title} /> : null}
|
|
31
|
+
</header>
|
|
32
|
+
<CmsEntryBody entry={entry} />
|
|
33
|
+
</article>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { QuoteRequestForm } from "@/components/quote-request-form"
|
|
2
|
+
import { quoteRequestConfig } from "@/lib/core/quotes"
|
|
3
|
+
import { requestStorefrontLocale } from "@/lib/storefront-locale-server"
|
|
4
|
+
|
|
5
|
+
export default async function QuoteRequestPage() {
|
|
6
|
+
const locale = await requestStorefrontLocale()
|
|
7
|
+
const english = locale === "en"
|
|
8
|
+
const config = await quoteRequestConfig().catch(() => ({ enabled: false, order_types: [], extra_fields: [] }))
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<div className="stack page-section narrow-page">
|
|
12
|
+
<header className="stack-sm">
|
|
13
|
+
<p className="eyebrow">{english ? "Business request" : "Üzleti megkeresés"}</p>
|
|
14
|
+
<h1>{english ? "Request a quote" : "Ajánlatkérés"}</h1>
|
|
15
|
+
<p className="muted">{english ? "Describe what you need and we will prepare a tailored offer." : "Írd le, mire van szükséged, és személyre szabott ajánlatot készítünk."}</p>
|
|
16
|
+
</header>
|
|
17
|
+
<QuoteRequestForm locale={locale} config={config} />
|
|
18
|
+
</div>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useState,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from "react"
|
|
11
|
+
|
|
12
|
+
type ContrastPreference = "normal" | "high"
|
|
13
|
+
type MotionPreference = "system" | "reduced" | "full"
|
|
14
|
+
type FontScalePreference = "normal" | "large"
|
|
15
|
+
|
|
16
|
+
type AccessibilityPreferences = {
|
|
17
|
+
contrast: ContrastPreference
|
|
18
|
+
motion: MotionPreference
|
|
19
|
+
fontScale: FontScalePreference
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type AccessibilityContextValue = AccessibilityPreferences & {
|
|
23
|
+
setContrast: (value: ContrastPreference) => void
|
|
24
|
+
setMotion: (value: MotionPreference) => void
|
|
25
|
+
setFontScale: (value: FontScalePreference) => void
|
|
26
|
+
reset: () => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const STORAGE_KEY = "hszrdm_accessibility_preferences"
|
|
30
|
+
const defaults: AccessibilityPreferences = {
|
|
31
|
+
contrast: "normal",
|
|
32
|
+
motion: "system",
|
|
33
|
+
fontScale: "normal",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const AccessibilityContext = createContext<AccessibilityContextValue | null>(null)
|
|
37
|
+
|
|
38
|
+
export function AccessibilityPreferencesProvider({ children }: { children: ReactNode }) {
|
|
39
|
+
const [preferences, setPreferences] = useState<AccessibilityPreferences>(defaults)
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
try {
|
|
43
|
+
const raw = window.localStorage.getItem(STORAGE_KEY)
|
|
44
|
+
if (!raw) return
|
|
45
|
+
const parsed = JSON.parse(raw) as Partial<AccessibilityPreferences>
|
|
46
|
+
setPreferences({
|
|
47
|
+
contrast: parsed.contrast === "high" ? "high" : "normal",
|
|
48
|
+
motion: parsed.motion === "reduced" || parsed.motion === "full" ? parsed.motion : "system",
|
|
49
|
+
fontScale: parsed.fontScale === "large" ? "large" : "normal",
|
|
50
|
+
})
|
|
51
|
+
} catch {
|
|
52
|
+
// Invalid legacy preference must not block rendering.
|
|
53
|
+
}
|
|
54
|
+
}, [])
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const root = document.documentElement
|
|
58
|
+
root.dataset.contrast = preferences.contrast
|
|
59
|
+
root.dataset.motion = preferences.motion
|
|
60
|
+
root.dataset.fontScale = preferences.fontScale
|
|
61
|
+
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(preferences))
|
|
62
|
+
}, [preferences])
|
|
63
|
+
|
|
64
|
+
const value = useMemo<AccessibilityContextValue>(() => ({
|
|
65
|
+
...preferences,
|
|
66
|
+
setContrast: (contrast) => setPreferences((current) => ({ ...current, contrast })),
|
|
67
|
+
setMotion: (motion) => setPreferences((current) => ({ ...current, motion })),
|
|
68
|
+
setFontScale: (fontScale) => setPreferences((current) => ({ ...current, fontScale })),
|
|
69
|
+
reset: () => setPreferences(defaults),
|
|
70
|
+
}), [preferences])
|
|
71
|
+
|
|
72
|
+
return <AccessibilityContext.Provider value={value}>{children}</AccessibilityContext.Provider>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function AccessibilityPreferencesControl({ locale = "hu" }: { locale?: "hu" | "en" }) {
|
|
76
|
+
const preferences = useAccessibilityPreferences()
|
|
77
|
+
const [open, setOpen] = useState(false)
|
|
78
|
+
const en = locale === "en"
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div className="accessibility-control">
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
className="text-button"
|
|
85
|
+
aria-expanded={open}
|
|
86
|
+
aria-controls="accessibility-preferences-panel"
|
|
87
|
+
onClick={() => setOpen((current) => !current)}
|
|
88
|
+
>
|
|
89
|
+
{en ? "Display preferences" : "Megjelenési beállítások"}
|
|
90
|
+
</button>
|
|
91
|
+
{open ? (
|
|
92
|
+
<div id="accessibility-preferences-panel" className="accessibility-panel stack-sm">
|
|
93
|
+
<label>
|
|
94
|
+
{en ? "Contrast" : "Kontraszt"}
|
|
95
|
+
<select value={preferences.contrast} onChange={(event) => preferences.setContrast(event.target.value as ContrastPreference)}>
|
|
96
|
+
<option value="normal">{en ? "Normal" : "Normál"}</option>
|
|
97
|
+
<option value="high">{en ? "High contrast" : "Magas kontraszt"}</option>
|
|
98
|
+
</select>
|
|
99
|
+
</label>
|
|
100
|
+
<label>
|
|
101
|
+
{en ? "Motion" : "Mozgás"}
|
|
102
|
+
<select value={preferences.motion} onChange={(event) => preferences.setMotion(event.target.value as MotionPreference)}>
|
|
103
|
+
<option value="system">{en ? "System preference" : "Rendszerbeállítás"}</option>
|
|
104
|
+
<option value="reduced">{en ? "Reduced" : "Csökkentett"}</option>
|
|
105
|
+
<option value="full">{en ? "Full" : "Teljes"}</option>
|
|
106
|
+
</select>
|
|
107
|
+
</label>
|
|
108
|
+
<label>
|
|
109
|
+
{en ? "Text size" : "Betűméret"}
|
|
110
|
+
<select value={preferences.fontScale} onChange={(event) => preferences.setFontScale(event.target.value as FontScalePreference)}>
|
|
111
|
+
<option value="normal">{en ? "Normal" : "Normál"}</option>
|
|
112
|
+
<option value="large">{en ? "Larger" : "Nagyobb"}</option>
|
|
113
|
+
</select>
|
|
114
|
+
</label>
|
|
115
|
+
<button type="button" className="button secondary" onClick={preferences.reset}>{en ? "Reset" : "Alaphelyzet"}</button>
|
|
116
|
+
</div>
|
|
117
|
+
) : null}
|
|
118
|
+
</div>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function useAccessibilityPreferences() {
|
|
123
|
+
const context = useContext(AccessibilityContext)
|
|
124
|
+
if (!context) throw new Error("useAccessibilityPreferences csak AccessibilityPreferencesProvider alatt használható.")
|
|
125
|
+
return context
|
|
126
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, type ReactNode } from "react"
|
|
4
|
+
|
|
5
|
+
const FOCUSABLE = [
|
|
6
|
+
"a[href]",
|
|
7
|
+
"button:not([disabled])",
|
|
8
|
+
"input:not([disabled])",
|
|
9
|
+
"select:not([disabled])",
|
|
10
|
+
"textarea:not([disabled])",
|
|
11
|
+
"[tabindex]:not([tabindex='-1'])",
|
|
12
|
+
].join(",")
|
|
13
|
+
|
|
14
|
+
export function AccessibleDialog({
|
|
15
|
+
open,
|
|
16
|
+
onClose,
|
|
17
|
+
labelledBy,
|
|
18
|
+
children,
|
|
19
|
+
className = "drawer",
|
|
20
|
+
}: {
|
|
21
|
+
open: boolean
|
|
22
|
+
onClose: () => void
|
|
23
|
+
labelledBy: string
|
|
24
|
+
children: ReactNode
|
|
25
|
+
className?: string
|
|
26
|
+
}) {
|
|
27
|
+
const ref = useRef<HTMLElement>(null)
|
|
28
|
+
const previousFocus = useRef<HTMLElement | null>(null)
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!open) return
|
|
32
|
+
previousFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null
|
|
33
|
+
const dialog = ref.current
|
|
34
|
+
const first = dialog?.querySelector<HTMLElement>(FOCUSABLE)
|
|
35
|
+
window.setTimeout(() => first?.focus(), 0)
|
|
36
|
+
|
|
37
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
38
|
+
if (event.key === "Escape") {
|
|
39
|
+
event.preventDefault()
|
|
40
|
+
onClose()
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
if (event.key !== "Tab" || !dialog) return
|
|
44
|
+
const focusable = Array.from(dialog.querySelectorAll<HTMLElement>(FOCUSABLE)).filter((element) => !element.hasAttribute("hidden"))
|
|
45
|
+
if (!focusable.length) {
|
|
46
|
+
event.preventDefault()
|
|
47
|
+
dialog.focus()
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
const firstElement = focusable[0]
|
|
51
|
+
const lastElement = focusable[focusable.length - 1]
|
|
52
|
+
if (event.shiftKey && document.activeElement === firstElement) {
|
|
53
|
+
event.preventDefault()
|
|
54
|
+
lastElement.focus()
|
|
55
|
+
} else if (!event.shiftKey && document.activeElement === lastElement) {
|
|
56
|
+
event.preventDefault()
|
|
57
|
+
firstElement.focus()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
document.addEventListener("keydown", onKeyDown)
|
|
62
|
+
const originalOverflow = document.body.style.overflow
|
|
63
|
+
document.body.style.overflow = "hidden"
|
|
64
|
+
return () => {
|
|
65
|
+
document.removeEventListener("keydown", onKeyDown)
|
|
66
|
+
document.body.style.overflow = originalOverflow
|
|
67
|
+
previousFocus.current?.focus()
|
|
68
|
+
}
|
|
69
|
+
}, [onClose, open])
|
|
70
|
+
|
|
71
|
+
if (!open) return null
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div className="drawer-backdrop" role="presentation" onMouseDown={onClose}>
|
|
75
|
+
<aside
|
|
76
|
+
ref={ref}
|
|
77
|
+
className={className}
|
|
78
|
+
role="dialog"
|
|
79
|
+
aria-modal="true"
|
|
80
|
+
aria-labelledby={labelledBy}
|
|
81
|
+
tabIndex={-1}
|
|
82
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</aside>
|
|
86
|
+
</div>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useEffect,
|
|
5
|
+
useId,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type KeyboardEvent as ReactKeyboardEvent,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from "react"
|
|
11
|
+
|
|
12
|
+
const ITEM_SELECTOR = "a[href], button:not([disabled]), [role='menuitem']:not([aria-disabled='true'])"
|
|
13
|
+
|
|
14
|
+
export function AccessibleDropdown({
|
|
15
|
+
label,
|
|
16
|
+
children,
|
|
17
|
+
}: {
|
|
18
|
+
label: ReactNode
|
|
19
|
+
children: ReactNode
|
|
20
|
+
}) {
|
|
21
|
+
const id = useId()
|
|
22
|
+
const rootRef = useRef<HTMLDivElement>(null)
|
|
23
|
+
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
24
|
+
const [open, setOpen] = useState(false)
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!open) return
|
|
28
|
+
const onPointerDown = (event: MouseEvent) => {
|
|
29
|
+
if (!rootRef.current?.contains(event.target as Node)) setOpen(false)
|
|
30
|
+
}
|
|
31
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
32
|
+
if (event.key === "Escape") {
|
|
33
|
+
event.preventDefault()
|
|
34
|
+
setOpen(false)
|
|
35
|
+
triggerRef.current?.focus()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
document.addEventListener("mousedown", onPointerDown)
|
|
39
|
+
document.addEventListener("keydown", onKeyDown)
|
|
40
|
+
return () => {
|
|
41
|
+
document.removeEventListener("mousedown", onPointerDown)
|
|
42
|
+
document.removeEventListener("keydown", onKeyDown)
|
|
43
|
+
}
|
|
44
|
+
}, [open])
|
|
45
|
+
|
|
46
|
+
const focusItem = (position: "first" | "last") => {
|
|
47
|
+
const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(ITEM_SELECTOR) || [])
|
|
48
|
+
const item = position === "first" ? items[0] : items[items.length - 1]
|
|
49
|
+
item?.focus()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const navigate = (event: ReactKeyboardEvent<HTMLDivElement>) => {
|
|
53
|
+
const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(ITEM_SELECTOR) || [])
|
|
54
|
+
if (!items.length) return
|
|
55
|
+
const index = items.indexOf(document.activeElement as HTMLElement)
|
|
56
|
+
if (event.key === "ArrowDown") {
|
|
57
|
+
event.preventDefault()
|
|
58
|
+
items[(index + 1 + items.length) % items.length]?.focus()
|
|
59
|
+
} else if (event.key === "ArrowUp") {
|
|
60
|
+
event.preventDefault()
|
|
61
|
+
items[(index - 1 + items.length) % items.length]?.focus()
|
|
62
|
+
} else if (event.key === "Home") {
|
|
63
|
+
event.preventDefault()
|
|
64
|
+
items[0]?.focus()
|
|
65
|
+
} else if (event.key === "End") {
|
|
66
|
+
event.preventDefault()
|
|
67
|
+
items[items.length - 1]?.focus()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className="accessible-dropdown" ref={rootRef} onKeyDown={navigate}>
|
|
73
|
+
<button
|
|
74
|
+
ref={triggerRef}
|
|
75
|
+
type="button"
|
|
76
|
+
className="accessible-dropdown-trigger"
|
|
77
|
+
aria-haspopup="menu"
|
|
78
|
+
aria-expanded={open}
|
|
79
|
+
aria-controls={id}
|
|
80
|
+
onClick={() => setOpen((current) => !current)}
|
|
81
|
+
onKeyDown={(event) => {
|
|
82
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
83
|
+
event.preventDefault()
|
|
84
|
+
setOpen(true)
|
|
85
|
+
requestAnimationFrame(() => focusItem(event.key === "ArrowDown" ? "first" : "last"))
|
|
86
|
+
}
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{label}
|
|
90
|
+
</button>
|
|
91
|
+
{open ? (
|
|
92
|
+
<div id={id} className="accessible-dropdown-menu" role="menu">
|
|
93
|
+
{children}
|
|
94
|
+
</div>
|
|
95
|
+
) : null}
|
|
96
|
+
</div>
|
|
97
|
+
)
|
|
98
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Link from "next/link"
|
|
4
|
+
import { usePathname } from "next/navigation"
|
|
5
|
+
import { useCallback, useEffect, useState } from "react"
|
|
6
|
+
import { CoreApiError } from "@/lib/core/client"
|
|
7
|
+
import {
|
|
8
|
+
listWishlist,
|
|
9
|
+
removeWishlistProduct,
|
|
10
|
+
type WishlistItem,
|
|
11
|
+
} from "@/lib/core/wishlist"
|
|
12
|
+
import { localeFromPathname, productPath, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
|
|
13
|
+
|
|
14
|
+
export function AccountWishlist() {
|
|
15
|
+
const pathname = usePathname()
|
|
16
|
+
const locale = localeFromPathname(pathname)
|
|
17
|
+
const english = locale === "en"
|
|
18
|
+
const [items, setItems] = useState<WishlistItem[]>([])
|
|
19
|
+
const [loading, setLoading] = useState(true)
|
|
20
|
+
const [error, setError] = useState<string | null>(null)
|
|
21
|
+
const [busy, setBusy] = useState<string | null>(null)
|
|
22
|
+
|
|
23
|
+
const load = useCallback(async () => {
|
|
24
|
+
setLoading(true)
|
|
25
|
+
setError(null)
|
|
26
|
+
try {
|
|
27
|
+
const result = await listWishlist()
|
|
28
|
+
setItems(result.items)
|
|
29
|
+
} catch (cause) {
|
|
30
|
+
if (cause instanceof CoreApiError && cause.status === 401) {
|
|
31
|
+
setError(english ? "Sign in to view your wishlist." : "A kedvencek megtekintéséhez jelentkezz be.")
|
|
32
|
+
} else {
|
|
33
|
+
setError(cause instanceof Error ? cause.message : (english ? "Wishlist could not be loaded." : "A kedvencek nem tölthetők be."))
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
setLoading(false)
|
|
37
|
+
}
|
|
38
|
+
}, [english])
|
|
39
|
+
|
|
40
|
+
useEffect(() => { void load() }, [load])
|
|
41
|
+
|
|
42
|
+
const remove = async (productId: string) => {
|
|
43
|
+
setBusy(productId)
|
|
44
|
+
try {
|
|
45
|
+
await removeWishlistProduct(productId)
|
|
46
|
+
setItems((current) => current.filter((item) => item.product_id !== productId))
|
|
47
|
+
} finally {
|
|
48
|
+
setBusy(null)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (loading) return <section className="panel"><p>{english ? "Loading wishlist…" : "Kedvencek betöltése…"}</p></section>
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<section className="panel stack">
|
|
56
|
+
<div>
|
|
57
|
+
<p className="eyebrow">{english ? "Customer account" : "Ügyfélfiók"}</p>
|
|
58
|
+
<h1>{english ? "Wishlist" : "Kedvencek"}</h1>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
{error ? (
|
|
62
|
+
<div className="empty-state stack-sm">
|
|
63
|
+
<p>{error}</p>
|
|
64
|
+
<Link className="button" href={STOREFRONT_ROUTES[locale].account}>{english ? "Go to account" : "Tovább a fiókhoz"}</Link>
|
|
65
|
+
</div>
|
|
66
|
+
) : null}
|
|
67
|
+
|
|
68
|
+
{!error && !items.length ? <div className="empty-state">{english ? "Your wishlist is empty." : "Még nincs mentett kedvenced."}</div> : null}
|
|
69
|
+
|
|
70
|
+
{!error && items.length ? (
|
|
71
|
+
<div className="product-grid">
|
|
72
|
+
{items.map((item) => {
|
|
73
|
+
const product = item.product
|
|
74
|
+
const handle = product?.handle || ""
|
|
75
|
+
return (
|
|
76
|
+
<article className="panel stack-sm" key={item.id}>
|
|
77
|
+
{product?.thumbnail ? <img src={product.thumbnail} alt={product.title || ""} className="product-card-image" /> : null}
|
|
78
|
+
<div>
|
|
79
|
+
<strong>{product?.title || item.product_id}</strong>
|
|
80
|
+
<p className="muted small">{english ? "Saved product" : "Mentett termék"}</p>
|
|
81
|
+
</div>
|
|
82
|
+
<div className="button-row">
|
|
83
|
+
{handle ? <Link className="button secondary" href={productPath(locale, handle)}>{english ? "View" : "Megnézem"}</Link> : null}
|
|
84
|
+
<button className="button secondary" type="button" disabled={busy === item.product_id} onClick={() => void remove(item.product_id)}>
|
|
85
|
+
{busy === item.product_id ? (english ? "Removing…" : "Törlés…") : (english ? "Remove" : "Törlés")}
|
|
86
|
+
</button>
|
|
87
|
+
</div>
|
|
88
|
+
</article>
|
|
89
|
+
)
|
|
90
|
+
})}
|
|
91
|
+
</div>
|
|
92
|
+
) : null}
|
|
93
|
+
</section>
|
|
94
|
+
)
|
|
95
|
+
}
|