create-brainerce-store 1.72.0 → 1.74.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 (88) hide show
  1. package/dist/index.js +37 -4
  2. package/messages/en.json +30 -1
  3. package/messages/he.json +30 -1
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/AGENTS.md.ejs +63 -16
  6. package/templates/nextjs/base/AI-GUIDE.md +17 -4
  7. package/templates/nextjs/base/CLAUDE.md.ejs +67 -20
  8. package/templates/nextjs/base/TRANSLATIONS.md +207 -207
  9. package/templates/nextjs/base/src/app/account/page.tsx +168 -122
  10. package/templates/nextjs/base/src/app/category/[slug]/page.tsx +10 -1
  11. package/templates/nextjs/base/src/app/checkout/page.tsx +1179 -1074
  12. package/templates/nextjs/base/src/app/layout.tsx.ejs +48 -4
  13. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +98 -3
  14. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +14 -2
  15. package/templates/nextjs/base/src/components/account/loyalty-panel.tsx +226 -0
  16. package/templates/nextjs/base/src/components/account/order-history.tsx +422 -371
  17. package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +85 -85
  18. package/templates/nextjs/base/src/components/account/saved-payment-methods.tsx +104 -0
  19. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +618 -612
  20. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +354 -306
  21. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +141 -74
  22. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +218 -127
  23. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +63 -51
  24. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +379 -295
  25. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +33 -1
  26. package/templates/nextjs/base/src/core/lib/capabilities.ts +65 -0
  27. package/templates/nextjs/base/src/core/lib/display-price.ts +139 -0
  28. package/templates/nextjs/base/src/core/lib/region.server.ts +112 -0
  29. package/templates/nextjs/base/src/core/lib/region.ts +112 -0
  30. package/templates/nextjs/base/src/core/lib/store-info.ts +19 -0
  31. package/templates/nextjs/base/src/core/providers/store-provider.tsx.ejs +423 -243
  32. package/templates/nextjs/base/src/ui/cart/cart-item.tsx +174 -164
  33. package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +109 -110
  34. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +219 -176
  35. package/templates/nextjs/base/src/ui/cart/gift-card-input.tsx +191 -0
  36. package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +137 -137
  37. package/templates/nextjs/base/src/ui/cart/tax-estimate-line.tsx +108 -0
  38. package/templates/nextjs/base/src/ui/home/home-client.tsx +27 -29
  39. package/templates/nextjs/base/src/ui/layout/header-search.tsx +249 -0
  40. package/templates/nextjs/base/src/ui/layout/region-switcher.tsx +59 -0
  41. package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +171 -152
  42. package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +197 -191
  43. package/templates/nextjs/base/src/ui/product/product-card.tsx +25 -52
  44. package/templates/nextjs/base/src/ui/product/product-client-section.tsx +12 -3
  45. package/templates/nextjs/base/src/ui/product/product-listing.tsx +460 -446
  46. package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +108 -102
  47. package/templates/nextjs/base/src/ui/product/review-form.tsx +33 -11
  48. package/templates/nextjs/base/src/ui/product/stock-badge.tsx +15 -3
  49. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +48 -4
  50. package/templates/nextjs/designs/atelier/messages-patch/en.json +21 -25
  51. package/templates/nextjs/designs/atelier/messages-patch/he.json +21 -25
  52. package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +177 -181
  53. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +168 -158
  54. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +106 -107
  55. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +229 -184
  56. package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +131 -131
  57. package/templates/nextjs/designs/atelier/ui/cart/tax-estimate-line.tsx +108 -0
  58. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +10 -1
  59. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +178 -174
  60. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +4 -6
  61. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +150 -78
  62. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +79 -46
  63. package/templates/nextjs/designs/atelier/ui/layout/header-search.tsx +264 -0
  64. package/templates/nextjs/designs/atelier/ui/layout/region-switcher.tsx +44 -0
  65. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +5 -0
  66. package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +202 -196
  67. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +27 -52
  68. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +12 -3
  69. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +332 -260
  70. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +101 -95
  71. package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +30 -10
  72. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +17 -2
  73. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +9 -0
  74. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +137 -137
  75. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +98 -99
  76. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +140 -140
  77. package/templates/nextjs/ui-canvas/cart/gift-card-input.tsx +142 -0
  78. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +124 -124
  79. package/templates/nextjs/ui-canvas/cart/tax-estimate-line.tsx +104 -0
  80. package/templates/nextjs/ui-canvas/home/home-client.tsx +24 -26
  81. package/templates/nextjs/ui-canvas/layout/region-switcher.tsx +51 -0
  82. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +3 -0
  83. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +174 -168
  84. package/templates/nextjs/ui-canvas/product/product-card.tsx +9 -51
  85. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +5 -3
  86. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +105 -99
  87. package/templates/nextjs/ui-canvas/product/review-form.tsx +9 -1
  88. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +17 -2
@@ -1,181 +1,177 @@
1
- 'use client';
2
-
3
- /**
4
- * Mini-cart drawer — a slide-over sheet anchored to the header cart side
5
- * (logical `end`, so it hugs the cart icon in both RTL and LTR).
6
- *
7
- * Opens via `openCartDrawer()` (fired after a successful add-to-cart);
8
- * the header cart icon itself still navigates to /cart — the drawer never
9
- * hijacks that. Closes on overlay click, Escape, the X, or any CTA.
10
- *
11
- * Stays mounted so the slide transition runs both ways; when closed it is
12
- * `inert` + aria-hidden so nothing inside is focusable.
13
- */
14
- import { useEffect, useRef, useState } from 'react';
15
- import { Link } from '@/core/lib/navigation';
16
- import { formatPrice } from 'brainerce';
17
- import { useCart } from '@/core/providers/store-provider';
18
- import { useTranslations } from '@/core/lib/translations';
19
- import { useCurrency } from '@/core/lib/use-currency';
20
- import { CartItem } from '@/ui/cart/cart-item';
21
- import { FreeShippingBar } from '@/ui/cart/free-shipping-bar';
22
- import { cn } from '@/core/lib/utils';
23
- import { IconBag, IconX } from '@/ui/shared/icons';
24
-
25
- const OPEN_EVENT = 'cart-drawer:open';
26
-
27
- /** Ask the mounted drawer to slide open (no-op during SSR). */
28
- export function openCartDrawer() {
29
- if (typeof window !== 'undefined') {
30
- window.dispatchEvent(new Event(OPEN_EVENT));
31
- }
32
- }
33
-
34
- export function CartDrawer() {
35
- const [open, setOpen] = useState(false);
36
- const { cart, itemCount, totals, refreshCart } = useCart();
37
- const t = useTranslations('cart');
38
- const tc = useTranslations('common');
39
- const currency = useCurrency();
40
- const closeRef = useRef<HTMLButtonElement>(null);
41
-
42
- useEffect(() => {
43
- const onOpen = () => setOpen(true);
44
- window.addEventListener(OPEN_EVENT, onOpen);
45
- return () => window.removeEventListener(OPEN_EVENT, onOpen);
46
- }, []);
47
-
48
- // Open state side-effects: Escape to close, scroll lock, focus the X.
49
- useEffect(() => {
50
- if (!open) return;
51
- const onKey = (e: KeyboardEvent) => {
52
- if (e.key === 'Escape') setOpen(false);
53
- };
54
- document.addEventListener('keydown', onKey);
55
- const prevOverflow = document.body.style.overflow;
56
- document.body.style.overflow = 'hidden';
57
- closeRef.current?.focus();
58
- return () => {
59
- document.removeEventListener('keydown', onKey);
60
- document.body.style.overflow = prevOverflow;
61
- };
62
- }, [open]);
63
-
64
- const close = () => setOpen(false);
65
- const items = cart?.items ?? [];
66
-
67
- return (
68
- <div
69
- aria-hidden={!open}
70
- inert={!open}
71
- className={cn('fixed inset-0 z-50', !open && 'pointer-events-none')}
72
- >
73
- {/* Overlay */}
74
- <div
75
- onClick={close}
76
- aria-hidden="true"
77
- className={cn(
78
- 'bg-foreground/35 absolute inset-0 backdrop-blur-[2px] transition-opacity duration-300 motion-reduce:transition-none',
79
- open ? 'opacity-100' : 'opacity-0'
80
- )}
81
- />
82
-
83
- {/* Panel — anchored at the logical end (same side as the cart icon) */}
84
- <aside
85
- role="dialog"
86
- aria-modal="true"
87
- aria-label={t('title')}
88
- className={cn(
89
- 'bg-background absolute inset-y-0 end-0 flex w-full max-w-md flex-col shadow-2xl transition-transform duration-300 ease-out motion-reduce:transition-none sm:rounded-s-3xl sm:border-s',
90
- open ? 'translate-x-0' : 'ltr:translate-x-full rtl:-translate-x-full'
91
- )}
92
- >
93
- <header className="flex items-center gap-3 border-b px-5 py-4">
94
- <h2 className="font-display text-foreground text-xl font-semibold">{t('title')}</h2>
95
- {itemCount > 0 && (
96
- <span className="bg-primary text-primary-foreground flex h-6 min-w-6 items-center justify-center rounded-full px-1.5 text-xs font-bold">
97
- {itemCount}
98
- </span>
99
- )}
100
- <button
101
- ref={closeRef}
102
- type="button"
103
- onClick={close}
104
- aria-label={tc('close')}
105
- className="text-foreground hover:bg-secondary ms-auto flex h-10 w-10 items-center justify-center rounded-full transition-colors"
106
- >
107
- <IconX size={20} />
108
- </button>
109
- </header>
110
-
111
- {items.length === 0 ? (
112
- <div className="flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center">
113
- <span className="bg-secondary text-muted-foreground flex h-16 w-16 items-center justify-center rounded-full">
114
- <IconBag size={24} />
115
- </span>
116
- <p className="font-display text-foreground text-lg font-semibold">{t('emptyTitle')}</p>
117
- <p className="text-muted-foreground max-w-xs text-sm">{t('emptySubtitle')}</p>
118
- <Link href="/products" onClick={close} className="btn-primary btn-sm mt-2">
119
- {tc('continueShopping')}
120
- </Link>
121
- </div>
122
- ) : (
123
- <>
124
- <div className="flex-1 overflow-y-auto px-5 py-4">
125
- <FreeShippingBar className="mb-4" />
126
- <ul className="divide-y">
127
- {items.map((item) => (
128
- <li key={item.id} className="py-4 first:pt-0">
129
- <CartItem item={item} onUpdate={refreshCart} />
130
- </li>
131
- ))}
132
- </ul>
133
- </div>
134
-
135
- <footer className="bg-secondary/40 border-t px-5 py-4">
136
- <div className="flex items-center justify-between text-sm">
137
- <span className="text-muted-foreground">{tc('subtotal')}</span>
138
- <strong className="text-foreground text-base">
139
- {formatPrice(totals.subtotal, { currency }) as string}
140
- </strong>
141
- </div>
142
- {totals.discount > 0 && (
143
- <div className="text-primary mt-1 flex items-center justify-between text-sm">
144
- <span>{tc('discount')}</span>
145
- <span>-{formatPrice(totals.discount, { currency }) as string}</span>
146
- </div>
147
- )}
148
- <p className="text-muted-foreground mt-1 text-xs">{t('shippingAtCheckout')}</p>
149
- <div className="mt-4 grid gap-2">
150
- {/* Same gate as the cart page: a line the server marked
151
- unavailable blocks checkout. A disabled-looking anchor
152
- would still navigate, so use a real disabled button. */}
153
- {items.some((item) => item.isAvailable === false) ? (
154
- <>
155
- <button
156
- type="button"
157
- disabled
158
- className="btn-primary btn-lg w-full opacity-50"
159
- >
160
- {t('proceedToCheckout')}
161
- </button>
162
- <p className="text-destructive text-center text-xs">
163
- {t('unavailableItemsHint')}
164
- </p>
165
- </>
166
- ) : (
167
- <Link href="/checkout" onClick={close} className="btn-primary btn-lg w-full">
168
- {t('proceedToCheckout')}
169
- </Link>
170
- )}
171
- <Link href="/cart" onClick={close} className="btn-outline btn-lg w-full">
172
- {t('viewCart')}
173
- </Link>
174
- </div>
175
- </footer>
176
- </>
177
- )}
178
- </aside>
179
- </div>
180
- );
181
- }
1
+ 'use client';
2
+
3
+ /**
4
+ * Mini-cart drawer — a slide-over sheet anchored to the header cart side
5
+ * (logical `end`, so it hugs the cart icon in both RTL and LTR).
6
+ *
7
+ * Opens via `openCartDrawer()` (fired after a successful add-to-cart);
8
+ * the header cart icon itself still navigates to /cart — the drawer never
9
+ * hijacks that. Closes on overlay click, Escape, the X, or any CTA.
10
+ *
11
+ * Stays mounted so the slide transition runs both ways; when closed it is
12
+ * `inert` + aria-hidden so nothing inside is focusable.
13
+ */
14
+ import { useEffect, useRef, useState } from 'react';
15
+ import { Link } from '@/core/lib/navigation';
16
+ import { formatPrice } from 'brainerce';
17
+ import { useCart } from '@/core/providers/store-provider';
18
+ import { useTranslations } from '@/core/lib/translations';
19
+ import { useCurrency } from '@/core/lib/use-currency';
20
+ import { CartItem } from '@/ui/cart/cart-item';
21
+ import { FreeShippingBar } from '@/ui/cart/free-shipping-bar';
22
+ import { cn } from '@/core/lib/utils';
23
+ import { IconBag, IconX } from '@/ui/shared/icons';
24
+
25
+ const OPEN_EVENT = 'cart-drawer:open';
26
+
27
+ /** Ask the mounted drawer to slide open (no-op during SSR). */
28
+ export function openCartDrawer() {
29
+ if (typeof window !== 'undefined') {
30
+ window.dispatchEvent(new Event(OPEN_EVENT));
31
+ }
32
+ }
33
+
34
+ export function CartDrawer() {
35
+ const [open, setOpen] = useState(false);
36
+ const { cart, itemCount, totals, refreshCart } = useCart();
37
+ const t = useTranslations('cart');
38
+ const tc = useTranslations('common');
39
+ const currency = useCurrency();
40
+ const closeRef = useRef<HTMLButtonElement>(null);
41
+
42
+ useEffect(() => {
43
+ const onOpen = () => setOpen(true);
44
+ window.addEventListener(OPEN_EVENT, onOpen);
45
+ return () => window.removeEventListener(OPEN_EVENT, onOpen);
46
+ }, []);
47
+
48
+ // Open state side-effects: Escape to close, scroll lock, focus the X.
49
+ useEffect(() => {
50
+ if (!open) return;
51
+ const onKey = (e: KeyboardEvent) => {
52
+ if (e.key === 'Escape') setOpen(false);
53
+ };
54
+ document.addEventListener('keydown', onKey);
55
+ const prevOverflow = document.body.style.overflow;
56
+ document.body.style.overflow = 'hidden';
57
+ closeRef.current?.focus();
58
+ return () => {
59
+ document.removeEventListener('keydown', onKey);
60
+ document.body.style.overflow = prevOverflow;
61
+ };
62
+ }, [open]);
63
+
64
+ const close = () => setOpen(false);
65
+ const items = cart?.items ?? [];
66
+
67
+ return (
68
+ <div
69
+ aria-hidden={!open}
70
+ inert={!open}
71
+ className={cn('fixed inset-0 z-50', !open && 'pointer-events-none')}
72
+ >
73
+ {/* Overlay */}
74
+ <div
75
+ onClick={close}
76
+ aria-hidden="true"
77
+ className={cn(
78
+ 'bg-foreground/35 absolute inset-0 backdrop-blur-[2px] transition-opacity duration-300 motion-reduce:transition-none',
79
+ open ? 'opacity-100' : 'opacity-0'
80
+ )}
81
+ />
82
+
83
+ {/* Panel — anchored at the logical end (same side as the cart icon) */}
84
+ <aside
85
+ role="dialog"
86
+ aria-modal="true"
87
+ aria-label={t('title')}
88
+ className={cn(
89
+ 'bg-background absolute inset-y-0 end-0 flex w-full max-w-md flex-col shadow-2xl transition-transform duration-300 ease-out motion-reduce:transition-none sm:rounded-s-3xl sm:border-s',
90
+ open ? 'translate-x-0' : 'ltr:translate-x-full rtl:-translate-x-full'
91
+ )}
92
+ >
93
+ <header className="flex items-center gap-3 border-b px-5 py-4">
94
+ <h2 className="font-display text-foreground text-xl font-semibold">{t('title')}</h2>
95
+ {itemCount > 0 && (
96
+ <span className="bg-primary text-primary-foreground flex h-6 min-w-6 items-center justify-center rounded-full px-1.5 text-xs font-bold">
97
+ {itemCount}
98
+ </span>
99
+ )}
100
+ <button
101
+ ref={closeRef}
102
+ type="button"
103
+ onClick={close}
104
+ aria-label={tc('close')}
105
+ className="text-foreground hover:bg-secondary ms-auto flex h-10 w-10 items-center justify-center rounded-full transition-colors"
106
+ >
107
+ <IconX size={20} />
108
+ </button>
109
+ </header>
110
+
111
+ {items.length === 0 ? (
112
+ <div className="flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center">
113
+ <span className="bg-secondary text-muted-foreground flex h-16 w-16 items-center justify-center rounded-full">
114
+ <IconBag size={24} />
115
+ </span>
116
+ <p className="font-display text-foreground text-lg font-semibold">{t('emptyTitle')}</p>
117
+ <p className="text-muted-foreground max-w-xs text-sm">{t('emptySubtitle')}</p>
118
+ <Link href="/products" onClick={close} className="btn-primary btn-sm mt-2">
119
+ {tc('continueShopping')}
120
+ </Link>
121
+ </div>
122
+ ) : (
123
+ <>
124
+ <div className="flex-1 overflow-y-auto px-5 py-4">
125
+ <FreeShippingBar className="mb-4" />
126
+ <ul className="divide-y">
127
+ {items.map((item) => (
128
+ <li key={item.id} className="py-4 first:pt-0">
129
+ <CartItem item={item} onUpdate={refreshCart} />
130
+ </li>
131
+ ))}
132
+ </ul>
133
+ </div>
134
+
135
+ <footer className="bg-secondary/40 border-t px-5 py-4">
136
+ <div className="flex items-center justify-between text-sm">
137
+ <span className="text-muted-foreground">{tc('subtotal')}</span>
138
+ <strong className="text-foreground text-base">
139
+ {formatPrice(totals.subtotal, { currency }) as string}
140
+ </strong>
141
+ </div>
142
+ {totals.discount > 0 && (
143
+ <div className="text-primary mt-1 flex items-center justify-between text-sm">
144
+ <span>{tc('discount')}</span>
145
+ <span>-{formatPrice(totals.discount, { currency }) as string}</span>
146
+ </div>
147
+ )}
148
+ <p className="text-muted-foreground mt-1 text-xs">{t('shippingAtCheckout')}</p>
149
+ <div className="mt-4 grid gap-2">
150
+ {/* Same gate as the cart page: a line the server marked
151
+ unavailable blocks checkout. A disabled-looking anchor
152
+ would still navigate, so use a real disabled button. */}
153
+ {items.some((item) => item.isAvailable === false) ? (
154
+ <>
155
+ <button type="button" disabled className="btn-primary btn-lg w-full opacity-50">
156
+ {t('proceedToCheckout')}
157
+ </button>
158
+ <p className="text-destructive text-center text-xs">
159
+ {t('unavailableItemsHint')}
160
+ </p>
161
+ </>
162
+ ) : (
163
+ <Link href="/checkout" onClick={close} className="btn-primary btn-lg w-full">
164
+ {t('proceedToCheckout')}
165
+ </Link>
166
+ )}
167
+ <Link href="/cart" onClick={close} className="btn-outline btn-lg w-full">
168
+ {t('viewCart')}
169
+ </Link>
170
+ </div>
171
+ </footer>
172
+ </>
173
+ )}
174
+ </aside>
175
+ </div>
176
+ );
177
+ }