create-brainerce-store 1.72.0 → 1.73.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.
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { useEffect, useState } from 'react';
4
- import { Star, X } from 'lucide-react';
4
+ import { ImagePlus, Star, X } from 'lucide-react';
5
5
  import { getClient } from '@/core/lib/brainerce';
6
6
  import { checkAuthStatus } from '@/core/lib/auth';
7
7
  import { Link } from '@/core/lib/navigation';
@@ -371,7 +371,7 @@ function ReviewEditor({
371
371
  setUploads((prev) => prev.filter((item) => item.key !== upload.key))
372
372
  }
373
373
  aria-label={t('removePhoto')}
374
- className="rounded-bs-none rounded-be absolute end-0 top-0 bg-black/60 px-1 text-xs text-white"
374
+ className="absolute end-1 top-1 rounded-full bg-black/60 p-1 text-white"
375
375
  >
376
376
  <X className="h-3 w-3" aria-hidden="true" />
377
377
  </button>
@@ -380,16 +380,38 @@ function ReviewEditor({
380
380
  </ul>
381
381
  )}
382
382
 
383
- <input
384
- type="file"
385
- accept="image/jpeg,image/png,image/webp,image/gif"
386
- multiple
387
- disabled={uploading || roomLeft <= 0}
388
- onChange={handleFiles}
389
- className="block text-sm"
390
- />
383
+ {/* A <label> wrapping a visually hidden input, not a bare file control.
384
+ The browser's own "Choose Files" button cannot be styled and looks
385
+ nothing like the rest of the form. Two things this has to do that the
386
+ native control did for free: `disabled` on a hidden input greys
387
+ NOTHING, so the label paints its own disabled state, and the line
388
+ underneath says WHY it is disabled rather than leaving a dead button.
389
+ The input stays a real input (no ref.click()) so keyboard and
390
+ assistive tech reach it, and focus-within restores the focus ring. */}
391
+ <Button asChild variant="outline" size="sm" className="w-fit">
392
+ <label
393
+ className={`focus-within:ring-ring inline-flex cursor-pointer items-center gap-2 focus-within:ring-2 ${
394
+ uploading || roomLeft <= 0 ? 'pointer-events-none opacity-50' : ''
395
+ }`}
396
+ >
397
+ <ImagePlus className="h-4 w-4" aria-hidden="true" />
398
+ {uploading ? t('photoUploading') : t('choosePhotos')}
399
+ <input
400
+ type="file"
401
+ accept="image/jpeg,image/png,image/webp,image/gif"
402
+ multiple
403
+ disabled={uploading || roomLeft <= 0}
404
+ onChange={handleFiles}
405
+ className="sr-only"
406
+ />
407
+ </label>
408
+ </Button>
391
409
 
392
- {uploading && <p className="text-muted-foreground text-xs">{t('photoUploading')}</p>}
410
+ <p className="text-muted-foreground text-xs">
411
+ {roomLeft <= 0
412
+ ? t('photoLimitReached', { max: String(photos.maxPerReview) })
413
+ : t('photoFormats', { mb: String(Math.round(photos.maxBytes / (1024 * 1024))) })}
414
+ </p>
393
415
  {/* Say it BEFORE they submit. A shopper who uploads a photo, submits, and
394
416
  then cannot see it will conclude the site is broken. */}
395
417
  {photos.requiresApproval && (
@@ -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
+ }