@transferwise/components 0.0.0-experimental-89ae24f → 0.0.0-experimental-c42d7d6
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/i18n/en.json +2 -0
- package/build/i18n/en.json.js +2 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +2 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/index.mjs +1 -0
- package/build/index.mjs.map +1 -1
- package/build/main.css +58 -0
- package/build/moneyInputField/AmountInput.js +281 -0
- package/build/moneyInputField/AmountInput.js.map +1 -0
- package/build/moneyInputField/AmountInput.mjs +279 -0
- package/build/moneyInputField/AmountInput.mjs.map +1 -0
- package/build/moneyInputField/AnimatedNumber.js +50 -0
- package/build/moneyInputField/AnimatedNumber.js.map +1 -0
- package/build/moneyInputField/AnimatedNumber.mjs +48 -0
- package/build/moneyInputField/AnimatedNumber.mjs.map +1 -0
- package/build/moneyInputField/Chevron.js +33 -0
- package/build/moneyInputField/Chevron.js.map +1 -0
- package/build/moneyInputField/Chevron.mjs +31 -0
- package/build/moneyInputField/Chevron.mjs.map +1 -0
- package/build/moneyInputField/CurrencySelector.js +160 -0
- package/build/moneyInputField/CurrencySelector.js.map +1 -0
- package/build/moneyInputField/CurrencySelector.mjs +157 -0
- package/build/moneyInputField/CurrencySelector.mjs.map +1 -0
- package/build/moneyInputField/MoneyInputField.js +113 -0
- package/build/moneyInputField/MoneyInputField.js.map +1 -0
- package/build/moneyInputField/MoneyInputField.messages.js +17 -0
- package/build/moneyInputField/MoneyInputField.messages.js.map +1 -0
- package/build/moneyInputField/MoneyInputField.messages.mjs +13 -0
- package/build/moneyInputField/MoneyInputField.messages.mjs.map +1 -0
- package/build/moneyInputField/MoneyInputField.mjs +109 -0
- package/build/moneyInputField/MoneyInputField.mjs.map +1 -0
- package/build/moneyInputField/useFocus.js +37 -0
- package/build/moneyInputField/useFocus.js.map +1 -0
- package/build/moneyInputField/useFocus.mjs +35 -0
- package/build/moneyInputField/useFocus.mjs.map +1 -0
- package/build/moneyInputField/useInputStyle.js +71 -0
- package/build/moneyInputField/useInputStyle.js.map +1 -0
- package/build/moneyInputField/useInputStyle.mjs +69 -0
- package/build/moneyInputField/useInputStyle.mjs.map +1 -0
- package/build/moneyInputField/utils.js +87 -0
- package/build/moneyInputField/utils.js.map +1 -0
- package/build/moneyInputField/utils.mjs +78 -0
- package/build/moneyInputField/utils.mjs.map +1 -0
- package/build/styles/main.css +58 -0
- package/build/styles/moneyInputField/AmountInput.css +32 -0
- package/build/styles/moneyInputField/Chevron.css +12 -0
- package/build/styles/moneyInputField/CurrencySelector.css +6 -0
- package/build/styles/moneyInputField/MoneyInputField.css +58 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/moneyInputField/AmountInput.d.ts +13 -0
- package/build/types/moneyInputField/AmountInput.d.ts.map +1 -0
- package/build/types/moneyInputField/AnimatedNumber.d.ts +9 -0
- package/build/types/moneyInputField/AnimatedNumber.d.ts.map +1 -0
- package/build/types/moneyInputField/Chevron.d.ts +6 -0
- package/build/types/moneyInputField/Chevron.d.ts.map +1 -0
- package/build/types/moneyInputField/CurrencySelector.d.ts +30 -0
- package/build/types/moneyInputField/CurrencySelector.d.ts.map +1 -0
- package/build/types/moneyInputField/MoneyInputField.d.ts +30 -0
- package/build/types/moneyInputField/MoneyInputField.d.ts.map +1 -0
- package/build/types/moneyInputField/MoneyInputField.messages.d.ts +12 -0
- package/build/types/moneyInputField/MoneyInputField.messages.d.ts.map +1 -0
- package/build/types/moneyInputField/index.d.ts +3 -0
- package/build/types/moneyInputField/index.d.ts.map +1 -0
- package/build/types/moneyInputField/useFocus.d.ts +7 -0
- package/build/types/moneyInputField/useFocus.d.ts.map +1 -0
- package/build/types/moneyInputField/useInputStyle.d.ts +10 -0
- package/build/types/moneyInputField/useInputStyle.d.ts.map +1 -0
- package/build/types/moneyInputField/useSelectionRange.d.ts +10 -0
- package/build/types/moneyInputField/useSelectionRange.d.ts.map +1 -0
- package/build/types/moneyInputField/utils.d.ts +22 -0
- package/build/types/moneyInputField/utils.d.ts.map +1 -0
- package/build/types/test-utils/index.d.ts +4 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +9 -2
- package/src/i18n/en.json +2 -0
- package/src/index.ts +2 -0
- package/src/main.css +58 -0
- package/src/main.less +1 -0
- package/src/moneyInputField/AmountInput.css +32 -0
- package/src/moneyInputField/AmountInput.less +43 -0
- package/src/moneyInputField/AmountInput.tsx +353 -0
- package/src/moneyInputField/AnimatedNumber.tsx +40 -0
- package/src/moneyInputField/Chevron.css +12 -0
- package/src/moneyInputField/Chevron.less +13 -0
- package/src/moneyInputField/Chevron.tsx +35 -0
- package/src/moneyInputField/CurrencySelector.css +6 -0
- package/src/moneyInputField/CurrencySelector.less +7 -0
- package/src/moneyInputField/CurrencySelector.tsx +218 -0
- package/src/moneyInputField/MoneyInputField.css +58 -0
- package/src/moneyInputField/MoneyInputField.less +13 -0
- package/src/moneyInputField/MoneyInputField.messages.ts +13 -0
- package/src/moneyInputField/MoneyInputField.story.tsx +188 -0
- package/src/moneyInputField/MoneyInputField.tsx +124 -0
- package/src/moneyInputField/index.ts +2 -0
- package/src/moneyInputField/useFocus.ts +35 -0
- package/src/moneyInputField/useInputStyle.ts +85 -0
- package/src/moneyInputField/useSelectionRange.ts +23 -0
- package/src/moneyInputField/utils.spec.ts +114 -0
- package/src/moneyInputField/utils.ts +116 -0
- package/src/ssr.spec.tsx +1 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Button_resolver = require('../button/Button.resolver.js');
|
|
4
|
+
var SelectInput = require('../inputs/SelectInput.js');
|
|
5
|
+
var icons = require('@transferwise/icons');
|
|
6
|
+
var art = require('@wise/art');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var reactIntl = require('react-intl');
|
|
9
|
+
var MoneyInputField_messages = require('./MoneyInputField.messages.js');
|
|
10
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
11
|
+
|
|
12
|
+
const CurrencySelector = ({
|
|
13
|
+
id,
|
|
14
|
+
currency,
|
|
15
|
+
options = [],
|
|
16
|
+
labelId,
|
|
17
|
+
onChange,
|
|
18
|
+
addons,
|
|
19
|
+
onOpen,
|
|
20
|
+
onSearchChange
|
|
21
|
+
}) => {
|
|
22
|
+
const intl = reactIntl.useIntl();
|
|
23
|
+
const allCurrencyOptions = React.useMemo(() => getUniqueCurrencies(options), [options]);
|
|
24
|
+
const activeCurrencyOption = React.useMemo(() => {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
|
+
return allCurrencyOptions.find(option => option.code === currency);
|
|
27
|
+
}, [currency, allCurrencyOptions]);
|
|
28
|
+
const disabled = !onChange || options.length === 0 || options.length === 1 && options[0].currencies.length <= 1;
|
|
29
|
+
const [searchQuery, setSearchQuery] = React.useState('');
|
|
30
|
+
const handleTriggerClick = event => {
|
|
31
|
+
const triggerEl = event.currentTarget;
|
|
32
|
+
if (triggerEl?.getAttribute('aria-expanded') === 'false') {
|
|
33
|
+
onOpen?.();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const items = searchQuery ? filterAndSortCurrenciesForQuery(allCurrencyOptions, searchQuery).map(getCurrencySelectOption) : options.map(getCurrencyGroup);
|
|
37
|
+
return /*#__PURE__*/jsxRuntime.jsx(SelectInput.SelectInput, {
|
|
38
|
+
compareValues: "code",
|
|
39
|
+
disabled: disabled,
|
|
40
|
+
id: id,
|
|
41
|
+
value: activeCurrencyOption,
|
|
42
|
+
filterable: true,
|
|
43
|
+
filterPlaceholder: intl.formatMessage(MoneyInputField_messages.default.currencySelectorSearchPlaceholder),
|
|
44
|
+
UNSAFE_triggerButtonProps: {
|
|
45
|
+
id: undefined,
|
|
46
|
+
'aria-labelledby': undefined,
|
|
47
|
+
'aria-describedby': labelId,
|
|
48
|
+
'aria-invalid': undefined,
|
|
49
|
+
'aria-label': intl.formatMessage(MoneyInputField_messages.default.currencySelectorSelectCurrency)
|
|
50
|
+
},
|
|
51
|
+
items: items,
|
|
52
|
+
renderValue: ({
|
|
53
|
+
code,
|
|
54
|
+
label
|
|
55
|
+
}) => {
|
|
56
|
+
return /*#__PURE__*/jsxRuntime.jsx(SelectInput.SelectInputOptionContent, {
|
|
57
|
+
title: code,
|
|
58
|
+
note: label,
|
|
59
|
+
icon: /*#__PURE__*/jsxRuntime.jsx(art.Flag, {
|
|
60
|
+
code: code,
|
|
61
|
+
intrinsicSize: 24
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
renderTrigger: () => /*#__PURE__*/jsxRuntime.jsx(SelectInput.SelectInputTriggerButton, {
|
|
66
|
+
as: ButtonInput
|
|
67
|
+
// @ts-expect-error new (v2) ButtonProps
|
|
68
|
+
,
|
|
69
|
+
addonStart: {
|
|
70
|
+
type: 'avatar',
|
|
71
|
+
value: [addons ? addons[0] : null, {
|
|
72
|
+
...(addons && addons.length > 1 ? {
|
|
73
|
+
...addons[1]
|
|
74
|
+
} : {
|
|
75
|
+
asset: /*#__PURE__*/jsxRuntime.jsx(art.Flag, {
|
|
76
|
+
code: currency
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
}].filter(avatar => Boolean(avatar))
|
|
80
|
+
},
|
|
81
|
+
addonEnd: disabled ? undefined : {
|
|
82
|
+
type: 'icon',
|
|
83
|
+
value: /*#__PURE__*/jsxRuntime.jsx(icons.ChevronDown, {})
|
|
84
|
+
},
|
|
85
|
+
onClick: event => handleTriggerClick(event),
|
|
86
|
+
children: currency
|
|
87
|
+
}),
|
|
88
|
+
onChange: newValue => {
|
|
89
|
+
onChange?.(newValue.code);
|
|
90
|
+
},
|
|
91
|
+
onFilterChange: ({
|
|
92
|
+
queryNormalized
|
|
93
|
+
}) => {
|
|
94
|
+
setSearchQuery(queryNormalized ?? '');
|
|
95
|
+
if (queryNormalized) {
|
|
96
|
+
onSearchChange?.({
|
|
97
|
+
query: queryNormalized,
|
|
98
|
+
resultCount: filterAndSortCurrenciesForQuery(allCurrencyOptions, queryNormalized).length
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const ButtonInput = /*#__PURE__*/React.forwardRef(function ButtonInput({
|
|
105
|
+
children,
|
|
106
|
+
...rest
|
|
107
|
+
}, ref) {
|
|
108
|
+
return /*#__PURE__*/jsxRuntime.jsx(Button_resolver.default, {
|
|
109
|
+
ref: ref,
|
|
110
|
+
size: "md",
|
|
111
|
+
v2: true,
|
|
112
|
+
className: "wds-currency-selector",
|
|
113
|
+
priority: "secondary-neutral",
|
|
114
|
+
...rest,
|
|
115
|
+
children: children
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
const getCurrencySelectOption = currency => {
|
|
119
|
+
return {
|
|
120
|
+
type: 'option',
|
|
121
|
+
value: currency,
|
|
122
|
+
filterMatchers: currency.keywords
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const getCurrencyGroup = section => {
|
|
126
|
+
return {
|
|
127
|
+
type: 'group',
|
|
128
|
+
label: section.title,
|
|
129
|
+
options: section.currencies.map(getCurrencySelectOption)
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const getUniqueCurrencies = options => {
|
|
133
|
+
const allCurrencyOptions = options.flatMap(section => section.currencies);
|
|
134
|
+
const uniqueCurrencies = new Map();
|
|
135
|
+
allCurrencyOptions.forEach(currencyObj => {
|
|
136
|
+
uniqueCurrencies.set(currencyObj.code, currencyObj);
|
|
137
|
+
});
|
|
138
|
+
return Array.from(uniqueCurrencies.values());
|
|
139
|
+
};
|
|
140
|
+
const filterAndSortCurrenciesForQuery = (currencies, query) => {
|
|
141
|
+
return currencies.filter(currency => {
|
|
142
|
+
return currency.code.toLowerCase().includes(query) || (currency.label ?? '').toLowerCase().includes(query) || currency.keywords?.some(keyword => keyword.toLowerCase().includes(query));
|
|
143
|
+
})
|
|
144
|
+
// prefer exact matches, then sort alphabetically by code
|
|
145
|
+
.sort((a, b) => {
|
|
146
|
+
const aCode = a.code.toLowerCase();
|
|
147
|
+
const bCode = b.code.toLowerCase();
|
|
148
|
+
if (aCode === query) {
|
|
149
|
+
return -1;
|
|
150
|
+
}
|
|
151
|
+
if (bCode === query) {
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
return aCode.localeCompare(bCode);
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
exports.ButtonInput = ButtonInput;
|
|
159
|
+
exports.CurrencySelector = CurrencySelector;
|
|
160
|
+
//# sourceMappingURL=CurrencySelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":";;;;;;;;;;;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,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,C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button.resolver.mjs';
|
|
2
|
+
import { SelectInput, SelectInputTriggerButton, SelectInputOptionContent } from '../inputs/SelectInput.mjs';
|
|
3
|
+
import { ChevronDown } from '@transferwise/icons';
|
|
4
|
+
import { Flag } from '@wise/art';
|
|
5
|
+
import { useMemo, useState, forwardRef } from 'react';
|
|
6
|
+
import { useIntl } from 'react-intl';
|
|
7
|
+
import messages from './MoneyInputField.messages.mjs';
|
|
8
|
+
import { jsx } from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
const CurrencySelector = ({
|
|
11
|
+
id,
|
|
12
|
+
currency,
|
|
13
|
+
options = [],
|
|
14
|
+
labelId,
|
|
15
|
+
onChange,
|
|
16
|
+
addons,
|
|
17
|
+
onOpen,
|
|
18
|
+
onSearchChange
|
|
19
|
+
}) => {
|
|
20
|
+
const intl = useIntl();
|
|
21
|
+
const allCurrencyOptions = useMemo(() => getUniqueCurrencies(options), [options]);
|
|
22
|
+
const activeCurrencyOption = useMemo(() => {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
24
|
+
return allCurrencyOptions.find(option => option.code === currency);
|
|
25
|
+
}, [currency, allCurrencyOptions]);
|
|
26
|
+
const disabled = !onChange || options.length === 0 || options.length === 1 && options[0].currencies.length <= 1;
|
|
27
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
28
|
+
const handleTriggerClick = event => {
|
|
29
|
+
const triggerEl = event.currentTarget;
|
|
30
|
+
if (triggerEl?.getAttribute('aria-expanded') === 'false') {
|
|
31
|
+
onOpen?.();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const items = searchQuery ? filterAndSortCurrenciesForQuery(allCurrencyOptions, searchQuery).map(getCurrencySelectOption) : options.map(getCurrencyGroup);
|
|
35
|
+
return /*#__PURE__*/jsx(SelectInput, {
|
|
36
|
+
compareValues: "code",
|
|
37
|
+
disabled: disabled,
|
|
38
|
+
id: id,
|
|
39
|
+
value: activeCurrencyOption,
|
|
40
|
+
filterable: true,
|
|
41
|
+
filterPlaceholder: intl.formatMessage(messages.currencySelectorSearchPlaceholder),
|
|
42
|
+
UNSAFE_triggerButtonProps: {
|
|
43
|
+
id: undefined,
|
|
44
|
+
'aria-labelledby': undefined,
|
|
45
|
+
'aria-describedby': labelId,
|
|
46
|
+
'aria-invalid': undefined,
|
|
47
|
+
'aria-label': intl.formatMessage(messages.currencySelectorSelectCurrency)
|
|
48
|
+
},
|
|
49
|
+
items: items,
|
|
50
|
+
renderValue: ({
|
|
51
|
+
code,
|
|
52
|
+
label
|
|
53
|
+
}) => {
|
|
54
|
+
return /*#__PURE__*/jsx(SelectInputOptionContent, {
|
|
55
|
+
title: code,
|
|
56
|
+
note: label,
|
|
57
|
+
icon: /*#__PURE__*/jsx(Flag, {
|
|
58
|
+
code: code,
|
|
59
|
+
intrinsicSize: 24
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
renderTrigger: () => /*#__PURE__*/jsx(SelectInputTriggerButton, {
|
|
64
|
+
as: ButtonInput
|
|
65
|
+
// @ts-expect-error new (v2) ButtonProps
|
|
66
|
+
,
|
|
67
|
+
addonStart: {
|
|
68
|
+
type: 'avatar',
|
|
69
|
+
value: [addons ? addons[0] : null, {
|
|
70
|
+
...(addons && addons.length > 1 ? {
|
|
71
|
+
...addons[1]
|
|
72
|
+
} : {
|
|
73
|
+
asset: /*#__PURE__*/jsx(Flag, {
|
|
74
|
+
code: currency
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
}].filter(avatar => Boolean(avatar))
|
|
78
|
+
},
|
|
79
|
+
addonEnd: disabled ? undefined : {
|
|
80
|
+
type: 'icon',
|
|
81
|
+
value: /*#__PURE__*/jsx(ChevronDown, {})
|
|
82
|
+
},
|
|
83
|
+
onClick: event => handleTriggerClick(event),
|
|
84
|
+
children: currency
|
|
85
|
+
}),
|
|
86
|
+
onChange: newValue => {
|
|
87
|
+
onChange?.(newValue.code);
|
|
88
|
+
},
|
|
89
|
+
onFilterChange: ({
|
|
90
|
+
queryNormalized
|
|
91
|
+
}) => {
|
|
92
|
+
setSearchQuery(queryNormalized ?? '');
|
|
93
|
+
if (queryNormalized) {
|
|
94
|
+
onSearchChange?.({
|
|
95
|
+
query: queryNormalized,
|
|
96
|
+
resultCount: filterAndSortCurrenciesForQuery(allCurrencyOptions, queryNormalized).length
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const ButtonInput = /*#__PURE__*/forwardRef(function ButtonInput({
|
|
103
|
+
children,
|
|
104
|
+
...rest
|
|
105
|
+
}, ref) {
|
|
106
|
+
return /*#__PURE__*/jsx(Button, {
|
|
107
|
+
ref: ref,
|
|
108
|
+
size: "md",
|
|
109
|
+
v2: true,
|
|
110
|
+
className: "wds-currency-selector",
|
|
111
|
+
priority: "secondary-neutral",
|
|
112
|
+
...rest,
|
|
113
|
+
children: children
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
const getCurrencySelectOption = currency => {
|
|
117
|
+
return {
|
|
118
|
+
type: 'option',
|
|
119
|
+
value: currency,
|
|
120
|
+
filterMatchers: currency.keywords
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
const getCurrencyGroup = section => {
|
|
124
|
+
return {
|
|
125
|
+
type: 'group',
|
|
126
|
+
label: section.title,
|
|
127
|
+
options: section.currencies.map(getCurrencySelectOption)
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const getUniqueCurrencies = options => {
|
|
131
|
+
const allCurrencyOptions = options.flatMap(section => section.currencies);
|
|
132
|
+
const uniqueCurrencies = new Map();
|
|
133
|
+
allCurrencyOptions.forEach(currencyObj => {
|
|
134
|
+
uniqueCurrencies.set(currencyObj.code, currencyObj);
|
|
135
|
+
});
|
|
136
|
+
return Array.from(uniqueCurrencies.values());
|
|
137
|
+
};
|
|
138
|
+
const filterAndSortCurrenciesForQuery = (currencies, query) => {
|
|
139
|
+
return currencies.filter(currency => {
|
|
140
|
+
return currency.code.toLowerCase().includes(query) || (currency.label ?? '').toLowerCase().includes(query) || currency.keywords?.some(keyword => keyword.toLowerCase().includes(query));
|
|
141
|
+
})
|
|
142
|
+
// prefer exact matches, then sort alphabetically by code
|
|
143
|
+
.sort((a, b) => {
|
|
144
|
+
const aCode = a.code.toLowerCase();
|
|
145
|
+
const bCode = b.code.toLowerCase();
|
|
146
|
+
if (aCode === query) {
|
|
147
|
+
return -1;
|
|
148
|
+
}
|
|
149
|
+
if (bCode === query) {
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
return aCode.localeCompare(bCode);
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export { ButtonInput, CurrencySelector };
|
|
157
|
+
//# sourceMappingURL=CurrencySelector.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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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|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Body = require('../body/Body.js');
|
|
6
|
+
var Label = require('../label/Label.js');
|
|
7
|
+
var clsx = require('clsx');
|
|
8
|
+
var framerMotion = require('framer-motion');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var CurrencySelector = require('./CurrencySelector.js');
|
|
11
|
+
var AmountInput = require('./AmountInput.js');
|
|
12
|
+
var Chevron = require('./Chevron.js');
|
|
13
|
+
var InlinePrompt = require('../prompt/InlinePrompt/InlinePrompt.js');
|
|
14
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
15
|
+
|
|
16
|
+
function MoneyInputField({
|
|
17
|
+
label,
|
|
18
|
+
currency,
|
|
19
|
+
currencySelector = {
|
|
20
|
+
options: []
|
|
21
|
+
},
|
|
22
|
+
amount,
|
|
23
|
+
onAmountChange,
|
|
24
|
+
className,
|
|
25
|
+
inlinePrompt,
|
|
26
|
+
showChevron,
|
|
27
|
+
autoFocus,
|
|
28
|
+
loading,
|
|
29
|
+
onFocusChange
|
|
30
|
+
}) {
|
|
31
|
+
const inputId = React.useId();
|
|
32
|
+
const labelId = React.useId();
|
|
33
|
+
const customAlertId = React.useId();
|
|
34
|
+
const currencyId = React.useId();
|
|
35
|
+
const selector = typeof currencySelector === 'function' ? currencySelector({
|
|
36
|
+
id: currencyId,
|
|
37
|
+
labelId
|
|
38
|
+
}) : /*#__PURE__*/jsxRuntime.jsx(CurrencySelector.CurrencySelector, {
|
|
39
|
+
id: currencyId,
|
|
40
|
+
labelId: labelId,
|
|
41
|
+
currency: currency,
|
|
42
|
+
...currencySelector
|
|
43
|
+
});
|
|
44
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
45
|
+
className: clsx.clsx('wds-money-input-field', className),
|
|
46
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(Label.Label, {
|
|
47
|
+
id: labelId,
|
|
48
|
+
htmlFor: inputId,
|
|
49
|
+
className: clsx.clsx('m-b-1', 'font-weight-normal'),
|
|
50
|
+
children: label
|
|
51
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
52
|
+
className: clsx.clsx('d-flex'),
|
|
53
|
+
role: "group",
|
|
54
|
+
"aria-labelledby": labelId,
|
|
55
|
+
...(inlinePrompt ? {
|
|
56
|
+
'aria-describedby': customAlertId
|
|
57
|
+
} : {}),
|
|
58
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
59
|
+
className: "wds-money-input-field-currency-selector",
|
|
60
|
+
children: selector
|
|
61
|
+
}), /*#__PURE__*/jsxRuntime.jsx(AmountInput.AmountInput, {
|
|
62
|
+
id: inputId,
|
|
63
|
+
describedById: currencyId,
|
|
64
|
+
amount: amount,
|
|
65
|
+
currency: currency
|
|
66
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
67
|
+
,
|
|
68
|
+
autoFocus: autoFocus,
|
|
69
|
+
loading: loading,
|
|
70
|
+
onChange: onAmountChange,
|
|
71
|
+
onFocusChange: onFocusChange
|
|
72
|
+
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
73
|
+
className: clsx.clsx('d-flex align-items-center', 'wds-money-input-field-chevron'),
|
|
74
|
+
children: /*#__PURE__*/jsxRuntime.jsx(Chevron.Chevron, {
|
|
75
|
+
shouldShow: Boolean(showChevron)
|
|
76
|
+
})
|
|
77
|
+
})]
|
|
78
|
+
}), /*#__PURE__*/jsxRuntime.jsx(framerMotion.AnimatePresence, {
|
|
79
|
+
initial: false,
|
|
80
|
+
children: inlinePrompt && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
81
|
+
className: clsx.clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1'),
|
|
82
|
+
children: /*#__PURE__*/jsxRuntime.jsx(framerMotion.motion.div, {
|
|
83
|
+
initial: {
|
|
84
|
+
opacity: 0,
|
|
85
|
+
height: 0
|
|
86
|
+
},
|
|
87
|
+
animate: {
|
|
88
|
+
opacity: 1,
|
|
89
|
+
height: 'auto',
|
|
90
|
+
transition: {
|
|
91
|
+
delay: 0.75,
|
|
92
|
+
duration: 0.3
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
exit: {
|
|
96
|
+
opacity: 0,
|
|
97
|
+
height: 0
|
|
98
|
+
},
|
|
99
|
+
children: inlinePrompt.sentiment ? /*#__PURE__*/jsxRuntime.jsx(InlinePrompt.InlinePrompt, {
|
|
100
|
+
id: customAlertId,
|
|
101
|
+
sentiment: inlinePrompt.sentiment,
|
|
102
|
+
children: inlinePrompt.message
|
|
103
|
+
}) : /*#__PURE__*/jsxRuntime.jsx(Body.default, {
|
|
104
|
+
children: inlinePrompt.message
|
|
105
|
+
})
|
|
106
|
+
}, customAlertId)
|
|
107
|
+
})
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exports.default = MoneyInputField;
|
|
113
|
+
//# sourceMappingURL=MoneyInputField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,E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C,OAAK,CACP;AAAA,KAAK,CACL,eAAAW,cAAA,CAACc,4BAAe,EAAA;AAACC,MAAAA,OAAO,EAAE,KAAM;MAAAX,QAAA,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;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var reactIntl = require('react-intl');
|
|
6
|
+
|
|
7
|
+
var messages = reactIntl.defineMessages({
|
|
8
|
+
currencySelectorSearchPlaceholder: {
|
|
9
|
+
id: "neptune.MoneyInputField.currency.search.placeholder"
|
|
10
|
+
},
|
|
11
|
+
currencySelectorSelectCurrency: {
|
|
12
|
+
id: "neptune.MoneyInputField.currency.select.currency"
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
exports.default = messages;
|
|
17
|
+
//# sourceMappingURL=MoneyInputField.messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoneyInputField.messages.js","sources":["../../src/moneyInputField/MoneyInputField.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n currencySelectorSearchPlaceholder: {\n id: 'neptune.MoneyInputField.currency.search.placeholder',\n defaultMessage: 'Type a currency / country',\n },\n\n currencySelectorSelectCurrency: {\n id: 'neptune.MoneyInputField.currency.select.currency',\n defaultMessage: 'Select currency',\n },\n});\n"],"names":["defineMessages","currencySelectorSearchPlaceholder","id","currencySelectorSelectCurrency"],"mappings":";;;;;;AAEA,eAAeA,wBAAc,CAAC;AAC5BC,EAAAA,iCAAiC,EAAE;IACjCC,EAAE,EAAA;GAEH;AAEDC,EAAAA,8BAA8B,EAAE;IAC9BD,EAAE,EAAA;AAEH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl';
|
|
2
|
+
|
|
3
|
+
var messages = defineMessages({
|
|
4
|
+
currencySelectorSearchPlaceholder: {
|
|
5
|
+
id: "neptune.MoneyInputField.currency.search.placeholder"
|
|
6
|
+
},
|
|
7
|
+
currencySelectorSelectCurrency: {
|
|
8
|
+
id: "neptune.MoneyInputField.currency.select.currency"
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { messages as default };
|
|
13
|
+
//# sourceMappingURL=MoneyInputField.messages.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MoneyInputField.messages.mjs","sources":["../../src/moneyInputField/MoneyInputField.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n currencySelectorSearchPlaceholder: {\n id: 'neptune.MoneyInputField.currency.search.placeholder',\n defaultMessage: 'Type a currency / country',\n },\n\n currencySelectorSelectCurrency: {\n id: 'neptune.MoneyInputField.currency.select.currency',\n defaultMessage: 'Select currency',\n },\n});\n"],"names":["defineMessages","currencySelectorSearchPlaceholder","id","currencySelectorSelectCurrency"],"mappings":";;AAEA,eAAeA,cAAc,CAAC;AAC5BC,EAAAA,iCAAiC,EAAE;IACjCC,EAAE,EAAA;GAEH;AAEDC,EAAAA,8BAA8B,EAAE;IAC9BD,EAAE,EAAA;AAEH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import Body from '../body/Body.mjs';
|
|
2
|
+
import { Label as LabelNamespace } from '../label/Label.mjs';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { AnimatePresence, motion } from 'framer-motion';
|
|
5
|
+
import { useId } from 'react';
|
|
6
|
+
import { CurrencySelector } from './CurrencySelector.mjs';
|
|
7
|
+
import { AmountInput } from './AmountInput.mjs';
|
|
8
|
+
import { Chevron } from './Chevron.mjs';
|
|
9
|
+
import { InlinePrompt } from '../prompt/InlinePrompt/InlinePrompt.mjs';
|
|
10
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
function MoneyInputField({
|
|
13
|
+
label,
|
|
14
|
+
currency,
|
|
15
|
+
currencySelector = {
|
|
16
|
+
options: []
|
|
17
|
+
},
|
|
18
|
+
amount,
|
|
19
|
+
onAmountChange,
|
|
20
|
+
className,
|
|
21
|
+
inlinePrompt,
|
|
22
|
+
showChevron,
|
|
23
|
+
autoFocus,
|
|
24
|
+
loading,
|
|
25
|
+
onFocusChange
|
|
26
|
+
}) {
|
|
27
|
+
const inputId = useId();
|
|
28
|
+
const labelId = useId();
|
|
29
|
+
const customAlertId = useId();
|
|
30
|
+
const currencyId = useId();
|
|
31
|
+
const selector = typeof currencySelector === 'function' ? currencySelector({
|
|
32
|
+
id: currencyId,
|
|
33
|
+
labelId
|
|
34
|
+
}) : /*#__PURE__*/jsx(CurrencySelector, {
|
|
35
|
+
id: currencyId,
|
|
36
|
+
labelId: labelId,
|
|
37
|
+
currency: currency,
|
|
38
|
+
...currencySelector
|
|
39
|
+
});
|
|
40
|
+
return /*#__PURE__*/jsxs("div", {
|
|
41
|
+
className: clsx('wds-money-input-field', className),
|
|
42
|
+
children: [/*#__PURE__*/jsx(LabelNamespace, {
|
|
43
|
+
id: labelId,
|
|
44
|
+
htmlFor: inputId,
|
|
45
|
+
className: clsx('m-b-1', 'font-weight-normal'),
|
|
46
|
+
children: label
|
|
47
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
48
|
+
className: clsx('d-flex'),
|
|
49
|
+
role: "group",
|
|
50
|
+
"aria-labelledby": labelId,
|
|
51
|
+
...(inlinePrompt ? {
|
|
52
|
+
'aria-describedby': customAlertId
|
|
53
|
+
} : {}),
|
|
54
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
55
|
+
className: "wds-money-input-field-currency-selector",
|
|
56
|
+
children: selector
|
|
57
|
+
}), /*#__PURE__*/jsx(AmountInput, {
|
|
58
|
+
id: inputId,
|
|
59
|
+
describedById: currencyId,
|
|
60
|
+
amount: amount,
|
|
61
|
+
currency: currency
|
|
62
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
63
|
+
,
|
|
64
|
+
autoFocus: autoFocus,
|
|
65
|
+
loading: loading,
|
|
66
|
+
onChange: onAmountChange,
|
|
67
|
+
onFocusChange: onFocusChange
|
|
68
|
+
}), /*#__PURE__*/jsx("div", {
|
|
69
|
+
className: clsx('d-flex align-items-center', 'wds-money-input-field-chevron'),
|
|
70
|
+
children: /*#__PURE__*/jsx(Chevron, {
|
|
71
|
+
shouldShow: Boolean(showChevron)
|
|
72
|
+
})
|
|
73
|
+
})]
|
|
74
|
+
}), /*#__PURE__*/jsx(AnimatePresence, {
|
|
75
|
+
initial: false,
|
|
76
|
+
children: inlinePrompt && /*#__PURE__*/jsx("div", {
|
|
77
|
+
className: clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1'),
|
|
78
|
+
children: /*#__PURE__*/jsx(motion.div, {
|
|
79
|
+
initial: {
|
|
80
|
+
opacity: 0,
|
|
81
|
+
height: 0
|
|
82
|
+
},
|
|
83
|
+
animate: {
|
|
84
|
+
opacity: 1,
|
|
85
|
+
height: 'auto',
|
|
86
|
+
transition: {
|
|
87
|
+
delay: 0.75,
|
|
88
|
+
duration: 0.3
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
exit: {
|
|
92
|
+
opacity: 0,
|
|
93
|
+
height: 0
|
|
94
|
+
},
|
|
95
|
+
children: inlinePrompt.sentiment ? /*#__PURE__*/jsx(InlinePrompt, {
|
|
96
|
+
id: customAlertId,
|
|
97
|
+
sentiment: inlinePrompt.sentiment,
|
|
98
|
+
children: inlinePrompt.message
|
|
99
|
+
}) : /*#__PURE__*/jsx(Body, {
|
|
100
|
+
children: inlinePrompt.message
|
|
101
|
+
})
|
|
102
|
+
}, customAlertId)
|
|
103
|
+
})
|
|
104
|
+
})]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { MoneyInputField as default };
|
|
109
|
+
//# sourceMappingURL=MoneyInputField.mjs.map
|