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

renderer.tsx 3.9KB

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