@pega/cosmos-react-core 3.0.0-dev.10.1 → 3.0.0-dev.13.0

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 (157) hide show
  1. package/lib/components/AppShell/AppHeader.d.ts.map +1 -1
  2. package/lib/components/AppShell/AppHeader.js +13 -3
  3. package/lib/components/AppShell/AppHeader.js.map +1 -1
  4. package/lib/components/AppShell/AppShell.d.ts.map +1 -1
  5. package/lib/components/AppShell/AppShell.js +8 -4
  6. package/lib/components/AppShell/AppShell.js.map +1 -1
  7. package/lib/components/AppShell/AppShell.styles.d.ts +1 -0
  8. package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
  9. package/lib/components/AppShell/AppShell.styles.js +62 -77
  10. package/lib/components/AppShell/AppShell.styles.js.map +1 -1
  11. package/lib/components/AppShell/AppShell.types.d.ts +3 -0
  12. package/lib/components/AppShell/AppShell.types.d.ts.map +1 -1
  13. package/lib/components/AppShell/AppShell.types.js.map +1 -1
  14. package/lib/components/AppShell/AppShellContext.d.ts +3 -1
  15. package/lib/components/AppShell/AppShellContext.d.ts.map +1 -1
  16. package/lib/components/AppShell/AppShellContext.js +3 -1
  17. package/lib/components/AppShell/AppShellContext.js.map +1 -1
  18. package/lib/components/CompositeInput/CompositeInput.d.ts +5 -0
  19. package/lib/components/CompositeInput/CompositeInput.d.ts.map +1 -0
  20. package/lib/components/CompositeInput/CompositeInput.js +59 -0
  21. package/lib/components/CompositeInput/CompositeInput.js.map +1 -0
  22. package/lib/components/CompositeInput/CompositeInput.styles.d.ts +5 -0
  23. package/lib/components/CompositeInput/CompositeInput.styles.d.ts.map +1 -0
  24. package/lib/components/CompositeInput/CompositeInput.styles.js +54 -0
  25. package/lib/components/CompositeInput/CompositeInput.styles.js.map +1 -0
  26. package/lib/components/CompositeInput/CompositeInput.types.d.ts +50 -0
  27. package/lib/components/CompositeInput/CompositeInput.types.d.ts.map +1 -0
  28. package/lib/components/CompositeInput/CompositeInput.types.js +2 -0
  29. package/lib/components/CompositeInput/CompositeInput.types.js.map +1 -0
  30. package/lib/components/CompositeInput/index.d.ts +3 -0
  31. package/lib/components/CompositeInput/index.d.ts.map +1 -0
  32. package/lib/components/CompositeInput/index.js +2 -0
  33. package/lib/components/CompositeInput/index.js.map +1 -0
  34. package/lib/components/Currency/CurrencyDisplay.d.ts.map +1 -1
  35. package/lib/components/Currency/CurrencyDisplay.js +2 -2
  36. package/lib/components/Currency/CurrencyDisplay.js.map +1 -1
  37. package/lib/components/Currency/CurrencyInput.d.ts.map +1 -1
  38. package/lib/components/Currency/CurrencyInput.js +64 -28
  39. package/lib/components/Currency/CurrencyInput.js.map +1 -1
  40. package/lib/components/Currency/utils.d.ts +6 -16
  41. package/lib/components/Currency/utils.d.ts.map +1 -1
  42. package/lib/components/Currency/utils.js +47 -49
  43. package/lib/components/Currency/utils.js.map +1 -1
  44. package/lib/components/FieldGroup/FieldGroup.d.ts.map +1 -1
  45. package/lib/components/FieldGroup/FieldGroup.js +3 -2
  46. package/lib/components/FieldGroup/FieldGroup.js.map +1 -1
  47. package/lib/components/FieldGroup/FieldGroupList.d.ts.map +1 -1
  48. package/lib/components/FieldGroup/FieldGroupList.js +6 -2
  49. package/lib/components/FieldGroup/FieldGroupList.js.map +1 -1
  50. package/lib/components/Form/Form.d.ts +5 -16
  51. package/lib/components/Form/Form.d.ts.map +1 -1
  52. package/lib/components/Form/Form.js +14 -11
  53. package/lib/components/Form/Form.js.map +1 -1
  54. package/lib/components/Icon/Icon.d.ts.map +1 -1
  55. package/lib/components/Icon/Icon.js +1 -1
  56. package/lib/components/Icon/Icon.js.map +1 -1
  57. package/lib/components/Icon/iconNames.d.ts +1 -1
  58. package/lib/components/Icon/iconNames.d.ts.map +1 -1
  59. package/lib/components/Icon/iconNames.js +0 -1
  60. package/lib/components/Icon/iconNames.js.map +1 -1
  61. package/lib/components/Icon/icons/script.icon.d.ts +1 -1
  62. package/lib/components/Icon/icons/script.icon.d.ts.map +1 -1
  63. package/lib/components/Icon/icons/script.icon.js +3 -3
  64. package/lib/components/Icon/icons/script.icon.js.map +1 -1
  65. package/lib/components/ListToolbar/ListToolbar.d.ts.map +1 -1
  66. package/lib/components/ListToolbar/ListToolbar.js +11 -10
  67. package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
  68. package/lib/components/ListToolbar/ListToolbar.types.d.ts +3 -1
  69. package/lib/components/ListToolbar/ListToolbar.types.d.ts.map +1 -1
  70. package/lib/components/ListToolbar/ListToolbar.types.js.map +1 -1
  71. package/lib/components/Menu/Menu.d.ts.map +1 -1
  72. package/lib/components/Menu/Menu.js +2 -1
  73. package/lib/components/Menu/Menu.js.map +1 -1
  74. package/lib/components/MultiStepForm/FormProgress.d.ts +10 -0
  75. package/lib/components/MultiStepForm/FormProgress.d.ts.map +1 -0
  76. package/lib/components/{MultiStep/MultiStep.js → MultiStepForm/FormProgress.js} +8 -22
  77. package/lib/components/MultiStepForm/FormProgress.js.map +1 -0
  78. package/lib/components/{MultiStep/MultiStep.styles.d.ts → MultiStepForm/FormProgress.styles.d.ts} +2 -4
  79. package/lib/components/MultiStepForm/FormProgress.styles.d.ts.map +1 -0
  80. package/lib/components/{MultiStep/MultiStep.styles.js → MultiStepForm/FormProgress.styles.js} +2 -4
  81. package/lib/components/MultiStepForm/FormProgress.styles.js.map +1 -0
  82. package/lib/components/MultiStepForm/MultiStepForm.d.ts +9 -0
  83. package/lib/components/MultiStepForm/MultiStepForm.d.ts.map +1 -0
  84. package/lib/components/MultiStepForm/MultiStepForm.js +50 -0
  85. package/lib/components/MultiStepForm/MultiStepForm.js.map +1 -0
  86. package/lib/components/MultiStepForm/MultiStepForm.types.d.ts +49 -0
  87. package/lib/components/MultiStepForm/MultiStepForm.types.d.ts.map +1 -0
  88. package/lib/components/MultiStepForm/MultiStepForm.types.js +2 -0
  89. package/lib/components/MultiStepForm/MultiStepForm.types.js.map +1 -0
  90. package/lib/components/MultiStepForm/index.d.ts +2 -0
  91. package/lib/components/MultiStepForm/index.d.ts.map +1 -0
  92. package/lib/components/MultiStepForm/index.js +2 -0
  93. package/lib/components/MultiStepForm/index.js.map +1 -0
  94. package/lib/components/Number/NumberDisplay.d.ts +0 -5
  95. package/lib/components/Number/NumberDisplay.d.ts.map +1 -1
  96. package/lib/components/Number/NumberDisplay.js +8 -12
  97. package/lib/components/Number/NumberDisplay.js.map +1 -1
  98. package/lib/components/Number/NumberInput.d.ts.map +1 -1
  99. package/lib/components/Number/NumberInput.js +25 -18
  100. package/lib/components/Number/NumberInput.js.map +1 -1
  101. package/lib/components/Number/NumberInput.styles.d.ts +2 -3
  102. package/lib/components/Number/NumberInput.styles.d.ts.map +1 -1
  103. package/lib/components/Number/NumberInput.styles.js +1 -2
  104. package/lib/components/Number/NumberInput.styles.js.map +1 -1
  105. package/lib/components/Number/NumberInput.types.d.ts +1 -4
  106. package/lib/components/Number/NumberInput.types.d.ts.map +1 -1
  107. package/lib/components/Number/NumberInput.types.js.map +1 -1
  108. package/lib/components/Number/utils.d.ts +3 -4
  109. package/lib/components/Number/utils.d.ts.map +1 -1
  110. package/lib/components/Number/utils.js +41 -18
  111. package/lib/components/Number/utils.js.map +1 -1
  112. package/lib/components/Popover/Popover.d.ts.map +1 -1
  113. package/lib/components/Popover/Popover.js +0 -6
  114. package/lib/components/Popover/Popover.js.map +1 -1
  115. package/lib/components/Popover/Popover.styles.d.ts.map +1 -1
  116. package/lib/components/Popover/Popover.styles.js +12 -57
  117. package/lib/components/Popover/Popover.styles.js.map +1 -1
  118. package/lib/components/SearchInput/SearchInput.d.ts.map +1 -1
  119. package/lib/components/SearchInput/SearchInput.js +5 -1
  120. package/lib/components/SearchInput/SearchInput.js.map +1 -1
  121. package/lib/components/Tabs/Tab.d.ts.map +1 -1
  122. package/lib/components/Tabs/Tab.js +0 -1
  123. package/lib/components/Tabs/Tab.js.map +1 -1
  124. package/lib/hooks/useI18n.d.ts +17 -9
  125. package/lib/hooks/useI18n.d.ts.map +1 -1
  126. package/lib/i18n/default.d.ts +17 -9
  127. package/lib/i18n/default.d.ts.map +1 -1
  128. package/lib/i18n/default.js +21 -10
  129. package/lib/i18n/default.js.map +1 -1
  130. package/lib/i18n/i18n.d.ts +34 -18
  131. package/lib/i18n/i18n.d.ts.map +1 -1
  132. package/lib/index.d.ts +2 -2
  133. package/lib/index.d.ts.map +1 -1
  134. package/lib/index.js +2 -2
  135. package/lib/index.js.map +1 -1
  136. package/package.json +2 -2
  137. package/lib/components/Currency/currencyCodes.d.ts +0 -3
  138. package/lib/components/Currency/currencyCodes.d.ts.map +0 -1
  139. package/lib/components/Currency/currencyCodes.js +0 -182
  140. package/lib/components/Currency/currencyCodes.js.map +0 -1
  141. package/lib/components/Icon/icons/script-solid.icon.d.ts +0 -4
  142. package/lib/components/Icon/icons/script-solid.icon.d.ts.map +0 -1
  143. package/lib/components/Icon/icons/script-solid.icon.js +0 -6
  144. package/lib/components/Icon/icons/script-solid.icon.js.map +0 -1
  145. package/lib/components/MultiStep/MultiStep.d.ts +0 -6
  146. package/lib/components/MultiStep/MultiStep.d.ts.map +0 -1
  147. package/lib/components/MultiStep/MultiStep.js.map +0 -1
  148. package/lib/components/MultiStep/MultiStep.styles.d.ts.map +0 -1
  149. package/lib/components/MultiStep/MultiStep.styles.js.map +0 -1
  150. package/lib/components/MultiStep/MultiStep.types.d.ts +0 -36
  151. package/lib/components/MultiStep/MultiStep.types.d.ts.map +0 -1
  152. package/lib/components/MultiStep/MultiStep.types.js +0 -2
  153. package/lib/components/MultiStep/MultiStep.types.js.map +0 -1
  154. package/lib/components/MultiStep/index.d.ts +0 -3
  155. package/lib/components/MultiStep/index.d.ts.map +0 -1
  156. package/lib/components/MultiStep/index.js +0 -2
  157. package/lib/components/MultiStep/index.js.map +0 -1
@@ -0,0 +1,50 @@
1
+ import { ComponentType, Ref } from 'react';
2
+ import { BaseProps, DeferInfer, NoChildrenProp } from '../../types';
3
+ import { FormControlProps } from '../FormControl';
4
+ export interface CompositeInputProps<P extends object = object> extends BaseProps, NoChildrenProp {
5
+ /**
6
+ * Sets DOM id for the control and associates label element via 'for' attribute.
7
+ * If an id is not pass, a random id will be generated for any render.
8
+ */
9
+ id?: FormControlProps['id'];
10
+ /** Set visual state based on a validation state. */
11
+ status?: FormControlProps['status'];
12
+ /** Pass a string or a fragment with an Icon and string. */
13
+ label?: FormControlProps['label'];
14
+ /** Visually hides the label region. */
15
+ labelHidden?: FormControlProps['labelHidden'];
16
+ /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */
17
+ info?: FormControlProps['info'];
18
+ /** Indicate if the field is required. The browser defaults to false. */
19
+ required?: FormControlProps['required'];
20
+ /** Disable the control. The browser defaults to false. */
21
+ disabled?: FormControlProps['disabled'];
22
+ /** Callback when clear button is clicked. */
23
+ onClear: () => void;
24
+ /** String representation of the complex value. */
25
+ value?: string;
26
+ /** Text visible when on value has been set. */
27
+ placeholder?: FormControlProps['placeholder'];
28
+ /** Value form options. */
29
+ dialog: {
30
+ /**
31
+ * A component to render the main portion of the form.
32
+ */
33
+ renderer: ComponentType<P>;
34
+ /**
35
+ * A props object that will be passed to the form renderer.
36
+ */
37
+ rendererProps?: DeferInfer<P>;
38
+ /** Callback when cancel button is clicked. */
39
+ onCancel: ({ close }: {
40
+ close: () => void;
41
+ }) => void;
42
+ /** Callback when apply button is clicked. */
43
+ onApply: ({ close }: {
44
+ close: () => void;
45
+ }) => void;
46
+ };
47
+ /** Ref forwarded to the wrapping element. */
48
+ ref?: Ref<HTMLDivElement>;
49
+ }
50
+ //# sourceMappingURL=CompositeInput.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompositeInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/CompositeInput/CompositeInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACpE,OA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ACrD,CAAC;IACF,6CAA6C;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CompositeInput.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompositeInput.types.js","sourceRoot":"","sources":["../../../src/components/CompositeInput/CompositeInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { ComponentType, Ref } from 'react';\n\nimport { BaseProps, DeferInfer, NoChildrenProp } from '../../types';\nimport { FormControlProps } from '../FormControl';\n\nexport interface CompositeInputProps<P extends object = object> extends BaseProps, NoChildrenProp {\n /**\n * Sets DOM id for the control and associates label element via 'for' attribute.\n * If an id is not pass, a random id will be generated for any render.\n */\n id?: FormControlProps['id'];\n /** Set visual state based on a validation state. */\n status?: FormControlProps['status'];\n /** Pass a string or a fragment with an Icon and string. */\n label?: FormControlProps['label'];\n /** Visually hides the label region. */\n labelHidden?: FormControlProps['labelHidden'];\n /** It is recommended to pass a simple string to offer guidance. Text will be styled based on status prop. */\n info?: FormControlProps['info'];\n /** Indicate if the field is required. The browser defaults to false. */\n required?: FormControlProps['required'];\n /** Disable the control. The browser defaults to false. */\n disabled?: FormControlProps['disabled'];\n /** Callback when clear button is clicked. */\n onClear: () => void;\n /** String representation of the complex value. */\n value?: string;\n /** Text visible when on value has been set. */\n placeholder?: FormControlProps['placeholder'];\n /** Value form options. */\n dialog: {\n /**\n * A component to render the main portion of the form.\n */\n renderer: ComponentType<P>;\n /**\n * A props object that will be passed to the form renderer.\n */\n rendererProps?: DeferInfer<P>;\n /** Callback when cancel button is clicked. */\n onCancel: ({ close }: { close: () => void }) => void;\n /** Callback when apply button is clicked. */\n onApply: ({ close }: { close: () => void }) => void;\n };\n /** Ref forwarded to the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { default as CompositeInput } from './CompositeInput';
2
+ export { CompositeInputProps } from './CompositeInput.types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CompositeInput/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as CompositeInput } from './CompositeInput';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/CompositeInput/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { default as CompositeInput } from './CompositeInput';\nexport { CompositeInputProps } from './CompositeInput.types';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMtE,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,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAqD3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"CurrencyDisplay.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMtE,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,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAsD3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -2,10 +2,10 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
2
2
  import { forwardRef } from 'react';
3
3
  import { useConfiguration } from '../../hooks';
4
4
  import VisuallyHiddenText from '../VisuallyHiddenText';
5
- import { formatCurrency, isCurrencyISOCodeValid } from './utils';
5
+ import { formatCurrency, isValidCurrency } from './utils';
6
6
  const CurrencyDisplay = forwardRef(({ value, currencyISOCode, formattingOptions: { currency = 'symbol', negative = 'minus-sign', notation = 'standard', groupSeparators = true, fractionDigits } = {}, ...restProps }, ref) => {
7
7
  const { locale } = useConfiguration();
8
- const options = isCurrencyISOCodeValid(currencyISOCode)
8
+ const options = currencyISOCode && isValidCurrency(currencyISOCode)
9
9
  ? {
10
10
  style: 'currency',
11
11
  currency: currencyISOCode,
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyDisplay.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyDisplay.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAA2C,MAAM,OAAO,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAkCjE,MAAM,eAAe,GAA2D,UAAU,CACxF,CACE,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,EAChC,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAC;IAEtC,MAAM,OAAO,GAAG,sBAAsB,CAAC,eAAe,CAAC;QACrD,CAAC,CAAE;YACC,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,eAAe;YACzB,eAAe,EAAE,QAAQ;YACzB,WAAW,EAAE,eAAe;YAC5B,QAAQ;YACR,YAAY,EAAE,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;YACpE,qBAAqB,EAAE,cAAc;YACrC,qBAAqB,EAAE,cAAc;SACT;QAChC,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,SAAS,GAAG;QAChB,GAAG,OAAO;QACV,WAAW,EAAE,KAAK;QAClB,YAAY,EAAE,UAAU;QACxB,eAAe,EAAE,MAAM;KACxB,CAAC;IAEF,OAAO,CACL,eAAM,GAAG,EAAE,GAAG,KAAM,SAAS,YAC1B,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CACtB,8BACE,8BAAkB,MAAM,YAAE,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAQ,EAC5E,KAAC,kBAAkB,cAChB,cAAc,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,GACnC,IACpB,CACJ,CAAC,CAAC,CAAC,CACF,8BAAkB,MAAM,6BAAsB,CAC/C,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, Ref } from 'react';\n\nimport { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport { useConfiguration } from '../../hooks';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\n\nimport { formatCurrency, isCurrencyISOCodeValid } 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: FunctionComponent<CurrencyDisplayProps & ForwardProps> = forwardRef(\n (\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 = isCurrencyISOCodeValid(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 };\n\n return (\n <span ref={ref} {...restProps}>\n {value || value === 0 ? (\n <>\n <span aria-hidden='true'>{formatCurrency(value, { locale, options })}</span>\n <VisuallyHiddenText>\n {formatCurrency(value, { locale, options: srOptions })}\n </VisuallyHiddenText>\n </>\n ) : (\n <span aria-hidden='true'>&ndash;&ndash;</span>\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,EAA2C,MAAM,OAAO,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAEvD,OA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CAC/C,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, Ref } from 'react';\n\nimport { BaseProps, ForwardProps, NoChildrenProp } from '../../types';\nimport { useConfiguration } from '../../hooks';\nimport VisuallyHiddenText from '../VisuallyHiddenText';\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: FunctionComponent<CurrencyDisplayProps & ForwardProps> = forwardRef(\n (\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 };\n\n return (\n <span ref={ref} {...restProps}>\n {value || value === 0 ? (\n <>\n <span aria-hidden='true'>{formatCurrency(value, { locale, options })}</span>\n <VisuallyHiddenText>\n {formatCurrency(value, { locale, options: srOptions })}\n </VisuallyHiddenText>\n </>\n ) : (\n <span aria-hidden='true'>&ndash;&ndash;</span>\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":"AAAA,OAAO,EAAc,iBAAiB,EAAyC,MAAM,OAAO,CAAC;AAG7F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAOvD,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CA+EvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"CurrencyInput.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAgB3C,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AAGvD,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CA8HvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,39 +1,75 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, useCallback, useMemo } from 'react';
3
3
  import FormField from '../FormField';
4
- import { useConfiguration, useUID } from '../../hooks';
5
- import { NumberInput } from '../Number';
6
- import { getCurrencyMaximumFractionDigits, getCurrencySymbol, isCurrencyISOCodeValid } from './utils';
4
+ import { useConfiguration, useConsolidatedRef, useI18n, useInputFormatter, useUID } from '../../hooks';
5
+ import { getCleanedValue, getDecimalSign, getDecrementedValue, getIncrementedValue } from '../Number/utils';
6
+ import Input from '../Input';
7
+ import { getCurrencyMaximumFractionDigits, getFormattedValue, isValidCurrency } from './utils';
7
8
  const CurrencyInput = forwardRef((props, ref) => {
8
9
  const uid = useUID();
9
- const { id = uid, status, label, labelHidden, info, required, disabled, readOnly, value = '', onBlur, onFocus, showDecimal = true, currencyISOCode, alwaysShowISOCode = false, ...restProps } = props;
10
+ const { id = uid, status, label, labelHidden, info, required, disabled, readOnly, value = '', onChange, onBlur, onFocus, currencyISOCode, showDecimal = true, showGroupSeparators = true, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, step = 1, alwaysShowISOCode = false, ...restProps } = props;
10
11
  const { locale } = useConfiguration();
11
- const validCurrencyISOCode = useMemo(() => (isCurrencyISOCodeValid(currencyISOCode) ? currencyISOCode : undefined), [currencyISOCode]);
12
- const { symbol, symbolPlacement } = useMemo(() => getCurrencySymbol(locale, alwaysShowISOCode, validCurrencyISOCode), [locale, alwaysShowISOCode, validCurrencyISOCode]);
12
+ const t = useI18n();
13
+ const inputRef = useConsolidatedRef(ref);
14
+ const validCurrencyISOCode = useMemo(() => (currencyISOCode && isValidCurrency(currencyISOCode) ? currencyISOCode : undefined), [currencyISOCode]);
13
15
  const maximumFractionDigits = useMemo(() => getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode), [locale, validCurrencyISOCode]);
14
- const onInputFocusEvent = useCallback((callbackFn) => {
15
- if (!callbackFn)
16
+ const numberOfDecimals = showDecimal ? maximumFractionDigits : 0;
17
+ const decimalSign = useMemo(() => getDecimalSign(locale), [locale]);
18
+ const formatValue = useCallback(number => {
19
+ return getFormattedValue(number, locale, validCurrencyISOCode, {
20
+ showGroupSeparators,
21
+ showAs: alwaysShowISOCode ? 'code' : 'symbol',
22
+ numberOfDecimals
23
+ });
24
+ }, [showDecimal, numberOfDecimals, showGroupSeparators, locale, validCurrencyISOCode]);
25
+ const onInputChange = (e) => {
26
+ const inputValue = e.target.value;
27
+ const cleanedInputValue = getCleanedValue(inputValue, decimalSign, numberOfDecimals);
28
+ if (cleanedInputValue === value)
16
29
  return;
17
- return (inputValue) => {
18
- let formattedValue = inputValue;
19
- if (validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {
20
- const [integer, fraction = ''] = inputValue.split('.');
21
- formattedValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;
22
- }
23
- callbackFn(formattedValue);
24
- };
25
- }, [maximumFractionDigits]);
26
- const Comp = (_jsx(NumberInput, { numberOfDecimals: maximumFractionDigits, onFocus: onInputFocusEvent(onFocus), onBlur: onInputFocusEvent(onBlur), unit: symbol, unitPlacement: symbolPlacement, ...{
27
- ref,
28
- id,
29
- value,
30
- showDecimal,
31
- readOnly,
32
- required,
33
- disabled,
34
- status,
35
- ...restProps
36
- } }));
30
+ onChange(cleanedInputValue);
31
+ };
32
+ const onKeyDown = (e) => {
33
+ if (readOnly)
34
+ return;
35
+ const input = e.currentTarget;
36
+ switch (e.key) {
37
+ case 'ArrowUp':
38
+ e.preventDefault();
39
+ onChange(getIncrementedValue(value, min, max, step));
40
+ break;
41
+ case 'ArrowDown':
42
+ e.preventDefault();
43
+ onChange(getDecrementedValue(value, min, max, step));
44
+ break;
45
+ case decimalSign:
46
+ if (input.value.includes(decimalSign)) {
47
+ if (input.selectionStart && input.value.charAt(input.selectionStart) === decimalSign) {
48
+ input.setSelectionRange(input.selectionStart + 1, input.selectionStart + 1);
49
+ }
50
+ e.preventDefault();
51
+ }
52
+ break;
53
+ case '-':
54
+ if (value.startsWith('-'))
55
+ e.preventDefault();
56
+ break;
57
+ default:
58
+ }
59
+ };
60
+ const onInputFocusEvent = (e) => {
61
+ let parsableValue = value;
62
+ if (validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {
63
+ const [integer, fraction = ''] = value.split('.');
64
+ parsableValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;
65
+ }
66
+ if (e.type === 'focus')
67
+ onFocus?.(parsableValue);
68
+ else
69
+ onBlur?.(parsableValue);
70
+ };
71
+ const formattedValue = useInputFormatter(inputRef, value, formatValue, `\\p{N}${decimalSign}-`);
72
+ const Comp = (_jsx(Input, { ...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }, inputMode: 'numeric', ref: inputRef, value: formattedValue, onKeyDown: onKeyDown, onFocus: onInputFocusEvent, onBlur: onInputFocusEvent, "aria-label": `${label}. ${validCurrencyISOCode ? t('measured_in', [validCurrencyISOCode]) : ''}`, maxLength: 16 }));
37
73
  return label ? (_jsx(FormField, { ...{ label, labelHidden, id, info, status, required, disabled }, children: Comp })) : (Comp);
38
74
  });
39
75
  export default CurrencyInput;
@@ -1 +1 @@
1
- {"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE7F,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EACL,gCAAgC,EAChC,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAEjB,MAAM,aAAa,GAAyD,UAAU,CACpF,CAAC,KAA0C,EAAE,GAA8B,EAAE,EAAE;IAC7E,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EACJ,EAAE,GAAG,GAAG,EACR,MAAM,EACN,KAAK,EACL,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,KAAK,GAAG,EAAE,EACV,MAAM,EACN,OAAO,EACP,WAAW,GAAG,IAAI,EAClB,eAAe,EACf,iBAAiB,GAAG,KA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AG,CACX,KAAC,WAAW,IACV,gBAAgB,EAAE,qBAAqB,EACvC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,EACnC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,EACjC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,eAAe,KAC1B;YACF,GAAG;YACH,EAAE;YACF,KAAK;YACL,WAAW;YACX,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,MAAM;YACN,GAAG,SAAS;SACb,GACD,CACH,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YACxE,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, useCallback, useMemo } from 'react';\n\nimport FormField from '../FormField';\nimport { ForwardProps } from '../../types';\nimport { useConfiguration, useUID } from '../../hooks';\nimport { NumberInput } from '../Number';\n\nimport CurrencyInputProps from './CurrencyInput.types';\nimport {\n getCurrencyMaximumFractionDigits,\n getCurrencySymbol,\n isCurrencyISOCodeValid\n} from './utils';\n\nconst CurrencyInput: FunctionComponent<CurrencyInputProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<CurrencyInputProps>, ref: CurrencyInputProps['ref']) => {\n const uid = useUID();\n const {\n id = uid,\n status,\n label,\n labelHidden,\n info,\n required,\n disabled,\n readOnly,\n value = '',\n onBlur,\n onFocus,\n showDecimal = true,\n currencyISOCode,\n alwaysShowISOCode = false,\n ...restProps\n } = props;\n\n const { locale } = useConfiguration();\n const validCurrencyISOCode = useMemo(\n () => (isCurrencyISOCodeValid(currencyISOCode) ? currencyISOCode : undefined),\n [currencyISOCode]\n );\n const { symbol, symbolPlacement } = useMemo(\n () => getCurrencySymbol(locale, alwaysShowISOCode, validCurrencyISOCode),\n [locale, alwaysShowISOCode, validCurrencyISOCode]\n );\n const maximumFractionDigits = useMemo(\n () => getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode),\n [locale, validCurrencyISOCode]\n );\n\n const onInputFocusEvent = useCallback(\n (callbackFn: CurrencyInputProps['onFocus' | 'onBlur']) => {\n if (!callbackFn) return;\n return (inputValue: string) => {\n let formattedValue = inputValue;\n if (validCurrencyISOCode && !Number.isNaN(parseFloat(value))) {\n const [integer, fraction = ''] = inputValue.split('.');\n formattedValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;\n }\n callbackFn(formattedValue);\n };\n },\n [maximumFractionDigits]\n );\n\n const Comp = (\n <NumberInput\n numberOfDecimals={maximumFractionDigits}\n onFocus={onInputFocusEvent(onFocus)}\n onBlur={onInputFocusEvent(onBlur)}\n unit={symbol}\n unitPlacement={symbolPlacement}\n {...{\n ref,\n id,\n value,\n showDecimal,\n readOnly,\n required,\n disabled,\n status,\n ...restProps\n }}\n />\n );\n\n return label ? (\n <FormField {...{ label, labelHidden, id, info, status, required, disabled }}>\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default CurrencyInput;\n"]}
1
+ {"version":3,"file":"CurrencyInput.js","sourceRoot":"","sources":["../../../src/components/Currency/CurrencyInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,WAAW,EACX,OAAO,EAIR,MAAM,OAAO,CAAC;AAEf,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,OAAO,EACP,iBAAiB,EACjB,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,MAAM,UAAU,CAAC;AAG7B,OAAO,EAAE,gCAAgC,EAAE,iBAAiB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E,MAAM,EAAE,GAAG,SAAS,EAAE,EACvF,SAAS,EAAC,SAAS,EACnB,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,iBAAiB,gBACb,GAAG,KAAK,KAClB,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EACpE,EAAE,EACF,SAAS,EAAE,EAAE,GACb,CACH,CAAC;IAEF,OAAO,KAAK,CAAC,CAAC,CAAC,CACb,KAAC,SAAS,OAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,YACxE,IAAI,GACK,CACb,CAAC,CAAC,CAAC,CACF,IAAI,CACL,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useCallback,\n useMemo,\n KeyboardEvent,\n ChangeEvent,\n FocusEvent\n} from 'react';\n\nimport FormField from '../FormField';\nimport { ForwardProps } from '../../types';\nimport {\n useConfiguration,\n useConsolidatedRef,\n useI18n,\n useInputFormatter,\n useUID\n} from '../../hooks';\nimport {\n getCleanedValue,\n getDecimalSign,\n getDecrementedValue,\n getIncrementedValue\n} from '../Number/utils';\nimport Input from '../Input';\n\nimport CurrencyInputProps from './CurrencyInput.types';\nimport { getCurrencyMaximumFractionDigits, getFormattedValue, isValidCurrency } from './utils';\n\nconst CurrencyInput: FunctionComponent<CurrencyInputProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<CurrencyInputProps>, ref: CurrencyInputProps['ref']) => {\n const uid = useUID();\n const {\n id = uid,\n status,\n label,\n labelHidden,\n info,\n required,\n disabled,\n readOnly,\n value = '',\n onChange,\n onBlur,\n onFocus,\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 ...restProps\n } = props;\n\n const { locale } = useConfiguration();\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 maximumFractionDigits = useMemo(\n () => getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode),\n [locale, validCurrencyISOCode]\n );\n\n const numberOfDecimals = showDecimal ? maximumFractionDigits : 0;\n\n const decimalSign = useMemo(() => getDecimalSign(locale), [locale]);\n\n const formatValue = useCallback(\n number => {\n return getFormattedValue(number, locale, validCurrencyISOCode, {\n showGroupSeparators,\n showAs: alwaysShowISOCode ? 'code' : 'symbol',\n numberOfDecimals\n });\n },\n [showDecimal, 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 (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 }\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(maximumFractionDigits, '0')}`;\n }\n\n if (e.type === 'focus') onFocus?.(parsableValue);\n else onBlur?.(parsableValue);\n };\n\n const formattedValue = useInputFormatter(inputRef, value, formatValue, `\\\\p{N}${decimalSign}-`);\n\n const Comp = (\n <Input\n {...{ onChange: onInputChange, id, readOnly, required, disabled, status, ...restProps }}\n inputMode='numeric'\n ref={inputRef}\n value={formattedValue}\n onKeyDown={onKeyDown}\n onFocus={onInputFocusEvent}\n onBlur={onInputFocusEvent}\n aria-label={`${label}. ${\n validCurrencyISOCode ? t('measured_in', [validCurrencyISOCode]) : ''\n }`}\n maxLength={16}\n />\n );\n\n return label ? (\n <FormField {...{ label, labelHidden, id, info, status, required, disabled }}>\n {Comp}\n </FormField>\n ) : (\n Comp\n );\n }\n);\n\nexport default CurrencyInput;\n"]}
@@ -1,20 +1,10 @@
1
- export declare type CurrencySymbol = {
2
- symbol: string;
3
- symbolPlacement: 'before' | 'after';
4
- };
5
- export declare function getCurrencySymbol(locale: string, alwaysShowISOCode: boolean, currencyISOCode?: string): CurrencySymbol;
1
+ export declare const isValidCurrency: (currency: string) => boolean;
2
+ export declare const getFormattedValue: (value: string, locale: string, currency?: string | undefined, { showGroupSeparators, showAs, numberOfDecimals }?: {
3
+ showGroupSeparators?: boolean | undefined;
4
+ showAs?: "symbol" | "code" | undefined;
5
+ numberOfDecimals?: number | undefined;
6
+ }) => string;
6
7
  export declare function getCurrencyMaximumFractionDigits(locale: string, currencyISOCode?: string): number;
7
- export declare function isCurrencyISOCodeValid(currencyISOCode?: string): boolean;
8
- export declare function addTrailingZeros(valueToFormat: string, maximumFractionDigits: number, currencyISOCode?: string): string;
9
- declare type DisplayValueParams = {
10
- value: string;
11
- locale: string;
12
- alwaysShowISOCode: boolean;
13
- showDecimal: boolean;
14
- showGroupSeparators: boolean;
15
- currencyISOCode?: string;
16
- };
17
- export declare function getDisplayValue({ value, locale, alwaysShowISOCode, showDecimal, showGroupSeparators, currencyISOCode }: DisplayValueParams): string;
18
8
  interface CurrencyFormatOptions {
19
9
  locale: string;
20
10
  options?: Intl.NumberFormatOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"AAQA,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,QAAQ,GAAG,OAAO,CAAC;CACrC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,OAAO,EAC1B,eAAe,CAAC,EAAE,MAAM,GACvB,cAAc,CAmBhB;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAOjG;AAED,wBAAgB,sBAAsB,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAExE;AAED,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,MAAM,EACrB,qBAAqB,EAAE,MAAM,EAC7B,eAAe,CAAC,EAAE,MAAM,UAQzB;AAED,aAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,OAAO,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,MAAM,EACN,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,eAAe,EAChB,EAAE,kBAAkB,UA+BpB;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACpC;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,qBAAqB,UAIhG"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/Currency/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,aAAc,MAAM,YAQ/C,CAAC;AAEF,eAAO,MAAM,iBAAiB,UACrB,MAAM,UACL,MAAM;;;;YAiDf,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAOjG;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;CACpC;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,qBAAqB,UAIhG"}
@@ -1,24 +1,52 @@
1
1
  import { NUMBER_MAX_DECIMAL_PLACES } from '../Number/NumberInput.types';
2
- import { getFormattedValue } from '../Number/utils';
3
- // Currency & funds code list valid for Intl.NumberFormat(): https://www.currency-iso.org/en/home/tables/table-a1.html
4
- import currencyCodeList from './currencyCodes';
5
- export function getCurrencySymbol(locale, alwaysShowISOCode, currencyISOCode) {
6
- const options = currencyISOCode
7
- ? {
8
- style: 'currency',
9
- currency: currencyISOCode
10
- }
11
- : undefined;
12
- return new Intl.NumberFormat(locale, options).formatToParts(1).reduce((currencyObj, part, index) => {
13
- if (part.type === 'currency') {
14
- currencyObj.symbol = alwaysShowISOCode ? currencyISOCode || '' : part.value;
15
- if (index === 0) {
16
- currencyObj.symbolPlacement = 'before';
2
+ import { getFormattedValue as getNumberFormattedValue } from '../Number/utils';
3
+ export const isValidCurrency = (currency) => {
4
+ try {
5
+ // eslint-disable-next-line no-new
6
+ new Intl.NumberFormat(undefined, { style: 'currency', currency });
7
+ return true;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ };
13
+ export const getFormattedValue = (value, locale, currency, { showGroupSeparators = true, showAs = 'code', numberOfDecimals } = {}) => {
14
+ if (!currency)
15
+ return getNumberFormattedValue(value, locale, undefined, {
16
+ useGrouping: showGroupSeparators,
17
+ maximumFractionDigits: numberOfDecimals
18
+ });
19
+ const isCurrency = isValidCurrency(currency);
20
+ const [integer, fractionPart] = value.split('.', 2);
21
+ const formatter = new Intl.NumberFormat(locale, {
22
+ useGrouping: showGroupSeparators,
23
+ maximumFractionDigits: numberOfDecimals,
24
+ minimumFractionDigits: numberOfDecimals,
25
+ ...(isCurrency
26
+ ? {
27
+ style: 'currency',
28
+ currency,
29
+ currencyDisplay: showAs
17
30
  }
18
- }
19
- return currencyObj;
20
- }, { symbol: '', symbolPlacement: 'after' });
21
- }
31
+ : {})
32
+ });
33
+ let formatted = value;
34
+ if (value && !Number.isNaN(parseFloat(integer))) {
35
+ const endsWithDot = fractionPart === '';
36
+ const valueNumber = Number(endsWithDot ? `${value}1` : value);
37
+ formatted = formatter.formatToParts(valueNumber).reduce((result, { type, value: part }) => {
38
+ if (type === 'fraction' && endsWithDot)
39
+ return result;
40
+ return result + part;
41
+ }, '');
42
+ }
43
+ else if (currency) {
44
+ formatted = formatter
45
+ .formatToParts(value.startsWith('-') ? -1 : 1)
46
+ .reduce((result, { type, value: part }) => ['currency', 'minusSign'].includes(type) ? result + part : result, '');
47
+ }
48
+ return formatted;
49
+ };
22
50
  export function getCurrencyMaximumFractionDigits(locale, currencyISOCode) {
23
51
  return currencyISOCode
24
52
  ? new Intl.NumberFormat(locale, {
@@ -27,36 +55,6 @@ export function getCurrencyMaximumFractionDigits(locale, currencyISOCode) {
27
55
  }).resolvedOptions().maximumFractionDigits
28
56
  : NUMBER_MAX_DECIMAL_PLACES;
29
57
  }
30
- export function isCurrencyISOCodeValid(currencyISOCode) {
31
- return currencyISOCode ? currencyCodeList.has(currencyISOCode) : false;
32
- }
33
- export function addTrailingZeros(valueToFormat, maximumFractionDigits, currencyISOCode) {
34
- let formattedValue = valueToFormat;
35
- if (currencyISOCode && !Number.isNaN(parseFloat(valueToFormat))) {
36
- const [integer, fraction = ''] = valueToFormat.split('.');
37
- formattedValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;
38
- }
39
- return formattedValue;
40
- }
41
- export function getDisplayValue({ value, locale, alwaysShowISOCode, showDecimal, showGroupSeparators, currencyISOCode }) {
42
- const validCurrencyISOCode = isCurrencyISOCodeValid(currencyISOCode)
43
- ? currencyISOCode
44
- : undefined;
45
- const { symbol, symbolPlacement } = getCurrencySymbol(locale, alwaysShowISOCode, validCurrencyISOCode);
46
- const maximumFractionDigits = getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode);
47
- let sign = '';
48
- let formattedValue = getFormattedValue(!showDecimal
49
- ? value.split('.')[0]
50
- : addTrailingZeros(value, maximumFractionDigits, validCurrencyISOCode), locale, showGroupSeparators, maximumFractionDigits);
51
- if (formattedValue.startsWith('-')) {
52
- sign = '-';
53
- formattedValue = formattedValue.substring(1);
54
- }
55
- let symbolBefore = symbolPlacement === 'before' ? symbol : '';
56
- symbolBefore += symbolBefore === currencyISOCode ? ' ' : '';
57
- const symbolAfter = symbolPlacement === 'after' && symbol ? ` ${symbol}` : '';
58
- return `${sign}${symbolBefore}${formattedValue}${symbolAfter}`;
59
- }
60
58
  export function formatCurrency(value, { locale, options }) {
61
59
  const formatter = new Intl.NumberFormat(locale, options);
62
60
  return formatter.format(value);
@@ -1 +1 @@
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,EAAE,MAAM,iBAAiB,CAAC;AAEpD,sHAAsH;AACtH,OAAO,gBAAgB,MAAM,iBAAiB,CAAC;AAS/C,MAAM,UAAU,iBAAiB,CAC/B,MAAc,EACd,iBAA0B,E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AC,EAAE,CAAC;IAC9D,YAAY,IAAI,YAAY,KAAK,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5D,MAAM,WAAW,GAAG,eAAe,KAAK,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9E,OAAO,GAAG,IAAI,GAAG,YAAY,GAAG,cAAc,GAAG,WAAW,EAAE,CAAC;AACjE,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 } from '../Number/utils';\n\n// Currency & funds code list valid for Intl.NumberFormat(): https://www.currency-iso.org/en/home/tables/table-a1.html\nimport currencyCodeList from './currencyCodes';\n\ntype CurrencyPart = { type: string; value: string };\n\nexport type CurrencySymbol = {\n symbol: string;\n symbolPlacement: 'before' | 'after';\n};\n\nexport function getCurrencySymbol(\n locale: string,\n alwaysShowISOCode: boolean,\n currencyISOCode?: string\n): CurrencySymbol {\n const options = currencyISOCode\n ? {\n style: 'currency',\n currency: currencyISOCode\n }\n : undefined;\n return new Intl.NumberFormat(locale, options).formatToParts(1).reduce(\n (currencyObj: CurrencySymbol, part: CurrencyPart, index: number) => {\n if (part.type === 'currency') {\n currencyObj.symbol = alwaysShowISOCode ? currencyISOCode || '' : part.value;\n if (index === 0) {\n currencyObj.symbolPlacement = 'before';\n }\n }\n return currencyObj;\n },\n { symbol: '', symbolPlacement: 'after' }\n );\n}\n\nexport function getCurrencyMaximumFractionDigits(locale: string, currencyISOCode?: string): number {\n return currencyISOCode\n ? new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currencyISOCode\n }).resolvedOptions().maximumFractionDigits\n : NUMBER_MAX_DECIMAL_PLACES;\n}\n\nexport function isCurrencyISOCodeValid(currencyISOCode?: string): boolean {\n return currencyISOCode ? currencyCodeList.has(currencyISOCode) : false;\n}\n\nexport function addTrailingZeros(\n valueToFormat: string,\n maximumFractionDigits: number,\n currencyISOCode?: string\n) {\n let formattedValue = valueToFormat;\n if (currencyISOCode && !Number.isNaN(parseFloat(valueToFormat))) {\n const [integer, fraction = ''] = valueToFormat.split('.');\n formattedValue = `${integer}.${fraction.padEnd(maximumFractionDigits, '0')}`;\n }\n return formattedValue;\n}\n\ntype DisplayValueParams = {\n value: string;\n locale: string;\n alwaysShowISOCode: boolean;\n showDecimal: boolean;\n showGroupSeparators: boolean;\n currencyISOCode?: string;\n};\n\nexport function getDisplayValue({\n value,\n locale,\n alwaysShowISOCode,\n showDecimal,\n showGroupSeparators,\n currencyISOCode\n}: DisplayValueParams) {\n const validCurrencyISOCode = isCurrencyISOCodeValid(currencyISOCode)\n ? currencyISOCode\n : undefined;\n const { symbol, symbolPlacement } = getCurrencySymbol(\n locale,\n alwaysShowISOCode,\n validCurrencyISOCode\n );\n const maximumFractionDigits = getCurrencyMaximumFractionDigits(locale, validCurrencyISOCode);\n\n let sign = '';\n let formattedValue = getFormattedValue(\n !showDecimal\n ? value.split('.')[0]\n : addTrailingZeros(value, maximumFractionDigits, validCurrencyISOCode),\n locale,\n showGroupSeparators,\n maximumFractionDigits\n );\n if (formattedValue.startsWith('-')) {\n sign = '-';\n formattedValue = formattedValue.substring(1);\n }\n\n let symbolBefore = symbolPlacement === 'before' ? symbol : '';\n symbolBefore += symbolBefore === currencyISOCode ? ' ' : '';\n\n const symbolAfter = symbolPlacement === 'after' && symbol ? ` ${symbol}` : '';\n\n return `${sign}${symbolBefore}${formattedValue}${symbolAfter}`;\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;QACF,kCAAkC;QAClC,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAAa,EACb,MAAc,EACd,QAAiB,EACjB,EACE,mBAAmB,GAAG,IAAI,EAC1B,MAAM,GAAG,MAAM,EACf,gBAAgB,KAC4E,EAAE,EAChG,EAAE;IACF,IAAI,CAAC,QAAQ;QACX,OAAO,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE;YACvD,WAAW,EAAE,mBAAmB;YAChC,qBAAqB,EAAE,gBAAgB;SACxC,CAAC,CAAC;IAEL,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAsB,CAAC;IAEzE,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;QAC9C,WAAW,EAAE,mBAAmB;QAChC,qBAAqB,EAAE,gBAAgB;QACvC,qBAAqB,EAAE,gBAAgB;QACvC,GA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ACvF,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;QAC5C,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 if (!currency)\n return getNumberFormattedValue(value, locale, undefined, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits: numberOfDecimals\n });\n\n const isCurrency = isValidCurrency(currency);\n const [integer, fractionPart] = value.split('.', 2) as [string, string?];\n\n const formatter = new Intl.NumberFormat(locale, {\n useGrouping: showGroupSeparators,\n maximumFractionDigits: numberOfDecimals,\n minimumFractionDigits: numberOfDecimals,\n ...(isCurrency\n ? {\n style: 'currency',\n currency,\n currencyDisplay: showAs\n }\n : {})\n });\n\n let formatted = value;\n\n if (value && !Number.isNaN(parseFloat(integer))) {\n const endsWithDot = fractionPart === '';\n const valueNumber = Number(endsWithDot ? `${value}1` : value);\n formatted = formatter.formatToParts(valueNumber).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 getCurrencyMaximumFractionDigits(locale: string, currencyISOCode?: string): number {\n return currencyISOCode\n ? new Intl.NumberFormat(locale, {\n style: 'currency',\n currency: currencyISOCode\n }).resolvedOptions().maximumFractionDigits\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 +1 @@
1
- {"version":3,"file":"FieldGroup.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwB,iBAAiB,EAAmB,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASjG,OAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMtD,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAChD,sCAAsC;IACtC,QAAQ,EAAE,SAAS,CAAC;IACpB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAChC,2CAA2C;IAC3C,GAAG,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC;CAChC;AAQD,eAAO,MAAM,sBAAsB;UAAyB,OAAO;SAsClE,CAAC;AAIF,eAAO,MAAM,gBAAgB,8GAqC5B,CAAC;AAoBF,QAAA,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAgEjE,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"FieldGroup.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwB,iBAAiB,EAAmB,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASjG,OAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMtD,MAAM,WAAW,eAAgB,SAAQ,SAAS;IAChD,sCAAsC;IACtC,QAAQ,EAAE,SAAS,CAAC;IACpB,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAChC,2CAA2C;IAC3C,GAAG,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC;CAChC;AAQD,eAAO,MAAM,sBAAsB;UAAyB,OAAO;SAsClE,CAAC;AAIF,eAAO,MAAM,gBAAgB,8GAsC5B,CAAC;AAoBF,QAAA,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,GAAG,YAAY,CAgEjE,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -32,7 +32,7 @@ export const StyledFieldGroupLegend = styled.legend(({ open, theme: { base: { sp
32
32
  transform: rotate(0);
33
33
  }
34
34
 
35
- > ${StyledFlex} {
35
+ > ${StyledFlex} ${StyledButton} {
36
36
  min-height: ${hitAreaMouse};
37
37
 
38
38
  @media (pointer: 'coarse') {
@@ -41,10 +41,11 @@ export const StyledFieldGroupLegend = styled.legend(({ open, theme: { base: { sp
41
41
  }
42
42
  `);
43
43
  StyledFieldGroupLegend.defaultProps = defaultThemeProp;
44
- export const StyledFieldGroup = styled.fieldset(({ theme: { base: { 'font-size': fontSize, 'font-scale': fontScale }, components: { text } } }) => {
44
+ export const StyledFieldGroup = styled.fieldset(({ theme: { base: { 'font-size': fontSize, 'font-scale': fontScale, spacing }, components: { text } } }) => {
45
45
  const fontSizes = calculateFontSize(fontSize, fontScale);
46
46
  return css `
47
47
  border: none;
48
+ margin-block-start: calc(3 * ${spacing});
48
49
 
49
50
  ${StyledFieldGroupLegend} ${StyledButton} {
50
51
  font-weight: inherit;
@@ -1 +1 @@
1
- {"version":3,"file":"FieldGroup.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAsD,MAAM,OAAO,CAAC;AACjG,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,OAAyB,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,OAAO,EAA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AC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef, useState, FunctionComponent, PropsWithoutRef, Ref, ReactNode } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Button, { StyledButton } from '../Button';\nimport ExpandCollapse from '../ExpandCollapse';\nimport Flex, { StyledFlex } from '../Flex';\nimport HTML from '../HTML';\nimport Icon, { StyledIcon, registerIcon } from '../Icon';\nimport * as caretRightIcon from '../Icon/icons/caret-right.icon';\nimport Actions, { ActionsProps } from '../Actions';\nimport { defaultThemeProp } from '../../theme';\nimport { BaseProps, ForwardProps } from '../../types';\nimport { useI18n, useUID } from '../../hooks';\nimport { calculateFontSize, FontSize } from '../../styles';\n\nregisterIcon(caretRightIcon);\n\nexport interface FieldGroupProps extends BaseProps {\n /** The content of the Field Group. */\n children: ReactNode;\n /** A description of the field group to be displayed above the controls. */\n description?: string;\n /**\n * If true, the Field Group will be able to collapse the content of its children by clicking on the name.\n * @default false\n */\n collapsible?: boolean;\n /**\n * If true, the Field Group will be collapsed on the first render.\n * @default false\n */\n defaultCollapsed?: boolean;\n /** The name associated with the Field Group. */\n name?: string;\n /** An array of actions to add to the header. */\n actions?: ActionsProps['items'];\n /** A reference to the wrapping element. */\n ref?: Ref<HTMLFieldSetElement>;\n}\n\ninterface FieldGroupLegendProps {\n open: boolean;\n actions?: ActionsProps['items'];\n children?: ReactNode;\n}\n\nexport const StyledFieldGroupLegend = styled.legend<{ open: boolean }>(\n ({\n open,\n theme: {\n base: {\n spacing,\n animation,\n 'hit-area': { 'mouse-min': hitAreaMouse, 'finger-min': hitAreaFinger }\n }\n }\n }) => css`\n width: 100%;\n margin-bottom: 0;\n ${open &&\n css`\n margin-block-end: calc(1.5 * ${spacing});\n `}\n transition: margin-block-end ${animation.speed} ${animation.timing.ease};\n\n button ${StyledIcon} {\n transition: transform ${animation.speed} ${animation.timing.ease};\n }\n\n button[aria-expanded='true'] ${StyledIcon} {\n transform: rotate(90deg);\n }\n button[aria-expanded='false'] ${StyledIcon} {\n transform: rotate(0);\n }\n\n > ${StyledFlex} {\n min-height: ${hitAreaMouse};\n\n @media (pointer: 'coarse') {\n min-height: ${hitAreaFinger};\n }\n }\n `\n);\n\nStyledFieldGroupLegend.defaultProps = defaultThemeProp;\n\nexport const StyledFieldGroup = styled.fieldset(\n ({\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale },\n components: { text }\n }\n }) => {\n const fontSizes = calculateFontSize(fontSize, fontScale);\n\n return css`\n border: none;\n\n ${StyledFieldGroupLegend} ${StyledButton} {\n font-weight: inherit;\n }\n\n & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h3['font-size'] as FontSize]};\n font-weight: ${text.h3['font-weight']};\n }\n\n & & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h4['font-size'] as FontSize]};\n font-weight: ${text.h4['font-weight']};\n }\n\n & & & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h5['font-size'] as FontSize]};\n font-weight: ${text.h5['font-weight']};\n }\n\n & & & & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h6['font-size'] as FontSize]};\n font-weight: ${text.h6['font-weight']};\n }\n `;\n }\n);\n\nStyledFieldGroup.defaultProps = defaultThemeProp;\n\nconst FieldGroupLegend: FunctionComponent<FieldGroupLegendProps> = ({\n children,\n open,\n actions,\n ...restProps\n}) => {\n return (\n <StyledFieldGroupLegend open={open} {...restProps}>\n <Flex container={{ alignItems: 'center', justify: 'between' }}>\n {children}\n {actions && <Actions items={actions} />}\n </Flex>\n </StyledFieldGroupLegend>\n );\n};\n\nconst FieldGroup: FunctionComponent<FieldGroupProps & ForwardProps> = forwardRef(\n (\n {\n children,\n description,\n name,\n actions,\n collapsible = false,\n defaultCollapsed = false,\n ...restProps\n }: PropsWithoutRef<FieldGroupProps>,\n ref: FieldGroupProps['ref']\n ) => {\n const [open, setOpen] = useState(!defaultCollapsed);\n const t = useI18n();\n const uid = useUID();\n\n const descAndChildren = (\n <Flex container={{ direction: 'column', gap: 3 }}>\n {description && <HTML id={`${uid}-description`} as='p' content={description} />}\n <div>{children}</div>\n </Flex>\n );\n\n return (\n <StyledFieldGroup\n aria-label={name}\n aria-describedby={description ? `${uid}-description` : undefined}\n {...restProps}\n ref={ref}\n >\n {name && (\n <FieldGroupLegend open={open} actions={actions}>\n {collapsible ? (\n <Button\n type='button'\n variant='text'\n onClick={() => {\n setOpen(cur => !cur);\n }}\n aria-expanded={open ? 'true' : 'false'}\n aria-label={t(open ? 'collapse_noun' : 'expand_noun', [name])}\n >\n <Flex\n container={{ direction: 'row', alignItems: 'center', gap: 0.5 }}\n forwardedAs='span'\n >\n <Icon name='caret-right' />\n <span>{name}</span>\n </Flex>\n </Button>\n ) : (\n <span>{name}</span>\n )}\n </FieldGroupLegend>\n )}\n {collapsible ? (\n <ExpandCollapse collapsed={!open}>{descAndChildren}</ExpandCollapse>\n ) : (\n descAndChildren\n )}\n </StyledFieldGroup>\n );\n }\n);\n\nexport default FieldGroup;\n"]}
1
+ {"version":3,"file":"FieldGroup.js","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAsD,MAAM,OAAO,CAAC;AACjG,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,OAAyB,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,gBAAgB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,EAAE,CAAC,IAAI,YAAG,eAAe,GAAkB,CACrE,CAAC,CAAC,CAAC,CACF,eAAe,CAChB,IACgB,CACpB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef, useState, FunctionComponent, PropsWithoutRef, Ref, ReactNode } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport Button, { StyledButton } from '../Button';\nimport ExpandCollapse from '../ExpandCollapse';\nimport Flex, { StyledFlex } from '../Flex';\nimport HTML from '../HTML';\nimport Icon, { StyledIcon, registerIcon } from '../Icon';\nimport * as caretRightIcon from '../Icon/icons/caret-right.icon';\nimport Actions, { ActionsProps } from '../Actions';\nimport { defaultThemeProp } from '../../theme';\nimport { BaseProps, ForwardProps } from '../../types';\nimport { useI18n, useUID } from '../../hooks';\nimport { calculateFontSize, FontSize } from '../../styles';\n\nregisterIcon(caretRightIcon);\n\nexport interface FieldGroupProps extends BaseProps {\n /** The content of the Field Group. */\n children: ReactNode;\n /** A description of the field group to be displayed above the controls. */\n description?: string;\n /**\n * If true, the Field Group will be able to collapse the content of its children by clicking on the name.\n * @default false\n */\n collapsible?: boolean;\n /**\n * If true, the Field Group will be collapsed on the first render.\n * @default false\n */\n defaultCollapsed?: boolean;\n /** The name associated with the Field Group. */\n name?: string;\n /** An array of actions to add to the header. */\n actions?: ActionsProps['items'];\n /** A reference to the wrapping element. */\n ref?: Ref<HTMLFieldSetElement>;\n}\n\ninterface FieldGroupLegendProps {\n open: boolean;\n actions?: ActionsProps['items'];\n children?: ReactNode;\n}\n\nexport const StyledFieldGroupLegend = styled.legend<{ open: boolean }>(\n ({\n open,\n theme: {\n base: {\n spacing,\n animation,\n 'hit-area': { 'mouse-min': hitAreaMouse, 'finger-min': hitAreaFinger }\n }\n }\n }) => css`\n width: 100%;\n margin-bottom: 0;\n ${open &&\n css`\n margin-block-end: calc(1.5 * ${spacing});\n `}\n transition: margin-block-end ${animation.speed} ${animation.timing.ease};\n\n button ${StyledIcon} {\n transition: transform ${animation.speed} ${animation.timing.ease};\n }\n\n button[aria-expanded='true'] ${StyledIcon} {\n transform: rotate(90deg);\n }\n button[aria-expanded='false'] ${StyledIcon} {\n transform: rotate(0);\n }\n\n > ${StyledFlex} ${StyledButton} {\n min-height: ${hitAreaMouse};\n\n @media (pointer: 'coarse') {\n min-height: ${hitAreaFinger};\n }\n }\n `\n);\n\nStyledFieldGroupLegend.defaultProps = defaultThemeProp;\n\nexport const StyledFieldGroup = styled.fieldset(\n ({\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale, spacing },\n components: { text }\n }\n }) => {\n const fontSizes = calculateFontSize(fontSize, fontScale);\n\n return css`\n border: none;\n margin-block-start: calc(3 * ${spacing});\n\n ${StyledFieldGroupLegend} ${StyledButton} {\n font-weight: inherit;\n }\n\n & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h3['font-size'] as FontSize]};\n font-weight: ${text.h3['font-weight']};\n }\n\n & & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h4['font-size'] as FontSize]};\n font-weight: ${text.h4['font-weight']};\n }\n\n & & & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h5['font-size'] as FontSize]};\n font-weight: ${text.h5['font-weight']};\n }\n\n & & & & ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.h6['font-size'] as FontSize]};\n font-weight: ${text.h6['font-weight']};\n }\n `;\n }\n);\n\nStyledFieldGroup.defaultProps = defaultThemeProp;\n\nconst FieldGroupLegend: FunctionComponent<FieldGroupLegendProps> = ({\n children,\n open,\n actions,\n ...restProps\n}) => {\n return (\n <StyledFieldGroupLegend open={open} {...restProps}>\n <Flex container={{ alignItems: 'center', justify: 'between' }}>\n {children}\n {actions && <Actions items={actions} />}\n </Flex>\n </StyledFieldGroupLegend>\n );\n};\n\nconst FieldGroup: FunctionComponent<FieldGroupProps & ForwardProps> = forwardRef(\n (\n {\n children,\n description,\n name,\n actions,\n collapsible = false,\n defaultCollapsed = false,\n ...restProps\n }: PropsWithoutRef<FieldGroupProps>,\n ref: FieldGroupProps['ref']\n ) => {\n const [open, setOpen] = useState(!defaultCollapsed);\n const t = useI18n();\n const uid = useUID();\n\n const descAndChildren = (\n <Flex container={{ direction: 'column', gap: 3 }}>\n {description && <HTML id={`${uid}-description`} as='p' content={description} />}\n <div>{children}</div>\n </Flex>\n );\n\n return (\n <StyledFieldGroup\n aria-label={name}\n aria-describedby={description ? `${uid}-description` : undefined}\n {...restProps}\n ref={ref}\n >\n {name && (\n <FieldGroupLegend open={open} actions={actions}>\n {collapsible ? (\n <Button\n type='button'\n variant='text'\n onClick={() => {\n setOpen(cur => !cur);\n }}\n aria-expanded={open ? 'true' : 'false'}\n aria-label={t(open ? 'collapse_noun' : 'expand_noun', [name])}\n >\n <Flex\n container={{ direction: 'row', alignItems: 'center', gap: 0.5 }}\n forwardedAs='span'\n >\n <Icon name='caret-right' />\n <span>{name}</span>\n </Flex>\n </Button>\n ) : (\n <span>{name}</span>\n )}\n </FieldGroupLegend>\n )}\n {collapsible ? (\n <ExpandCollapse collapsed={!open}>{descAndChildren}</ExpandCollapse>\n ) : (\n descAndChildren\n )}\n </StyledFieldGroup>\n );\n }\n);\n\nexport default FieldGroup;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"FieldGroupList.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA+B,GAAG,EAAE,MAAM,OAAO,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,OAAmB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI3D,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAWD,eAAO,MAAM,cAAc,qJAe1B,CAAC;AAaF,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA6CzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"FieldGroupList.d.ts","sourceRoot":"","sources":["../../../src/components/FieldGroup/FieldGroupList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA+B,GAAG,EAAE,MAAM,OAAO,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,OAAmB,EAAE,eAAe,EAAoB,MAAM,cAAc,CAAC;AAI7E,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,uBAAuB,EAAE,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B;AAeD,eAAO,MAAM,cAAc,qJAe1B,CAAC;AAaF,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA6CzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -6,10 +6,14 @@ import Icon, { registerIcon } from '../Icon';
6
6
  import * as plusIcon from '../Icon/icons/plus.icon';
7
7
  import { useI18n } from '../../hooks';
8
8
  import { defaultThemeProp } from '../../theme';
9
- import FieldGroup from './FieldGroup';
9
+ import FieldGroup, { StyledFieldGroup } from './FieldGroup';
10
10
  registerIcon(plusIcon);
11
11
  const StyledFieldGroupList = styled.div(({ theme }) => css `
12
- margin-top: ${theme.base.spacing};
12
+ margin-block-start: ${theme.base.spacing};
13
+
14
+ ${StyledFieldGroup} {
15
+ margin-block-start: 0;
16
+ }
13
17
  `);
14
18
  StyledFieldGroupList.defaultProps = defaultThemeProp;
15
19
  export const StyledListItem = styled(FieldGroup)(({ theme }) => css `