@transferwise/components 0.0.0-experimental-77845f6 → 0.0.0-experimental-e556371
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 +0 -2
- package/build/i18n/en.json.js +0 -2
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +0 -2
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/index.mjs +0 -1
- package/build/index.mjs.map +1 -1
- package/build/main.css +15 -65
- package/build/prompt/InlinePrompt/InlinePrompt.js +0 -7
- package/build/prompt/InlinePrompt/InlinePrompt.js.map +1 -1
- package/build/prompt/InlinePrompt/InlinePrompt.mjs +1 -8
- package/build/prompt/InlinePrompt/InlinePrompt.mjs.map +1 -1
- package/build/styles/main.css +15 -65
- package/build/styles/moneyInput/MoneyInput.css +8 -0
- package/build/styles/prompt/InlinePrompt/InlinePrompt.css +7 -7
- package/build/types/index.d.ts +0 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts +2 -3
- package/build/types/prompt/InlinePrompt/InlinePrompt.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +0 -4
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/i18n/en.json +0 -2
- package/src/index.ts +0 -2
- package/src/main.css +15 -65
- package/src/main.less +0 -1
- package/src/moneyInput/MoneyInput.css +8 -0
- package/src/moneyInput/MoneyInput.less +5 -0
- package/src/prompt/InlinePrompt/InlinePrompt.css +7 -7
- package/src/prompt/InlinePrompt/InlinePrompt.less +7 -7
- package/src/prompt/InlinePrompt/InlinePrompt.spec.tsx +0 -6
- package/src/prompt/InlinePrompt/InlinePrompt.tsx +2 -12
- package/src/ssr.spec.tsx +0 -1
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.js +0 -114
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.js.map +0 -1
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.js +0 -17
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.js.map +0 -1
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.mjs +0 -13
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.messages.mjs.map +0 -1
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.mjs +0 -110
- package/build/expressiveMoneyInput/ExpressiveMoneyInput.mjs.map +0 -1
- package/build/expressiveMoneyInput/amountInput/AmountInput.js +0 -281
- package/build/expressiveMoneyInput/amountInput/AmountInput.js.map +0 -1
- package/build/expressiveMoneyInput/amountInput/AmountInput.mjs +0 -279
- package/build/expressiveMoneyInput/amountInput/AmountInput.mjs.map +0 -1
- package/build/expressiveMoneyInput/amountInput/utils.js +0 -87
- package/build/expressiveMoneyInput/amountInput/utils.js.map +0 -1
- package/build/expressiveMoneyInput/amountInput/utils.mjs +0 -78
- package/build/expressiveMoneyInput/amountInput/utils.mjs.map +0 -1
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.js +0 -50
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.js.map +0 -1
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.mjs +0 -48
- package/build/expressiveMoneyInput/animatedNumber/AnimatedNumber.mjs.map +0 -1
- package/build/expressiveMoneyInput/chevron/Chevron.js +0 -31
- package/build/expressiveMoneyInput/chevron/Chevron.js.map +0 -1
- package/build/expressiveMoneyInput/chevron/Chevron.mjs +0 -29
- package/build/expressiveMoneyInput/chevron/Chevron.mjs.map +0 -1
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js +0 -160
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js.map +0 -1
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs +0 -157
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs.map +0 -1
- package/build/expressiveMoneyInput/hooks/useFocus.js +0 -37
- package/build/expressiveMoneyInput/hooks/useFocus.js.map +0 -1
- package/build/expressiveMoneyInput/hooks/useFocus.mjs +0 -35
- package/build/expressiveMoneyInput/hooks/useFocus.mjs.map +0 -1
- package/build/expressiveMoneyInput/hooks/useInputStyle.js +0 -71
- package/build/expressiveMoneyInput/hooks/useInputStyle.js.map +0 -1
- package/build/expressiveMoneyInput/hooks/useInputStyle.mjs +0 -69
- package/build/expressiveMoneyInput/hooks/useInputStyle.mjs.map +0 -1
- package/build/styles/expressiveMoneyInput/ExpressiveMoneyInput.css +0 -58
- package/build/styles/expressiveMoneyInput/amountInput/AmountInput.css +0 -32
- package/build/styles/expressiveMoneyInput/chevron/Chevron.css +0 -12
- package/build/styles/expressiveMoneyInput/currencySelector/CurrencySelector.css +0 -6
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.d.ts +0 -33
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.messages.d.ts +0 -12
- package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.messages.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/amountInput/AmountInput.d.ts +0 -13
- package/build/types/expressiveMoneyInput/amountInput/AmountInput.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/amountInput/utils.d.ts +0 -22
- package/build/types/expressiveMoneyInput/amountInput/utils.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/animatedNumber/AnimatedNumber.d.ts +0 -9
- package/build/types/expressiveMoneyInput/animatedNumber/AnimatedNumber.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/chevron/Chevron.d.ts +0 -6
- package/build/types/expressiveMoneyInput/chevron/Chevron.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/currencySelector/CurrencySelector.d.ts +0 -30
- package/build/types/expressiveMoneyInput/currencySelector/CurrencySelector.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/hooks/useFocus.d.ts +0 -7
- package/build/types/expressiveMoneyInput/hooks/useFocus.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/hooks/useInputStyle.d.ts +0 -10
- package/build/types/expressiveMoneyInput/hooks/useInputStyle.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/hooks/useSelectionRange.d.ts +0 -10
- package/build/types/expressiveMoneyInput/hooks/useSelectionRange.d.ts.map +0 -1
- package/build/types/expressiveMoneyInput/index.d.ts +0 -3
- package/build/types/expressiveMoneyInput/index.d.ts.map +0 -1
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.css +0 -58
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.less +0 -13
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.messages.ts +0 -13
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.story.tsx +0 -290
- package/src/expressiveMoneyInput/ExpressiveMoneyInput.tsx +0 -125
- package/src/expressiveMoneyInput/amountInput/AmountInput.css +0 -32
- package/src/expressiveMoneyInput/amountInput/AmountInput.less +0 -43
- package/src/expressiveMoneyInput/amountInput/AmountInput.tsx +0 -353
- package/src/expressiveMoneyInput/amountInput/utils.spec.ts +0 -114
- package/src/expressiveMoneyInput/amountInput/utils.ts +0 -116
- package/src/expressiveMoneyInput/animatedNumber/AnimatedNumber.tsx +0 -40
- package/src/expressiveMoneyInput/chevron/Chevron.css +0 -12
- package/src/expressiveMoneyInput/chevron/Chevron.less +0 -13
- package/src/expressiveMoneyInput/chevron/Chevron.tsx +0 -35
- package/src/expressiveMoneyInput/currencySelector/CurrencySelector.css +0 -6
- package/src/expressiveMoneyInput/currencySelector/CurrencySelector.less +0 -7
- package/src/expressiveMoneyInput/currencySelector/CurrencySelector.tsx +0 -218
- package/src/expressiveMoneyInput/hooks/useFocus.ts +0 -35
- package/src/expressiveMoneyInput/hooks/useInputStyle.ts +0 -85
- package/src/expressiveMoneyInput/hooks/useSelectionRange.ts +0 -23
- package/src/expressiveMoneyInput/index.ts +0 -2
- package/src/prompt/InlinePrompt/InlinePrompt.story.tsx +0 -57
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ChevronLeft } from '@transferwise/icons';
|
|
2
|
-
import { clsx } from 'clsx';
|
|
3
|
-
import { motion } from 'framer-motion';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
shouldShow: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const Chevron = ({ shouldShow = true }: Props) => {
|
|
10
|
-
return (
|
|
11
|
-
<div
|
|
12
|
-
className={clsx(
|
|
13
|
-
'd-flex align-items-center',
|
|
14
|
-
'wds-chevron-container',
|
|
15
|
-
!shouldShow && 'wds-chevron-hidden',
|
|
16
|
-
)}
|
|
17
|
-
>
|
|
18
|
-
<motion.div
|
|
19
|
-
animate={{
|
|
20
|
-
x: [12, 0, 0, -12],
|
|
21
|
-
opacity: [0, 1, 1, 0],
|
|
22
|
-
}}
|
|
23
|
-
transition={{
|
|
24
|
-
duration: 3,
|
|
25
|
-
ease: [[0.3, 0, 0.1, 1], 'linear', [0.3, 0, 0.1, 1]],
|
|
26
|
-
times: [0, 0.1, 0.9, 1],
|
|
27
|
-
repeat: Infinity,
|
|
28
|
-
repeatType: 'loop',
|
|
29
|
-
}}
|
|
30
|
-
>
|
|
31
|
-
<ChevronLeft />
|
|
32
|
-
</motion.div>
|
|
33
|
-
</div>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import type { AvatarLayoutProps } from '../../avatarLayout';
|
|
2
|
-
import Button from '../../button';
|
|
3
|
-
import {
|
|
4
|
-
SelectInput,
|
|
5
|
-
SelectInputOptionContent,
|
|
6
|
-
SelectInputTriggerButton,
|
|
7
|
-
} from '../../inputs/SelectInput';
|
|
8
|
-
import { CurrencyType, Props as ExpressiveMoneyInputProps } from '../ExpressiveMoneyInput';
|
|
9
|
-
import { ChevronDown } from '@transferwise/icons';
|
|
10
|
-
import { Flag } from '@wise/art';
|
|
11
|
-
import {
|
|
12
|
-
type ButtonHTMLAttributes,
|
|
13
|
-
forwardRef,
|
|
14
|
-
type MouseEventHandler,
|
|
15
|
-
useMemo,
|
|
16
|
-
useState,
|
|
17
|
-
} from 'react';
|
|
18
|
-
import { useIntl } from 'react-intl';
|
|
19
|
-
|
|
20
|
-
import messages from '../ExpressiveMoneyInput.messages';
|
|
21
|
-
|
|
22
|
-
export interface CurrencyOption {
|
|
23
|
-
label?: string;
|
|
24
|
-
code: string;
|
|
25
|
-
keywords: string[] | undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface CurrencySection {
|
|
29
|
-
title: string;
|
|
30
|
-
currencies: CurrencyOption[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type CurrencyOptions = CurrencySection[];
|
|
34
|
-
|
|
35
|
-
export type Props = {
|
|
36
|
-
id: string;
|
|
37
|
-
labelId: string;
|
|
38
|
-
options?: CurrencyOptions;
|
|
39
|
-
onChange?: (currency: CurrencyType) => void;
|
|
40
|
-
onOpen?: () => void;
|
|
41
|
-
addons?: AvatarLayoutProps['avatars'];
|
|
42
|
-
onSearchChange?: (payload: { query: string; resultCount: number }) => void;
|
|
43
|
-
} & Pick<ExpressiveMoneyInputProps, 'currency'>;
|
|
44
|
-
|
|
45
|
-
export const CurrencySelector = ({
|
|
46
|
-
id,
|
|
47
|
-
currency,
|
|
48
|
-
options = [],
|
|
49
|
-
labelId,
|
|
50
|
-
onChange,
|
|
51
|
-
addons,
|
|
52
|
-
onOpen,
|
|
53
|
-
onSearchChange,
|
|
54
|
-
}: Props) => {
|
|
55
|
-
const intl = useIntl();
|
|
56
|
-
|
|
57
|
-
const allCurrencyOptions = useMemo(() => getUniqueCurrencies(options), [options]);
|
|
58
|
-
|
|
59
|
-
const activeCurrencyOption = useMemo(() => {
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
61
|
-
return allCurrencyOptions.find((option) => option.code === currency)!;
|
|
62
|
-
}, [currency, allCurrencyOptions]);
|
|
63
|
-
|
|
64
|
-
const disabled =
|
|
65
|
-
!onChange ||
|
|
66
|
-
options.length === 0 ||
|
|
67
|
-
(options.length === 1 && options[0].currencies.length <= 1);
|
|
68
|
-
|
|
69
|
-
const [searchQuery, setSearchQuery] = useState<string>('');
|
|
70
|
-
|
|
71
|
-
const handleTriggerClick: MouseEventHandler = (event) => {
|
|
72
|
-
const triggerEl = event.currentTarget;
|
|
73
|
-
if (triggerEl?.getAttribute('aria-expanded') === 'false') {
|
|
74
|
-
onOpen?.();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const items = searchQuery
|
|
79
|
-
? filterAndSortCurrenciesForQuery(allCurrencyOptions, searchQuery).map(getCurrencySelectOption)
|
|
80
|
-
: options.map(getCurrencyGroup);
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<SelectInput
|
|
84
|
-
compareValues="code"
|
|
85
|
-
disabled={disabled}
|
|
86
|
-
id={id}
|
|
87
|
-
value={activeCurrencyOption}
|
|
88
|
-
filterable
|
|
89
|
-
filterPlaceholder={intl.formatMessage(messages.currencySelectorSearchPlaceholder)}
|
|
90
|
-
UNSAFE_triggerButtonProps={{
|
|
91
|
-
id: undefined,
|
|
92
|
-
'aria-labelledby': undefined,
|
|
93
|
-
'aria-describedby': labelId,
|
|
94
|
-
'aria-invalid': undefined,
|
|
95
|
-
'aria-label': intl.formatMessage(messages.currencySelectorSelectCurrency),
|
|
96
|
-
}}
|
|
97
|
-
items={items}
|
|
98
|
-
renderValue={({ code, label }) => {
|
|
99
|
-
return (
|
|
100
|
-
<SelectInputOptionContent
|
|
101
|
-
title={code}
|
|
102
|
-
note={label}
|
|
103
|
-
icon={<Flag code={code} intrinsicSize={24} />}
|
|
104
|
-
/>
|
|
105
|
-
);
|
|
106
|
-
}}
|
|
107
|
-
renderTrigger={() => (
|
|
108
|
-
<SelectInputTriggerButton
|
|
109
|
-
as={ButtonInput}
|
|
110
|
-
// @ts-expect-error new (v2) ButtonProps
|
|
111
|
-
addonStart={{
|
|
112
|
-
type: 'avatar',
|
|
113
|
-
value: [
|
|
114
|
-
addons ? addons[0] : null,
|
|
115
|
-
{
|
|
116
|
-
...(addons && addons.length > 1
|
|
117
|
-
? { ...addons[1] }
|
|
118
|
-
: {
|
|
119
|
-
asset: <Flag code={currency} />,
|
|
120
|
-
}),
|
|
121
|
-
},
|
|
122
|
-
].filter((avatar) => Boolean(avatar)),
|
|
123
|
-
}}
|
|
124
|
-
addonEnd={disabled ? undefined : { type: 'icon', value: <ChevronDown /> }}
|
|
125
|
-
onClick={(event) => handleTriggerClick(event)}
|
|
126
|
-
>
|
|
127
|
-
{currency}
|
|
128
|
-
</SelectInputTriggerButton>
|
|
129
|
-
)}
|
|
130
|
-
onChange={(newValue) => {
|
|
131
|
-
onChange?.(newValue.code);
|
|
132
|
-
}}
|
|
133
|
-
onFilterChange={({ queryNormalized }) => {
|
|
134
|
-
setSearchQuery(queryNormalized ?? '');
|
|
135
|
-
if (queryNormalized) {
|
|
136
|
-
onSearchChange?.({
|
|
137
|
-
query: queryNormalized,
|
|
138
|
-
resultCount: filterAndSortCurrenciesForQuery(allCurrencyOptions, queryNormalized)
|
|
139
|
-
.length,
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}}
|
|
143
|
-
/>
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const ButtonInput = forwardRef(function ButtonInput(
|
|
148
|
-
{ children, ...rest }: React.PropsWithChildren<ButtonHTMLAttributes<HTMLButtonElement>>,
|
|
149
|
-
ref: React.ForwardedRef<HTMLButtonElement | null>,
|
|
150
|
-
) {
|
|
151
|
-
return (
|
|
152
|
-
<Button
|
|
153
|
-
ref={ref}
|
|
154
|
-
size="md"
|
|
155
|
-
v2
|
|
156
|
-
className="wds-currency-selector"
|
|
157
|
-
priority="secondary-neutral"
|
|
158
|
-
{...rest}
|
|
159
|
-
>
|
|
160
|
-
{children}
|
|
161
|
-
</Button>
|
|
162
|
-
);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const getCurrencySelectOption = (currency: CurrencyOption) => {
|
|
166
|
-
return {
|
|
167
|
-
type: 'option' as const,
|
|
168
|
-
value: currency,
|
|
169
|
-
filterMatchers: currency.keywords,
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const getCurrencyGroup = (section: CurrencySection) => {
|
|
174
|
-
return {
|
|
175
|
-
type: 'group' as const,
|
|
176
|
-
label: section.title,
|
|
177
|
-
options: section.currencies.map(getCurrencySelectOption),
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const getUniqueCurrencies = (options: CurrencyOptions) => {
|
|
182
|
-
const allCurrencyOptions = options.flatMap((section) => section.currencies);
|
|
183
|
-
const uniqueCurrencies = new Map<string, CurrencyOption>();
|
|
184
|
-
|
|
185
|
-
allCurrencyOptions.forEach((currencyObj) => {
|
|
186
|
-
uniqueCurrencies.set(currencyObj.code, currencyObj);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
return Array.from(uniqueCurrencies.values());
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
const filterAndSortCurrenciesForQuery = (
|
|
193
|
-
currencies: CurrencyOption[],
|
|
194
|
-
query: string,
|
|
195
|
-
): CurrencyOption[] => {
|
|
196
|
-
return (
|
|
197
|
-
currencies
|
|
198
|
-
.filter((currency) => {
|
|
199
|
-
return (
|
|
200
|
-
currency.code.toLowerCase().includes(query) ||
|
|
201
|
-
(currency.label ?? '').toLowerCase().includes(query) ||
|
|
202
|
-
currency.keywords?.some((keyword) => keyword.toLowerCase().includes(query))
|
|
203
|
-
);
|
|
204
|
-
})
|
|
205
|
-
// prefer exact matches, then sort alphabetically by code
|
|
206
|
-
.sort((a, b) => {
|
|
207
|
-
const aCode = a.code.toLowerCase();
|
|
208
|
-
const bCode = b.code.toLowerCase();
|
|
209
|
-
if (aCode === query) {
|
|
210
|
-
return -1;
|
|
211
|
-
}
|
|
212
|
-
if (bCode === query) {
|
|
213
|
-
return 1;
|
|
214
|
-
}
|
|
215
|
-
return aCode.localeCompare(bCode);
|
|
216
|
-
})
|
|
217
|
-
);
|
|
218
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
const focusTimeout = 5 * 1000;
|
|
4
|
-
|
|
5
|
-
export const useFocus = () => {
|
|
6
|
-
const [focus, setFocus] = useState(false);
|
|
7
|
-
const [visualFocus, setVisualFocus] = useState(false);
|
|
8
|
-
const [counter, setCounter] = useState(0);
|
|
9
|
-
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (focus) {
|
|
12
|
-
const timeout = setTimeout(() => {
|
|
13
|
-
setVisualFocus(false);
|
|
14
|
-
}, focusTimeout);
|
|
15
|
-
return () => clearTimeout(timeout);
|
|
16
|
-
}
|
|
17
|
-
}, [focus, counter]);
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
focus,
|
|
21
|
-
setFocus: (value: boolean) => {
|
|
22
|
-
setFocus(value);
|
|
23
|
-
if (value) {
|
|
24
|
-
setVisualFocus(true);
|
|
25
|
-
}
|
|
26
|
-
// any call to setFocus should reset the timeout, even if the input was already in focus
|
|
27
|
-
// updating the counter will trigger the useEffect to reset the timeout
|
|
28
|
-
setCounter((prev) => prev + 1);
|
|
29
|
-
},
|
|
30
|
-
visualFocus,
|
|
31
|
-
setVisualFocus: (value: boolean) => {
|
|
32
|
-
setVisualFocus(value);
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { type CSSProperties, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
|
-
import { Props as ExpressiveMoneyInputProps } from '../ExpressiveMoneyInput';
|
|
3
|
-
|
|
4
|
-
type InputStyleObject = {
|
|
5
|
-
value: string;
|
|
6
|
-
focus: boolean;
|
|
7
|
-
inputElement: HTMLInputElement | null;
|
|
8
|
-
} & Pick<ExpressiveMoneyInputProps, 'loading'>;
|
|
9
|
-
|
|
10
|
-
export const useInputStyle = ({ value, focus, inputElement, loading }: InputStyleObject) => {
|
|
11
|
-
const initialRender = !useTimeout(300);
|
|
12
|
-
const inputWidth = useFirstDefinedValue(inputElement?.clientWidth, [inputElement, value]);
|
|
13
|
-
|
|
14
|
-
const getStyle = (): CSSProperties => {
|
|
15
|
-
const fontSize = getFontSize(value, focus, inputWidth);
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
fontSize,
|
|
19
|
-
height: fontSize,
|
|
20
|
-
// aligns the top of the digit with the currency button
|
|
21
|
-
marginTop: fontSize * -0.19,
|
|
22
|
-
// if the input loads with a pre-filled value, we don't want to animate the font-size immediately
|
|
23
|
-
transition: initialRender ? 'none' : undefined,
|
|
24
|
-
color: loading ? 'var(--color-interactive-secondary)' : undefined,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const [style, setStyle] = useState(getStyle());
|
|
29
|
-
|
|
30
|
-
useLayoutEffect(() => {
|
|
31
|
-
setStyle(getStyle());
|
|
32
|
-
}, [value, focus, loading, inputWidth]);
|
|
33
|
-
|
|
34
|
-
return style;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function getFontSize(inputValue: string, isFocused: boolean, inputWidth: number | undefined) {
|
|
38
|
-
const defaultFontSize = 52;
|
|
39
|
-
const focusFontSize = 90;
|
|
40
|
-
const minimumFontSize = 34;
|
|
41
|
-
|
|
42
|
-
let fontSize = isFocused ? focusFontSize : defaultFontSize;
|
|
43
|
-
|
|
44
|
-
if (typeof inputWidth === 'undefined') {
|
|
45
|
-
return fontSize;
|
|
46
|
-
}
|
|
47
|
-
const textLength = inputValue.length;
|
|
48
|
-
const maxCharactersWithoutShrinking = Math.floor(inputWidth / 40);
|
|
49
|
-
|
|
50
|
-
if (textLength > maxCharactersWithoutShrinking) {
|
|
51
|
-
const adjustedSize = Math.round((inputWidth / textLength) * 1.9);
|
|
52
|
-
fontSize = Math.min(fontSize, adjustedSize);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return Math.max(fontSize, minimumFontSize);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const useFirstDefinedValue = (newValue: number | undefined, dependencies: unknown[]) => {
|
|
59
|
-
const [value, setValue] = useState<number | undefined>(newValue);
|
|
60
|
-
|
|
61
|
-
useLayoutEffect(() => {
|
|
62
|
-
if (typeof newValue !== 'undefined' && typeof value === 'undefined') {
|
|
63
|
-
setValue(newValue);
|
|
64
|
-
}
|
|
65
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
-
}, [...dependencies, value]);
|
|
67
|
-
|
|
68
|
-
return value;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const useTimeout = (delay: number) => {
|
|
72
|
-
const [ready, setReady] = useState(false);
|
|
73
|
-
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
const timeout = setTimeout(() => {
|
|
76
|
-
setReady(true);
|
|
77
|
-
}, delay);
|
|
78
|
-
|
|
79
|
-
return () => {
|
|
80
|
-
clearTimeout(timeout);
|
|
81
|
-
};
|
|
82
|
-
}, [delay]);
|
|
83
|
-
|
|
84
|
-
return ready;
|
|
85
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type SyntheticEvent, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
export const useSelectionRange = () => {
|
|
4
|
-
const selection = useRef<{
|
|
5
|
-
selectionStart: number | null;
|
|
6
|
-
selectionEnd: number | null;
|
|
7
|
-
}>();
|
|
8
|
-
|
|
9
|
-
const handleSelect = (e: SyntheticEvent<HTMLInputElement>) => {
|
|
10
|
-
const input = e.target as HTMLInputElement;
|
|
11
|
-
const { selectionStart, selectionEnd } = input;
|
|
12
|
-
selection.current = { selectionStart, selectionEnd };
|
|
13
|
-
};
|
|
14
|
-
const handleSelectionBlur = () => {
|
|
15
|
-
selection.current = undefined;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
selection: selection.current,
|
|
20
|
-
handleSelect,
|
|
21
|
-
handleSelectionBlur,
|
|
22
|
-
};
|
|
23
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { lorem10, lorem5 } from '../../test-utils';
|
|
2
|
-
import { InlinePrompt } from './InlinePrompt';
|
|
3
|
-
import { CardWise, Rewards } from '@transferwise/icons';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Internal/InlinePrompt',
|
|
7
|
-
component: InlinePrompt,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const AllVariants = () => {
|
|
11
|
-
return (
|
|
12
|
-
<div
|
|
13
|
-
style={{
|
|
14
|
-
display: 'grid',
|
|
15
|
-
gridAutoFlow: 'row',
|
|
16
|
-
rowGap: 'var(--size-12)',
|
|
17
|
-
justifyItems: 'start',
|
|
18
|
-
width: 'fit-content',
|
|
19
|
-
}}
|
|
20
|
-
>
|
|
21
|
-
<InlinePrompt sentiment="positive">
|
|
22
|
-
{lorem5}
|
|
23
|
-
</InlinePrompt>
|
|
24
|
-
<InlinePrompt media={<Rewards />} sentiment="positive">
|
|
25
|
-
{lorem10}
|
|
26
|
-
</InlinePrompt>
|
|
27
|
-
<InlinePrompt sentiment="negative">
|
|
28
|
-
{lorem5}
|
|
29
|
-
</InlinePrompt>
|
|
30
|
-
<InlinePrompt sentiment="negative">
|
|
31
|
-
{lorem10}
|
|
32
|
-
</InlinePrompt>
|
|
33
|
-
<InlinePrompt sentiment="neutral">
|
|
34
|
-
{lorem5}
|
|
35
|
-
</InlinePrompt>
|
|
36
|
-
<InlinePrompt sentiment="neutral">
|
|
37
|
-
{lorem10}
|
|
38
|
-
</InlinePrompt>
|
|
39
|
-
<InlinePrompt sentiment="warning">
|
|
40
|
-
{lorem5}
|
|
41
|
-
</InlinePrompt>
|
|
42
|
-
<InlinePrompt sentiment="warning">
|
|
43
|
-
{lorem10}
|
|
44
|
-
</InlinePrompt>
|
|
45
|
-
<InlinePrompt sentiment="proposition">
|
|
46
|
-
{lorem5}
|
|
47
|
-
</InlinePrompt>
|
|
48
|
-
<InlinePrompt sentiment="proposition">
|
|
49
|
-
{lorem10}
|
|
50
|
-
</InlinePrompt>
|
|
51
|
-
<InlinePrompt sentiment="proposition" media={<CardWise />}>
|
|
52
|
-
{lorem10}
|
|
53
|
-
</InlinePrompt>
|
|
54
|
-
<InlinePrompt>{lorem5}</InlinePrompt>
|
|
55
|
-
</div>
|
|
56
|
-
);
|
|
57
|
-
};
|