create-nymbal-app 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/index.js +14 -5
  3. package/dist/index.js.map +1 -1
  4. package/package.json +5 -4
  5. package/scaffold/project/astro/src/pages/index.astro +13 -15
  6. package/scaffold/templates/astro/_dot.node-version +1 -1
  7. package/scaffold/templates/astro/astro.config.mjs +23 -0
  8. package/scaffold/templates/astro/package.json +26 -26
  9. package/scaffold/templates/astro/src/components/SkipNav.astro +3 -1
  10. package/scaffold/templates/astro/src/elements/index.ts +11 -0
  11. package/scaffold/templates/astro/src/layouts/BaseLayout.astro +15 -4
  12. package/scaffold/templates/astro/src/lib/api.ts +162 -38
  13. package/scaffold/templates/astro/src/lib/chrome.ts +59 -0
  14. package/scaffold/templates/astro/src/lib/client.ts +4 -4
  15. package/scaffold/templates/astro/src/lib/fragments.ts +48 -0
  16. package/scaffold/templates/astro/src/lib/server-elements.ts +5 -0
  17. package/scaffold/templates/astro/src/middleware.ts +37 -0
  18. package/scaffold/templates/astro/src/pages/404.astro +3 -0
  19. package/scaffold/templates/astro/src/pages/account/addresses.astro +5 -97
  20. package/scaffold/templates/astro/src/pages/account/login.astro +7 -34
  21. package/scaffold/templates/astro/src/pages/account/orders/[orderNumber].astro +11 -3
  22. package/scaffold/templates/astro/src/pages/account/profile.astro +6 -56
  23. package/scaffold/templates/astro/src/pages/account/register.astro +7 -73
  24. package/scaffold/templates/astro/src/pages/alerts/confirm.astro +59 -0
  25. package/scaffold/templates/astro/src/pages/alerts/unsubscribe.astro +53 -0
  26. package/scaffold/templates/astro/src/pages/cart.astro +14 -7
  27. package/scaffold/templates/astro/src/pages/category/[slug].astro +25 -27
  28. package/scaffold/templates/astro/src/pages/checkout.astro +30 -94
  29. package/scaffold/templates/astro/src/pages/fragments/footer.astro +5 -2
  30. package/scaffold/templates/astro/src/pages/fragments/header.astro +12 -2
  31. package/scaffold/templates/astro/src/pages/fragments/nav.astro +8 -5
  32. package/scaffold/templates/astro/src/pages/fragments/product/[slug].astro +9 -10
  33. package/scaffold/templates/astro/src/pages/index.astro +25 -15
  34. package/scaffold/templates/astro/src/pages/order/[orderNumber].astro +34 -45
  35. package/scaffold/templates/astro/src/pages/product/[slug].astro +64 -34
  36. package/scaffold/templates/astro/src/pages/products/index.astro +16 -21
  37. package/scaffold/templates/astro/src/pages/search.astro +10 -11
  38. package/scaffold/templates/astro/src/scripts/init-client.ts +14 -0
  39. package/scaffold/templates/astro/src/scripts/order-status.ts +3 -1
  40. package/scaffold/templates/astro/src/scripts/pdp.ts +29 -21
  41. package/scaffold/templates/astro/src/scripts/plp.ts +15 -93
  42. package/scaffold/templates/astro/src/scripts/search.ts +7 -132
  43. package/scaffold/templates/astro/src/scripts/signed-in-redirect.ts +4 -0
  44. package/scaffold/templates/astro/src/styles/global.css +49 -45
  45. package/scaffold/templates/astro/src/styles/pages/account.css +4 -90
  46. package/scaffold/templates/astro/src/styles/pages/confirmation.css +6 -0
  47. package/scaffold/templates/astro/src/styles/pages/home.css +9 -100
  48. package/scaffold/templates/astro/src/styles/pages/pdp.css +5 -171
  49. package/scaffold/templates/astro/src/styles/pages/plp.css +3 -42
  50. package/scaffold/templates/astro/src/styles/pages/search.css +4 -110
  51. package/scaffold/templates/astro/src/styles/tokens.css +56 -0
  52. package/scaffold/templates/nextjs/_dot.node-version +1 -1
  53. package/scaffold/templates/nextjs/app/(catalog)/category/[slug]/page.tsx +74 -0
  54. package/scaffold/templates/nextjs/app/(catalog)/home/[key]/page.tsx +85 -0
  55. package/scaffold/templates/nextjs/app/(catalog)/layout.tsx +13 -0
  56. package/scaffold/templates/nextjs/app/(catalog)/not-found.tsx +7 -0
  57. package/scaffold/templates/nextjs/app/(catalog)/product/[slug]/page.tsx +201 -0
  58. package/scaffold/templates/nextjs/app/(catalog)/products/page.tsx +62 -0
  59. package/scaffold/templates/nextjs/app/(catalog)/search/SearchView.tsx +90 -0
  60. package/scaffold/templates/nextjs/app/(catalog)/search/page.tsx +46 -0
  61. package/scaffold/templates/nextjs/app/(shopper)/account/addresses/AddressesView.tsx +5 -0
  62. package/scaffold/templates/nextjs/app/(shopper)/account/addresses/page.tsx +17 -0
  63. package/scaffold/templates/nextjs/app/(shopper)/account/login/LoginView.tsx +28 -0
  64. package/scaffold/templates/nextjs/app/(shopper)/account/login/page.tsx +23 -0
  65. package/scaffold/templates/nextjs/app/{account → (shopper)/account}/orders/[orderNumber]/page.tsx +10 -3
  66. package/scaffold/templates/nextjs/app/(shopper)/account/profile/ProfileView.tsx +5 -0
  67. package/scaffold/templates/nextjs/app/(shopper)/account/profile/page.tsx +20 -0
  68. package/scaffold/templates/nextjs/app/(shopper)/account/register/RegisterView.tsx +26 -0
  69. package/scaffold/templates/nextjs/app/(shopper)/account/register/page.tsx +11 -0
  70. package/scaffold/templates/nextjs/app/(shopper)/alerts/AlertLinkForm.tsx +90 -0
  71. package/scaffold/templates/nextjs/app/(shopper)/alerts/LinkInvalid.tsx +19 -0
  72. package/scaffold/templates/nextjs/app/(shopper)/alerts/actions.ts +33 -0
  73. package/scaffold/templates/nextjs/app/(shopper)/alerts/confirm/page.tsx +19 -0
  74. package/scaffold/templates/nextjs/app/(shopper)/alerts/unsubscribe/page.tsx +17 -0
  75. package/scaffold/templates/nextjs/app/(shopper)/cart/CartView.tsx +5 -0
  76. package/scaffold/templates/nextjs/app/(shopper)/cart/page.tsx +22 -0
  77. package/scaffold/templates/nextjs/app/(shopper)/checkout/CheckoutView.tsx +34 -0
  78. package/scaffold/templates/nextjs/app/(shopper)/checkout/page.tsx +39 -0
  79. package/scaffold/templates/nextjs/app/(shopper)/layout.tsx +12 -0
  80. package/scaffold/templates/nextjs/app/(shopper)/not-found.tsx +6 -0
  81. package/scaffold/templates/nextjs/app/{order → (shopper)/order}/[orderNumber]/page.tsx +44 -9
  82. package/scaffold/templates/nextjs/app/error.tsx +3 -7
  83. package/scaffold/templates/nextjs/app/fragments/footer/route.ts +13 -0
  84. package/scaffold/templates/nextjs/app/fragments/header/[key]/route.ts +18 -0
  85. package/scaffold/templates/nextjs/app/fragments/nav/[key]/route.ts +23 -0
  86. package/scaffold/templates/nextjs/app/fragments/product/[slug]/route.ts +22 -0
  87. package/scaffold/templates/nextjs/app/globals.css +5 -23
  88. package/scaffold/templates/nextjs/app/layout.tsx +8 -5
  89. package/scaffold/templates/nextjs/app/not-found.tsx +9 -33
  90. package/scaffold/templates/nextjs/app/tokens.css +56 -0
  91. package/scaffold/templates/nextjs/components/client/ListingControls.tsx +87 -0
  92. package/scaffold/templates/nextjs/components/client/NymbalSetup.tsx +48 -6
  93. package/scaffold/templates/nextjs/components/client/OrderStatusRefresh.tsx +8 -2
  94. package/scaffold/templates/nextjs/components/client/ProductInteractive.tsx +47 -15
  95. package/scaffold/templates/nextjs/components/client/elements.tsx +17 -0
  96. package/scaffold/templates/nextjs/components/server/Header.tsx +33 -102
  97. package/scaffold/templates/nextjs/components/server/NotFoundView.tsx +39 -0
  98. package/scaffold/templates/nextjs/components/server/SkipNav.tsx +7 -3
  99. package/scaffold/templates/nextjs/elements/index.ts +12 -0
  100. package/scaffold/templates/nextjs/lib/api.ts +198 -62
  101. package/scaffold/templates/nextjs/lib/chrome.ts +40 -0
  102. package/scaffold/templates/nextjs/lib/fragments.ts +16 -0
  103. package/scaffold/templates/nextjs/lib/header.ts +39 -0
  104. package/scaffold/templates/nextjs/lib/render.ts +14 -0
  105. package/scaffold/templates/nextjs/next.config.mjs +41 -0
  106. package/scaffold/templates/nextjs/package.json +28 -27
  107. package/scaffold/templates/nextjs/styles/pages/account.module.css +0 -70
  108. package/scaffold/templates/nextjs/styles/pages/confirmation.module.css +6 -85
  109. package/scaffold/templates/nextjs/styles/pages/home.module.css +2 -103
  110. package/scaffold/templates/nextjs/styles/pages/pdp.module.css +3 -183
  111. package/scaffold/templates/nextjs/styles/pages/plp.module.css +9 -143
  112. package/scaffold/templates/nextjs/styles/pages/search.module.css +1 -145
  113. package/scaffold/templates/nextjs/tsconfig.dist.json +5 -0
  114. package/scaffold/templates/astro/src/components/AddressForm.astro +0 -107
  115. package/scaffold/templates/astro/src/components/Breadcrumb.astro +0 -20
  116. package/scaffold/templates/astro/src/components/CategoryNav.astro +0 -27
  117. package/scaffold/templates/astro/src/components/CheckoutSteps.astro +0 -29
  118. package/scaffold/templates/astro/src/components/Footer.astro +0 -108
  119. package/scaffold/templates/astro/src/components/Header.astro +0 -198
  120. package/scaffold/templates/astro/src/components/ImageGallery.astro +0 -42
  121. package/scaffold/templates/astro/src/components/OrderSummary.astro +0 -53
  122. package/scaffold/templates/astro/src/components/Pagination.astro +0 -13
  123. package/scaffold/templates/astro/src/components/PriceDisplay.astro +0 -25
  124. package/scaffold/templates/astro/src/components/ProductCard.astro +0 -44
  125. package/scaffold/templates/astro/src/components/RelatedProducts.astro +0 -28
  126. package/scaffold/templates/astro/src/components/ReviewForm.astro +0 -74
  127. package/scaffold/templates/astro/src/components/ReviewList.astro +0 -41
  128. package/scaffold/templates/astro/src/components/StockBadge.astro +0 -15
  129. package/scaffold/templates/astro/src/scripts/auth-forms.ts +0 -82
  130. package/scaffold/templates/astro/src/scripts/cart-page.ts +0 -118
  131. package/scaffold/templates/astro/src/scripts/checkout.ts +0 -271
  132. package/scaffold/templates/astro/src/scripts/image-gallery.ts +0 -22
  133. package/scaffold/templates/astro/src/scripts/profile-form.ts +0 -57
  134. package/scaffold/templates/astro/src/scripts/review-form.ts +0 -27
  135. package/scaffold/templates/astro/src/styles/pages/cart.css +0 -215
  136. package/scaffold/templates/astro/src/styles/pages/checkout.css +0 -270
  137. package/scaffold/templates/nextjs/app/account/addresses/page.tsx +0 -10
  138. package/scaffold/templates/nextjs/app/account/login/page.tsx +0 -23
  139. package/scaffold/templates/nextjs/app/account/profile/page.tsx +0 -10
  140. package/scaffold/templates/nextjs/app/account/register/page.tsx +0 -10
  141. package/scaffold/templates/nextjs/app/cart/page.tsx +0 -10
  142. package/scaffold/templates/nextjs/app/category/[slug]/page.tsx +0 -61
  143. package/scaffold/templates/nextjs/app/checkout/page.tsx +0 -17
  144. package/scaffold/templates/nextjs/app/page.tsx +0 -63
  145. package/scaffold/templates/nextjs/app/product/[slug]/page.tsx +0 -111
  146. package/scaffold/templates/nextjs/app/products/page.tsx +0 -40
  147. package/scaffold/templates/nextjs/app/search/page.tsx +0 -24
  148. package/scaffold/templates/nextjs/components/client/AddressManager.tsx +0 -181
  149. package/scaffold/templates/nextjs/components/client/CartPage.tsx +0 -121
  150. package/scaffold/templates/nextjs/components/client/CheckoutForm.tsx +0 -482
  151. package/scaffold/templates/nextjs/components/client/ImageGallery.tsx +0 -68
  152. package/scaffold/templates/nextjs/components/client/LoginForm.tsx +0 -89
  153. package/scaffold/templates/nextjs/components/client/MiniCartWrapper.tsx +0 -12
  154. package/scaffold/templates/nextjs/components/client/ProductGrid.tsx +0 -137
  155. package/scaffold/templates/nextjs/components/client/ProfileForm.tsx +0 -112
  156. package/scaffold/templates/nextjs/components/client/RegisterForm.tsx +0 -131
  157. package/scaffold/templates/nextjs/components/client/ReviewForm.tsx +0 -116
  158. package/scaffold/templates/nextjs/components/client/SearchBarWrapper.tsx +0 -27
  159. package/scaffold/templates/nextjs/components/client/SearchResults.tsx +0 -181
  160. package/scaffold/templates/nextjs/components/server/Breadcrumb.tsx +0 -36
  161. package/scaffold/templates/nextjs/components/server/CategoryNav.tsx +0 -29
  162. package/scaffold/templates/nextjs/components/server/CheckoutSteps.tsx +0 -60
  163. package/scaffold/templates/nextjs/components/server/Footer.module.css +0 -64
  164. package/scaffold/templates/nextjs/components/server/Footer.tsx +0 -79
  165. package/scaffold/templates/nextjs/components/server/Header.module.css +0 -147
  166. package/scaffold/templates/nextjs/components/server/OrderSummary.tsx +0 -79
  167. package/scaffold/templates/nextjs/components/server/PriceDisplay.tsx +0 -31
  168. package/scaffold/templates/nextjs/components/server/ProductCard.tsx +0 -59
  169. package/scaffold/templates/nextjs/components/server/RelatedProducts.tsx +0 -31
  170. package/scaffold/templates/nextjs/components/server/ReviewList.tsx +0 -62
  171. package/scaffold/templates/nextjs/styles/pages/cart.module.css +0 -240
  172. package/scaffold/templates/nextjs/styles/pages/checkout.module.css +0 -404
  173. /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/layout.tsx +0 -0
  174. /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/orders/page.tsx +0 -0
  175. /package/scaffold/templates/nextjs/app/{account → (shopper)/account}/page.tsx +0 -0
@@ -0,0 +1,56 @@
1
+ /* ----------------------------------------------------------------
2
+ Design tokens: this store's file, edit it to restyle.
3
+ Every Nymbal element reads its look from these custom properties,
4
+ which cross into its shadow root. An element's `part`s can be
5
+ styled further with ::part(), e.g. nymbal-add-to-cart::part(button).
6
+ Defaults: @nymbalhq/web-components/tokens.css.
7
+ ---------------------------------------------------------------- */
8
+
9
+ :root {
10
+ --nymbal-color-primary: #18181b;
11
+ --nymbal-color-primary-hover: #27272a;
12
+ --nymbal-color-accent: #2563eb;
13
+ --nymbal-color-accent-hover: #1d4ed8;
14
+ --nymbal-color-success: #16a34a;
15
+ --nymbal-color-error: #dc2626;
16
+ --nymbal-color-warning: #d97706;
17
+ --nymbal-color-text: #18181b;
18
+ --nymbal-color-text-muted: #71717a;
19
+ --nymbal-color-text-inverse: #ffffff;
20
+ --nymbal-color-border: #e4e4e7;
21
+ --nymbal-color-surface: #ffffff;
22
+ --nymbal-color-overlay: rgba(0, 0, 0, 0.4);
23
+
24
+ --nymbal-font-family: system-ui, -apple-system, sans-serif;
25
+ --nymbal-font-size-xs: 0.75rem;
26
+ --nymbal-font-size-sm: 0.875rem;
27
+ --nymbal-font-size-base: 1rem;
28
+ --nymbal-font-size-lg: 1.125rem;
29
+ --nymbal-font-size-xl: 1.25rem;
30
+ --nymbal-font-weight-normal: 400;
31
+ --nymbal-font-weight-medium: 500;
32
+ --nymbal-font-weight-bold: 700;
33
+
34
+ --nymbal-spacing-xs: 0.25rem;
35
+ --nymbal-spacing-sm: 0.5rem;
36
+ --nymbal-spacing-md: 1rem;
37
+ --nymbal-spacing-lg: 1.5rem;
38
+ --nymbal-spacing-xl: 2rem;
39
+
40
+ --nymbal-radius-sm: 0.25rem;
41
+ --nymbal-radius-md: 0.375rem;
42
+ --nymbal-radius-lg: 0.5rem;
43
+ --nymbal-radius-full: 9999px;
44
+
45
+ --nymbal-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
46
+ --nymbal-shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
47
+ --nymbal-shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
48
+
49
+ --nymbal-transition-fast: 150ms ease;
50
+ --nymbal-transition-normal: 200ms ease;
51
+ --nymbal-transition-slow: 300ms ease;
52
+
53
+ --nymbal-z-dropdown: 100;
54
+ --nymbal-z-drawer: 200;
55
+ --nymbal-z-toast: 300;
56
+ }
@@ -0,0 +1,87 @@
1
+ 'use client'
2
+
3
+ import { useCallback, useEffect, useState, type ReactNode } from 'react'
4
+ import type { Facet, ProductSortKey } from '@nymbalhq/types'
5
+ import { ProductFilter, SortDropdown, useNymbalClient } from '@nymbalhq/react'
6
+ import styles from '@/styles/pages/plp.module.css'
7
+
8
+ interface ListingControlsProps {
9
+ /** The server-rendered listing's sort and category: the product-list store loads the same page on mount. */
10
+ sort: ProductSortKey
11
+ category?: string
12
+ /** The listing's facets: none when the store's search cannot facet, and then no filter. */
13
+ facets: Facet[]
14
+ /** The sort keys the store reports, in order, and the one it lists by when none is asked. */
15
+ sortKeys: ProductSortKey[]
16
+ defaultSort?: ProductSortKey | undefined
17
+ /** The listing's `nymbal-product-grid`, which follows the store once this load settles. */
18
+ children: ReactNode
19
+ }
20
+
21
+ /** A listing's filter and sort around its grid: they drive the product-list store, which the grid follows. */
22
+ export function ListingControls({
23
+ sort,
24
+ category,
25
+ facets,
26
+ sortKeys,
27
+ defaultSort,
28
+ children,
29
+ }: ListingControlsProps) {
30
+ const client = useNymbalClient()
31
+ const [showMobileFilters, setShowMobileFilters] = useState(false)
32
+
33
+ useEffect(() => {
34
+ void client.productList.load({ limit: 24, category, sort })
35
+ }, [client, category, sort])
36
+
37
+ // The URL carries the sort, so a reload or a shared link renders the same order server-side.
38
+ const handleSort = useCallback(
39
+ (event: CustomEvent<{ sort: string }>) => {
40
+ const key = event.detail.sort as ProductSortKey
41
+ const url = new URL(window.location.href)
42
+ url.searchParams.set('sort', key)
43
+ window.history.replaceState(window.history.state, '', url)
44
+ void client.productList.setSort(key)
45
+ },
46
+ [client],
47
+ )
48
+
49
+ return (
50
+ <div className={styles.layout}>
51
+ <aside className={styles.sidebar}>
52
+ {facets.length > 0 && (
53
+ <>
54
+ <button
55
+ className={styles.mobileFilterToggle}
56
+ onClick={() => setShowMobileFilters((v) => !v)}
57
+ type="button"
58
+ >
59
+ {showMobileFilters ? 'Hide Filters' : 'Show Filters'}
60
+ </button>
61
+ <div
62
+ className={styles.filterSection}
63
+ style={{ display: showMobileFilters ? 'block' : undefined }}
64
+ >
65
+ <ProductFilter facets={facets} />
66
+ </div>
67
+ </>
68
+ )}
69
+ </aside>
70
+
71
+ <div className={styles.content}>
72
+ {sortKeys.length > 0 && (
73
+ <div className={styles.sortBar}>
74
+ <SortDropdown
75
+ className={styles.sortSelect}
76
+ sortKeys={sortKeys}
77
+ value={sort}
78
+ defaultSort={defaultSort}
79
+ onSortChange={handleSort}
80
+ />
81
+ </div>
82
+ )}
83
+ {children}
84
+ </div>
85
+ </div>
86
+ )
87
+ }
@@ -1,24 +1,66 @@
1
1
  'use client'
2
2
 
3
- import { useEffect, useRef, type ReactNode } from 'react'
3
+ import { useEffect, useLayoutEffect, useRef, type ReactNode } from 'react'
4
+ import { useRouter } from 'next/navigation'
4
5
  import { NymbalProvider } from '@nymbalhq/react'
5
- import { registerClient, registerComponents } from '@nymbalhq/web-components'
6
- import '@nymbalhq/web-components/tokens.css'
6
+ import '@/elements'
7
+ import { registerClient } from '@nymbalhq/web-components'
8
+ import { NymbalCartDrawer } from '@nymbalhq/web-components/elements/nymbal-cart-drawer'
9
+ import { NymbalMiniCart } from '@nymbalhq/web-components/elements/nymbal-mini-cart'
10
+ import { NymbalSearchBar } from '@nymbalhq/web-components/elements/nymbal-search-bar'
11
+ import { NymbalSiteFooter } from '@nymbalhq/web-components/elements/nymbal-site-footer'
12
+ import { NymbalSiteHeader } from '@nymbalhq/web-components/elements/nymbal-site-header'
7
13
  import { getNymbalClient, restoreSession } from '@/lib/client'
8
14
 
9
15
  export function NymbalSetup({ children }: { children: ReactNode }) {
10
16
  const client = getNymbalClient()
17
+ const router = useRouter()
11
18
  const initialized = useRef(false)
12
19
 
13
- useEffect(() => {
20
+ // A layout effect runs before every passive effect of the commit, so the client is registered before any wrapper
21
+ // defines its element (each wrapper defines its own, so a route loads only the elements it renders). The cart starts
22
+ // loading first, so an element the server rendered from the cart keeps showing it until the load settles.
23
+ useLayoutEffect(() => {
14
24
  if (!initialized.current) {
15
25
  registerClient(client)
16
- registerComponents()
17
- client.cart.load()
26
+ void client.cart.load()
27
+ NymbalSiteHeader.define()
28
+ NymbalSiteFooter.define()
29
+ NymbalSearchBar.define()
30
+ NymbalMiniCart.define()
31
+ NymbalCartDrawer.define()
18
32
  void restoreSession()
19
33
  initialized.current = true
20
34
  }
21
35
  }, [client])
22
36
 
37
+ // The elements' links are plain anchors in shadow roots, which the router does not see: each asks with
38
+ // `nymbal:navigate`, and the router takes it. The header's search bar and mini-cart are in its server HTML, not
39
+ // React children, so their events are taken here too.
40
+ useEffect(() => {
41
+ const navigate = (event: Event): void => {
42
+ const href = (event as CustomEvent<{ href?: string }>).detail?.href
43
+ if (!href || new URL(href, window.location.href).origin !== window.location.origin) return
44
+ event.preventDefault()
45
+ router.push(href)
46
+ }
47
+ const searchSelected = (event: Event): void => {
48
+ const slug = (event as CustomEvent<{ product?: { slug?: string } }>).detail?.product?.slug
49
+ if (slug) router.push(`/product/${encodeURIComponent(slug)}`)
50
+ }
51
+ // Before the drawer's own listener toggles it, as the wrapper's listener on the mini-cart ran.
52
+ const miniCartClicked = (): void => {
53
+ window.dispatchEvent(new CustomEvent('nymbal:cart:open'))
54
+ }
55
+ document.addEventListener('nymbal:navigate', navigate)
56
+ document.addEventListener('nymbal:search:selected', searchSelected)
57
+ document.addEventListener('nymbal:mini-cart:clicked', miniCartClicked, true)
58
+ return () => {
59
+ document.removeEventListener('nymbal:navigate', navigate)
60
+ document.removeEventListener('nymbal:search:selected', searchSelected)
61
+ document.removeEventListener('nymbal:mini-cart:clicked', miniCartClicked, true)
62
+ }
63
+ }, [router])
64
+
23
65
  return <NymbalProvider client={client}>{children}</NymbalProvider>
24
66
  }
@@ -12,9 +12,12 @@ const POLL_FOR_MS = 10_000
12
12
 
13
13
  export function OrderStatusRefresh({
14
14
  orderNumber,
15
+ orderKey,
15
16
  status,
16
17
  }: {
17
18
  orderNumber: string
19
+ /** The page's `?key=`: the API answers a guest's order to its key only. */
20
+ orderKey?: string | undefined
18
21
  status: OrderStatus
19
22
  }) {
20
23
  const router = useRouter()
@@ -26,7 +29,10 @@ export function OrderStatusRefresh({
26
29
  let stopped = false
27
30
  const poll = async () => {
28
31
  try {
29
- const order = await getNymbalClient().customer.orders.get(orderNumber)
32
+ const order = await getNymbalClient().customer.orders.get(
33
+ orderNumber,
34
+ orderKey ? { key: orderKey } : {},
35
+ )
30
36
  if (stopped) return
31
37
  if (order.status !== status) {
32
38
  router.refresh()
@@ -42,7 +48,7 @@ export function OrderStatusRefresh({
42
48
  stopped = true
43
49
  clearTimeout(timer)
44
50
  }
45
- }, [orderNumber, status, router])
51
+ }, [orderNumber, orderKey, status, router])
46
52
 
47
53
  return null
48
54
  }
@@ -2,24 +2,45 @@
2
2
 
3
3
  import { useRef, useState } from 'react'
4
4
  import type { DenormalisedProduct } from '@nymbalhq/sdk'
5
- import { STOCK_LABELS, stockLevel } from '@nymbalhq/types'
6
- import { useProduct, VariantSelector, AddToCart, QuantitySelector } from '@nymbalhq/react'
7
- import { formatPrice } from '@/lib/format'
5
+ import {
6
+ useProduct,
7
+ VariantSelector,
8
+ AddToCart,
9
+ ProductPrice,
10
+ QuantitySelector,
11
+ StockBadge,
12
+ NotifyMe,
13
+ } from '@nymbalhq/react'
8
14
  import styles from '@/styles/pages/pdp.module.css'
9
15
 
10
16
  interface ProductInteractiveProps {
11
17
  product: DenormalisedProduct
18
+ /** The store's email delivers, so the page offers a back-in-stock alert (GET /api/capabilities). */
19
+ offersAlerts?: boolean
20
+ /** The server's render of each element, for the product's first variant (app/product/[slug]/page.tsx). */
21
+ serverHtml?: {
22
+ price: string
23
+ stock: string
24
+ variantSelector: string
25
+ quantity: string
26
+ addToCart: string
27
+ notifyMe?: string | undefined
28
+ }
12
29
  }
13
30
 
14
- export function ProductInteractive({ product }: ProductInteractiveProps) {
31
+ export function ProductInteractive({
32
+ product,
33
+ offersAlerts = false,
34
+ serverHtml,
35
+ }: ProductInteractiveProps) {
15
36
  const { selectedVariant } = useProduct(product.slug)
16
37
 
17
38
  const variant = selectedVariant ?? product.variants?.[0]
18
- const price = variant?.priceMinor ?? product.priceMinor ?? 0
19
- const currency = product.currency ?? 'GBP'
20
39
  // A product with no variants has nothing to sell, so it reads as out of stock.
21
40
  const stock = variant?.stock ?? 0
22
- const level = stockLevel(stock)
41
+ // The price and the badge are the server's first variant until the store settles on this product; they follow it
42
+ // themselves, so a soft navigation from another product never shows that product's price here.
43
+ const first = product.variants?.[0]
23
44
 
24
45
  // The quantity belongs to the variant it was chosen for, so a variant change starts again at 1.
25
46
  const [chosen, setChosen] = useState<{ variantId: string | undefined; qty: number }>({
@@ -40,18 +61,18 @@ export function ProductInteractive({ product }: ProductInteractiveProps) {
40
61
  {product.name}
41
62
  </h1>
42
63
 
43
- <div className={styles.price} data-testid="product-price">
44
- {formatPrice(price, currency)}
45
- </div>
64
+ <ProductPrice
65
+ productId={product.id}
66
+ priceMinor={first?.priceMinor ?? product.priceMinor ?? 0}
67
+ currency={product.currency ?? 'GBP'}
68
+ serverHtml={serverHtml?.price}
69
+ />
46
70
 
47
- <div className={styles.stockBadge} data-testid="stock-badge" data-level={level}>
48
- <span className={styles.stockDot} aria-hidden="true" />
49
- {STOCK_LABELS[level]}
50
- </div>
71
+ <StockBadge productId={product.id} stock={first?.stock ?? 0} serverHtml={serverHtml?.stock} />
51
72
 
52
73
  {hasVariantChoice && (
53
74
  <div className={styles.variantSection}>
54
- <VariantSelector />
75
+ <VariantSelector product={product} serverHtml={serverHtml?.variantSelector} />
55
76
  </div>
56
77
  )}
57
78
 
@@ -62,6 +83,7 @@ export function ProductInteractive({ product }: ProductInteractiveProps) {
62
83
  value={1}
63
84
  min={1}
64
85
  max={99}
86
+ serverHtml={serverHtml?.quantity}
65
87
  onQuantityChange={(e) => {
66
88
  // A typed quantity changes on blur, and the press on Add is what blurs it: the wrapper's effect lands
67
89
  // after a fast click has already read `qty`, so the element gets it here, in the same event.
@@ -75,8 +97,18 @@ export function ProductInteractive({ product }: ProductInteractiveProps) {
75
97
  variantId={variant?.id ?? product.id}
76
98
  qty={qty}
77
99
  disabled={stock <= 0}
100
+ serverHtml={serverHtml?.addToCart}
78
101
  />
79
102
  </div>
103
+
104
+ {offersAlerts && first !== undefined && (
105
+ <NotifyMe
106
+ productId={product.id}
107
+ variantId={first.id}
108
+ stock={first.stock ?? 0}
109
+ serverHtml={serverHtml?.notifyMe}
110
+ />
111
+ )}
80
112
  </div>
81
113
  )
82
114
  }
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+
3
+ // The generated wrappers the server components render with their server HTML (`renderNymbal`): each defines its
4
+ // element and keeps its attributes in the browser, so it is a client module.
5
+ export {
6
+ Breadcrumb,
7
+ CategoryNav,
8
+ ImageGallery,
9
+ OrderSummary,
10
+ OrderTimeline,
11
+ ProductGrid,
12
+ RecentlyViewed,
13
+ ReviewForm,
14
+ ReviewList,
15
+ SiteFooter,
16
+ SiteHeader,
17
+ } from '@nymbalhq/react'
@@ -1,107 +1,38 @@
1
- import Link from 'next/link'
2
- import { SearchBarWrapper } from '@/components/client/SearchBarWrapper'
3
- import { MiniCartWrapper } from '@/components/client/MiniCartWrapper'
4
- import { fetchCapabilities } from '@/lib/api'
5
- import styles from './Header.module.css'
1
+ import { headers } from 'next/headers'
2
+ import { SiteHeader } from '@/components/client/elements'
3
+ import { fetchCart } from '@/lib/api'
4
+ import { HEADER } from '@/lib/chrome'
5
+ import { canSearch, siteHeader } from '@/lib/header'
6
+ import { renderNymbal } from '@/lib/render'
6
7
 
7
- const NAV_LINKS = [
8
- { href: '/products', label: 'Shop' },
9
- { href: '/products?category=new', label: 'New Arrivals' },
10
- { href: '/products?category=sale', label: 'Sale' },
11
- ]
12
-
13
- export async function Header() {
14
- const capabilities = await fetchCapabilities()
15
- const canSearch = capabilities?.search.capabilities.includes('search') ?? false
8
+ function HeaderElement({ header }: { header: ReturnType<typeof siteHeader> }) {
9
+ const serverHtml = renderNymbal('nymbal-site-header', header.attributes, header.children).__html
16
10
  return (
17
- <header className={styles.header} data-testid="site-header">
18
- <div className={`container ${styles.inner}`}>
19
- <Link href="/" className={styles.logo}>
20
- Nymbal
21
- </Link>
22
-
23
- <nav className={styles.nav} aria-label="Main navigation">
24
- <ul className={styles.navList}>
25
- {NAV_LINKS.map((link) => (
26
- <li key={link.href}>
27
- <Link href={link.href} className={styles.navLink}>
28
- {link.label}
29
- </Link>
30
- </li>
31
- ))}
32
- </ul>
33
- </nav>
34
-
35
- <div className={styles.actions}>
36
- {canSearch && (
37
- <div className={styles.search}>
38
- <SearchBarWrapper />
39
- </div>
40
- )}
41
- <Link href="/account" className={styles.iconLink} aria-label="Account">
42
- <svg
43
- width="20"
44
- height="20"
45
- viewBox="0 0 24 24"
46
- fill="none"
47
- stroke="currentColor"
48
- strokeWidth="2"
49
- strokeLinecap="round"
50
- strokeLinejoin="round"
51
- aria-hidden="true"
52
- >
53
- <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2" />
54
- <circle cx="12" cy="7" r="4" />
55
- </svg>
56
- </Link>
57
- <MiniCartWrapper />
58
- </div>
11
+ <SiteHeader
12
+ links={HEADER.links}
13
+ logo={HEADER.logo}
14
+ accountHref={HEADER.accountHref}
15
+ serverHtml={serverHtml}
16
+ />
17
+ )
18
+ }
59
19
 
60
- <input
61
- type="checkbox"
62
- id="mobile-menu-toggle"
63
- className={styles.menuCheckbox}
64
- aria-hidden="true"
65
- />
66
- <label
67
- htmlFor="mobile-menu-toggle"
68
- className={styles.menuButton}
69
- aria-label="Toggle menu"
70
- >
71
- <svg
72
- width="24"
73
- height="24"
74
- viewBox="0 0 24 24"
75
- fill="none"
76
- stroke="currentColor"
77
- strokeWidth="2"
78
- strokeLinecap="round"
79
- strokeLinejoin="round"
80
- aria-hidden="true"
81
- >
82
- <line x1="3" y1="6" x2="21" y2="6" />
83
- <line x1="3" y1="12" x2="21" y2="12" />
84
- <line x1="3" y1="18" x2="21" y2="18" />
85
- </svg>
86
- </label>
20
+ /**
21
+ * The header of a page. `shopper` reads the request's cart cookie, so the count is in the HTML with JavaScript off and
22
+ * the page renders per request; without it the page may be cached for every shopper, and the mini-cart fills its count
23
+ * in the browser.
24
+ */
25
+ export async function Header({ shopper = false }: { shopper?: boolean }) {
26
+ const cookie = shopper ? (await headers()).get('cookie') : null
27
+ const [search, cart] = await Promise.all([canSearch(), shopper ? fetchCart(cookie) : null])
28
+ return <HeaderElement header={siteHeader(search, cart?.itemCount)} />
29
+ }
87
30
 
88
- <nav className={styles.mobileNav} aria-label="Mobile navigation">
89
- <ul className={styles.mobileNavList}>
90
- {NAV_LINKS.map((link) => (
91
- <li key={link.href}>
92
- <Link href={link.href} className={styles.mobileNavLink}>
93
- {link.label}
94
- </Link>
95
- </li>
96
- ))}
97
- <li>
98
- <Link href="/account" className={styles.mobileNavLink}>
99
- Account
100
- </Link>
101
- </li>
102
- </ul>
103
- </nav>
104
- </div>
105
- </header>
106
- )
31
+ /**
32
+ * The header with no search bar and no count, for the root 404: Next renders that 404 into every page under the root
33
+ * layout and at build, so it can neither read the request (a cached page would fail) nor call the API (a build with
34
+ * the API down would fail).
35
+ */
36
+ export function PlainHeader() {
37
+ return <HeaderElement header={siteHeader(false)} />
107
38
  }
@@ -0,0 +1,39 @@
1
+ import Link from 'next/link'
2
+ import styles from '@/styles/pages/error.module.css'
3
+
4
+ /** The 404's message and its ways back, under whichever header the 404 has. */
5
+ export function NotFoundView() {
6
+ return (
7
+ <div className={styles.page}>
8
+ <div className={styles.wrapper}>
9
+ <div className={`${styles.icon} ${styles.notFoundIcon}`}>
10
+ <svg
11
+ viewBox="0 0 24 24"
12
+ fill="none"
13
+ stroke="currentColor"
14
+ strokeWidth="2"
15
+ strokeLinecap="round"
16
+ strokeLinejoin="round"
17
+ aria-hidden="true"
18
+ >
19
+ <circle cx="11" cy="11" r="8" />
20
+ <line x1="21" y1="21" x2="16.65" y2="16.65" />
21
+ </svg>
22
+ </div>
23
+ <p className={styles.statusCode}>404</p>
24
+ <h1 className={styles.title}>Page Not Found</h1>
25
+ <p className={styles.message}>
26
+ The page you are looking for does not exist or may have been moved.
27
+ </p>
28
+ <div className={styles.actions}>
29
+ <Link href="/" className={styles.homeLink}>
30
+ Go Home
31
+ </Link>
32
+ <Link href="/products" className={styles.retryButton}>
33
+ Browse Products
34
+ </Link>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ )
39
+ }
@@ -1,7 +1,11 @@
1
+ // In a landmark of its own: the header's links are in its shadow root, where a checker cannot tell the skip link
2
+ // comes before them, so it would count it as content outside every landmark.
1
3
  export function SkipNav() {
2
4
  return (
3
- <a href="#main" className="skip-nav">
4
- Skip to content
5
- </a>
5
+ <nav aria-label="Skip link">
6
+ <a href="#main" className="skip-nav">
7
+ Skip to content
8
+ </a>
9
+ </nav>
6
10
  )
7
11
  }
@@ -0,0 +1,12 @@
1
+ // This store's own elements. Everything here runs before any Nymbal element is defined (components/client/
2
+ // NymbalSetup.tsx imports it first), and Nymbal leaves alone any tag that is already defined, so an element defined
3
+ // here under a Nymbal tag replaces Nymbal's. The server renders Nymbal's elements too, so a replacement is also named
4
+ // in `serverElements`, and the server renders it under the tag (lib/render.ts). The module is evaluated on the server
5
+ // as well, so define elements only in the browser, and import @nymbalhq/web-components/hydrate-support before lit,
6
+ // so the element takes over what the server rendered:
7
+ //
8
+ // import '@nymbalhq/web-components/hydrate-support'
9
+ // import { MyMiniCart } from './my-mini-cart'
10
+ // if (typeof window !== 'undefined') customElements.define('nymbal-mini-cart', MyMiniCart)
11
+ // export const serverElements = { 'nymbal-mini-cart': MyMiniCart }
12
+ export const serverElements = {}