소스 검색

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 일 전
부모
커밋
8aa780237c
2개의 변경된 파일과 35개의 추가작업 그리고 25개의 파일을 삭제
  1. 33
    25
      resources/js/storefront/pages/cart.tsx
  2. 2
    0
      resources/js/storefront/text.ts

+ 33
- 25
resources/js/storefront/pages/cart.tsx 파일 보기

1
 import { router } from '@inertiajs/react';
1
 import { router } from '@inertiajs/react';
2
+import { Trash2 } from 'lucide-react';
2
 import { useState } from 'react';
3
 import { useState } from 'react';
3
 import { useStorefront } from '../context';
4
 import { useStorefront } from '../context';
4
 import { ProductImage } from '../product-card';
5
 import { ProductImage } from '../product-card';
52
                         </SfButton>
53
                         </SfButton>
53
                     </div>
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
                             {cart.lines.map((line, index) => (
58
                             {cart.lines.map((line, index) => (
58
                                 <li
59
                                 <li
59
                                     key={line.product.id}
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
                                     <SfLink
63
                                     <SfLink
63
                                         href={`/products/${line.product.slug}`}
64
                                         href={`/products/${line.product.slug}`}
67
                                             src={line.product.image}
68
                                             src={line.product.image}
68
                                             alt={line.product.name}
69
                                             alt={line.product.name}
69
                                             seed={index}
70
                                             seed={index}
70
-                                            className="size-20 sm:size-24"
71
+                                            className="size-20 sm:size-28"
71
                                         />
72
                                         />
72
                                     </SfLink>
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
                                             </p>
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
                                         </div>
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
                                             <QuantityStepper
102
                                             <QuantityStepper
96
                                                 value={line.quantity}
103
                                                 value={line.quantity}
97
                                                 max={line.max}
104
                                                 max={line.max}
102
                                                 decreaseLabel={`${t.decrease}: ${line.product.name}`}
109
                                                 decreaseLabel={`${t.decrease}: ${line.product.name}`}
103
                                                 increaseLabel={`${t.increase}: ${line.product.name}`}
110
                                                 increaseLabel={`${t.increase}: ${line.product.name}`}
104
                                             />
111
                                             />
105
-                                            <p className="font-medium tabular-nums">
106
-                                                {formatPrice(line.line_total)}
107
-                                            </p>
108
                                             <button
112
                                             <button
109
                                                 type="button"
113
                                                 type="button"
110
                                                 disabled={busy}
114
                                                 disabled={busy}
111
                                                 onClick={() => change(line, 0)}
115
                                                 onClick={() => change(line, 0)}
112
                                                 aria-label={`${t.remove}: ${line.product.name}`}
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
                                                 {t.remove}
123
                                                 {t.remove}
116
                                             </button>
124
                                             </button>
117
                                         </div>
125
                                         </div>

+ 2
- 0
resources/js/storefront/text.ts 파일 보기

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

Loading…
취소
저장