@nicolassancho/storybook-core 3.0.11 → 3.0.13

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.
@@ -18,7 +18,7 @@ const productCardStyles = tv({
18
18
  action: "relative z-10 mt-2",
19
19
  },
20
20
  });
21
- export const ProductCard = ({ imageUrl, title, brand, price, tag, buttonLabel = "Add to Cart", onClick = undefined, onProductClick, href, LinkComponent = "a", ImageComponent, imageProps, className, }) => {
21
+ export const ProductCard = ({ imageUrl, title, brand, price, tag, buttonLabel = "Add to Cart", onClick, onProductClick, href, LinkComponent = "a", ImageComponent, imageProps, className, }) => {
22
22
  const styles = productCardStyles();
23
23
  let titleContent = title;
24
24
  if (href) {
@@ -15,6 +15,10 @@ export interface ProductGridProps {
15
15
  * `ImageComponent`. See `ProductCard`.
16
16
  */
17
17
  ImageComponent?: ProductCardProps["ImageComponent"];
18
+ /**
19
+ * Returns the click handler for a product, called with the product and its index. It is
20
+ * the fallback: a product that sets its own `onProductClick` keeps it. See `ProductCard`.
21
+ */
18
22
  getOnProductClick?: (product: ProductCardProps, index: number) => () => void;
19
23
  }
20
24
  export declare const ProductGrid: React.FC<ProductGridProps>;
@@ -5,10 +5,9 @@ import { ProductCard } from "../../Molecules/ProductCard/ProductCard";
5
5
  const productGridStyles = tv({
6
6
  base: "xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4",
7
7
  });
8
- export const ProductGrid = ({ products, columns = 3, gap = "medium", className, LinkComponent, ImageComponent, getOnProductClick = () => undefined, // optional click handler for each product card
9
- }) => {
8
+ export const ProductGrid = ({ products, columns = 3, gap = "medium", className, LinkComponent, ImageComponent, getOnProductClick, }) => {
10
9
  return (_jsx(Grid, { columns: columns, gap: gap, className: productGridStyles({ className }), children: products.map((product, idx) => {
11
- var _a;
12
- return (_jsx(ProductCard, Object.assign({ LinkComponent: LinkComponent, ImageComponent: ImageComponent }, product, { onProductClick: getOnProductClick === null || getOnProductClick === void 0 ? void 0 : getOnProductClick(product, idx) }), (_a = product.id) !== null && _a !== void 0 ? _a : product.title));
10
+ var _a, _b;
11
+ return (_jsx(ProductCard, Object.assign({ LinkComponent: LinkComponent, ImageComponent: ImageComponent }, product, { onProductClick: (_a = product.onProductClick) !== null && _a !== void 0 ? _a : getOnProductClick === null || getOnProductClick === void 0 ? void 0 : getOnProductClick(product, idx) }), (_b = product.id) !== null && _b !== void 0 ? _b : product.title));
13
12
  }) }));
14
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicolassancho/storybook-core",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "description": "Accessible React + Tailwind component library built with tailwind-variants and documented in Storybook.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",