@godaddy/gd-commerce-storefront 0.3.0 → 0.4.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.
- package/README.md +51 -2
- package/dist/index.d.ts +120 -7
- package/dist/index.js +516 -243
- package/dist/styles.css +63 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,9 +100,10 @@ The repository example uses React Router 7. Follow each router version's own Rea
|
|
|
100
100
|
| --- | --- |
|
|
101
101
|
| `CommerceStorefront` | Recommended integration: provider and one drawer |
|
|
102
102
|
| `Catalog` | Six products per cursor page, with `title`, `description`, and `showHeader` props |
|
|
103
|
+
| `CatalogRoot` and catalog parts | Build a [custom catalog or card layout](#custom-catalog-layouts) with the same rules as `Catalog` |
|
|
103
104
|
| `ProductDetails` | Reads `:productId`; validates URL option selections against catalog results |
|
|
104
105
|
| `ProductDetailsRoot` and product parts | Build a [custom product layout](#custom-product-layouts) with the same rules as `ProductDetails` |
|
|
105
|
-
| `ProductCard` | Renders one `SKUGroup` with direct add or a product-details link |
|
|
106
|
+
| `ProductCard` | Renders one `SKUGroup` with direct add or a product-details link; `ProductCardRoot` and card parts customize it |
|
|
106
107
|
| `CartButton` | Opens the shared drawer and displays item count |
|
|
107
108
|
| `AddToCartButton` | Adds a verified `sku`, `name`, and optional integer `quantity` |
|
|
108
109
|
| `CommerceStatus` | Connection progress/error/retry for custom layouts |
|
|
@@ -153,7 +154,7 @@ Every part is named `ProductDetails*` because it works only inside `ProductDetai
|
|
|
153
154
|
|
|
154
155
|
Parts read state from the root and take no product, SKU, price or quantity props. Whatever the layout, only a server-verified SKU can be added, and changing a selection resets the quantity and image. Every part throws if it is rendered outside `ProductDetailsRoot`. In development builds, if no control is rendered for an attribute the product requires, a console warning names the missing ones. A control that mounts later, such as one in a closed accordion, can trigger it; the product becomes purchasable once the control renders. Products without attributes but with several SKUs need `ProductDetailsOptions` or `ProductDetailsPurchase`. Parts can be rendered more than once, such as in a sticky mobile purchase bar; each copy gets its own element IDs.
|
|
155
156
|
|
|
156
|
-
Every part accepts `className`, which is added to the part's outer element, a wrapper the package's CSS reset leaves alone. Host classes there control margin, padding, border, color, width and grid placement, including layered utilities such as Tailwind v4's. The packaged layout sets its spacing and grid placement this way. Elements inside the part, such as the title's `<h1>`, keep the package's own styles: a host font size on `ProductDetailsTitle` does not change the heading's size, but a host color does reach it, because the heading inherits its color.
|
|
157
|
+
Every part accepts `className`, which is added to the part's outer element, a wrapper the package's CSS reset leaves alone. Host classes there control margin, padding, border, color, width, display, gap and grid placement, including layered utilities such as Tailwind v4's. In `ProductDetailsOptions` and `ProductDetailsPurchase`, each control keeps a 24px bottom margin, even in a host grid. The exception is a class name the package also uses, such as `grid-cols-1` or `p-6`: the package's rule wins, even over the host's responsive variants on the same element, such as `md:grid-cols-4`. The packaged layout sets its spacing and grid placement this way. Elements inside the part, such as the title's `<h1>`, keep the package's own styles: a host font size on `ProductDetailsTitle` does not change the heading's size, but a host color does reach it, because the heading inherits its color.
|
|
157
158
|
|
|
158
159
|
Two hooks support custom parts inside the root:
|
|
159
160
|
|
|
@@ -178,6 +179,54 @@ function ColorSwatches() {
|
|
|
178
179
|
|
|
179
180
|
Parts are flat named exports, not properties such as `ProductDetails.Title`, so each one is an ordinary module export.
|
|
180
181
|
|
|
182
|
+
## Custom catalog layouts
|
|
183
|
+
|
|
184
|
+
`Catalog` is the recommended catalog. When its layout or its cards do not fit, compose the same parts inside `CatalogRoot`. The root loads one cursor page of six products, or the built-in samples when `sampleProducts` is set and no store is connected, and shows the connection state itself. This is `<Catalog sampleProducts />` written out with its packaged card:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
import {
|
|
188
|
+
CatalogHeader, CatalogPagination, CatalogProducts, CatalogRoot, CatalogSummary, ProductCardAction,
|
|
189
|
+
ProductCardDescription, ProductCardImage, ProductCardPrice, ProductCardRoot, ProductCardTitle,
|
|
190
|
+
} from '@godaddy/gd-commerce-storefront';
|
|
191
|
+
|
|
192
|
+
<CatalogRoot sampleProducts>
|
|
193
|
+
<CatalogHeader className='border-b border-neutral-200 pb-10 pt-4 sm:pb-14 sm:pt-8' />
|
|
194
|
+
<CatalogSummary className='border-b border-neutral-200 py-6 sm:py-8' />
|
|
195
|
+
<CatalogProducts className='grid grid-cols-1 gap-6 py-8 sm:grid-cols-2 lg:grid-cols-3 lg:gap-8 lg:py-10'>
|
|
196
|
+
<ProductCardRoot className='flex min-w-0 flex-col overflow-hidden rounded-lg border border-neutral-200'>
|
|
197
|
+
<ProductCardImage />
|
|
198
|
+
<div className='flex flex-1 flex-col p-6'>
|
|
199
|
+
<ProductCardTitle />
|
|
200
|
+
<ProductCardDescription className='mt-3' />
|
|
201
|
+
<div className='mt-auto pt-6'>
|
|
202
|
+
<div className='flex flex-wrap items-end justify-between gap-4 border-t border-neutral-200 pt-5'>
|
|
203
|
+
<ProductCardPrice className='min-w-0 flex-1' />
|
|
204
|
+
<ProductCardAction className='max-w-full' />
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
</ProductCardRoot>
|
|
209
|
+
</CatalogProducts>
|
|
210
|
+
<CatalogPagination className='border-t border-neutral-200 pt-6' />
|
|
211
|
+
</CatalogRoot>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
As with product layouts, the grid, spacing and border classes come from your own stylesheet in a custom layout. Without them, the cards stack in one column.
|
|
215
|
+
|
|
216
|
+
| Part | Renders |
|
|
217
|
+
| --- | --- |
|
|
218
|
+
| `CatalogHeader` | The `title` as the page's H1 and a `description`; leave it out when the host page owns the H1 |
|
|
219
|
+
| `CatalogSummary` | The loading, failure or product-count status line |
|
|
220
|
+
| `CatalogProducts` | One card per product. Its children are the card, rendered once for each product; without children, the packaged card |
|
|
221
|
+
| `CatalogPagination` | First-page and next-page buttons; nothing for samples |
|
|
222
|
+
| `ProductCardImage`, `ProductCardTitle` | The first image and the name as an H2, each linked to the product page. With a title in the card, keyboard and screen reader users get only the title link; without one, the image link takes its place once the page is interactive |
|
|
223
|
+
| `ProductCardDescription`, `ProductCardPrice` | Up to three lines of description (nothing without one), and the price or price range |
|
|
224
|
+
| `ProductCardAction` | Adds the product directly only when it has one SKU and no options; otherwise links to the product page to choose |
|
|
225
|
+
|
|
226
|
+
`className` on `CatalogProducts` goes on the element whose direct children are the cards, so a host grid places them, and `className` on `ProductCardRoot` goes on each card, so classes such as `col-span-2` work. The loading placeholder (three cards, one to three columns), the error with its retry button, and the empty message render just before that element, whatever the layout. Card parts take no product, SKU or price props. Inside `CatalogProducts`, `ProductCardRoot` takes no `product` prop either and throws if it gets one, so a card always shows the product it is rendered for. Samples use the same card: they show a placeholder image, no description and no links, and add only to the sample cart. Card and catalog parts throw if they are rendered outside their root. Packaged cards fill their grid row, with the price and action at the bottom of each card.
|
|
227
|
+
|
|
228
|
+
For a product the host already has, such as a featured product, use `ProductCard` or `ProductCardRoot` with a `product` prop outside the catalog. `useProductCard()` returns read-only `product` (`null` for samples), `name`, `href` (`null` for samples) and `isSample` for building custom card parts. Every part accepts `className` on an outer wrapper that the package's CSS reset leaves alone, with the same limits as [product parts](#custom-product-layouts).
|
|
229
|
+
|
|
181
230
|
## How it works
|
|
182
231
|
|
|
183
232
|
Products are SKU groups. The package purchases only an unambiguous SKU, verifies all selected attributes through the server, uses SKU prices/images, and distinguishes untracked inventory from sold-out inventory. Server-side inventory and pricing checks remain mandatory.
|
package/dist/index.d.ts
CHANGED
|
@@ -301,6 +301,8 @@ declare function getAvailableInventoryQuantity(item: InventoryCountContainer | n
|
|
|
301
301
|
declare function getImageUrls(item: MediaObjectContainer | null | undefined): string[];
|
|
302
302
|
declare function getPrimaryImageUrl(item: MediaObjectContainer | null | undefined): string | null;
|
|
303
303
|
declare function getProductAttributes(skuGroup: SKUGroup | null | undefined): StorefrontProductAttribute[];
|
|
304
|
+
/** The product's display name: its label, then its name. */
|
|
305
|
+
declare function getProductName(skuGroup: SKUGroup): string;
|
|
304
306
|
//#endregion
|
|
305
307
|
//#region src/cart.d.ts
|
|
306
308
|
declare function CartButton(): ReactElement;
|
|
@@ -316,11 +318,53 @@ declare function AddToCartButton({
|
|
|
316
318
|
declare function CartDrawer(): ReactElement;
|
|
317
319
|
//#endregion
|
|
318
320
|
//#region src/catalog.d.ts
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
/** Props shared by every catalog part. `className` is added to the part's outer element. */
|
|
322
|
+
interface CatalogPartProps {
|
|
323
|
+
className?: string;
|
|
324
|
+
}
|
|
325
|
+
interface CatalogRootProps {
|
|
326
|
+
children: ReactNode;
|
|
327
|
+
/** Added to the root `<section>`. */
|
|
328
|
+
className?: string;
|
|
329
|
+
/** Permit built-in examples only while the host confirms this site is unbound. */
|
|
330
|
+
sampleProducts?: boolean;
|
|
331
|
+
}
|
|
332
|
+
/** Loads one cursor page of products, or the built-in samples, and provides them to catalog parts. */
|
|
333
|
+
declare function CatalogRoot({
|
|
334
|
+
children,
|
|
335
|
+
className,
|
|
336
|
+
sampleProducts
|
|
337
|
+
}: CatalogRootProps): ReactElement;
|
|
338
|
+
interface CatalogHeaderProps extends CatalogPartProps {
|
|
339
|
+
title?: string;
|
|
340
|
+
description?: string;
|
|
341
|
+
}
|
|
342
|
+
/** The catalog title as the page's H1, with a description. */
|
|
343
|
+
declare function CatalogHeader({
|
|
344
|
+
title,
|
|
345
|
+
description,
|
|
346
|
+
className
|
|
347
|
+
}: CatalogHeaderProps): ReactElement;
|
|
348
|
+
/** Announces loading, failure, or how many products the page shows. */
|
|
349
|
+
declare function CatalogSummary({
|
|
350
|
+
className
|
|
351
|
+
}: CatalogPartProps): ReactElement;
|
|
352
|
+
interface CatalogProductsProps extends CatalogPartProps {
|
|
353
|
+
/** One card, rendered for every product. Defaults to the packaged card. */
|
|
354
|
+
children?: ReactNode;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* The product cards. `className` goes on the element that contains the cards, such as a grid. The loading
|
|
358
|
+
* placeholder, the error with its retry, and the empty message render just before that element.
|
|
359
|
+
*/
|
|
360
|
+
declare function CatalogProducts({
|
|
361
|
+
className,
|
|
362
|
+
children
|
|
363
|
+
}: CatalogProductsProps): ReactElement;
|
|
364
|
+
/** First-page and next-page buttons. Renders nothing for samples, which have one page. */
|
|
365
|
+
declare function CatalogPagination({
|
|
366
|
+
className
|
|
367
|
+
}: CatalogPartProps): ReactElement | null;
|
|
324
368
|
interface CatalogProps {
|
|
325
369
|
title?: string;
|
|
326
370
|
description?: string;
|
|
@@ -328,7 +372,13 @@ interface CatalogProps {
|
|
|
328
372
|
/** Permit built-in examples only while the host confirms this site is unbound. */
|
|
329
373
|
sampleProducts?: boolean;
|
|
330
374
|
}
|
|
331
|
-
|
|
375
|
+
/** The packaged catalog. Compose `CatalogRoot` and the catalog parts for a custom layout. */
|
|
376
|
+
declare function Catalog({
|
|
377
|
+
title,
|
|
378
|
+
description,
|
|
379
|
+
showHeader,
|
|
380
|
+
sampleProducts
|
|
381
|
+
}: CatalogProps): ReactElement;
|
|
332
382
|
//#endregion
|
|
333
383
|
//#region src/commerce-provider.d.ts
|
|
334
384
|
interface CommerceContextValue {
|
|
@@ -387,6 +437,69 @@ declare function CommerceStorefront({
|
|
|
387
437
|
...props
|
|
388
438
|
}: CommerceProviderProps): react_jsx_runtime0.JSX.Element;
|
|
389
439
|
//#endregion
|
|
440
|
+
//#region src/product-card.d.ts
|
|
441
|
+
/** Read-only card state for custom parts rendered inside `ProductCardRoot`. */
|
|
442
|
+
interface ProductCardState {
|
|
443
|
+
/** `null` for a built-in sample, which is not a catalog product. */
|
|
444
|
+
readonly product: SKUGroup | null;
|
|
445
|
+
readonly name: string;
|
|
446
|
+
/** The product page, or `null` for a sample, which has none. */
|
|
447
|
+
readonly href: string | null;
|
|
448
|
+
readonly isSample: boolean;
|
|
449
|
+
}
|
|
450
|
+
/** Props shared by every card part. `className` is added to the part's outer element. */
|
|
451
|
+
interface ProductCardPartProps {
|
|
452
|
+
className?: string;
|
|
453
|
+
}
|
|
454
|
+
/** Read the card's product, name, and link from inside `ProductCardRoot`. */
|
|
455
|
+
declare function useProductCard(): ProductCardState;
|
|
456
|
+
interface ProductCardRootProps {
|
|
457
|
+
children: ReactNode;
|
|
458
|
+
/** The catalog product to show. Leave it out inside `CatalogProducts`, which supplies each product. */
|
|
459
|
+
product?: SKUGroup;
|
|
460
|
+
/** Added to the root `<article>`. */
|
|
461
|
+
className?: string;
|
|
462
|
+
}
|
|
463
|
+
/** Provides one product to card parts. Inside `CatalogProducts` it renders the current catalog entry. */
|
|
464
|
+
declare function ProductCardRoot({
|
|
465
|
+
children,
|
|
466
|
+
product,
|
|
467
|
+
className
|
|
468
|
+
}: ProductCardRootProps): ReactElement;
|
|
469
|
+
/**
|
|
470
|
+
* The product's first image, linked to its page. Samples show a placeholder. With a `ProductCardTitle` in the card,
|
|
471
|
+
* the title is the one link keyboard and screen reader users get; without one, the image link is.
|
|
472
|
+
*/
|
|
473
|
+
declare function ProductCardImage({
|
|
474
|
+
className
|
|
475
|
+
}: ProductCardPartProps): ReactElement;
|
|
476
|
+
/** The product name as an H2, linked to its page. */
|
|
477
|
+
declare function ProductCardTitle({
|
|
478
|
+
className
|
|
479
|
+
}: ProductCardPartProps): ReactElement;
|
|
480
|
+
/** Up to three lines of the product description. Renders nothing without one. */
|
|
481
|
+
declare function ProductCardDescription({
|
|
482
|
+
className
|
|
483
|
+
}: ProductCardPartProps): ReactElement | null;
|
|
484
|
+
/** The product's price, or its price range when variants differ. */
|
|
485
|
+
declare function ProductCardPrice({
|
|
486
|
+
className
|
|
487
|
+
}: ProductCardPartProps): ReactElement;
|
|
488
|
+
/**
|
|
489
|
+
* Adds the product directly when it has exactly one SKU and no options; otherwise links to its page to choose.
|
|
490
|
+
* Samples add to the sample cart.
|
|
491
|
+
*/
|
|
492
|
+
declare function ProductCardAction({
|
|
493
|
+
className
|
|
494
|
+
}: ProductCardPartProps): ReactElement;
|
|
495
|
+
interface ProductCardProps {
|
|
496
|
+
product: SKUGroup;
|
|
497
|
+
}
|
|
498
|
+
/** The packaged card for one `SKUGroup`. Compose `ProductCardRoot` and the card parts for a custom card. */
|
|
499
|
+
declare function ProductCard({
|
|
500
|
+
product
|
|
501
|
+
}: ProductCardProps): ReactElement;
|
|
502
|
+
//#endregion
|
|
390
503
|
//#region src/product-details-context.d.ts
|
|
391
504
|
/** Where the shopper is in choosing a purchasable SKU. Only `ready` has a verified `selectedSku`. */
|
|
392
505
|
type ProductDetailsStatus = 'incomplete' | 'checking' | 'variant-error' | 'unavailable' | 'not-purchasable' | 'ready';
|
|
@@ -498,4 +611,4 @@ declare function ProductDetailsAddToCart({
|
|
|
498
611
|
//#region src/storefront-surface.d.ts
|
|
499
612
|
declare function CommerceStatus(): ReactElement | null;
|
|
500
613
|
//#endregion
|
|
501
|
-
export { AddToCartButton, AddToCartItemInput, ApiError, CartAddress, CartButton, CartDiscount, CartDrawer, CartLineItem, CartLineItemDetails, CartNote, CartOrder, CartSelectedAddon, CartSelectedAddonValue, CartSelectedOption, CartShippingInfo, CartSummaryTotals, CartTax, Catalog, type CatalogProps, type CommerceContextValue, CommerceProvider, type CommerceProviderProps, CommerceStatus, CommerceStorefront, Connection, ConnectionEdge, DraftOrderContext, InventoryCount, LabelFilter, LineItemTotals, MediaObject, Money, OrderTotals, PageInfo, PriceRange, ProductCard, ProductDetails, ProductDetailsAddToCart, ProductDetailsAvailability, ProductDetailsBackLink, ProductDetailsDescription, ProductDetailsGallery, ProductDetailsOption, type ProductDetailsOptionProps, type ProductDetailsOptionState, type ProductDetailsOptionValueState, ProductDetailsOptions, type ProductDetailsPartProps, ProductDetailsPrice, ProductDetailsPurchase, ProductDetailsPurchaseStatus, ProductDetailsQuantity, ProductDetailsRoot, type ProductDetailsRootProps, type ProductDetailsState, type ProductDetailsStatus, ProductDetailsTitle, ProductDetailsVariablesInput, ProductGridVariablesInput, SKU, SKUAttributeValue, SKUGroup, SKUGroupAttribute, SKUGroupAttributeValue, SKUGroupSKU, SKUPrice, SkuGroupResult, SkuGroupVariables, SkuGroupsResult, SkuGroupsVariables, SkuResult, SkuVariables, type StorefrontConfig, StorefrontProductAttribute, StorefrontProductAttributeValue, type StorefrontTheme, StringInFilter, addToCart, getAvailableInventoryQuantity, getCartSummaryTotals, getImageUrls, getLabeledSkuOptions, getPrimaryImageUrl, getProductAttributes, getSingleMatchedSku, getSingleMatchedSkuId, money, useCommerce, useProductDetails, useProductDetailsOption };
|
|
614
|
+
export { AddToCartButton, AddToCartItemInput, ApiError, CartAddress, CartButton, CartDiscount, CartDrawer, CartLineItem, CartLineItemDetails, CartNote, CartOrder, CartSelectedAddon, CartSelectedAddonValue, CartSelectedOption, CartShippingInfo, CartSummaryTotals, CartTax, Catalog, CatalogHeader, type CatalogHeaderProps, CatalogPagination, type CatalogPartProps, CatalogProducts, type CatalogProductsProps, type CatalogProps, CatalogRoot, type CatalogRootProps, CatalogSummary, type CommerceContextValue, CommerceProvider, type CommerceProviderProps, CommerceStatus, CommerceStorefront, Connection, ConnectionEdge, DraftOrderContext, InventoryCount, LabelFilter, LineItemTotals, MediaObject, Money, OrderTotals, PageInfo, PriceRange, ProductCard, ProductCardAction, ProductCardDescription, ProductCardImage, type ProductCardPartProps, ProductCardPrice, type ProductCardProps, ProductCardRoot, type ProductCardRootProps, type ProductCardState, ProductCardTitle, ProductDetails, ProductDetailsAddToCart, ProductDetailsAvailability, ProductDetailsBackLink, ProductDetailsDescription, ProductDetailsGallery, ProductDetailsOption, type ProductDetailsOptionProps, type ProductDetailsOptionState, type ProductDetailsOptionValueState, ProductDetailsOptions, type ProductDetailsPartProps, ProductDetailsPrice, ProductDetailsPurchase, ProductDetailsPurchaseStatus, ProductDetailsQuantity, ProductDetailsRoot, type ProductDetailsRootProps, type ProductDetailsState, type ProductDetailsStatus, ProductDetailsTitle, ProductDetailsVariablesInput, ProductGridVariablesInput, SKU, SKUAttributeValue, SKUGroup, SKUGroupAttribute, SKUGroupAttributeValue, SKUGroupSKU, SKUPrice, SkuGroupResult, SkuGroupVariables, SkuGroupsResult, SkuGroupsVariables, SkuResult, SkuVariables, type StorefrontConfig, StorefrontProductAttribute, StorefrontProductAttributeValue, type StorefrontTheme, StringInFilter, addToCart, getAvailableInventoryQuantity, getCartSummaryTotals, getImageUrls, getLabeledSkuOptions, getPrimaryImageUrl, getProductAttributes, getProductName, getSingleMatchedSku, getSingleMatchedSkuId, money, useCommerce, useProductCard, useProductDetails, useProductDetailsOption };
|