@hszrdm/create-commerce 1.1.0 → 1.2.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.
Files changed (38) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +5 -2
  3. package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +41 -9
  4. package/templates/storefront/src/app/account/page.tsx +12 -1
  5. package/templates/storefront/src/app/account/wishlist/page.tsx +9 -0
  6. package/templates/storefront/src/app/core-ux.css +244 -0
  7. package/templates/storefront/src/app/layout.tsx +31 -12
  8. package/templates/storefront/src/app/newsletter/confirm/page.tsx +19 -0
  9. package/templates/storefront/src/app/newsletter/unsubscribe/page.tsx +19 -0
  10. package/templates/storefront/src/components/accessibility-preferences.tsx +126 -0
  11. package/templates/storefront/src/components/accessible-dialog.tsx +88 -0
  12. package/templates/storefront/src/components/accessible-dropdown.tsx +98 -0
  13. package/templates/storefront/src/components/account-wishlist.tsx +95 -0
  14. package/templates/storefront/src/components/add-to-cart.tsx +110 -15
  15. package/templates/storefront/src/components/back-to-top.tsx +26 -0
  16. package/templates/storefront/src/components/breadcrumbs.tsx +26 -0
  17. package/templates/storefront/src/components/cart-view.tsx +72 -16
  18. package/templates/storefront/src/components/form-ux.tsx +47 -0
  19. package/templates/storefront/src/components/free-shipping-progress.tsx +35 -0
  20. package/templates/storefront/src/components/newsletter-action.tsx +66 -0
  21. package/templates/storefront/src/components/product-gallery.tsx +64 -0
  22. package/templates/storefront/src/components/quantity-stepper.tsx +41 -0
  23. package/templates/storefront/src/components/share-button.tsx +63 -0
  24. package/templates/storefront/src/components/storefront-header.tsx +72 -18
  25. package/templates/storefront/src/components/tier-progress-hint.tsx +32 -0
  26. package/templates/storefront/src/components/toast-provider.tsx +92 -0
  27. package/templates/storefront/src/components/variant-price-display.tsx +31 -0
  28. package/templates/storefront/src/components/wishlist-button.tsx +88 -0
  29. package/templates/storefront/src/lib/core/account.ts +3 -0
  30. package/templates/storefront/src/lib/core/cms-contract.ts +35 -0
  31. package/templates/storefront/src/lib/core/cms.ts +66 -7
  32. package/templates/storefront/src/lib/core/form-ux.ts +57 -0
  33. package/templates/storefront/src/lib/core/newsletter.ts +53 -0
  34. package/templates/storefront/src/lib/core/reviews.ts +40 -0
  35. package/templates/storefront/src/lib/core/share.ts +57 -0
  36. package/templates/storefront/src/lib/core/wishlist.ts +88 -0
  37. package/templates/storefront/src/lib/storefront-routes.ts +3 -0
  38. package/templates/storefront/src/proxy.ts +3 -0
@@ -3,6 +3,8 @@
3
3
  import Link from "next/link"
4
4
  import { usePathname } from "next/navigation"
5
5
  import { useState } from "react"
6
+ import { QuantityStepper } from "./quantity-stepper"
7
+ import { useToast } from "./toast-provider"
6
8
  import { useCart } from "./cart-provider"
7
9
  import {
8
10
  cartCurrency,
@@ -17,6 +19,7 @@ import {
17
19
  numberValue,
18
20
  stringValue,
19
21
  } from "@/lib/core/commerce"
22
+ import { humanizeStorefrontError } from "@/lib/core/form-ux"
20
23
  import type { CoreConfig } from "@/lib/core/types"
21
24
  import { storefrontCopy } from "@/lib/storefront-copy"
22
25
  import { localeFromPathname, STOREFRONT_ROUTES } from "@/lib/storefront-routes"
@@ -27,6 +30,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
27
30
  loading,
28
31
  mutating,
29
32
  error,
33
+ addItem,
30
34
  updateItem,
31
35
  removeItem,
32
36
  addPromotion,
@@ -39,8 +43,9 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
39
43
  const copy = storefrontCopy(locale)
40
44
  const formatLocale = locale === "en" ? "en-US" : "hu-HU"
41
45
  const [promo, setPromo] = useState("")
46
+ const { showToast } = useToast()
42
47
 
43
- if (loading) return <div className="empty-state">{copy.cartLoading}</div>
48
+ if (loading) return <div className="empty-state" role="status">{copy.cartLoading}</div>
44
49
  const items = cartItems(cart)
45
50
  if (!cart || !items.length) {
46
51
  return (
@@ -59,29 +64,57 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
59
64
  ? cart.promotions.filter((item): item is Record<string, unknown> => Boolean(item && typeof item === "object"))
60
65
  : []
61
66
 
67
+ const reportError = (cause: unknown) => {
68
+ const message = humanizeStorefrontError(cause, locale)
69
+ showToast({ message, tone: "error" })
70
+ }
71
+
62
72
  return (
63
73
  <div className="stack">
64
- <div className="cart-lines">
74
+ <div className="cart-lines" aria-live="polite">
65
75
  {items.map((item) => {
66
76
  const id = stringValue(item.id)
67
77
  const quantity = Math.max(1, numberValue(item.quantity, 1))
68
78
  const thumbnail = stringValue(item.thumbnail)
79
+ const title = stringValue(item.product_title || item.title)
80
+ const variantId = stringValue(item.variant_id)
69
81
  return (
70
82
  <div className="cart-line" key={id}>
71
83
  <div className="cart-line-image">
72
- {thumbnail ? <img src={thumbnail} alt="" /> : <span />}
84
+ {thumbnail ? <img src={thumbnail} alt={title} loading="lazy" /> : <span className="media-placeholder" aria-hidden="true" />}
73
85
  </div>
74
86
  <div className="cart-line-copy">
75
- <strong>{stringValue(item.product_title || item.title)}</strong>
87
+ <strong>{title}</strong>
76
88
  {item.variant_title ? <span className="muted">{stringValue(item.variant_title)}</span> : null}
77
89
  <span>{formatMoney(lineTotal(item), currency, formatLocale)}</span>
78
90
  </div>
79
- <div className="quantity-control">
80
- <button type="button" disabled={mutating} onClick={() => void updateItem(id, quantity - 1)} aria-label={copy.decreaseQuantity}>−</button>
81
- <span>{quantity}</span>
82
- <button type="button" disabled={mutating} onClick={() => void updateItem(id, quantity + 1)} aria-label={copy.increaseQuantity}>+</button>
83
- </div>
84
- <button className="text-button danger" type="button" disabled={mutating} onClick={() => void removeItem(id)}>
91
+ <QuantityStepper
92
+ value={quantity}
93
+ min={1}
94
+ max={999}
95
+ disabled={mutating}
96
+ label={locale === "en" ? `Quantity for ${title}` : `${title} mennyisége`}
97
+ decreaseLabel={locale === "en" ? `Decrease quantity for ${title}` : `${title} mennyiségének csökkentése`}
98
+ increaseLabel={locale === "en" ? `Increase quantity for ${title}` : `${title} mennyiségének növelése`}
99
+ onChange={(next) => void updateItem(id, next).catch(reportError)}
100
+ />
101
+ <button
102
+ className="text-button danger"
103
+ type="button"
104
+ disabled={mutating}
105
+ onClick={() => {
106
+ void removeItem(id)
107
+ .then(() => {
108
+ showToast({
109
+ message: locale === "en" ? "Item removed from cart." : "A terméket eltávolítottuk a kosárból.",
110
+ tone: "info",
111
+ actionLabel: variantId ? (locale === "en" ? "Undo" : "Visszavonás") : undefined,
112
+ onAction: variantId ? () => addItem(variantId, quantity) : undefined,
113
+ })
114
+ })
115
+ .catch(reportError)
116
+ }}
117
+ >
85
118
  {copy.remove}
86
119
  </button>
87
120
  </div>
@@ -93,17 +126,40 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
93
126
  <div className="panel stack-sm">
94
127
  <strong>{copy.couponCode}</strong>
95
128
  <div className="inline-form">
96
- <input value={promo} onChange={(event) => setPromo(event.target.value)} placeholder={copy.couponCode} />
97
- <button className="button secondary" type="button" disabled={mutating || !promo.trim()} onClick={() => void addPromotion(promo).then(() => setPromo(""))}>
129
+ <input
130
+ value={promo}
131
+ onChange={(event) => setPromo(event.target.value)}
132
+ placeholder={copy.couponCode}
133
+ aria-label={copy.couponCode}
134
+ autoComplete="off"
135
+ />
136
+ <button
137
+ className="button secondary"
138
+ type="button"
139
+ disabled={mutating || !promo.trim()}
140
+ aria-busy={mutating}
141
+ onClick={() => void addPromotion(promo)
142
+ .then(() => {
143
+ setPromo("")
144
+ showToast({ message: locale === "en" ? "Coupon applied." : "Kuponkód alkalmazva.", tone: "success" })
145
+ })
146
+ .catch(reportError)}
147
+ >
98
148
  {copy.redeem}
99
149
  </button>
100
150
  </div>
101
151
  {promotions.length ? (
102
- <div className="chip-row">
152
+ <div className="chip-row" aria-label={locale === "en" ? "Applied promotions" : "Alkalmazott kedvezmények"}>
103
153
  {promotions.map((promotion) => {
104
154
  const code = stringValue(promotion.code)
105
155
  return (
106
- <button className="chip" key={stringValue(promotion.id || code)} type="button" onClick={() => void removePromotion(code)}>
156
+ <button
157
+ className="chip"
158
+ key={stringValue(promotion.id || code)}
159
+ type="button"
160
+ aria-label={locale === "en" ? `Remove promotion ${code}` : `${code} kedvezmény eltávolítása`}
161
+ onClick={() => void removePromotion(code).catch(reportError)}
162
+ >
107
163
  {code || copy.discount} ×
108
164
  </button>
109
165
  )
@@ -113,7 +169,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
113
169
  </div>
114
170
  ) : null}
115
171
 
116
- <div className="totals">
172
+ <div className="totals" aria-live="polite">
117
173
  <TotalRow label={copy.subtotal} value={cartSubtotal(cart)} currency={currency} locale={formatLocale} />
118
174
  {cartDiscountTotal(cart) ? <TotalRow label={copy.discount} value={-cartDiscountTotal(cart)} currency={currency} locale={formatLocale} /> : null}
119
175
  <TotalRow label={copy.shipping} value={cartShippingTotal(cart)} currency={currency} locale={formatLocale} />
@@ -121,7 +177,7 @@ export function CartView({ config, compact = false }: { config: CoreConfig; comp
121
177
  <TotalRow label={copy.total} value={cartTotal(cart)} currency={currency} locale={formatLocale} strong />
122
178
  </div>
123
179
 
124
- {error ? <p className="error">{error}</p> : null}
180
+ {error ? <p className="error" role="alert">{humanizeStorefrontError(new Error(error), locale)}</p> : null}
125
181
 
126
182
  <div className="button-row">
127
183
  {compact ? (
@@ -0,0 +1,47 @@
1
+ "use client"
2
+
3
+ import { useCallback, useState, type FormEvent } from "react"
4
+ import { fieldErrorId, focusFirstInvalidField, humanizeStorefrontError } from "@/lib/core/form-ux"
5
+
6
+ export function FieldError({ name, error }: { name: string; error?: string | null }) {
7
+ if (!error) return null
8
+ return <p id={fieldErrorId(name)} className="field-error" role="alert">{error}</p>
9
+ }
10
+
11
+ export function RequiredMark({ label = "kötelező" }: { label?: string }) {
12
+ return <span className="required-mark" aria-label={label}>*</span>
13
+ }
14
+
15
+ export function useAccessibleSubmit(options: {
16
+ locale?: "hu" | "en"
17
+ onSubmit: () => Promise<void>
18
+ onSuccess?: () => void
19
+ }) {
20
+ const [submitting, setSubmitting] = useState(false)
21
+ const [submitError, setSubmitError] = useState<string | null>(null)
22
+
23
+ const submit = useCallback(async (event?: FormEvent<HTMLFormElement>) => {
24
+ event?.preventDefault()
25
+ if (submitting) return
26
+ const form = event?.currentTarget
27
+ if (form && !form.checkValidity()) {
28
+ form.reportValidity()
29
+ focusFirstInvalidField(form)
30
+ return
31
+ }
32
+
33
+ setSubmitting(true)
34
+ setSubmitError(null)
35
+ try {
36
+ await options.onSubmit()
37
+ options.onSuccess?.()
38
+ } catch (error) {
39
+ setSubmitError(humanizeStorefrontError(error, options.locale || "hu"))
40
+ requestAnimationFrame(() => focusFirstInvalidField(form || document))
41
+ } finally {
42
+ setSubmitting(false)
43
+ }
44
+ }, [options, submitting])
45
+
46
+ return { submit, submitting, submitError, setSubmitError }
47
+ }
@@ -0,0 +1,35 @@
1
+ import { formatMoney } from "@/lib/core/commerce"
2
+
3
+ export function FreeShippingProgress({
4
+ subtotal,
5
+ threshold,
6
+ currency,
7
+ locale = "hu-HU",
8
+ }: {
9
+ subtotal: number
10
+ threshold: number
11
+ currency: string
12
+ locale?: string
13
+ }) {
14
+ if (!Number.isFinite(threshold) || threshold <= 0) return null
15
+ const remaining = Math.max(0, threshold - subtotal)
16
+ const progress = Math.max(0, Math.min(100, (subtotal / threshold) * 100))
17
+ const reached = remaining <= 0
18
+ const en = locale.toLowerCase().startsWith("en")
19
+
20
+ return (
21
+ <div className="shipping-progress stack-sm" role="status" aria-live="polite">
22
+ <div className="shipping-progress-copy">
23
+ <strong>
24
+ {reached
25
+ ? (en ? "You've reached the free shipping threshold." : "Elérted az ingyenes szállítási küszöböt.")
26
+ : (en
27
+ ? `${formatMoney(remaining, currency, locale)} more for free shipping.`
28
+ : `Még ${formatMoney(remaining, currency, locale)} az ingyenes szállításig.`)}
29
+ </strong>
30
+ <span>{formatMoney(subtotal, currency, locale)} / {formatMoney(threshold, currency, locale)}</span>
31
+ </div>
32
+ <div className="progress-track" aria-hidden="true"><span style={{ width: `${progress}%` }} /></div>
33
+ </div>
34
+ )
35
+ }
@@ -0,0 +1,66 @@
1
+ "use client"
2
+
3
+ import { useEffect, useState } from "react"
4
+ import { confirmNewsletter, unsubscribeNewsletter } from "@/lib/core/newsletter"
5
+
6
+ type Props = {
7
+ action: "confirm" | "unsubscribe"
8
+ token: string
9
+ locale: "hu" | "en"
10
+ }
11
+
12
+ export function NewsletterAction({ action, token, locale }: Props) {
13
+ const english = locale === "en"
14
+ const [status, setStatus] = useState<"idle" | "loading" | "success" | "error">("idle")
15
+ const [message, setMessage] = useState("")
16
+
17
+ const run = async () => {
18
+ if (!token || status === "loading" || status === "success") return
19
+ setStatus("loading")
20
+ setMessage("")
21
+ try {
22
+ const response = action === "confirm"
23
+ ? await confirmNewsletter(token)
24
+ : await unsubscribeNewsletter(token)
25
+ setStatus("success")
26
+ setMessage(response.message)
27
+ } catch (cause) {
28
+ setStatus("error")
29
+ setMessage(cause instanceof Error ? cause.message : (english ? "The operation failed." : "A művelet nem sikerült."))
30
+ }
31
+ }
32
+
33
+ useEffect(() => {
34
+ if (action === "confirm" && token) void run()
35
+ // The confirmation link intentionally performs the POST only in the browser.
36
+ // Server-side page fetching must never mutate newsletter state.
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
38
+ }, [action, token])
39
+
40
+ if (!token) {
41
+ return <div className="empty-state">{english ? "The link is invalid." : "A link érvénytelen."}</div>
42
+ }
43
+
44
+ if (status === "success") {
45
+ return <div className="empty-state">{message}</div>
46
+ }
47
+
48
+ if (status === "error") {
49
+ return <div className="empty-state"><p>{message}</p></div>
50
+ }
51
+
52
+ if (action === "confirm") {
53
+ return <div className="empty-state">{english ? "Confirming your subscription…" : "Feliratkozás megerősítése…"}</div>
54
+ }
55
+
56
+ return (
57
+ <div className="empty-state">
58
+ <p>{english ? "Do you want to unsubscribe from the newsletter?" : "Biztosan le szeretnél iratkozni a hírlevélről?"}</p>
59
+ <button type="button" className="button button-large" onClick={() => void run()} disabled={status === "loading"}>
60
+ {status === "loading"
61
+ ? (english ? "Unsubscribing…" : "Leiratkozás…")
62
+ : (english ? "Unsubscribe" : "Leiratkozom")}
63
+ </button>
64
+ </div>
65
+ )
66
+ }
@@ -0,0 +1,64 @@
1
+ "use client"
2
+
3
+ import { useEffect, useMemo, useState } from "react"
4
+
5
+ export type ProductGalleryImage = {
6
+ id?: string
7
+ url: string
8
+ alt?: string
9
+ }
10
+
11
+ export function ProductGallery({
12
+ title,
13
+ images,
14
+ emptyLabel = "Nincs kép",
15
+ galleryLabel = "Termékképek",
16
+ }: {
17
+ title: string
18
+ images: ProductGalleryImage[]
19
+ emptyLabel?: string
20
+ galleryLabel?: string
21
+ }) {
22
+ const normalized = useMemo(() => images.filter((image) => image.url), [images])
23
+ const [activeUrl, setActiveUrl] = useState(normalized[0]?.url || "")
24
+
25
+ useEffect(() => {
26
+ const listener = (event: Event) => {
27
+ const custom = event as CustomEvent<{ imageUrl?: string }>
28
+ const imageUrl = String(custom.detail?.imageUrl || "").trim()
29
+ if (imageUrl) setActiveUrl(imageUrl)
30
+ }
31
+ window.addEventListener("hszrdm:product-variant-change", listener)
32
+ return () => window.removeEventListener("hszrdm:product-variant-change", listener)
33
+ }, [])
34
+
35
+ const allImages = activeUrl && !normalized.some((image) => image.url === activeUrl)
36
+ ? [{ url: activeUrl, alt: title }, ...normalized]
37
+ : normalized
38
+
39
+ return (
40
+ <div className="product-gallery">
41
+ <div className="product-main-image">
42
+ {activeUrl
43
+ ? <img src={activeUrl} alt={title} />
44
+ : <span className="media-placeholder">{emptyLabel}</span>}
45
+ </div>
46
+ {allImages.length > 1 ? (
47
+ <div className="thumbnail-row" aria-label={galleryLabel}>
48
+ {allImages.slice(0, 8).map((image, index) => (
49
+ <button
50
+ type="button"
51
+ className={`thumbnail-button${image.url === activeUrl ? " is-active" : ""}`}
52
+ key={`${image.id || image.url}:${index}`}
53
+ aria-label={`${title} – ${index + 1}`}
54
+ aria-pressed={image.url === activeUrl}
55
+ onClick={() => setActiveUrl(image.url)}
56
+ >
57
+ <img src={image.url} alt="" loading="lazy" />
58
+ </button>
59
+ ))}
60
+ </div>
61
+ ) : null}
62
+ </div>
63
+ )
64
+ }
@@ -0,0 +1,41 @@
1
+ "use client"
2
+
3
+ export function QuantityStepper({
4
+ value,
5
+ onChange,
6
+ min = 1,
7
+ max = 999,
8
+ disabled = false,
9
+ label = "Mennyiség",
10
+ decreaseLabel,
11
+ increaseLabel,
12
+ }: {
13
+ value: number
14
+ onChange: (value: number) => void
15
+ min?: number
16
+ max?: number
17
+ disabled?: boolean
18
+ label?: string
19
+ decreaseLabel?: string
20
+ increaseLabel?: string
21
+ }) {
22
+ const clamped = Math.max(min, Math.min(max, Math.trunc(value || min)))
23
+ const set = (next: number) => onChange(Math.max(min, Math.min(max, Math.trunc(next || min))))
24
+
25
+ return (
26
+ <div className="quantity-stepper" role="group" aria-label={label}>
27
+ <button type="button" disabled={disabled || clamped <= min} aria-label={decreaseLabel || `${label}: csökkentés`} onClick={() => set(clamped - 1)}>−</button>
28
+ <input
29
+ type="number"
30
+ inputMode="numeric"
31
+ min={min}
32
+ max={max}
33
+ value={clamped}
34
+ disabled={disabled}
35
+ aria-label={label}
36
+ onChange={(event) => set(Number(event.target.value))}
37
+ />
38
+ <button type="button" disabled={disabled || clamped >= max} aria-label={increaseLabel || `${label}: növelés`} onClick={() => set(clamped + 1)}>+</button>
39
+ </div>
40
+ )
41
+ }
@@ -0,0 +1,63 @@
1
+ "use client"
2
+
3
+ import { usePathname } from "next/navigation"
4
+ import { useMemo, useState } from "react"
5
+ import { copyText, shareContent, shareFallbackLinks } from "@/lib/core/share"
6
+ import { localeFromPathname } from "@/lib/storefront-routes"
7
+ import { useToast } from "./toast-provider"
8
+
9
+ export function ShareButton({
10
+ title,
11
+ text,
12
+ url,
13
+ showFallbackLinks = false,
14
+ }: {
15
+ title?: string
16
+ text?: string
17
+ url?: string
18
+ showFallbackLinks?: boolean
19
+ }) {
20
+ const pathname = usePathname()
21
+ const locale = localeFromPathname(pathname)
22
+ const en = locale === "en"
23
+ const { showToast } = useToast()
24
+ const [expanded, setExpanded] = useState(false)
25
+ const resolvedUrl = useMemo(() => {
26
+ if (url) return url
27
+ if (typeof window === "undefined") return pathname
28
+ return window.location.href
29
+ }, [pathname, url])
30
+ const links = shareFallbackLinks({ title, text, url: resolvedUrl })
31
+
32
+ const share = async () => {
33
+ try {
34
+ const result = await shareContent({ title, text, url: resolvedUrl })
35
+ if (result === "copied") showToast({ message: en ? "Link copied" : "Link másolva", tone: "success" })
36
+ } catch {
37
+ setExpanded(true)
38
+ showToast({ message: en ? "Sharing is not available. You can copy the link instead." : "A megosztás nem érhető el. A linket külön kimásolhatod.", tone: "error" })
39
+ }
40
+ }
41
+
42
+ return (
43
+ <div className="share-control">
44
+ <button type="button" className="button secondary" onClick={() => void share()}>
45
+ {en ? "Share" : "Megosztás"}
46
+ </button>
47
+ <button
48
+ type="button"
49
+ className="text-button"
50
+ onClick={() => void copyText(resolvedUrl).then(() => showToast({ message: en ? "Link copied" : "Link másolva", tone: "success" }))}
51
+ >
52
+ {en ? "Copy link" : "Link másolása"}
53
+ </button>
54
+ {showFallbackLinks || expanded ? (
55
+ <div className="share-links" aria-label={en ? "Share options" : "Megosztási lehetőségek"}>
56
+ <a href={links.facebook} target="_blank" rel="noreferrer">Facebook</a>
57
+ <a href={links.linkedin} target="_blank" rel="noreferrer">LinkedIn</a>
58
+ <a href={links.email}>{en ? "Email" : "E-mail"}</a>
59
+ </div>
60
+ ) : null}
61
+ </div>
62
+ )
63
+ }
@@ -2,6 +2,8 @@
2
2
 
3
3
  import Link from "next/link"
4
4
  import { usePathname } from "next/navigation"
5
+ import { useCallback, useEffect, useState } from "react"
6
+ import { AccessibleDialog } from "./accessible-dialog"
5
7
  import { useCart } from "./cart-provider"
6
8
  import { CartView } from "./cart-view"
7
9
  import type { CoreConfig } from "@/lib/core/types"
@@ -14,43 +16,95 @@ import {
14
16
 
15
17
  export function StorefrontHeader({ config }: { config: CoreConfig }) {
16
18
  const { count, drawerOpen, setDrawerOpen } = useCart()
19
+ const [menuOpen, setMenuOpen] = useState(false)
17
20
  const pathname = usePathname()
18
21
  const locale = localeFromPathname(pathname)
19
22
  const routes = STOREFRONT_ROUTES[locale]
20
23
  const copy = storefrontCopy(locale)
24
+ const closeDrawer = useCallback(() => setDrawerOpen(false), [setDrawerOpen])
25
+ const closeMenu = useCallback(() => setMenuOpen(false), [])
26
+
27
+ useEffect(() => {
28
+ closeDrawer()
29
+ closeMenu()
30
+ }, [closeDrawer, closeMenu, pathname])
31
+
32
+ const primaryLinks = [
33
+ { href: routes.products, label: copy.products },
34
+ { href: routes.legal, label: copy.legalDocuments },
35
+ ...(config.features.account ? [{ href: routes.account, label: copy.account }] : []),
36
+ ]
21
37
 
22
38
  return (
23
39
  <>
24
40
  <header className="shell header">
25
- <Link className="brand" href={routes.home}>{config.store.name}</Link>
41
+ <Link className="brand" href={routes.home} aria-current={pathname === routes.home ? "page" : undefined}>{config.store.name}</Link>
26
42
  <nav className="nav" aria-label={locale === "en" ? "Main navigation" : "Fő navigáció"}>
27
- <Link href={routes.products}>{copy.products}</Link>
28
- <Link href={routes.legal}>{copy.legalDocuments}</Link>
29
- {config.features.account ? <Link href={routes.account}>{copy.account}</Link> : null}
43
+ {primaryLinks.map((item) => (
44
+ <Link key={item.href} href={item.href} aria-current={isActive(pathname, item.href) ? "page" : undefined}>{item.label}</Link>
45
+ ))}
30
46
  <span className="locale-switch" aria-label={locale === "en" ? "Language" : "Nyelv"}>
31
47
  <Link aria-current={locale === "hu" ? "page" : undefined} href={equivalentLocalePath(pathname, "hu")}>HU</Link>
32
48
  <Link aria-current={locale === "en" ? "page" : undefined} href={equivalentLocalePath(pathname, "en")}>EN</Link>
33
49
  </span>
34
- <button className="nav-cart" type="button" onClick={() => setDrawerOpen(true)}>
35
- {copy.cart} <span className="cart-count">{count}</span>
50
+ <button
51
+ className="mobile-menu-trigger icon-button"
52
+ type="button"
53
+ aria-label={locale === "en" ? "Open menu" : "Menü megnyitása"}
54
+ aria-haspopup="dialog"
55
+ aria-expanded={menuOpen}
56
+ aria-controls="mobile-navigation"
57
+ onClick={() => setMenuOpen(true)}
58
+ >
59
+ ☰
60
+ </button>
61
+ <button
62
+ className="nav-cart"
63
+ type="button"
64
+ aria-haspopup="dialog"
65
+ aria-expanded={drawerOpen}
66
+ aria-controls="cart-drawer"
67
+ onClick={() => setDrawerOpen(true)}
68
+ >
69
+ {copy.cart} <span className="cart-count" aria-label={`${count} ${copy.productCountSuffix}`}>{count}</span>
36
70
  </button>
37
71
  </nav>
38
72
  </header>
39
73
 
40
- {drawerOpen ? (
41
- <div className="drawer-backdrop" onMouseDown={() => setDrawerOpen(false)}>
42
- <aside className="drawer" onMouseDown={(event) => event.stopPropagation()} aria-label={copy.cart}>
43
- <div className="drawer-head">
44
- <div>
45
- <p className="eyebrow">{copy.cart}</p>
46
- <h2>{count} {copy.productCountSuffix}</h2>
47
- </div>
48
- <button className="icon-button" type="button" aria-label={copy.close} onClick={() => setDrawerOpen(false)}>×</button>
74
+ <AccessibleDialog open={menuOpen} onClose={closeMenu} labelledBy="mobile-menu-title" className="mobile-menu-drawer">
75
+ <div id="mobile-navigation" className="stack">
76
+ <div className="drawer-head">
77
+ <h2 id="mobile-menu-title">{locale === "en" ? "Menu" : "Menü"}</h2>
78
+ <button className="icon-button" type="button" aria-label={copy.close} onClick={closeMenu}>×</button>
79
+ </div>
80
+ <nav className="mobile-nav-links" aria-label={locale === "en" ? "Mobile navigation" : "Mobil navigáció"}>
81
+ {primaryLinks.map((item) => (
82
+ <Link key={item.href} href={item.href} aria-current={isActive(pathname, item.href) ? "page" : undefined}>{item.label}</Link>
83
+ ))}
84
+ </nav>
85
+ <div className="mobile-locale-switch" aria-label={locale === "en" ? "Language" : "Nyelv"}>
86
+ <Link aria-current={locale === "hu" ? "page" : undefined} href={equivalentLocalePath(pathname, "hu")}>Magyar</Link>
87
+ <Link aria-current={locale === "en" ? "page" : undefined} href={equivalentLocalePath(pathname, "en")}>English</Link>
88
+ </div>
89
+ </div>
90
+ </AccessibleDialog>
91
+
92
+ <AccessibleDialog open={drawerOpen} onClose={closeDrawer} labelledBy="cart-drawer-title">
93
+ <div id="cart-drawer">
94
+ <div className="drawer-head">
95
+ <div>
96
+ <p className="eyebrow">{copy.cart}</p>
97
+ <h2 id="cart-drawer-title">{count} {copy.productCountSuffix}</h2>
49
98
  </div>
50
- <CartView config={config} compact />
51
- </aside>
99
+ <button className="icon-button" type="button" aria-label={copy.close} onClick={closeDrawer}>×</button>
100
+ </div>
101
+ <CartView config={config} compact />
52
102
  </div>
53
- ) : null}
103
+ </AccessibleDialog>
54
104
  </>
55
105
  )
56
106
  }
107
+
108
+ function isActive(pathname: string, href: string) {
109
+ return pathname === href || pathname.startsWith(`${href}/`)
110
+ }
@@ -0,0 +1,32 @@
1
+ export type QuantityPriceTier = {
2
+ minQuantity: number
3
+ unitPrice?: number
4
+ }
5
+
6
+ export function unitsUntilNextPriceTier(quantity: number, tiers: QuantityPriceTier[]) {
7
+ const sorted = [...tiers]
8
+ .filter((tier) => Number.isFinite(tier.minQuantity) && tier.minQuantity > 0)
9
+ .sort((a, b) => a.minQuantity - b.minQuantity)
10
+ const next = sorted.find((tier) => tier.minQuantity > quantity)
11
+ return next ? { remaining: next.minQuantity - quantity, tier: next } : null
12
+ }
13
+
14
+ export function TierProgressHint({
15
+ quantity,
16
+ tiers,
17
+ locale = "hu",
18
+ }: {
19
+ quantity: number
20
+ tiers: QuantityPriceTier[]
21
+ locale?: "hu" | "en"
22
+ }) {
23
+ const next = unitsUntilNextPriceTier(quantity, tiers)
24
+ if (!next) return null
25
+ return (
26
+ <p className="tier-progress-hint" role="status" aria-live="polite">
27
+ {locale === "en"
28
+ ? `${next.remaining} more to reach the next price tier.`
29
+ : `Még ${next.remaining} db a következő árszintig.`}
30
+ </p>
31
+ )
32
+ }