@transferwise/components 0.0.0-experimental-643f4d2 → 0.0.0-experimental-77845f6
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/expressiveMoneyInput/ExpressiveMoneyInput.js +114 -0
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.js.map +1 -0
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.js +17 -0
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.js.map +1 -0
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.mjs +13 -0
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.mjs.map +1 -0
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.mjs +110 -0
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.mjs.map +1 -0
- package/build/expressiveMoneyInput/amountInput/AmountInput.js +281 -0
- package/build/expressiveMoneyInput/amountInput/AmountInput.js.map +1 -0
- package/build/expressiveMoneyInput/amountInput/AmountInput.mjs +279 -0
- package/build/expressiveMoneyInput/amountInput/AmountInput.mjs.map +1 -0
- package/build/expressiveMoneyInput/amountInput/utils.js +87 -0
- package/build/expressiveMoneyInput/amountInput/utils.js.map +1 -0
- package/build/expressiveMoneyInput/amountInput/utils.mjs +78 -0
- package/build/expressiveMoneyInput/amountInput/utils.mjs.map +1 -0
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.js +50 -0
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.js.map +1 -0
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.mjs +48 -0
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.mjs.map +1 -0
- package/build/expressiveMoneyInput/chevron/Chevron.js +31 -0
- package/build/expressiveMoneyInput/chevron/Chevron.js.map +1 -0
- package/build/expressiveMoneyInput/chevron/Chevron.mjs +29 -0
- package/build/expressiveMoneyInput/chevron/Chevron.mjs.map +1 -0
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js +160 -0
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js.map +1 -0
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs +157 -0
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs.map +1 -0
- package/build/expressiveMoneyInput/hooks/useFocus.js +37 -0
- package/build/expressiveMoneyInput/hooks/useFocus.js.map +1 -0
- package/build/expressiveMoneyInput/hooks/useFocus.mjs +35 -0
- package/build/expressiveMoneyInput/hooks/useFocus.mjs.map +1 -0
- package/build/expressiveMoneyInput/hooks/useInputStyle.js +71 -0
- package/build/expressiveMoneyInput/hooks/useInputStyle.js.map +1 -0
- package/build/expressiveMoneyInput/hooks/useInputStyle.mjs +69 -0
- package/build/expressiveMoneyInput/hooks/useInputStyle.mjs.map +1 -0
- 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 +65 -15
- package/build/prompt/InlinePrompt/InlinePrompt.js +7 -0
- package/build/prompt/InlinePrompt/InlinePrompt.js.map +1 -1
- package/build/prompt/InlinePrompt/InlinePrompt.mjs +8 -1
- package/build/prompt/InlinePrompt/InlinePrompt.mjs.map +1 -1
- package/build/styles/expressiveMoneyInput/ExpressiveMoneyInput.css +58 -0
- package/build/styles/expressiveMoneyInput/amountInput/AmountInput.css +32 -0
- package/build/styles/expressiveMoneyInput/chevron/Chevron.css +12 -0
- package/build/styles/expressiveMoneyInput/currencySelector/CurrencySelector.css +6 -0
- package/build/styles/main.css +65 -15
- package/build/styles/moneyInput/MoneyInput.css +0 -8
- package/build/styles/prompt/InlinePrompt/InlinePrompt.css +7 -7
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.d.ts +33 -0
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.messages.d.ts +12 -0
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.messages.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/amountInput/AmountInput.d.ts +13 -0
- package/build/types/expressiveMoneyInput/amountInput/AmountInput.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/amountInput/utils.d.ts +22 -0
- package/build/types/expressiveMoneyInput/amountInput/utils.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/animatedNumber/AnimatedNumber.d.ts +9 -0
- package/build/types/expressiveMoneyInput/animatedNumber/AnimatedNumber.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/chevron/Chevron.d.ts +6 -0
- package/build/types/expressiveMoneyInput/chevron/Chevron.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/currencySelector/CurrencySelector.d.ts +30 -0
- package/build/types/expressiveMoneyInput/currencySelector/CurrencySelector.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/hooks/useFocus.d.ts +7 -0
- package/build/types/expressiveMoneyInput/hooks/useFocus.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/hooks/useInputStyle.d.ts +10 -0
- package/build/types/expressiveMoneyInput/hooks/useInputStyle.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/hooks/useSelectionRange.d.ts +10 -0
- package/build/types/expressiveMoneyInput/hooks/useSelectionRange.d.ts.map +1 -0
- package/build/types/expressiveMoneyInput/index.d.ts +3 -0
- package/build/types/expressiveMoneyInput/index.d.ts.map +1 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts +3 -2
- package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +4 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.css +58 -0
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.less +13 -0
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.messages.ts +13 -0
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.story.tsx +290 -0
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.tsx +125 -0
- package/src/expressiveMoneyInput/amountInput/AmountInput.css +32 -0
- package/src/expressiveMoneyInput/amountInput/AmountInput.less +43 -0
- package/src/expressiveMoneyInput/amountInput/AmountInput.tsx +353 -0
- package/src/expressiveMoneyInput/amountInput/utils.spec.ts +114 -0
- package/src/expressiveMoneyInput/amountInput/utils.ts +116 -0
- package/src/expressiveMoneyInput/animatedNumber/AnimatedNumber.tsx +40 -0
- package/src/expressiveMoneyInput/chevron/Chevron.css +12 -0
- package/src/expressiveMoneyInput/chevron/Chevron.less +13 -0
- package/src/expressiveMoneyInput/chevron/Chevron.tsx +35 -0
- package/src/expressiveMoneyInput/currencySelector/CurrencySelector.css +6 -0
- package/src/expressiveMoneyInput/currencySelector/CurrencySelector.less +7 -0
- package/src/expressiveMoneyInput/currencySelector/CurrencySelector.tsx +218 -0
- package/src/expressiveMoneyInput/hooks/useFocus.ts +35 -0
- package/src/expressiveMoneyInput/hooks/useInputStyle.ts +85 -0
- package/src/expressiveMoneyInput/hooks/useSelectionRange.ts +23 -0
- package/src/expressiveMoneyInput/index.ts +2 -0
- package/src/i18n/en.json +2 -0
- package/src/index.ts +2 -0
- package/src/main.css +65 -15
- package/src/main.less +1 -0
- package/src/moneyInput/MoneyInput.css +0 -8
- package/src/moneyInput/MoneyInput.less +0 -5
- package/src/prompt/InlinePrompt/InlinePrompt.css +7 -7
- package/src/prompt/InlinePrompt/InlinePrompt.less +7 -7
- package/src/prompt/InlinePrompt/InlinePrompt.spec.tsx +6 -0
- package/src/prompt/InlinePrompt/InlinePrompt.story.tsx +57 -0
- package/src/prompt/InlinePrompt/InlinePrompt.tsx +12 -2
- package/src/ssr.spec.tsx +1 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/anchor-is-valid, no-console, jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
|
|
2
|
+
import { Meta } from '@storybook/react-webpack5';
|
|
3
|
+
import ExpressiveMoneyInput, { Props as ExpressiveMoneyInputProps } from './ExpressiveMoneyInput';
|
|
4
|
+
import { lorem10, lorem5 } from '../test-utils';
|
|
5
|
+
import { Sentiment } from '../common';
|
|
6
|
+
import Image from '../image';
|
|
7
|
+
import Link from '../link';
|
|
8
|
+
import Money from '../money';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import Button from '../button';
|
|
11
|
+
import Modal from '../modal';
|
|
12
|
+
import ListItem from '../listItem';
|
|
13
|
+
import List from '../list';
|
|
14
|
+
import { Flag } from '@wise/art';
|
|
15
|
+
import Alert from '../alert';
|
|
16
|
+
import Divider from '../divider';
|
|
17
|
+
import { Rewards, Tags } from '@transferwise/icons';
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
title: 'Forms/ExpressiveMoneyInput',
|
|
21
|
+
component: ExpressiveMoneyInput,
|
|
22
|
+
} as Meta;
|
|
23
|
+
|
|
24
|
+
const props: ExpressiveMoneyInputProps = {
|
|
25
|
+
label: 'You send',
|
|
26
|
+
currency: 'GBP',
|
|
27
|
+
amount: 1234.56,
|
|
28
|
+
onAmountChange: (amount) => {
|
|
29
|
+
console.log('Amount changed', amount);
|
|
30
|
+
},
|
|
31
|
+
currencySelector: {
|
|
32
|
+
addons: [
|
|
33
|
+
{ asset: <Image src="../avatar-square-dude.webp" alt="" /> },
|
|
34
|
+
{ profileName: 'Test Test' },
|
|
35
|
+
],
|
|
36
|
+
options: [
|
|
37
|
+
{
|
|
38
|
+
title: 'Popular',
|
|
39
|
+
currencies: [
|
|
40
|
+
{ code: 'USD', label: 'US Dollar', keywords: ['dollar', 'us'] },
|
|
41
|
+
{ code: 'AUD', label: 'Australia Dollar', keywords: ['dollar', 'us'] },
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: 'Others',
|
|
46
|
+
currencies: [
|
|
47
|
+
{ code: 'GBP', label: 'Pound', keywords: ['british'] },
|
|
48
|
+
{ code: 'EUR', label: 'Euro', keywords: ['euro'] },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
onOpen: () => {
|
|
53
|
+
console.log('Currency selector opened');
|
|
54
|
+
},
|
|
55
|
+
onSearchChange: (payload) => {
|
|
56
|
+
console.log('Search changed', payload);
|
|
57
|
+
},
|
|
58
|
+
onChange: (currency) => {
|
|
59
|
+
console.log('Currency changed', currency);
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
loading: false,
|
|
63
|
+
inlinePrompt: { message: lorem10, sentiment: Sentiment.POSITIVE },
|
|
64
|
+
showChevron: true,
|
|
65
|
+
autoFocus: true,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const NullAmount = {
|
|
69
|
+
args: props,
|
|
70
|
+
render: (args: ExpressiveMoneyInputProps) => (
|
|
71
|
+
<ExpressiveMoneyInput
|
|
72
|
+
label={args.label}
|
|
73
|
+
amount={null}
|
|
74
|
+
currency="EUR"
|
|
75
|
+
onAmountChange={args.onAmountChange}
|
|
76
|
+
/>
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const WithInitAmount = {
|
|
81
|
+
args: props,
|
|
82
|
+
render: (args: ExpressiveMoneyInputProps) => {
|
|
83
|
+
const availableBalance = 1500;
|
|
84
|
+
return (
|
|
85
|
+
<ExpressiveMoneyInput
|
|
86
|
+
label={args.label}
|
|
87
|
+
amount={availableBalance}
|
|
88
|
+
currency="EUR"
|
|
89
|
+
onAmountChange={args.onAmountChange}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const WithLoading = {
|
|
96
|
+
args: props,
|
|
97
|
+
render: (args: ExpressiveMoneyInputProps) => {
|
|
98
|
+
const availableBalance = 1500;
|
|
99
|
+
return (
|
|
100
|
+
<ExpressiveMoneyInput
|
|
101
|
+
label={args.label}
|
|
102
|
+
amount={availableBalance}
|
|
103
|
+
currency="EUR"
|
|
104
|
+
loading
|
|
105
|
+
onAmountChange={args.onAmountChange}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const WithoutChevron = {
|
|
112
|
+
args: props,
|
|
113
|
+
render: (args: ExpressiveMoneyInputProps) => {
|
|
114
|
+
const availableBalance = 1500;
|
|
115
|
+
return (
|
|
116
|
+
<ExpressiveMoneyInput
|
|
117
|
+
label={args.label}
|
|
118
|
+
amount={availableBalance}
|
|
119
|
+
currency="EUR"
|
|
120
|
+
showChevron={false}
|
|
121
|
+
onAmountChange={args.onAmountChange}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const WithCurrencySelector = {
|
|
128
|
+
args: props,
|
|
129
|
+
render: (args: ExpressiveMoneyInputProps) => {
|
|
130
|
+
const availableBalance = 1500;
|
|
131
|
+
return (
|
|
132
|
+
<ExpressiveMoneyInput
|
|
133
|
+
label={args.label}
|
|
134
|
+
amount={availableBalance}
|
|
135
|
+
currency="EUR"
|
|
136
|
+
currencySelector={args.currencySelector}
|
|
137
|
+
onAmountChange={args.onAmountChange}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const WithInlinePromptNoSentiment = {
|
|
144
|
+
args: props,
|
|
145
|
+
render: (args: ExpressiveMoneyInputProps) => {
|
|
146
|
+
const availableBalance = 1500;
|
|
147
|
+
const [sourceAmount, setSourceAmount] = React.useState(args.amount);
|
|
148
|
+
return (
|
|
149
|
+
<ExpressiveMoneyInput
|
|
150
|
+
label={args.label}
|
|
151
|
+
amount={sourceAmount}
|
|
152
|
+
currency="EUR"
|
|
153
|
+
currencySelector={args.currencySelector}
|
|
154
|
+
inlinePrompt={{
|
|
155
|
+
message: (
|
|
156
|
+
<>
|
|
157
|
+
{`Available balance `}
|
|
158
|
+
<Link
|
|
159
|
+
onClick={() => {
|
|
160
|
+
setSourceAmount(availableBalance);
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
<Money amount={availableBalance} currency={args.currency} />
|
|
164
|
+
</Link>
|
|
165
|
+
</>
|
|
166
|
+
),
|
|
167
|
+
}}
|
|
168
|
+
onAmountChange={args.onAmountChange}
|
|
169
|
+
/>
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export const WithInlinePromptSentiment = {
|
|
175
|
+
args: props,
|
|
176
|
+
render: (args: ExpressiveMoneyInputProps) => {
|
|
177
|
+
return (
|
|
178
|
+
<>
|
|
179
|
+
<ExpressiveMoneyInput
|
|
180
|
+
label={args.label}
|
|
181
|
+
currency="EUR"
|
|
182
|
+
currencySelector={args.currencySelector}
|
|
183
|
+
inlinePrompt={{ message: lorem5, sentiment: 'negative' }}
|
|
184
|
+
onAmountChange={args.onAmountChange}
|
|
185
|
+
/>
|
|
186
|
+
<ExpressiveMoneyInput
|
|
187
|
+
label={args.label}
|
|
188
|
+
currency="EUR"
|
|
189
|
+
currencySelector={args.currencySelector}
|
|
190
|
+
inlinePrompt={{ message: lorem5, sentiment: 'warning' }}
|
|
191
|
+
onAmountChange={args.onAmountChange}
|
|
192
|
+
/>
|
|
193
|
+
<ExpressiveMoneyInput
|
|
194
|
+
label={args.label}
|
|
195
|
+
currency="EUR"
|
|
196
|
+
currencySelector={args.currencySelector}
|
|
197
|
+
inlinePrompt={{ message: lorem5, sentiment: 'neutral' }}
|
|
198
|
+
onAmountChange={args.onAmountChange}
|
|
199
|
+
/>
|
|
200
|
+
<ExpressiveMoneyInput
|
|
201
|
+
label={args.label}
|
|
202
|
+
currency="EUR"
|
|
203
|
+
currencySelector={args.currencySelector}
|
|
204
|
+
inlinePrompt={{ message: lorem5, sentiment: 'positive' }}
|
|
205
|
+
onAmountChange={args.onAmountChange}
|
|
206
|
+
/>
|
|
207
|
+
<ExpressiveMoneyInput
|
|
208
|
+
label={args.label}
|
|
209
|
+
currency="EUR"
|
|
210
|
+
currencySelector={args.currencySelector}
|
|
211
|
+
inlinePrompt={{ message: lorem5, sentiment: 'positive', media: <Tags /> }}
|
|
212
|
+
onAmountChange={args.onAmountChange}
|
|
213
|
+
/>
|
|
214
|
+
<ExpressiveMoneyInput
|
|
215
|
+
label={args.label}
|
|
216
|
+
currency="EUR"
|
|
217
|
+
currencySelector={args.currencySelector}
|
|
218
|
+
inlinePrompt={{ message: lorem5, sentiment: 'proposition' }}
|
|
219
|
+
onAmountChange={args.onAmountChange}
|
|
220
|
+
/>
|
|
221
|
+
<ExpressiveMoneyInput
|
|
222
|
+
label={args.label}
|
|
223
|
+
currency="EUR"
|
|
224
|
+
currencySelector={args.currencySelector}
|
|
225
|
+
inlinePrompt={{ message: lorem5, sentiment: 'proposition', media: <Rewards /> }}
|
|
226
|
+
onAmountChange={args.onAmountChange}
|
|
227
|
+
/>
|
|
228
|
+
</>
|
|
229
|
+
);
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export const Autofocus = {
|
|
234
|
+
args: props,
|
|
235
|
+
render: (args: ExpressiveMoneyInputProps) => (
|
|
236
|
+
<ExpressiveMoneyInput {...args} currency="MXN" inlinePrompt={undefined} />
|
|
237
|
+
),
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export const WithCustomRender = {
|
|
241
|
+
args: props,
|
|
242
|
+
render: (args: ExpressiveMoneyInputProps) => {
|
|
243
|
+
const [open, setOpen] = React.useState(false);
|
|
244
|
+
return (
|
|
245
|
+
<>
|
|
246
|
+
<ExpressiveMoneyInput
|
|
247
|
+
label="Instance with Custom Currency Selector"
|
|
248
|
+
currency="AUD"
|
|
249
|
+
currencySelector={{
|
|
250
|
+
customRender: ({ id, labelId }) => (
|
|
251
|
+
<Button v2 size="sm" priority="primary" onClick={() => setOpen(true)}>
|
|
252
|
+
Custom Render
|
|
253
|
+
</Button>
|
|
254
|
+
),
|
|
255
|
+
}}
|
|
256
|
+
onAmountChange={(amount) => console.log(amount)}
|
|
257
|
+
/>
|
|
258
|
+
<Modal
|
|
259
|
+
open={open}
|
|
260
|
+
title="Custom UX for currency selectors"
|
|
261
|
+
body={
|
|
262
|
+
<List>
|
|
263
|
+
<ListItem
|
|
264
|
+
media={
|
|
265
|
+
<ListItem.AvatarView>
|
|
266
|
+
<Flag code="gb" />
|
|
267
|
+
</ListItem.AvatarView>
|
|
268
|
+
}
|
|
269
|
+
title="GBP"
|
|
270
|
+
control={<ListItem.Radio name="currency-key" checked={false} />}
|
|
271
|
+
/>
|
|
272
|
+
<ListItem
|
|
273
|
+
media={
|
|
274
|
+
<ListItem.AvatarView>
|
|
275
|
+
<Flag code="au" />
|
|
276
|
+
</ListItem.AvatarView>
|
|
277
|
+
}
|
|
278
|
+
title="AUD"
|
|
279
|
+
control={<ListItem.Radio name="currency-key" checked />}
|
|
280
|
+
/>
|
|
281
|
+
</List>
|
|
282
|
+
}
|
|
283
|
+
onClose={() => setOpen(false)}
|
|
284
|
+
/>
|
|
285
|
+
<Divider className="m-y-2" />
|
|
286
|
+
<Alert type="info" message="TODO: add proper message here" />
|
|
287
|
+
</>
|
|
288
|
+
);
|
|
289
|
+
},
|
|
290
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Body from '../body';
|
|
2
|
+
import { Label } from '../label/Label';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { AnimatePresence, motion } from 'framer-motion';
|
|
5
|
+
import { useId, type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type Props as CurrencySelectorProps,
|
|
9
|
+
CurrencySelector,
|
|
10
|
+
} from './currencySelector/CurrencySelector';
|
|
11
|
+
import { CommonProps } from '../common';
|
|
12
|
+
import { AmountInput } from './amountInput/AmountInput';
|
|
13
|
+
import { Chevron } from './chevron/Chevron';
|
|
14
|
+
import { InlinePrompt, type InlinePromptProps } from '../prompt/InlinePrompt';
|
|
15
|
+
|
|
16
|
+
type AmountType = number | null;
|
|
17
|
+
export type CurrencyType = string;
|
|
18
|
+
|
|
19
|
+
type DefaultCurrencySelectorInstanceType = Pick<
|
|
20
|
+
CurrencySelectorProps,
|
|
21
|
+
'addons' | 'options' | 'onChange' | 'onOpen' | 'onSearchChange'
|
|
22
|
+
>;
|
|
23
|
+
type CustomCurrencySelectorInstanceType = {
|
|
24
|
+
customRender?: (props: { id: string; labelId: string }) => ReactNode;
|
|
25
|
+
};
|
|
26
|
+
type CurrencySelectorType = DefaultCurrencySelectorInstanceType &
|
|
27
|
+
CustomCurrencySelectorInstanceType;
|
|
28
|
+
|
|
29
|
+
export type Props = {
|
|
30
|
+
label?: ReactNode;
|
|
31
|
+
currencySelector?: CurrencySelectorType;
|
|
32
|
+
amount?: AmountType;
|
|
33
|
+
currency: CurrencyType;
|
|
34
|
+
inlinePrompt?: {
|
|
35
|
+
sentiment?: InlinePromptProps['sentiment'];
|
|
36
|
+
message: InlinePromptProps['children'];
|
|
37
|
+
media?: InlinePromptProps['media'];
|
|
38
|
+
};
|
|
39
|
+
showChevron?: boolean;
|
|
40
|
+
autoFocus?: boolean;
|
|
41
|
+
loading?: boolean;
|
|
42
|
+
onAmountChange: (amount: AmountType) => void;
|
|
43
|
+
onFocusChange?: (focused: boolean) => void;
|
|
44
|
+
} & CommonProps;
|
|
45
|
+
|
|
46
|
+
export default function ExpressiveMoneyInput({
|
|
47
|
+
label,
|
|
48
|
+
currency,
|
|
49
|
+
currencySelector = { options: [] } as DefaultCurrencySelectorInstanceType,
|
|
50
|
+
amount,
|
|
51
|
+
onAmountChange,
|
|
52
|
+
className,
|
|
53
|
+
inlinePrompt,
|
|
54
|
+
showChevron,
|
|
55
|
+
autoFocus,
|
|
56
|
+
loading,
|
|
57
|
+
onFocusChange,
|
|
58
|
+
}: Props) {
|
|
59
|
+
const inputId = useId();
|
|
60
|
+
const labelId = useId();
|
|
61
|
+
const customAlertId = useId();
|
|
62
|
+
const currencyId = useId();
|
|
63
|
+
|
|
64
|
+
const selector = currencySelector.customRender?.({ id: currencyId, labelId }) ?? (
|
|
65
|
+
<CurrencySelector id={currencyId} labelId={labelId} currency={currency} {...currencySelector} />
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div className={clsx('wds-expressive-money-input', className)}>
|
|
70
|
+
<Label id={labelId} htmlFor={inputId} className={clsx('m-b-1', 'font-weight-normal')}>
|
|
71
|
+
{label}
|
|
72
|
+
</Label>
|
|
73
|
+
<div
|
|
74
|
+
className={clsx('d-flex')}
|
|
75
|
+
role="group"
|
|
76
|
+
aria-labelledby={labelId}
|
|
77
|
+
{...(inlinePrompt ? { 'aria-describedby': customAlertId } : {})}
|
|
78
|
+
>
|
|
79
|
+
<div className="wds-expressive-money-input-currency-selector">{selector}</div>
|
|
80
|
+
<AmountInput
|
|
81
|
+
id={inputId}
|
|
82
|
+
describedById={currencyId}
|
|
83
|
+
amount={amount}
|
|
84
|
+
currency={currency}
|
|
85
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
86
|
+
autoFocus={autoFocus}
|
|
87
|
+
loading={loading}
|
|
88
|
+
onChange={onAmountChange}
|
|
89
|
+
onFocusChange={onFocusChange}
|
|
90
|
+
/>
|
|
91
|
+
<div className={clsx('d-flex align-items-center', 'wds-expressive-money-input-chevron')}>
|
|
92
|
+
<Chevron shouldShow={Boolean(showChevron)} />
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
<AnimatePresence initial={false}>
|
|
96
|
+
{inlinePrompt && (
|
|
97
|
+
<div className={clsx('d-flex justify-content-end', inlinePrompt && 'm-t-1')}>
|
|
98
|
+
<motion.div
|
|
99
|
+
key={customAlertId}
|
|
100
|
+
initial={{ opacity: 0, height: 0 }}
|
|
101
|
+
animate={{
|
|
102
|
+
opacity: 1,
|
|
103
|
+
height: 'auto',
|
|
104
|
+
transition: { delay: 0.75, duration: 0.3 },
|
|
105
|
+
}}
|
|
106
|
+
exit={{ opacity: 0, height: 0 }}
|
|
107
|
+
>
|
|
108
|
+
{inlinePrompt.sentiment ? (
|
|
109
|
+
<InlinePrompt
|
|
110
|
+
id={customAlertId}
|
|
111
|
+
media={inlinePrompt.media}
|
|
112
|
+
sentiment={inlinePrompt.sentiment}
|
|
113
|
+
>
|
|
114
|
+
{inlinePrompt.message}
|
|
115
|
+
</InlinePrompt>
|
|
116
|
+
) : (
|
|
117
|
+
<Body>{inlinePrompt.message}</Body>
|
|
118
|
+
)}
|
|
119
|
+
</motion.div>
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
122
|
+
</AnimatePresence>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.wds-amount-input-container {
|
|
2
|
+
width: 100%;
|
|
3
|
+
}
|
|
4
|
+
.wds-amount-input-input-container {
|
|
5
|
+
display: flex;
|
|
6
|
+
justify-content: right;
|
|
7
|
+
width: 100%;
|
|
8
|
+
transition: font-size 0.4s cubic-bezier(0.3, 0, 0.1, 1), height 0.4s cubic-bezier(0.3, 0, 0.1, 1), margin-top 0.4s cubic-bezier(0.3, 0, 0.1, 1), color 0.4s ease;
|
|
9
|
+
color: var(--color-interactive-primary);
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
margin-bottom: 0 !important;
|
|
12
|
+
}
|
|
13
|
+
@media (prefers-reduced-motion: reduce) {
|
|
14
|
+
.wds-amount-input-input-container {
|
|
15
|
+
transition: none;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
.wds-amount-input-input {
|
|
19
|
+
border: none;
|
|
20
|
+
outline: none;
|
|
21
|
+
flex-grow: 1;
|
|
22
|
+
text-align: right;
|
|
23
|
+
background-color: transparent;
|
|
24
|
+
}
|
|
25
|
+
.wds-amount-input-input:focus-visible {
|
|
26
|
+
outline: none;
|
|
27
|
+
}
|
|
28
|
+
.wds-amount-input-placeholder {
|
|
29
|
+
flex-grow: 0;
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
.wds-amount-input {
|
|
2
|
+
&-container {
|
|
3
|
+
width: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
&-input-container {
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: right;
|
|
9
|
+
width: 100%;
|
|
10
|
+
transition:
|
|
11
|
+
font-size 0.4s cubic-bezier(0.3, 0, 0.1, 1),
|
|
12
|
+
height 0.4s cubic-bezier(0.3, 0, 0.1, 1),
|
|
13
|
+
margin-top 0.4s cubic-bezier(0.3, 0, 0.1, 1),
|
|
14
|
+
color 0.4s ease;
|
|
15
|
+
color: var(--color-interactive-primary);
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
margin-bottom: 0 !important;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@media (prefers-reduced-motion: reduce) {
|
|
21
|
+
&-input-container {
|
|
22
|
+
transition: none;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&-input {
|
|
27
|
+
border: none;
|
|
28
|
+
outline: none;
|
|
29
|
+
flex-grow: 1;
|
|
30
|
+
text-align: right;
|
|
31
|
+
background-color: transparent;
|
|
32
|
+
|
|
33
|
+
&:focus-visible {
|
|
34
|
+
outline: none;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&-placeholder {
|
|
39
|
+
flex-grow: 0;
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
}
|
|
43
|
+
}
|