@transferwise/components 0.0.0-experimental-b3df26d → 0.0.0-experimental-050f154

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 (121) hide show
  1. package/build/expressiveMoneyInput/AmountInput.js +281 -0
  2. package/build/expressiveMoneyInput/AmountInput.js.map +1 -0
  3. package/build/expressiveMoneyInput/AmountInput.mjs +279 -0
  4. package/build/expressiveMoneyInput/AmountInput.mjs.map +1 -0
  5. package/build/expressiveMoneyInput/AnimatedNumber.js +50 -0
  6. package/build/expressiveMoneyInput/AnimatedNumber.js.map +1 -0
  7. package/build/expressiveMoneyInput/AnimatedNumber.mjs +48 -0
  8. package/build/expressiveMoneyInput/AnimatedNumber.mjs.map +1 -0
  9. package/build/expressiveMoneyInput/Chevron.js +33 -0
  10. package/build/expressiveMoneyInput/Chevron.js.map +1 -0
  11. package/build/expressiveMoneyInput/Chevron.mjs +31 -0
  12. package/build/expressiveMoneyInput/Chevron.mjs.map +1 -0
  13. package/build/expressiveMoneyInput/CurrencySelector.js +160 -0
  14. package/build/expressiveMoneyInput/CurrencySelector.js.map +1 -0
  15. package/build/expressiveMoneyInput/CurrencySelector.mjs +157 -0
  16. package/build/expressiveMoneyInput/CurrencySelector.mjs.map +1 -0
  17. package/build/expressiveMoneyInput/ExpressiveMoneyInput.js +114 -0
  18. package/build/expressiveMoneyInput/ExpressiveMoneyInput.js.map +1 -0
  19. package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.js +17 -0
  20. package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.js.map +1 -0
  21. package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.mjs +13 -0
  22. package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.mjs.map +1 -0
  23. package/build/expressiveMoneyInput/ExpressiveMoneyInput.mjs +110 -0
  24. package/build/expressiveMoneyInput/ExpressiveMoneyInput.mjs.map +1 -0
  25. package/build/expressiveMoneyInput/useFocus.js +37 -0
  26. package/build/expressiveMoneyInput/useFocus.js.map +1 -0
  27. package/build/expressiveMoneyInput/useFocus.mjs +35 -0
  28. package/build/expressiveMoneyInput/useFocus.mjs.map +1 -0
  29. package/build/expressiveMoneyInput/useInputStyle.js +71 -0
  30. package/build/expressiveMoneyInput/useInputStyle.js.map +1 -0
  31. package/build/expressiveMoneyInput/useInputStyle.mjs +69 -0
  32. package/build/expressiveMoneyInput/useInputStyle.mjs.map +1 -0
  33. package/build/expressiveMoneyInput/utils.js +87 -0
  34. package/build/expressiveMoneyInput/utils.js.map +1 -0
  35. package/build/expressiveMoneyInput/utils.mjs +78 -0
  36. package/build/expressiveMoneyInput/utils.mjs.map +1 -0
  37. package/build/i18n/en.json +2 -0
  38. package/build/i18n/en.json.js +2 -0
  39. package/build/i18n/en.json.js.map +1 -1
  40. package/build/i18n/en.json.mjs +2 -0
  41. package/build/i18n/en.json.mjs.map +1 -1
  42. package/build/index.js +2 -0
  43. package/build/index.js.map +1 -1
  44. package/build/index.mjs +1 -0
  45. package/build/index.mjs.map +1 -1
  46. package/build/main.css +65 -7
  47. package/build/prompt/InlinePrompt/InlinePrompt.js +7 -0
  48. package/build/prompt/InlinePrompt/InlinePrompt.js.map +1 -1
  49. package/build/prompt/InlinePrompt/InlinePrompt.mjs +8 -1
  50. package/build/prompt/InlinePrompt/InlinePrompt.mjs.map +1 -1
  51. package/build/styles/expressiveMoneyInput/AmountInput.css +32 -0
  52. package/build/styles/expressiveMoneyInput/Chevron.css +12 -0
  53. package/build/styles/expressiveMoneyInput/CurrencySelector.css +6 -0
  54. package/build/styles/expressiveMoneyInput/ExpressiveMoneyInput.css +58 -0
  55. package/build/styles/main.css +65 -7
  56. package/build/styles/prompt/InlinePrompt/InlinePrompt.css +7 -7
  57. package/build/types/expressiveMoneyInput/AmountInput.d.ts +13 -0
  58. package/build/types/expressiveMoneyInput/AmountInput.d.ts.map +1 -0
  59. package/build/types/expressiveMoneyInput/AnimatedNumber.d.ts +9 -0
  60. package/build/types/expressiveMoneyInput/AnimatedNumber.d.ts.map +1 -0
  61. package/build/types/expressiveMoneyInput/Chevron.d.ts +6 -0
  62. package/build/types/expressiveMoneyInput/Chevron.d.ts.map +1 -0
  63. package/build/types/expressiveMoneyInput/CurrencySelector.d.ts +30 -0
  64. package/build/types/expressiveMoneyInput/CurrencySelector.d.ts.map +1 -0
  65. package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.d.ts +33 -0
  66. package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.d.ts.map +1 -0
  67. package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.messages.d.ts +12 -0
  68. package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.messages.d.ts.map +1 -0
  69. package/build/types/expressiveMoneyInput/index.d.ts +3 -0
  70. package/build/types/expressiveMoneyInput/index.d.ts.map +1 -0
  71. package/build/types/expressiveMoneyInput/useFocus.d.ts +7 -0
  72. package/build/types/expressiveMoneyInput/useFocus.d.ts.map +1 -0
  73. package/build/types/expressiveMoneyInput/useInputStyle.d.ts +10 -0
  74. package/build/types/expressiveMoneyInput/useInputStyle.d.ts.map +1 -0
  75. package/build/types/expressiveMoneyInput/useSelectionRange.d.ts +10 -0
  76. package/build/types/expressiveMoneyInput/useSelectionRange.d.ts.map +1 -0
  77. package/build/types/expressiveMoneyInput/utils.d.ts +22 -0
  78. package/build/types/expressiveMoneyInput/utils.d.ts.map +1 -0
  79. package/build/types/index.d.ts +2 -0
  80. package/build/types/index.d.ts.map +1 -1
  81. package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts +3 -2
  82. package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts.map +1 -1
  83. package/build/types/test-utils/index.d.ts +4 -0
  84. package/build/types/test-utils/index.d.ts.map +1 -1
  85. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  86. package/build/withDisplayFormat/WithDisplayFormat.js +1 -0
  87. package/build/withDisplayFormat/WithDisplayFormat.js.map +1 -1
  88. package/build/withDisplayFormat/WithDisplayFormat.mjs +1 -0
  89. package/build/withDisplayFormat/WithDisplayFormat.mjs.map +1 -1
  90. package/package.json +1 -1
  91. package/src/expressiveMoneyInput/AmountInput.css +32 -0
  92. package/src/expressiveMoneyInput/AmountInput.less +43 -0
  93. package/src/expressiveMoneyInput/AmountInput.tsx +353 -0
  94. package/src/expressiveMoneyInput/AnimatedNumber.tsx +40 -0
  95. package/src/expressiveMoneyInput/Chevron.css +12 -0
  96. package/src/expressiveMoneyInput/Chevron.less +13 -0
  97. package/src/expressiveMoneyInput/Chevron.tsx +35 -0
  98. package/src/expressiveMoneyInput/CurrencySelector.css +6 -0
  99. package/src/expressiveMoneyInput/CurrencySelector.less +7 -0
  100. package/src/expressiveMoneyInput/CurrencySelector.tsx +218 -0
  101. package/src/expressiveMoneyInput/ExpressiveMoneyInput.css +58 -0
  102. package/src/expressiveMoneyInput/ExpressiveMoneyInput.less +13 -0
  103. package/src/expressiveMoneyInput/ExpressiveMoneyInput.messages.ts +13 -0
  104. package/src/expressiveMoneyInput/ExpressiveMoneyInput.story.tsx +290 -0
  105. package/src/expressiveMoneyInput/ExpressiveMoneyInput.tsx +118 -0
  106. package/src/expressiveMoneyInput/index.ts +2 -0
  107. package/src/expressiveMoneyInput/useFocus.ts +35 -0
  108. package/src/expressiveMoneyInput/useInputStyle.ts +85 -0
  109. package/src/expressiveMoneyInput/useSelectionRange.ts +23 -0
  110. package/src/expressiveMoneyInput/utils.spec.ts +114 -0
  111. package/src/expressiveMoneyInput/utils.ts +116 -0
  112. package/src/i18n/en.json +2 -0
  113. package/src/index.ts +2 -0
  114. package/src/main.css +65 -7
  115. package/src/main.less +1 -0
  116. package/src/prompt/InlinePrompt/InlinePrompt.css +7 -7
  117. package/src/prompt/InlinePrompt/InlinePrompt.less +7 -7
  118. package/src/prompt/InlinePrompt/InlinePrompt.story.tsx +49 -0
  119. package/src/prompt/InlinePrompt/InlinePrompt.tsx +12 -2
  120. package/src/ssr.spec.tsx +1 -0
  121. package/src/withDisplayFormat/WithDisplayFormat.tsx +1 -0
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var Body = require('../body/Body.js');
6
+ var Label = require('../label/Label.js');
7
+ var clsx = require('clsx');
8
+ var framerMotion = require('framer-motion');
9
+ var React = require('react');
10
+ var CurrencySelector = require('./CurrencySelector.js');
11
+ var AmountInput = require('./AmountInput.js');
12
+ var Chevron = require('./Chevron.js');
13
+ var InlinePrompt = require('../prompt/InlinePrompt/InlinePrompt.js');
14
+ var jsxRuntime = require('react/jsx-runtime');
15
+
16
+ function ExpressiveMoneyInput({
17
+ label,
18
+ currency,
19
+ currencySelector = {
20
+ options: []
21
+ },
22
+ amount,
23
+ onAmountChange,
24
+ className,
25
+ inlinePrompt,
26
+ showChevron,
27
+ autoFocus,
28
+ loading,
29
+ onFocusChange
30
+ }) {
31
+ const inputId = React.useId();
32
+ const labelId = React.useId();
33
+ const customAlertId = React.useId();
34
+ const currencyId = React.useId();
35
+ const selector = currencySelector.customRender?.({
36
+ id: currencyId,
37
+ labelId
38
+ }) ?? /*#__PURE__*/jsxRuntime.jsx(CurrencySelector.CurrencySelector, {
39
+ id: currencyId,
40
+ labelId: labelId,
41
+ currency: currency,
42
+ ...currencySelector
43
+ });
44
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
45
+ className: clsx.clsx('wds-expressive-money-input', className),
46
+ children: [/*#__PURE__*/jsxRuntime.jsx(Label.Label, {
47
+ id: labelId,
48
+ htmlFor: inputId,
49
+ className: clsx.clsx('m-b-1', 'font-weight-normal'),
50
+ children: label
51
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
52
+ className: clsx.clsx('d-flex'),
53
+ role: "group",
54
+ "aria-labelledby": labelId,
55
+ ...(inlinePrompt ? {
56
+ 'aria-describedby': customAlertId
57
+ } : {}),
58
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
59
+ className: "wds-expressive-money-input-currency-selector",
60
+ children: selector
61
+ }), /*#__PURE__*/jsxRuntime.jsx(AmountInput.AmountInput, {
62
+ id: inputId,
63
+ describedById: currencyId,
64
+ amount: amount,
65
+ currency: currency
66
+ // eslint-disable-next-line jsx-a11y/no-autofocus
67
+ ,
68
+ autoFocus: autoFocus,
69
+ loading: loading,
70
+ onChange: onAmountChange,
71
+ onFocusChange: onFocusChange
72
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
73
+ className: clsx.clsx('d-flex align-items-center', 'wds-expressive-money-input-chevron'),
74
+ children: /*#__PURE__*/jsxRuntime.jsx(Chevron.Chevron, {
75
+ shouldShow: Boolean(showChevron)
76
+ })
77
+ })]
78
+ }), /*#__PURE__*/jsxRuntime.jsx(framerMotion.AnimatePresence, {
79
+ initial: false,
80
+ children: inlinePrompt && /*#__PURE__*/jsxRuntime.jsx("div", {
81
+ className: clsx.clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1'),
82
+ children: /*#__PURE__*/jsxRuntime.jsx(framerMotion.motion.div, {
83
+ initial: {
84
+ opacity: 0,
85
+ height: 0
86
+ },
87
+ animate: {
88
+ opacity: 1,
89
+ height: 'auto',
90
+ transition: {
91
+ delay: 0.75,
92
+ duration: 0.3
93
+ }
94
+ },
95
+ exit: {
96
+ opacity: 0,
97
+ height: 0
98
+ },
99
+ children: inlinePrompt.sentiment ? /*#__PURE__*/jsxRuntime.jsx(InlinePrompt.InlinePrompt, {
100
+ id: customAlertId,
101
+ media: inlinePrompt.media,
102
+ sentiment: inlinePrompt.sentiment,
103
+ children: inlinePrompt.message
104
+ }) : /*#__PURE__*/jsxRuntime.jsx(Body.default, {
105
+ children: inlinePrompt.message
106
+ })
107
+ }, customAlertId)
108
+ })
109
+ })]
110
+ });
111
+ }
112
+
113
+ exports.default = ExpressiveMoneyInput;
114
+ //# sourceMappingURL=ExpressiveMoneyInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpressiveMoneyInput.js","sources":["../../src/expressiveMoneyInput/ExpressiveMoneyInput.tsx"],"sourcesContent":["import Body from '../body';\nimport { Label } from '../label/Label';\nimport { clsx } from 'clsx';\nimport { AnimatePresence, motion } from 'framer-motion';\nimport { useId, type ReactNode } from 'react';\n\nimport { type Props as CurrencySelectorProps, CurrencySelector } from './CurrencySelector';\nimport { CommonProps } from '../common';\nimport { AmountInput } from './AmountInput';\nimport { Chevron } from './Chevron';\nimport { InlinePrompt, type InlinePromptProps } from '../prompt/InlinePrompt';\n\ntype AmountType = number | null;\nexport type CurrencyType = string;\n\ntype DefaultCurrencySelectorInstanceType = Pick<\n CurrencySelectorProps,\n 'addons' | 'options' | 'onChange' | 'onOpen' | 'onSearchChange'\n>;\ntype CustomCurrencySelectorInstanceType = {\n customRender?: (props: { id: string; labelId: string }) => ReactNode;\n};\ntype CurrencySelectorType = DefaultCurrencySelectorInstanceType &\n CustomCurrencySelectorInstanceType;\n\nexport type Props = {\n label?: ReactNode;\n currencySelector?: CurrencySelectorType;\n amount?: AmountType;\n currency: CurrencyType;\n inlinePrompt?: {\n sentiment?: InlinePromptProps['sentiment'];\n message: InlinePromptProps['children'];\n media?: InlinePromptProps['media'];\n };\n showChevron?: boolean;\n autoFocus?: boolean;\n loading?: boolean;\n onAmountChange: (amount: AmountType) => void;\n onFocusChange?: (focused: boolean) => void;\n} & CommonProps;\n\nexport default function ExpressiveMoneyInput({\n label,\n currency,\n currencySelector = { options: [] } as DefaultCurrencySelectorInstanceType,\n amount,\n onAmountChange,\n className,\n inlinePrompt,\n showChevron,\n autoFocus,\n loading,\n onFocusChange,\n}: Props) {\n const inputId = useId();\n const labelId = useId();\n const customAlertId = useId();\n const currencyId = useId();\n\n const selector = currencySelector.customRender?.({ id: currencyId, labelId }) ?? (\n <CurrencySelector id={currencyId} labelId={labelId} currency={currency} {...currencySelector} />\n );\n\n return (\n <div className={clsx('wds-expressive-money-input', className)}>\n <Label id={labelId} htmlFor={inputId} className={clsx('m-b-1', 'font-weight-normal')}>\n {label}\n </Label>\n <div\n className={clsx('d-flex')}\n role=\"group\"\n aria-labelledby={labelId}\n {...(inlinePrompt ? { 'aria-describedby': customAlertId } : {})}\n >\n <div className=\"wds-expressive-money-input-currency-selector\">{selector}</div>\n <AmountInput\n id={inputId}\n describedById={currencyId}\n amount={amount}\n currency={currency}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n loading={loading}\n onChange={onAmountChange}\n onFocusChange={onFocusChange}\n />\n <div className={clsx('d-flex align-items-center', 'wds-expressive-money-input-chevron')}>\n <Chevron shouldShow={Boolean(showChevron)} />\n </div>\n </div>\n <AnimatePresence initial={false}>\n {inlinePrompt && (\n <div className={clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1')}>\n <motion.div\n key={customAlertId}\n initial={{ opacity: 0, height: 0 }}\n animate={{\n opacity: 1,\n height: 'auto',\n transition: { delay: 0.75, duration: 0.3 },\n }}\n exit={{ opacity: 0, height: 0 }}\n >\n {inlinePrompt.sentiment ? (\n <InlinePrompt id={customAlertId} media={inlinePrompt.media} sentiment={inlinePrompt.sentiment}>\n {inlinePrompt.message}\n </InlinePrompt>\n ) : (\n <Body>{inlinePrompt.message}</Body>\n )}\n </motion.div>\n </div>\n )}\n </AnimatePresence>\n </div>\n );\n}\n"],"names":["ExpressiveMoneyInput","label","currency","currencySelector","options","amount","onAmountChange","className","inlinePrompt","showChevron","autoFocus","loading","onFocusChange","inputId","useId","labelId","customAlertId","currencyId","selector","customRender","id","_jsx","CurrencySelector","_jsxs","clsx","children","Label","htmlFor","role","AmountInput","describedById","onChange","Chevron","shouldShow","Boolean","AnimatePresence","initial","motion","div","opacity","height","animate","transition","delay","duration","exit","sentiment","InlinePrompt","media","message","Body"],"mappings":";;;;;;;;;;;;;;;AA0Cc,SAAUA,oBAAoBA,CAAC;EAC3CC,KAAK;EACLC,QAAQ;AACRC,EAAAA,gBAAgB,GAAG;AAAEC,IAAAA,OAAO,EAAE;GAA2C;EACzEC,MAAM;EACNC,cAAc;EACdC,SAAS;EACTC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A,QAAA,EAE/BjB,YAAY,CAACsC,SAAS,gBACrBzB,cAAA,CAAC0B,yBAAY,EAAA;AAAC3B,YAAAA,EAAE,EAAEJ,aAAc;YAACgC,KAAK,EAAExC,YAAY,CAACwC,KAAM;YAACF,SAAS,EAAEtC,YAAY,CAACsC,SAAU;YAAArB,QAAA,EAC3FjB,YAAY,CAACyC;AAAO,WACT,CAAC,gBAEf5B,cAAA,CAAC6B,YAAI,EAAA;YAAAzB,QAAA,EAAEjB,YAAY,CAACyC;WAAc;AACnC,SAAA,EAfIjC,aAgBK;OACT;AACN,KACc,CACnB;AAAA,GAAK,CAAC;AAEV;;;;"}
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var reactIntl = require('react-intl');
6
+
7
+ var messages = reactIntl.defineMessages({
8
+ currencySelectorSearchPlaceholder: {
9
+ id: "neptune.ExpressiveMoneyInput.currency.search.placeholder"
10
+ },
11
+ currencySelectorSelectCurrency: {
12
+ id: "neptune.ExpressiveMoneyInput.currency.select.currency"
13
+ }
14
+ });
15
+
16
+ exports.default = messages;
17
+ //# sourceMappingURL=ExpressiveMoneyInput.messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpressiveMoneyInput.messages.js","sources":["../../src/expressiveMoneyInput/ExpressiveMoneyInput.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n currencySelectorSearchPlaceholder: {\n id: 'neptune.ExpressiveMoneyInput.currency.search.placeholder',\n defaultMessage: 'Type a currency / country',\n },\n\n currencySelectorSelectCurrency: {\n id: 'neptune.ExpressiveMoneyInput.currency.select.currency',\n defaultMessage: 'Select currency',\n },\n});\n"],"names":["defineMessages","currencySelectorSearchPlaceholder","id","currencySelectorSelectCurrency"],"mappings":";;;;;;AAEA,eAAeA,wBAAc,CAAC;AAC5BC,EAAAA,iCAAiC,EAAE;IACjCC,EAAE,EAAA;GAEH;AAEDC,EAAAA,8BAA8B,EAAE;IAC9BD,EAAE,EAAA;AAEH;AACF,CAAA,CAAC;;;;"}
@@ -0,0 +1,13 @@
1
+ import { defineMessages } from 'react-intl';
2
+
3
+ var messages = defineMessages({
4
+ currencySelectorSearchPlaceholder: {
5
+ id: "neptune.ExpressiveMoneyInput.currency.search.placeholder"
6
+ },
7
+ currencySelectorSelectCurrency: {
8
+ id: "neptune.ExpressiveMoneyInput.currency.select.currency"
9
+ }
10
+ });
11
+
12
+ export { messages as default };
13
+ //# sourceMappingURL=ExpressiveMoneyInput.messages.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpressiveMoneyInput.messages.mjs","sources":["../../src/expressiveMoneyInput/ExpressiveMoneyInput.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n currencySelectorSearchPlaceholder: {\n id: 'neptune.ExpressiveMoneyInput.currency.search.placeholder',\n defaultMessage: 'Type a currency / country',\n },\n\n currencySelectorSelectCurrency: {\n id: 'neptune.ExpressiveMoneyInput.currency.select.currency',\n defaultMessage: 'Select currency',\n },\n});\n"],"names":["defineMessages","currencySelectorSearchPlaceholder","id","currencySelectorSelectCurrency"],"mappings":";;AAEA,eAAeA,cAAc,CAAC;AAC5BC,EAAAA,iCAAiC,EAAE;IACjCC,EAAE,EAAA;GAEH;AAEDC,EAAAA,8BAA8B,EAAE;IAC9BD,EAAE,EAAA;AAEH;AACF,CAAA,CAAC;;;;"}
@@ -0,0 +1,110 @@
1
+ import Body from '../body/Body.mjs';
2
+ import { Label as LabelNamespace } from '../label/Label.mjs';
3
+ import { clsx } from 'clsx';
4
+ import { AnimatePresence, motion } from 'framer-motion';
5
+ import { useId } from 'react';
6
+ import { CurrencySelector } from './CurrencySelector.mjs';
7
+ import { AmountInput } from './AmountInput.mjs';
8
+ import { Chevron } from './Chevron.mjs';
9
+ import { InlinePrompt } from '../prompt/InlinePrompt/InlinePrompt.mjs';
10
+ import { jsx, jsxs } from 'react/jsx-runtime';
11
+
12
+ function ExpressiveMoneyInput({
13
+ label,
14
+ currency,
15
+ currencySelector = {
16
+ options: []
17
+ },
18
+ amount,
19
+ onAmountChange,
20
+ className,
21
+ inlinePrompt,
22
+ showChevron,
23
+ autoFocus,
24
+ loading,
25
+ onFocusChange
26
+ }) {
27
+ const inputId = useId();
28
+ const labelId = useId();
29
+ const customAlertId = useId();
30
+ const currencyId = useId();
31
+ const selector = currencySelector.customRender?.({
32
+ id: currencyId,
33
+ labelId
34
+ }) ?? /*#__PURE__*/jsx(CurrencySelector, {
35
+ id: currencyId,
36
+ labelId: labelId,
37
+ currency: currency,
38
+ ...currencySelector
39
+ });
40
+ return /*#__PURE__*/jsxs("div", {
41
+ className: clsx('wds-expressive-money-input', className),
42
+ children: [/*#__PURE__*/jsx(LabelNamespace, {
43
+ id: labelId,
44
+ htmlFor: inputId,
45
+ className: clsx('m-b-1', 'font-weight-normal'),
46
+ children: label
47
+ }), /*#__PURE__*/jsxs("div", {
48
+ className: clsx('d-flex'),
49
+ role: "group",
50
+ "aria-labelledby": labelId,
51
+ ...(inlinePrompt ? {
52
+ 'aria-describedby': customAlertId
53
+ } : {}),
54
+ children: [/*#__PURE__*/jsx("div", {
55
+ className: "wds-expressive-money-input-currency-selector",
56
+ children: selector
57
+ }), /*#__PURE__*/jsx(AmountInput, {
58
+ id: inputId,
59
+ describedById: currencyId,
60
+ amount: amount,
61
+ currency: currency
62
+ // eslint-disable-next-line jsx-a11y/no-autofocus
63
+ ,
64
+ autoFocus: autoFocus,
65
+ loading: loading,
66
+ onChange: onAmountChange,
67
+ onFocusChange: onFocusChange
68
+ }), /*#__PURE__*/jsx("div", {
69
+ className: clsx('d-flex align-items-center', 'wds-expressive-money-input-chevron'),
70
+ children: /*#__PURE__*/jsx(Chevron, {
71
+ shouldShow: Boolean(showChevron)
72
+ })
73
+ })]
74
+ }), /*#__PURE__*/jsx(AnimatePresence, {
75
+ initial: false,
76
+ children: inlinePrompt && /*#__PURE__*/jsx("div", {
77
+ className: clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1'),
78
+ children: /*#__PURE__*/jsx(motion.div, {
79
+ initial: {
80
+ opacity: 0,
81
+ height: 0
82
+ },
83
+ animate: {
84
+ opacity: 1,
85
+ height: 'auto',
86
+ transition: {
87
+ delay: 0.75,
88
+ duration: 0.3
89
+ }
90
+ },
91
+ exit: {
92
+ opacity: 0,
93
+ height: 0
94
+ },
95
+ children: inlinePrompt.sentiment ? /*#__PURE__*/jsx(InlinePrompt, {
96
+ id: customAlertId,
97
+ media: inlinePrompt.media,
98
+ sentiment: inlinePrompt.sentiment,
99
+ children: inlinePrompt.message
100
+ }) : /*#__PURE__*/jsx(Body, {
101
+ children: inlinePrompt.message
102
+ })
103
+ }, customAlertId)
104
+ })
105
+ })]
106
+ });
107
+ }
108
+
109
+ export { ExpressiveMoneyInput as default };
110
+ //# sourceMappingURL=ExpressiveMoneyInput.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpressiveMoneyInput.mjs","sources":["../../src/expressiveMoneyInput/ExpressiveMoneyInput.tsx"],"sourcesContent":["import Body from '../body';\nimport { Label } from '../label/Label';\nimport { clsx } from 'clsx';\nimport { AnimatePresence, motion } from 'framer-motion';\nimport { useId, type ReactNode } from 'react';\n\nimport { type Props as CurrencySelectorProps, CurrencySelector } from './CurrencySelector';\nimport { CommonProps } from '../common';\nimport { AmountInput } from './AmountInput';\nimport { Chevron } from './Chevron';\nimport { InlinePrompt, type InlinePromptProps } from '../prompt/InlinePrompt';\n\ntype AmountType = number | null;\nexport type CurrencyType = string;\n\ntype DefaultCurrencySelectorInstanceType = Pick<\n CurrencySelectorProps,\n 'addons' | 'options' | 'onChange' | 'onOpen' | 'onSearchChange'\n>;\ntype CustomCurrencySelectorInstanceType = {\n customRender?: (props: { id: string; labelId: string }) => ReactNode;\n};\ntype CurrencySelectorType = DefaultCurrencySelectorInstanceType &\n CustomCurrencySelectorInstanceType;\n\nexport type Props = {\n label?: ReactNode;\n currencySelector?: CurrencySelectorType;\n amount?: AmountType;\n currency: CurrencyType;\n inlinePrompt?: {\n sentiment?: InlinePromptProps['sentiment'];\n message: InlinePromptProps['children'];\n media?: InlinePromptProps['media'];\n };\n showChevron?: boolean;\n autoFocus?: boolean;\n loading?: boolean;\n onAmountChange: (amount: AmountType) => void;\n onFocusChange?: (focused: boolean) => void;\n} & CommonProps;\n\nexport default function ExpressiveMoneyInput({\n label,\n currency,\n currencySelector = { options: [] } as DefaultCurrencySelectorInstanceType,\n amount,\n onAmountChange,\n className,\n inlinePrompt,\n showChevron,\n autoFocus,\n loading,\n onFocusChange,\n}: Props) {\n const inputId = useId();\n const labelId = useId();\n const customAlertId = useId();\n const currencyId = useId();\n\n const selector = currencySelector.customRender?.({ id: currencyId, labelId }) ?? (\n <CurrencySelector id={currencyId} labelId={labelId} currency={currency} {...currencySelector} />\n );\n\n return (\n <div className={clsx('wds-expressive-money-input', className)}>\n <Label id={labelId} htmlFor={inputId} className={clsx('m-b-1', 'font-weight-normal')}>\n {label}\n </Label>\n <div\n className={clsx('d-flex')}\n role=\"group\"\n aria-labelledby={labelId}\n {...(inlinePrompt ? { 'aria-describedby': customAlertId } : {})}\n >\n <div className=\"wds-expressive-money-input-currency-selector\">{selector}</div>\n <AmountInput\n id={inputId}\n describedById={currencyId}\n amount={amount}\n currency={currency}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n loading={loading}\n onChange={onAmountChange}\n onFocusChange={onFocusChange}\n />\n <div className={clsx('d-flex align-items-center', 'wds-expressive-money-input-chevron')}>\n <Chevron shouldShow={Boolean(showChevron)} />\n </div>\n </div>\n <AnimatePresence initial={false}>\n {inlinePrompt && (\n <div className={clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1')}>\n <motion.div\n key={customAlertId}\n initial={{ opacity: 0, height: 0 }}\n animate={{\n opacity: 1,\n height: 'auto',\n transition: { delay: 0.75, duration: 0.3 },\n }}\n exit={{ opacity: 0, height: 0 }}\n >\n {inlinePrompt.sentiment ? (\n <InlinePrompt id={customAlertId} media={inlinePrompt.media} sentiment={inlinePrompt.sentiment}>\n {inlinePrompt.message}\n </InlinePrompt>\n ) : (\n <Body>{inlinePrompt.message}</Body>\n )}\n </motion.div>\n </div>\n )}\n </AnimatePresence>\n </div>\n );\n}\n"],"names":["ExpressiveMoneyInput","label","currency","currencySelector","options","amount","onAmountChange","className","inlinePrompt","showChevron","autoFocus","loading","onFocusChange","inputId","useId","labelId","customAlertId","currencyId","selector","customRender","id","_jsx","CurrencySelector","_jsxs","clsx","children","Label","htmlFor","role","AmountInput","describedById","onChange","Chevron","shouldShow","Boolean","AnimatePresence","initial","motion","div","opacity","height","animate","transition","delay","duration","exit","sentiment","InlinePrompt","media","message","Body"],"mappings":";;;;;;;;;;;AA0Cc,SAAUA,oBAAoBA,CAAC;EAC3CC,KAAK;EACLC,QAAQ;AACRC,EAAAA,gBAAgB,GAAG;AAAEC,IAAAA,OAAO,EAAE;GAA2C;EACzEC,MAAM;EACNC,cAAc;EACdC,SAAS;EACTC,YAAY;EACZC,WAAW;EACXC,SAAS;EACTC,OAAO;AACPC,EAAAA;AAAa,CACP,EAAA;AACN,EAAA,MAAMC,OAAO,GAAGC,KAAK,EAAE;AACvB,EAAA,MAAMC,OAAO,GAAGD,KAAK,EAAE;AACvB,EAAA,MAAME,aAAa,GAAGF,KAAK,EAAE;AAC7B,EAAA,MAAMG,UAAU,GAAGH,KAAK,EAAE;AAE1B,EAAA,MAAMI,QAAQ,GAAGf,gBAAgB,CAACgB,YAAY,GAAG;AAAEC,IAAAA,EAAE,EAAEH,UAAU;AAAEF,IAAAA;AAAO,GAAE,CAAC,iBAC3EM,GAAA,CAACC,gBAAgB,EAAA;AAACF,IAAAA,EAAE,EAAEH,UAAW;AAACF,IAAAA,OAAO,EAAEA,OAAQ;AAACb,IAAAA,QAAQ,EAAEA,QAAS;IAAA,GAAKC;AAAgB,GAAC,CAC9F;AAED,EAAA,oBACEoB,IAAA,CAAA,KA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,eAAAY,GAAA,CAACc,eAAe,EAAA;AAACC,MAAAA,OAAO,EAAE,KAAM;MAAAX,QAAA,EAC7BjB,YAAY,iBACXa,GAAA,CAAA,KAAA,EAAA;QAAKd,SAAS,EAAEiB,IAAI,CAAC,4BAA4B,EAAEhB,YAAY,IAAI,OAAO,CAAE;AAAAiB,QAAAA,QAAA,eAC1EJ,GAAA,CAACgB,MAAM,CAACC,GAAG,EAAA;AAETF,UAAAA,OAAO,EAAE;AAAEG,YAAAA,OAAO,EAAE,CAAC;AAAEC,YAAAA,MAAM,EAAE;WAAI;AACnCC,UAAAA,OAAO,EAAE;AACPF,YAAAA,OAAO,EAAE,CAAC;AACVC,YAAAA,MAAM,EAAE,MAAM;AACdE,YAAAA,UAAU,EAAE;AAAEC,cAAAA,KAAK,EAAE,IAAI;AAAEC,cAAAA,QAAQ,EAAE;AAAG;WACxC;AACFC,UAAAA,IAAI,EAAE;AAAEN,YAAAA,OAAO,EAAE,CAAC;AAAEC,YAAAA,MAAM,EAAE;WAAI;AAAAf,UAAAA,QAAA,EAE/BjB,YAAY,CAACsC,SAAS,gBACrBzB,GAAA,CAAC0B,YAAY,EAAA;AAAC3B,YAAAA,EAAE,EAAEJ,aAAc;YAACgC,KAAK,EAAExC,YAAY,CAACwC,KAAM;YAACF,SAAS,EAAEtC,YAAY,CAACsC,SAAU;YAAArB,QAAA,EAC3FjB,YAAY,CAACyC;AAAO,WACT,CAAC,gBAEf5B,GAAA,CAAC6B,IAAI,EAAA;YAAAzB,QAAA,EAAEjB,YAAY,CAACyC;WAAc;AACnC,SAAA,EAfIjC,aAgBK;OACT;AACN,KACc,CACnB;AAAA,GAAK,CAAC;AAEV;;;;"}
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ const focusTimeout = 5 * 1000;
6
+ const useFocus = () => {
7
+ const [focus, setFocus] = React.useState(false);
8
+ const [visualFocus, setVisualFocus] = React.useState(false);
9
+ const [counter, setCounter] = React.useState(0);
10
+ React.useEffect(() => {
11
+ if (focus) {
12
+ const timeout = setTimeout(() => {
13
+ setVisualFocus(false);
14
+ }, focusTimeout);
15
+ return () => clearTimeout(timeout);
16
+ }
17
+ }, [focus, counter]);
18
+ return {
19
+ focus,
20
+ setFocus: value => {
21
+ setFocus(value);
22
+ if (value) {
23
+ setVisualFocus(true);
24
+ }
25
+ // any call to setFocus should reset the timeout, even if the input was already in focus
26
+ // updating the counter will trigger the useEffect to reset the timeout
27
+ setCounter(prev => prev + 1);
28
+ },
29
+ visualFocus,
30
+ setVisualFocus: value => {
31
+ setVisualFocus(value);
32
+ }
33
+ };
34
+ };
35
+
36
+ exports.useFocus = useFocus;
37
+ //# sourceMappingURL=useFocus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocus.js","sources":["../../src/expressiveMoneyInput/useFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst focusTimeout = 5 * 1000;\n\nexport const useFocus = () => {\n const [focus, setFocus] = useState(false);\n const [visualFocus, setVisualFocus] = useState(false);\n const [counter, setCounter] = useState(0);\n\n useEffect(() => {\n if (focus) {\n const timeout = setTimeout(() => {\n setVisualFocus(false);\n }, focusTimeout);\n return () => clearTimeout(timeout);\n }\n }, [focus, counter]);\n\n return {\n focus,\n setFocus: (value: boolean) => {\n setFocus(value);\n if (value) {\n setVisualFocus(true);\n }\n // any call to setFocus should reset the timeout, even if the input was already in focus\n // updating the counter will trigger the useEffect to reset the timeout\n setCounter((prev) => prev + 1);\n },\n visualFocus,\n setVisualFocus: (value: boolean) => {\n setVisualFocus(value);\n },\n };\n};\n"],"names":["focusTimeout","useFocus","focus","setFocus","useState","visualFocus","setVisualFocus","counter","setCounter","useEffect","timeout","setTimeout","clearTimeout","value","prev"],"mappings":";;;;AAEA,MAAMA,YAAY,GAAG,CAAC,GAAG,IAAI;AAEtB,MAAMC,QAAQ,GAAGA,MAAK;EAC3B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;EACzC,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGF,cAAQ,CAAC,KAAK,CAAC;EACrD,MAAM,CAACG,OAAO,EAAEC,UAAU,CAAC,GAAGJ,cAAQ,CAAC,CAAC,CAAC;AAEzCK,EAAAA,eAAS,CAAC,MAAK;AACb,IAAA,IAAIP,KAAK,EAAE;AACT,MAAA,MAAMQ,OAAO,GAAGC,UAAU,CAAC,MAAK;QAC9BL,cAAc,CAAC,KAAK,CAAC;MACvB,CAAC,EAAEN,YAAY,CAAC;AAChB,MAAA,OAAO,MAAMY,YAAY,CAACF,OAAO,CAAC;AACpC,IAAA;AACF,EAAA,CAAC,EAAE,CAACR,KAAK,EAAEK,OAAO,CAAC,CAAC;EAEpB,OAAO;IACLL,KAAK;IACLC,QAAQ,EAAGU,KAAc,IAAI;MAC3BV,QAAQ,CAACU,KAAK,CAAC;AACf,MAAA,IAAIA,KAAK,EAAE;QACTP,cAAc,CAAC,IAAI,CAAC;AACtB,MAAA;AACA;AACA;AACAE,MAAAA,UAAU,CAAEM,IAAI,IAAKA,IAAI,GAAG,CAAC,CAAC;IAChC,CAAC;IACDT,WAAW;IACXC,cAAc,EAAGO,KAAc,IAAI;MACjCP,cAAc,CAACO,KAAK,CAAC;AACvB,IAAA;GACD;AACH;;;;"}
@@ -0,0 +1,35 @@
1
+ import { useState, useEffect } from 'react';
2
+
3
+ const focusTimeout = 5 * 1000;
4
+ const useFocus = () => {
5
+ const [focus, setFocus] = useState(false);
6
+ const [visualFocus, setVisualFocus] = useState(false);
7
+ const [counter, setCounter] = useState(0);
8
+ useEffect(() => {
9
+ if (focus) {
10
+ const timeout = setTimeout(() => {
11
+ setVisualFocus(false);
12
+ }, focusTimeout);
13
+ return () => clearTimeout(timeout);
14
+ }
15
+ }, [focus, counter]);
16
+ return {
17
+ focus,
18
+ setFocus: value => {
19
+ setFocus(value);
20
+ if (value) {
21
+ setVisualFocus(true);
22
+ }
23
+ // any call to setFocus should reset the timeout, even if the input was already in focus
24
+ // updating the counter will trigger the useEffect to reset the timeout
25
+ setCounter(prev => prev + 1);
26
+ },
27
+ visualFocus,
28
+ setVisualFocus: value => {
29
+ setVisualFocus(value);
30
+ }
31
+ };
32
+ };
33
+
34
+ export { useFocus };
35
+ //# sourceMappingURL=useFocus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFocus.mjs","sources":["../../src/expressiveMoneyInput/useFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst focusTimeout = 5 * 1000;\n\nexport const useFocus = () => {\n const [focus, setFocus] = useState(false);\n const [visualFocus, setVisualFocus] = useState(false);\n const [counter, setCounter] = useState(0);\n\n useEffect(() => {\n if (focus) {\n const timeout = setTimeout(() => {\n setVisualFocus(false);\n }, focusTimeout);\n return () => clearTimeout(timeout);\n }\n }, [focus, counter]);\n\n return {\n focus,\n setFocus: (value: boolean) => {\n setFocus(value);\n if (value) {\n setVisualFocus(true);\n }\n // any call to setFocus should reset the timeout, even if the input was already in focus\n // updating the counter will trigger the useEffect to reset the timeout\n setCounter((prev) => prev + 1);\n },\n visualFocus,\n setVisualFocus: (value: boolean) => {\n setVisualFocus(value);\n },\n };\n};\n"],"names":["focusTimeout","useFocus","focus","setFocus","useState","visualFocus","setVisualFocus","counter","setCounter","useEffect","timeout","setTimeout","clearTimeout","value","prev"],"mappings":";;AAEA,MAAMA,YAAY,GAAG,CAAC,GAAG,IAAI;AAEtB,MAAMC,QAAQ,GAAGA,MAAK;EAC3B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EACzC,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGF,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAM,CAACG,OAAO,EAAEC,UAAU,CAAC,GAAGJ,QAAQ,CAAC,CAAC,CAAC;AAEzCK,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,IAAIP,KAAK,EAAE;AACT,MAAA,MAAMQ,OAAO,GAAGC,UAAU,CAAC,MAAK;QAC9BL,cAAc,CAAC,KAAK,CAAC;MACvB,CAAC,EAAEN,YAAY,CAAC;AAChB,MAAA,OAAO,MAAMY,YAAY,CAACF,OAAO,CAAC;AACpC,IAAA;AACF,EAAA,CAAC,EAAE,CAACR,KAAK,EAAEK,OAAO,CAAC,CAAC;EAEpB,OAAO;IACLL,KAAK;IACLC,QAAQ,EAAGU,KAAc,IAAI;MAC3BV,QAAQ,CAACU,KAAK,CAAC;AACf,MAAA,IAAIA,KAAK,EAAE;QACTP,cAAc,CAAC,IAAI,CAAC;AACtB,MAAA;AACA;AACA;AACAE,MAAAA,UAAU,CAAEM,IAAI,IAAKA,IAAI,GAAG,CAAC,CAAC;IAChC,CAAC;IACDT,WAAW;IACXC,cAAc,EAAGO,KAAc,IAAI;MACjCP,cAAc,CAACO,KAAK,CAAC;AACvB,IAAA;GACD;AACH;;;;"}
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ const useInputStyle = ({
6
+ value,
7
+ focus,
8
+ inputElement,
9
+ loading
10
+ }) => {
11
+ const initialRender = !useTimeout(300);
12
+ const inputWidth = useFirstDefinedValue(inputElement?.clientWidth, [inputElement, value]);
13
+ const getStyle = () => {
14
+ const fontSize = getFontSize(value, focus, inputWidth);
15
+ return {
16
+ fontSize,
17
+ height: fontSize,
18
+ // aligns the top of the digit with the currency button
19
+ marginTop: fontSize * -0.19,
20
+ // if the input loads with a pre-filled value, we don't want to animate the font-size immediately
21
+ transition: initialRender ? 'none' : undefined,
22
+ color: loading ? 'var(--color-interactive-secondary)' : undefined
23
+ };
24
+ };
25
+ const [style, setStyle] = React.useState(getStyle());
26
+ React.useLayoutEffect(() => {
27
+ setStyle(getStyle());
28
+ }, [value, focus, loading, inputWidth]);
29
+ return style;
30
+ };
31
+ function getFontSize(inputValue, isFocused, inputWidth) {
32
+ const defaultFontSize = 52;
33
+ const focusFontSize = 90;
34
+ const minimumFontSize = 34;
35
+ let fontSize = isFocused ? focusFontSize : defaultFontSize;
36
+ if (typeof inputWidth === 'undefined') {
37
+ return fontSize;
38
+ }
39
+ const textLength = inputValue.length;
40
+ const maxCharactersWithoutShrinking = Math.floor(inputWidth / 40);
41
+ if (textLength > maxCharactersWithoutShrinking) {
42
+ const adjustedSize = Math.round(inputWidth / textLength * 1.9);
43
+ fontSize = Math.min(fontSize, adjustedSize);
44
+ }
45
+ return Math.max(fontSize, minimumFontSize);
46
+ }
47
+ const useFirstDefinedValue = (newValue, dependencies) => {
48
+ const [value, setValue] = React.useState(newValue);
49
+ React.useLayoutEffect(() => {
50
+ if (typeof newValue !== 'undefined' && typeof value === 'undefined') {
51
+ setValue(newValue);
52
+ }
53
+ // eslint-disable-next-line react-hooks/exhaustive-deps
54
+ }, [...dependencies, value]);
55
+ return value;
56
+ };
57
+ const useTimeout = delay => {
58
+ const [ready, setReady] = React.useState(false);
59
+ React.useEffect(() => {
60
+ const timeout = setTimeout(() => {
61
+ setReady(true);
62
+ }, delay);
63
+ return () => {
64
+ clearTimeout(timeout);
65
+ };
66
+ }, [delay]);
67
+ return ready;
68
+ };
69
+
70
+ exports.useInputStyle = useInputStyle;
71
+ //# sourceMappingURL=useInputStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInputStyle.js","sources":["../../src/expressiveMoneyInput/useInputStyle.ts"],"sourcesContent":["import { type CSSProperties, useEffect, useLayoutEffect, useState } from 'react';\nimport { Props as ExpressiveMoneyInputProps } from './ExpressiveMoneyInput';\n\ntype InputStyleObject = {\n value: string;\n focus: boolean;\n inputElement: HTMLInputElement | null;\n} & Pick<ExpressiveMoneyInputProps, 'loading'>;\n\nexport const useInputStyle = ({ value, focus, inputElement, loading }: InputStyleObject) => {\n const initialRender = !useTimeout(300);\n const inputWidth = useFirstDefinedValue(inputElement?.clientWidth, [inputElement, value]);\n\n const getStyle = (): CSSProperties => {\n const fontSize = getFontSize(value, focus, inputWidth);\n\n return {\n fontSize,\n height: fontSize,\n // aligns the top of the digit with the currency button\n marginTop: fontSize * -0.19,\n // if the input loads with a pre-filled value, we don't want to animate the font-size immediately\n transition: initialRender ? 'none' : undefined,\n color: loading ? 'var(--color-interactive-secondary)' : undefined,\n };\n };\n\n const [style, setStyle] = useState(getStyle());\n\n useLayoutEffect(() => {\n setStyle(getStyle());\n }, [value, focus, loading, inputWidth]);\n\n return style;\n};\n\nfunction getFontSize(inputValue: string, isFocused: boolean, inputWidth: number | undefined) {\n const defaultFontSize = 52;\n const focusFontSize = 90;\n const minimumFontSize = 34;\n\n let fontSize = isFocused ? focusFontSize : defaultFontSize;\n\n if (typeof inputWidth === 'undefined') {\n return fontSize;\n }\n const textLength = inputValue.length;\n const maxCharactersWithoutShrinking = Math.floor(inputWidth / 40);\n\n if (textLength > maxCharactersWithoutShrinking) {\n const adjustedSize = Math.round((inputWidth / textLength) * 1.9);\n fontSize = Math.min(fontSize, adjustedSize);\n }\n\n return Math.max(fontSize, minimumFontSize);\n}\n\nconst useFirstDefinedValue = (newValue: number | undefined, dependencies: unknown[]) => {\n const [value, setValue] = useState<number | undefined>(newValue);\n\n useLayoutEffect(() => {\n if (typeof newValue !== 'undefined' && typeof value === 'undefined') {\n setValue(newValue);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [...dependencies, value]);\n\n return value;\n};\n\nconst useTimeout = (delay: number) => {\n const [ready, setReady] = useState(false);\n\n useEffect(() => {\n const timeout = setTimeout(() => {\n setReady(true);\n }, delay);\n\n return () => {\n clearTimeout(timeout);\n };\n }, [delay]);\n\n return ready;\n};\n"],"names":["useInputStyle","value","focus","inputElement","loading","initialRender","useTimeout","inputWidth","useFirstDefinedValue","clientWidth","getStyle","fontSize","getFontSize","height","marginTop","transition","undefined","color","style","setStyle","useState","useLayoutEffect","inputValue","isFocused","defaultFontSize","focusFontSize","minimumFontSize","textLength","length","maxCharactersWithoutShrinking","Math","floor","adjustedSize","round","min","max","newValue","dependencies","set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AC;IACvB,CAAC;AACH,EAAA,CAAC,EAAE,CAACJ,KAAK,CAAC,CAAC;AAEX,EAAA,OAAOC,KAAK;AACd,CAAC;;;;"}
@@ -0,0 +1,69 @@
1
+ import { useState, useLayoutEffect, useEffect } from 'react';
2
+
3
+ const useInputStyle = ({
4
+ value,
5
+ focus,
6
+ inputElement,
7
+ loading
8
+ }) => {
9
+ const initialRender = !useTimeout(300);
10
+ const inputWidth = useFirstDefinedValue(inputElement?.clientWidth, [inputElement, value]);
11
+ const getStyle = () => {
12
+ const fontSize = getFontSize(value, focus, inputWidth);
13
+ return {
14
+ fontSize,
15
+ height: fontSize,
16
+ // aligns the top of the digit with the currency button
17
+ marginTop: fontSize * -0.19,
18
+ // if the input loads with a pre-filled value, we don't want to animate the font-size immediately
19
+ transition: initialRender ? 'none' : undefined,
20
+ color: loading ? 'var(--color-interactive-secondary)' : undefined
21
+ };
22
+ };
23
+ const [style, setStyle] = useState(getStyle());
24
+ useLayoutEffect(() => {
25
+ setStyle(getStyle());
26
+ }, [value, focus, loading, inputWidth]);
27
+ return style;
28
+ };
29
+ function getFontSize(inputValue, isFocused, inputWidth) {
30
+ const defaultFontSize = 52;
31
+ const focusFontSize = 90;
32
+ const minimumFontSize = 34;
33
+ let fontSize = isFocused ? focusFontSize : defaultFontSize;
34
+ if (typeof inputWidth === 'undefined') {
35
+ return fontSize;
36
+ }
37
+ const textLength = inputValue.length;
38
+ const maxCharactersWithoutShrinking = Math.floor(inputWidth / 40);
39
+ if (textLength > maxCharactersWithoutShrinking) {
40
+ const adjustedSize = Math.round(inputWidth / textLength * 1.9);
41
+ fontSize = Math.min(fontSize, adjustedSize);
42
+ }
43
+ return Math.max(fontSize, minimumFontSize);
44
+ }
45
+ const useFirstDefinedValue = (newValue, dependencies) => {
46
+ const [value, setValue] = useState(newValue);
47
+ useLayoutEffect(() => {
48
+ if (typeof newValue !== 'undefined' && typeof value === 'undefined') {
49
+ setValue(newValue);
50
+ }
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, [...dependencies, value]);
53
+ return value;
54
+ };
55
+ const useTimeout = delay => {
56
+ const [ready, setReady] = useState(false);
57
+ useEffect(() => {
58
+ const timeout = setTimeout(() => {
59
+ setReady(true);
60
+ }, delay);
61
+ return () => {
62
+ clearTimeout(timeout);
63
+ };
64
+ }, [delay]);
65
+ return ready;
66
+ };
67
+
68
+ export { useInputStyle };
69
+ //# sourceMappingURL=useInputStyle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInputStyle.mjs","sources":["../../src/expressiveMoneyInput/useInputStyle.ts"],"sourcesContent":["import { type CSSProperties, useEffect, useLayoutEffect, useState } from 'react';\nimport { Props as ExpressiveMoneyInputProps } from './ExpressiveMoneyInput';\n\ntype InputStyleObject = {\n value: string;\n focus: boolean;\n inputElement: HTMLInputElement | null;\n} & Pick<ExpressiveMoneyInputProps, 'loading'>;\n\nexport const useInputStyle = ({ value, focus, inputElement, loading }: InputStyleObject) => {\n const initialRender = !useTimeout(300);\n const inputWidth = useFirstDefinedValue(inputElement?.clientWidth, [inputElement, value]);\n\n const getStyle = (): CSSProperties => {\n const fontSize = getFontSize(value, focus, inputWidth);\n\n return {\n fontSize,\n height: fontSize,\n // aligns the top of the digit with the currency button\n marginTop: fontSize * -0.19,\n // if the input loads with a pre-filled value, we don't want to animate the font-size immediately\n transition: initialRender ? 'none' : undefined,\n color: loading ? 'var(--color-interactive-secondary)' : undefined,\n };\n };\n\n const [style, setStyle] = useState(getStyle());\n\n useLayoutEffect(() => {\n setStyle(getStyle());\n }, [value, focus, loading, inputWidth]);\n\n return style;\n};\n\nfunction getFontSize(inputValue: string, isFocused: boolean, inputWidth: number | undefined) {\n const defaultFontSize = 52;\n const focusFontSize = 90;\n const minimumFontSize = 34;\n\n let fontSize = isFocused ? focusFontSize : defaultFontSize;\n\n if (typeof inputWidth === 'undefined') {\n return fontSize;\n }\n const textLength = inputValue.length;\n const maxCharactersWithoutShrinking = Math.floor(inputWidth / 40);\n\n if (textLength > maxCharactersWithoutShrinking) {\n const adjustedSize = Math.round((inputWidth / textLength) * 1.9);\n fontSize = Math.min(fontSize, adjustedSize);\n }\n\n return Math.max(fontSize, minimumFontSize);\n}\n\nconst useFirstDefinedValue = (newValue: number | undefined, dependencies: unknown[]) => {\n const [value, setValue] = useState<number | undefined>(newValue);\n\n useLayoutEffect(() => {\n if (typeof newValue !== 'undefined' && typeof value === 'undefined') {\n setValue(newValue);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [...dependencies, value]);\n\n return value;\n};\n\nconst useTimeout = (delay: number) => {\n const [ready, setReady] = useState(false);\n\n useEffect(() => {\n const timeout = setTimeout(() => {\n setReady(true);\n }, delay);\n\n return () => {\n clearTimeout(timeout);\n };\n }, [delay]);\n\n return ready;\n};\n"],"names":["useInputStyle","value","focus","inputElement","loading","initialRender","useTimeout","inputWidth","useFirstDefinedValue","clientWidth","getStyle","fontSize","getFontSize","height","marginTop","transition","undefined","color","style","setStyle","useState","useLayoutEffect","inputValue","isFocused","defaultFontSize","focusFontSize","minimumFontSize","textLength","length","maxCharactersWithoutShrinking","Math","floor","adjustedSize","round","min","max","newValue","dependencies","setValue","delay","ready","setReady","useEffect","timeout","setTimeout","clearTimeout"],"mappings":";;AASO,MAAMA,aAAa,GAAGA,CAAC;EAAEC,KAAK;EAAEC,KAAK;EAAEC,YAAY;AAAEC,EAAAA;AAAO,CAAoB,KAAI;AACzF,EAAA,MAAMC,aAAa,GAAG,CAACC,UAAU,CAAC,GAAG,CAAC;AACtC,EAAA,MAAMC,UAAU,GAAGC,oBAAoB,CAACL,YAAY,EAAEM,WAAW,EAAE,CAACN,YAAY,EAAEF,KAAK,CAAC,CAAC;EAEzF,MAAMS,QAAQ,GAAGA,MAAoB;IACnC,MAAMC,QAAQ,GAAGC,WAAW,CAACX,KAAK,EAAEC,KAAK,EAAEK,UAAU,CAAC;IAEtD,OAAO;MACLI,QAAQ;AACRE,MAAAA,MAAM,EAAEF,QAAQ;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MlB,oBAAoB,GAAGA,CAAC4B,QAA4B,EAAEC,YAAuB,KAAI;EACrF,MAAM,CAACpC,KAAK,EAAEqC,QAAQ,CAAC,GAAGlB,QAAQ,CAAqBgB,QAAQ,CAAC;AAEhEf,EAAAA,eAAe,CAAC,MAAK;IACnB,IAAI,OAAOe,QAAQ,KAAK,WAAW,IAAI,OAAOnC,KAAK,KAAK,WAAW,EAAE;MACnEqC,QAAQ,CAACF,QAAQ,CAAC;AACpB,IAAA;AACA;AACF,EAAA,CAAC,EAAE,CAAC,GAAGC,YAAY,EAAEpC,KAAK,CAAC,CAAC;AAE5B,EAAA,OAAOA,KAAK;AACd,CAAC;AAED,MAAMK,UAAU,GAAIiC,KAAa,IAAI;EACnC,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGrB,QAAQ,CAAC,KAAK,CAAC;AAEzCsB,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,MAAMC,OAAO,GAAGC,UAAU,CAAC,MAAK;MAC9BH,QAAQ,CAAC,IAAI,CAAC;IAChB,CAAC,EAAEF,KAAK,CAAC;AAET,IAAA,OAAO,MAAK;MACVM,YAAY,CAACF,OAAO,CAAC;IACvB,CAAC;AACH,EAAA,CAAC,EAAE,CAACJ,KAAK,CAAC,CAAC;AAEX,EAAA,OAAOC,KAAK;AACd,CAAC;;;;"}
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ var formatting = require('@transferwise/formatting');
4
+
5
+ const getDecimalSeparator = (currency, locale) => {
6
+ return formatting.formatAmount(1.1, currency, locale).replace(/\p{Number}/gu, '');
7
+ };
8
+ const getGroupSeparator = (currency, locale) => {
9
+ return formatting.formatAmount(10000000, currency, locale).replace(/\p{Number}/gu, '')[0];
10
+ };
11
+ const getDecimalCount = (currency, locale) => {
12
+ const decimalSeparator = getDecimalSeparator(currency, locale);
13
+ if (!decimalSeparator) {
14
+ return 0;
15
+ }
16
+ const parts = formatting.formatAmount(1.1, currency, locale).split(decimalSeparator);
17
+ return parts.length === 2 ? parts[1].length : 0;
18
+ };
19
+ const getEnteredDecimalsCount = (value, decimalSeparator) => {
20
+ return value.split(decimalSeparator)[1]?.length ?? 0;
21
+ };
22
+ const getUnformattedNumber = ({
23
+ value: formattedValue,
24
+ currency,
25
+ locale
26
+ }) => {
27
+ const groupSeparator = getGroupSeparator(currency, locale);
28
+ const decimalSeparator = getDecimalSeparator(currency, locale);
29
+ if (!formattedValue) {
30
+ return null;
31
+ }
32
+ // parseFloat can't handle thousands separators
33
+ const withoutGroupSeparator = groupSeparator ? formattedValue.replace(/ /gu, '').replace(new RegExp(`\\${groupSeparator}`, 'g'), '') : formattedValue;
34
+ // parseFloat can only handle . as decimal separator
35
+ const withNormalisedDecimalSeparator = decimalSeparator ? withoutGroupSeparator.replace(decimalSeparator, '.') : withoutGroupSeparator;
36
+ const parsedValue = Number.parseFloat(withNormalisedDecimalSeparator);
37
+ return parsedValue;
38
+ };
39
+ const getFormattedString = ({
40
+ value: unformattedValue,
41
+ currency,
42
+ locale,
43
+ alwaysShowDecimals = false
44
+ }) => {
45
+ const decimalSeparator = getDecimalSeparator(currency, locale);
46
+ // formatAmount rounds extra decimals, so 1.999 will become 2. Instead we will manually strip extra decimals so that it becomes 1.99 after formatting
47
+ const decimalCount = getDecimalCount(currency, locale);
48
+ const unformattedString = unformattedValue.toString();
49
+ const [integerPart, decimalPart] = decimalSeparator ? unformattedString.split(decimalSeparator) : [unformattedString, undefined];
50
+ const formattedDecimalPart = decimalPart ? decimalPart.slice(0, decimalCount) : '';
51
+ const sanitisedUnformattedValue = Number.parseFloat(`${integerPart}.${formattedDecimalPart}`);
52
+ return formatting.formatAmount(sanitisedUnformattedValue, currency, locale, {
53
+ alwaysShowDecimals
54
+ });
55
+ };
56
+ const isInputPossiblyOverflowing = ({
57
+ ref,
58
+ value
59
+ }) => {
60
+ const textLength = value.length;
61
+ const inputWidth = ref.current?.clientWidth;
62
+ if (!inputWidth || !textLength) {
63
+ return;
64
+ }
65
+ const maxCharactersWithoutOverflow = Math.floor(inputWidth / 19);
66
+ return textLength > maxCharactersWithoutOverflow;
67
+ };
68
+ const allowedInputKeys = new Set(['Backspace', 'Delete', ',', '.', 'ArrowLeft', 'ArrowRight', 'Enter', 'Tab']);
69
+ const isAllowedInputKey = e => {
70
+ const {
71
+ metaKey,
72
+ key,
73
+ ctrlKey
74
+ } = e;
75
+ const isNumberKey = !Number.isNaN(Number.parseInt(key, 10));
76
+ return isNumberKey || metaKey || ctrlKey || allowedInputKeys.has(key);
77
+ };
78
+
79
+ exports.getDecimalCount = getDecimalCount;
80
+ exports.getDecimalSeparator = getDecimalSeparator;
81
+ exports.getEnteredDecimalsCount = getEnteredDecimalsCount;
82
+ exports.getFormattedString = getFormattedString;
83
+ exports.getGroupSeparator = getGroupSeparator;
84
+ exports.getUnformattedNumber = getUnformattedNumber;
85
+ exports.isAllowedInputKey = isAllowedInputKey;
86
+ exports.isInputPossiblyOverflowing = isInputPossiblyOverflowing;
87
+ //# sourceMappingURL=utils.js.map