@pega/cosmos-react-core 10.0.0-build.4.3 → 10.0.0-build.4.30

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.
Files changed (283) hide show
  1. package/lib/components/AppShell/AppHeader.d.ts.map +1 -1
  2. package/lib/components/AppShell/AppHeader.js +44 -7
  3. package/lib/components/AppShell/AppHeader.js.map +1 -1
  4. package/lib/components/AppShell/AppHeader.styles.d.ts +6 -2
  5. package/lib/components/AppShell/AppHeader.styles.d.ts.map +1 -1
  6. package/lib/components/AppShell/AppHeader.styles.js +36 -18
  7. package/lib/components/AppShell/AppHeader.styles.js.map +1 -1
  8. package/lib/components/AppShell/AppNavigationPanel.js +1 -1
  9. package/lib/components/AppShell/AppNavigationPanel.js.map +1 -1
  10. package/lib/components/AppShell/AppShell.d.ts.map +1 -1
  11. package/lib/components/AppShell/AppShell.js +27 -9
  12. package/lib/components/AppShell/AppShell.js.map +1 -1
  13. package/lib/components/AppShell/AppShellContext.d.ts +1 -0
  14. package/lib/components/AppShell/AppShellContext.d.ts.map +1 -1
  15. package/lib/components/AppShell/AppShellContext.js +1 -0
  16. package/lib/components/AppShell/AppShellContext.js.map +1 -1
  17. package/lib/components/AppShell/AppShellList.js +1 -1
  18. package/lib/components/AppShell/AppShellList.js.map +1 -1
  19. package/lib/components/AppShell/NavigationList.d.ts.map +1 -1
  20. package/lib/components/AppShell/NavigationList.js +3 -2
  21. package/lib/components/AppShell/NavigationList.js.map +1 -1
  22. package/lib/components/AppShell/NavigationListItemWrapper.d.ts.map +1 -1
  23. package/lib/components/AppShell/NavigationListItemWrapper.js +87 -48
  24. package/lib/components/AppShell/NavigationListItemWrapper.js.map +1 -1
  25. package/lib/components/Avatar/Avatar.d.ts +1 -1
  26. package/lib/components/Avatar/Avatar.d.ts.map +1 -1
  27. package/lib/components/Avatar/Avatar.js.map +1 -1
  28. package/lib/components/Badges/Selection.js +1 -1
  29. package/lib/components/Badges/Selection.js.map +1 -1
  30. package/lib/components/ComboBox/ComboBox.d.ts.map +1 -1
  31. package/lib/components/ComboBox/ComboBox.js +3 -6
  32. package/lib/components/ComboBox/ComboBox.js.map +1 -1
  33. package/lib/components/ComboBox/ComboBox.styles.d.ts.map +1 -1
  34. package/lib/components/ComboBox/ComboBox.styles.js +6 -1
  35. package/lib/components/ComboBox/ComboBox.styles.js.map +1 -1
  36. package/lib/components/ComboBox/ComboBoxInput.d.ts +0 -2
  37. package/lib/components/ComboBox/ComboBoxInput.d.ts.map +1 -1
  38. package/lib/components/ComboBox/ComboBoxInput.js +2 -2
  39. package/lib/components/ComboBox/ComboBoxInput.js.map +1 -1
  40. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.d.ts +4 -6
  41. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.d.ts.map +1 -1
  42. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js +96 -189
  43. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.js.map +1 -1
  44. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.styles.d.ts +190 -0
  45. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.styles.d.ts.map +1 -0
  46. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.styles.js +72 -0
  47. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.styles.js.map +1 -0
  48. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.types.d.ts +0 -2
  49. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.types.d.ts.map +1 -1
  50. package/lib/components/ComboBox/MultiSelectInput/MultiSelectInput.types.js.map +1 -1
  51. package/lib/components/Configuration/Configuration.d.ts.map +1 -1
  52. package/lib/components/Configuration/Configuration.js +3 -1
  53. package/lib/components/Configuration/Configuration.js.map +1 -1
  54. package/lib/components/Currency/CurrencyDisplay.d.ts.map +1 -1
  55. package/lib/components/Currency/CurrencyDisplay.js +13 -5
  56. package/lib/components/Currency/CurrencyDisplay.js.map +1 -1
  57. package/lib/components/Currency/CurrencyInput.d.ts.map +1 -1
  58. package/lib/components/Currency/CurrencyInput.js +19 -12
  59. package/lib/components/Currency/CurrencyInput.js.map +1 -1
  60. package/lib/components/Currency/utils.d.ts +8 -0
  61. package/lib/components/Currency/utils.d.ts.map +1 -1
  62. package/lib/components/Currency/utils.js +34 -4
  63. package/lib/components/Currency/utils.js.map +1 -1
  64. package/lib/components/DateTime/DateTimeDisplay.d.ts +2 -2
  65. package/lib/components/DateTime/DateTimeDisplay.d.ts.map +1 -1
  66. package/lib/components/DateTime/DateTimeDisplay.js +29 -4
  67. package/lib/components/DateTime/DateTimeDisplay.js.map +1 -1
  68. package/lib/components/DateTime/Input/DateInput.d.ts.map +1 -1
  69. package/lib/components/DateTime/Input/DateInput.js +7 -7
  70. package/lib/components/DateTime/Input/DateInput.js.map +1 -1
  71. package/lib/components/DateTime/Input/DateRangeInput.d.ts.map +1 -1
  72. package/lib/components/DateTime/Input/DateRangeInput.js +8 -2
  73. package/lib/components/DateTime/Input/DateRangeInput.js.map +1 -1
  74. package/lib/components/DateTime/Input/DateTimeInput.d.ts +1 -1
  75. package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
  76. package/lib/components/DateTime/Input/DateTimeInput.js +8 -8
  77. package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
  78. package/lib/components/DateTime/Input/MonthInput.js +2 -2
  79. package/lib/components/DateTime/Input/MonthInput.js.map +1 -1
  80. package/lib/components/DateTime/Input/QuarterInput.js +2 -2
  81. package/lib/components/DateTime/Input/QuarterInput.js.map +1 -1
  82. package/lib/components/DateTime/Input/TimeInput.d.ts.map +1 -1
  83. package/lib/components/DateTime/Input/TimeInput.js +3 -3
  84. package/lib/components/DateTime/Input/TimeInput.js.map +1 -1
  85. package/lib/components/DateTime/Input/TimeRangeInput.d.ts.map +1 -1
  86. package/lib/components/DateTime/Input/TimeRangeInput.js +12 -4
  87. package/lib/components/DateTime/Input/TimeRangeInput.js.map +1 -1
  88. package/lib/components/DateTime/Input/WeekInput.d.ts.map +1 -1
  89. package/lib/components/DateTime/Input/WeekInput.js +2 -2
  90. package/lib/components/DateTime/Input/WeekInput.js.map +1 -1
  91. package/lib/components/DateTime/Input/utils.d.ts +6 -0
  92. package/lib/components/DateTime/Input/utils.d.ts.map +1 -1
  93. package/lib/components/DateTime/Input/utils.js +47 -0
  94. package/lib/components/DateTime/Input/utils.js.map +1 -1
  95. package/lib/components/DateTime/utils.d.ts +15 -4
  96. package/lib/components/DateTime/utils.d.ts.map +1 -1
  97. package/lib/components/DateTime/utils.js +24 -3
  98. package/lib/components/DateTime/utils.js.map +1 -1
  99. package/lib/components/Dialog/InfoDialogWrapper.d.ts +4 -0
  100. package/lib/components/Dialog/InfoDialogWrapper.d.ts.map +1 -0
  101. package/lib/components/Dialog/InfoDialogWrapper.js +13 -0
  102. package/lib/components/Dialog/InfoDialogWrapper.js.map +1 -0
  103. package/lib/components/Dialog/TouchDialog.d.ts +5 -0
  104. package/lib/components/Dialog/TouchDialog.d.ts.map +1 -0
  105. package/lib/components/Dialog/TouchDialog.js +85 -0
  106. package/lib/components/Dialog/TouchDialog.js.map +1 -0
  107. package/lib/components/Dialog/TouchDialog.styles.d.ts +7 -0
  108. package/lib/components/Dialog/TouchDialog.styles.d.ts.map +1 -0
  109. package/lib/components/Dialog/TouchDialog.styles.js +62 -0
  110. package/lib/components/Dialog/TouchDialog.styles.js.map +1 -0
  111. package/lib/components/Dialog/TouchDialog.test-ids.d.ts +2 -0
  112. package/lib/components/Dialog/TouchDialog.test-ids.d.ts.map +1 -0
  113. package/lib/components/Dialog/TouchDialog.test-ids.js +3 -0
  114. package/lib/components/Dialog/TouchDialog.test-ids.js.map +1 -0
  115. package/lib/components/Dialog/TouchDialog.types.d.ts +42 -0
  116. package/lib/components/Dialog/TouchDialog.types.d.ts.map +1 -0
  117. package/lib/components/Dialog/TouchDialog.types.js +2 -0
  118. package/lib/components/Dialog/TouchDialog.types.js.map +1 -0
  119. package/lib/components/Dialog/TouchInfoDialog.d.ts +4 -0
  120. package/lib/components/Dialog/TouchInfoDialog.d.ts.map +1 -0
  121. package/lib/components/Dialog/TouchInfoDialog.js +14 -0
  122. package/lib/components/Dialog/TouchInfoDialog.js.map +1 -0
  123. package/lib/components/Dialog/index.d.ts +4 -1
  124. package/lib/components/Dialog/index.d.ts.map +1 -1
  125. package/lib/components/Dialog/index.js +3 -1
  126. package/lib/components/Dialog/index.js.map +1 -1
  127. package/lib/components/FieldGroup/FieldGroup.d.ts +12 -7
  128. package/lib/components/FieldGroup/FieldGroup.d.ts.map +1 -1
  129. package/lib/components/FieldGroup/FieldGroup.js +28 -25
  130. package/lib/components/FieldGroup/FieldGroup.js.map +1 -1
  131. package/lib/components/FieldGroup/FieldGroupList.js +1 -1
  132. package/lib/components/FieldGroup/FieldGroupList.js.map +1 -1
  133. package/lib/components/FieldValueList/FieldValueList.d.ts +3 -1
  134. package/lib/components/FieldValueList/FieldValueList.d.ts.map +1 -1
  135. package/lib/components/FieldValueList/FieldValueList.js +15 -6
  136. package/lib/components/FieldValueList/FieldValueList.js.map +1 -1
  137. package/lib/components/File/CompactList.js +1 -1
  138. package/lib/components/File/CompactList.js.map +1 -1
  139. package/lib/components/File/FileItem.d.ts +38 -0
  140. package/lib/components/File/FileItem.d.ts.map +1 -1
  141. package/lib/components/File/FileItem.js +167 -23
  142. package/lib/components/File/FileItem.js.map +1 -1
  143. package/lib/components/File/FileList.d.ts.map +1 -1
  144. package/lib/components/File/FileList.js +6 -2
  145. package/lib/components/File/FileList.js.map +1 -1
  146. package/lib/components/File/index.d.ts +1 -1
  147. package/lib/components/File/index.d.ts.map +1 -1
  148. package/lib/components/File/index.js.map +1 -1
  149. package/lib/components/File/mimeTypes.json +1 -0
  150. package/lib/components/FormField/FormField.d.ts +9 -1
  151. package/lib/components/FormField/FormField.d.ts.map +1 -1
  152. package/lib/components/FormField/FormField.js +26 -10
  153. package/lib/components/FormField/FormField.js.map +1 -1
  154. package/lib/components/Icon/Icon.d.ts +5 -0
  155. package/lib/components/Icon/Icon.d.ts.map +1 -1
  156. package/lib/components/Icon/Icon.js +44 -4
  157. package/lib/components/Icon/Icon.js.map +1 -1
  158. package/lib/components/Icon/iconNames.d.ts +1 -0
  159. package/lib/components/Icon/iconNames.d.ts.map +1 -1
  160. package/lib/components/Icon/iconNames.js +1 -0
  161. package/lib/components/Icon/iconNames.js.map +1 -1
  162. package/lib/components/Icon/icons/search-solid.icon.d.ts +1 -1
  163. package/lib/components/Icon/icons/search-solid.icon.js +3 -3
  164. package/lib/components/Icon/icons/search-solid.icon.js.map +1 -1
  165. package/lib/components/Icon/streamlineIconNames.d.ts +1 -0
  166. package/lib/components/Icon/streamlineIconNames.d.ts.map +1 -1
  167. package/lib/components/Icon/streamlineIconNames.js +1 -0
  168. package/lib/components/Icon/streamlineIconNames.js.map +1 -1
  169. package/lib/components/Link/Link.d.ts +6 -13
  170. package/lib/components/Link/Link.d.ts.map +1 -1
  171. package/lib/components/Link/Link.js.map +1 -1
  172. package/lib/components/ListToolbar/ListToolbar.d.ts.map +1 -1
  173. package/lib/components/ListToolbar/ListToolbar.js +1 -1
  174. package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
  175. package/lib/components/ListToolbar/PresetMenuPopover.d.ts.map +1 -1
  176. package/lib/components/ListToolbar/PresetMenuPopover.js +16 -5
  177. package/lib/components/ListToolbar/PresetMenuPopover.js.map +1 -1
  178. package/lib/components/MenuButton/MenuButton.d.ts.map +1 -1
  179. package/lib/components/MenuButton/MenuButton.js +33 -7
  180. package/lib/components/MenuButton/MenuButton.js.map +1 -1
  181. package/lib/components/MultiStepForm/FormProgress.styles.d.ts +25 -1
  182. package/lib/components/MultiStepForm/FormProgress.styles.d.ts.map +1 -1
  183. package/lib/components/MultiStepForm/FormProgress.styles.js +168 -5
  184. package/lib/components/MultiStepForm/FormProgress.styles.js.map +1 -1
  185. package/lib/components/MultiStepForm/HorizontalFormProgress.d.ts +2 -2
  186. package/lib/components/MultiStepForm/HorizontalFormProgress.d.ts.map +1 -1
  187. package/lib/components/MultiStepForm/HorizontalFormProgress.js +48 -22
  188. package/lib/components/MultiStepForm/HorizontalFormProgress.js.map +1 -1
  189. package/lib/components/MultiStepForm/MultiStepForm.d.ts.map +1 -1
  190. package/lib/components/MultiStepForm/MultiStepForm.js +2 -2
  191. package/lib/components/MultiStepForm/MultiStepForm.js.map +1 -1
  192. package/lib/components/MultiStepForm/MultiStepForm.types.d.ts +5 -0
  193. package/lib/components/MultiStepForm/MultiStepForm.types.d.ts.map +1 -1
  194. package/lib/components/MultiStepForm/MultiStepForm.types.js.map +1 -1
  195. package/lib/components/MultiStepForm/VerticalFormProgress.d.ts +2 -2
  196. package/lib/components/MultiStepForm/VerticalFormProgress.d.ts.map +1 -1
  197. package/lib/components/MultiStepForm/VerticalFormProgress.js +45 -20
  198. package/lib/components/MultiStepForm/VerticalFormProgress.js.map +1 -1
  199. package/lib/components/MultiStepForm/useFormProgressOverflow.d.ts +1 -1
  200. package/lib/components/MultiStepForm/useFormProgressOverflow.d.ts.map +1 -1
  201. package/lib/components/MultiStepForm/useFormProgressOverflow.js +17 -9
  202. package/lib/components/MultiStepForm/useFormProgressOverflow.js.map +1 -1
  203. package/lib/components/Number/utils.js +1 -1
  204. package/lib/components/Number/utils.js.map +1 -1
  205. package/lib/components/PageTemplates/PageTemplates.js +1 -1
  206. package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
  207. package/lib/components/RadioCheckGroup/RadioCheckGroup.d.ts.map +1 -1
  208. package/lib/components/RadioCheckGroup/RadioCheckGroup.js +1 -1
  209. package/lib/components/RadioCheckGroup/RadioCheckGroup.js.map +1 -1
  210. package/lib/components/Scanner/Scanner.d.ts +21 -0
  211. package/lib/components/Scanner/Scanner.d.ts.map +1 -0
  212. package/lib/components/Scanner/Scanner.js +177 -0
  213. package/lib/components/Scanner/Scanner.js.map +1 -0
  214. package/lib/components/Scanner/Scanner.styles.d.ts +4 -0
  215. package/lib/components/Scanner/Scanner.styles.d.ts.map +1 -0
  216. package/lib/components/Scanner/Scanner.styles.js +17 -0
  217. package/lib/components/Scanner/Scanner.styles.js.map +1 -0
  218. package/lib/components/Scanner/Scanner.test-ids.d.ts +2 -0
  219. package/lib/components/Scanner/Scanner.test-ids.d.ts.map +1 -0
  220. package/lib/components/Scanner/Scanner.test-ids.js +3 -0
  221. package/lib/components/Scanner/Scanner.test-ids.js.map +1 -0
  222. package/lib/components/Scanner/index.d.ts +3 -0
  223. package/lib/components/Scanner/index.d.ts.map +1 -0
  224. package/lib/components/Scanner/index.js +2 -0
  225. package/lib/components/Scanner/index.js.map +1 -0
  226. package/lib/components/SelectionCard/SelectionCard.d.ts +1 -1
  227. package/lib/components/SelectionCard/SelectionCard.d.ts.map +1 -1
  228. package/lib/components/SelectionCard/SelectionCard.js +3 -3
  229. package/lib/components/SelectionCard/SelectionCard.js.map +1 -1
  230. package/lib/components/SelectionCard/SelectionCardDisplay.d.ts +5 -0
  231. package/lib/components/SelectionCard/SelectionCardDisplay.d.ts.map +1 -1
  232. package/lib/components/SelectionCard/SelectionCardDisplay.js +4 -2
  233. package/lib/components/SelectionCard/SelectionCardDisplay.js.map +1 -1
  234. package/lib/components/SpeechToTextButton/SpeechToTextButton.js +1 -1
  235. package/lib/components/SpeechToTextButton/SpeechToTextButton.js.map +1 -1
  236. package/lib/components/SummaryList/SummaryList.d.ts.map +1 -1
  237. package/lib/components/SummaryList/SummaryList.js +8 -4
  238. package/lib/components/SummaryList/SummaryList.js.map +1 -1
  239. package/lib/components/TextArea/TextArea.d.ts.map +1 -1
  240. package/lib/components/TextArea/TextArea.js +7 -21
  241. package/lib/components/TextArea/TextArea.js.map +1 -1
  242. package/lib/components/TextArea/TextArea.styles.d.ts +0 -1
  243. package/lib/components/TextArea/TextArea.styles.d.ts.map +1 -1
  244. package/lib/components/TextArea/TextArea.styles.js +1 -2
  245. package/lib/components/TextArea/TextArea.styles.js.map +1 -1
  246. package/lib/hooks/useI18n.d.ts +22 -9
  247. package/lib/hooks/useI18n.d.ts.map +1 -1
  248. package/lib/i18n/default.d.ts +22 -10
  249. package/lib/i18n/default.d.ts.map +1 -1
  250. package/lib/i18n/default.js +25 -12
  251. package/lib/i18n/default.js.map +1 -1
  252. package/lib/i18n/i18n.d.ts +22 -9
  253. package/lib/i18n/i18n.d.ts.map +1 -1
  254. package/lib/index.d.ts +2 -0
  255. package/lib/index.d.ts.map +1 -1
  256. package/lib/index.js +2 -0
  257. package/lib/index.js.map +1 -1
  258. package/lib/styles/GlobalStyle.d.ts.map +1 -1
  259. package/lib/styles/GlobalStyle.js +3 -3
  260. package/lib/styles/GlobalStyle.js.map +1 -1
  261. package/lib/theme/index.d.ts +2 -0
  262. package/lib/theme/index.d.ts.map +1 -1
  263. package/lib/theme/index.js +2 -0
  264. package/lib/theme/index.js.map +1 -1
  265. package/lib/theme/theme.d.ts +48 -0
  266. package/lib/theme/theme.d.ts.map +1 -1
  267. package/lib/theme/themeDefinition.json +26 -0
  268. package/lib/theme/themeOverrides.schema.json +36 -0
  269. package/lib/theme/themes/aurigaDarkTheme.json +74 -62
  270. package/lib/theme/themes/aurigaTheme.json +61 -56
  271. package/lib/theme/themes/velaDarkTheme.json +175 -0
  272. package/lib/theme/themes/velaTheme.json +169 -0
  273. package/lib/theme/themes/virgoDarkTheme.json +2 -2
  274. package/lib/theme/themes/virgoTheme.json +3 -3
  275. package/lib/utils/index.d.ts +1 -0
  276. package/lib/utils/index.d.ts.map +1 -1
  277. package/lib/utils/index.js +1 -0
  278. package/lib/utils/index.js.map +1 -1
  279. package/lib/utils/isTouchDevice.d.ts +3 -0
  280. package/lib/utils/isTouchDevice.d.ts.map +1 -0
  281. package/lib/utils/isTouchDevice.js +4 -0
  282. package/lib/utils/isTouchDevice.js.map +1 -0
  283. package/package.json +3 -2
@@ -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 options = currencyISOCode && isValidCurrency(currencyISOCode)
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,U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E,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 } 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, 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 options =\n currencyISOCode && isValidCurrency(currencyISOCode)\n ? ({\n style: 'currency',\n currency: currencyISOCode,\n currencyDisplay: currency,\n useGrouping: groupSeparators,\n notation,\n currencySign: negative === 'parentheses' ? 'accounting' : 'standard',\n minimumFractionDigits: fractionDigits,\n maximumFractionDigits: fractionDigits\n } as 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"]}
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,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,gCAAgC,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAkC5F,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,eAAe,EACf,iBAAiB,EAAE,EACjB,QAAQ,GAAG,QAAQ,EACnB,QAAQ,GAAG,YAAY,EACvB,QAAQ,GAAG,UAAU,EACrB,eAAe,GAAG,IAAI,EACtB,cAAc,EACf,GAAG,EAAE,EACN,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAEtC,MAAM,oBAAoB,GAAG,OAAO,CAClC,GAAG,EAA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AAC,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyInput.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAmBnE,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAC;;;;AA0M5D,wBAAmE"}
1
+ {"version":3,"file":"CurrencyInput.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAmBnE,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAC;;;;AAkN5D,wBAAmE"}
@@ -10,39 +10,43 @@ import { getCurrencyMinimumFractionDigits, getFormattedValue, isValidCurrency }
10
10
  import { getCurrencyInputTestIds } from './Currency.test-ids';
11
11
  const CurrencyInput = forwardRef(function CurrencyInput(props, ref) {
12
12
  const uid = useUID();
13
- const { testId, id = uid, status, label, labelHidden, info, required, disabled, readOnly, additionalInfo, value: valueProp = '', onChange, onBlur, onFocus, suggestion, currencyISOCode, showDecimal = true, showGroupSeparators = true, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, step = 1, alwaysShowISOCode = false, maximumFractionDigits = 0, className, ...restProps } = props;
13
+ const { testId, id = uid, status, label, labelHidden, info, required, disabled, readOnly, additionalInfo, value: valueProp = '', onChange, onBlur, onFocus, suggestion, currencyISOCode, showDecimal = true, showGroupSeparators = true, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, step = 1, alwaysShowISOCode = false, minimumFractionDigits: minimumFractionDigitsProp, maximumFractionDigits: maximumFractionDigitsProp, className, ...restProps } = props;
14
14
  const descriptionId = useUID();
15
15
  const testIds = useTestIds(testId, getCurrencyInputTestIds);
16
16
  const { locale } = useConfiguration();
17
17
  const t = useI18n();
18
18
  const inputRef = useConsolidatedRef(ref);
19
19
  const validCurrencyISOCode = useMemo(() => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined), [currencyISOCode]);
20
- const minimumFractionDigits = useMemo(() => getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode), [locale, validCurrencyISOCode]);
21
- const numberOfDecimals = showDecimal
22
- ? Math.max(maximumFractionDigits, minimumFractionDigits)
20
+ const minimumCurrencyFractionDigits = useMemo(() => getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode), [locale, validCurrencyISOCode]);
21
+ const minimumFractionDigits = showDecimal
22
+ ? minimumFractionDigitsProp ?? minimumCurrencyFractionDigits
23
+ : 0;
24
+ const maximumFractionDigits = showDecimal
25
+ ? maximumFractionDigitsProp ?? Math.max(minimumCurrencyFractionDigits, minimumFractionDigits)
23
26
  : 0;
24
27
  const decimalSign = useMemo(() => getDecimalSign(locale, {
25
28
  numberingSystem: 'latn',
26
29
  style: validCurrencyISOCode ? 'currency' : undefined,
27
- currency: validCurrencyISOCode
28
- }), [locale, validCurrencyISOCode]);
30
+ currency: validCurrencyISOCode,
31
+ maximumFractionDigits
32
+ }), [locale, validCurrencyISOCode, maximumFractionDigits]);
29
33
  // on initial render only pad the value with 0 if necessary
30
34
  const rendered = usePrevious(true);
31
35
  let value = valueProp;
32
36
  if (!rendered && validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {
33
37
  const [integer, fraction = ''] = value.split('.');
34
- value = `${integer}.${fraction.padEnd(numberOfDecimals, '0')}`;
38
+ value = `${integer}.${fraction.padEnd(minimumFractionDigits, '0')}`;
35
39
  }
36
40
  const formatValue = useCallback((number) => {
37
41
  return getFormattedValue(number, locale, validCurrencyISOCode, {
38
42
  showGroupSeparators,
39
43
  showAs: alwaysShowISOCode ? 'code' : 'symbol',
40
- numberOfDecimals
44
+ numberOfDecimals: maximumFractionDigits
41
45
  });
42
- }, [alwaysShowISOCode, numberOfDecimals, showGroupSeparators, locale, validCurrencyISOCode]);
46
+ }, [alwaysShowISOCode, maximumFractionDigits, showGroupSeparators, locale, validCurrencyISOCode]);
43
47
  const onInputChange = (e) => {
44
48
  const inputValue = e.target.value;
45
- const cleanedInputValue = getCleanedValue(inputValue, decimalSign, numberOfDecimals);
49
+ const cleanedInputValue = getCleanedValue(inputValue, decimalSign, maximumFractionDigits);
46
50
  if (cleanedInputValue === value)
47
51
  return;
48
52
  onChange(cleanedInputValue);
@@ -71,7 +75,7 @@ const CurrencyInput = forwardRef(function CurrencyInput(props, ref) {
71
75
  }
72
76
  else if (input.selectionStart !== null &&
73
77
  !input.value.charAt(input.selectionStart - 1).match(/\d/)) {
74
- onChange(getCleanedValue(`${input.value}0${decimalSign}`, decimalSign, numberOfDecimals));
78
+ onChange(getCleanedValue(`${input.value}0${decimalSign}`, decimalSign, maximumFractionDigits));
75
79
  e.preventDefault();
76
80
  }
77
81
  break;
@@ -86,7 +90,10 @@ const CurrencyInput = forwardRef(function CurrencyInput(props, ref) {
86
90
  let parsableValue = value;
87
91
  if (validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {
88
92
  const [integer, fraction = ''] = value.split('.');
89
- parsableValue = `${integer}.${fraction.padEnd(numberOfDecimals, '0')}`;
93
+ const numberOfDecimals = Math.min(minimumFractionDigits, maximumFractionDigits);
94
+ if (fraction.length < numberOfDecimals) {
95
+ parsableValue = `${integer}.${fraction.padEnd(numberOfDecimals, '0')}`;
96
+ }
90
97
  }
91
98
  if (e.type === 'focus')
92
99
  onFocus?.(parsableValue);
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,OAAO,EACP,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,mBAAmB,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,gCAAgC,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,MAAM,aAAa,GAAwD,UAAU,CACnF,SAAS,aAAa,CACpB,KAA0C,EAC1C,GAA8B;IAE9B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MA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AAE,EACN,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,KACV,SAAS,EACb,UAAU,EAAE,UAAU,EACtB,SAAS,EAAC,SAAS,EACnB,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,iBAAiB,sBACP,oBAAoB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,EAClE,SAAS,EAAE,eAAe,CAAC,gBAAgB,EAAE,SAAS,CAAC,GACvD,EACD,oBAAoB,IAAI,CACvB,KAAC,kBAAkB,IAAC,EAAE,EAAE,aAAa,iCAClC,CAAC,CAAC,aAAa,EAAE,CAAC,oBAAoB,CAAC,CAAC,GACtB,CACtB,IACA,CACJ,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,UAAU,YAErB,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useMemo } from 'react';\nimport type { PropsWithoutRef, KeyboardEvent, ChangeEvent, FocusEvent } from 'react';\n\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport FormField from '../FormField';\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport {\n useConfiguration,\n useConsolidatedRef,\n useI18n,\n useInputFormatter,\n usePrevious,\n useTestIds,\n useUID\n} from '../../hooks';\nimport {\n getCleanedValue,\n getDecimalSign,\n getDecrementedValue,\n getIncrementedValue\n} from '../Number/utils';\nimport { createClassName, withTestIds } from '../../utils';\n\nimport StyledCurrencyInput from './CurrencyInput.styles';\nimport type CurrencyInputProps from './CurrencyInput.types';\nimport { getCurrencyMinimumFractionDigits, getFormattedValue, isValidCurrency } from './utils';\nimport { getCurrencyInputTestIds } from './Currency.test-ids';\n\nconst CurrencyInput: ForwardRefForwardPropsComponent<CurrencyInputProps> = forwardRef(\n function CurrencyInput(\n props: PropsWithoutRef<CurrencyInputProps>,\n ref: CurrencyInputProps['ref']\n ) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n status,\n label,\n labelHidden,\n info,\n required,\n disabled,\n readOnly,\n additionalInfo,\n value: valueProp = '',\n onChange,\n onBlur,\n onFocus,\n suggestion,\n currencyISOCode,\n showDecimal = true,\n showGroupSeparators = true,\n min = Number.MIN_SAFE_INTEGER,\n max = Number.MAX_SAFE_INTEGER,\n step = 1,\n alwaysShowISOCode = false,\n maximumFractionDigits = 0,\n className,\n ...restProps\n } = props;\n\n const descriptionId = useUID();\n const testIds = useTestIds(testId, getCurrencyInputTestIds);\n\n const { locale } = useConfiguration();\n\n const t = useI18n();\n const inputRef = useConsolidatedRef(ref);\n\n const validCurrencyISOCode = useMemo(\n () => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined),\n [currencyISOCode]\n );\n\n const minimumFractionDigits = useMemo(\n () => getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode),\n [locale, validCurrencyISOCode]\n );\n\n const numberOfDecimals = showDecimal\n ? Math.max(maximumFractionDigits, minimumFractionDigits)\n : 0;\n\n const decimalSign = useMemo(\n () =>\n getDecimalSign(locale, {\n numberingSystem: 'latn',\n style: validCurrencyISOCode ? 'currency' : undefined,\n currency: validCurrencyISOCode\n }),\n [locale, validCurrencyISOCode]\n );\n\n // on initial render only pad the value with 0 if necessary\n const rendered = usePrevious(true);\n let value = valueProp;\n if (!rendered && validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {\n const [integer, fraction = ''] = value.split('.');\n value = `${integer}.${fraction.padEnd(numberOfDecimals, '0')}`;\n }\n\n const formatValue = useCallback(\n (number: string) => {\n return getFormattedValue(number, locale, validCurrencyISOCode, {\n showGroupSeparators,\n showAs: alwaysShowISOCode ? 'code' : 'symbol',\n numberOfDecimals\n });\n },\n [alwaysShowISOCode, numberOfDecimals, showGroupSeparators, locale, validCurrencyISOCode]\n );\n\n const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value;\n const cleanedInputValue = getCleanedValue(inputValue, decimalSign, numberOfDecimals);\n if (cleanedInputValue === value) return;\n onChange(cleanedInputValue);\n };\n\n const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) return;\n const input = e.currentTarget;\n switch (e.key) {\n case 'ArrowUp':\n e.preventDefault();\n onChange(getIncrementedValue(value, min, max, step));\n break;\n case 'ArrowDown':\n e.preventDefault();\n onChange(getDecrementedValue(value, min, max, step));\n break;\n case decimalSign:\n if (!showDecimal) e.preventDefault();\n if (input.value.includes(decimalSign)) {\n if (input.selectionStart && input.value.charAt(input.selectionStart) === decimalSign) {\n input.setSelectionRange(input.selectionStart + 1, input.selectionStart + 1);\n }\n e.preventDefault();\n } else if (\n input.selectionStart !== null &&\n !input.value.charAt(input.selectionStart - 1).match(/\\d/)\n ) {\n onChange(\n getCleanedValue(`${input.value}0${decimalSign}`, decimalSign, numberOfDecimals)\n );\n e.preventDefault();\n }\n break;\n case '-':\n if (value.startsWith('-')) e.preventDefault();\n break;\n default:\n }\n };\n\n const onInputFocusEvent = (e: FocusEvent<HTMLInputElement>) => {\n let parsableValue = value;\n if (validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {\n const [integer, fraction = ''] = value.split('.');\n parsableValue = `${integer}.${fraction.padEnd(numberOfDecimals, '0')}`;\n }\n\n if (e.type === 'focus') onFocus?.(parsableValue);\n else {\n if (parsableValue !== value) {\n onChange(parsableValue);\n }\n\n onBlur?.(parsableValue);\n }\n };\n\n const formattedValue = useInputFormatter(inputRef, value, formatValue, `0-9${decimalSign}-`);\n\n const Comp = (\n <>\n <StyledCurrencyInput\n data-testid={testIds.control}\n onChange={onInputChange}\n id={id}\n readOnly={readOnly}\n required={required}\n disabled={disabled}\n status={status}\n {...restProps}\n suggestion={suggestion}\n inputMode='numeric'\n ref={inputRef}\n value={formattedValue}\n onKeyDown={onKeyDown}\n onFocus={onInputFocusEvent}\n onBlur={onInputFocusEvent}\n aria-describedby={validCurrencyISOCode ? descriptionId : undefined}\n className={createClassName('currency-input', className)}\n />\n {validCurrencyISOCode && (\n <VisuallyHiddenText id={descriptionId} aria-hidden>\n {t('measured_in', [validCurrencyISOCode])}\n </VisuallyHiddenText>\n )}\n </>\n );\n\n return label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n readOnly={readOnly}\n status={status}\n required={required}\n disabled={disabled}\n additionalInfo={additionalInfo}\n suggestion={suggestion}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default withTestIds(CurrencyInput, getCurrencyInputTestIds);\n"]}
1
+ {"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,OAAO,EACP,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACpB,MAAM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AAa,EAAE,CAAC,oBAAoB,CAAC,CAAC,GACtB,CACtB,IACA,CACJ,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,IACR,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,UAAU,YAErB,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC","sourcesContent":["import { forwardRef, useCallback, useMemo } from 'react';\nimport type { PropsWithoutRef, KeyboardEvent, ChangeEvent, FocusEvent } from 'react';\n\nimport VisuallyHiddenText from '../VisuallyHiddenText';\nimport FormField from '../FormField';\nimport type { ForwardRefForwardPropsComponent } from '../../types';\nimport {\n useConfiguration,\n useConsolidatedRef,\n useI18n,\n useInputFormatter,\n usePrevious,\n useTestIds,\n useUID\n} from '../../hooks';\nimport {\n getCleanedValue,\n getDecimalSign,\n getDecrementedValue,\n getIncrementedValue\n} from '../Number/utils';\nimport { createClassName, withTestIds } from '../../utils';\n\nimport StyledCurrencyInput from './CurrencyInput.styles';\nimport type CurrencyInputProps from './CurrencyInput.types';\nimport { getCurrencyMinimumFractionDigits, getFormattedValue, isValidCurrency } from './utils';\nimport { getCurrencyInputTestIds } from './Currency.test-ids';\n\nconst CurrencyInput: ForwardRefForwardPropsComponent<CurrencyInputProps> = forwardRef(\n function CurrencyInput(\n props: PropsWithoutRef<CurrencyInputProps>,\n ref: CurrencyInputProps['ref']\n ) {\n const uid = useUID();\n const {\n testId,\n id = uid,\n status,\n label,\n labelHidden,\n info,\n required,\n disabled,\n readOnly,\n additionalInfo,\n value: valueProp = '',\n onChange,\n onBlur,\n onFocus,\n suggestion,\n currencyISOCode,\n showDecimal = true,\n showGroupSeparators = true,\n min = Number.MIN_SAFE_INTEGER,\n max = Number.MAX_SAFE_INTEGER,\n step = 1,\n alwaysShowISOCode = false,\n minimumFractionDigits: minimumFractionDigitsProp,\n maximumFractionDigits: maximumFractionDigitsProp,\n className,\n ...restProps\n } = props;\n\n const descriptionId = useUID();\n const testIds = useTestIds(testId, getCurrencyInputTestIds);\n\n const { locale } = useConfiguration();\n\n const t = useI18n();\n const inputRef = useConsolidatedRef(ref);\n\n const validCurrencyISOCode = useMemo(\n () => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined),\n [currencyISOCode]\n );\n\n const minimumCurrencyFractionDigits = useMemo(\n () => getCurrencyMinimumFractionDigits(locale, validCurrencyISOCode),\n [locale, validCurrencyISOCode]\n );\n\n const minimumFractionDigits = showDecimal\n ? minimumFractionDigitsProp ?? minimumCurrencyFractionDigits\n : 0;\n const maximumFractionDigits = showDecimal\n ? maximumFractionDigitsProp ?? Math.max(minimumCurrencyFractionDigits, minimumFractionDigits)\n : 0;\n\n const decimalSign = useMemo(\n () =>\n getDecimalSign(locale, {\n numberingSystem: 'latn',\n style: validCurrencyISOCode ? 'currency' : undefined,\n currency: validCurrencyISOCode,\n maximumFractionDigits\n }),\n [locale, validCurrencyISOCode, maximumFractionDigits]\n );\n\n // on initial render only pad the value with 0 if necessary\n const rendered = usePrevious(true);\n let value = valueProp;\n if (!rendered && validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {\n const [integer, fraction = ''] = value.split('.');\n value = `${integer}.${fraction.padEnd(minimumFractionDigits, '0')}`;\n }\n\n const formatValue = useCallback(\n (number: string) => {\n return getFormattedValue(number, locale, validCurrencyISOCode, {\n showGroupSeparators,\n showAs: alwaysShowISOCode ? 'code' : 'symbol',\n numberOfDecimals: maximumFractionDigits\n });\n },\n [alwaysShowISOCode, maximumFractionDigits, showGroupSeparators, locale, validCurrencyISOCode]\n );\n\n const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {\n const inputValue = e.target.value;\n const cleanedInputValue = getCleanedValue(inputValue, decimalSign, maximumFractionDigits);\n if (cleanedInputValue === value) return;\n onChange(cleanedInputValue);\n };\n\n const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n if (readOnly) return;\n const input = e.currentTarget;\n switch (e.key) {\n case 'ArrowUp':\n e.preventDefault();\n onChange(getIncrementedValue(value, min, max, step));\n break;\n case 'ArrowDown':\n e.preventDefault();\n onChange(getDecrementedValue(value, min, max, step));\n break;\n case decimalSign:\n if (!showDecimal) e.preventDefault();\n if (input.value.includes(decimalSign)) {\n if (input.selectionStart && input.value.charAt(input.selectionStart) === decimalSign) {\n input.setSelectionRange(input.selectionStart + 1, input.selectionStart + 1);\n }\n e.preventDefault();\n } else if (\n input.selectionStart !== null &&\n !input.value.charAt(input.selectionStart - 1).match(/\\d/)\n ) {\n onChange(\n getCleanedValue(`${input.value}0${decimalSign}`, decimalSign, maximumFractionDigits)\n );\n e.preventDefault();\n }\n break;\n case '-':\n if (value.startsWith('-')) e.preventDefault();\n break;\n default:\n }\n };\n\n const onInputFocusEvent = (e: FocusEvent<HTMLInputElement>) => {\n let parsableValue = value;\n if (validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {\n const [integer, fraction = ''] = value.split('.');\n const numberOfDecimals = Math.min(minimumFractionDigits, maximumFractionDigits);\n if (fraction.length < numberOfDecimals) {\n parsableValue = `${integer}.${fraction.padEnd(numberOfDecimals, '0')}`;\n }\n }\n\n if (e.type === 'focus') onFocus?.(parsableValue);\n else {\n if (parsableValue !== value) {\n onChange(parsableValue);\n }\n\n onBlur?.(parsableValue);\n }\n };\n\n const formattedValue = useInputFormatter(inputRef, value, formatValue, `0-9${decimalSign}-`);\n\n const Comp = (\n <>\n <StyledCurrencyInput\n data-testid={testIds.control}\n onChange={onInputChange}\n id={id}\n readOnly={readOnly}\n required={required}\n disabled={disabled}\n status={status}\n {...restProps}\n suggestion={suggestion}\n inputMode='numeric'\n ref={inputRef}\n value={formattedValue}\n onKeyDown={onKeyDown}\n onFocus={onInputFocusEvent}\n onBlur={onInputFocusEvent}\n aria-describedby={validCurrencyISOCode ? descriptionId : undefined}\n className={createClassName('currency-input', className)}\n />\n {validCurrencyISOCode && (\n <VisuallyHiddenText id={descriptionId} aria-hidden>\n {t('measured_in', [validCurrencyISOCode])}\n </VisuallyHiddenText>\n )}\n </>\n );\n\n return label ? (\n <FormField\n testId={testIds}\n label={label}\n labelHidden={labelHidden}\n id={id}\n info={info}\n readOnly={readOnly}\n status={status}\n required={required}\n disabled={disabled}\n additionalInfo={additionalInfo}\n suggestion={suggestion}\n >\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default withTestIds(CurrencyInput, getCurrencyInputTestIds);\n"]}
@@ -4,6 +4,14 @@ export declare const getFormattedValue: (value: string, locale: string, currency
4
4
  showAs?: "code" | "symbol";
5
5
  numberOfDecimals?: number;
6
6
  }) => string;
7
+ /**
8
+ * Manual overrides for the minimum fraction digits of specific currencies, keyed by ISO currency
9
+ * code. `Intl.NumberFormat` resolved options can be inconsistent across browsers for some
10
+ * currencies, e.g. Chrome resolves `minimumFractionDigits` to 0 for RSD while Safari correctly
11
+ * resolves it to 2 (https://issues.chromium.org/issues/40877066). Extend this map as further
12
+ * browser inconsistencies are found.
13
+ */
14
+ export declare const CURRENCY_MINIMUM_FRACTION_DIGITS_OVERRIDES: Record<string, number>;
7
15
  export declare function getCurrencyMinimumFractionDigits(locale: string, currencyISOCode?: string): number;
8
16
  interface CurrencyFormatOptions {
9
17
  locale: string;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,YAQ/C,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,O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AAM,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,qBAAqB,UAIhG"}
@@ -51,13 +51,43 @@ export const getFormattedValue = (value, locale, currency, { showGroupSeparators
51
51
  }
52
52
  return formatted;
53
53
  };
54
+ /**
55
+ * Manual overrides for the minimum fraction digits of specific currencies, keyed by ISO currency
56
+ * code. `Intl.NumberFormat` resolved options can be inconsistent across browsers for some
57
+ * currencies, e.g. Chrome resolves `minimumFractionDigits` to 0 for RSD while Safari correctly
58
+ * resolves it to 2 (https://issues.chromium.org/issues/40877066). Extend this map as further
59
+ * browser inconsistencies are found.
60
+ */
61
+ export const CURRENCY_MINIMUM_FRACTION_DIGITS_OVERRIDES = {
62
+ AFN: 2,
63
+ ALL: 2,
64
+ IQD: 3,
65
+ IRR: 2,
66
+ KPW: 2,
67
+ LAK: 2,
68
+ LBP: 2,
69
+ MGA: 2,
70
+ MMK: 2,
71
+ MRO: 2,
72
+ RSD: 2,
73
+ SLL: 2,
74
+ SOS: 2,
75
+ STD: 2,
76
+ SYP: 2,
77
+ TRL: 2,
78
+ YER: 2,
79
+ ZWD: 2
80
+ };
54
81
  export function getCurrencyMinimumFractionDigits(locale, currencyISOCode) {
55
- return currencyISOCode
56
- ? new Intl.NumberFormat(locale, {
82
+ if (!currencyISOCode)
83
+ return NUMBER_MAX_DECIMAL_PLACES;
84
+ const overriddenMinimumFractionDigits = CURRENCY_MINIMUM_FRACTION_DIGITS_OVERRIDES[currencyISOCode.toUpperCase()];
85
+ return overriddenMinimumFractionDigits !== undefined
86
+ ? overriddenMinimumFractionDigits
87
+ : new Intl.NumberFormat(locale, {
57
88
  style: 'currency',
58
89
  currency: currencyISOCode
59
- }).resolvedOptions().minimumFractionDigits ?? 0
60
- : NUMBER_MAX_DECIMAL_PLACES;
90
+ }).resolvedOptions().minimumFractionDigits ?? 0;
61
91
  }
62
92
  export function formatCurrency(value, { locale, options }) {
63
93
  const formatter = new Intl.NumberFormat(locale, options);
@@ -1 +1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M,EACnE,EAAE,CACH,CAAC;IACN,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,UAAU,gCAAgC,CAAC,MAAc,EAAE,eAAwB;IACvF,OAAO,eAAe;QACpB,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YAC5B,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,eAAe;SAC1B,CAAC,CAAC,eAAe,EAAE,CAAC,qBAAqB,IAAI,CAAC;QACjD,CAAC,CAAC,yBAAyB,CAAC;AAChC,CAAC;AAOD,MAAM,UAAU,cAAc,CAAC,KAAsB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAyB;IAC/F,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzD,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import { NUMBER_MAX_DECIMAL_PLACES } from '../Number/NumberInput.types';\nimport { getFormattedValue as getNumberFormattedValue } from '../Number/utils';\n\nexport const isValidCurrency = (currency: string) => {\n try {\n // eslint-disable-next-line no-new\n new Intl.NumberFormat(undefined, { style: 'currency', currency });\n return true;\n } catch {\n return false;\n }\n};\n\nexport const getFormattedValue = (\n value: string,\n locale: string,\n currency?: string,\n {\n showGroupSeparators = true,\n showAs = 'code',\n numberOfDecimals\n }: { showGroupSeparators?: boolean; showAs?: 'code' | 'symbol'; numberOfDecimals?: number } = {}\n) => {\n const [integer, fractionPart] = value.split('.', 2) as [string, string?];\n\n if (!currency)\n return getNumberFormattedValue(value, locale, undefined, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits: numberOfDecimals,\n minimumFractionDigits: Math.min(numberOfDecimals ?? 0, fractionPart?.length ?? 0)\n });\n\n const isCurrency = isValidCurrency(currency);\n\n const formatter = new Intl.NumberFormat(locale, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits: numberOfDecimals,\n minimumFractionDigits: Math.min(numberOfDecimals ?? 0, fractionPart?.length ?? 0),\n ...(isCurrency\n ? {\n style: 'currency',\n currency,\n currencyDisplay: showAs\n }\n : {}),\n numberingSystem: 'latn'\n });\n\n let formatted = value;\n\n if (value && !Number.isNaN(parseFloat(integer))) {\n const endsWithDot = fractionPart === '';\n const valueNumber = endsWithDot ? `${value}1` : value;\n formatted = formatter\n .formatToParts(valueNumber as `${number}`)\n .reduce((result, { type, value: part }) => {\n if (type === 'fraction' && endsWithDot) return result;\n return result + part;\n }, '');\n } else if (currency) {\n formatted = formatter\n .formatToParts(value.startsWith('-') ? -1 : 1)\n .reduce(\n (result, { type, value: part }) =>\n ['currency', 'minusSign'].includes(type) ? result + part : result,\n ''\n );\n }\n return formatted;\n};\n\nexport function getCurrencyMinimumFractionDigits(locale: string, currencyISOCode?: string): number {\n return currencyISOCode\n ? new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currencyISOCode\n }).resolvedOptions().minimumFractionDigits ?? 0\n : NUMBER_MAX_DECIMAL_PLACES;\n}\n\ninterface CurrencyFormatOptions {\n locale: string;\n options?: Intl.NumberFormatOptions;\n}\n\nexport function formatCurrency(value: number | bigint, { locale, options }: CurrencyFormatOptions) {\n const formatter = new Intl.NumberFormat(locale, options);\n\n return formatter.format(value);\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,EAAE;IAClD,IAAI,CAAC;QACH,kCAAkC;QAClC,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClE,OAAO,IAAI,CAA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AG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;CACP,CAAC;AAEF,MAAM,UAAU,gCAAgC,CAAC,MAAc,EAAE,eAAwB;IACvF,IAAI,CAAC,eAAe;QAAE,OAAO,yBAAyB,CAAC;IAEvD,MAAM,+BAA+B,GACnC,0CAA0C,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,CAAC;IAE5E,OAAO,+BAA+B,KAAK,SAAS;QAClD,CAAC,CAAC,+BAA+B;QACjC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YAC5B,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,eAAe;SAC1B,CAAC,CAAC,eAAe,EAAE,CAAC,qBAAqB,IAAI,CAAC,CAAC;AACtD,CAAC;AAOD,MAAM,UAAU,cAAc,CAAC,KAAsB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAyB;IAC/F,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEzD,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import { NUMBER_MAX_DECIMAL_PLACES } from '../Number/NumberInput.types';\nimport { getFormattedValue as getNumberFormattedValue } from '../Number/utils';\n\nexport const isValidCurrency = (currency: string) => {\n try {\n // eslint-disable-next-line no-new\n new Intl.NumberFormat(undefined, { style: 'currency', currency });\n return true;\n } catch {\n return false;\n }\n};\n\nexport const getFormattedValue = (\n value: string,\n locale: string,\n currency?: string,\n {\n showGroupSeparators = true,\n showAs = 'code',\n numberOfDecimals\n }: { showGroupSeparators?: boolean; showAs?: 'code' | 'symbol'; numberOfDecimals?: number } = {}\n) => {\n const [integer, fractionPart] = value.split('.', 2) as [string, string?];\n\n if (!currency)\n return getNumberFormattedValue(value, locale, undefined, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits: numberOfDecimals,\n minimumFractionDigits: Math.min(numberOfDecimals ?? 0, fractionPart?.length ?? 0)\n });\n\n const isCurrency = isValidCurrency(currency);\n\n const formatter = new Intl.NumberFormat(locale, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits: numberOfDecimals,\n minimumFractionDigits: Math.min(numberOfDecimals ?? 0, fractionPart?.length ?? 0),\n ...(isCurrency\n ? {\n style: 'currency',\n currency,\n currencyDisplay: showAs\n }\n : {}),\n numberingSystem: 'latn'\n });\n\n let formatted = value;\n\n if (value && !Number.isNaN(parseFloat(integer))) {\n const endsWithDot = fractionPart === '';\n const valueNumber = endsWithDot ? `${value}1` : value;\n formatted = formatter\n .formatToParts(valueNumber as `${number}`)\n .reduce((result, { type, value: part }) => {\n if (type === 'fraction' && endsWithDot) return result;\n return result + part;\n }, '');\n } else if (currency) {\n formatted = formatter\n .formatToParts(value.startsWith('-') ? -1 : 1)\n .reduce(\n (result, { type, value: part }) =>\n ['currency', 'minusSign'].includes(type) ? result + part : result,\n ''\n );\n }\n return formatted;\n};\n\n/**\n * Manual overrides for the minimum fraction digits of specific currencies, keyed by ISO currency\n * code. `Intl.NumberFormat` resolved options can be inconsistent across browsers for some\n * currencies, e.g. Chrome resolves `minimumFractionDigits` to 0 for RSD while Safari correctly\n * resolves it to 2 (https://issues.chromium.org/issues/40877066). Extend this map as further\n * browser inconsistencies are found.\n */\nexport const CURRENCY_MINIMUM_FRACTION_DIGITS_OVERRIDES: Record<string, number> = {\n AFN: 2,\n ALL: 2,\n IQD: 3,\n IRR: 2,\n KPW: 2,\n LAK: 2,\n LBP: 2,\n MGA: 2,\n MMK: 2,\n MRO: 2,\n RSD: 2,\n SLL: 2,\n SOS: 2,\n STD: 2,\n SYP: 2,\n TRL: 2,\n YER: 2,\n ZWD: 2\n};\n\nexport function getCurrencyMinimumFractionDigits(locale: string, currencyISOCode?: string): number {\n if (!currencyISOCode) return NUMBER_MAX_DECIMAL_PLACES;\n\n const overriddenMinimumFractionDigits =\n CURRENCY_MINIMUM_FRACTION_DIGITS_OVERRIDES[currencyISOCode.toUpperCase()];\n\n return overriddenMinimumFractionDigits !== undefined\n ? overriddenMinimumFractionDigits\n : new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currencyISOCode\n }).resolvedOptions().minimumFractionDigits ?? 0;\n}\n\ninterface CurrencyFormatOptions {\n locale: string;\n options?: Intl.NumberFormatOptions;\n}\n\nexport function formatCurrency(value: number | bigint, { locale, options }: CurrencyFormatOptions) {\n const formatter = new Intl.NumberFormat(locale, options);\n\n return formatter.format(value);\n}\n"]}
@@ -15,9 +15,9 @@ export interface DateTimeDisplayProps extends BaseProps {
15
15
  /** Defines clock format that overrides locale based format */
16
16
  clockFormat?: ClockFormat;
17
17
  /** Ref for the wrapping element. */
18
- ref?: Ref<HTMLSpanElement>;
18
+ ref?: Ref<HTMLTimeElement>;
19
19
  }
20
- export declare const StyledDateTimeDisplay: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
20
+ export declare const StyledDateTimeDisplay: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").TimeHTMLAttributes<HTMLTimeElement>, HTMLTimeElement>, never>> & string;
21
21
  declare const DateTimeDisplay: ForwardRefForwardPropsComponent<DateTimeDisplayProps>;
22
22
  export default DateTimeDisplay;
23
23
  //# sourceMappingURL=DateTimeDisplay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DateTimeDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/DateTime/DateTimeDisplay.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAGlD,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAK9E,OAAO,K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GAAG,CAAC,eAAe,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,qBAAqB,mOAAgB,CAAC;AAEnD,QAAA,MAAM,eAAe,EAAE,+BAA+B,CAAC,oBAAoB,CAqE1E,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { forwardRef } from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { useConfiguration, useI18n } from '../../hooks';
@@ -7,18 +7,43 @@ import cap from '../../utils/cap';
7
7
  import { parseToDate } from './Input/utils';
8
8
  import { isValidDate } from './Picker/utils';
9
9
  import { formatDateTime } from './utils';
10
- export const StyledDateTimeDisplay = styled.span ``;
10
+ export const StyledDateTimeDisplay = styled.time ``;
11
11
  const DateTimeDisplay = forwardRef(function DateTimeDisplay({ value, variant, format = 'medium', clockFormat, ...restProps }, ref) {
12
12
  const { locale } = useConfiguration();
13
13
  const t = useI18n();
14
- return (_jsx(StyledDateTimeDisplay, { ref: ref, ...restProps, children: (value || value === 0) && isValidDate(parseToDate(value)) ? (cap(formatDateTime(parseToDate(value), {
14
+ const parsedDate = value || value === 0 ? parseToDate(value) : undefined;
15
+ const hasValue = !!parsedDate && isValidDate(parsedDate);
16
+ const displayText = hasValue
17
+ ? cap(formatDateTime(parsedDate, {
15
18
  t,
16
19
  locale,
17
20
  format,
18
21
  variant,
19
22
  clockFormat,
20
23
  timeZone: 'UTC'
21
- }))) : (_jsx(NoValue, {})) }));
24
+ }))
25
+ : undefined;
26
+ // Abbreviated month names (e.g. "Oct") read phonetically to screen readers, so an
27
+ // accessible, fully expanded label (e.g. "October") is exposed via aria-label while
28
+ // the visible, abbreviated text stays unchanged. Only 'medium' format ever renders an
29
+ // abbreviated month name, so other formats simply reuse the display text.
30
+ const accessibleText = hasValue && format === 'medium'
31
+ ? cap(formatDateTime(parsedDate, {
32
+ t,
33
+ locale,
34
+ format,
35
+ variant,
36
+ clockFormat,
37
+ timeZone: 'UTC',
38
+ abbreviated: false
39
+ }))
40
+ : displayText;
41
+ let content = _jsx(NoValue, {});
42
+ if (hasValue) {
43
+ content =
44
+ displayText !== accessibleText ? (_jsx("abbr", { "aria-label": accessibleText, children: displayText })) : (_jsx(_Fragment, { children: displayText }));
45
+ }
46
+ return (_jsx(StyledDateTimeDisplay, { ref: ref, dateTime: hasValue ? parsedDate.toISOString() : undefined, ...restProps, children: content }));
22
47
  });
23
48
  export default DateTimeDisplay;
24
49
  //# sourceMappingURL=DateTimeDisplay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DateTimeDisplay.js","sourceRoot":"","sources":["../../../src/components/DateTime/DateTimeDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAkBzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAA,EAAE,CAAC;AAEnD,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,OAAO,EACP,MAAM,GAAG,QAAQ,EACjB,WAAW,EACX,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,OAAO,CACL,KAAC,qBAAqB,IAAC,GAAG,EAAE,GAAG,KAAM,SAAS,YAC3C,CAAC,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3D,GAAG,CACD,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;YACjC,CAAC;YACD,MAAM;YACN,MAAM;YACN,OAAO;YACP,WAAW;YACX,QAAQ,EAAE,KAAK;SAChB,CAAC,CACH,CACF,CAAC,CAAC,CAAC,CACF,KAAC,OAAO,KAAG,CACZ,GACqB,CACzB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent } from '../../types';\nimport { useConfiguration, useI18n } from '../../hooks';\nimport NoValue from '../NoValue/NoValue';\nimport cap from '../../utils/cap';\n\nimport type { DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { parseToDate } from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\nimport { isValidDate } from './Picker/utils';\nimport { formatDateTime } from './utils';\n\nexport interface DateTimeDisplayProps extends BaseProps {\n /** Date as ISO8601 string, timestamp or native Date object. */\n value?: Date | string | number;\n /** Controls date time variant. */\n variant: DateTimeVariant;\n /**\n * Controls display format.\n * @default 'medium'\n */\n format?: DateTimeFormat;\n /** Defines clock format that overrides locale based format */\n clockFormat?: ClockFormat;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLSpanElement>;\n}\n\nexport const StyledDateTimeDisplay = styled.span``;\n\nconst DateTimeDisplay: ForwardRefForwardPropsComponent<DateTimeDisplayProps> = forwardRef(\n function DateTimeDisplay(\n {\n value,\n variant,\n format = 'medium',\n clockFormat,\n ...restProps\n }: PropsWithoutRef<DateTimeDisplayProps>,\n ref: DateTimeDisplayProps['ref']\n ) {\n const { locale } = useConfiguration();\n const t = useI18n();\n\n return (\n <StyledDateTimeDisplay ref={ref} {...restProps}>\n {(value || value === 0) && isValidDate(parseToDate(value)) ? (\n cap(\n formatDateTime(parseToDate(value), {\n t,\n locale,\n format,\n variant,\n clockFormat,\n timeZone: 'UTC'\n })\n )\n ) : (\n <NoValue />\n )}\n </StyledDateTimeDisplay>\n );\n }\n);\n\nexport default DateTimeDisplay;\n"]}
1
+ {"version":3,"file":"DateTimeDisplay.js","sourceRoot":"","sources":["../../../src/components/DateTime/DateTimeDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAkBzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAA,EAAE,CAAC;AAEnD,MAAM,eAAe,GAA0D,UAAU,CACvF,SAAS,eAAe,CACtB,EACE,KAAK,EACL,OAAO,EACP,MAAM,GAAG,QAAQ,EACjB,WAAW,EACX,GAAG,SAAS,EAC0B,EACxC,GAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IACtC,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,UAAU,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzE,MAAM,QAAQ,GAAG,CAAC,CAAC,UAAU,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC;IAEzD,MAAM,WAAW,GAAG,QAAQ;QAC1B,CAAC,CAAC,GAAG,CACD,cAAc,CAAC,UAAU,EAAE;YACzB,CAAC;YACD,MAAM;YACN,MAAM;YACN,OAAO;YACP,WAAW;YACX,QAAQ,EAAE,KAAK;SAChB,CAAC,CACH;QACH,CAAC,CAAC,SAAS,CAAC;IAEd,kFAAkF;IAClF,oFAAoF;IACpF,sFAAsF;IACtF,0EAA0E;IAC1E,MAAM,cAAc,GAClB,QAAQ,IAAI,MAAM,KAAK,QAAQ;QAC7B,CAAC,CAAC,GAAG,CACD,cAAc,CAAC,UAAU,EAAE;YACzB,CAAC;YACD,MAAM;YACN,MAAM;YACN,OAAO;YACP,WAAW;YACX,QAAQ,EAAE,KAAK;YACf,WAAW,EAAE,KAAK;SACnB,CAAC,CACH;QACH,CAAC,CAAC,WAAW,CAAC;IAElB,IAAI,OAAO,GAAG,KAAC,OAAO,KAAG,CAAC;IAC1B,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO;YACL,WAAW,KAAK,cAAc,CAAC,CAAC,CAAC,CAC/B,6BAAkB,cAAc,YAAG,WAAW,GAAQ,CACvD,CAAC,CAAC,CAAC,CACF,4BAAG,WAAW,GAAI,CACnB,CAAC;IACN,CAAC;IAED,OAAO,CACL,KAAC,qBAAqB,IACpB,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,KACrD,SAAS,YAEZ,OAAO,GACc,CACzB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { PropsWithoutRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport type { BaseProps, ForwardRefForwardPropsComponent } from '../../types';\nimport { useConfiguration, useI18n } from '../../hooks';\nimport NoValue from '../NoValue/NoValue';\nimport cap from '../../utils/cap';\n\nimport type { DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { parseToDate } from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\nimport { isValidDate } from './Picker/utils';\nimport { formatDateTime } from './utils';\n\nexport interface DateTimeDisplayProps extends BaseProps {\n /** Date as ISO8601 string, timestamp or native Date object. */\n value?: Date | string | number;\n /** Controls date time variant. */\n variant: DateTimeVariant;\n /**\n * Controls display format.\n * @default 'medium'\n */\n format?: DateTimeFormat;\n /** Defines clock format that overrides locale based format */\n clockFormat?: ClockFormat;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLTimeElement>;\n}\n\nexport const StyledDateTimeDisplay = styled.time``;\n\nconst DateTimeDisplay: ForwardRefForwardPropsComponent<DateTimeDisplayProps> = forwardRef(\n function DateTimeDisplay(\n {\n value,\n variant,\n format = 'medium',\n clockFormat,\n ...restProps\n }: PropsWithoutRef<DateTimeDisplayProps>,\n ref: DateTimeDisplayProps['ref']\n ) {\n const { locale } = useConfiguration();\n const t = useI18n();\n\n const parsedDate = value || value === 0 ? parseToDate(value) : undefined;\n const hasValue = !!parsedDate && isValidDate(parsedDate);\n\n const displayText = hasValue\n ? cap(\n formatDateTime(parsedDate, {\n t,\n locale,\n format,\n variant,\n clockFormat,\n timeZone: 'UTC'\n })\n )\n : undefined;\n\n // Abbreviated month names (e.g. \"Oct\") read phonetically to screen readers, so an\n // accessible, fully expanded label (e.g. \"October\") is exposed via aria-label while\n // the visible, abbreviated text stays unchanged. Only 'medium' format ever renders an\n // abbreviated month name, so other formats simply reuse the display text.\n const accessibleText =\n hasValue && format === 'medium'\n ? cap(\n formatDateTime(parsedDate, {\n t,\n locale,\n format,\n variant,\n clockFormat,\n timeZone: 'UTC',\n abbreviated: false\n })\n )\n : displayText;\n\n let content = <NoValue />;\n if (hasValue) {\n content =\n displayText !== accessibleText ? (\n <abbr aria-label={accessibleText}>{displayText}</abbr>\n ) : (\n <>{displayText}</>\n );\n }\n\n return (\n <StyledDateTimeDisplay\n ref={ref}\n dateTime={hasValue ? parsedDate.toISOString() : undefined}\n {...restProps}\n >\n {content}\n </StyledDateTimeDisplay>\n );\n }\n);\n\nexport default DateTimeDisplay;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"DateInput.d.ts","sourceRoot":"","sources":["../../../../src/components/DateTime/Input/DateInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,iBAAiB,EAEjB,GAAG,EACH,SAAS,EACT,QAAQ,EACR,cAAc,EACd,aAAa,EACd,MAAM,OAAO,CAAC;AAYf,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAMnD,OAAO,KAAK,eAAe,MAAM,4BAA4B,CAAC;AAE9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AA0BnE,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3C,eAAe,EAAE,MAAM,yBAAyB,CAAC;CAClD;AAED,KAAK,YAAY,GAAG,YAAY,GAAG,GAAG,mBAAmB,CAAC,eAAe,CAAC,MAAM,CAAC;AAEjF,MAAM,WAAW,cAAe,SAAQ,aAAa;IACnD;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kCAAkC;IAClC,MAAM,CAAC,EAAE;QACP,QAAQ,EAAE,aAAa,CAAC;QACxB,aAAa,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,YAAY,CAAC;KACzD,CAAC;IACF,8EAA8E;IAC9E,cAAc,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACpD,6CAA6C;IAC7C,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,oDAAoD;IACpD,MAAM,CAAC,EAAE,GAAG,CAAC,oBAAoB,CAAC,CAAC;CACp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AA6YF,wBAA2D"}
@@ -12,7 +12,7 @@ import { StyledFormControl } from '../../FormControl';
12
12
  import { createClassName, withTestIds } from '../../../utils';
13
13
  import { getDateInputTestIds } from '../DateTime.test-ids';
14
14
  import HiddenText from '../../HiddenText';
15
- import { getDateFormat, getDateTimeParts, parsePastedTextToDate, parseToDate, validateDate, generatePickerButtonAriaLabel } from './utils';
15
+ import { buildRawDateString, generatePickerButtonAriaLabel, getDateFormat, getDateTimeParts, parsePastedTextToDate, parseToDate, validateDate } from './utils';
16
16
  import StyledDateTime, { StyledDatePickerDialog, StyledDialogContent, StyledInputButton, StyledInputContainer } from './DateTime.styles';
17
17
  import useAutoFocusNextInput from './useAutoFocusNextInput';
18
18
  import PartInput from './PartInput';
@@ -22,11 +22,11 @@ export const StyledDateInput = styled(StyledDateTime) `
22
22
  padding-inline-end: 0;
23
23
  `;
24
24
  StyledDateInput.defaultProps = defaultThemeProp;
25
- const convertToCallbackParameter = (date, { year, month: monthIndex, day }) => {
25
+ const convertToCallbackParameter = (date, { year, month: monthIndex, day }, locale) => {
26
26
  if ([year, monthIndex, day].every(Boolean)) {
27
27
  if (!validateDate(Number(year), Number(monthIndex) + 1, Number(day))) {
28
28
  return {
29
- valueAsISOString: '',
29
+ valueAsISOString: buildRawDateString(year, monthIndex, day, locale),
30
30
  valueAsTimestamp: NaN,
31
31
  state: 'invalid'
32
32
  };
@@ -44,7 +44,7 @@ const convertToCallbackParameter = (date, { year, month: monthIndex, day }) => {
44
44
  };
45
45
  }
46
46
  return {
47
- valueAsISOString: '',
47
+ valueAsISOString: buildRawDateString(year, monthIndex, day, locale),
48
48
  valueAsTimestamp: NaN,
49
49
  state: 'incomplete'
50
50
  };
@@ -89,7 +89,7 @@ const DateInput = forwardRef(function DateInput(props, ref) {
89
89
  const [open, setOpen, , setPopoverRef, datePickerButtonEl, setDatePickerButtonEl] = usePickerButton();
90
90
  const inputContainerRef = useRef(null);
91
91
  const onFocusChange = (focused) => {
92
- const callbackParam = convertToCallbackParameter(date ? new Date(date) : new Date(), pickParts());
92
+ const callbackParam = convertToCallbackParameter(date ? new Date(date) : new Date(), pickParts(), locale);
93
93
  if (onFocus && focused)
94
94
  onFocus(callbackParam);
95
95
  if (!focused) {
@@ -99,7 +99,7 @@ const DateInput = forwardRef(function DateInput(props, ref) {
99
99
  }
100
100
  };
101
101
  const onInputChange = () => {
102
- onChange?.(convertToCallbackParameter(date ? new Date(date) : new Date(), pickParts()));
102
+ onChange?.(convertToCallbackParameter(date ? new Date(date) : new Date(), pickParts(), locale));
103
103
  datePickerButtonEl?.setAttribute('aria-label', generatePickerButtonAriaLabel(currentlySelectedDate(), 'date', locale, t, open));
104
104
  if (dayInputRef.current?.value || monthInputRef.current?.value || yearInputRef.current?.value) {
105
105
  setHasValue(true);
@@ -146,7 +146,7 @@ const DateInput = forwardRef(function DateInput(props, ref) {
146
146
  useFocusWithin([containerRef], onFocusChange);
147
147
  useImperativeHandle(handle, () => ({
148
148
  setOpen,
149
- getCurrentValue: () => convertToCallbackParameter(date ? new Date(date) : new Date(), pickParts())
149
+ getCurrentValue: () => convertToCallbackParameter(date ? new Date(date) : new Date(), pickParts(), locale)
150
150
  }));
151
151
  const PickerButton = (_jsxs(_Fragment, { children: [_jsx(StyledInputButton, { "data-testid": testIds.openClosePicker, variant: 'simple', icon: true, ref: setDatePickerButtonEl, onClick: () => setOpen(cur => !cur), "aria-label": generatePickerButtonAriaLabel(currentlySelectedDate(), 'date', locale, t, open), readOnly: readOnly, disabled: disabled, children: _jsx(Icon, { name: 'calendar' }) }), open && datePickerButtonEl && (_jsx(StyledDatePickerDialog, { ref: setPopoverRef, target: datePickerButtonEl, placement: 'bottom-end', "aria-label": t('choose_date'), children: _jsx(Flex, { container: { direction: 'column' }, as: StyledDialogContent, children: _jsx(PickerComp, { testId: testIds.picker, selected: currentlySelectedDate(), min: min, max: max, showWeekNumber: showWeekNumber, timeZone: timeZone, ...rendererProps, onChange: selected => {
152
152
  setInputValue(selected);