@transferwise/components 0.0.0-experimental-c41b5aa → 0.0.0-experimental-564532f

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 (47) hide show
  1. package/build/button/Button.js +1 -4
  2. package/build/button/Button.js.map +1 -1
  3. package/build/button/Button.messages.js.map +1 -1
  4. package/build/button/Button.messages.mjs.map +1 -1
  5. package/build/button/Button.mjs +1 -4
  6. package/build/button/Button.mjs.map +1 -1
  7. package/build/button/classMap.js.map +1 -1
  8. package/build/button/classMap.mjs.map +1 -1
  9. package/build/button/legacyUtils/legacyUtils.js +6 -5
  10. package/build/button/legacyUtils/legacyUtils.js.map +1 -1
  11. package/build/button/legacyUtils/legacyUtils.mjs +7 -6
  12. package/build/button/legacyUtils/legacyUtils.mjs.map +1 -1
  13. package/build/checkbox/Checkbox.js +1 -1
  14. package/build/checkbox/Checkbox.mjs +1 -1
  15. package/build/checkboxOption/CheckboxOption.js +1 -1
  16. package/build/checkboxOption/CheckboxOption.mjs +1 -1
  17. package/build/index.js +2 -2
  18. package/build/index.mjs +1 -1
  19. package/build/stepper/deviceDetection.js +2 -3
  20. package/build/stepper/deviceDetection.js.map +1 -1
  21. package/build/stepper/deviceDetection.mjs +2 -3
  22. package/build/stepper/deviceDetection.mjs.map +1 -1
  23. package/build/types/button/Button.d.ts +1 -1
  24. package/build/types/button/Button.d.ts.map +1 -1
  25. package/build/types/button/Button.messages.d.ts +7 -7
  26. package/build/types/button/Button.messages.d.ts.map +1 -1
  27. package/build/types/button/classMap.d.ts +10 -10
  28. package/build/types/button/classMap.d.ts.map +1 -1
  29. package/build/types/button/legacyUtils/index.d.ts +1 -1
  30. package/build/types/button/legacyUtils/index.d.ts.map +1 -1
  31. package/build/types/button/legacyUtils/legacyUtils.d.ts +20 -6
  32. package/build/types/button/legacyUtils/legacyUtils.d.ts.map +1 -1
  33. package/build/types/checkboxButton/index.d.ts +1 -1
  34. package/build/types/checkboxButton/index.d.ts.map +1 -1
  35. package/build/types/stepper/deviceDetection.d.ts +1 -1
  36. package/build/types/stepper/deviceDetection.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/button/Button.tsx +1 -4
  39. package/src/button/legacyUtils/legacyUtils.ts +74 -0
  40. package/src/flowNavigation/{FlowNavigation.story.js → FlowNavigation.story.tsx} +34 -16
  41. package/src/select/{Select.story.js → Select.story.tsx} +97 -47
  42. package/src/stepper/{deviceDetection.js → deviceDetection.ts} +2 -6
  43. package/src/button/legacyUtils/legacyUtils.js +0 -54
  44. /package/src/button/{Button.messages.js → Button.messages.ts} +0 -0
  45. /package/src/button/{classMap.js → classMap.ts} +0 -0
  46. /package/src/button/legacyUtils/{index.js → index.ts} +0 -0
  47. /package/src/checkboxButton/{index.js → index.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-c41b5aa",
3
+ "version": "0.0.0-experimental-564532f",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -45,7 +45,7 @@ type ButtonProps = CommonProps &
45
45
  };
46
46
 
47
47
  type AnchorProps = CommonProps &
48
- Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {
48
+ React.ComponentPropsWithRef<'a'> & {
49
49
  as?: 'a';
50
50
  };
51
51
 
@@ -72,12 +72,9 @@ const Button = forwardRef<ButtonReferenceType, Props>(
72
72
  ) => {
73
73
  const intl = useIntl();
74
74
 
75
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
76
75
  logDeprecationNotices({ size, type });
77
76
 
78
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
79
77
  const newType = establishNewType(type);
80
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
81
78
  const newPriority = establishNewPriority(priority, type);
82
79
 
83
80
  const classes = clsx(
@@ -0,0 +1,74 @@
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
+ };
@@ -24,6 +24,10 @@ const avatarProfiles = {
24
24
  Business: <BriefcaseIcon />,
25
25
  Profile: <ProfileIcon />,
26
26
  };
27
+ type ProfileTypeKeys = keyof typeof ProfileType;
28
+
29
+ const getAvatarProfile = (showAvatar: string) =>
30
+ showAvatar in avatarProfiles ? avatarProfiles[showAvatar as keyof typeof avatarProfiles] : null;
27
31
 
28
32
  export const Variants = () => {
29
33
  const [activeStep, setActiveStep] = useState(2);
@@ -32,7 +36,11 @@ export const Variants = () => {
32
36
  const showCloseButton = boolean('show closeButton', true);
33
37
  const showMobileBackButton = boolean('show mobile backButton', true);
34
38
  const done = boolean('done', false);
35
- const profileType = select('profileType', Object.keys(ProfileType));
39
+ const profileType: ProfileTypeKeys | undefined = select(
40
+ 'profileType',
41
+ Object.keys(ProfileType) as ProfileTypeKeys[],
42
+ undefined,
43
+ );
36
44
  const avatarURL = text(
37
45
  'avatarURL',
38
46
  'https://wise.com/web-art/assets/illustrations/heart-small@2x.webp',
@@ -44,7 +52,7 @@ export const Variants = () => {
44
52
  avatar={
45
53
  !showAvatar ? null : (
46
54
  <Avatar type={AvatarType.ICON} size={Size.MEDIUM}>
47
- {avatarProfiles[showAvatar]}
55
+ {getAvatarProfile(showAvatar)}
48
56
  </Avatar>
49
57
  )
50
58
  }
@@ -70,9 +78,11 @@ export const Variants = () => {
70
78
  onClick: () => setActiveStep(4),
71
79
  },
72
80
  ]}
73
- onClose={showCloseButton && (() => setClosed(true))}
81
+ onClose={showCloseButton ? () => setClosed(true) : undefined}
74
82
  onGoBack={
75
- showMobileBackButton && (() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0))
83
+ showMobileBackButton
84
+ ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)
85
+ : undefined
76
86
  }
77
87
  />
78
88
 
@@ -112,9 +122,11 @@ export const Variants = () => {
112
122
  onClick: () => setActiveStep(4),
113
123
  },
114
124
  ]}
115
- onClose={showCloseButton && (() => setClosed(true))}
125
+ onClose={showCloseButton ? () => setClosed(true) : undefined}
116
126
  onGoBack={
117
- showMobileBackButton && (() => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0))
127
+ showMobileBackButton
128
+ ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0)
129
+ : undefined
118
130
  }
119
131
  />
120
132
 
@@ -155,9 +167,11 @@ export const Variants = () => {
155
167
  onClick: () => setActiveStep(4),
156
168
  },
157
169
  ]}
158
- onClose={showCloseButton && (() => setClosed(true))}
170
+ onClose={showCloseButton ? () => setClosed(true) : undefined}
159
171
  onGoBack={
160
- showMobileBackButton && (() => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0))
172
+ showMobileBackButton
173
+ ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0)
174
+ : undefined
161
175
  }
162
176
  />
163
177
 
@@ -171,9 +185,11 @@ export const Variants = () => {
171
185
  { label: 'Review', hoverLabel: 'Antonio Dozortevo', onClick: () => setActiveStep(1) },
172
186
  { label: 'Pay', hoverLabel: 'Enrico Gusso', onClick: () => setActiveStep(2) },
173
187
  ]}
174
- onClose={showCloseButton && (() => setClosed(true))}
188
+ onClose={showCloseButton ? () => setClosed(true) : undefined}
175
189
  onGoBack={
176
- showMobileBackButton && (() => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0))
190
+ showMobileBackButton
191
+ ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0)
192
+ : undefined
177
193
  }
178
194
  />
179
195
 
@@ -216,7 +232,7 @@ export const SendFlow = () => {
216
232
  ...(activeStep > 3 && { onClick: handleStepClick(3) }),
217
233
  },
218
234
  ];
219
- function handleStepClick(step) {
235
+ function handleStepClick(step: number) {
220
236
  return () => {
221
237
  setActiveStep(step);
222
238
  };
@@ -268,16 +284,18 @@ export const WithOverlayHeaderComparison = () => {
268
284
  avatar={
269
285
  showAvatar ? (
270
286
  <Avatar type={AvatarType.ICON} size={Size.MEDIUM}>
271
- {avatarProfiles[showAvatar]}
287
+ {getAvatarProfile(showAvatar)}
272
288
  </Avatar>
273
289
  ) : null
274
290
  }
275
291
  activeStep={activeStep}
276
292
  done={done}
277
293
  steps={[]}
278
- onClose={showCloseButton && (() => setClosed(true))}
294
+ onClose={showCloseButton ? () => setClosed(true) : undefined}
279
295
  onGoBack={
280
- showMobileBackButton && (() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0))
296
+ showMobileBackButton
297
+ ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)
298
+ : undefined
281
299
  }
282
300
  />
283
301
  </div>
@@ -286,11 +304,11 @@ export const WithOverlayHeaderComparison = () => {
286
304
  avatar={
287
305
  showAvatar ? (
288
306
  <Avatar type={AvatarType.ICON} size={Size.MEDIUM}>
289
- {avatarProfiles[showAvatar]}
307
+ {getAvatarProfile(showAvatar)}
290
308
  </Avatar>
291
309
  ) : null
292
310
  }
293
- onClose={showCloseButton && (() => setClosed(true))}
311
+ onClose={showCloseButton ? () => setClosed(true) : undefined}
294
312
  />
295
313
  </div>
296
314
  </>
@@ -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 from './Select';
5
+ import Select, { SelectItem, SelectOptionItem } from './Select';
6
6
 
7
7
  export default {
8
8
  component: Select,
@@ -17,8 +17,16 @@ 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
+
20
28
  export const Basic = () => {
21
- const [selected, setSelected] = useState({
29
+ const [selected, setSelected] = useState<SelectOptionItem>({
22
30
  value: 0,
23
31
  label: 'A thing',
24
32
  note: 'with a note',
@@ -26,7 +34,7 @@ export const Basic = () => {
26
34
 
27
35
  const size = select('size', ['sm', 'md', 'lg'], 'md');
28
36
  const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
29
- const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
37
+ const dropdownWidth = select('dropdownWidth', [undefined, 'sm', 'md', 'lg'], 'md');
30
38
 
31
39
  const id = text('id', 'basic-button');
32
40
  const placeholder = text('placeholder', 'Placeholder text');
@@ -35,14 +43,12 @@ export const Basic = () => {
35
43
  const required = boolean('required', false);
36
44
  const dropdownUp = boolean('dropdownUp', false);
37
45
  const disabled = boolean('disabled', false);
38
- const search = boolean('search', false);
39
- const hasError = boolean('hasError', false);
46
+ const search = boolean('search', true);
40
47
 
41
48
  return (
42
49
  <Select
43
50
  id={id}
44
51
  size={size}
45
- classNames={hasError ? 'has-error' : ''}
46
52
  placeholder={placeholder}
47
53
  dropdownRight={dropdownRight}
48
54
  dropdownWidth={dropdownWidth}
@@ -108,13 +114,17 @@ export const Basic = () => {
108
114
  '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',
109
115
  },
110
116
  ]}
111
- onChange={(v) => setSelected(v)}
117
+ onChange={(option) => {
118
+ if (isSelectOptionItem(option)) {
119
+ setSelected(option);
120
+ }
121
+ }}
112
122
  />
113
123
  );
114
124
  };
115
125
 
116
126
  export const CustomSearchFunction = () => {
117
- const [selected, setSelected] = useState({
127
+ const [selected, setSelected] = useState<SelectOptionItem>({
118
128
  value: 1,
119
129
  label: 'EUR',
120
130
  currency: 'EUR',
@@ -122,7 +132,7 @@ export const CustomSearchFunction = () => {
122
132
 
123
133
  const size = select('size', ['sm', 'md', 'lg'], 'md');
124
134
  const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
125
- const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
135
+ const dropdownWidth = select('dropdownWidth', [undefined, 'sm', 'md', 'lg'], 'md');
126
136
 
127
137
  const id = text('id', 'custom-search-button');
128
138
  const placeholder = text('placeholder', 'placeholder');
@@ -144,12 +154,7 @@ export const CustomSearchFunction = () => {
144
154
  block={block}
145
155
  selected={selected}
146
156
  disabled={disabled}
147
- search={
148
- search
149
- ? (option, keyword) =>
150
- option.countries && option.countries.toLowerCase().includes(keyword.toLowerCase())
151
- : false
152
- }
157
+ search={search}
153
158
  required={required}
154
159
  searchPlaceholder="Search placeholder"
155
160
  dropdownUp={dropdownUp}
@@ -159,106 +164,143 @@ export const CustomSearchFunction = () => {
159
164
  value: 1,
160
165
  label: 'EUR',
161
166
  currency: 'EUR',
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',
167
+ searchStrings: [
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
+ ],
164
194
  },
165
195
  {
166
196
  value: 2,
167
197
  label: 'GBP',
168
198
  currency: 'GBP',
169
- countries: 'Isle of Man United Kingdom',
199
+ searchStrings: ['Isle of Man', 'United Kingdom'],
170
200
  },
171
201
  {
172
202
  value: 3,
173
203
  label: 'INR',
174
204
  currency: 'INR',
175
- countries: 'India',
205
+ searchStrings: ['India'],
176
206
  },
177
207
  {
178
208
  value: 4,
179
209
  label: 'USD',
180
210
  currency: 'USD',
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",
211
+ searchStrings: [
212
+ 'United States',
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
+ ],
183
232
  },
184
233
  {
185
234
  value: 5,
186
235
  label: 'DOP',
187
236
  currency: 'dop',
188
- countries: 'Dop',
189
237
  },
190
238
  {
191
239
  value: 6,
192
240
  label: 'UZS',
193
241
  currency: 'uzs',
194
- countries: 'Uzs',
195
242
  },
196
243
  {
197
244
  value: 7,
198
245
  label: 'TTD',
199
246
  currency: 'ttd',
200
- countries: 'Ttd',
201
247
  },
202
248
  { header: 'All currencies' },
203
249
  {
204
250
  currency: 'aed',
205
251
  value: 'AED',
206
252
  label: 'AED',
207
- searchable: 'United Arab Emirates',
253
+ searchStrings: ['United Arab Emirates'],
208
254
  },
209
255
  {
210
256
  currency: 'aud',
211
257
  value: 'AUD',
212
258
  label: 'AUD',
213
259
  note: 'Australian dollar',
214
- searchable: 'Australia',
215
- classNames: {},
260
+ searchStrings: ['Australia'],
216
261
  secondary: '',
217
262
  icon: null,
218
- selected: false,
219
263
  },
220
264
  {
221
265
  currency: 'bgn',
222
266
  value: 'BGN',
223
267
  label: 'BGN',
224
268
  note: 'Bulgarian lev',
225
- searchable: 'Bulgaria',
226
- classNames: {},
269
+ searchStrings: ['Bulgaria'],
227
270
  secondary: '',
228
271
  icon: null,
229
- selected: false,
230
272
  },
231
273
  {
232
274
  currency: 'brl',
233
275
  value: 'BRL',
234
276
  label: 'BRL',
235
277
  note: 'Brazilian real',
236
- searchable: 'Brazil',
237
- classNames: {},
278
+ searchStrings: ['Brazil'],
238
279
  secondary: '',
239
280
  icon: null,
240
- selected: false,
241
281
  },
242
282
  {
243
- currency: null,
283
+ currency: undefined,
244
284
  value: 'USD',
245
285
  label: 'USD',
246
286
  note: 'United States dollar - Outside of the US',
247
- searchable: 'United States',
248
- classNames: {},
287
+ searchStrings: ['United States'],
249
288
  secondary: '',
250
289
  icon: <GlobeIcon />,
251
- selected: false,
252
290
  },
253
291
  ]}
254
- onChange={(v) => setSelected(v)}
292
+ onChange={(option) => {
293
+ if (isSelectOptionItem(option)) {
294
+ setSelected(option);
295
+ }
296
+ }}
255
297
  />
256
298
  );
257
299
  };
258
300
 
259
301
  export const AdvancedSearch = () => {
260
302
  const [searchValue, setSearchValue] = useState('');
261
- const [selected, setSelected] = useState({
303
+ const [selected, setSelected] = useState<SelectOptionItem>({
262
304
  value: 0,
263
305
  label: 'A thing',
264
306
  note: 'with a note',
@@ -266,7 +308,7 @@ export const AdvancedSearch = () => {
266
308
 
267
309
  const size = select('size', ['sm', 'md', 'lg'], 'md');
268
310
  const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
269
- const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
311
+ const dropdownWidth = select('dropdownWidth', [undefined, 'sm', 'md', 'lg'], 'md');
270
312
 
271
313
  const id = text('id', 'advanced-search-button');
272
314
  const placeholder = text('placeholder', 'placeholder');
@@ -318,15 +360,19 @@ export const AdvancedSearch = () => {
318
360
  label: 'A thing with searchable alternatives',
319
361
  searchStrings: ['abbreviation', 'acronym', 'nickname'],
320
362
  },
321
- ].filter((option) => option.label && option.label.toLowerCase().includes(searchValue))}
322
- onChange={(v) => setSelected(v)}
363
+ ].filter((option) => option.label?.toLowerCase().includes(searchValue))}
364
+ onChange={(option) => {
365
+ if (isSelectOptionItem(option)) {
366
+ setSelected(option);
367
+ }
368
+ }}
323
369
  onSearchChange={(v) => setSearchValue(v)}
324
370
  />
325
371
  );
326
372
  };
327
373
 
328
374
  export const SearchingLargeLists = () => {
329
- const [selected, setSelected] = useState({
375
+ const [selected, setSelected] = useState<SelectOptionItem>({
330
376
  value: 'option1',
331
377
  label: 'Option 1',
332
378
  secondary: 'Here we have a description describing option 1',
@@ -334,7 +380,7 @@ export const SearchingLargeLists = () => {
334
380
 
335
381
  const size = select('size', ['sm', 'md', 'lg'], 'md');
336
382
  const dropdownRight = select('dropdownRight', ['xs', 'sm', 'md', 'lg', 'xl'], 'md');
337
- const dropdownWidth = select('dropdownWidth', [null, 'sm', 'md', 'lg'], 'md');
383
+ const dropdownWidth = select('dropdownWidth', [undefined, 'sm', 'md', 'lg'], 'md');
338
384
 
339
385
  const id = text('id', 'large-list-button');
340
386
  const placeholder = text('placeholder', 'Placeholder text');
@@ -359,12 +405,16 @@ export const SearchingLargeLists = () => {
359
405
  required={required}
360
406
  searchPlaceholder="Search placeholder"
361
407
  dropdownUp={dropdownUp}
362
- options={new Array(1500).fill().map((x, index) => ({
408
+ options={new Array(1500).fill(null).map((x, index) => ({
363
409
  value: `option${index + 1}`,
364
410
  label: `Option ${index + 1}`,
365
411
  secondary: `Here we have a description describing option ${index + 1}`,
366
412
  }))}
367
- onChange={(v) => setSelected(v)}
413
+ onChange={(option) => {
414
+ if (isSelectOptionItem(option)) {
415
+ setSelected(option);
416
+ }
417
+ }}
368
418
  />
369
419
  );
370
420
  };
@@ -1,12 +1,8 @@
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;
8
4
 
9
- return !!(onTouchStartIsDefined || maxTouchPointsIsDefined || documentTouchIsDefined);
5
+ return !!(onTouchStartIsDefined || maxTouchPointsIsDefined);
10
6
  }
11
7
 
12
8
  function userAgentSuggestsTouchDevice() {
@@ -21,7 +17,7 @@ function userAgentSuggestsTouchDevice() {
21
17
  ];
22
18
  const matchString = sampleTouchDevices.map((device) => `(${device})`).join('|');
23
19
  const regex = new RegExp(matchString, 'gi');
24
- return typeof navigator !== 'undefined' && !!navigator.userAgent.match(regex);
20
+ return typeof navigator !== 'undefined' && !!regex.test(navigator.userAgent);
25
21
  }
26
22
  // Important: this is not fool-proof! It gives false positives and negatives, and will be outdated.
27
23
  // Only use this for small vanity changes where it still works either way.
@@ -1,54 +0,0 @@
1
- import { ControlType, Priority, Size, Type } from '../../common';
2
- import { logActionRequiredIf } from '../../utilities';
3
-
4
- const deprecatedTypeMap = {
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
- const oldTypePriorityMap = {
13
- [Type.DANGER]: Priority.SECONDARY,
14
- [Type.LINK]: Priority.TERTIARY,
15
- [Type.SECONDARY]: Priority.SECONDARY,
16
- };
17
-
18
- const deprecatedTypeMapMessage = {
19
- [Type.DANGER]: 'Type.NEGATIVE',
20
- [Type.LINK]: 'ControlType.ACCENT with priority Priority.TERTIARY',
21
- [Type.PAY]: 'ControlType.POSITIVE',
22
- [Type.PRIMARY]: 'ControlType.ACCENT',
23
- [Type.SECONDARY]: 'ControlType.ACCENT with priority Priority.SECONDARY',
24
- };
25
-
26
- const deprecatedTypes = Object.keys(deprecatedTypeMap);
27
-
28
- export const establishNewType = (originalType) => deprecatedTypeMap[originalType] || originalType;
29
-
30
- export const establishNewPriority = (originalPriority, originalType) => {
31
- const type = establishNewType(originalType);
32
-
33
- // The old SECONDARY and LINK types now map to priorities. If they're still using one of
34
- // these old types, ignore whatever priority they've passed and use this instead.
35
- if (oldTypePriorityMap[originalType]) {
36
- return oldTypePriorityMap[originalType];
37
- }
38
- // Only ControlType.ACCENT supports tertiary styles
39
- if (originalPriority === Priority.TERTIARY && type !== ControlType.ACCENT) {
40
- return Priority.SECONDARY;
41
- }
42
- return originalPriority;
43
- };
44
-
45
- export const logDeprecationNotices = ({ size, type }) => {
46
- logActionRequiredIf(
47
- 'Button has deprecated the `Size.EXTRA_SMALL` value for the `size` prop. Please use Size.SMALL instead.',
48
- size === Size.EXTRA_SMALL,
49
- );
50
- logActionRequiredIf(
51
- `Button has deprecated the ${type} value for the \`type\` prop. Please update to ${deprecatedTypeMapMessage[type]}.`,
52
- deprecatedTypes.includes(type),
53
- );
54
- };
File without changes
File without changes
File without changes