2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-26 21:54:03 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-10-16 15:18:29 +00:00
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import { LocaleConsumer } from "../Locale";
|
2021-04-21 09:03:57 +00:00
|
|
|
import { formatMoney, IMoney } from "../Money";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export interface MoneyRangeProps {
|
|
|
|
from?: IMoney;
|
|
|
|
to?: IMoney;
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
export const MoneyRange: React.FC<MoneyRangeProps> = ({ from, to }) => {
|
2019-08-26 21:54:03 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<LocaleConsumer>
|
2019-10-16 15:18:29 +00:00
|
|
|
{({ locale }) =>
|
2019-08-26 21:54:03 +00:00
|
|
|
from && to
|
|
|
|
? intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "{fromMoney} - {toMoney}",
|
|
|
|
description: "money"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fromMoney: formatMoney(from, locale),
|
|
|
|
toMoney: formatMoney(to, locale)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
: from && !to
|
|
|
|
? intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "from {money}",
|
|
|
|
description: "money"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
money: formatMoney(from, locale)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
: !from && to
|
|
|
|
? intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "to {money}",
|
|
|
|
description: "money"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
money: formatMoney(to, locale)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
: "-"
|
|
|
|
}
|
|
|
|
</LocaleConsumer>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
MoneyRange.displayName = "MoneyRange";
|
|
|
|
export default MoneyRange;
|