Skip to content

Commit

Permalink
Merge branch 'master' into X2-6273
Browse files Browse the repository at this point in the history
  • Loading branch information
SemenStruchev authored Jan 14, 2024
2 parents 7c7229e + 6a615b4 commit 155a864
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xola/ui-kit",
"version": "2.1.38",
"version": "2.1.39",
"description": "Xola UI Kit",
"license": "MIT",
"files": [
Expand Down
17 changes: 10 additions & 7 deletions src/components/Breakdown.jsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 (
<CurrencyContext.Provider value={currency}>
<CurrencyContext.Provider value={value}>
<table className={clsx("ui-breakdown", "w-full", className)} {...rest}>
<tbody>{children}</tbody>
</table>
Expand All @@ -31,10 +32,12 @@ 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);
/** When BreakdownItem is directly used without outer <Breakdown /> component, the context would be `undefined` */
const { currency, locale } = useContext(CurrencyContext) ?? {};

return (
<tr className={clsx("ui-breakdown-item", colors[color], className)} {...rest}>
Expand All @@ -57,7 +60,7 @@ const BreakdownItem = ({ children, info, methodIcon, secondary, value, className

<td className="w-[1%] whitespace-nowrap pl-4 text-right">
{isNumber(value) ? (
<Currency shouldRemoveTrailingZeroes={false} currency={currency}>
<Currency shouldRemoveTrailingZeroes={false} currency={currency} locale={locale}>
{value}
</Currency>
) : (
Expand All @@ -82,15 +85,15 @@ 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 (
<tr className={clsx("ui-breakdown-subtotal-item", "font-bold", colors[color], className)} {...rest}>
<td className="pt-1 pb-4 text-left">{children}</td>
<td className="whitespace-nowrap pt-1 pb-4 text-right">{info}</td>

<td className="w-[1%] whitespace-nowrap pt-1 pb-4 pl-4 text-right">
<Currency shouldRemoveTrailingZeroes={false} currency={currency}>
<Currency shouldRemoveTrailingZeroes={false} currency={currency} locale={locale}>
{value}
</Currency>
</td>
Expand Down
1 change: 1 addition & 0 deletions src/helpers/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/stories/DataDisplay/Currency.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down

0 comments on commit 155a864

Please sign in to comment.