AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

layout-picker.tsx 6.1KB

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