AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

layout-picker.tsx 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { router } from '@inertiajs/react';
  2. import { useState } from 'react';
  3. import SectionLayoutController from '@/actions/App/Http/Controllers/SectionLayoutController';
  4. import { SectionName } from '@/components/stores/preview-highlight';
  5. import { typeNames } from '@/components/stores/section-names';
  6. import type { LayoutSection, Store } from '@/types';
  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. const layoutNames: Record<string, Record<string, string>> = {
  10. header: { simple: 'Logo on the left', centered: 'Logo in the middle' },
  11. trust_bar: { row: 'Icon row', boxed: 'Small cards' },
  12. shop_by: { circles: 'Round photos', tiles: 'Photo tiles' },
  13. bento: { mosaic: 'One big tile and smaller ones', even: 'Equal tiles' },
  14. video: { wide: 'Wide video', split: 'Words beside the video' },
  15. product_grid: {
  16. grid: 'Grid',
  17. minimal: 'Centred grid',
  18. carousel: 'Sliding row',
  19. large: 'Large cards',
  20. },
  21. featured_product: {
  22. 'image-left': 'Photo on the left',
  23. 'image-right': 'Photo on the right',
  24. stacked: 'Wide photo on top',
  25. },
  26. about: {
  27. simple: 'Centred text',
  28. 'with-stats': 'Text with numbers',
  29. statement: 'One big statement',
  30. },
  31. testimonials: {
  32. cards: 'Cards',
  33. single: 'One big quote',
  34. wall: 'Wall of quotes',
  35. },
  36. faq: {
  37. list: 'Fold-open list',
  38. 'two-column': 'Two columns',
  39. cards: 'All answers in cards',
  40. },
  41. newsletter: {
  42. banner: 'Colour banner',
  43. card: 'Colour card',
  44. split: 'Heading beside the form',
  45. },
  46. contact: { simple: 'Simple', card: 'Card' },
  47. footer: { simple: 'One line', centered: 'Centred', columns: 'Columns' },
  48. };
  49. /**
  50. * The Design tab's Layouts box: the layout of every section, header and footer included.
  51. * Heroes have their own box.
  52. */
  53. export default function LayoutPicker({
  54. store,
  55. sections,
  56. options,
  57. busy,
  58. }: {
  59. store: Store;
  60. sections: LayoutSection[];
  61. options: Record<string, string[]>;
  62. busy: boolean;
  63. }) {
  64. const [saving, setSaving] = useState<string | null>(null);
  65. if (sections.length === 0) {
  66. return null;
  67. }
  68. function choose(section: LayoutSection, variant: string) {
  69. router.put(
  70. SectionLayoutController.update.url({
  71. slug: store.slug,
  72. sectionId: section.section_id,
  73. }),
  74. { variant },
  75. {
  76. preserveScroll: true,
  77. onStart: () => setSaving(section.section_id),
  78. onFinish: () => setSaving(null),
  79. },
  80. );
  81. }
  82. return (
  83. <div data-test="layout-picker">
  84. <p className="text-sm text-muted-foreground">
  85. How each part of your store is arranged.
  86. </p>
  87. <ul className="mt-4 divide-y">
  88. {sections.map((section) => {
  89. const id = `layout-${section.section_id}`;
  90. const names = layoutNames[section.type] ?? {};
  91. return (
  92. <li
  93. key={section.section_id}
  94. className="grid gap-2 py-3 sm:grid-cols-[1fr_220px] sm:items-center"
  95. >
  96. <SectionName
  97. target={{
  98. sectionId: section.section_id,
  99. pageId: section.page_id,
  100. label:
  101. typeNames[section.type] ?? section.type,
  102. }}
  103. className="text-sm"
  104. >
  105. <span className="font-medium">
  106. {typeNames[section.type] ?? section.type}
  107. </span>
  108. {section.label &&
  109. !['header', 'footer'].includes(
  110. section.type,
  111. ) && (
  112. <span className="text-muted-foreground">
  113. {' '}
  114. · “{section.label}”
  115. </span>
  116. )}
  117. {section.page_id &&
  118. section.page_id !== 'home' && (
  119. <span className="text-muted-foreground">
  120. {' '}
  121. on {section.page_title}
  122. </span>
  123. )}
  124. </SectionName>
  125. <select
  126. id={id}
  127. aria-label={`Layout of ${typeNames[section.type] ?? section.type}`}
  128. value={section.variant}
  129. disabled={busy || saving === section.section_id}
  130. onChange={(event) =>
  131. choose(section, event.target.value)
  132. }
  133. className={fieldClass}
  134. >
  135. {(options[section.type] ?? []).map(
  136. (variant) => (
  137. <option key={variant} value={variant}>
  138. {names[variant] ?? variant}
  139. </option>
  140. ),
  141. )}
  142. </select>
  143. </li>
  144. );
  145. })}
  146. </ul>
  147. </div>
  148. );
  149. }