Просмотр исходного кода

Add more section layouts and a Layouts box

- Products: sliding row and large cards; featured: wide photo on top
- About: big statement; reviews: wall of quotes; FAQ: answers in cards
- Newsletter: heading beside form; footer: columns
- Layouts box in Design tab; AI knows when each layout suits
redesign/part-5-section-layouts
fahmisaad 5 дней назад
Родитель
Сommit
64b8caef0b

+ 22
- 3
PROGRESS.md Просмотреть файл

@@ -4,8 +4,8 @@ This file is the single source of truth for the project plan and status.
4 4
 Update it at the end of every work session.
5 5
 
6 6
 **Last updated:** 2026-11-19
7
-**Current step:** Step 9 — Modern store design (parts 1–4 done; next: part 5, more layouts per section)
8
-**Next action:** Commit part 4 on `redesign/part-4-style-options` (do not merge into `main` yet). Then create `redesign/part-5-section-layouts` from it and add more layouts per section. Step 7 part 2 still waits for an EasyParcel API key
7
+**Current step:** Step 9 — Modern store design (parts 1–5 done; next: part 6, category guides)
8
+**Next action:** Commit part 5 on `redesign/part-5-section-layouts` (do not merge into `main` yet). Then create `redesign/part-6-category-guides` from it and write the category guides. Step 7 part 2 still waits for an EasyParcel API key
9 9
 
10 10
 Status marks: `[ ]` not started · `[~]` in progress · `[x]` done
11 11
 
@@ -229,6 +229,23 @@ Changing from Claude to another AI model (or back) must be a settings change, no
229 229
 - **Gentle motion:** sections that start below the first screen fade up as they come into view. Anything on the first screen is never hidden, and nothing moves for visitors who ask their device for less motion. A scroll check is used instead of an intersection observer, for the same reason as the sticky cart bar.
230 230
 - **AI:** chooses a style that fits the brand when generating (with examples per kind of brand), and changes it by chat ("make it more premium", "bolder").
231 231
 
232
+### Section layouts (added in Step 9 part 5)
233
+
234
+| Section                    | Layouts (new ones in bold)                                                                            |
235
+| -------------------------- | ----------------------------------------------------------------------------------------------------- |
236
+| Hero                       | centered, split, image-full                                                                           |
237
+| Products                   | grid, minimal, **carousel** (one sideways row with arrows), **large** (2 big cards, up to 4 products) |
238
+| Featured product           | image-left, image-right, **stacked** (wide photo on top, words centred)                               |
239
+| About                      | simple, with-stats, **statement** (the story as one large statement; a step smaller when it is long)  |
240
+| Reviews                    | cards, single, **wall** (quotes packed in columns)                                                    |
241
+| FAQ                        | list, two-column, **cards** (every answer showing)                                                    |
242
+| Newsletter                 | banner, card, **split** (big heading beside the form)                                                 |
243
+| Footer                     | simple, centered, **columns** (store name and text, links, shop and help links)                       |
244
+| Header, contact, trust row | 2 each, unchanged                                                                                     |
245
+
246
+- The Design tab has a **Layouts** box (closed by default) listing every section with its layout in plain words; heroes stay in their own Hero box. `App\StorePlan\SectionLayouts` finds and changes them; only layouts of the section's own type are accepted.
247
+- The AI is told what each new layout looks like and when it suits, and can switch layouts by chat ("make the products slide sideways").
248
+
232 249
 ### Category guides for the AI (agreed 2026-11-17)
233 250
 
234 251
 - The category the merchant picks on the Create store page (Fashion, Beauty, Food, Home, Electronics, Health, Kids, Digital, Other) chooses a short design guide that is sent to the AI with the brand description.
@@ -371,7 +388,7 @@ Agreed on 2026-11-17 after comparing our stores with 2026 design trends (researc
371 388
 - [x] Part 2 — Announcement bar and trust row (done 2026-11-18): a slim bar above the header and a row of trust points, filled in by themselves from free shipping, automatic discounts, secure payment and WhatsApp
372 389
 - [x] Part 3 — Product page upgrade (done 2026-11-18): trust points under the button, folding sections (the product's own, such as "How to use", plus shipping from real fees), sticky add-to-cart bar on phones, "pairs well with", photos that stay in view on wide screens, and a phone menu for the header
373 390
 - [x] Part 4 — Style options and motion (done 2026-11-19): six style options (buttons, cards, spacing, headings, backgrounds, motion), six ready-made looks in a Style box in the Design tab, 12 more fonts (20 in all), gentle fade-in motion, and AI rules so each brand gets a fitting style
374
-- [ ] Part 5 — More layouts per section: 3 to 4 layouts instead of 2 for the main sections (moved out of part 4 on 2026-11-19)
391
+- [x] Part 5 — More layouts per section (done 2026-11-19): 7 new layouts, so the main sections have 3 or 4 each, and a Layouts box in the Design tab
375 392
 - [ ] Part 6 — Category guides for the AI (see section 2)
376 393
 - [ ] Part 7 — Collections ("shop by need" tiles and menu links), bento grid section, video section, real reviews from buyers after delivery
377 394
 
@@ -485,6 +502,7 @@ Then, from the project folder:
485 502
 | Announcement bar and trust row         | `app/Storefront/Announcements.php`, `storefront/sections/announcement-bar.tsx`, `storefront/sections/trust-bar.tsx`                                                                    |
486 503
 | Product page, phone menu               | `storefront/pages/product.tsx`, `app/Storefront/RelatedProducts.php`, `components/stores/details-editor.tsx`, `storefront/sections/header.tsx`                                         |
487 504
 | Store styles                           | `PlanSchema::STYLE_OPTIONS` and `STYLE_PRESETS`, `StoreStyleController`, `storefront/theme.ts`, `storefront/reveal.tsx`, `resources/css/app.css`, `components/stores/style-picker.tsx` |
505
+| Section layouts                        | `PlanSchema::SECTIONS`, `app/StorePlan/SectionLayouts.php`, `SectionLayoutController`, `storefront/sections/*.tsx`, `components/stores/layout-picker.tsx`                              |
488 506
 | Storefront words (English, Malay)      | `resources/js/storefront/text.ts`                                                                                                                                                      |
489 507
 | Store plan format (frontend types)     | `resources/js/storefront/types.ts`                                                                                                                                                     |
490 508
 | Storefront renderer and sections       | `resources/js/storefront/renderer.tsx`, `resources/js/storefront/sections/`                                                                                                            |
@@ -546,3 +564,4 @@ Add one line per work session: date, what was done, what is next.
546 564
 | 2026-11-18 | Step 9 part 2 on branch `redesign/part-2-announcement-bar` (from part 1): announcement bar (automatic lines + merchant lines, Settings card) and trust row section with live facts. Plan checker now supports "required if" rules. 257 tests pass; real DeepSeek added a trust row to Luna Skin correctly; checked in the browser.                                                                                                                                 | Commit; part 3 branches from part 2                             |
547 565
 | 2026-11-18 | Step 9 part 3 on branch `redesign/part-3-product-page` (from part 2): folding sections (form, chat with merge by title), trust points, sticky phone add-to-cart bar, pairs well with, phone menu, sticky photos. Found and fixed the sticky bar hiding under the header. 261 tests pass; real DeepSeek wrote a sensible "How to use" for the sunscreen (confirmed); checked at phone width.                                                                        | Commit; part 4 branches from part 3                             |
548 566
 | 2026-11-19 | Step 9 part 4 on branch `redesign/part-4-style-options` (from part 3): style options, six ready-made looks with a Style box, 12 more fonts, gentle motion, AI style rules. Fixed fade-in hiding a section that was already partly on screen. "More layouts per section" moved to a new part 5; category guides are now part 6 and collections part 7. 266 tests pass; Bold look and a real DeepSeek "more premium and elegant" change both checked in the browser. | Commit; part 5 branches from part 4                             |
567
+| 2026-11-19 | Step 9 part 5 on branch `redesign/part-5-section-layouts` (from part 4): 7 new section layouts (products carousel and large, featured stacked, about statement, reviews wall, FAQ cards, newsletter split, footer columns) and a Layouts box. 270 tests pass; every layout checked in the browser on Luna Skin; long About statements now shown a step smaller.                                                                                                    | Commit; part 6 branches from part 5                             |

+ 2
- 1
README.md Просмотреть файл

@@ -21,7 +21,7 @@ An AI store generator for ecommerce. A customer describes their brand, and the A
21 21
 | 6    | Our own subscription billing                            | Done                                                           |
22 22
 | 7    | Malaysia features: FPX, DuitNow, EasyParcel, WhatsApp   | Part 1 done (shipping fees, WhatsApp); EasyParcel and FPX next |
23 23
 | 8    | Discounts and product options: codes, variants, bundles | Done                                                           |
24
-| 9    | Modern store design: photos, styles, category guides    | In progress: parts 1–4 done; part 5 next                       |
24
+| 9    | Modern store design: photos, styles, category guides    | In progress: parts 1–5 done; part 6 next                       |
25 25
 | 10   | Before launch: hosting, legal pages, backups            | Not started                                                    |
26 26
 
27 27
 ## What works today
@@ -40,6 +40,7 @@ An AI store generator for ecommerce. A customer describes their brand, and the A
40 40
 - Trust row under the hero: shipping, secure payment and WhatsApp, always taken from the store's real settings
41 41
 - Product page: folding sections such as "How to use" (written in the form or by chat) plus shipping from real fees, trust points, "Pairs well with", and an add-to-cart bar that stays at the bottom on phones
42 42
 - Phone menu for the store header
43
+- More layouts per section (3 or 4 for the main ones), such as a sliding product row, large product cards, a wall of reviews and a columns footer, changeable in the Layouts box of the Design tab or by chat
43 44
 - Store styles: six ready-made looks (Minimal, Soft, Elegant, Bold, Playful, Classic) in the Design tab, with fine-tuning for buttons, cards, spacing, headings, backgrounds and motion; 20 fonts. The AI picks a style that fits the brand and changes it by chat
44 45
 - Change the store by chat, for example "make a 10% code RAYA10 until the end of the month" or "set the 100ml moisturiser to RM 52", or "write descriptions for my products". The AI shows what it will do, and nothing changes until you press Confirm
45 46
 - Add or remove whole pages by chat, for example "add an About page". The menu link is added automatically

+ 42
- 0
app/Http/Controllers/SectionLayoutController.php Просмотреть файл

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use App\StorePlan\PlanSchema;
6
+use App\StorePlan\PlanValidator;
7
+use App\StorePlan\SectionLayouts;
8
+use Illuminate\Http\RedirectResponse;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Validation\Rule;
11
+use Inertia\Inertia;
12
+
13
+/**
14
+ * Changes one section's layout from the Design tab's Layouts box.
15
+ * This changes the working design, so a live store shows it after "Publish changes".
16
+ */
17
+class SectionLayoutController extends Controller
18
+{
19
+    public function update(Request $request, PlanValidator $validator, string $slug, string $sectionId): RedirectResponse
20
+    {
21
+        $store = $request->user()->stores()->where('slug', $slug)->firstOrFail();
22
+
23
+        abort_if($store->plan === null, 404);
24
+
25
+        $type = SectionLayouts::typeOf($store->plan, $sectionId);
26
+
27
+        abort_if($type === null, 404);
28
+
29
+        $validated = $request->validate([
30
+            'variant' => ['required', Rule::in(PlanSchema::SECTIONS[$type])],
31
+        ]);
32
+
33
+        $store->plan = $validator->validate(SectionLayouts::update($store->plan, $sectionId, $validated['variant']));
34
+        $store->save();
35
+
36
+        Inertia::flash('toast', ['type' => 'success', 'message' => $store->isPublished()
37
+            ? __('Saved. Click "Publish changes" to show it on your live store.')
38
+            : __('Layout saved.')]);
39
+
40
+        return to_route('stores.show', $store->slug);
41
+    }
42
+}

+ 4
- 0
app/Http/Controllers/StoreController.php Просмотреть файл

@@ -14,6 +14,7 @@ use App\Storefront\Storefront;
14 14
 use App\StorePlan\FeaturedProducts;
15 15
 use App\StorePlan\HeroImages;
16 16
 use App\StorePlan\PlanSchema;
17
+use App\StorePlan\SectionLayouts;
17 18
 use Illuminate\Http\RedirectResponse;
18 19
 use Illuminate\Http\Request;
19 20
 use Inertia\Inertia;
@@ -99,6 +100,9 @@ class StoreController extends Controller
99 100
                 'radius' => $store->plan['theme']['radius'] ?? 'medium',
100 101
                 'fonts' => $store->plan['theme']['fonts'] ?? null,
101 102
             ] : null,
103
+            // Every section (heroes have their own box) with its layout, and the layouts each type allows.
104
+            'layoutSections' => $store->plan !== null ? SectionLayouts::sections($store->plan) : [],
105
+            'layoutOptions' => PlanSchema::SECTIONS,
102 106
             'stylePresets' => collect(PlanSchema::STYLE_PRESETS)
103 107
                 ->map(fn (array $preset, string $key) => ['key' => $key, ...$preset])
104 108
                 ->values(),

+ 1
- 0
app/StorePlan/Ai/PlanPrompt.php Просмотреть файл

@@ -39,6 +39,7 @@ final class PlanPrompt
39 39
         - Design one page for now: the home page (id "home", title "Home"), with 5 to 8 sections. Start it with a "hero". Pick the other sections to suit the brand.
40 40
         - The header and footer are written once, at the top of the plan. Do not put them inside a page.
41 41
         - Choose a colour palette, fonts and a "style" that fit the brand's mood. Do not default to the same look for every store. The style changes buttons, cards, spacing, headings, backgrounds and motion, so two stores with similar colours still feel different. For example: a quiet skincare or homeware brand suits plain cards, airy spacing and outline or solid buttons; a premium or fashion brand suits spaced-capital headings, no-edge cards and a serif heading font; a loud streetwear, snack or kids brand suits heavy headings, bold shadow buttons, hard cards and alternating bands. Gentle motion suits most stores.
42
+        - Layouts to know: product_grid "carousel" (one row that scrolls sideways, good for many products) and "large" (2 big cards across, good for a few hero products); featured_product "stacked" (wide photo on top, words centred); about "statement" (the story as one large statement); testimonials "wall" (quotes of different lengths packed in columns; only with 3 or more quotes); faq "cards" (all answers showing, good for 2 to 6 short questions); newsletter "split" (big heading beside the form, calmer than a colour banner); footer "columns" (store name, links and help links).
42 43
         - Make the structure fit the brand too. Decide which sections this brand really needs, in which order, and pick each variant on purpose. You do not need every section type. A store with one main product may put "featured_product" right after the hero; a brand with a strong story may put "about" early; a small catalogue suits "product_grid" with the "minimal" variant. Do not reuse the section order or variants of the example below.
43 44
         - Text must be easy to read: strong contrast between "foreground" and "background", and between "primaryForeground" and "primary".
44 45
         - Write specific, warm, concrete copy for this brand. Avoid generic filler.

+ 14
- 7
app/StorePlan/PlanSchema.php Просмотреть файл

@@ -171,14 +171,21 @@ final class PlanSchema
171 171
         'hero' => ['centered', 'split', 'image-full'],
172 172
         // A row of short reassurances, such as free shipping and secure payment. row: a band. boxed: small cards.
173 173
         'trust_bar' => ['row', 'boxed'],
174
-        'product_grid' => ['grid', 'minimal'],
175
-        'featured_product' => ['image-left', 'image-right'],
176
-        'about' => ['simple', 'with-stats'],
177
-        'testimonials' => ['cards', 'single'],
178
-        'faq' => ['list', 'two-column'],
179
-        'newsletter' => ['banner', 'card'],
174
+        // carousel: one row that scrolls sideways. large: 2 big cards across, like a magazine.
175
+        'product_grid' => ['grid', 'minimal', 'carousel', 'large'],
176
+        // stacked: a wide photo on top, the words centred under it.
177
+        'featured_product' => ['image-left', 'image-right', 'stacked'],
178
+        // statement: the body as one large statement, the heading as a small label.
179
+        'about' => ['simple', 'with-stats', 'statement'],
180
+        // wall: cards of different heights packed in columns.
181
+        'testimonials' => ['cards', 'single', 'wall'],
182
+        // list and two-column fold open; cards shows every answer in a grid.
183
+        'faq' => ['list', 'two-column', 'cards'],
184
+        // split: a big heading beside the form, in the store's normal colours.
185
+        'newsletter' => ['banner', 'card', 'split'],
180 186
         'contact' => ['simple', 'card'],
181
-        'footer' => ['simple', 'centered'],
187
+        // columns: store name and text, the footer links, and shop and help links.
188
+        'footer' => ['simple', 'centered', 'columns'],
182 189
     ];
183 190
 
184 191
     /**

+ 90
- 0
app/StorePlan/SectionLayouts.php Просмотреть файл

@@ -0,0 +1,90 @@
1
+<?php
2
+
3
+namespace App\StorePlan;
4
+
5
+/**
6
+ * The layout (variant) of each section, for the Design tab's Layouts box.
7
+ * The header and footer use the ids "header" and "footer". Heroes have their own box, so they are left out.
8
+ */
9
+final class SectionLayouts
10
+{
11
+    /**
12
+     * @param  array<string, mixed>  $plan
13
+     * @return list<array{page_id: string|null, page_title: string|null, section_id: string, type: string, variant: string, label: string}>
14
+     */
15
+    public static function sections(array $plan): array
16
+    {
17
+        $found = [[
18
+            'page_id' => null, 'page_title' => null, 'section_id' => 'header', 'type' => 'header',
19
+            'variant' => (string) ($plan['header']['variant'] ?? ''), 'label' => 'Header',
20
+        ]];
21
+
22
+        foreach ($plan['pages'] ?? [] as $page) {
23
+            foreach ($page['sections'] ?? [] as $section) {
24
+                $type = (string) ($section['type'] ?? '');
25
+
26
+                if ($type === 'hero') {
27
+                    continue;
28
+                }
29
+
30
+                $content = is_array($section['content'] ?? null) ? $section['content'] : [];
31
+
32
+                $found[] = [
33
+                    'page_id' => (string) ($page['id'] ?? ''),
34
+                    'page_title' => (string) ($page['title'] ?? ''),
35
+                    'section_id' => (string) ($section['id'] ?? ''),
36
+                    'type' => $type,
37
+                    'variant' => (string) ($section['variant'] ?? ''),
38
+                    // The section's own heading, so the merchant recognises it.
39
+                    'label' => (string) ($content['heading'] ?? $content['name'] ?? ''),
40
+                ];
41
+            }
42
+        }
43
+
44
+        $found[] = [
45
+            'page_id' => null, 'page_title' => null, 'section_id' => 'footer', 'type' => 'footer',
46
+            'variant' => (string) ($plan['footer']['variant'] ?? ''), 'label' => 'Footer',
47
+        ];
48
+
49
+        return $found;
50
+    }
51
+
52
+    /**
53
+     * The section's type, or null when the plan has no such section (heroes excluded).
54
+     *
55
+     * @param  array<string, mixed>  $plan
56
+     */
57
+    public static function typeOf(array $plan, string $sectionId): ?string
58
+    {
59
+        foreach (self::sections($plan) as $section) {
60
+            if ($section['section_id'] === $sectionId) {
61
+                return $section['type'];
62
+            }
63
+        }
64
+
65
+        return null;
66
+    }
67
+
68
+    /**
69
+     * @param  array<string, mixed>  $plan
70
+     * @return array<string, mixed>
71
+     */
72
+    public static function update(array $plan, string $sectionId, string $variant): array
73
+    {
74
+        if (in_array($sectionId, ['header', 'footer'], true)) {
75
+            $plan[$sectionId]['variant'] = $variant;
76
+
77
+            return $plan;
78
+        }
79
+
80
+        foreach ($plan['pages'] ?? [] as $pageIndex => $page) {
81
+            foreach ($page['sections'] ?? [] as $sectionIndex => $section) {
82
+                if (($section['id'] ?? null) === $sectionId) {
83
+                    $plan['pages'][$pageIndex]['sections'][$sectionIndex]['variant'] = $variant;
84
+                }
85
+            }
86
+        }
87
+
88
+        return $plan;
89
+    }
90
+}

+ 165
- 0
resources/js/components/stores/layout-picker.tsx Просмотреть файл

@@ -0,0 +1,165 @@
1
+import { router } from '@inertiajs/react';
2
+import { LayoutTemplate } from 'lucide-react';
3
+import { useState } from 'react';
4
+import SectionLayoutController from '@/actions/App/Http/Controllers/SectionLayoutController';
5
+import type { LayoutSection, Store } from '@/types';
6
+
7
+const fieldClass =
8
+    'h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50 md:text-sm';
9
+
10
+/** Section types and layouts in plain words. Unknown ones fall back to their code name. */
11
+const typeNames: Record<string, string> = {
12
+    header: 'Header',
13
+    trust_bar: 'Trust row',
14
+    product_grid: 'Products',
15
+    featured_product: 'Featured product',
16
+    about: 'About',
17
+    testimonials: 'Reviews',
18
+    faq: 'FAQ',
19
+    newsletter: 'Newsletter',
20
+    contact: 'Contact',
21
+    footer: 'Footer',
22
+};
23
+
24
+const layoutNames: Record<string, Record<string, string>> = {
25
+    header: { simple: 'Logo on the left', centered: 'Logo in the middle' },
26
+    trust_bar: { row: 'Icon row', boxed: 'Small cards' },
27
+    product_grid: {
28
+        grid: 'Grid',
29
+        minimal: 'Centred grid',
30
+        carousel: 'Sliding row',
31
+        large: 'Large cards',
32
+    },
33
+    featured_product: {
34
+        'image-left': 'Photo on the left',
35
+        'image-right': 'Photo on the right',
36
+        stacked: 'Wide photo on top',
37
+    },
38
+    about: {
39
+        simple: 'Centred text',
40
+        'with-stats': 'Text with numbers',
41
+        statement: 'One big statement',
42
+    },
43
+    testimonials: {
44
+        cards: 'Cards',
45
+        single: 'One big quote',
46
+        wall: 'Wall of quotes',
47
+    },
48
+    faq: {
49
+        list: 'Fold-open list',
50
+        'two-column': 'Two columns',
51
+        cards: 'All answers in cards',
52
+    },
53
+    newsletter: {
54
+        banner: 'Colour banner',
55
+        card: 'Colour card',
56
+        split: 'Heading beside the form',
57
+    },
58
+    contact: { simple: 'Simple', card: 'Card' },
59
+    footer: { simple: 'One line', centered: 'Centred', columns: 'Columns' },
60
+};
61
+
62
+/**
63
+ * The Design tab's Layouts box: the layout of every section, header and footer included.
64
+ * Heroes have their own box.
65
+ */
66
+export default function LayoutPicker({
67
+    store,
68
+    sections,
69
+    options,
70
+    busy,
71
+}: {
72
+    store: Store;
73
+    sections: LayoutSection[];
74
+    options: Record<string, string[]>;
75
+    busy: boolean;
76
+}) {
77
+    const [saving, setSaving] = useState<string | null>(null);
78
+
79
+    if (sections.length === 0) {
80
+        return null;
81
+    }
82
+
83
+    function choose(section: LayoutSection, variant: string) {
84
+        router.put(
85
+            SectionLayoutController.update.url({
86
+                slug: store.slug,
87
+                sectionId: section.section_id,
88
+            }),
89
+            { variant },
90
+            {
91
+                preserveScroll: true,
92
+                onStart: () => setSaving(section.section_id),
93
+                onFinish: () => setSaving(null),
94
+            },
95
+        );
96
+    }
97
+
98
+    return (
99
+        <details className="rounded-xl border p-4" data-test="layout-picker">
100
+            <summary className="flex cursor-pointer list-none items-start gap-3 [&::-webkit-details-marker]:hidden">
101
+                <LayoutTemplate className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
102
+                <div>
103
+                    <h3 className="font-medium">Layouts</h3>
104
+                    <p className="mt-0.5 text-sm text-muted-foreground">
105
+                        How each part of your store is arranged. Open to change
106
+                        one.
107
+                    </p>
108
+                </div>
109
+            </summary>
110
+
111
+            <ul className="mt-4 divide-y">
112
+                {sections.map((section) => {
113
+                    const id = `layout-${section.section_id}`;
114
+                    const names = layoutNames[section.type] ?? {};
115
+
116
+                    return (
117
+                        <li
118
+                            key={section.section_id}
119
+                            className="grid gap-2 py-3 sm:grid-cols-[1fr_220px] sm:items-center"
120
+                        >
121
+                            <label htmlFor={id} className="min-w-0 text-sm">
122
+                                <span className="font-medium">
123
+                                    {typeNames[section.type] ?? section.type}
124
+                                </span>
125
+                                {section.label &&
126
+                                    !['header', 'footer'].includes(
127
+                                        section.type,
128
+                                    ) && (
129
+                                        <span className="text-muted-foreground">
130
+                                            {' '}
131
+                                            · “{section.label}”
132
+                                        </span>
133
+                                    )}
134
+                                {section.page_id &&
135
+                                    section.page_id !== 'home' && (
136
+                                        <span className="text-muted-foreground">
137
+                                            {' '}
138
+                                            on {section.page_title}
139
+                                        </span>
140
+                                    )}
141
+                            </label>
142
+                            <select
143
+                                id={id}
144
+                                value={section.variant}
145
+                                disabled={busy || saving === section.section_id}
146
+                                onChange={(event) =>
147
+                                    choose(section, event.target.value)
148
+                                }
149
+                                className={fieldClass}
150
+                            >
151
+                                {(options[section.type] ?? []).map(
152
+                                    (variant) => (
153
+                                        <option key={variant} value={variant}>
154
+                                            {names[variant] ?? variant}
155
+                                        </option>
156
+                                    ),
157
+                                )}
158
+                            </select>
159
+                        </li>
160
+                    );
161
+                })}
162
+            </ul>
163
+        </details>
164
+    );
165
+}

+ 14
- 0
resources/js/pages/stores/show.tsx Просмотреть файл

@@ -13,6 +13,7 @@ import StoreGenerationController from '@/actions/App/Http/Controllers/StoreGener
13 13
 import DesignChat from '@/components/stores/design-chat';
14 14
 import FeaturedPicker from '@/components/stores/featured-picker';
15 15
 import HeroPicker from '@/components/stores/hero-picker';
16
+import LayoutPicker from '@/components/stores/layout-picker';
16 17
 import StylePicker from '@/components/stores/style-picker';
17 18
 import DesignProgress from '@/components/stores/design-progress';
18 19
 import PublishPanel from '@/components/stores/publish-panel';
@@ -44,6 +45,7 @@ import type {
44 45
     FeaturedSection,
45 46
     HeroChoice,
46 47
     HeroSectionInfo,
48
+    LayoutSection,
47 49
     ProductOption,
48 50
     StoreStyleInfo,
49 51
     StylePreset,
@@ -65,6 +67,8 @@ type Props = {
65 67
     heroChoices: HeroChoice[];
66 68
     style: StoreStyleInfo | null;
67 69
     stylePresets: StylePreset[];
70
+    layoutSections: LayoutSection[];
71
+    layoutOptions: Record<string, string[]>;
68 72
 };
69 73
 
70 74
 export default function ShowStore({
@@ -78,6 +82,8 @@ export default function ShowStore({
78 82
     heroChoices,
79 83
     style,
80 84
     stylePresets,
85
+    layoutSections,
86
+    layoutOptions,
81 87
 }: Props) {
82 88
     const [device, setDevice] = useState<Device>('desktop');
83 89
     const [confirmOpen, setConfirmOpen] = useState(false);
@@ -109,6 +115,7 @@ export default function ShowStore({
109 115
                     'featuredSections',
110 116
                     'heroSections',
111 117
                     'style',
118
+                    'layoutSections',
112 119
                 ],
113 120
             });
114 121
         }, 2000);
@@ -310,6 +317,13 @@ export default function ShowStore({
310 317
                             busy={busy}
311 318
                         />
312 319
 
320
+                        <LayoutPicker
321
+                            store={store}
322
+                            sections={layoutSections}
323
+                            options={layoutOptions}
324
+                            busy={busy}
325
+                        />
326
+
313 327
                         <FeaturedPicker
314 328
                             store={store}
315 329
                             sections={featuredSections}

+ 46
- 0
resources/js/storefront/sections/about.tsx Просмотреть файл

@@ -1,3 +1,4 @@
1
+import { cn } from '@/lib/utils';
1 2
 import type { AboutSection } from '../types';
2 3
 import { Container } from '../ui';
3 4
 
@@ -5,6 +6,51 @@ export function About({ section }: { section: AboutSection }) {
5 6
     const { heading, body, stats } = section.content;
6 7
     const showStats = section.variant === 'with-stats' && stats.length > 0;
7 8
 
9
+    // statement: the story as one large statement, with the heading as a small label above it.
10
+    if (section.variant === 'statement') {
11
+        return (
12
+            <section
13
+                id={section.id}
14
+                className="sf-section scroll-mt-20 py-16 md:py-28"
15
+                data-layout="statement"
16
+            >
17
+                <Container className="max-w-5xl">
18
+                    <h2 className="text-xs font-semibold tracking-[0.18em] text-(--sf-primary) uppercase">
19
+                        {heading}
20
+                    </h2>
21
+                    <p
22
+                        className={cn(
23
+                            'sf-heading mt-6 leading-snug font-medium text-balance whitespace-pre-line',
24
+                            // A long story reads better a step smaller.
25
+                            body.length > 220
26
+                                ? 'text-xl sm:text-2xl md:text-3xl'
27
+                                : 'text-2xl sm:text-4xl md:text-5xl md:leading-[1.15]',
28
+                        )}
29
+                    >
30
+                        {body}
31
+                    </p>
32
+                    {stats.length > 0 && (
33
+                        <dl className="mt-12 flex flex-wrap gap-x-14 gap-y-6 border-t border-(--sf-border) pt-8">
34
+                            {stats.map((stat) => (
35
+                                <div
36
+                                    key={stat.label}
37
+                                    className="flex flex-col-reverse gap-1"
38
+                                >
39
+                                    <dt className="text-sm text-(--sf-muted)">
40
+                                        {stat.label}
41
+                                    </dt>
42
+                                    <dd className="sf-heading text-3xl font-semibold text-(--sf-primary)">
43
+                                        {stat.value}
44
+                                    </dd>
45
+                                </div>
46
+                            ))}
47
+                        </dl>
48
+                    )}
49
+                </Container>
50
+            </section>
51
+        );
52
+    }
53
+
8 54
     return (
9 55
         <section
10 56
             id={section.id}

+ 30
- 0
resources/js/storefront/sections/faq.tsx Просмотреть файл

@@ -7,6 +7,36 @@ export function Faq({ section }: { section: FaqSection }) {
7 7
     const { heading, items } = section.content;
8 8
     const twoColumn = section.variant === 'two-column';
9 9
 
10
+    // cards: every answer showing, in a grid of cards. Good for a few short questions.
11
+    if (section.variant === 'cards') {
12
+        return (
13
+            <section
14
+                id={section.id}
15
+                className="sf-section scroll-mt-20 py-16 md:py-20"
16
+                data-layout="cards"
17
+            >
18
+                <Container>
19
+                    <SectionHeading heading={heading} />
20
+                    <dl className="mt-10 grid gap-5 md:grid-cols-2">
21
+                        {items.map((item) => (
22
+                            <div
23
+                                key={item.question}
24
+                                className="sf-card rounded-(--sf-radius-card) border border-(--sf-border) p-6"
25
+                            >
26
+                                <dt className="font-semibold">
27
+                                    {item.question}
28
+                                </dt>
29
+                                <dd className="mt-2 leading-relaxed text-(--sf-muted)">
30
+                                    {item.answer}
31
+                                </dd>
32
+                            </div>
33
+                        ))}
34
+                    </dl>
35
+                </Container>
36
+            </section>
37
+        );
38
+    }
39
+
10 40
     return (
11 41
         <section
12 42
             id={section.id}

+ 30
- 4
resources/js/storefront/sections/featured-product.tsx Просмотреть файл

@@ -27,13 +27,23 @@ export function FeaturedProduct({
27 27
 
28 28
     const name = product?.name ?? section.content.name;
29 29
     const href = product ? `/products/${product.slug}` : cta.href;
30
+    // stacked: a wide photo on top, the words centred under it.
31
+    const stacked = section.variant === 'stacked';
30 32
 
31 33
     return (
32 34
         <section id={section.id} className="scroll-mt-20 bg-(--sf-surface)">
33
-            <Container className="sf-section grid items-center gap-10 py-16 md:grid-cols-2 md:py-20">
35
+            <Container
36
+                className={cn(
37
+                    'sf-section grid items-center gap-10 py-16 md:py-20',
38
+                    stacked
39
+                        ? 'justify-items-center text-center'
40
+                        : 'md:grid-cols-2',
41
+                )}
42
+            >
34 43
                 <div
35 44
                     className={cn(
36 45
                         'relative',
46
+                        stacked && 'w-full',
37 47
                         section.variant === 'image-right' && 'md:order-last',
38 48
                     )}
39 49
                 >
@@ -41,7 +51,12 @@ export function FeaturedProduct({
41 51
                         src={product?.image ?? null}
42 52
                         alt={name}
43 53
                         seed={2}
44
-                        className="aspect-square w-full"
54
+                        className={cn(
55
+                            'w-full',
56
+                            stacked
57
+                                ? 'aspect-[4/3] md:aspect-[21/9]'
58
+                                : 'aspect-square',
59
+                        )}
45 60
                     />
46 61
                     {product && !product.in_stock && (
47 62
                         <span className="absolute top-3 left-3 rounded-(--sf-radius) bg-(--sf-fg) px-2.5 py-1 text-xs font-semibold text-(--sf-bg)">
@@ -50,7 +65,11 @@ export function FeaturedProduct({
50 65
                     )}
51 66
                 </div>
52 67
 
53
-                <div>
68
+                <div
69
+                    className={cn(
70
+                        stacked && 'flex max-w-2xl flex-col items-center',
71
+                    )}
72
+                >
54 73
                     {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
55 74
                     <h2 className="sf-heading mt-3 text-3xl leading-tight font-semibold sm:text-4xl">
56 75
                         {name}
@@ -83,7 +102,14 @@ export function FeaturedProduct({
83 102
                     </p>
84 103
 
85 104
                     {bullets.length > 0 && (
86
-                        <ul className="mt-6 space-y-2.5 text-sm">
105
+                        <ul
106
+                            className={cn(
107
+                                'mt-6 text-sm',
108
+                                stacked
109
+                                    ? 'flex flex-wrap justify-center gap-x-6 gap-y-2.5'
110
+                                    : 'space-y-2.5',
111
+                            )}
112
+                        >
87 113
                             {bullets.map((bullet) => (
88 114
                                 <li key={bullet} className="flex gap-2.5">
89 115
                                     <Check

+ 79
- 0
resources/js/storefront/sections/footer.tsx Просмотреть файл

@@ -1,6 +1,9 @@
1 1
 import { cn } from '@/lib/utils';
2
+import { useStorefront } from '../context';
3
+import { storefrontText } from '../text';
2 4
 import type { FooterSection } from '../types';
3 5
 import { Container, SfLink } from '../ui';
6
+import { whatsappLink } from '../whatsapp';
4 7
 
5 8
 export function Footer({
6 9
     section,
@@ -9,6 +12,82 @@ export function Footer({
9 12
 }) {
10 13
     const { text, links } = section.content;
11 14
     const centered = section.variant === 'centered';
15
+    const { storeName, shop, language } = useStorefront();
16
+    const t = storefrontText(language);
17
+
18
+    // columns: a fuller footer with the store name, its links, and help links.
19
+    if (section.variant === 'columns') {
20
+        return (
21
+            <footer
22
+                className="border-t border-(--sf-border) bg-(--sf-surface)"
23
+                data-layout="columns"
24
+            >
25
+                <Container className="grid gap-10 py-14 text-sm sm:grid-cols-2 md:grid-cols-[2fr_1fr_1fr]">
26
+                    <div>
27
+                        <p className="sf-heading text-2xl font-semibold">
28
+                            {storeName}
29
+                        </p>
30
+                        <p className="mt-3 max-w-sm text-(--sf-muted)">
31
+                            {text}
32
+                        </p>
33
+                    </div>
34
+                    {links.length > 0 && (
35
+                        <nav aria-label="Footer">
36
+                            <p className="font-semibold">{t.footerExplore}</p>
37
+                            <ul className="mt-3 space-y-2 text-(--sf-muted)">
38
+                                {links.map((link) => (
39
+                                    <li key={link.label + link.href}>
40
+                                        <SfLink
41
+                                            href={link.href}
42
+                                            className="transition-colors hover:text-(--sf-fg)"
43
+                                        >
44
+                                            {link.label}
45
+                                        </SfLink>
46
+                                    </li>
47
+                                ))}
48
+                            </ul>
49
+                        </nav>
50
+                    )}
51
+                    <div>
52
+                        <p className="font-semibold">{t.footerHelp}</p>
53
+                        <ul className="mt-3 space-y-2 text-(--sf-muted)">
54
+                            <li>
55
+                                <SfLink
56
+                                    href="/shop"
57
+                                    className="transition-colors hover:text-(--sf-fg)"
58
+                                >
59
+                                    {t.allProducts}
60
+                                </SfLink>
61
+                            </li>
62
+                            <li>
63
+                                <SfLink
64
+                                    href="/cart"
65
+                                    className="transition-colors hover:text-(--sf-fg)"
66
+                                >
67
+                                    {t.cart}
68
+                                </SfLink>
69
+                            </li>
70
+                            {shop.whatsapp && (
71
+                                <li>
72
+                                    <a
73
+                                        href={whatsappLink(
74
+                                            shop.whatsapp,
75
+                                            t.whatsAppHello(storeName),
76
+                                        )}
77
+                                        target="_blank"
78
+                                        rel="noreferrer"
79
+                                        className="transition-colors hover:text-(--sf-fg)"
80
+                                    >
81
+                                        {t.chatOnWhatsApp}
82
+                                    </a>
83
+                                </li>
84
+                            )}
85
+                        </ul>
86
+                    </div>
87
+                </Container>
88
+            </footer>
89
+        );
90
+    }
12 91
 
13 92
     return (
14 93
         <footer className="border-t border-(--sf-border)">

+ 47
- 0
resources/js/storefront/sections/newsletter.tsx Просмотреть файл

@@ -6,6 +6,53 @@ export function Newsletter({ section }: { section: NewsletterSection }) {
6 6
     const { heading, body, placeholder, buttonLabel } = section.content;
7 7
     const card = section.variant === 'card';
8 8
 
9
+    // split: a big heading on one side, the form on the other, in the store's normal colours.
10
+    if (section.variant === 'split') {
11
+        return (
12
+            <section
13
+                id={section.id}
14
+                className="sf-section scroll-mt-20 border-y border-(--sf-border) py-16 md:py-20"
15
+                data-layout="split"
16
+            >
17
+                <Container className="grid gap-8 md:grid-cols-2 md:items-end">
18
+                    <div>
19
+                        <h2 className="sf-heading text-3xl leading-tight font-semibold text-balance sm:text-4xl">
20
+                            {heading}
21
+                        </h2>
22
+                        {body && (
23
+                            <p className="mt-3 max-w-md text-(--sf-muted)">
24
+                                {body}
25
+                            </p>
26
+                        )}
27
+                    </div>
28
+                    <form
29
+                        className="flex w-full gap-2 md:justify-self-end"
30
+                        onSubmit={(event) => event.preventDefault()}
31
+                    >
32
+                        <label
33
+                            className="sr-only"
34
+                            htmlFor={`${section.id}-email`}
35
+                        >
36
+                            {placeholder}
37
+                        </label>
38
+                        <input
39
+                            id={`${section.id}-email`}
40
+                            type="email"
41
+                            placeholder={placeholder}
42
+                            className="min-w-0 flex-1 rounded-(--sf-radius) border border-(--sf-border) bg-(--sf-bg) px-4 py-3 text-sm placeholder:text-(--sf-muted) focus-visible:outline-2 focus-visible:outline-(--sf-primary)"
43
+                        />
44
+                        <button
45
+                            type="submit"
46
+                            className="sf-btn-primary rounded-(--sf-radius) bg-(--sf-primary) px-5 py-3 text-sm font-semibold text-(--sf-primary-fg) transition-opacity hover:opacity-90"
47
+                        >
48
+                            {buttonLabel}
49
+                        </button>
50
+                    </form>
51
+                </Container>
52
+            </section>
53
+        );
54
+    }
55
+
9 56
     return (
10 57
         <section
11 58
             id={section.id}

+ 183
- 56
resources/js/storefront/sections/product-grid.tsx Просмотреть файл

@@ -1,3 +1,7 @@
1
+import { ChevronLeft, ChevronRight } from 'lucide-react';
2
+import type { ReactNode } from 'react';
3
+import { useRef } from 'react';
4
+import { cn } from '@/lib/utils';
1 5
 import { useStorefront } from '../context';
2 6
 import { ProductCard } from '../product-card';
3 7
 import { storefrontText } from '../text';
@@ -8,16 +12,35 @@ import { Container, ImagePlaceholder, SectionHeading, SfButton } from '../ui';
8 12
 /** How many real products the home page shows before "View all". */
9 13
 const maxShown = 8;
10 14
 
15
+/** The large layout shows fewer, bigger products. */
16
+const maxLarge = 4;
17
+
11 18
 /**
12 19
  * Shows the merchant's real products when there are any.
13 20
  * Until then it shows the example items the AI wrote, so a new store never looks empty.
21
+ *
22
+ * Layouts: grid (4 across), minimal (centred), carousel (one row that scrolls sideways)
23
+ * and large (2 big cards across, like a magazine).
14 24
  */
15 25
 export function ProductGrid({ section }: { section: ProductGridSection }) {
16
-    const { heading, subheading, items } = section.content;
17
-    const minimal = section.variant === 'minimal';
26
+    const { heading, subheading } = section.content;
27
+    const variant = section.variant;
28
+    const centered = variant === 'minimal';
18 29
     const { products, language } = useStorefront();
19 30
     const t = storefrontText(language);
20 31
     const hasProducts = products.length > 0;
32
+    const cards = useCards(section, centered);
33
+    const shown = variant === 'large' ? cards.slice(0, maxLarge) : cards;
34
+
35
+    const viewAll = hasProducts && (
36
+        <SfButton href="/shop" variant="outline">
37
+            {t.viewAll}
38
+        </SfButton>
39
+    );
40
+
41
+    if (variant === 'carousel') {
42
+        return <Carousel section={section} cards={shown} viewAll={viewAll} />;
43
+    }
21 44
 
22 45
     return (
23 46
         <section
@@ -27,7 +50,7 @@ export function ProductGrid({ section }: { section: ProductGridSection }) {
27 50
             <Container>
28 51
                 <div
29 52
                     className={
30
-                        minimal
53
+                        centered
31 54
                             ? ''
32 55
                             : 'flex flex-wrap items-end justify-between gap-4'
33 56
                     }
@@ -35,66 +58,170 @@ export function ProductGrid({ section }: { section: ProductGridSection }) {
35 58
                     <SectionHeading
36 59
                         heading={heading}
37 60
                         subheading={subheading}
38
-                        align={minimal ? 'center' : 'left'}
61
+                        align={centered ? 'center' : 'left'}
39 62
                     />
40
-                    {hasProducts && !minimal && (
41
-                        <SfButton href="/shop" variant="outline">
42
-                            {t.viewAll}
43
-                        </SfButton>
44
-                    )}
63
+                    {!centered && viewAll}
45 64
                 </div>
46 65
 
47
-                <ul className="mt-10 grid grid-cols-2 gap-x-5 gap-y-9 lg:grid-cols-4">
48
-                    {hasProducts
49
-                        ? products.slice(0, maxShown).map((product, index) => (
50
-                              <li key={product.id}>
51
-                                  <ProductCard
52
-                                      product={product}
53
-                                      seed={index}
54
-                                      centered={minimal}
55
-                                  />
56
-                              </li>
57
-                          ))
58
-                        : items.map((item, index) => (
59
-                              <li key={item.name + index}>
60
-                                  <div className="relative">
61
-                                      <ImagePlaceholder
62
-                                          seed={index}
63
-                                          label={item.name}
64
-                                          className="aspect-[4/5] w-full"
65
-                                      />
66
-                                      {item.badge && (
67
-                                          <span className="absolute top-3 left-3 rounded-(--sf-radius) bg-(--sf-fg) px-2.5 py-1 text-xs font-semibold text-(--sf-bg)">
68
-                                              {item.badge}
69
-                                          </span>
70
-                                      )}
71
-                                  </div>
72
-                                  <div
73
-                                      className={
74
-                                          minimal
75
-                                              ? 'mt-4 text-center'
76
-                                              : 'mt-4 flex flex-col gap-1 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3'
77
-                                      }
78
-                                  >
79
-                                      <h3 className="font-medium">
80
-                                          {item.name}
81
-                                      </h3>
82
-                                      <p className="text-sm text-(--sf-muted) tabular-nums">
83
-                                          {formatPrice(item.price)}
84
-                                      </p>
85
-                                  </div>
86
-                              </li>
87
-                          ))}
66
+                <ul
67
+                    className={cn(
68
+                        'mt-10 grid',
69
+                        variant === 'large'
70
+                            ? 'grid-cols-1 gap-x-8 gap-y-12 sm:grid-cols-2'
71
+                            : 'grid-cols-2 gap-x-5 gap-y-9 lg:grid-cols-4',
72
+                    )}
73
+                >
74
+                    {shown.map((card) => (
75
+                        <li key={card.key}>{card.node}</li>
76
+                    ))}
88 77
                 </ul>
89 78
 
90
-                {hasProducts && minimal && (
91
-                    <div className="mt-10 text-center">
92
-                        <SfButton href="/shop" variant="outline">
93
-                            {t.viewAll}
94
-                        </SfButton>
95
-                    </div>
79
+                {centered && viewAll && (
80
+                    <div className="mt-10 text-center">{viewAll}</div>
96 81
                 )}
97 82
             </Container>
98 83
         </section>
99 84
     );
100 85
 }
86
+
87
+/** One row of products that scrolls sideways, with arrows on wide screens. */
88
+function Carousel({
89
+    section,
90
+    cards,
91
+    viewAll,
92
+}: {
93
+    section: ProductGridSection;
94
+    cards: { key: string; node: ReactNode }[];
95
+    viewAll: ReactNode;
96
+}) {
97
+    const { language } = useStorefront();
98
+    const t = storefrontText(language);
99
+    const row = useRef<HTMLUListElement>(null);
100
+
101
+    function scroll(direction: 1 | -1) {
102
+        const list = row.current;
103
+
104
+        if (list) {
105
+            list.scrollBy({
106
+                left: direction * list.clientWidth * 0.8,
107
+                behavior: window.matchMedia('(prefers-reduced-motion: reduce)')
108
+                    .matches
109
+                    ? 'auto'
110
+                    : 'smooth',
111
+            });
112
+        }
113
+    }
114
+
115
+    const arrow =
116
+        'hidden size-10 items-center justify-center rounded-full border border-(--sf-border) text-(--sf-fg) transition-colors hover:bg-(--sf-surface) md:inline-flex';
117
+
118
+    return (
119
+        <section
120
+            id={section.id}
121
+            className="sf-section scroll-mt-20 py-16 md:py-20"
122
+            data-layout="carousel"
123
+        >
124
+            <Container>
125
+                <div className="flex flex-wrap items-end justify-between gap-4">
126
+                    <SectionHeading
127
+                        heading={section.content.heading}
128
+                        subheading={section.content.subheading}
129
+                    />
130
+                    <div className="flex items-center gap-2">
131
+                        {viewAll}
132
+                        <button
133
+                            type="button"
134
+                            onClick={() => scroll(-1)}
135
+                            aria-label={t.previousProducts}
136
+                            className={arrow}
137
+                        >
138
+                            <ChevronLeft
139
+                                className="size-5"
140
+                                aria-hidden="true"
141
+                            />
142
+                        </button>
143
+                        <button
144
+                            type="button"
145
+                            onClick={() => scroll(1)}
146
+                            aria-label={t.nextProducts}
147
+                            className={arrow}
148
+                        >
149
+                            <ChevronRight
150
+                                className="size-5"
151
+                                aria-hidden="true"
152
+                            />
153
+                        </button>
154
+                    </div>
155
+                </div>
156
+
157
+                <ul
158
+                    ref={row}
159
+                    className="-mx-5 mt-10 flex snap-x snap-mandatory scroll-px-5 gap-5 overflow-x-auto px-5 pb-4 sm:-mx-8 sm:scroll-px-8 sm:px-8 [&::-webkit-scrollbar]:hidden"
160
+                    style={{ scrollbarWidth: 'none' }}
161
+                >
162
+                    {cards.map((card) => (
163
+                        <li
164
+                            key={card.key}
165
+                            className="w-[70%] shrink-0 snap-start sm:w-[40%] lg:w-[calc(25%-15px)]"
166
+                        >
167
+                            {card.node}
168
+                        </li>
169
+                    ))}
170
+                </ul>
171
+            </Container>
172
+        </section>
173
+    );
174
+}
175
+
176
+/** The real products as cards, or the AI's example items until the merchant adds products. */
177
+function useCards(
178
+    section: ProductGridSection,
179
+    centered: boolean,
180
+): { key: string; node: ReactNode }[] {
181
+    const { products } = useStorefront();
182
+
183
+    if (products.length > 0) {
184
+        return products.slice(0, maxShown).map((product, index) => ({
185
+            key: `p${product.id}`,
186
+            node: (
187
+                <ProductCard
188
+                    product={product}
189
+                    seed={index}
190
+                    centered={centered}
191
+                />
192
+            ),
193
+        }));
194
+    }
195
+
196
+    return section.content.items.map((item, index) => ({
197
+        key: `i${index}${item.name}`,
198
+        node: (
199
+            <>
200
+                <div className="relative">
201
+                    <ImagePlaceholder
202
+                        seed={index}
203
+                        label={item.name}
204
+                        className="aspect-[4/5] w-full"
205
+                    />
206
+                    {item.badge && (
207
+                        <span className="absolute top-3 left-3 rounded-(--sf-radius) bg-(--sf-fg) px-2.5 py-1 text-xs font-semibold text-(--sf-bg)">
208
+                            {item.badge}
209
+                        </span>
210
+                    )}
211
+                </div>
212
+                <div
213
+                    className={
214
+                        centered
215
+                            ? 'mt-4 text-center'
216
+                            : 'mt-4 flex flex-col gap-1 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3'
217
+                    }
218
+                >
219
+                    <h3 className="font-medium">{item.name}</h3>
220
+                    <p className="text-sm text-(--sf-muted) tabular-nums">
221
+                        {formatPrice(item.price)}
222
+                    </p>
223
+                </div>
224
+            </>
225
+        ),
226
+    }));
227
+}

+ 18
- 3
resources/js/storefront/sections/testimonials.tsx Просмотреть файл

@@ -1,3 +1,4 @@
1
+import { cn } from '@/lib/utils';
1 2
 import type { TestimonialsSection } from '../types';
2 3
 import { Container, SectionHeading } from '../ui';
3 4
 
@@ -28,18 +29,32 @@ export function Testimonials({ section }: { section: TestimonialsSection }) {
28 29
         );
29 30
     }
30 31
 
32
+    // wall: cards of different heights packed in columns, like notes on a board.
33
+    const wall = section.variant === 'wall';
34
+
31 35
     return (
32 36
         <section
33 37
             id={section.id}
34 38
             className="sf-section scroll-mt-20 bg-(--sf-surface) py-16 md:py-20"
39
+            data-layout={section.variant}
35 40
         >
36 41
             <Container>
37 42
                 <SectionHeading heading={heading} />
38
-                <ul className="mt-10 grid gap-5 md:grid-cols-3">
39
-                    {items.map((item) => (
43
+                <ul
44
+                    className={
45
+                        wall
46
+                            ? 'mt-10 columns-1 gap-5 sm:columns-2 lg:columns-3'
47
+                            : 'mt-10 grid gap-5 md:grid-cols-3'
48
+                    }
49
+                >
50
+                    {items.map((item, index) => (
40 51
                         <li
41 52
                             key={item.name + item.quote}
42
-                            className="sf-card flex flex-col justify-between gap-6 rounded-(--sf-radius-card) border border-(--sf-border) bg-(--sf-bg) p-6"
53
+                            className={cn(
54
+                                'sf-card flex flex-col justify-between gap-6 rounded-(--sf-radius-card) border border-(--sf-border) bg-(--sf-bg) p-6',
55
+                                wall && 'mb-5 break-inside-avoid',
56
+                                wall && index % 3 === 0 && 'sf-heading text-lg',
57
+                            )}
43 58
                         >
44 59
                             <blockquote className="leading-relaxed">
45 60
                                 “{item.quote}”

+ 8
- 0
resources/js/storefront/text.ts Просмотреть файл

@@ -23,6 +23,10 @@ const words = {
23 23
         trustWhatsApp: 'Questions? Ask us',
24 24
         trustWhatsAppText: 'Quick replies on WhatsApp',
25 25
         pairsWellWith: 'Pairs well with',
26
+        previousProducts: 'Previous products',
27
+        nextProducts: 'More products',
28
+        footerExplore: 'Explore',
29
+        footerHelp: 'Shop and help',
26 30
         openMenu: 'Open menu',
27 31
         closeMenu: 'Close menu',
28 32
         chooseShort: 'Choose an option',
@@ -126,6 +130,10 @@ const words = {
126 130
         trustWhatsApp: 'Ada soalan? Tanya kami',
127 131
         trustWhatsAppText: 'Balasan pantas di WhatsApp',
128 132
         pairsWellWith: 'Sesuai digandingkan dengan',
133
+        previousProducts: 'Produk sebelum',
134
+        nextProducts: 'Lagi produk',
135
+        footerExplore: 'Terokai',
136
+        footerHelp: 'Beli-belah dan bantuan',
129 137
         openMenu: 'Buka menu',
130 138
         closeMenu: 'Tutup menu',
131 139
         chooseShort: 'Pilih pilihan',

+ 7
- 7
resources/js/storefront/types.ts Просмотреть файл

@@ -70,7 +70,7 @@ export type HeroImageSet = {
70 70
 
71 71
 export type ProductGridSection = SectionOf<
72 72
     'product_grid',
73
-    'grid' | 'minimal',
73
+    'grid' | 'minimal' | 'carousel' | 'large',
74 74
     {
75 75
         heading: string;
76 76
         subheading?: string | null;
@@ -80,7 +80,7 @@ export type ProductGridSection = SectionOf<
80 80
 
81 81
 export type FeaturedProductSection = SectionOf<
82 82
     'featured_product',
83
-    'image-left' | 'image-right',
83
+    'image-left' | 'image-right' | 'stacked',
84 84
     {
85 85
         eyebrow?: string | null;
86 86
         name: string;
@@ -95,7 +95,7 @@ export type FeaturedProductSection = SectionOf<
95 95
 
96 96
 export type AboutSection = SectionOf<
97 97
     'about',
98
-    'simple' | 'with-stats',
98
+    'simple' | 'with-stats' | 'statement',
99 99
     {
100 100
         heading: string;
101 101
         body: string;
@@ -105,7 +105,7 @@ export type AboutSection = SectionOf<
105 105
 
106 106
 export type TestimonialsSection = SectionOf<
107 107
     'testimonials',
108
-    'cards' | 'single',
108
+    'cards' | 'single' | 'wall',
109 109
     {
110 110
         heading: string;
111 111
         items: { quote: string; name: string; role?: string | null }[];
@@ -114,13 +114,13 @@ export type TestimonialsSection = SectionOf<
114 114
 
115 115
 export type FaqSection = SectionOf<
116 116
     'faq',
117
-    'list' | 'two-column',
117
+    'list' | 'two-column' | 'cards',
118 118
     { heading: string; items: { question: string; answer: string }[] }
119 119
 >;
120 120
 
121 121
 export type NewsletterSection = SectionOf<
122 122
     'newsletter',
123
-    'banner' | 'card',
123
+    'banner' | 'card' | 'split',
124 124
     {
125 125
         heading: string;
126 126
         body?: string | null;
@@ -144,7 +144,7 @@ export type ContactSection = SectionOf<
144 144
 
145 145
 export type FooterSection = SectionOf<
146 146
     'footer',
147
-    'simple' | 'centered',
147
+    'simple' | 'centered' | 'columns',
148 148
     { text: string; links: PlanLink[] }
149 149
 >;
150 150
 

+ 10
- 0
resources/js/types/store.ts Просмотреть файл

@@ -189,6 +189,16 @@ export type StoreStyleInfo = {
189 189
     fonts: { heading: string; body: string } | null;
190 190
 };
191 191
 
192
+/** One section's layout, for the Design tab's Layouts box. Header and footer have no page. */
193
+export type LayoutSection = {
194
+    page_id: string | null;
195
+    page_title: string | null;
196
+    section_id: string;
197
+    type: string;
198
+    variant: string;
199
+    label: string;
200
+};
201
+
192 202
 /** A ready-made look in the Design tab's Style box. */
193 203
 export type StylePreset = {
194 204
     key: string;

+ 2
- 0
routes/web.php Просмотреть файл

@@ -9,6 +9,7 @@ use App\Http\Controllers\FeaturedProductController;
9 9
 use App\Http\Controllers\HeroImageController;
10 10
 use App\Http\Controllers\OrderController;
11 11
 use App\Http\Controllers\ProductController;
12
+use App\Http\Controllers\SectionLayoutController;
12 13
 use App\Http\Controllers\StoreController;
13 14
 use App\Http\Controllers\StoreDesignController;
14 15
 use App\Http\Controllers\StoreGenerationController;
@@ -115,6 +116,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
115 116
     Route::put('stores/{slug}/featured/{sectionId}', [FeaturedProductController::class, 'update'])->name('stores.featured.update');
116 117
     Route::put('stores/{slug}/hero/{sectionId}', [HeroImageController::class, 'update'])->name('stores.hero.update');
117 118
     Route::put('stores/{slug}/style', [StoreStyleController::class, 'update'])->name('stores.style.update');
119
+    Route::put('stores/{slug}/layouts/{sectionId}', [SectionLayoutController::class, 'update'])->name('stores.layouts.update');
118 120
     Route::post('stores/{slug}/hero/{sectionId}/photo', [HeroImageController::class, 'upload'])->name('stores.hero.upload');
119 121
     Route::get('stores/{slug}/settings', [StoreSettingsController::class, 'edit'])->name('stores.settings');
120 122
     Route::put('stores/{slug}/settings', [StoreSettingsController::class, 'update'])->name('stores.settings.update');

+ 120
- 0
tests/Feature/Stores/SectionLayoutTest.php Просмотреть файл

@@ -0,0 +1,120 @@
1
+<?php
2
+
3
+namespace Tests\Feature\Stores;
4
+
5
+use App\Models\Store;
6
+use App\Models\User;
7
+use App\StorePlan\Ai\PlanPrompt;
8
+use App\StorePlan\PlanSchema;
9
+use App\StorePlan\PlanValidator;
10
+use App\StorePlan\SamplePlan;
11
+use App\StorePlan\SectionLayouts;
12
+use Illuminate\Foundation\Testing\RefreshDatabase;
13
+use Inertia\Testing\AssertableInertia as Assert;
14
+use Tests\Support\ScriptedDriver;
15
+use Tests\TestCase;
16
+
17
+class SectionLayoutTest extends TestCase
18
+{
19
+    use RefreshDatabase;
20
+
21
+    private User $user;
22
+
23
+    private Store $store;
24
+
25
+    protected function setUp(): void
26
+    {
27
+        parent::setUp();
28
+
29
+        $this->user = User::factory()->create();
30
+        $this->store = Store::factory()->for($this->user)->create();
31
+        $this->store->plan = SamplePlan::for($this->store);
32
+        $this->store->save();
33
+        $this->actingAs($this->user);
34
+    }
35
+
36
+    private function variantOf(string $sectionId): ?string
37
+    {
38
+        $plan = $this->store->fresh()->plan;
39
+
40
+        if (in_array($sectionId, ['header', 'footer'], true)) {
41
+            return $plan[$sectionId]['variant'];
42
+        }
43
+
44
+        foreach ($plan['pages'][0]['sections'] as $section) {
45
+            if ($section['id'] === $sectionId) {
46
+                return $section['variant'];
47
+            }
48
+        }
49
+
50
+        return null;
51
+    }
52
+
53
+    public function test_every_layout_of_every_section_in_the_sample_passes_the_checker()
54
+    {
55
+        $validator = app(PlanValidator::class);
56
+        $plan = $this->store->plan;
57
+
58
+        foreach (SectionLayouts::sections($plan) as $section) {
59
+            foreach (PlanSchema::SECTIONS[$section['type']] as $variant) {
60
+                $this->assertTrue(
61
+                    $validator->passes(SectionLayouts::update($plan, $section['section_id'], $variant)),
62
+                    "{$section['type']} / $variant",
63
+                );
64
+            }
65
+        }
66
+
67
+        // The main sections now have at least 3 layouts each.
68
+        foreach (['hero', 'product_grid', 'featured_product', 'about', 'testimonials', 'faq', 'newsletter', 'footer'] as $type) {
69
+            $this->assertGreaterThanOrEqual(3, count(PlanSchema::SECTIONS[$type]), $type);
70
+        }
71
+    }
72
+
73
+    public function test_the_design_tab_lists_sections_and_changes_a_layout()
74
+    {
75
+        $this->get(route('stores.show', $this->store->slug))
76
+            ->assertInertia(fn (Assert $page) => $page
77
+                ->where('layoutSections.0.section_id', 'header')
78
+                ->where('layoutSections.1.type', 'trust_bar')
79
+                ->where('layoutOptions.product_grid', ['grid', 'minimal', 'carousel', 'large']));
80
+
81
+        $this->put(route('stores.layouts.update', [$this->store->slug, 'products']), ['variant' => 'carousel'])
82
+            ->assertRedirect(route('stores.show', $this->store->slug));
83
+        $this->put(route('stores.layouts.update', [$this->store->slug, 'footer']), ['variant' => 'columns'])->assertSessionHasNoErrors();
84
+        $this->put(route('stores.layouts.update', [$this->store->slug, 'header']), ['variant' => 'centered'])->assertSessionHasNoErrors();
85
+
86
+        $this->assertSame('carousel', $this->variantOf('products'));
87
+        $this->assertSame('columns', $this->variantOf('footer'));
88
+        $this->assertSame('centered', $this->variantOf('header'));
89
+    }
90
+
91
+    public function test_only_real_layouts_and_sections_are_accepted()
92
+    {
93
+        // A layout of another section type, or a made-up one.
94
+        $this->put(route('stores.layouts.update', [$this->store->slug, 'products']), ['variant' => 'stacked'])->assertSessionHasErrors('variant');
95
+        $this->put(route('stores.layouts.update', [$this->store->slug, 'products']), ['variant' => 'spiral'])->assertSessionHasErrors('variant');
96
+        // Heroes have their own box; unknown sections are not found.
97
+        $this->put(route('stores.layouts.update', [$this->store->slug, 'hero']), ['variant' => 'split'])->assertNotFound();
98
+        $this->put(route('stores.layouts.update', [$this->store->slug, 'nothing-here']), ['variant' => 'grid'])->assertNotFound();
99
+
100
+        $this->actingAs(User::factory()->create())
101
+            ->put(route('stores.layouts.update', [$this->store->slug, 'products']), ['variant' => 'large'])
102
+            ->assertNotFound();
103
+
104
+        $this->assertSame('grid', $this->variantOf('products'));
105
+    }
106
+
107
+    public function test_the_ai_knows_the_new_layouts_and_can_switch_to_them()
108
+    {
109
+        ScriptedDriver::use([(string) json_encode([
110
+            'reply' => 'Your products now slide in one row.',
111
+            'update' => [['id' => 'products', 'variant' => 'carousel']],
112
+        ])]);
113
+
114
+        $this->post(route('stores.edits', $this->store->slug), ['instruction' => 'Make the products slide sideways']);
115
+
116
+        $this->assertSame('carousel', $this->variantOf('products'));
117
+        $this->assertStringContainsString('variants: grid, minimal, carousel, large', ScriptedDriver::$requests[0]->system);
118
+        $this->assertStringContainsString('Layouts to know', PlanPrompt::generateSystem());
119
+    }
120
+}

Загрузка…
Отмена
Сохранить