diff --git a/src/components/Breakdown.jsx b/src/components/Breakdown.jsx index 62e0de96..e6d07931 100644 --- a/src/components/Breakdown.jsx +++ b/src/components/Breakdown.jsx @@ -1,6 +1,6 @@ import clsx from "clsx"; import PropTypes from "prop-types"; -import React, { createContext, useContext } from "react"; +import React, { createContext, useContext, useMemo } from "react"; import { isNumber } from "lodash"; import { Currency } from "./Utilities/Currency"; @@ -17,9 +17,10 @@ const colors = { const CurrencyContext = createContext(); -export const Breakdown = ({ children, className, currency, ...rest }) => { +export const Breakdown = ({ children, className, currency, locale, ...rest }) => { + const value = useMemo(() => ({ currency, locale }), [currency, locale]); return ( - + {children}
@@ -31,10 +32,11 @@ Breakdown.propTypes = { children: PropTypes.node, className: PropTypes.string, currency: PropTypes.string.isRequired, + locale: PropTypes.string, }; const BreakdownItem = ({ children, info, methodIcon, secondary, value, className, color = "default", ...rest }) => { - const currency = useContext(CurrencyContext); + const { currency, locale } = useContext(CurrencyContext); return ( @@ -51,7 +53,7 @@ const BreakdownItem = ({ children, info, methodIcon, secondary, value, className {isNumber(value) ? ( - + {value} ) : ( @@ -76,7 +78,7 @@ Breakdown.Item = BreakdownItem; Breakdown.Item.displayName = "Breakdown.Item"; const BreakdownSubtotalItem = ({ children, info, value, className, color = "black", ...rest }) => { - const currency = useContext(CurrencyContext); + const { currency, locale } = useContext(CurrencyContext); return ( @@ -84,7 +86,7 @@ const BreakdownSubtotalItem = ({ children, info, value, className, color = "blac {info} - + {value} diff --git a/src/helpers/numbers.js b/src/helpers/numbers.js index 92e20edf..ee1dadf9 100644 --- a/src/helpers/numbers.js +++ b/src/helpers/numbers.js @@ -20,6 +20,7 @@ export const numberFormat = ( const style = currency ? "currency" : "decimal"; const params = { style, minimumFractionDigits: maximumFractionDigits, maximumFractionDigits }; + if (currency) { params.currency = currency; params.currencyDisplay = isNarrowSymbolForm ? "narrowSymbol" : "symbol"; diff --git a/src/stories/DataDisplay/Currency.stories.js b/src/stories/DataDisplay/Currency.stories.js index 6c62b99f..86b21144 100644 --- a/src/stories/DataDisplay/Currency.stories.js +++ b/src/stories/DataDisplay/Currency.stories.js @@ -29,7 +29,7 @@ const CurrencyStories = { description: "A locale string", type: { required: true }, control: { type: "select" }, - options: ["en-IN", "en-US", "fr-FR", "ja-JP", "de-DE", "ar-AE"], + options: ["en-IN", "en-US", "fr-FR", "ja-JP", "de-DE", "ar-AE", "en-CA", "fr-CA"], table: { type: { summary: null }, defaultValue: { summary: "Auto-detected based on browser settings" },