diff --git a/docs/faststore/components/molecules/product-card.mdx b/docs/faststore/components/molecules/product-card.mdx index d5ab62f206..a6aba344c4 100644 --- a/docs/faststore/components/molecules/product-card.mdx +++ b/docs/faststore/components/molecules/product-card.mdx @@ -1,4 +1,4 @@ ---- +--- title: "ProductCard" excerpt: Displays summarized information about a product. components: @@ -25,25 +25,7 @@ Use the `ProductCard` to: - - - {product.image[1].alternateName} - - {}} - /> - + @@ -589,6 +571,111 @@ To replicate this style, add the prop to both `ProductCard` and `ProductCardCont +### Button Click Action + + + + + + + {product.image[1].alternateName} + + console.log('Product action triggered')} + /> + + + + + ```tsx + import { useCallback, useMemo } from "react"; + import { + ProductCard, + ProductCardImage, + ProductCardContent, + } from "@faststore/ui"; + + const product = { + isVariantOf: { name: "Apple Mouse" }, + image: [ + {}, + { + url: "https://vtexhelp.vtexassets.com/assets/docs/img/faststore/product-placeholder___1e7c8f8d9f38b8a0a8f8a6a8a0f5e07d.png", + alternateName: "Apple Mouse", + }, + ], + offers: { + offers: [ + { + price: 950.04, + listPrice: 999, + availability: "https://schema.org/InStock", + }, + ], + }, + }; + + interface PriceFormatterOptions { + decimals?: boolean; + } + export const usePriceFormatter = ({ decimals }: PriceFormatterOptions = {}) => { + return useCallback( + (price: number) => + Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD", + minimumFractionDigits: decimals ? 2 : 0, + }).format(price), + [decimals] + ); + }; + export const useFormattedPrice = (price: number) => { + const formatter = usePriceFormatter(); + return useMemo(() => formatter(price), [formatter, price]); + }; + + export function Example() { + const handleClick = () => { + console.log("Product action triggered"); + }; + + return ( + + + {product.image[1].alternateName} + + + + ); + } + ``` + + + --- ## Design tokens @@ -766,7 +853,9 @@ Adjusts the bordered variant outline via border width and color for a subtle fra /> -#### Wide +### Design tokens: Wide + +Defines layout and spacing for the wide variant, covering padding, content padding, minimum width, and background color.