@pega/cosmos-react-core 9.23.0 → 9.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO9F,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,cAAc;IACrE,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,+GAA+G;IAC/G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,iBAAiB,CAAC,EAAE;QAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;QACtC;;;WAGG;QACH,QAAQ,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;QACxC;;;WAGG;QACH,QAAQ,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;QAClC;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB;;WAEG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAC9B;AAED,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,
|
|
1
|
+
{"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO9F,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,cAAc;IACrE,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,+GAA+G;IAC/G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oCAAoC;IACpC,iBAAiB,CAAC,EAAE;QAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;QACtC;;;WAGG;QACH,QAAQ,CAAC,EAAE,YAAY,GAAG,aAAa,CAAC;QACxC;;;WAGG;QACH,QAAQ,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;QAClC;;;WAGG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB;;WAEG;QACH,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B,CAAC;IACF,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAC9B;AAED,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CAqE1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from 'react';
|
|
2
|
+
import { forwardRef, useMemo } from 'react';
|
|
3
3
|
import { useConfiguration } from '../../hooks';
|
|
4
4
|
import VisuallyHiddenText from '../VisuallyHiddenText';
|
|
5
5
|
import NoValue from '../NoValue/NoValue';
|
|
6
|
-
import { formatCurrency, isValidCurrency } from './utils';
|
|
6
|
+
import { formatCurrency, getCurrencyMinimumFractionDigits, isValidCurrency } from './utils';
|
|
7
7
|
const CurrencyDisplay = forwardRef(function CurrencyDisplay({ value, currencyISOCode, formattingOptions: { currency = 'symbol', negative = 'minus-sign', notation = 'standard', groupSeparators = true, fractionDigits } = {}, ...restProps }, ref) {
|
|
8
8
|
const { locale } = useConfiguration();
|
|
9
|
-
const
|
|
9
|
+
const validCurrencyISOCode = useMemo(() => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined), [currencyISOCode]);
|
|
10
|
+
const minimumCurrencyFractionDigits = useMemo(
|
|
11
|
+
// Only relevant for 'standard' notation: 'compact' notation relies on Intl's own
|
|
12
|
+
// rounding to a small number of significant digits, which a fixed fraction digit
|
|
13
|
+
// count would defeat (e.g. preventing 999.99 from being abbreviated to 1K).
|
|
14
|
+
() => notation === 'standard'
|
|
15
|
+
? getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode)
|
|
16
|
+
: undefined, [locale, validCurrencyISOCode, notation]);
|
|
17
|
+
const options = validCurrencyISOCode
|
|
10
18
|
? {
|
|
11
19
|
style: 'currency',
|
|
12
20
|
currency: currencyISOCode,
|
|
@@ -14,8 +22,8 @@ const CurrencyDisplay = forwardRef(function CurrencyDisplay({ value, currencyISO
|
|
|
14
22
|
useGrouping: groupSeparators,
|
|
15
23
|
notation,
|
|
16
24
|
currencySign: negative === 'parentheses' ? 'accounting' : 'standard',
|
|
17
|
-
minimumFractionDigits: fractionDigits,
|
|
18
|
-
maximumFractionDigits: fractionDigits
|
|
25
|
+
minimumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits,
|
|
26
|
+
maximumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits
|
|
19
27
|
}
|
|
20
28
|
: undefined;
|
|
21
29
|
const srOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencyDisplay.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"CurrencyDisplay.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAI5C,OAAO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AqB,EAAE,cAAc,IAAI,6BAA6B;YACtE,qBAAqB,EAAE,cAAc,IAAI,6BAA6B;SACnC;QACvC,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,SAAS,GAAG;QAChB,GAAG,OAAO;QACV,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,UAAU;QACxB,eAAe,EAAE,MAAM;KACW,CAAC;IAErC,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CACtB,8BACE,8CAAmB,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAQ,EACrE,KAAC,kBAAkB,cAChB,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,GACnC,IACpB,CACJ,CAAC,CAAC,CAAC,CACF,KAAC,OAAO,KAAG,CACZ,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, useMemo } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent, NoChildrenProp } from '../../types';\nimport { useConfiguration } from '../../hooks';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport NoValue from '../NoValue/NoValue';\n\nimport { formatCurrency, getCurrencyMinimumFractionDigits, isValidCurrency } from './utils';\n\nexport interface CurrencyDisplayProps extends BaseProps, NoChildrenProp {\n /** Number value. */\n value?: number | bigint;\n /** Three letter currency shorthand ISO code. If not provided or invalid, component renders only the number. */\n currencyISOCode?: string;\n /** Options to define formatting. */\n formattingOptions?: {\n currency?: 'symbol' | 'code' | 'name';\n /**\n * Determines negative value notation: using minus sign or parentheses.\n * @default 'minus-sign'\n */\n negative?: 'minus-sign' | 'parentheses';\n /**\n * Value display notation.\n * @default 'standard'\n */\n notation?: 'standard' | 'compact';\n /**\n * Fixed number of fraction digits. Maximum is 20, default is currency dependant.\n * @default variable\n */\n fractionDigits?: number;\n /** Determines whether group separators should be shown.\n * @default true\n */\n groupSeparators?: boolean;\n };\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLAnchorElement>;\n}\n\nconst CurrencyDisplay: ForwardRefForwardPropsComponent<CurrencyDisplayProps> = forwardRef(\n function CurrencyDisplay(\n {\n value,\n currencyISOCode,\n formattingOptions: {\n currency = 'symbol',\n negative = 'minus-sign',\n notation = 'standard',\n groupSeparators = true,\n fractionDigits\n } = {},\n ...restProps\n }: PropsWithoutRef<CurrencyDisplayProps>,\n ref: CurrencyDisplayProps['ref']\n ) {\n const { locale } = useConfiguration();\n\n const validCurrencyISOCode = useMemo(\n () => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined),\n [currencyISOCode]\n );\n\n const minimumCurrencyFractionDigits = useMemo(\n // Only relevant for 'standard' notation: 'compact' notation relies on Intl's own\n // rounding to a small number of significant digits, which a fixed fraction digit\n // count would defeat (e.g. preventing 999.99 from being abbreviated to 1K).\n () =>\n notation === 'standard'\n ? getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode)\n : undefined,\n [locale, validCurrencyISOCode, notation]\n );\n\n const options = validCurrencyISOCode\n ? ({\n style: 'currency',\n currency: currencyISOCode,\n currencyDisplay: currency,\n useGrouping: groupSeparators,\n notation,\n currencySign: negative === 'parentheses' ? 'accounting' : 'standard',\n minimumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits,\n maximumFractionDigits: fractionDigits ?? minimumCurrencyFractionDigits\n } satisfies Intl.NumberFormatOptions)\n : undefined;\n\n const srOptions = {\n ...options,\n useGrouping: false,\n currencySign: 'standard',\n currencyDisplay: 'name'\n } satisfies Intl.NumberFormatOptions;\n\n return (\n <span ref={ref} {...restProps}>\n {value || value === 0 ? (\n <>\n <span aria-hidden>{formatCurrency(value, { locale, options })}</span>\n <VisuallyHiddenText>\n {formatCurrency(value, { locale, options: srOptions })}\n </VisuallyHiddenText>\n </>\n ) : (\n <NoValue />\n )}\n </span>\n );\n }\n);\n\nexport default CurrencyDisplay;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/cosmos-react-core",
|
|
3
|
-
"version": "9.23.
|
|
3
|
+
"version": "9.23.2",
|
|
4
4
|
"description": "Cosmos is a visual design system and UI component collection. Its goal is to empower application developers in their pursuit to create engaging and rewarding user experiences.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Pegasystems",
|