@transferwise/components 0.0.0-experimental-eaf43c2 → 0.0.0-experimental-29f2750
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.
- package/build/moneyInputField/AmountInput.js +4 -7
- package/build/moneyInputField/AmountInput.js.map +1 -1
- package/build/moneyInputField/AmountInput.mjs +5 -8
- package/build/moneyInputField/AmountInput.mjs.map +1 -1
- package/build/moneyInputField/CurrencySelector.js +2 -2
- package/build/moneyInputField/CurrencySelector.js.map +1 -1
- package/build/moneyInputField/CurrencySelector.mjs +2 -2
- package/build/moneyInputField/CurrencySelector.mjs.map +1 -1
- package/build/moneyInputField/MoneyInputField.js +2 -2
- package/build/moneyInputField/MoneyInputField.js.map +1 -1
- package/build/moneyInputField/MoneyInputField.mjs +2 -2
- package/build/moneyInputField/MoneyInputField.mjs.map +1 -1
- package/build/types/moneyInputField/AmountInput.d.ts.map +1 -1
- package/build/types/moneyInputField/CurrencySelector.d.ts +3 -3
- package/build/types/moneyInputField/CurrencySelector.d.ts.map +1 -1
- package/build/types/moneyInputField/MoneyInputField.d.ts.map +1 -1
- package/package.json +10 -4
- package/src/moneyInputField/AmountInput.tsx +4 -6
- package/src/moneyInputField/CurrencySelector.tsx +3 -4
- package/src/moneyInputField/MoneyInputField.tsx +2 -1
|
@@ -222,13 +222,10 @@ const AmountInput = ({
|
|
|
222
222
|
inputElement: ref.current,
|
|
223
223
|
loading
|
|
224
224
|
});
|
|
225
|
-
|
|
226
|
-
return '';
|
|
227
|
-
};
|
|
228
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
225
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
229
226
|
className: "wds-amount-input-container",
|
|
230
|
-
children:
|
|
231
|
-
className:
|
|
227
|
+
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
228
|
+
className: clsx.clsx('wds-amount-input-input-container', 'np-text-display-large'),
|
|
232
229
|
style: style,
|
|
233
230
|
children: [/*#__PURE__*/jsxRuntime.jsx("input", {
|
|
234
231
|
ref: ref,
|
|
@@ -264,7 +261,7 @@ const AmountInput = ({
|
|
|
264
261
|
children: addonContent
|
|
265
262
|
})
|
|
266
263
|
})]
|
|
267
|
-
})
|
|
264
|
+
})
|
|
268
265
|
});
|
|
269
266
|
};
|
|
270
267
|
const getPlaceholder = (currency, locale) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AmountInput.js","sources":["../../src/moneyInputField/AmountInput.tsx"],"sourcesContent":["import { formatAmount } from '@transferwise/formatting';\nimport { clsx } from 'clsx';\nimport { AnimatePresence } from 'framer-motion';\nimport { type ChangeEvent, type KeyboardEvent, useEffect, useMemo, useRef, useState } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { AnimatedNumber } from './AnimatedNumber';\nimport { useFocus } from './useFocus';\nimport { useInputStyle } from './useInputStyle';\nimport {\n getDecimalCount,\n getDecimalSeparator,\n getEnteredDecimalsCount,\n getFormattedString,\n getGroupSeparator,\n getUnformattedNumber,\n isAllowedInputKey,\n isInputPossiblyOverflowing,\n} from './utils';\n\ntype Props = {\n id: string;\n describedById?: string;\n amount?: number | null;\n currency: string;\n autoFocus?: boolean;\n onChange: (amount: number | null) => void;\n onFocusChange?: (focused: boolean) => void;\n} & Pick<MoneyInputFieldProps, 'loading'>;\n\nexport const AmountInput = ({\n id,\n describedById,\n amount,\n currency,\n autoFocus,\n onChange,\n onFocusChange,\n loading,\n}: Props) => {\n const intl = useIntl();\n const { focus, setFocus, visualFocus, setVisualFocus } = useFocus();\n\n const [value, setValue] = useState<string>(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n const numericValue = useMemo(() => {\n return getUnformattedNumber({\n value,\n currency,\n locale: intl.locale,\n });\n }, [value, currency, intl.locale]);\n\n const valueWithFullDecimals = useMemo(() => {\n return getFormattedString({\n value: numericValue ?? 0,\n currency,\n locale: intl.locale,\n alwaysShowDecimals: true,\n });\n }, [numericValue, currency, intl.locale]);\n\n const ref = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (autoFocus) {\n ref.current?.focus();\n }\n }, []);\n\n const placeholder = getPlaceholder(currency, intl.locale);\n const groupSeparator = getGroupSeparator(currency, intl.locale);\n const decimalSeparator = getDecimalSeparator(currency, intl.locale);\n const maxDecimalCount = getDecimalCount(currency, intl.locale);\n\n const decimalPart = getDecimalPart(value, decimalSeparator);\n const decimalMode = decimalSeparator && value.includes(decimalSeparator);\n\n useEffect(() => {\n if (!focus) {\n setValue(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [amount]);\n\n useEffect(() => {\n onFocusChange?.(visualFocus);\n }, [visualFocus]);\n\n const shouldReformatAfterUserInput = (newValue: string) => {\n // don't reformat if formatting would wipe out user's input\n if (reformatValue(newValue) === '') {\n return false;\n }\n\n const endsWithDecimalSeparator = decimalSeparator && newValue.endsWith(decimalSeparator);\n const endsWithGroupSeparator = groupSeparator && newValue.endsWith(groupSeparator);\n\n // if the user has entered a seperator to the end, formatting would delete it\n if (endsWithDecimalSeparator || endsWithGroupSeparator) {\n return false;\n }\n\n const containsDecimalSeparator = decimalSeparator && newValue.includes(decimalSeparator);\n\n if (containsDecimalSeparator) {\n const enteredDecimalsCount = getEnteredDecimalsCount(newValue, decimalSeparator);\n // don't reformat until user has entered all the allowed decimals\n // for example, we don't want 1.1 to be reformatted to 1.10 immediately\n if (enteredDecimalsCount < maxDecimalCount) {\n return false;\n }\n }\n\n return true;\n };\n\n const reformatValue = (newValue: string) => {\n const unformattedValue = getUnformattedNumber({\n value: newValue,\n currency,\n locale: intl.locale,\n });\n const formattedValue = unformattedValue\n ? getFormattedString({\n value: unformattedValue,\n currency,\n locale: intl.locale,\n })\n : '';\n return formattedValue;\n };\n\n const handleChange = (newValue: string) => {\n const oldCursorPosition = ref.current?.selectionStart ?? 0;\n\n const newFormattedString = shouldReformatAfterUserInput(newValue)\n ? reformatValue(newValue)\n : newValue;\n setValue(newFormattedString);\n\n const newNumber = getUnformattedNumber({\n value: newFormattedString,\n currency,\n locale: intl.locale,\n });\n\n if (newNumber !== numericValue) {\n if (numericValue || newNumber) {\n onChange(newNumber);\n }\n }\n\n const newCursorPosition = oldCursorPosition + (newFormattedString.length - newValue.length);\n requestAnimationFrame(() => {\n ref?.current?.setSelectionRange(newCursorPosition, newCursorPosition);\n });\n };\n\n const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {\n e.preventDefault();\n\n const clipboardData = e.clipboardData?.getData('text/plain');\n if (!clipboardData) {\n return;\n }\n\n // need to sanitise the pasted value otherwise other validation logic will ignore the input entirely\n const sanitisedValue = reformatValue(clipboardData);\n\n handleChange(sanitisedValue);\n };\n\n const handleBlur = () => {\n setFocus(false);\n setValue(reformatValue(value));\n };\n\n const handleBackspace = (e: KeyboardEvent<HTMLInputElement>) => {\n const input = e.target as HTMLInputElement;\n // using the updated selection range after the backspace key has been processed, instead of the current selection range in state\n const { value: currentValue, selectionStart, selectionEnd } = input;\n\n if (selectionStart === selectionEnd && selectionStart && selectionStart > 0) {\n const charBeforeCursor = currentValue[selectionStart - 1];\n\n // if the user deletes a thousands separator, remove the digit before it as well\n if (charBeforeCursor === groupSeparator) {\n e.preventDefault();\n const beforeCursor = currentValue.slice(0, selectionStart - 2);\n const afterCursor = currentValue.slice(selectionStart);\n const newValue = `${beforeCursor}${afterCursor}`;\n input.setSelectionRange(beforeCursor.length, beforeCursor.length);\n handleChange(newValue);\n }\n }\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n setFocus(true);\n if (!isAllowedInputKey(e)) {\n e.preventDefault();\n }\n\n if (e.key === 'Backspace') {\n handleBackspace(e);\n }\n };\n\n const isAllowedInput = (e: ChangeEvent<HTMLInputElement>) => {\n const hasMultipleDecimalSeparators =\n decimalSeparator && e.target.value.split(decimalSeparator).length > 2;\n if (hasMultipleDecimalSeparators) {\n return false;\n }\n\n const newNumericValue = getUnformattedNumber({\n value: e.target.value,\n currency,\n locale: intl.locale,\n });\n const maxLength = Number.MAX_SAFE_INTEGER.toString().length;\n if (String(newNumericValue).length > maxLength) {\n return false;\n }\n\n return true;\n };\n\n const addonContent = useMemo((): string | null | undefined => {\n // because we're using a separate \"addon\" element for the placeholder decimals, there is a possibility that the input itself will become scrollable\n // and the decimals will appear on top of the input. Safest thing to do is to just hide the addon if there is not enough room\n if (isInputPossiblyOverflowing({ ref, value })) {\n return null;\n }\n if (!decimalSeparator || !value) {\n return null;\n }\n\n // if the user has typed a decimal separator, show the full decimal part as a placeholder\n // this returns a string even if there is no content, typing should replace the placeholder immediately without animation\n // otherwise there is an ugly animation when going from 1.23 to 1.2 due to AnimatePresence\n if (focus && decimalMode) {\n // reuse getDecimalPart\n const fullDecimalPart = getDecimalPart(valueWithFullDecimals, decimalSeparator);\n // show only the characters that are not already displayed by the input\n return fullDecimalPart?.slice(decimalPart?.length);\n }\n\n // in unfocused state, always show the full decimal part unless the user has already entered decimals\n if (!focus && !decimalMode) {\n const [_, decimalPlaceholder] = placeholder.split(decimalSeparator);\n return decimalSeparator + decimalPlaceholder;\n }\n\n return null;\n }, [\n decimalMode,\n decimalPart?.length,\n decimalSeparator,\n focus,\n placeholder,\n value,\n valueWithFullDecimals,\n ]);\n\n const style = useInputStyle({\n // whenever decimals are shown, we need to account for the full decimal part for the font size calculation\n value: addonContent ? valueWithFullDecimals : value,\n focus: visualFocus,\n inputElement: ref.current,\n loading,\n });\n\n const getInputMask = () => {\n return '';\n };\n\n return (\n <div className=\"wds-amount-input-container\">\n <div className=\"wds-amount-input-input-container display-2\" style={style}>\n <input\n ref={ref}\n className=\"wds-amount-input-input\"\n id={id}\n autoComplete=\"off\"\n inputMode=\"decimal\"\n value={value}\n type=\"text\"\n placeholder={placeholder}\n aria-describedby={describedById}\n /* without this, the input tries to keep an aspect ratio and doesn't respect CSS width rules */\n size={1}\n onChange={(e) => {\n if (isAllowedInput(e)) {\n handleChange(e.target.value);\n }\n }}\n onBlurCapture={() => handleBlur()}\n onPaste={(e) => handlePaste(e)}\n onFocus={() => {\n setFocus(true);\n }}\n onBlur={() => {\n setTimeout(() => setVisualFocus(false), 30);\n }}\n onKeyDown={(e) => handleKeyDown(e)}\n />\n <AnimatePresence initial={false}>\n {addonContent !== null && (\n <AnimatedNumber\n className={clsx(\n 'wds-amount-input-placeholder',\n visualFocus && 'wds-amount-input-placeholder-focus',\n )}\n onClick={() => ref.current?.focus()}\n >\n {addonContent}\n </AnimatedNumber>\n )}\n </AnimatePresence>\n </div>\n {getInputMask()}\n </div>\n );\n};\n\nconst getPlaceholder = (currency: string, locale: string) => {\n return formatAmount(0, currency, locale, { alwaysShowDecimals: true });\n};\n\nconst getDecimalPart = (value: string, decimalSeparator: string | null) => {\n if (!value || !decimalSeparator) {\n return undefined;\n }\n\n const [_, decimalPart] = value.split(decimalSeparator);\n return decimalPart ?? undefined;\n};\n"],"names":["AmountInput","id","describedById","amount","currency","autoFocus","onChange","onFocusChange","loading","intl","useIntl","focus","setFocus","visualFocus","setVisualFocus","useFocus","value","setValue","useState","getFormattedString","locale","numericValue","useMemo","getUnformattedNumber","valueWithFullDecimals","alwaysShowDecimals","ref","useRef","useEffect","current","placeholder","getPlaceholder","groupSeparator","getGroupSeparator","decimalSeparator","getDecimalSeparator","maxDecimalCount","getDecimalCount","decimalPart","getDecimalPart","decimalMode","includes","shouldReformatAfterUserInput","newValue","reformatValue","endsWithDecimalSeparator","endsWith","endsWithGroupSeparator","containsDecimalSeparator","enteredDecimalsCount","getEnteredDecimalsCount","unformattedValue","formattedValue","handleChange","oldCursorPosition","selectionStart","newFormattedString","newNumber","newCursorPosition","length","requestAnimationFrame","setSelectionRange","handlePaste","e","preventDefault","clipboardData","getData","sanitisedValue","handleBlur","handleBackspace","input","target","currentValue","selectionEnd","charBeforeCursor","beforeCursor","slice","afterCursor","handleKeyDown","isAllowedInputKey","key","isAllowedInput","hasMultipleDecimalSeparators","split","newNumericValue","maxLength","Number","MAX_SAFE_INTEGER","toString","String","addonContent","isInputPossiblyOverflowing","fullDecimalPart","_","decimalPlaceholder","style","useInputStyle","inputElement","getInputMask","_jsxs","className","children","_jsx","autoComplete","inputMode","type","size","onBlurCapture","onPaste","onFocus","onBlur","setTimeout","onKeyDown","AnimatePresence","initial","AnimatedNumber","clsx","onClick","formatAmount","undefined"],"mappings":";;;;;;;;;;;;;AA+BO,MAAMA,WAAW,GAAGA,CAAC;EAC1BC,EAAE;EACFC,aAAa;EACbC,MAAM;EACNC,QAAQ;EACRC,SAAS;EACTC,QAAQ;EACRC,aAAa;AACbC,EAAAA;AAAO,CACD,KAAI;AACV,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE;EACtB,MAAM;IAAEC,KAAK;IAAEC,QAAQ;IAAEC,WAAW;AAAEC,IAAAA;GAAgB,GAAGC,iBAAQ,EAAE;EAEnE,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAQ,CAChCf,MAAM,GACFgB,wBAAkB,CAAC;AACjBH,IAAAA,KAAK,EAAEb,MAAM;IACbC,QAAQ;IACRgB,MAAM,EAAEX,IAAI,CAACW;GACd,CAAC,GACF,EAAE,CACP;AACD,EAAA,MAAMC,YAAY,GAAGC,aAAO,CAAC,MAAK;AAChC,IAAA,OAAOC,0BAAoB,CAAC;MAC1BP,KAAK;MACLZ,QAAQ;MACRgB,MAAM,EAAEX,IAAI,CAACW;AACd,KAAA,CAAC;EACJ,CAAC,EAAE,CAACJ,KAAK,EAAEZ,QAAQ,EAAEK,IAAI,CAACW,MAAM,CAAC,CAAC;AAElC,EAAA,MAAMI,qBAAqB,GAAGF,aAAO,CAAC,MAAK;AACzC,IAAA,OAAOH,wBAAkB,CAAC;MACxBH,KAAK,EAAEK,YAAY,IAAI,CAAC;MACxBjB,QAAQ;MACRgB,MAAM,EAAEX,IAAI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
{"version":3,"file":"AmountInput.js","sources":["../../src/moneyInputField/AmountInput.tsx"],"sourcesContent":["import { formatAmount } from '@transferwise/formatting';\nimport { clsx } from 'clsx';\nimport { AnimatePresence } from 'framer-motion';\nimport { type ChangeEvent, type KeyboardEvent, useEffect, useMemo, useRef, useState } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { AnimatedNumber } from './AnimatedNumber';\nimport { useFocus } from './useFocus';\nimport { useInputStyle } from './useInputStyle';\nimport {\n getDecimalCount,\n getDecimalSeparator,\n getEnteredDecimalsCount,\n getFormattedString,\n getGroupSeparator,\n getUnformattedNumber,\n isAllowedInputKey,\n isInputPossiblyOverflowing,\n} from './utils';\n\ntype Props = {\n id: string;\n describedById?: string;\n amount?: number | null;\n currency: string;\n autoFocus?: boolean;\n onChange: (amount: number | null) => void;\n onFocusChange?: (focused: boolean) => void;\n} & Pick<MoneyInputFieldProps, 'loading'>;\n\nexport const AmountInput = ({\n id,\n describedById,\n amount,\n currency,\n autoFocus,\n onChange,\n onFocusChange,\n loading,\n}: Props) => {\n const intl = useIntl();\n const { focus, setFocus, visualFocus, setVisualFocus } = useFocus();\n\n const [value, setValue] = useState<string>(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n const numericValue = useMemo(() => {\n return getUnformattedNumber({\n value,\n currency,\n locale: intl.locale,\n });\n }, [value, currency, intl.locale]);\n\n const valueWithFullDecimals = useMemo(() => {\n return getFormattedString({\n value: numericValue ?? 0,\n currency,\n locale: intl.locale,\n alwaysShowDecimals: true,\n });\n }, [numericValue, currency, intl.locale]);\n\n const ref = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (autoFocus) {\n ref.current?.focus();\n }\n }, []);\n\n const placeholder = getPlaceholder(currency, intl.locale);\n const groupSeparator = getGroupSeparator(currency, intl.locale);\n const decimalSeparator = getDecimalSeparator(currency, intl.locale);\n const maxDecimalCount = getDecimalCount(currency, intl.locale);\n\n const decimalPart = getDecimalPart(value, decimalSeparator);\n const decimalMode = decimalSeparator && value.includes(decimalSeparator);\n\n useEffect(() => {\n if (!focus) {\n setValue(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [amount]);\n\n useEffect(() => {\n onFocusChange?.(visualFocus);\n }, [visualFocus]);\n\n const shouldReformatAfterUserInput = (newValue: string) => {\n // don't reformat if formatting would wipe out user's input\n if (reformatValue(newValue) === '') {\n return false;\n }\n\n const endsWithDecimalSeparator = decimalSeparator && newValue.endsWith(decimalSeparator);\n const endsWithGroupSeparator = groupSeparator && newValue.endsWith(groupSeparator);\n\n // if the user has entered a seperator to the end, formatting would delete it\n if (endsWithDecimalSeparator || endsWithGroupSeparator) {\n return false;\n }\n\n const containsDecimalSeparator = decimalSeparator && newValue.includes(decimalSeparator);\n\n if (containsDecimalSeparator) {\n const enteredDecimalsCount = getEnteredDecimalsCount(newValue, decimalSeparator);\n // don't reformat until user has entered all the allowed decimals\n // for example, we don't want 1.1 to be reformatted to 1.10 immediately\n if (enteredDecimalsCount < maxDecimalCount) {\n return false;\n }\n }\n\n return true;\n };\n\n const reformatValue = (newValue: string) => {\n const unformattedValue = getUnformattedNumber({\n value: newValue,\n currency,\n locale: intl.locale,\n });\n const formattedValue = unformattedValue\n ? getFormattedString({\n value: unformattedValue,\n currency,\n locale: intl.locale,\n })\n : '';\n return formattedValue;\n };\n\n const handleChange = (newValue: string) => {\n const oldCursorPosition = ref.current?.selectionStart ?? 0;\n\n const newFormattedString = shouldReformatAfterUserInput(newValue)\n ? reformatValue(newValue)\n : newValue;\n setValue(newFormattedString);\n\n const newNumber = getUnformattedNumber({\n value: newFormattedString,\n currency,\n locale: intl.locale,\n });\n\n if (newNumber !== numericValue) {\n if (numericValue || newNumber) {\n onChange(newNumber);\n }\n }\n\n const newCursorPosition = oldCursorPosition + (newFormattedString.length - newValue.length);\n requestAnimationFrame(() => {\n ref?.current?.setSelectionRange(newCursorPosition, newCursorPosition);\n });\n };\n\n const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {\n e.preventDefault();\n\n const clipboardData = e.clipboardData?.getData('text/plain');\n if (!clipboardData) {\n return;\n }\n\n // need to sanitise the pasted value otherwise other validation logic will ignore the input entirely\n const sanitisedValue = reformatValue(clipboardData);\n\n handleChange(sanitisedValue);\n };\n\n const handleBlur = () => {\n setFocus(false);\n setValue(reformatValue(value));\n };\n\n const handleBackspace = (e: KeyboardEvent<HTMLInputElement>) => {\n const input = e.target as HTMLInputElement;\n // using the updated selection range after the backspace key has been processed, instead of the current selection range in state\n const { value: currentValue, selectionStart, selectionEnd } = input;\n\n if (selectionStart === selectionEnd && selectionStart && selectionStart > 0) {\n const charBeforeCursor = currentValue[selectionStart - 1];\n\n // if the user deletes a thousands separator, remove the digit before it as well\n if (charBeforeCursor === groupSeparator) {\n e.preventDefault();\n const beforeCursor = currentValue.slice(0, selectionStart - 2);\n const afterCursor = currentValue.slice(selectionStart);\n const newValue = `${beforeCursor}${afterCursor}`;\n input.setSelectionRange(beforeCursor.length, beforeCursor.length);\n handleChange(newValue);\n }\n }\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n setFocus(true);\n if (!isAllowedInputKey(e)) {\n e.preventDefault();\n }\n\n if (e.key === 'Backspace') {\n handleBackspace(e);\n }\n };\n\n const isAllowedInput = (e: ChangeEvent<HTMLInputElement>) => {\n const hasMultipleDecimalSeparators =\n decimalSeparator && e.target.value.split(decimalSeparator).length > 2;\n if (hasMultipleDecimalSeparators) {\n return false;\n }\n\n const newNumericValue = getUnformattedNumber({\n value: e.target.value,\n currency,\n locale: intl.locale,\n });\n const maxLength = Number.MAX_SAFE_INTEGER.toString().length;\n if (String(newNumericValue).length > maxLength) {\n return false;\n }\n\n return true;\n };\n\n const addonContent = useMemo((): string | null | undefined => {\n // because we're using a separate \"addon\" element for the placeholder decimals, there is a possibility that the input itself will become scrollable\n // and the decimals will appear on top of the input. Safest thing to do is to just hide the addon if there is not enough room\n if (isInputPossiblyOverflowing({ ref, value })) {\n return null;\n }\n if (!decimalSeparator || !value) {\n return null;\n }\n\n // if the user has typed a decimal separator, show the full decimal part as a placeholder\n // this returns a string even if there is no content, typing should replace the placeholder immediately without animation\n // otherwise there is an ugly animation when going from 1.23 to 1.2 due to AnimatePresence\n if (focus && decimalMode) {\n // reuse getDecimalPart\n const fullDecimalPart = getDecimalPart(valueWithFullDecimals, decimalSeparator);\n // show only the characters that are not already displayed by the input\n return fullDecimalPart?.slice(decimalPart?.length);\n }\n\n // in unfocused state, always show the full decimal part unless the user has already entered decimals\n if (!focus && !decimalMode) {\n const [_, decimalPlaceholder] = placeholder.split(decimalSeparator);\n return decimalSeparator + decimalPlaceholder;\n }\n\n return null;\n }, [\n decimalMode,\n decimalPart?.length,\n decimalSeparator,\n focus,\n placeholder,\n value,\n valueWithFullDecimals,\n ]);\n\n const style = useInputStyle({\n // whenever decimals are shown, we need to account for the full decimal part for the font size calculation\n value: addonContent ? valueWithFullDecimals : value,\n focus: visualFocus,\n inputElement: ref.current,\n loading,\n });\n\n return (\n <div className=\"wds-amount-input-container\">\n <div\n className={clsx('wds-amount-input-input-container', 'np-text-display-large')}\n style={style}\n >\n <input\n ref={ref}\n className=\"wds-amount-input-input\"\n id={id}\n autoComplete=\"off\"\n inputMode=\"decimal\"\n value={value}\n type=\"text\"\n placeholder={placeholder}\n aria-describedby={describedById}\n /* without this, the input tries to keep an aspect ratio and doesn't respect CSS width rules */\n size={1}\n onChange={(e) => {\n if (isAllowedInput(e)) {\n handleChange(e.target.value);\n }\n }}\n onBlurCapture={() => handleBlur()}\n onPaste={(e) => handlePaste(e)}\n onFocus={() => {\n setFocus(true);\n }}\n onBlur={() => {\n setTimeout(() => setVisualFocus(false), 30);\n }}\n onKeyDown={(e) => handleKeyDown(e)}\n />\n <AnimatePresence initial={false}>\n {addonContent !== null && (\n <AnimatedNumber\n className={clsx(\n 'wds-amount-input-placeholder',\n visualFocus && 'wds-amount-input-placeholder-focus',\n )}\n onClick={() => ref.current?.focus()}\n >\n {addonContent}\n </AnimatedNumber>\n )}\n </AnimatePresence>\n </div>\n </div>\n );\n};\n\nconst getPlaceholder = (currency: string, locale: string) => {\n return formatAmount(0, currency, locale, { alwaysShowDecimals: true });\n};\n\nconst getDecimalPart = (value: string, decimalSeparator: string | null) => {\n if (!value || !decimalSeparator) {\n return undefined;\n }\n\n const [_, decimalPart] = value.split(decimalSeparator);\n return decimalPart ?? undefined;\n};\n"],"names":["AmountInput","id","describedById","amount","currency","autoFocus","onChange","onFocusChange","loading","intl","useIntl","focus","setFocus","visualFocus","setVisualFocus","useFocus","value","setValue","useState","getFormattedString","locale","numericValue","useMemo","getUnformattedNumber","valueWithFullDecimals","alwaysShowDecimals","ref","useRef","useEffect","current","placeholder","getPlaceholder","groupSeparator","getGroupSeparator","decimalSeparator","getDecimalSeparator","maxDecimalCount","getDecimalCount","decimalPart","getDecimalPart","decimalMode","includes","shouldReformatAfterUserInput","newValue","reformatValue","endsWithDecimalSeparator","endsWith","endsWithGroupSeparator","containsDecimalSeparator","enteredDecimalsCount","getEnteredDecimalsCount","unformattedValue","formattedValue","handleChange","oldCursorPosition","selectionStart","newFormattedString","newNumber","newCursorPosition","length","requestAnimationFrame","setSelectionRange","handlePaste","e","preventDefault","clipboardData","getData","sanitisedValue","handleBlur","handleBackspace","input","target","currentValue","selectionEnd","charBeforeCursor","beforeCursor","slice","afterCursor","handleKeyDown","isAllowedInputKey","key","isAllowedInput","hasMultipleDecimalSeparators","split","newNumericValue","maxLength","Number","MAX_SAFE_INTEGER","toString","String","addonContent","isInputPossiblyOverflowing","fullDecimalPart","_","decimalPlaceholder","style","useInputStyle","inputElement","_jsx","className","children","_jsxs","clsx","autoComplete","inputMode","type","size","onBlurCapture","onPaste","onFocus","onBlur","setTimeout","onKeyDown","AnimatePresence","initial","AnimatedNumber","onClick","formatAmount","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,4BAAe,EAAA;AAACC,QAAAA,OAAO,EAAE,KAAM;AAAAd,QAAAA,QAAA,EAC7BV,YAAY,KAAK,IAAI,iBACpBQ,cAAA,CAACiB,6BAAc,EAAA;UACbhB,SAAS,EAAEG,SAAI,CACb,8BAA8B,EAC9BzF,WAAW,IAAI,oCAAoC,CACnD;UACFuG,OAAO,EAAEA,MAAM1F,GAAG,CAACG,OAAO,EAAElB,KAAK,EAAG;AAAAyF,UAAAA,QAAA,EAEnCV;SACa;AACjB,OACc,CACnB;KAAK;AACP,GAAK,CAAC;AAEV;AAEA,MAAM3D,cAAc,GAAGA,CAAC3B,QAAgB,EAAEgB,MAAc,KAAI;AAC1D,EAAA,OAAOiG,uBAAY,CAAC,CAAC,EAAEjH,QAAQ,EAAEgB,MAAM,EAAE;AAAEK,IAAAA,kBAAkB,EAAE;AAAI,GAAE,CAAC;AACxE,CAAC;AAED,MAAMc,cAAc,GAAGA,CAACvB,KAAa,EAAEkB,gBAA+B,KAAI;AACxE,EAAA,IAAI,CAAClB,KAAK,IAAI,CAACkB,gBAAgB,EAAE;AAC/B,IAAA,OAAOoF,SAAS;AAClB,EAAA;EAEA,MAAM,CAACzB,CAAC,EAAEvD,WAAW,CAAC,GAAGtB,KAAK,CAACmE,KAAK,CAACjD,gBAAgB,CAAC;EACtD,OAAOI,WAAW,IAAIgF,SAAS;AACjC,CAAC;;;;"}
|
|
@@ -7,7 +7,7 @@ import { AnimatedNumber } from './AnimatedNumber.mjs';
|
|
|
7
7
|
import { useFocus } from './useFocus.mjs';
|
|
8
8
|
import { useInputStyle } from './useInputStyle.mjs';
|
|
9
9
|
import { getFormattedString, getUnformattedNumber, getGroupSeparator, getDecimalSeparator, getDecimalCount, isInputPossiblyOverflowing, isAllowedInputKey, getEnteredDecimalsCount } from './utils.mjs';
|
|
10
|
-
import {
|
|
10
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
11
11
|
|
|
12
12
|
const AmountInput = ({
|
|
13
13
|
id,
|
|
@@ -220,13 +220,10 @@ const AmountInput = ({
|
|
|
220
220
|
inputElement: ref.current,
|
|
221
221
|
loading
|
|
222
222
|
});
|
|
223
|
-
|
|
224
|
-
return '';
|
|
225
|
-
};
|
|
226
|
-
return /*#__PURE__*/jsxs("div", {
|
|
223
|
+
return /*#__PURE__*/jsx("div", {
|
|
227
224
|
className: "wds-amount-input-container",
|
|
228
|
-
children:
|
|
229
|
-
className:
|
|
225
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
226
|
+
className: clsx('wds-amount-input-input-container', 'np-text-display-large'),
|
|
230
227
|
style: style,
|
|
231
228
|
children: [/*#__PURE__*/jsx("input", {
|
|
232
229
|
ref: ref,
|
|
@@ -262,7 +259,7 @@ const AmountInput = ({
|
|
|
262
259
|
children: addonContent
|
|
263
260
|
})
|
|
264
261
|
})]
|
|
265
|
-
})
|
|
262
|
+
})
|
|
266
263
|
});
|
|
267
264
|
};
|
|
268
265
|
const getPlaceholder = (currency, locale) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AmountInput.mjs","sources":["../../src/moneyInputField/AmountInput.tsx"],"sourcesContent":["import { formatAmount } from '@transferwise/formatting';\nimport { clsx } from 'clsx';\nimport { AnimatePresence } from 'framer-motion';\nimport { type ChangeEvent, type KeyboardEvent, useEffect, useMemo, useRef, useState } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { AnimatedNumber } from './AnimatedNumber';\nimport { useFocus } from './useFocus';\nimport { useInputStyle } from './useInputStyle';\nimport {\n getDecimalCount,\n getDecimalSeparator,\n getEnteredDecimalsCount,\n getFormattedString,\n getGroupSeparator,\n getUnformattedNumber,\n isAllowedInputKey,\n isInputPossiblyOverflowing,\n} from './utils';\n\ntype Props = {\n id: string;\n describedById?: string;\n amount?: number | null;\n currency: string;\n autoFocus?: boolean;\n onChange: (amount: number | null) => void;\n onFocusChange?: (focused: boolean) => void;\n} & Pick<MoneyInputFieldProps, 'loading'>;\n\nexport const AmountInput = ({\n id,\n describedById,\n amount,\n currency,\n autoFocus,\n onChange,\n onFocusChange,\n loading,\n}: Props) => {\n const intl = useIntl();\n const { focus, setFocus, visualFocus, setVisualFocus } = useFocus();\n\n const [value, setValue] = useState<string>(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n const numericValue = useMemo(() => {\n return getUnformattedNumber({\n value,\n currency,\n locale: intl.locale,\n });\n }, [value, currency, intl.locale]);\n\n const valueWithFullDecimals = useMemo(() => {\n return getFormattedString({\n value: numericValue ?? 0,\n currency,\n locale: intl.locale,\n alwaysShowDecimals: true,\n });\n }, [numericValue, currency, intl.locale]);\n\n const ref = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (autoFocus) {\n ref.current?.focus();\n }\n }, []);\n\n const placeholder = getPlaceholder(currency, intl.locale);\n const groupSeparator = getGroupSeparator(currency, intl.locale);\n const decimalSeparator = getDecimalSeparator(currency, intl.locale);\n const maxDecimalCount = getDecimalCount(currency, intl.locale);\n\n const decimalPart = getDecimalPart(value, decimalSeparator);\n const decimalMode = decimalSeparator && value.includes(decimalSeparator);\n\n useEffect(() => {\n if (!focus) {\n setValue(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [amount]);\n\n useEffect(() => {\n onFocusChange?.(visualFocus);\n }, [visualFocus]);\n\n const shouldReformatAfterUserInput = (newValue: string) => {\n // don't reformat if formatting would wipe out user's input\n if (reformatValue(newValue) === '') {\n return false;\n }\n\n const endsWithDecimalSeparator = decimalSeparator && newValue.endsWith(decimalSeparator);\n const endsWithGroupSeparator = groupSeparator && newValue.endsWith(groupSeparator);\n\n // if the user has entered a seperator to the end, formatting would delete it\n if (endsWithDecimalSeparator || endsWithGroupSeparator) {\n return false;\n }\n\n const containsDecimalSeparator = decimalSeparator && newValue.includes(decimalSeparator);\n\n if (containsDecimalSeparator) {\n const enteredDecimalsCount = getEnteredDecimalsCount(newValue, decimalSeparator);\n // don't reformat until user has entered all the allowed decimals\n // for example, we don't want 1.1 to be reformatted to 1.10 immediately\n if (enteredDecimalsCount < maxDecimalCount) {\n return false;\n }\n }\n\n return true;\n };\n\n const reformatValue = (newValue: string) => {\n const unformattedValue = getUnformattedNumber({\n value: newValue,\n currency,\n locale: intl.locale,\n });\n const formattedValue = unformattedValue\n ? getFormattedString({\n value: unformattedValue,\n currency,\n locale: intl.locale,\n })\n : '';\n return formattedValue;\n };\n\n const handleChange = (newValue: string) => {\n const oldCursorPosition = ref.current?.selectionStart ?? 0;\n\n const newFormattedString = shouldReformatAfterUserInput(newValue)\n ? reformatValue(newValue)\n : newValue;\n setValue(newFormattedString);\n\n const newNumber = getUnformattedNumber({\n value: newFormattedString,\n currency,\n locale: intl.locale,\n });\n\n if (newNumber !== numericValue) {\n if (numericValue || newNumber) {\n onChange(newNumber);\n }\n }\n\n const newCursorPosition = oldCursorPosition + (newFormattedString.length - newValue.length);\n requestAnimationFrame(() => {\n ref?.current?.setSelectionRange(newCursorPosition, newCursorPosition);\n });\n };\n\n const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {\n e.preventDefault();\n\n const clipboardData = e.clipboardData?.getData('text/plain');\n if (!clipboardData) {\n return;\n }\n\n // need to sanitise the pasted value otherwise other validation logic will ignore the input entirely\n const sanitisedValue = reformatValue(clipboardData);\n\n handleChange(sanitisedValue);\n };\n\n const handleBlur = () => {\n setFocus(false);\n setValue(reformatValue(value));\n };\n\n const handleBackspace = (e: KeyboardEvent<HTMLInputElement>) => {\n const input = e.target as HTMLInputElement;\n // using the updated selection range after the backspace key has been processed, instead of the current selection range in state\n const { value: currentValue, selectionStart, selectionEnd } = input;\n\n if (selectionStart === selectionEnd && selectionStart && selectionStart > 0) {\n const charBeforeCursor = currentValue[selectionStart - 1];\n\n // if the user deletes a thousands separator, remove the digit before it as well\n if (charBeforeCursor === groupSeparator) {\n e.preventDefault();\n const beforeCursor = currentValue.slice(0, selectionStart - 2);\n const afterCursor = currentValue.slice(selectionStart);\n const newValue = `${beforeCursor}${afterCursor}`;\n input.setSelectionRange(beforeCursor.length, beforeCursor.length);\n handleChange(newValue);\n }\n }\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n setFocus(true);\n if (!isAllowedInputKey(e)) {\n e.preventDefault();\n }\n\n if (e.key === 'Backspace') {\n handleBackspace(e);\n }\n };\n\n const isAllowedInput = (e: ChangeEvent<HTMLInputElement>) => {\n const hasMultipleDecimalSeparators =\n decimalSeparator && e.target.value.split(decimalSeparator).length > 2;\n if (hasMultipleDecimalSeparators) {\n return false;\n }\n\n const newNumericValue = getUnformattedNumber({\n value: e.target.value,\n currency,\n locale: intl.locale,\n });\n const maxLength = Number.MAX_SAFE_INTEGER.toString().length;\n if (String(newNumericValue).length > maxLength) {\n return false;\n }\n\n return true;\n };\n\n const addonContent = useMemo((): string | null | undefined => {\n // because we're using a separate \"addon\" element for the placeholder decimals, there is a possibility that the input itself will become scrollable\n // and the decimals will appear on top of the input. Safest thing to do is to just hide the addon if there is not enough room\n if (isInputPossiblyOverflowing({ ref, value })) {\n return null;\n }\n if (!decimalSeparator || !value) {\n return null;\n }\n\n // if the user has typed a decimal separator, show the full decimal part as a placeholder\n // this returns a string even if there is no content, typing should replace the placeholder immediately without animation\n // otherwise there is an ugly animation when going from 1.23 to 1.2 due to AnimatePresence\n if (focus && decimalMode) {\n // reuse getDecimalPart\n const fullDecimalPart = getDecimalPart(valueWithFullDecimals, decimalSeparator);\n // show only the characters that are not already displayed by the input\n return fullDecimalPart?.slice(decimalPart?.length);\n }\n\n // in unfocused state, always show the full decimal part unless the user has already entered decimals\n if (!focus && !decimalMode) {\n const [_, decimalPlaceholder] = placeholder.split(decimalSeparator);\n return decimalSeparator + decimalPlaceholder;\n }\n\n return null;\n }, [\n decimalMode,\n decimalPart?.length,\n decimalSeparator,\n focus,\n placeholder,\n value,\n valueWithFullDecimals,\n ]);\n\n const style = useInputStyle({\n // whenever decimals are shown, we need to account for the full decimal part for the font size calculation\n value: addonContent ? valueWithFullDecimals : value,\n focus: visualFocus,\n inputElement: ref.current,\n loading,\n });\n\n const getInputMask = () => {\n return '';\n };\n\n return (\n <div className=\"wds-amount-input-container\">\n <div className=\"wds-amount-input-input-container display-2\" style={style}>\n <input\n ref={ref}\n className=\"wds-amount-input-input\"\n id={id}\n autoComplete=\"off\"\n inputMode=\"decimal\"\n value={value}\n type=\"text\"\n placeholder={placeholder}\n aria-describedby={describedById}\n /* without this, the input tries to keep an aspect ratio and doesn't respect CSS width rules */\n size={1}\n onChange={(e) => {\n if (isAllowedInput(e)) {\n handleChange(e.target.value);\n }\n }}\n onBlurCapture={() => handleBlur()}\n onPaste={(e) => handlePaste(e)}\n onFocus={() => {\n setFocus(true);\n }}\n onBlur={() => {\n setTimeout(() => setVisualFocus(false), 30);\n }}\n onKeyDown={(e) => handleKeyDown(e)}\n />\n <AnimatePresence initial={false}>\n {addonContent !== null && (\n <AnimatedNumber\n className={clsx(\n 'wds-amount-input-placeholder',\n visualFocus && 'wds-amount-input-placeholder-focus',\n )}\n onClick={() => ref.current?.focus()}\n >\n {addonContent}\n </AnimatedNumber>\n )}\n </AnimatePresence>\n </div>\n {getInputMask()}\n </div>\n );\n};\n\nconst getPlaceholder = (currency: string, locale: string) => {\n return formatAmount(0, currency, locale, { alwaysShowDecimals: true });\n};\n\nconst getDecimalPart = (value: string, decimalSeparator: string | null) => {\n if (!value || !decimalSeparator) {\n return undefined;\n }\n\n const [_, decimalPart] = value.split(decimalSeparator);\n return decimalPart ?? undefined;\n};\n"],"names":["AmountInput","id","describedById","amount","currency","autoFocus","onChange","onFocusChange","loading","intl","useIntl","focus","setFocus","visualFocus","setVisualFocus","useFocus","value","setValue","useState","getFormattedString","locale","numericValue","useMemo","getUnformattedNumber","valueWithFullDecimals","alwaysShowDecimals","ref","useRef","useEffect","current","placeholder","getPlaceholder","groupSeparator","getGroupSeparator","decimalSeparator","getDecimalSeparator","maxDecimalCount","getDecimalCount","decimalPart","getDecimalPart","decimalMode","includes","shouldReformatAfterUserInput","newValue","reformatValue","endsWithDecimalSeparator","endsWith","endsWithGroupSeparator","containsDecimalSeparator","enteredDecimalsCount","getEnteredDecimalsCount","unformattedValue","formattedValue","handleChange","oldCursorPosition","selectionStart","newFormattedString","newNumber","newCursorPosition","length","requestAnimationFrame","setSelectionRange","handlePaste","e","preventDefault","clipboardData","getData","sanitisedValue","handleBlur","handleBackspace","input","target","currentValue","selectionEnd","charBeforeCursor","beforeCursor","slice","afterCursor","handleKeyDown","isAllowedInputKey","key","isAllowedInput","hasMultipleDecimalSeparators","split","newNumericValue","maxLength","Number","MAX_SAFE_INTEGER","toString","String","addonContent","isInputPossiblyOverflowing","fullDecimalPart","_","decimalPlaceholder","style","useInputStyle","inputElement","getInputMask","_jsxs","className","children","_jsx","autoComplete","inputMode","type","size","onBlurCapture","onPaste","onFocus","onBlur","setTimeout","onKeyDown","AnimatePresence","initial","AnimatedNumber","clsx","onClick","formatAmount","undefined"],"mappings":";;;;;;;;;;;AA+BO,MAAMA,WAAW,GAAGA,CAAC;EAC1BC,EAAE;EACFC,aAAa;EACbC,MAAM;EACNC,QAAQ;EACRC,SAAS;EACTC,QAAQ;EACRC,aAAa;AACbC,EAAAA;AAAO,CACD,KAAI;AACV,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;EACtB,MAAM;IAAEC,KAAK;IAAEC,QAAQ;IAAEC,WAAW;AAAEC,IAAAA;GAAgB,GAAGC,QAAQ,EAAE;EAEnE,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,QAAQ,CAChCf,MAAM,GACFgB,kBAAkB,CAAC;AACjBH,IAAAA,KAAK,EAAEb,MAAM;IACbC,QAAQ;IACRgB,MAAM,EAAEX,IAAI,CAACW;GACd,CAAC,GACF,EAAE,CACP;AACD,EAAA,MAAMC,YAAY,GAAGC,OAAO,CAAC,MAA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B,EAAE;AAAI,GAAE,CAAC;AACxE,CAAC;AAED,MAAMc,cAAc,GAAGA,CAACvB,KAAa,EAAEkB,gBAA+B,KAAI;AACxE,EAAA,IAAI,CAAClB,KAAK,IAAI,CAACkB,gBAAgB,EAAE;AAC/B,IAAA,OAAOqF,SAAS;AAClB,EAAA;EAEA,MAAM,CAAC1B,CAAC,EAAEvD,WAAW,CAAC,GAAGtB,KAAK,CAACmE,KAAK,CAACjD,gBAAgB,CAAC;EACtD,OAAOI,WAAW,IAAIiF,SAAS;AACjC,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"AmountInput.mjs","sources":["../../src/moneyInputField/AmountInput.tsx"],"sourcesContent":["import { formatAmount } from '@transferwise/formatting';\nimport { clsx } from 'clsx';\nimport { AnimatePresence } from 'framer-motion';\nimport { type ChangeEvent, type KeyboardEvent, useEffect, useMemo, useRef, useState } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport { Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { AnimatedNumber } from './AnimatedNumber';\nimport { useFocus } from './useFocus';\nimport { useInputStyle } from './useInputStyle';\nimport {\n getDecimalCount,\n getDecimalSeparator,\n getEnteredDecimalsCount,\n getFormattedString,\n getGroupSeparator,\n getUnformattedNumber,\n isAllowedInputKey,\n isInputPossiblyOverflowing,\n} from './utils';\n\ntype Props = {\n id: string;\n describedById?: string;\n amount?: number | null;\n currency: string;\n autoFocus?: boolean;\n onChange: (amount: number | null) => void;\n onFocusChange?: (focused: boolean) => void;\n} & Pick<MoneyInputFieldProps, 'loading'>;\n\nexport const AmountInput = ({\n id,\n describedById,\n amount,\n currency,\n autoFocus,\n onChange,\n onFocusChange,\n loading,\n}: Props) => {\n const intl = useIntl();\n const { focus, setFocus, visualFocus, setVisualFocus } = useFocus();\n\n const [value, setValue] = useState<string>(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n const numericValue = useMemo(() => {\n return getUnformattedNumber({\n value,\n currency,\n locale: intl.locale,\n });\n }, [value, currency, intl.locale]);\n\n const valueWithFullDecimals = useMemo(() => {\n return getFormattedString({\n value: numericValue ?? 0,\n currency,\n locale: intl.locale,\n alwaysShowDecimals: true,\n });\n }, [numericValue, currency, intl.locale]);\n\n const ref = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (autoFocus) {\n ref.current?.focus();\n }\n }, []);\n\n const placeholder = getPlaceholder(currency, intl.locale);\n const groupSeparator = getGroupSeparator(currency, intl.locale);\n const decimalSeparator = getDecimalSeparator(currency, intl.locale);\n const maxDecimalCount = getDecimalCount(currency, intl.locale);\n\n const decimalPart = getDecimalPart(value, decimalSeparator);\n const decimalMode = decimalSeparator && value.includes(decimalSeparator);\n\n useEffect(() => {\n if (!focus) {\n setValue(\n amount\n ? getFormattedString({\n value: amount,\n currency,\n locale: intl.locale,\n })\n : '',\n );\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [amount]);\n\n useEffect(() => {\n onFocusChange?.(visualFocus);\n }, [visualFocus]);\n\n const shouldReformatAfterUserInput = (newValue: string) => {\n // don't reformat if formatting would wipe out user's input\n if (reformatValue(newValue) === '') {\n return false;\n }\n\n const endsWithDecimalSeparator = decimalSeparator && newValue.endsWith(decimalSeparator);\n const endsWithGroupSeparator = groupSeparator && newValue.endsWith(groupSeparator);\n\n // if the user has entered a seperator to the end, formatting would delete it\n if (endsWithDecimalSeparator || endsWithGroupSeparator) {\n return false;\n }\n\n const containsDecimalSeparator = decimalSeparator && newValue.includes(decimalSeparator);\n\n if (containsDecimalSeparator) {\n const enteredDecimalsCount = getEnteredDecimalsCount(newValue, decimalSeparator);\n // don't reformat until user has entered all the allowed decimals\n // for example, we don't want 1.1 to be reformatted to 1.10 immediately\n if (enteredDecimalsCount < maxDecimalCount) {\n return false;\n }\n }\n\n return true;\n };\n\n const reformatValue = (newValue: string) => {\n const unformattedValue = getUnformattedNumber({\n value: newValue,\n currency,\n locale: intl.locale,\n });\n const formattedValue = unformattedValue\n ? getFormattedString({\n value: unformattedValue,\n currency,\n locale: intl.locale,\n })\n : '';\n return formattedValue;\n };\n\n const handleChange = (newValue: string) => {\n const oldCursorPosition = ref.current?.selectionStart ?? 0;\n\n const newFormattedString = shouldReformatAfterUserInput(newValue)\n ? reformatValue(newValue)\n : newValue;\n setValue(newFormattedString);\n\n const newNumber = getUnformattedNumber({\n value: newFormattedString,\n currency,\n locale: intl.locale,\n });\n\n if (newNumber !== numericValue) {\n if (numericValue || newNumber) {\n onChange(newNumber);\n }\n }\n\n const newCursorPosition = oldCursorPosition + (newFormattedString.length - newValue.length);\n requestAnimationFrame(() => {\n ref?.current?.setSelectionRange(newCursorPosition, newCursorPosition);\n });\n };\n\n const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {\n e.preventDefault();\n\n const clipboardData = e.clipboardData?.getData('text/plain');\n if (!clipboardData) {\n return;\n }\n\n // need to sanitise the pasted value otherwise other validation logic will ignore the input entirely\n const sanitisedValue = reformatValue(clipboardData);\n\n handleChange(sanitisedValue);\n };\n\n const handleBlur = () => {\n setFocus(false);\n setValue(reformatValue(value));\n };\n\n const handleBackspace = (e: KeyboardEvent<HTMLInputElement>) => {\n const input = e.target as HTMLInputElement;\n // using the updated selection range after the backspace key has been processed, instead of the current selection range in state\n const { value: currentValue, selectionStart, selectionEnd } = input;\n\n if (selectionStart === selectionEnd && selectionStart && selectionStart > 0) {\n const charBeforeCursor = currentValue[selectionStart - 1];\n\n // if the user deletes a thousands separator, remove the digit before it as well\n if (charBeforeCursor === groupSeparator) {\n e.preventDefault();\n const beforeCursor = currentValue.slice(0, selectionStart - 2);\n const afterCursor = currentValue.slice(selectionStart);\n const newValue = `${beforeCursor}${afterCursor}`;\n input.setSelectionRange(beforeCursor.length, beforeCursor.length);\n handleChange(newValue);\n }\n }\n };\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n setFocus(true);\n if (!isAllowedInputKey(e)) {\n e.preventDefault();\n }\n\n if (e.key === 'Backspace') {\n handleBackspace(e);\n }\n };\n\n const isAllowedInput = (e: ChangeEvent<HTMLInputElement>) => {\n const hasMultipleDecimalSeparators =\n decimalSeparator && e.target.value.split(decimalSeparator).length > 2;\n if (hasMultipleDecimalSeparators) {\n return false;\n }\n\n const newNumericValue = getUnformattedNumber({\n value: e.target.value,\n currency,\n locale: intl.locale,\n });\n const maxLength = Number.MAX_SAFE_INTEGER.toString().length;\n if (String(newNumericValue).length > maxLength) {\n return false;\n }\n\n return true;\n };\n\n const addonContent = useMemo((): string | null | undefined => {\n // because we're using a separate \"addon\" element for the placeholder decimals, there is a possibility that the input itself will become scrollable\n // and the decimals will appear on top of the input. Safest thing to do is to just hide the addon if there is not enough room\n if (isInputPossiblyOverflowing({ ref, value })) {\n return null;\n }\n if (!decimalSeparator || !value) {\n return null;\n }\n\n // if the user has typed a decimal separator, show the full decimal part as a placeholder\n // this returns a string even if there is no content, typing should replace the placeholder immediately without animation\n // otherwise there is an ugly animation when going from 1.23 to 1.2 due to AnimatePresence\n if (focus && decimalMode) {\n // reuse getDecimalPart\n const fullDecimalPart = getDecimalPart(valueWithFullDecimals, decimalSeparator);\n // show only the characters that are not already displayed by the input\n return fullDecimalPart?.slice(decimalPart?.length);\n }\n\n // in unfocused state, always show the full decimal part unless the user has already entered decimals\n if (!focus && !decimalMode) {\n const [_, decimalPlaceholder] = placeholder.split(decimalSeparator);\n return decimalSeparator + decimalPlaceholder;\n }\n\n return null;\n }, [\n decimalMode,\n decimalPart?.length,\n decimalSeparator,\n focus,\n placeholder,\n value,\n valueWithFullDecimals,\n ]);\n\n const style = useInputStyle({\n // whenever decimals are shown, we need to account for the full decimal part for the font size calculation\n value: addonContent ? valueWithFullDecimals : value,\n focus: visualFocus,\n inputElement: ref.current,\n loading,\n });\n\n return (\n <div className=\"wds-amount-input-container\">\n <div\n className={clsx('wds-amount-input-input-container', 'np-text-display-large')}\n style={style}\n >\n <input\n ref={ref}\n className=\"wds-amount-input-input\"\n id={id}\n autoComplete=\"off\"\n inputMode=\"decimal\"\n value={value}\n type=\"text\"\n placeholder={placeholder}\n aria-describedby={describedById}\n /* without this, the input tries to keep an aspect ratio and doesn't respect CSS width rules */\n size={1}\n onChange={(e) => {\n if (isAllowedInput(e)) {\n handleChange(e.target.value);\n }\n }}\n onBlurCapture={() => handleBlur()}\n onPaste={(e) => handlePaste(e)}\n onFocus={() => {\n setFocus(true);\n }}\n onBlur={() => {\n setTimeout(() => setVisualFocus(false), 30);\n }}\n onKeyDown={(e) => handleKeyDown(e)}\n />\n <AnimatePresence initial={false}>\n {addonContent !== null && (\n <AnimatedNumber\n className={clsx(\n 'wds-amount-input-placeholder',\n visualFocus && 'wds-amount-input-placeholder-focus',\n )}\n onClick={() => ref.current?.focus()}\n >\n {addonContent}\n </AnimatedNumber>\n )}\n </AnimatePresence>\n </div>\n </div>\n );\n};\n\nconst getPlaceholder = (currency: string, locale: string) => {\n return formatAmount(0, currency, locale, { alwaysShowDecimals: true });\n};\n\nconst getDecimalPart = (value: string, decimalSeparator: string | null) => {\n if (!value || !decimalSeparator) {\n return undefined;\n }\n\n const [_, decimalPart] = value.split(decimalSeparator);\n return decimalPart ?? undefined;\n};\n"],"names":["AmountInput","id","describedById","amount","currency","autoFocus","onChange","onFocusChange","loading","intl","useIntl","focus","setFocus","visualFocus","setVisualFocus","useFocus","value","setValue","useState","getFormattedString","locale","numericValue","useMemo","getUnformattedNumber","valueWithFullDecimals","alwaysShowDecimals","ref","useRef","useEffect","current","placeholder","getPlaceholder","groupSeparator","getGroupSeparator","decimalSeparator","getDecimalSeparator","maxDecimalCount","getDecimalCount","decimalPart","getDecimalPart","decimalMode","includes","shouldReformatAfterUserInput","newValue","reformatValue","endsWithDecimalSeparator","endsWith","endsWithGroupSeparator","containsDecimalSeparator","enteredDecimalsCount","getEnteredDecimalsCount","unformattedValue","formattedValue","handleChange","oldCursorPosition","selectionStart","newFormattedString","newNumber","newCursorPosition","length","requestAnimationFrame","setSelectionRange","handlePaste","e","preventDefault","clipboardData","getData","sanitisedValue","handleBlur","handleBackspace","input","target","currentValue","selectionEnd","charBeforeCursor","beforeCursor","slice","afterCursor","handleKeyDown","isAllowedInputKey","key","isAllowedInput","hasMultipleDecimalSeparators","split","newNumericValue","maxLength","Number","MAX_SAFE_INTEGER","toString","String","addonContent","isInputPossiblyOverflowing","fullDecimalPart","_","decimalPlaceholder","style","useInputStyle","inputElement","_jsx","className","children","_jsxs","clsx","autoComplete","inputMode","type","size","onBlurCapture","onPaste","onFocus","onBlur","setTimeout","onKeyDown","AnimatePresence","initial","AnimatedNumber","onClick","formatAmount","undefined"],"mappings":";;;;;;;;;;;AA+BO,MAAMA,WAAW,GAAGA,CAAC;EAC1BC,EAAE;EACFC,aAAa;EACbC,MAAM;EACNC,QAAQ;EACRC,SAAS;EACTC,QAAQ;EACRC,aAAa;AACbC,EAAAA;AAAO,CACD,KAAI;AACV,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;EACtB,MAAM;IAAEC,KAAK;IAAEC,QAAQ;IAAEC,WAAW;AAAEC,IAAAA;GAAgB,GAAGC,QAAQ,EAAE;EAEnE,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,QAAQ,CAChCf,MAAM,GACFgB,kBAAkB,CAAC;AACjBH,IAAAA,KAAK,EAAEb,MAAM;IACbC,QAAQ;IACRgB,MAAM,EAAEX,IAAI,CAACW;GACd,CAAC,GACF,EAAE,CACP;AACD,EAAA,MAAMC,YAAY,GAAGC,OAAO,CAAC,MAAK;AAChC,IAAA,OAAOC,oBAAoB,CAAC;MAC1BP,KAAK;MACLZ,QAAQ;MACRgB,MAAM,EAAEX,IAAI,CAACW;AACd,KAAA,CAAC;EACJ,CAAC,EAAE,CAACJ,KAAK,EAAEZ,QAAQ,EAAEK,IAAI,CAACW,MAAM,CAAC,CAAC;AAElC,EAAA,MAAMI,qBAAqB,GAAGF,OAAO,CAAC,MAAK;AACzC,IAAA,OAAOH,kBAAkB,CAAC;MACxBH,KAAK,EAAEK,Y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
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var Button_resolver = require('../button/Button.resolver.js');
|
|
4
|
+
var SelectInput = require('../inputs/SelectInput.js');
|
|
3
5
|
var icons = require('@transferwise/icons');
|
|
4
6
|
var art = require('@wise/art');
|
|
5
7
|
var React = require('react');
|
|
6
8
|
var reactIntl = require('react-intl');
|
|
7
9
|
var MoneyInputField_messages = require('./MoneyInputField.messages.js');
|
|
8
10
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
-
var SelectInput = require('../inputs/SelectInput.js');
|
|
10
|
-
var Button_resolver = require('../button/Button.resolver.js');
|
|
11
11
|
|
|
12
12
|
const CurrencySelector = ({
|
|
13
13
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencySelector.js","sources":["../../src/moneyInputField/CurrencySelector.tsx"],"sourcesContent":["import {\n AvatarLayoutProps,\n Button,\n SelectInput,\n SelectInputOptionContent,\n SelectInputTriggerButton,\n} from '..';\nimport { CurrencyType, Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { ChevronDown } from '@transferwise/icons';\nimport { Flag } from '@wise/art';\nimport {\n type ButtonHTMLAttributes,\n forwardRef,\n type MouseEventHandler,\n type ReactNode,\n useMemo,\n useState,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport messages from './MoneyInputField.messages';\n\nexport interface CurrencyOption {\n label?: string;\n code: string;\n keywords: string[] | undefined;\n}\n\nexport interface CurrencySection {\n title: string;\n currencies: CurrencyOption[];\n}\n\nexport type CurrencyOptions = CurrencySection[];\n\nexport type Props = {\n id: string;\n labelId: string;\n options?: CurrencyOptions;\n onChange?: (currency: CurrencyType) => void;\n onOpen?: () => void;\n addons?: AvatarLayoutProps['avatars'];\n onSearchChange?: (payload: { query: string; resultCount: number }) => void;\n} & Pick<MoneyInputFieldProps, 'currency'>;\n\nexport const CurrencySelector = ({\n id,\n currency,\n options = [],\n labelId,\n onChange,\n addons,\n onOpen,\n onSearchChange,\n}: Props) => {\n const intl = useIntl();\n\n const allCurrencyOptions = useMemo(() => getUniqueCurrencies(options), [options]);\n\n const activeCurrencyOption = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allCurrencyOptions.find((option) => option.code === currency)!;\n }, [currency, allCurrencyOptions]);\n\n const disabled =\n !onChange ||\n options.length === 0 ||\n (options.length === 1 && options[0].currencies.length <= 1);\n\n const [searchQuery, setSearchQuery] = useState<string>('');\n\n const handleTriggerClick: MouseEventHandler = (event) => {\n const triggerEl = event.currentTarget;\n if (triggerEl?.getAttribute('aria-expanded') === 'false') {\n onOpen?.();\n }\n };\n\n const items = searchQuery\n ? filterAndSortCurrenciesForQuery(allCurrencyOptions, searchQuery).map(getCurrencySelectOption)\n : options.map(getCurrencyGroup);\n\n return (\n <SelectInput\n compareValues=\"code\"\n disabled={disabled}\n id={id}\n value={activeCurrencyOption}\n filterable\n filterPlaceholder={intl.formatMessage(messages.currencySelectorSearchPlaceholder)}\n UNSAFE_triggerButtonProps={{\n id: undefined,\n 'aria-labelledby': undefined,\n 'aria-describedby': labelId,\n 'aria-invalid': undefined,\n 'aria-label': intl.formatMessage(messages.currencySelectorSelectCurrency),\n }}\n items={items}\n renderValue={({ code, label }) => {\n return (\n <SelectInputOptionContent\n title={code}\n note={label}\n icon={<Flag code={code} intrinsicSize={24} />}\n />\n );\n }}\n renderTrigger={() => (\n <SelectInputTriggerButton\n as={ButtonInput}\n // @ts-expect-error new (v2) ButtonProps\n addonStart={{\n type: 'avatar',\n value: [\n addons ? addons[0] : null,\n {\n ...(addons && addons.length > 1\n ? { ...addons[1] }\n : {\n asset: <Flag code={currency} />,\n }),\n },\n ].filter((avatar) => Boolean(avatar)),\n }}\n addonEnd={disabled ? undefined : { type: 'icon', value: <ChevronDown /> }}\n onClick={(event) => handleTriggerClick(event)}\n >\n {currency}\n </SelectInputTriggerButton>\n )}\n onChange={(newValue) => {\n onChange?.(newValue.code);\n }}\n onFilterChange={({ queryNormalized }) => {\n setSearchQuery(queryNormalized ?? '');\n if (queryNormalized) {\n onSearchChange?.({\n query: queryNormalized,\n resultCount: filterAndSortCurrenciesForQuery(allCurrencyOptions, queryNormalized)\n .length,\n });\n }\n }}\n />\n );\n};\n\nexport const ButtonInput = forwardRef(function ButtonInput(\n { children, ...rest }: React.PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>,\n ref: React.ForwardedRef<HTMLButtonElement | null>,\n) {\n return (\n <Button\n ref={ref}\n size=\"md\"\n v2\n className=\"wds-currency-selector\"\n priority=\"secondary-neutral\"\n {...rest}\n >\n {children}\n </Button>\n );\n});\n\nconst getCurrencySelectOption = (currency: CurrencyOption) => {\n return {\n type: 'option' as const,\n value: currency,\n filterMatchers: currency.keywords,\n };\n};\n\nconst getCurrencyGroup = (section: CurrencySection) => {\n return {\n type: 'group' as const,\n label: section.title,\n options: section.currencies.map(getCurrencySelectOption),\n };\n};\n\nconst getUniqueCurrencies = (options: CurrencyOptions) => {\n const allCurrencyOptions = options.flatMap((section) => section.currencies);\n const uniqueCurrencies = new Map<string, CurrencyOption>();\n\n allCurrencyOptions.forEach((currencyObj) => {\n uniqueCurrencies.set(currencyObj.code, currencyObj);\n });\n\n return Array.from(uniqueCurrencies.values());\n};\n\nconst filterAndSortCurrenciesForQuery = (\n currencies: CurrencyOption[],\n query: string,\n): CurrencyOption[] => {\n return (\n currencies\n .filter((currency) => {\n return (\n currency.code.toLowerCase().includes(query) ||\n (currency.label ?? '').toLowerCase().includes(query) ||\n currency.keywords?.some((keyword) => keyword.toLowerCase().includes(query))\n );\n })\n // prefer exact matches, then sort alphabetically by code\n .sort((a, b) => {\n const aCode = a.code.toLowerCase();\n const bCode = b.code.toLowerCase();\n if (aCode === query) {\n return -1;\n }\n if (bCode === query) {\n return 1;\n }\n return aCode.localeCompare(bCode);\n })\n );\n};\n"],"names":["CurrencySelector","id","currency","options","labelId","onChange","addons","onOpen","onSearchChange","intl","useIntl","allCurrencyOptions","useMemo","getUniqueCurrencies","activeCurrencyOption","find","option","code","disabled","length","currencies","searchQuery","setSearchQuery","useState","handleTriggerClick","event","triggerEl","currentTarget","getAttribute","items","filterAndSortCurrenciesForQuery","map","getCurrencySelectOption","getCurrencyGroup","_jsx","SelectInput","compareValues","value","filterable","filterPlaceholder","formatMessage","messages","currencySelectorSearchPlaceholder","UNSAFE_triggerButtonProps","undefined","currencySelectorSelectCurrency","renderValue","label","SelectInputOptionContent","title","note","icon","Flag","intrinsicSize","renderTrigger","SelectInputTriggerButton","as","ButtonInput","addonStart","type","asset","filter","avatar","Boolean","addonEnd","ChevronDown","onClick","children","newValue","onFilterChange","queryNormalized","query","resultCount","forwardRef","rest","ref","Button","size","v2","className","priority","filterMatchers","keywords","section","flatMap","uniqueCurrencies","Map","forEach","currencyObj","set","Array","from","values","toLowerCase","includes","some","keyword","sort","a","b","aCode","bCode","localeCompare"],"mappings":";;;;;;;;;;;AA6CO,MAAMA,gBAAgB,GAAGA,CAAC;EAC/BC,EAAE;EACFC,QAAQ;AACRC,EAAAA,OAAO,GAAG,EAAE;EACZC,OAAO;EACPC,QAAQ;EACRC,MAAM;EACNC,MAAM;AACNC,EAAAA;AAAc,CACR,KAAI;AACV,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE;AAEtB,EAAA,MAAMC,kBAAkB,GAAGC,aAAO,CAAC,MAAMC,mBAAmB,CAACV,OAAO,CAAC,EAAE,CAACA,OAAO,CAAC,CAAC;AAEjF,EAAA,MAAMW,oBAAoB,GAAGF,aAAO,CAAC,MAAK;AACxC;IACA,OAAOD,kBAAkB,CAACI,IAAI,CAAEC,MAAM,IAAKA,MAAM,CAACC,IAAI,KAAKf,QAAQ,CAAE;AACvE,EAAA,CAAC,EAAE,CAACA,QAAQ,EAAES,kBAAkB,CAAC,CAAC;EAElC,MAAMO,QAAQ,GACZ,CAACb,QAAQ,IACTF,OAAO,CAACgB,MAAM,KAAK,CAAC,IACnBhB,OAAO,CAACgB,MAAM,KAAK,CAAC,IA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AA,kBAAkB,CAAC4E,OAAO,CAAEC,WAAW,IAAI;IACzCH,gBAAgB,CAACI,GAAG,CAACD,WAAW,CAACvE,IAAI,EAAEuE,WAAW,CAAC;AACrD,EAAA,CAAC,CAAC;EAEF,OAAOE,KAAK,CAACC,IAAI,CAACN,gBAAgB,CAACO,MAAM,EAAE,CAAC;AAC9C,CAAC;AAED,MAAM9D,+BAA+B,GAAGA,CACtCV,UAA4B,EAC5BmD,KAAa,KACO;AACpB,EAAA,OACEnD,UAAU,CACPyC,MAAM,CAAE3D,QAAQ,IAAI;IACnB,OACEA,QAAQ,CAACe,IAAI,CAAC4E,WAAW,EAAE,CAACC,QAAQ,CAACvB,KAAK,CAAC,IAC3C,CAACrE,QAAQ,CAAC6C,KAAK,IAAI,EAAE,EAAE8C,WAAW,EAAE,CAACC,QAAQ,CAACvB,KAAK,CAAC,IACpDrE,QAAQ,CAACgF,QAAQ,EAAEa,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACH,WAAW,EAAE,CAACC,QAAQ,CAACvB,KAAK,CAAC,CAAC;EAE/E,CAAC;AACD;AAAA,GACC0B,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAI;IACb,MAAMC,KAAK,GAAGF,CAAC,CAACjF,IAAI,CAAC4E,WAAW,EAAE;IAClC,MAAMQ,KAAK,GAAGF,CAAC,CAAClF,IAAI,CAAC4E,WAAW,EAAE;IAClC,IAAIO,KAAK,KAAK7B,KAAK,EAAE;AACnB,MAAA,OAAO,EAAE;AACX,IAAA;IACA,IAAI8B,KAAK,KAAK9B,KAAK,EAAE;AACnB,MAAA,OAAO,CAAC;AACV,IAAA;AACA,IAAA,OAAO6B,KAAK,CAACE,aAAa,CAACD,KAAK,CAAC;AACnC,EAAA,CAAC,CAAC;AAER,CAAC;;;;;"}
|
|
1
|
+
{"version":3,"file":"CurrencySelector.js","sources":["../../src/moneyInputField/CurrencySelector.tsx"],"sourcesContent":["import type { AvatarLayoutProps } from '../avatarLayout';\nimport Button from '../button';\nimport {\n SelectInput,\n SelectInputOptionContent,\n SelectInputTriggerButton,\n} from '../inputs/SelectInput';\nimport { CurrencyType, Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { ChevronDown } from '@transferwise/icons';\nimport { Flag } from '@wise/art';\nimport {\n type ButtonHTMLAttributes,\n forwardRef,\n type MouseEventHandler,\n useMemo,\n useState,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport messages from './MoneyInputField.messages';\n\nexport interface CurrencyOption {\n label?: string;\n code: string;\n keywords: string[] | undefined;\n}\n\nexport interface CurrencySection {\n title: string;\n currencies: CurrencyOption[];\n}\n\nexport type CurrencyOptions = CurrencySection[];\n\nexport type Props = {\n id: string;\n labelId: string;\n options?: CurrencyOptions;\n onChange?: (currency: CurrencyType) => void;\n onOpen?: () => void;\n addons?: AvatarLayoutProps['avatars'];\n onSearchChange?: (payload: { query: string; resultCount: number }) => void;\n} & Pick<MoneyInputFieldProps, 'currency'>;\n\nexport const CurrencySelector = ({\n id,\n currency,\n options = [],\n labelId,\n onChange,\n addons,\n onOpen,\n onSearchChange,\n}: Props) => {\n const intl = useIntl();\n\n const allCurrencyOptions = useMemo(() => getUniqueCurrencies(options), [options]);\n\n const activeCurrencyOption = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allCurrencyOptions.find((option) => option.code === currency)!;\n }, [currency, allCurrencyOptions]);\n\n const disabled =\n !onChange ||\n options.length === 0 ||\n (options.length === 1 && options[0].currencies.length <= 1);\n\n const [searchQuery, setSearchQuery] = useState<string>('');\n\n const handleTriggerClick: MouseEventHandler = (event) => {\n const triggerEl = event.currentTarget;\n if (triggerEl?.getAttribute('aria-expanded') === 'false') {\n onOpen?.();\n }\n };\n\n const items = searchQuery\n ? filterAndSortCurrenciesForQuery(allCurrencyOptions, searchQuery).map(getCurrencySelectOption)\n : options.map(getCurrencyGroup);\n\n return (\n <SelectInput\n compareValues=\"code\"\n disabled={disabled}\n id={id}\n value={activeCurrencyOption}\n filterable\n filterPlaceholder={intl.formatMessage(messages.currencySelectorSearchPlaceholder)}\n UNSAFE_triggerButtonProps={{\n id: undefined,\n 'aria-labelledby': undefined,\n 'aria-describedby': labelId,\n 'aria-invalid': undefined,\n 'aria-label': intl.formatMessage(messages.currencySelectorSelectCurrency),\n }}\n items={items}\n renderValue={({ code, label }) => {\n return (\n <SelectInputOptionContent\n title={code}\n note={label}\n icon={<Flag code={code} intrinsicSize={24} />}\n />\n );\n }}\n renderTrigger={() => (\n <SelectInputTriggerButton\n as={ButtonInput}\n // @ts-expect-error new (v2) ButtonProps\n addonStart={{\n type: 'avatar',\n value: [\n addons ? addons[0] : null,\n {\n ...(addons && addons.length > 1\n ? { ...addons[1] }\n : {\n asset: <Flag code={currency} />,\n }),\n },\n ].filter((avatar) => Boolean(avatar)),\n }}\n addonEnd={disabled ? undefined : { type: 'icon', value: <ChevronDown /> }}\n onClick={(event) => handleTriggerClick(event)}\n >\n {currency}\n </SelectInputTriggerButton>\n )}\n onChange={(newValue) => {\n onChange?.(newValue.code);\n }}\n onFilterChange={({ queryNormalized }) => {\n setSearchQuery(queryNormalized ?? '');\n if (queryNormalized) {\n onSearchChange?.({\n query: queryNormalized,\n resultCount: filterAndSortCurrenciesForQuery(allCurrencyOptions, queryNormalized)\n .length,\n });\n }\n }}\n />\n );\n};\n\nexport const ButtonInput = forwardRef(function ButtonInput(\n { children, ...rest }: React.PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>,\n ref: React.ForwardedRef<HTMLButtonElement | null>,\n) {\n return (\n <Button\n ref={ref}\n size=\"md\"\n v2\n className=\"wds-currency-selector\"\n priority=\"secondary-neutral\"\n {...rest}\n >\n {children}\n </Button>\n );\n});\n\nconst getCurrencySelectOption = (currency: CurrencyOption) => {\n return {\n type: 'option' as const,\n value: currency,\n filterMatchers: currency.keywords,\n };\n};\n\nconst getCurrencyGroup = (section: CurrencySection) => {\n return {\n type: 'group' as const,\n label: section.title,\n options: section.currencies.map(getCurrencySelectOption),\n };\n};\n\nconst getUniqueCurrencies = (options: CurrencyOptions) => {\n const allCurrencyOptions = options.flatMap((section) => section.currencies);\n const uniqueCurrencies = new Map<string, CurrencyOption>();\n\n allCurrencyOptions.forEach((currencyObj) => {\n uniqueCurrencies.set(currencyObj.code, currencyObj);\n });\n\n return Array.from(uniqueCurrencies.values());\n};\n\nconst filterAndSortCurrenciesForQuery = (\n currencies: CurrencyOption[],\n query: string,\n): CurrencyOption[] => {\n return (\n currencies\n .filter((currency) => {\n return (\n currency.code.toLowerCase().includes(query) ||\n (currency.label ?? '').toLowerCase().includes(query) ||\n currency.keywords?.some((keyword) => keyword.toLowerCase().includes(query))\n );\n })\n // prefer exact matches, then sort alphabetically by code\n .sort((a, b) => {\n const aCode = a.code.toLowerCase();\n const bCode = b.code.toLowerCase();\n if (aCode === query) {\n return -1;\n }\n if (bCode === query) {\n return 1;\n }\n return aCode.localeCompare(bCode);\n })\n );\n};\n"],"names":["CurrencySelector","id","currency","options","labelId","onChange","addons","onOpen","onSearchChange","intl","useIntl","allCurrencyOptions","useMemo","getUniqueCurrencies","activeCurrencyOption","find","option","code","disabled","length","currencies","searchQuery","setSearchQuery","useState","handleTriggerClick","event","triggerEl","currentTarget","getAttribute","items","filterAndSortCurrenciesForQuery","map","getCurrencySelectOption","getCurrencyGroup","_jsx","SelectInput","compareValues","value","filterable","filterPlaceholder","formatMessage","messages","currencySelectorSearchPlaceholder","UNSAFE_triggerButtonProps","undefined","currencySelectorSelectCurrency","renderValue","label","SelectInputOptionContent","title","note","icon","Flag","intrinsicSize","renderTrigger","SelectInputTriggerButton","as","ButtonInput","addonStart","type","asset","filter","avatar","Boolean","addonEnd","ChevronDown","onClick","children","newValue","onFilterChange","queryNormalized","query","resultCount","forwardRef","rest","ref","Button","size","v2","className","priority","filterMatchers","keywords","section","flatMap","uniqueCurrencies","Map","forEach","currencyObj","set","Array","from","values","toLowerCase","includes","some","keyword","sort","a","b","aCode","bCode","localeCompare"],"mappings":";;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F,QAAQ,EAAEa,IAAI,CAAEC,OAAO,IAAKA,OAAO,CAACH,WAAW,EAAE,CAACC,QAAQ,CAACvB,KAAK,CAAC,CAAC;EAE/E,CAAC;AACD;AAAA,GACC0B,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAI;IACb,MAAMC,KAAK,GAAGF,CAAC,CAACjF,IAAI,CAAC4E,WAAW,EAAE;IAClC,MAAMQ,KAAK,GAAGF,CAAC,CAAClF,IAAI,CAAC4E,WAAW,EAAE;IAClC,IAAIO,KAAK,KAAK7B,KAAK,EAAE;AACnB,MAAA,OAAO,EAAE;AACX,IAAA;IACA,IAAI8B,KAAK,KAAK9B,KAAK,EAAE;AACnB,MAAA,OAAO,CAAC;AACV,IAAA;AACA,IAAA,OAAO6B,KAAK,CAACE,aAAa,CAACD,KAAK,CAAC;AACnC,EAAA,CAAC,CAAC;AAER,CAAC;;;;;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import Button from '../button/Button.resolver.mjs';
|
|
2
|
+
import { SelectInput, SelectInputTriggerButton, SelectInputOptionContent } from '../inputs/SelectInput.mjs';
|
|
1
3
|
import { ChevronDown } from '@transferwise/icons';
|
|
2
4
|
import { Flag } from '@wise/art';
|
|
3
5
|
import { useMemo, useState, forwardRef } from 'react';
|
|
4
6
|
import { useIntl } from 'react-intl';
|
|
5
7
|
import messages from './MoneyInputField.messages.mjs';
|
|
6
8
|
import { jsx } from 'react/jsx-runtime';
|
|
7
|
-
import { SelectInput, SelectInputTriggerButton, SelectInputOptionContent } from '../inputs/SelectInput.mjs';
|
|
8
|
-
import Button from '../button/Button.resolver.mjs';
|
|
9
9
|
|
|
10
10
|
const CurrencySelector = ({
|
|
11
11
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencySelector.mjs","sources":["../../src/moneyInputField/CurrencySelector.tsx"],"sourcesContent":["import {\n AvatarLayoutProps,\n Button,\n SelectInput,\n SelectInputOptionContent,\n SelectInputTriggerButton,\n} from '..';\nimport { CurrencyType, Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { ChevronDown } from '@transferwise/icons';\nimport { Flag } from '@wise/art';\nimport {\n type ButtonHTMLAttributes,\n forwardRef,\n type MouseEventHandler,\n type ReactNode,\n useMemo,\n useState,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport messages from './MoneyInputField.messages';\n\nexport interface CurrencyOption {\n label?: string;\n code: string;\n keywords: string[] | undefined;\n}\n\nexport interface CurrencySection {\n title: string;\n currencies: CurrencyOption[];\n}\n\nexport type CurrencyOptions = CurrencySection[];\n\nexport type Props = {\n id: string;\n labelId: string;\n options?: CurrencyOptions;\n onChange?: (currency: CurrencyType) => void;\n onOpen?: () => void;\n addons?: AvatarLayoutProps['avatars'];\n onSearchChange?: (payload: { query: string; resultCount: number }) => void;\n} & Pick<MoneyInputFieldProps, 'currency'>;\n\nexport const CurrencySelector = ({\n id,\n currency,\n options = [],\n labelId,\n onChange,\n addons,\n onOpen,\n onSearchChange,\n}: Props) => {\n const intl = useIntl();\n\n const allCurrencyOptions = useMemo(() => getUniqueCurrencies(options), [options]);\n\n const activeCurrencyOption = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allCurrencyOptions.find((option) => option.code === currency)!;\n }, [currency, allCurrencyOptions]);\n\n const disabled =\n !onChange ||\n options.length === 0 ||\n (options.length === 1 && options[0].currencies.length <= 1);\n\n const [searchQuery, setSearchQuery] = useState<string>('');\n\n const handleTriggerClick: MouseEventHandler = (event) => {\n const triggerEl = event.currentTarget;\n if (triggerEl?.getAttribute('aria-expanded') === 'false') {\n onOpen?.();\n }\n };\n\n const items = searchQuery\n ? filterAndSortCurrenciesForQuery(allCurrencyOptions, searchQuery).map(getCurrencySelectOption)\n : options.map(getCurrencyGroup);\n\n return (\n <SelectInput\n compareValues=\"code\"\n disabled={disabled}\n id={id}\n value={activeCurrencyOption}\n filterable\n filterPlaceholder={intl.formatMessage(messages.currencySelectorSearchPlaceholder)}\n UNSAFE_triggerButtonProps={{\n id: undefined,\n 'aria-labelledby': undefined,\n 'aria-describedby': labelId,\n 'aria-invalid': undefined,\n 'aria-label': intl.formatMessage(messages.currencySelectorSelectCurrency),\n }}\n items={items}\n renderValue={({ code, label }) => {\n return (\n <SelectInputOptionContent\n title={code}\n note={label}\n icon={<Flag code={code} intrinsicSize={24} />}\n />\n );\n }}\n renderTrigger={() => (\n <SelectInputTriggerButton\n as={ButtonInput}\n // @ts-expect-error new (v2) ButtonProps\n addonStart={{\n type: 'avatar',\n value: [\n addons ? addons[0] : null,\n {\n ...(addons && addons.length > 1\n ? { ...addons[1] }\n : {\n asset: <Flag code={currency} />,\n }),\n },\n ].filter((avatar) => Boolean(avatar)),\n }}\n addonEnd={disabled ? undefined : { type: 'icon', value: <ChevronDown /> }}\n onClick={(event) => handleTriggerClick(event)}\n >\n {currency}\n </SelectInputTriggerButton>\n )}\n onChange={(newValue) => {\n onChange?.(newValue.code);\n }}\n onFilterChange={({ queryNormalized }) => {\n setSearchQuery(queryNormalized ?? '');\n if (queryNormalized) {\n onSearchChange?.({\n query: queryNormalized,\n resultCount: filterAndSortCurrenciesForQuery(allCurrencyOptions, queryNormalized)\n .length,\n });\n }\n }}\n />\n );\n};\n\nexport const ButtonInput = forwardRef(function ButtonInput(\n { children, ...rest }: React.PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>,\n ref: React.ForwardedRef<HTMLButtonElement | null>,\n) {\n return (\n <Button\n ref={ref}\n size=\"md\"\n v2\n className=\"wds-currency-selector\"\n priority=\"secondary-neutral\"\n {...rest}\n >\n {children}\n </Button>\n );\n});\n\nconst getCurrencySelectOption = (currency: CurrencyOption) => {\n return {\n type: 'option' as const,\n value: currency,\n filterMatchers: currency.keywords,\n };\n};\n\nconst getCurrencyGroup = (section: CurrencySection) => {\n return {\n type: 'group' as const,\n label: section.title,\n options: section.currencies.map(getCurrencySelectOption),\n };\n};\n\nconst getUniqueCurrencies = (options: CurrencyOptions) => {\n const allCurrencyOptions = options.flatMap((section) => section.currencies);\n const uniqueCurrencies = new Map<string, CurrencyOption>();\n\n allCurrencyOptions.forEach((currencyObj) => {\n uniqueCurrencies.set(currencyObj.code, currencyObj);\n });\n\n return Array.from(uniqueCurrencies.values());\n};\n\nconst filterAndSortCurrenciesForQuery = (\n currencies: CurrencyOption[],\n query: string,\n): CurrencyOption[] => {\n return (\n currencies\n .filter((currency) => {\n return (\n currency.code.toLowerCase().includes(query) ||\n (currency.label ?? '').toLowerCase().includes(query) ||\n currency.keywords?.some((keyword) => keyword.toLowerCase().includes(query))\n );\n })\n // prefer exact matches, then sort alphabetically by code\n .sort((a, b) => {\n const aCode = a.code.toLowerCase();\n const bCode = b.code.toLowerCase();\n if (aCode === query) {\n return -1;\n }\n if (bCode === query) {\n return 1;\n }\n return aCode.localeCompare(bCode);\n })\n );\n};\n"],"names":["CurrencySelector","id","currency","options","labelId","onChange","addons","onOpen","onSearchChange","intl","useIntl","allCurrencyOptions","useMemo","getUniqueCurrencies","activeCurrencyOption","find","option","code","disabled","length","currencies","searchQuery","setSearchQuery","useState","handleTriggerClick","event","triggerEl","currentTarget","getAttribute","items","filterAndSortCurrenciesForQuery","map","getCurrencySelectOption","getCurrencyGroup","_jsx","SelectInput","compareValues","value","filterable","filterPlaceholder","formatMessage","messages","currencySelectorSearchPlaceholder","UNSAFE_triggerButtonProps","undefined","currencySelectorSelectCurrency","renderValue","label","SelectInputOptionContent","title","note","icon","Flag","intrinsicSize","renderTrigger","SelectInputTriggerButton","as","ButtonInput","addonStart","type","asset","filter","avatar","Boolean","addonEnd","ChevronDown","onClick","children","newValue","onFilterChange","queryNormalized","query","resultCount","forwardRef","rest","ref","Button","size","v2","className","priority","filterMatchers","keywords","section","flatMap","uniqueCurrencies","Map","forEach","currencyObj","set","Array","from","values","toLowerCase","includes","some","keyword","sort","a","b","aCode","bCode","localeCompare"],"mappings":";;;;;;;;;AA6CO,MAAMA,gBAAgB,GAAGA,CAAC;EAC/B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EAAE,CAACC,QAAQ,CAACvB,KAAK,CAAC,CAAC;EAE/E,CAAC;AACD;AAAA,GACC0B,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAI;IACb,MAAMC,KAAK,GAAGF,CAAC,CAACjF,IAAI,CAAC4E,WAAW,EAAE;IAClC,MAAMQ,KAAK,GAAGF,CAAC,CAAClF,IAAI,CAAC4E,WAAW,EAAE;IAClC,IAAIO,KAAK,KAAK7B,KAAK,EAAE;AACnB,MAAA,OAAO,EAAE;AACX,IAAA;IACA,IAAI8B,KAAK,KAAK9B,KAAK,EAAE;AACnB,MAAA,OAAO,CAAC;AACV,IAAA;AACA,IAAA,OAAO6B,KAAK,CAACE,aAAa,CAACD,KAAK,CAAC;AACnC,EAAA,CAAC,CAAC;AAER,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"CurrencySelector.mjs","sources":["../../src/moneyInputField/CurrencySelector.tsx"],"sourcesContent":["import type { AvatarLayoutProps } from '../avatarLayout';\nimport Button from '../button';\nimport {\n SelectInput,\n SelectInputOptionContent,\n SelectInputTriggerButton,\n} from '../inputs/SelectInput';\nimport { CurrencyType, Props as MoneyInputFieldProps } from './MoneyInputField';\nimport { ChevronDown } from '@transferwise/icons';\nimport { Flag } from '@wise/art';\nimport {\n type ButtonHTMLAttributes,\n forwardRef,\n type MouseEventHandler,\n useMemo,\n useState,\n} from 'react';\nimport { useIntl } from 'react-intl';\n\nimport messages from './MoneyInputField.messages';\n\nexport interface CurrencyOption {\n label?: string;\n code: string;\n keywords: string[] | undefined;\n}\n\nexport interface CurrencySection {\n title: string;\n currencies: CurrencyOption[];\n}\n\nexport type CurrencyOptions = CurrencySection[];\n\nexport type Props = {\n id: string;\n labelId: string;\n options?: CurrencyOptions;\n onChange?: (currency: CurrencyType) => void;\n onOpen?: () => void;\n addons?: AvatarLayoutProps['avatars'];\n onSearchChange?: (payload: { query: string; resultCount: number }) => void;\n} & Pick<MoneyInputFieldProps, 'currency'>;\n\nexport const CurrencySelector = ({\n id,\n currency,\n options = [],\n labelId,\n onChange,\n addons,\n onOpen,\n onSearchChange,\n}: Props) => {\n const intl = useIntl();\n\n const allCurrencyOptions = useMemo(() => getUniqueCurrencies(options), [options]);\n\n const activeCurrencyOption = useMemo(() => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return allCurrencyOptions.find((option) => option.code === currency)!;\n }, [currency, allCurrencyOptions]);\n\n const disabled =\n !onChange ||\n options.length === 0 ||\n (options.length === 1 && options[0].currencies.length <= 1);\n\n const [searchQuery, setSearchQuery] = useState<string>('');\n\n const handleTriggerClick: MouseEventHandler = (event) => {\n const triggerEl = event.currentTarget;\n if (triggerEl?.getAttribute('aria-expanded') === 'false') {\n onOpen?.();\n }\n };\n\n const items = searchQuery\n ? filterAndSortCurrenciesForQuery(allCurrencyOptions, searchQuery).map(getCurrencySelectOption)\n : options.map(getCurrencyGroup);\n\n return (\n <SelectInput\n compareValues=\"code\"\n disabled={disabled}\n id={id}\n value={activeCurrencyOption}\n filterable\n filterPlaceholder={intl.formatMessage(messages.currencySelectorSearchPlaceholder)}\n UNSAFE_triggerButtonProps={{\n id: undefined,\n 'aria-labelledby': undefined,\n 'aria-describedby': labelId,\n 'aria-invalid': undefined,\n 'aria-label': intl.formatMessage(messages.currencySelectorSelectCurrency),\n }}\n items={items}\n renderValue={({ code, label }) => {\n return (\n <SelectInputOptionContent\n title={code}\n note={label}\n icon={<Flag code={code} intrinsicSize={24} />}\n />\n );\n }}\n renderTrigger={() => (\n <SelectInputTriggerButton\n as={ButtonInput}\n // @ts-expect-error new (v2) ButtonProps\n addonStart={{\n type: 'avatar',\n value: [\n addons ? addons[0] : null,\n {\n ...(addons && addons.length > 1\n ? { ...addons[1] }\n : {\n asset: <Flag code={currency} />,\n }),\n },\n ].filter((avatar) => Boolean(avatar)),\n }}\n addonEnd={disabled ? undefined : { type: 'icon', value: <ChevronDown /> }}\n onClick={(event) => handleTriggerClick(event)}\n >\n {currency}\n </SelectInputTriggerButton>\n )}\n onChange={(newValue) => {\n onChange?.(newValue.code);\n }}\n onFilterChange={({ queryNormalized }) => {\n setSearchQuery(queryNormalized ?? '');\n if (queryNormalized) {\n onSearchChange?.({\n query: queryNormalized,\n resultCount: filterAndSortCurrenciesForQuery(allCurrencyOptions, queryNormalized)\n .length,\n });\n }\n }}\n />\n );\n};\n\nexport const ButtonInput = forwardRef(function ButtonInput(\n { children, ...rest }: React.PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>,\n ref: React.ForwardedRef<HTMLButtonElement | null>,\n) {\n return (\n <Button\n ref={ref}\n size=\"md\"\n v2\n className=\"wds-currency-selector\"\n priority=\"secondary-neutral\"\n {...rest}\n >\n {children}\n </Button>\n );\n});\n\nconst getCurrencySelectOption = (currency: CurrencyOption) => {\n return {\n type: 'option' as const,\n value: currency,\n filterMatchers: currency.keywords,\n };\n};\n\nconst getCurrencyGroup = (section: CurrencySection) => {\n return {\n type: 'group' as const,\n label: section.title,\n options: section.currencies.map(getCurrencySelectOption),\n };\n};\n\nconst getUniqueCurrencies = (options: CurrencyOptions) => {\n const allCurrencyOptions = options.flatMap((section) => section.currencies);\n const uniqueCurrencies = new Map<string, CurrencyOption>();\n\n allCurrencyOptions.forEach((currencyObj) => {\n uniqueCurrencies.set(currencyObj.code, currencyObj);\n });\n\n return Array.from(uniqueCurrencies.values());\n};\n\nconst filterAndSortCurrenciesForQuery = (\n currencies: CurrencyOption[],\n query: string,\n): CurrencyOption[] => {\n return (\n currencies\n .filter((currency) => {\n return (\n currency.code.toLowerCase().includes(query) ||\n (currency.label ?? '').toLowerCase().includes(query) ||\n currency.keywords?.some((keyword) => keyword.toLowerCase().includes(query))\n );\n })\n // prefer exact matches, then sort alphabetically by code\n .sort((a, b) => {\n const aCode = a.code.toLowerCase();\n const bCode = b.code.toLowerCase();\n if (aCode === query) {\n return -1;\n }\n if (bCode === query) {\n return 1;\n }\n return aCode.localeCompare(bCode);\n })\n );\n};\n"],"names":["CurrencySelector","id","currency","options","labelId","onChange","addons","onOpen","onSearchChange","intl","useIntl","allCurrencyOptions","useMemo","getUniqueCurrencies","activeCurrencyOption","find","option","code","disabled","length","currencies","searchQuery","setSearchQuery","useState","handleTriggerClick","event","triggerEl","currentTarget","getAttribute","items","filterAndSortCurrenciesForQuery","map","getCurrencySelectOption","getCurrencyGroup","_jsx","SelectInput","compareValues","value","filterable","filterPlaceholder","formatMessage","messages","currencySelectorSearchPlaceholder","UNSAFE_triggerButtonProps","undefined","currencySelectorSelectCurrency","renderValue","label","SelectInputOptionContent","title","note","icon","Flag","intrinsicSize","renderTrigger","SelectInputTriggerButton","as","ButtonInput","addonStart","type","asset","filter","avatar","Boolean","addonEnd","ChevronDown","onClick","children","newValue","onFilterChange","queryNormalized","query","resultCount","forwardRef","rest","ref","Button","size","v2","className","priority","filterMatchers","keywords","section","flatMap","uniqueCurrencies","Map","forEach","currencyObj","set","Array","from","values","toLowerCase","includes","some","keyword","sort","a","b","aCode","bCode","localeCompare"],"mappings":";;;;;;;;;AA4CO,MAAMA,gBAAgB,GAAGA,CAAC;EAC/BC,EAAE;EACFC,QAAQ;AACRC,EAAAA,OAAO,GAAG,EAAE;EACZC,OAAO;EACPC,QAAQ;EACRC,MAAM;EACNC,MAAM;AACNC,EAAAA;AAAc,CACR,KAAI;AACV,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;AAEtB,EAAA,MAAMC,kBAAkB,GAAGC,OAAO,CAAC,MAAMC,mBAAmB,CAACV,OAAO,CAAC,EAAE,CAACA,OAAO,CAAC,CAAC;AAEjF,EAAA,MAAMW,oBAAoB,GAAGF,OAAO,CAAC,MAAK;AACxC;IACA,OAAOD,kBAAkB,CAACI,IAAI,CAAEC,MAAM,IAAKA,MAAM,CAACC,IAAI,KAAKf,QAAQ,CAAE;AACvE,EAAA,CAAC,EAAE,CAACA,QAAQ,EAAES,kBAAkB,CAAC,CAAC;EAElC,MAAMO,QAAQ,GACZ,CAACb,QAAQ,IACTF,OAAO,CAACgB,MAA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esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var Body = require('../body/Body.js');
|
|
6
|
+
var Label = require('../label/Label.js');
|
|
5
7
|
var clsx = require('clsx');
|
|
6
8
|
var framerMotion = require('framer-motion');
|
|
7
9
|
var React = require('react');
|
|
@@ -10,8 +12,6 @@ var AmountInput = require('./AmountInput.js');
|
|
|
10
12
|
var Chevron = require('./Chevron.js');
|
|
11
13
|
var InlinePrompt = require('../prompt/InlinePrompt/InlinePrompt.js');
|
|
12
14
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
|
-
var Label = require('../label/Label.js');
|
|
14
|
-
var Body = require('../body/Body.js');
|
|
15
15
|
|
|
16
16
|
function MoneyInputField({
|
|
17
17
|
label,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyInputField.js","sources":["../../src/moneyInputField/MoneyInputField.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MoneyInputField.js","sources":["../../src/moneyInputField/MoneyInputField.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 = (props: { id: string; labelId: string }) => ReactNode;\ntype CurrencySelectorType =\n | 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 };\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 MoneyInputField({\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 =\n typeof currencySelector === 'function' ? (\n currencySelector({ id: currencyId, labelId })\n ) : (\n <CurrencySelector\n id={currencyId}\n labelId={labelId}\n currency={currency}\n {...currencySelector}\n />\n );\n\n return (\n <div className={clsx('wds-money-input-field', 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-money-input-field-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-money-input-field-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} 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":["MoneyInputField","label","currency","currencySelector","options","amount","onAmountChange","className","inlinePrompt","showChevron","autoFocus","loading","onFocusChange","inputId","useId","labelId","customAlertId","currencyId","selector","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","message","Body"],"mappings":";;;;;;;;;;;;;;;AAwCc,SAAUA,eAAeA,CAAC;EACtCC,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,WAAK,EAAE;AACvB,EAAA,MAAMC,OAAO,GAAGD,WAAK,EAAE;AACvB,EAAA,MAAME,aAAa,GAAGF,WAAK,EAAE;AAC7B,EAAA,MAAMG,UAAU,GAAGH,WAAK,EAAE;EAE1B,MAAMI,QAAQ,GACZ,OAAOf,gBAAgB,KAAK,UAAU,GACpCA,gBAAgB,CAAC;AAAEgB,IAAAA,EAAE,EAAEF,UAAU;AAAEF,IAAAA;GAAS,CAAC,gBAE7CK,cAAA,CAACC,iCAAgB,EAAA;AACfF,IAAAA,EAAE,EAAEF,UAAW;AACfF,IAAAA,OAAO,EAAEA,OAAQ;AACjBb,IAAAA,QAAQ,EAAEA,QAAS;IAAA,GACfC;AAAgB,GAAC,CAExB;AAEH,EAAA,oBACEmB,eAAA,CAAA,KAAA,EAAA;AAAKf,IAAAA,SAAS,EAAEgB,SAAI,CAAC,uBAAuB,EAAEhB,SAAS,CA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AA,EAC7BhB,YAAY,iBACXY,cAAA,CAAA,KAAA,EAAA;QAAKb,SAAS,EAAEgB,SAAI,CAAC,4BAA4B,EAAEf,YAAY,IAAI,OAAO,CAAE;AAAAgB,QAAAA,QAAA,eAC1EJ,cAAA,CAACgB,mBAAM,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/BhB,YAAY,CAACqC,SAAS,gBACrBzB,cAAA,CAAC0B,yBAAY,EAAA;AAAC3B,YAAAA,EAAE,EAAEH,aAAc;YAAC6B,SAAS,EAAErC,YAAY,CAACqC,SAAU;YAAArB,QAAA,EAChEhB,YAAY,CAACuC;AAAO,WACT,CAAC,gBAEf3B,cAAA,CAAC4B,YAAI,EAAA;YAAAxB,QAAA,EAAEhB,YAAY,CAACuC;WAAc;AACnC,SAAA,EAfI/B,aAgBK;OACT;AACN,KACc,CACnB;AAAA,GAAK,CAAC;AAEV;;;;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import Body from '../body/Body.mjs';
|
|
2
|
+
import { Label as LabelNamespace } from '../label/Label.mjs';
|
|
1
3
|
import { clsx } from 'clsx';
|
|
2
4
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
3
5
|
import { useId } from 'react';
|
|
@@ -6,8 +8,6 @@ import { AmountInput } from './AmountInput.mjs';
|
|
|
6
8
|
import { Chevron } from './Chevron.mjs';
|
|
7
9
|
import { InlinePrompt } from '../prompt/InlinePrompt/InlinePrompt.mjs';
|
|
8
10
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
9
|
-
import { Label as LabelNamespace } from '../label/Label.mjs';
|
|
10
|
-
import Body from '../body/Body.mjs';
|
|
11
11
|
|
|
12
12
|
function MoneyInputField({
|
|
13
13
|
label,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyInputField.mjs","sources":["../../src/moneyInputField/MoneyInputField.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"MoneyInputField.mjs","sources":["../../src/moneyInputField/MoneyInputField.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 = (props: { id: string; labelId: string }) => ReactNode;\ntype CurrencySelectorType =\n | 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 };\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 MoneyInputField({\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 =\n typeof currencySelector === 'function' ? (\n currencySelector({ id: currencyId, labelId })\n ) : (\n <CurrencySelector\n id={currencyId}\n labelId={labelId}\n currency={currency}\n {...currencySelector}\n />\n );\n\n return (\n <div className={clsx('wds-money-input-field', 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-money-input-field-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-money-input-field-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} 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":["MoneyInputField","label","currency","currencySelector","options","amount","onAmountChange","className","inlinePrompt","showChevron","autoFocus","loading","onFocusChange","inputId","useId","labelId","customAlertId","currencyId","selector","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","message","Body"],"mappings":";;;;;;;;;;;AAwCc,SAAUA,eAAeA,CAAC;EACtCC,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;EAE1B,MAAMI,QAAQ,GACZ,OAAOf,gBAAgB,KAAK,UAAU,GACpCA,gBAAgB,CAAC;AAAEgB,IAAAA,EAAE,EAAEF,UAAU;AAAEF,IAAAA;GAAS,CAAC,gBAE7CK,GAAA,CAACC,gBAAgB,EAAA;AACfF,IAAAA,EAAE,EAAEF,UAAW;AACfF,IAAAA,OAAO,EAAEA,OAAQ;AACjBb,IAAAA,QAAQ,EAAEA,QAAS;IAAA,GACfC;AAAgB,GAAC,CAExB;AAEH,EAAA,oBACEmB,IAAA,CAAA,KAAA,EAAA;AAAKf,IAAAA,SAAS,EAAEgB,IAAI,CAAC,uBAAuB,EAAEhB,SAAS,CAAE;IAAAiB,QAAA,EAAA,cACvDJ,GAAA,CAACK,cAAK,EAAA;AAACN,MAAAA,EAAE,EAAEJ,OAAQ;AAACW,MAAAA,OAAO,EAAEb,OAAQ;AAACN,MAAAA,SAAS,EAAEgB,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAE;AAAAC,MAAAA,QAAA,EAClFvB;KACI,CACP,eAAAqB,IAA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AC,oBAAoB,EAAE,SAAS,CAAC,CAAC;AAE1C,eAAO,MAAM,WAAW,GAAI,uFASzB,KAAK,
|
|
1
|
+
{"version":3,"file":"AmountInput.d.ts","sourceRoot":"","sources":["../../../src/moneyInputField/AmountInput.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAelE,KAAK,KAAK,GAAG;IACX,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1C,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,GAAG,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;AAE1C,eAAO,MAAM,WAAW,GAAI,uFASzB,KAAK,gCA2SP,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AvatarLayoutProps } from '
|
|
1
|
+
import type { AvatarLayoutProps } from '../avatarLayout';
|
|
2
2
|
import { CurrencyType, Props as MoneyInputFieldProps } from './MoneyInputField';
|
|
3
|
-
import { type ButtonHTMLAttributes
|
|
3
|
+
import { type ButtonHTMLAttributes } from 'react';
|
|
4
4
|
export interface CurrencyOption {
|
|
5
5
|
label?: string;
|
|
6
6
|
code: string;
|
|
@@ -25,6 +25,6 @@ export type Props = {
|
|
|
25
25
|
} & Pick<MoneyInputFieldProps, 'currency'>;
|
|
26
26
|
export declare const CurrencySelector: ({ id, currency, options, labelId, onChange, addons, onOpen, onSearchChange, }: Props) => import("react").JSX.Element;
|
|
27
27
|
export declare const ButtonInput: import("react").ForwardRefExoticComponent<ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
28
|
-
children?: ReactNode | undefined;
|
|
28
|
+
children?: import("react").ReactNode | undefined;
|
|
29
29
|
} & import("react").RefAttributes<HTMLButtonElement | null>>;
|
|
30
30
|
//# sourceMappingURL=CurrencySelector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrencySelector.d.ts","sourceRoot":"","sources":["../../../src/moneyInputField/CurrencySelector.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"CurrencySelector.d.ts","sourceRoot":"","sources":["../../../src/moneyInputField/CurrencySelector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAOzD,OAAO,EAAE,YAAY,EAAE,KAAK,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGhF,OAAO,EACL,KAAK,oBAAoB,EAK1B,MAAM,OAAO,CAAC;AAKf,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,cAAc,EAAE,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,GAAG,eAAe,EAAE,CAAC;AAEhD,MAAM,MAAM,KAAK,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IAC5C,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC5E,GAAG,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;AAE3C,eAAO,MAAM,gBAAgB,GAAI,+EAS9B,KAAK,gCA2FP,CAAC;AAEF,eAAO,MAAM,WAAW;;4DAgBtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyInputField.d.ts","sourceRoot":"","sources":["../../../src/moneyInputField/MoneyInputField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MoneyInputField.d.ts","sourceRoot":"","sources":["../../../src/moneyInputField/MoneyInputField.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAE,KAAK,KAAK,IAAI,qBAAqB,EAAoB,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,KAAK,UAAU,GAAG,MAAM,GAAG,IAAI,CAAC;AAChC,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,KAAK,mCAAmC,GAAG,IAAI,CAC7C,qBAAqB,EACrB,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,gBAAgB,CAChE,CAAC;AACF,KAAK,kCAAkC,GAAG,CAAC,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,KAAK,SAAS,CAAC;AAChG,KAAK,oBAAoB,GACrB,mCAAmC,GACnC,kCAAkC,CAAC;AAEvC,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IACxC,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC;IACvB,YAAY,CAAC,EAAE;QACb,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAC3C,OAAO,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;KACxC,CAAC;IACF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C,GAAG,WAAW,CAAC;AAEhB,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,KAAK,EACL,QAAQ,EACR,gBAAyE,EACzE,MAAM,EACN,cAAc,EACd,SAAS,EACT,YAAY,EACZ,WAAW,EACX,SAAS,EACT,OAAO,EACP,aAAa,GACd,EAAE,KAAK,+BAuEP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-29f2750",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -83,9 +83,10 @@
|
|
|
83
83
|
"storybook": "^9.1.3",
|
|
84
84
|
"storybook-addon-tag-badges": "^2.0.2",
|
|
85
85
|
"storybook-addon-test-codegen": "^2.0.1",
|
|
86
|
+
"framer-motion": "^12.15.0",
|
|
86
87
|
"@transferwise/less-config": "3.1.2",
|
|
87
|
-
"@transferwise/neptune-css": "14.25.0",
|
|
88
88
|
"@wise/components-theming": "1.7.0",
|
|
89
|
+
"@transferwise/neptune-css": "14.25.0",
|
|
89
90
|
"@wise/wds-configs": "0.0.0"
|
|
90
91
|
},
|
|
91
92
|
"peerDependencies": {
|
|
@@ -95,13 +96,18 @@
|
|
|
95
96
|
"@wise/components-theming": "^1.6.2",
|
|
96
97
|
"react": ">=18",
|
|
97
98
|
"react-dom": ">=18",
|
|
98
|
-
"react-intl": "^5.10.0 || ^6 || ^7"
|
|
99
|
+
"react-intl": "^5.10.0 || ^6 || ^7",
|
|
100
|
+
"framer-motion": "^12.15.0"
|
|
101
|
+
},
|
|
102
|
+
"peerDependenciesMeta": {
|
|
103
|
+
"framer-motion": {
|
|
104
|
+
"optional": true
|
|
105
|
+
}
|
|
99
106
|
},
|
|
100
107
|
"dependencies": {
|
|
101
108
|
"@babel/runtime": "^7.28.3",
|
|
102
109
|
"@floating-ui/react": "^0.27.16",
|
|
103
110
|
"@headlessui/react": "^1.7.19",
|
|
104
|
-
"framer-motion": "^12.15.0",
|
|
105
111
|
"@popperjs/core": "^2.11.8",
|
|
106
112
|
"@react-aria/focus": "^3.21.0",
|
|
107
113
|
"@react-aria/overlays": "^3.28.0",
|
|
@@ -288,13 +288,12 @@ export const AmountInput = ({
|
|
|
288
288
|
loading,
|
|
289
289
|
});
|
|
290
290
|
|
|
291
|
-
const getInputMask = () => {
|
|
292
|
-
return '';
|
|
293
|
-
};
|
|
294
|
-
|
|
295
291
|
return (
|
|
296
292
|
<div className="wds-amount-input-container">
|
|
297
|
-
<div
|
|
293
|
+
<div
|
|
294
|
+
className={clsx('wds-amount-input-input-container', 'np-text-display-large')}
|
|
295
|
+
style={style}
|
|
296
|
+
>
|
|
298
297
|
<input
|
|
299
298
|
ref={ref}
|
|
300
299
|
className="wds-amount-input-input"
|
|
@@ -336,7 +335,6 @@ export const AmountInput = ({
|
|
|
336
335
|
)}
|
|
337
336
|
</AnimatePresence>
|
|
338
337
|
</div>
|
|
339
|
-
{getInputMask()}
|
|
340
338
|
</div>
|
|
341
339
|
);
|
|
342
340
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { AvatarLayoutProps } from '../avatarLayout';
|
|
2
|
+
import Button from '../button';
|
|
1
3
|
import {
|
|
2
|
-
AvatarLayoutProps,
|
|
3
|
-
Button,
|
|
4
4
|
SelectInput,
|
|
5
5
|
SelectInputOptionContent,
|
|
6
6
|
SelectInputTriggerButton,
|
|
7
|
-
} from '
|
|
7
|
+
} from '../inputs/SelectInput';
|
|
8
8
|
import { CurrencyType, Props as MoneyInputFieldProps } from './MoneyInputField';
|
|
9
9
|
import { ChevronDown } from '@transferwise/icons';
|
|
10
10
|
import { Flag } from '@wise/art';
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
type ButtonHTMLAttributes,
|
|
13
13
|
forwardRef,
|
|
14
14
|
type MouseEventHandler,
|
|
15
|
-
type ReactNode,
|
|
16
15
|
useMemo,
|
|
17
16
|
useState,
|
|
18
17
|
} from 'react';
|