@transferwise/components 45.14.2 → 45.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/build/index.esm.js +680 -50
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +683 -50
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/common/closeButton/CloseButton.css +1 -1
  7. package/build/styles/inputs/Input.css +1 -1
  8. package/build/styles/inputs/InputGroup.css +1 -1
  9. package/build/styles/inputs/SelectInput.css +1 -0
  10. package/build/styles/inputs/TextArea.css +1 -1
  11. package/build/styles/main.css +1 -1
  12. package/build/styles/promoCard/PromoCard.css +1 -1
  13. package/build/styles/stepper/Stepper.css +1 -1
  14. package/build/types/common/hooks/useMedia.d.ts +2 -0
  15. package/build/types/common/hooks/useMedia.d.ts.map +1 -0
  16. package/build/types/common/hooks/useScreenSize.d.ts +3 -0
  17. package/build/types/common/hooks/useScreenSize.d.ts.map +1 -0
  18. package/build/types/common/preventScroll/PreventScroll.d.ts +2 -0
  19. package/build/types/common/preventScroll/PreventScroll.d.ts.map +1 -0
  20. package/build/types/dateLookup/dateTrigger/DateTrigger.messages.d.ts +7 -7
  21. package/build/types/dateLookup/dateTrigger/DateTrigger.messages.d.ts.map +1 -1
  22. package/build/types/index.d.ts +4 -0
  23. package/build/types/index.d.ts.map +1 -1
  24. package/build/types/inputs/Input.d.ts +1 -0
  25. package/build/types/inputs/Input.d.ts.map +1 -1
  26. package/build/types/inputs/SearchInput.d.ts +10 -0
  27. package/build/types/inputs/SearchInput.d.ts.map +1 -0
  28. package/build/types/inputs/SelectInput.d.ts +41 -0
  29. package/build/types/inputs/SelectInput.d.ts.map +1 -0
  30. package/build/types/inputs/_BottomSheet.d.ts +17 -0
  31. package/build/types/inputs/_BottomSheet.d.ts.map +1 -0
  32. package/build/types/inputs/_ButtonInput.d.ts +6 -0
  33. package/build/types/inputs/_ButtonInput.d.ts.map +1 -0
  34. package/build/types/inputs/_Popover.d.ts +18 -0
  35. package/build/types/inputs/_Popover.d.ts.map +1 -0
  36. package/build/types/inputs/_common.d.ts.map +1 -1
  37. package/build/types/logo/Logo.d.ts.map +1 -1
  38. package/build/types/stepper/Stepper.d.ts.map +1 -1
  39. package/build/types/tile/Tile.d.ts.map +1 -1
  40. package/build/types/utilities/wrapInFragment.d.ts +3 -0
  41. package/build/types/utilities/wrapInFragment.d.ts.map +1 -0
  42. package/package.json +26 -20
  43. package/src/common/closeButton/CloseButton.css +1 -1
  44. package/src/common/hooks/useMedia.spec.ts +39 -0
  45. package/src/common/hooks/useMedia.ts +15 -0
  46. package/src/common/hooks/useScreenSize.ts +7 -0
  47. package/src/common/preventScroll/PreventScroll.tsx +6 -0
  48. package/src/decision/Decision.story.js +11 -11
  49. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +12 -12
  50. package/src/i18n/en.json +1 -0
  51. package/src/index.ts +8 -0
  52. package/src/inputs/Input.css +1 -1
  53. package/src/inputs/Input.less +14 -0
  54. package/src/inputs/Input.tsx +6 -2
  55. package/src/inputs/InputGroup.css +1 -1
  56. package/src/inputs/InputGroup.less +5 -0
  57. package/src/inputs/SearchInput.story.tsx +40 -0
  58. package/src/inputs/SearchInput.tsx +35 -0
  59. package/src/inputs/SelectInput.css +1 -0
  60. package/src/inputs/SelectInput.less +183 -0
  61. package/src/inputs/SelectInput.spec.tsx +120 -0
  62. package/src/inputs/SelectInput.story.tsx +259 -0
  63. package/src/inputs/SelectInput.tsx +565 -0
  64. package/src/inputs/TextArea.css +1 -1
  65. package/src/inputs/TextArea.less +5 -0
  66. package/src/inputs/_BottomSheet.less +107 -0
  67. package/src/inputs/_BottomSheet.tsx +128 -0
  68. package/src/inputs/_ButtonInput.less +7 -0
  69. package/src/inputs/_ButtonInput.tsx +27 -0
  70. package/src/inputs/_Popover.less +38 -0
  71. package/src/inputs/_Popover.tsx +118 -0
  72. package/src/inputs/_common.less +0 -4
  73. package/src/inputs/_common.ts +0 -1
  74. package/src/logo/Logo.js +3 -21
  75. package/src/logo/__snapshots__/Logo.spec.js.snap +78 -30
  76. package/src/main.css +1 -1
  77. package/src/main.less +4 -0
  78. package/src/promoCard/PromoCard.css +1 -1
  79. package/src/select/searchBox/__snapshots__/SearchBox.spec.js.snap +1 -1
  80. package/src/ssr.spec.js +7 -0
  81. package/src/stepper/Stepper.css +1 -1
  82. package/src/stepper/Stepper.less +1 -9
  83. package/src/stepper/Stepper.spec.js +4 -4
  84. package/src/stepper/Stepper.tsx +2 -5
  85. package/src/tile/Tile.js +5 -11
  86. package/src/tile/__snapshots__/Tile.spec.js.snap +7 -9
  87. package/src/utilities/wrapInFragment.tsx +3 -0
  88. /package/src/dateLookup/dateTrigger/{DateTrigger.messages.js → DateTrigger.messages.ts} +0 -0
@@ -0,0 +1,259 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import { Calendar } from '@transferwise/icons';
3
+ import { Flag } from '@wise/art';
4
+ import { useState } from 'react';
5
+
6
+ import { getMonthNames } from '../common/dateUtils';
7
+
8
+ import { SelectInput, type SelectInputItem, SelectInputOptionContent } from './SelectInput';
9
+
10
+ export default {
11
+ component: SelectInput,
12
+ } satisfies Meta<typeof SelectInput>;
13
+
14
+ interface TestMonth {
15
+ id: number;
16
+ name: string;
17
+ unavailable: boolean;
18
+ }
19
+
20
+ const testMonths: TestMonth[] = getMonthNames('en-US').map((name, index) => ({
21
+ id: index + 1,
22
+ name,
23
+ unavailable: index % 6 === 2,
24
+ }));
25
+
26
+ const testQuarters = [
27
+ testMonths.slice(0, 3),
28
+ testMonths.slice(3, 6),
29
+ testMonths.slice(6, 9),
30
+ testMonths.slice(9, 12),
31
+ ] as const;
32
+
33
+ export const Basic: StoryObj<{
34
+ filterable: boolean;
35
+ filterPlaceholder: string;
36
+ clearable: boolean;
37
+ invalid: boolean;
38
+ disabled: boolean;
39
+ onChange: (value: TestMonth | null) => void;
40
+ onClear: () => void;
41
+ }> = {
42
+ render: function Story({
43
+ filterable,
44
+ filterPlaceholder,
45
+ clearable,
46
+ disabled,
47
+ onChange,
48
+ onClear,
49
+ }) {
50
+ const [selectedMonth, setSelectedMonth] = useState<TestMonth | null>(null);
51
+
52
+ return (
53
+ <div className="d-flex flex-column">
54
+ {/* TODO:
55
+ <Field
56
+ label="Label"
57
+ hint="Information message."
58
+ error={invalid ? "Error message." : undefined}
59
+ >
60
+ */}
61
+ <SelectInput
62
+ placeholder="Month"
63
+ items={testQuarters
64
+ .flatMap<SelectInputItem<TestMonth>>((quarterMonths, index) => [
65
+ {
66
+ type: 'group',
67
+ label: `Quarter #${index + 1}`,
68
+ options: quarterMonths.map((month) => ({
69
+ type: 'option',
70
+ value: month,
71
+ filterMatchers: [month.name],
72
+ disabled: month.unavailable,
73
+ })),
74
+ },
75
+ { type: 'separator' },
76
+ ])
77
+ .slice(0, -1)}
78
+ value={selectedMonth}
79
+ renderValue={(month, compact) => (
80
+ <SelectInputOptionContent
81
+ title={month.name}
82
+ note="Note"
83
+ description={compact ? undefined : `Month #${month.id}`}
84
+ icon={<Calendar size={24} />}
85
+ />
86
+ )}
87
+ filterable={filterable}
88
+ filterPlaceholder={filterPlaceholder}
89
+ disabled={disabled}
90
+ onChange={(month) => {
91
+ setSelectedMonth(month);
92
+ onChange(month);
93
+ }}
94
+ onClear={
95
+ clearable
96
+ ? () => {
97
+ setSelectedMonth(null);
98
+ onClear();
99
+ }
100
+ : undefined
101
+ }
102
+ />
103
+ </div>
104
+ );
105
+ },
106
+ args: {
107
+ filterable: true,
108
+ filterPlaceholder: 'Type a month’s name',
109
+ clearable: true,
110
+ invalid: false,
111
+ disabled: false,
112
+ },
113
+ argTypes: {
114
+ onChange: {
115
+ action: 'changed',
116
+ },
117
+ onClear: {
118
+ action: 'cleared',
119
+ },
120
+ },
121
+ };
122
+
123
+ interface Month {
124
+ id: number;
125
+ name: string;
126
+ }
127
+
128
+ const months: Month[] = getMonthNames('en-US').map((name, index) => ({
129
+ id: index + 1,
130
+ name,
131
+ }));
132
+
133
+ export const Months: StoryObj<{
134
+ onChange: (value: Month | null) => void;
135
+ onClear: () => void;
136
+ }> = {
137
+ render: function Story({ onChange, onClear }) {
138
+ const [selectedMonth, setSelectedMonth] = useState<Month | null>(null);
139
+
140
+ return (
141
+ <div className="d-flex flex-column">
142
+ <SelectInput
143
+ placeholder="Month"
144
+ items={months.map((month) => ({ type: 'option', value: month }))}
145
+ value={selectedMonth}
146
+ renderValue={(month) => <SelectInputOptionContent title={month.name} />}
147
+ onChange={(month) => {
148
+ setSelectedMonth(month);
149
+ onChange(month);
150
+ }}
151
+ onClear={() => {
152
+ setSelectedMonth(null);
153
+ onClear();
154
+ }}
155
+ />
156
+ </div>
157
+ );
158
+ },
159
+ argTypes: {
160
+ onChange: {
161
+ action: 'changed',
162
+ },
163
+ onClear: {
164
+ action: 'cleared',
165
+ },
166
+ },
167
+ };
168
+
169
+ interface Currency {
170
+ code: string;
171
+ name: string;
172
+ countries?: string[];
173
+ }
174
+
175
+ const popularCurrencies: Currency[] = [
176
+ {
177
+ code: 'USD',
178
+ name: 'United States dollar',
179
+ countries: ['Hong Kong', 'Saudi Arabia'],
180
+ },
181
+ {
182
+ code: 'EUR',
183
+ name: 'Euro',
184
+ countries: ['Spain', 'Germany', 'France', 'Austria', 'Estonia'],
185
+ },
186
+ {
187
+ code: 'GBP',
188
+ name: 'British pound',
189
+ countries: ['England', 'Scotland', 'Wales'],
190
+ },
191
+ ];
192
+
193
+ const otherCurrencies: Currency[] = [
194
+ {
195
+ code: 'CAD',
196
+ name: 'Canadian dollar',
197
+ countries: ['Canada'],
198
+ },
199
+ {
200
+ code: 'AUD',
201
+ name: 'Australian dollar',
202
+ },
203
+ ];
204
+
205
+ const allCurrencies: Currency[] = [...popularCurrencies, ...otherCurrencies].sort((a, b) =>
206
+ a.code.localeCompare(b.code),
207
+ );
208
+
209
+ export const Currencies: StoryObj<{
210
+ onChange: (value: Currency) => void;
211
+ }> = {
212
+ render: function Story({ onChange }) {
213
+ const [selectedCurrency, setSelectedCurrency] = useState<Currency>(popularCurrencies[0]);
214
+
215
+ return (
216
+ <div className="d-flex flex-column">
217
+ <SelectInput
218
+ items={[
219
+ {
220
+ type: 'group',
221
+ label: 'Popular currencies',
222
+ options: popularCurrencies.map((currency) => ({
223
+ type: 'option',
224
+ value: currency,
225
+ })),
226
+ },
227
+ {
228
+ type: 'group',
229
+ label: 'All currencies',
230
+ options: allCurrencies.map((currency) => ({
231
+ type: 'option',
232
+ value: currency,
233
+ })),
234
+ },
235
+ ]}
236
+ value={selectedCurrency}
237
+ renderValue={(currency) => (
238
+ <SelectInputOptionContent
239
+ title={currency.code}
240
+ note={currency.name}
241
+ icon={<Flag code={currency.code} intrinsicSize={24} />}
242
+ />
243
+ )}
244
+ filterable
245
+ filterPlaceholder="Type a currency / country"
246
+ onChange={(currency) => {
247
+ setSelectedCurrency(currency);
248
+ onChange(currency);
249
+ }}
250
+ />
251
+ </div>
252
+ );
253
+ },
254
+ argTypes: {
255
+ onChange: {
256
+ action: 'changed',
257
+ },
258
+ },
259
+ };