Documentation
Feedback
Guides
Storefront Development

Storefront Development
Storefront development
ProductPrice

Displays the product's listing and spot price.

The ProductPrice component displays both the listing price and spot price of a product. It wraps two Price components. The ProductPrice component wraps two instances of the Price component, representing the prices with the spot and listing variants.
  • If the spot price and listing price are the same, only the spot price is shown.
  • If the listing price is set to 0, only the spot price is shown.
Example
Code
Original price:$999Price:$950.04

Usage

Import the component


_10
import { ProductPrice } from "@faststore/ui";

Import styles

To apply styles, include the following in your stylesheet:

_10
@import "@faststore/ui/src/components/molecules/ProductPrice/styles.scss";


Examples

Example
Code
Original price:$999Price:$950.04

Example of price formatter function


_22
// Example of formatter
_22
interface PriceFormatterOptions {
_22
decimals?: boolean;
_22
}
_22
_22
export const usePriceFormatter = ({ decimals }: PriceFormatterOptions = {}) => {
_22
return useCallback(
_22
(price: number) =>
_22
Intl.NumberFormat("en-US", {
_22
style: "currency",
_22
currency: "USD",
_22
minimumFractionDigits: decimals ? 2 : 0,
_22
}).format(price),
_22
[decimals]
_22
);
_22
};
_22
_22
export const useFormattedPrice = (price: number) => {
_22
const formatter = usePriceFormatter();
_22
_22
return useMemo(() => formatter(price), [formatter, price]);
_22
};


Design tokens

Local tokenDefault value/Global token linked
--fs-product-price-gapvar(--fs-spacing-1)

Data attributes

You can target and override ProductPrice styles using the following data attributes:
data-fs-product-price

Props

NameTypeDescriptionDefault
value*numberSpecifies product's raw price value.
listPrice*numberSpecifies product's listing price.
formatterPriceFormatterFormatter function that transforms the raw price value and render the result.
testIdstringID to find this component in testing tools (e.g.: cypress, testing-library, and jest).fs-product-price

Contributors
2
Photo of the contributor
Photo of the contributor
Was this helpful?
Yes
No
Suggest Edits (GitHub)
Contributors
2
Photo of the contributor
Photo of the contributor
On this page