AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

renderer.tsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import type { ReactNode } from 'react';
  2. import { StorefrontProvider } from './context';
  3. import { ProductPage } from './pages/product';
  4. import { ShopPage } from './pages/shop';
  5. import { About } from './sections/about';
  6. import { Contact } from './sections/contact';
  7. import { Faq } from './sections/faq';
  8. import { FeaturedProduct } from './sections/featured-product';
  9. import { Footer } from './sections/footer';
  10. import { Header } from './sections/header';
  11. import { Hero } from './sections/hero';
  12. import { Newsletter } from './sections/newsletter';
  13. import { ProductGrid } from './sections/product-grid';
  14. import { Testimonials } from './sections/testimonials';
  15. import { themeStyle } from './theme';
  16. import type {
  17. FontMap,
  18. PlanSection,
  19. StorePlan,
  20. StoreProduct,
  21. StorefrontView,
  22. } from './types';
  23. /**
  24. * Draw one section. To add a new section type: add it to PlanSchema.php and
  25. * types.ts, write its component, and add one line here.
  26. */
  27. function Section({ section }: { section: PlanSection }) {
  28. switch (section.type) {
  29. case 'hero':
  30. return <Hero section={section} />;
  31. case 'product_grid':
  32. return <ProductGrid section={section} />;
  33. case 'featured_product':
  34. return <FeaturedProduct section={section} />;
  35. case 'about':
  36. return <About section={section} />;
  37. case 'testimonials':
  38. return <Testimonials section={section} />;
  39. case 'faq':
  40. return <Faq section={section} />;
  41. case 'newsletter':
  42. return <Newsletter section={section} />;
  43. case 'contact':
  44. return <Contact section={section} />;
  45. default:
  46. // A type this version of the app does not know. Skip it and keep the page working.
  47. return null;
  48. }
  49. }
  50. function PageBody({ plan, view }: { plan: StorePlan; view: StorefrontView }) {
  51. if (view.type === 'shop') {
  52. return <ShopPage />;
  53. }
  54. if (view.type === 'product') {
  55. return <ProductPage product={view.product} />;
  56. }
  57. const page =
  58. plan.pages.find((candidate) => candidate.id === view.pageId) ??
  59. plan.pages[0];
  60. return (
  61. <main>
  62. {page?.sections.map((section) => (
  63. <Section key={section.id} section={section} />
  64. ))}
  65. </main>
  66. );
  67. }
  68. /**
  69. * Turn a store plan into one storefront page: the shared header, the page itself, the shared footer.
  70. */
  71. export function StorefrontRenderer({
  72. plan,
  73. fonts,
  74. view,
  75. baseUrl,
  76. language,
  77. products,
  78. }: {
  79. plan: StorePlan;
  80. fonts: FontMap;
  81. view: StorefrontView;
  82. baseUrl: string;
  83. language: string;
  84. products: StoreProduct[];
  85. }): ReactNode {
  86. const isHome = view.type === 'page' && view.pageId === 'home';
  87. return (
  88. <StorefrontProvider value={{ baseUrl, isHome, language, products }}>
  89. <div
  90. className="sf-root flex min-h-screen flex-col"
  91. style={themeStyle(plan.theme, fonts)}
  92. >
  93. <Header section={plan.header} />
  94. <div className="flex-1">
  95. <PageBody plan={plan} view={view} />
  96. </div>
  97. <Footer section={plan.footer} />
  98. </div>
  99. </StorefrontProvider>
  100. );
  101. }