@transferwise/components 0.0.0-experimental-08de8b3 → 0.0.0-experimental-ab588f3
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/button/Button.js +4 -1
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.messages.js.map +1 -1
- package/build/button/Button.messages.mjs.map +1 -1
- package/build/button/Button.mjs +4 -1
- package/build/button/Button.mjs.map +1 -1
- package/build/button/classMap.js.map +1 -1
- package/build/button/classMap.mjs.map +1 -1
- package/build/button/legacyUtils/legacyUtils.js +5 -6
- package/build/button/legacyUtils/legacyUtils.js.map +1 -1
- package/build/button/legacyUtils/legacyUtils.mjs +6 -7
- package/build/button/legacyUtils/legacyUtils.mjs.map +1 -1
- package/build/checkbox/Checkbox.js +1 -1
- package/build/checkbox/Checkbox.mjs +1 -1
- package/build/checkboxOption/CheckboxOption.js +1 -1
- package/build/checkboxOption/CheckboxOption.mjs +1 -1
- package/build/index.js +2 -2
- package/build/index.mjs +1 -1
- package/build/inputs/SelectInput.js +12 -3
- package/build/inputs/SelectInput.js.map +1 -1
- package/build/inputs/SelectInput.mjs +12 -3
- package/build/inputs/SelectInput.mjs.map +1 -1
- package/build/stepper/deviceDetection.js +3 -2
- package/build/stepper/deviceDetection.js.map +1 -1
- package/build/stepper/deviceDetection.mjs +3 -2
- package/build/stepper/deviceDetection.mjs.map +1 -1
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/button/Button.messages.d.ts +7 -7
- package/build/types/button/Button.messages.d.ts.map +1 -1
- package/build/types/button/classMap.d.ts +10 -10
- package/build/types/button/classMap.d.ts.map +1 -1
- package/build/types/button/legacyUtils/index.d.ts +1 -1
- package/build/types/button/legacyUtils/index.d.ts.map +1 -1
- package/build/types/button/legacyUtils/legacyUtils.d.ts +6 -20
- package/build/types/button/legacyUtils/legacyUtils.d.ts.map +1 -1
- package/build/types/checkboxButton/index.d.ts +1 -1
- package/build/types/checkboxButton/index.d.ts.map +1 -1
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/stepper/deviceDetection.d.ts +1 -1
- package/build/types/stepper/deviceDetection.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/button/Button.tsx +3 -0
- package/src/button/legacyUtils/legacyUtils.js +54 -0
- package/src/flowNavigation/{FlowNavigation.story.tsx → FlowNavigation.story.js} +16 -34
- package/src/inputs/SelectInput.tsx +15 -8
- package/src/select/{Select.story.tsx → Select.story.js} +47 -97
- package/src/stepper/{deviceDetection.ts → deviceDetection.js} +6 -2
- package/src/button/legacyUtils/legacyUtils.ts +0 -74
- /package/src/button/{Button.messages.ts → Button.messages.js} +0 -0
- /package/src/button/{classMap.ts → classMap.js} +0 -0
- /package/src/button/legacyUtils/{index.ts → index.js} +0 -0
- /package/src/checkboxButton/{index.ts → index.js} +0 -0
|
@@ -2,7 +2,7 @@ import { text, boolean, select } from '@storybook/addon-knobs';
|
|
|
2
2
|
import { Person as ProfileIcon, Globe as GlobeIcon } from '@transferwise/icons';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
|
|
5
|
-
import Select
|
|
5
|
+
import Select from './Select';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
component: Select,
|
|
@@ -17,16 +17,8 @@ const ImageIcon = () => (
|
|
|
17
17
|
/>
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
interface SelectItemWithCountries extends SelectItem {
|
|
21
|
-
countries?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const isSelectOptionItem = (option: SelectItem | null): option is SelectOptionItem => {
|
|
25
|
-
return option !== null && typeof option.value !== 'undefined';
|
|
26
|
-
};
|
|
27
|
-
|
|
28
20
|
export const Basic = () => {
|
|
29
|
-
const [selected, setSelected] = useState
|
|
21
|
+
const [selected, setSelected] = useState({
|
|
30
22
|
value: 0,
|
|
31
23
|
label: 'A thing',
|
|
32
24
|
note: 'with a note',
|
|
@@ -34,7 +26,7 @@ export const Basic = () => {
|
|
|
34
26
|
|
|
35
27
|
const size = select('size', ['sm', 'md', 'lg'], 'md');
|
|
36
28
|
const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
|
|
37
|
-
const dropdownWidth = select('dropdownWidth', [
|
|
29
|
+
const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
|
|
38
30
|
|
|
39
31
|
const id = text('id', 'basic-button');
|
|
40
32
|
const placeholder = text('placeholder', 'Placeholder text');
|
|
@@ -43,12 +35,14 @@ export const Basic = () => {
|
|
|
43
35
|
const required = boolean('required', false);
|
|
44
36
|
const dropdownUp = boolean('dropdownUp', false);
|
|
45
37
|
const disabled = boolean('disabled', false);
|
|
46
|
-
const search = boolean('search',
|
|
38
|
+
const search = boolean('search', false);
|
|
39
|
+
const hasError = boolean('hasError', false);
|
|
47
40
|
|
|
48
41
|
return (
|
|
49
42
|
<Select
|
|
50
43
|
id={id}
|
|
51
44
|
size={size}
|
|
45
|
+
classNames={hasError ? 'has-error' : ''}
|
|
52
46
|
placeholder={placeholder}
|
|
53
47
|
dropdownRight={dropdownRight}
|
|
54
48
|
dropdownWidth={dropdownWidth}
|
|
@@ -114,17 +108,13 @@ export const Basic = () => {
|
|
|
114
108
|
'and with lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation secondary text',
|
|
115
109
|
},
|
|
116
110
|
]}
|
|
117
|
-
onChange={(
|
|
118
|
-
if (isSelectOptionItem(option)) {
|
|
119
|
-
setSelected(option);
|
|
120
|
-
}
|
|
121
|
-
}}
|
|
111
|
+
onChange={(v) => setSelected(v)}
|
|
122
112
|
/>
|
|
123
113
|
);
|
|
124
114
|
};
|
|
125
115
|
|
|
126
116
|
export const CustomSearchFunction = () => {
|
|
127
|
-
const [selected, setSelected] = useState
|
|
117
|
+
const [selected, setSelected] = useState({
|
|
128
118
|
value: 1,
|
|
129
119
|
label: 'EUR',
|
|
130
120
|
currency: 'EUR',
|
|
@@ -132,7 +122,7 @@ export const CustomSearchFunction = () => {
|
|
|
132
122
|
|
|
133
123
|
const size = select('size', ['sm', 'md', 'lg'], 'md');
|
|
134
124
|
const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
|
|
135
|
-
const dropdownWidth = select('dropdownWidth', [
|
|
125
|
+
const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
|
|
136
126
|
|
|
137
127
|
const id = text('id', 'custom-search-button');
|
|
138
128
|
const placeholder = text('placeholder', 'placeholder');
|
|
@@ -154,7 +144,12 @@ export const CustomSearchFunction = () => {
|
|
|
154
144
|
block={block}
|
|
155
145
|
selected={selected}
|
|
156
146
|
disabled={disabled}
|
|
157
|
-
search={
|
|
147
|
+
search={
|
|
148
|
+
search
|
|
149
|
+
? (option, keyword) =>
|
|
150
|
+
option.countries && option.countries.toLowerCase().includes(keyword.toLowerCase())
|
|
151
|
+
: false
|
|
152
|
+
}
|
|
158
153
|
required={required}
|
|
159
154
|
searchPlaceholder="Search placeholder"
|
|
160
155
|
dropdownUp={dropdownUp}
|
|
@@ -164,143 +159,106 @@ export const CustomSearchFunction = () => {
|
|
|
164
159
|
value: 1,
|
|
165
160
|
label: 'EUR',
|
|
166
161
|
currency: 'EUR',
|
|
167
|
-
|
|
168
|
-
'Austria',
|
|
169
|
-
'Belgium',
|
|
170
|
-
'Cyprus',
|
|
171
|
-
'Estonia',
|
|
172
|
-
'Finland',
|
|
173
|
-
'France',
|
|
174
|
-
'Germany',
|
|
175
|
-
'Greece',
|
|
176
|
-
'Ireland',
|
|
177
|
-
'Italy',
|
|
178
|
-
'Latvia',
|
|
179
|
-
'Lithuania',
|
|
180
|
-
'Luxembourg',
|
|
181
|
-
'Malta',
|
|
182
|
-
'Netherlands',
|
|
183
|
-
'Portugal',
|
|
184
|
-
'Slovakia',
|
|
185
|
-
'Slovenia',
|
|
186
|
-
'Spain',
|
|
187
|
-
'Andorra',
|
|
188
|
-
'Monaco',
|
|
189
|
-
'San Marino',
|
|
190
|
-
'Vatican City',
|
|
191
|
-
'Kosovo',
|
|
192
|
-
'Montenegro',
|
|
193
|
-
],
|
|
162
|
+
countries:
|
|
163
|
+
'Seychelles Romania Saudi Arabia Macedonia, Former Yugoslav Republic of Serbia Kazakhstan Saint Lucia Malta Kosovo, Republic of Israel Slovakia Andorra United Kingdom Faroe Islands Ukraine Bulgaria Czech Republic Sao Tome and Principe Qatar Belgium Gibraltar Lebanon Netherlands Lithuania Slovenia France Norway Austria Hungary Spain United Arab Emirates Portugal Kuwait San Marino British Virgin Islands Georgia Timor-Leste Croatia Mauritania Finland Iceland Moldova Montenegro Turkey Switzerland Italy Sweden Costa Rica Estonia Guatemala Ireland Monaco Bosnia and Herzegovina Cyprus Greece Mauritius Bahrain Germany Poland Greenland Albania Tunisia Dominican Republic Luxembourg Azerbaijan Latvia Liechtenstein Denmark',
|
|
194
164
|
},
|
|
195
165
|
{
|
|
196
166
|
value: 2,
|
|
197
167
|
label: 'GBP',
|
|
198
168
|
currency: 'GBP',
|
|
199
|
-
|
|
169
|
+
countries: 'Isle of Man United Kingdom',
|
|
200
170
|
},
|
|
201
171
|
{
|
|
202
172
|
value: 3,
|
|
203
173
|
label: 'INR',
|
|
204
174
|
currency: 'INR',
|
|
205
|
-
|
|
175
|
+
countries: 'India',
|
|
206
176
|
},
|
|
207
177
|
{
|
|
208
178
|
value: 4,
|
|
209
179
|
label: 'USD',
|
|
210
180
|
currency: 'USD',
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
'Ecuador',
|
|
214
|
-
'El Salvador',
|
|
215
|
-
'Panama',
|
|
216
|
-
'East Timor',
|
|
217
|
-
'Zimbabwe',
|
|
218
|
-
'Micronesia',
|
|
219
|
-
'Marshall Islands',
|
|
220
|
-
'Palau',
|
|
221
|
-
'Turks and Caicos Islands',
|
|
222
|
-
'British Virgin Islands',
|
|
223
|
-
'Caribbean Netherlands',
|
|
224
|
-
'Bermuda',
|
|
225
|
-
'Bahamas',
|
|
226
|
-
'Puerto Rico',
|
|
227
|
-
'Guam',
|
|
228
|
-
'Northern Mariana Islands',
|
|
229
|
-
'American Samoa',
|
|
230
|
-
'U.S. Virgin Islands',
|
|
231
|
-
],
|
|
181
|
+
countries:
|
|
182
|
+
"Saudi Arabia Cape Verde Serbia Haiti Suriname Israel Slovakia Guadeloupe Namibia Uzbekistan Singapore Macao Maldives Ukraine Ethiopia Marshall Islands Netherlands Lithuania Uruguay Ecuador Falkland Islands Guernsey Hungary Argentina Kuwait Japan Cayman Islands South Africa Palau Moldova Montenegro Turkey Nauru Ireland Bermuda Jersey Algeria United States Samoa Uganda Vatican City Honduras Cocos (Keeling) Islands Côte d'Ivoire Macedonia, Former Yugoslav Republic of Kazakhstan Malta Solomon Islands Gabon Andorra Canada Faroe Islands Sao Tome and Principe Barbados Gibraltar French Polynesia Vietnam Bahamas Taiwan United Arab Emirates Mozambique Armenia Kiribati Panama Saint Kitts and Nevis Estonia Micronesia, Federated States of Mongolia China Niger Isle of Man Malaysia Guyana Senegal Germany Kyrgyzstan Greenland Albania Dominican Republic Hong Kong Luxembourg Morocco Norfolk Island Turks and Caicos Islands Rwanda Grenada Venezuela Gambia Seychelles Oman Antigua and Barbuda Papua New Guinea Colombia Sri Lanka Wallis and Futuna Anguilla Tanzania Kenya Bhutan Laos Fiji Australia Qatar Belgium Réunion Nicaragua El Salvador Slovenia New Caledonia Niue South Korea Guinea-Bissau Austria Cook Islands Spain Portugal Tonga Trinidad and Tobago Philippines Croatia Mauritania Finland Angola Saint Helena Switzerland Sierra Leone Costa Rica Mexico French Guiana Guatemala Cambodia Botswana Peru Cyprus Brunei Darussalam Bahrain Jamaica Paraguay Poland Tunisia Myanmar Burkina Faso Denmark Lesotho Zambia New Zealand Liberia Romania Dominica Saint Lucia Saint Pierre and Miquelon Mali United Kingdom Malawi Egypt Bulgaria Czech Republic Nepal Lebanon Guinea France Norway Puerto Rico Tuvalu Tajikistan Martinique San Marino Georgia Timor-Leste British Virgin Islands Montserrat Vanuatu Iceland Italy Saint Vincent and the Grenadines Thailand Sweden Indonesia American Samoa Bosnia and Herzegovina Monaco Benin Ghana Greece Mauritius Bangladesh Christmas Island Azerbaijan Chile Mayotte Liechtenstein Latvia Aruba Åland Islands Bolivia",
|
|
232
183
|
},
|
|
233
184
|
{
|
|
234
185
|
value: 5,
|
|
235
186
|
label: 'DOP',
|
|
236
187
|
currency: 'dop',
|
|
188
|
+
countries: 'Dop',
|
|
237
189
|
},
|
|
238
190
|
{
|
|
239
191
|
value: 6,
|
|
240
192
|
label: 'UZS',
|
|
241
193
|
currency: 'uzs',
|
|
194
|
+
countries: 'Uzs',
|
|
242
195
|
},
|
|
243
196
|
{
|
|
244
197
|
value: 7,
|
|
245
198
|
label: 'TTD',
|
|
246
199
|
currency: 'ttd',
|
|
200
|
+
countries: 'Ttd',
|
|
247
201
|
},
|
|
248
202
|
{ header: 'All currencies' },
|
|
249
203
|
{
|
|
250
204
|
currency: 'aed',
|
|
251
205
|
value: 'AED',
|
|
252
206
|
label: 'AED',
|
|
253
|
-
|
|
207
|
+
searchable: 'United Arab Emirates',
|
|
254
208
|
},
|
|
255
209
|
{
|
|
256
210
|
currency: 'aud',
|
|
257
211
|
value: 'AUD',
|
|
258
212
|
label: 'AUD',
|
|
259
213
|
note: 'Australian dollar',
|
|
260
|
-
|
|
214
|
+
searchable: 'Australia',
|
|
215
|
+
classNames: {},
|
|
261
216
|
secondary: '',
|
|
262
217
|
icon: null,
|
|
218
|
+
selected: false,
|
|
263
219
|
},
|
|
264
220
|
{
|
|
265
221
|
currency: 'bgn',
|
|
266
222
|
value: 'BGN',
|
|
267
223
|
label: 'BGN',
|
|
268
224
|
note: 'Bulgarian lev',
|
|
269
|
-
|
|
225
|
+
searchable: 'Bulgaria',
|
|
226
|
+
classNames: {},
|
|
270
227
|
secondary: '',
|
|
271
228
|
icon: null,
|
|
229
|
+
selected: false,
|
|
272
230
|
},
|
|
273
231
|
{
|
|
274
232
|
currency: 'brl',
|
|
275
233
|
value: 'BRL',
|
|
276
234
|
label: 'BRL',
|
|
277
235
|
note: 'Brazilian real',
|
|
278
|
-
|
|
236
|
+
searchable: 'Brazil',
|
|
237
|
+
classNames: {},
|
|
279
238
|
secondary: '',
|
|
280
239
|
icon: null,
|
|
240
|
+
selected: false,
|
|
281
241
|
},
|
|
282
242
|
{
|
|
283
|
-
currency:
|
|
243
|
+
currency: null,
|
|
284
244
|
value: 'USD',
|
|
285
245
|
label: 'USD',
|
|
286
246
|
note: 'United States dollar - Outside of the US',
|
|
287
|
-
|
|
247
|
+
searchable: 'United States',
|
|
248
|
+
classNames: {},
|
|
288
249
|
secondary: '',
|
|
289
250
|
icon: <GlobeIcon />,
|
|
251
|
+
selected: false,
|
|
290
252
|
},
|
|
291
253
|
]}
|
|
292
|
-
onChange={(
|
|
293
|
-
if (isSelectOptionItem(option)) {
|
|
294
|
-
setSelected(option);
|
|
295
|
-
}
|
|
296
|
-
}}
|
|
254
|
+
onChange={(v) => setSelected(v)}
|
|
297
255
|
/>
|
|
298
256
|
);
|
|
299
257
|
};
|
|
300
258
|
|
|
301
259
|
export const AdvancedSearch = () => {
|
|
302
260
|
const [searchValue, setSearchValue] = useState('');
|
|
303
|
-
const [selected, setSelected] = useState
|
|
261
|
+
const [selected, setSelected] = useState({
|
|
304
262
|
value: 0,
|
|
305
263
|
label: 'A thing',
|
|
306
264
|
note: 'with a note',
|
|
@@ -308,7 +266,7 @@ export const AdvancedSearch = () => {
|
|
|
308
266
|
|
|
309
267
|
const size = select('size', ['sm', 'md', 'lg'], 'md');
|
|
310
268
|
const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
|
|
311
|
-
const dropdownWidth = select('dropdownWidth', [
|
|
269
|
+
const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
|
|
312
270
|
|
|
313
271
|
const id = text('id', 'advanced-search-button');
|
|
314
272
|
const placeholder = text('placeholder', 'placeholder');
|
|
@@ -360,19 +318,15 @@ export const AdvancedSearch = () => {
|
|
|
360
318
|
label: 'A thing with searchable alternatives',
|
|
361
319
|
searchStrings: ['abbreviation', 'acronym', 'nickname'],
|
|
362
320
|
},
|
|
363
|
-
].filter((option) => option.label
|
|
364
|
-
onChange={(
|
|
365
|
-
if (isSelectOptionItem(option)) {
|
|
366
|
-
setSelected(option);
|
|
367
|
-
}
|
|
368
|
-
}}
|
|
321
|
+
].filter((option) => option.label && option.label.toLowerCase().includes(searchValue))}
|
|
322
|
+
onChange={(v) => setSelected(v)}
|
|
369
323
|
onSearchChange={(v) => setSearchValue(v)}
|
|
370
324
|
/>
|
|
371
325
|
);
|
|
372
326
|
};
|
|
373
327
|
|
|
374
328
|
export const SearchingLargeLists = () => {
|
|
375
|
-
const [selected, setSelected] = useState
|
|
329
|
+
const [selected, setSelected] = useState({
|
|
376
330
|
value: 'option1',
|
|
377
331
|
label: 'Option 1',
|
|
378
332
|
secondary: 'Here we have a description describing option 1',
|
|
@@ -380,7 +334,7 @@ export const SearchingLargeLists = () => {
|
|
|
380
334
|
|
|
381
335
|
const size = select('size', ['sm', 'md', 'lg'], 'md');
|
|
382
336
|
const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
|
|
383
|
-
const dropdownWidth = select('dropdownWidth', [
|
|
337
|
+
const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
|
|
384
338
|
|
|
385
339
|
const id = text('id', 'large-list-button');
|
|
386
340
|
const placeholder = text('placeholder', 'Placeholder text');
|
|
@@ -405,16 +359,12 @@ export const SearchingLargeLists = () => {
|
|
|
405
359
|
required={required}
|
|
406
360
|
searchPlaceholder="Search placeholder"
|
|
407
361
|
dropdownUp={dropdownUp}
|
|
408
|
-
options={new Array(1500).fill(
|
|
362
|
+
options={new Array(1500).fill().map((x, index) => ({
|
|
409
363
|
value: `option${index + 1}`,
|
|
410
364
|
label: `Option ${index + 1}`,
|
|
411
365
|
secondary: `Here we have a description describing option ${index + 1}`,
|
|
412
366
|
}))}
|
|
413
|
-
onChange={(
|
|
414
|
-
if (isSelectOptionItem(option)) {
|
|
415
|
-
setSelected(option);
|
|
416
|
-
}
|
|
417
|
-
}}
|
|
367
|
+
onChange={(v) => setSelected(v)}
|
|
418
368
|
/>
|
|
419
369
|
);
|
|
420
370
|
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
function supportsTouchEvents() {
|
|
2
2
|
const onTouchStartIsDefined = typeof window !== 'undefined' && window.ontouchstart !== undefined;
|
|
3
3
|
const maxTouchPointsIsDefined = typeof navigator !== 'undefined' && navigator.maxTouchPoints;
|
|
4
|
+
const documentTouchIsDefined =
|
|
5
|
+
typeof window !== 'undefined' &&
|
|
6
|
+
window.DocumentTouch &&
|
|
7
|
+
document instanceof window.DocumentTouch;
|
|
4
8
|
|
|
5
|
-
return !!(onTouchStartIsDefined || maxTouchPointsIsDefined);
|
|
9
|
+
return !!(onTouchStartIsDefined || maxTouchPointsIsDefined || documentTouchIsDefined);
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
function userAgentSuggestsTouchDevice() {
|
|
@@ -17,7 +21,7 @@ function userAgentSuggestsTouchDevice() {
|
|
|
17
21
|
];
|
|
18
22
|
const matchString = sampleTouchDevices.map((device) => `(${device})`).join('|');
|
|
19
23
|
const regex = new RegExp(matchString, 'gi');
|
|
20
|
-
return typeof navigator !== 'undefined' && !!
|
|
24
|
+
return typeof navigator !== 'undefined' && !!navigator.userAgent.match(regex);
|
|
21
25
|
}
|
|
22
26
|
// Important: this is not fool-proof! It gives false positives and negatives, and will be outdated.
|
|
23
27
|
// Only use this for small vanity changes where it still works either way.
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ControlType, Priority, Size, Type } from '../../common';
|
|
2
|
-
import { logActionRequired, logActionRequiredIf } from '../../utilities';
|
|
3
|
-
|
|
4
|
-
const deprecatedTypeMap: Record<Type, ControlType> = {
|
|
5
|
-
[Type.PRIMARY]: ControlType.ACCENT,
|
|
6
|
-
[Type.SECONDARY]: ControlType.ACCENT,
|
|
7
|
-
[Type.LINK]: ControlType.ACCENT,
|
|
8
|
-
[Type.PAY]: ControlType.POSITIVE,
|
|
9
|
-
[Type.DANGER]: ControlType.NEGATIVE,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type OldTypeKeys = Type.DANGER | Type.LINK | Type.SECONDARY;
|
|
13
|
-
const oldTypePriorityMap: Record<OldTypeKeys, Priority> = {
|
|
14
|
-
[Type.DANGER]: Priority.SECONDARY,
|
|
15
|
-
[Type.LINK]: Priority.TERTIARY,
|
|
16
|
-
[Type.SECONDARY]: Priority.SECONDARY,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const deprecatedTypeMapMessage = {
|
|
20
|
-
[Type.DANGER]: 'Type.NEGATIVE',
|
|
21
|
-
[Type.LINK]: 'ControlType.ACCENT with priority Priority.TERTIARY',
|
|
22
|
-
[Type.PAY]: 'ControlType.POSITIVE',
|
|
23
|
-
[Type.PRIMARY]: 'ControlType.ACCENT',
|
|
24
|
-
[Type.SECONDARY]: 'ControlType.ACCENT with priority Priority.SECONDARY',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const deprecatedTypes = Object.keys(deprecatedTypeMap);
|
|
28
|
-
|
|
29
|
-
type EstablishNewTypeType = (
|
|
30
|
-
originalType: Type | (string & Record<never, never>) | null,
|
|
31
|
-
) => `${ControlType}` | string | null;
|
|
32
|
-
|
|
33
|
-
export const establishNewType: EstablishNewTypeType = (originalType) =>
|
|
34
|
-
originalType && originalType in deprecatedTypeMap
|
|
35
|
-
? deprecatedTypeMap[originalType as Type]
|
|
36
|
-
: originalType;
|
|
37
|
-
|
|
38
|
-
type EstablishNewPriorityType = (
|
|
39
|
-
originalPriority?: Priority | (string & Record<never, never>) | null,
|
|
40
|
-
originalType?: OldTypeKeys | (string & Record<never, never>) | null,
|
|
41
|
-
) => `${ControlType}` | string | null | undefined;
|
|
42
|
-
|
|
43
|
-
export const establishNewPriority: EstablishNewPriorityType = (originalPriority, originalType) => {
|
|
44
|
-
const type = originalType ? establishNewType(originalType) : '';
|
|
45
|
-
|
|
46
|
-
// The old SECONDARY and LINK types now map to priorities. If they're still using one of
|
|
47
|
-
// these old types, ignore whatever priority they've passed and use this instead.
|
|
48
|
-
if (originalType && originalType in oldTypePriorityMap) {
|
|
49
|
-
return oldTypePriorityMap[originalType as OldTypeKeys];
|
|
50
|
-
}
|
|
51
|
-
// Only ControlType.ACCENT supports tertiary styles
|
|
52
|
-
if (originalPriority === Priority.TERTIARY && type !== ControlType.ACCENT) {
|
|
53
|
-
return Priority.SECONDARY;
|
|
54
|
-
}
|
|
55
|
-
return originalPriority;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
type DeprecatedTypeMapMessageType = keyof typeof deprecatedTypeMapMessage;
|
|
59
|
-
type LogDeprecationNoticesType = (params: {
|
|
60
|
-
size: `${Size}`;
|
|
61
|
-
type: DeprecatedTypeMapMessageType | (string & Record<never, never>) | null;
|
|
62
|
-
}) => void;
|
|
63
|
-
export const logDeprecationNotices: LogDeprecationNoticesType = ({ size, type }) => {
|
|
64
|
-
logActionRequiredIf(
|
|
65
|
-
'Button has deprecated the `Size.EXTRA_SMALL` value for the `size` prop. Please use Size.SMALL instead.',
|
|
66
|
-
size === Size.EXTRA_SMALL,
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
if (type && deprecatedTypes.includes(type) && type in deprecatedTypeMapMessage) {
|
|
70
|
-
logActionRequired(
|
|
71
|
-
`Button has deprecated the ${type} value for the \`type\` prop. Please update to ${deprecatedTypeMapMessage[type as DeprecatedTypeMapMessageType]}.`,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|