Przeglądaj źródła

Redesign cart items as cards

Each cart line is now a card with the photo, name, unit price, line
total, quantity stepper and a Remove button with an icon. Fixes the
list stretching to the height of the summary card.
feature/publishing
fahmisaad 5 dni temu
rodzic
commit
8aa780237c

+ 33
- 25
resources/js/storefront/pages/cart.tsx Wyświetl plik

@@ -1,4 +1,5 @@
1 1
 import { router } from '@inertiajs/react';
2
+import { Trash2 } from 'lucide-react';
2 3
 import { useState } from 'react';
3 4
 import { useStorefront } from '../context';
4 5
 import { ProductImage } from '../product-card';
@@ -52,12 +53,12 @@ export function CartPage() {
52 53
                         </SfButton>
53 54
                     </div>
54 55
                 ) : (
55
-                    <div className="mt-10 grid gap-10 lg:grid-cols-[1fr_340px] lg:gap-14">
56
-                        <ul className="divide-y divide-(--sf-border) border-y border-(--sf-border)">
56
+                    <div className="mt-10 grid items-start gap-8 lg:grid-cols-[1fr_340px] lg:gap-10">
57
+                        <ul className="space-y-4">
57 58
                             {cart.lines.map((line, index) => (
58 59
                                 <li
59 60
                                     key={line.product.id}
60
-                                    className="flex gap-4 py-5"
61
+                                    className="flex gap-4 rounded-(--sf-radius-card) border border-(--sf-border) bg-(--sf-bg) p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-shadow hover:shadow-[0_4px_16px_rgb(0_0_0/0.06)] sm:gap-5 sm:p-5"
61 62
                                 >
62 63
                                     <SfLink
63 64
                                         href={`/products/${line.product.slug}`}
@@ -67,31 +68,37 @@ export function CartPage() {
67 68
                                             src={line.product.image}
68 69
                                             alt={line.product.name}
69 70
                                             seed={index}
70
-                                            className="size-20 sm:size-24"
71
+                                            className="size-20 sm:size-28"
71 72
                                         />
72 73
                                     </SfLink>
73 74
 
74
-                                    <div className="flex min-w-0 flex-1 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
75
-                                        <div className="min-w-0">
76
-                                            <SfLink
77
-                                                href={`/products/${line.product.slug}`}
78
-                                                className="font-medium hover:underline"
79
-                                            >
80
-                                                {line.product.name}
81
-                                            </SfLink>
82
-                                            <p className="mt-1 text-sm text-(--sf-muted) tabular-nums">
83
-                                                {formatPrice(
84
-                                                    line.product.price,
75
+                                    <div className="flex min-w-0 flex-1 flex-col justify-between gap-4">
76
+                                        <div className="flex items-start justify-between gap-4">
77
+                                            <div className="min-w-0">
78
+                                                <SfLink
79
+                                                    href={`/products/${line.product.slug}`}
80
+                                                    className="font-medium hover:underline"
81
+                                                >
82
+                                                    {line.product.name}
83
+                                                </SfLink>
84
+                                                <p className="mt-1 text-sm text-(--sf-muted) tabular-nums">
85
+                                                    {formatPrice(
86
+                                                        line.product.price,
87
+                                                    )}{' '}
88
+                                                    {t.each}
89
+                                                </p>
90
+                                                {line.quantity >= line.max && (
91
+                                                    <p className="mt-2 inline-block rounded-full bg-(--sf-surface) px-2.5 py-0.5 text-xs text-(--sf-muted)">
92
+                                                        {t.onlyLeft(line.max)}
93
+                                                    </p>
85 94
                                                 )}
95
+                                            </div>
96
+                                            <p className="shrink-0 text-lg font-semibold tabular-nums">
97
+                                                {formatPrice(line.line_total)}
86 98
                                             </p>
87
-                                            {line.quantity >= line.max && (
88
-                                                <p className="mt-1 text-xs text-(--sf-muted)">
89
-                                                    {t.onlyLeft(line.max)}
90
-                                                </p>
91
-                                            )}
92 99
                                         </div>
93 100
 
94
-                                        <div className="flex items-center gap-4 sm:flex-col sm:items-end sm:gap-2">
101
+                                        <div className="flex items-center justify-between gap-4">
95 102
                                             <QuantityStepper
96 103
                                                 value={line.quantity}
97 104
                                                 max={line.max}
@@ -102,16 +109,17 @@ export function CartPage() {
102 109
                                                 decreaseLabel={`${t.decrease}: ${line.product.name}`}
103 110
                                                 increaseLabel={`${t.increase}: ${line.product.name}`}
104 111
                                             />
105
-                                            <p className="font-medium tabular-nums">
106
-                                                {formatPrice(line.line_total)}
107
-                                            </p>
108 112
                                             <button
109 113
                                                 type="button"
110 114
                                                 disabled={busy}
111 115
                                                 onClick={() => change(line, 0)}
112 116
                                                 aria-label={`${t.remove}: ${line.product.name}`}
113
-                                                className="text-sm text-(--sf-muted) underline underline-offset-2 hover:text-(--sf-fg) disabled:opacity-50"
117
+                                                className="inline-flex items-center gap-1.5 rounded-(--sf-radius) px-2.5 py-1.5 text-sm text-(--sf-muted) transition-colors hover:bg-(--sf-surface) hover:text-(--sf-fg) disabled:opacity-50"
114 118
                                             >
119
+                                                <Trash2
120
+                                                    className="size-4"
121
+                                                    aria-hidden="true"
122
+                                                />
115 123
                                                 {t.remove}
116 124
                                             </button>
117 125
                                         </div>

+ 2
- 0
resources/js/storefront/text.ts Wyświetl plik

@@ -18,6 +18,7 @@ const words = {
18 18
         cartEmpty: 'Your cart is empty.',
19 19
         continueShopping: 'Continue shopping',
20 20
         remove: 'Remove',
21
+        each: 'each',
21 22
         decrease: 'Decrease quantity',
22 23
         increase: 'Increase quantity',
23 24
         subtotal: 'Subtotal',
@@ -72,6 +73,7 @@ const words = {
72 73
         cartEmpty: 'Troli anda kosong.',
73 74
         continueShopping: 'Teruskan membeli-belah',
74 75
         remove: 'Buang',
76
+        each: 'seunit',
75 77
         decrease: 'Kurangkan kuantiti',
76 78
         increase: 'Tambah kuantiti',
77 79
         subtotal: 'Jumlah kecil',

Ładowanie…
Anuluj
Zapisz