@transferwise/components 0.0.0-experimental-adc1a81 → 0.0.0-experimental-046a59f

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 (62) hide show
  1. package/build/button/Button.js +4 -1
  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 +4 -1
  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 +5 -6
  10. package/build/button/legacyUtils/legacyUtils.js.map +1 -1
  11. package/build/button/legacyUtils/legacyUtils.mjs +6 -7
  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/instructionsList/InstructionsList.js +4 -3
  20. package/build/instructionsList/InstructionsList.js.map +1 -1
  21. package/build/instructionsList/InstructionsList.mjs +4 -3
  22. package/build/instructionsList/InstructionsList.mjs.map +1 -1
  23. package/build/stepper/deviceDetection.js +3 -2
  24. package/build/stepper/deviceDetection.js.map +1 -1
  25. package/build/stepper/deviceDetection.mjs +3 -2
  26. package/build/stepper/deviceDetection.mjs.map +1 -1
  27. package/build/types/button/Button.d.ts.map +1 -1
  28. package/build/types/button/Button.messages.d.ts +7 -7
  29. package/build/types/button/Button.messages.d.ts.map +1 -1
  30. package/build/types/button/classMap.d.ts +10 -10
  31. package/build/types/button/classMap.d.ts.map +1 -1
  32. package/build/types/button/legacyUtils/index.d.ts +1 -1
  33. package/build/types/button/legacyUtils/index.d.ts.map +1 -1
  34. package/build/types/button/legacyUtils/legacyUtils.d.ts +6 -20
  35. package/build/types/button/legacyUtils/legacyUtils.d.ts.map +1 -1
  36. package/build/types/checkboxButton/index.d.ts +1 -1
  37. package/build/types/checkboxButton/index.d.ts.map +1 -1
  38. package/build/types/instructionsList/InstructionsList.d.ts.map +1 -1
  39. package/build/types/stepper/deviceDetection.d.ts +1 -1
  40. package/build/types/stepper/deviceDetection.d.ts.map +1 -1
  41. package/package.json +3 -3
  42. package/src/accordion/AccordionItem/__snapshots__/AccordionItem.spec.js.snap +4 -4
  43. package/src/avatarWrapper/__snapshots__/AvatarWrapper.spec.tsx.snap +8 -8
  44. package/src/button/Button.tsx +3 -0
  45. package/src/button/legacyUtils/legacyUtils.js +54 -0
  46. package/src/chips/__snapshots__/Chips.spec.tsx.snap +2 -2
  47. package/src/circularButton/__snapshots__/CircularButton.spec.tsx.snap +20 -20
  48. package/src/common/bottomSheet/__snapshots__/BottomSheet.spec.tsx.snap +2 -2
  49. package/src/common/closeButton/__snapshots__/CloseButton.spec.tsx.snap +2 -2
  50. package/src/drawer/__snapshots__/Drawer.rtl.spec.tsx.snap +2 -2
  51. package/src/flowNavigation/{FlowNavigation.story.tsx → FlowNavigation.story.js} +16 -34
  52. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +4 -4
  53. package/src/instructionsList/InstructionsList.spec.tsx +21 -5
  54. package/src/instructionsList/InstructionsList.tsx +11 -3
  55. package/src/overlayHeader/__snapshots__/OverlayHeader.spec.tsx.snap +2 -2
  56. package/src/select/{Select.story.tsx → Select.story.js} +47 -97
  57. package/src/stepper/{deviceDetection.ts → deviceDetection.js} +6 -2
  58. package/src/button/legacyUtils/legacyUtils.ts +0 -73
  59. /package/src/button/{Button.messages.ts → Button.messages.js} +0 -0
  60. /package/src/button/{classMap.ts → classMap.js} +0 -0
  61. /package/src/button/legacyUtils/{index.ts → index.js} +0 -0
  62. /package/src/checkboxButton/{index.ts → index.js} +0 -0
@@ -24,10 +24,6 @@ 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;
31
27
 
32
28
  export const Variants = () => {
33
29
  const [activeStep, setActiveStep] = useState(2);
@@ -36,11 +32,7 @@ export const Variants = () => {
36
32
  const showCloseButton = boolean('show closeButton', true);
37
33
  const showMobileBackButton = boolean('show mobile backButton', true);
38
34
  const done = boolean('done', false);
39
- const profileType: ProfileTypeKeys | undefined = select(
40
- 'profileType',
41
- Object.keys(ProfileType) as ProfileTypeKeys[],
42
- undefined,
43
- );
35
+ const profileType = select('profileType', Object.keys(ProfileType));
44
36
  const avatarURL = text(
45
37
  'avatarURL',
46
38
  'https://wise.com/web-art/assets/illustrations/heart-small@2x.webp',
@@ -52,7 +44,7 @@ export const Variants = () => {
52
44
  avatar={
53
45
  !showAvatar ? null : (
54
46
  <Avatar type={AvatarType.ICON} size={Size.MEDIUM}>
55
- {getAvatarProfile(showAvatar)}
47
+ {avatarProfiles[showAvatar]}
56
48
  </Avatar>
57
49
  )
58
50
  }
@@ -78,11 +70,9 @@ export const Variants = () => {
78
70
  onClick: () => setActiveStep(4),
79
71
  },
80
72
  ]}
81
- onClose={showCloseButton ? () => setClosed(true) : undefined}
73
+ onClose={showCloseButton && (() => setClosed(true))}
82
74
  onGoBack={
83
- showMobileBackButton
84
- ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)
85
- : undefined
75
+ showMobileBackButton && (() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0))
86
76
  }
87
77
  />
88
78
 
@@ -122,11 +112,9 @@ export const Variants = () => {
122
112
  onClick: () => setActiveStep(4),
123
113
  },
124
114
  ]}
125
- onClose={showCloseButton ? () => setClosed(true) : undefined}
115
+ onClose={showCloseButton && (() => setClosed(true))}
126
116
  onGoBack={
127
- showMobileBackButton
128
- ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0)
129
- : undefined
117
+ showMobileBackButton && (() => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0))
130
118
  }
131
119
  />
132
120
 
@@ -167,11 +155,9 @@ export const Variants = () => {
167
155
  onClick: () => setActiveStep(4),
168
156
  },
169
157
  ]}
170
- onClose={showCloseButton ? () => setClosed(true) : undefined}
158
+ onClose={showCloseButton && (() => setClosed(true))}
171
159
  onGoBack={
172
- showMobileBackButton
173
- ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0)
174
- : undefined
160
+ showMobileBackButton && (() => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0))
175
161
  }
176
162
  />
177
163
 
@@ -185,11 +171,9 @@ export const Variants = () => {
185
171
  { label: 'Review', hoverLabel: 'Antonio Dozortevo', onClick: () => setActiveStep(1) },
186
172
  { label: 'Pay', hoverLabel: 'Enrico Gusso', onClick: () => setActiveStep(2) },
187
173
  ]}
188
- onClose={showCloseButton ? () => setClosed(true) : undefined}
174
+ onClose={showCloseButton && (() => setClosed(true))}
189
175
  onGoBack={
190
- showMobileBackButton
191
- ? () => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0)
192
- : undefined
176
+ showMobileBackButton && (() => setActiveStep(activeStep - 1 > 0 ? activeStep - 1 : 0))
193
177
  }
194
178
  />
195
179
 
@@ -232,7 +216,7 @@ export const SendFlow = () => {
232
216
  ...(activeStep > 3 && { onClick: handleStepClick(3) }),
233
217
  },
234
218
  ];
235
- function handleStepClick(step: number) {
219
+ function handleStepClick(step) {
236
220
  return () => {
237
221
  setActiveStep(step);
238
222
  };
@@ -284,18 +268,16 @@ export const WithOverlayHeaderComparison = () => {
284
268
  avatar={
285
269
  showAvatar ? (
286
270
  <Avatar type={AvatarType.ICON} size={Size.MEDIUM}>
287
- {getAvatarProfile(showAvatar)}
271
+ {avatarProfiles[showAvatar]}
288
272
  </Avatar>
289
273
  ) : null
290
274
  }
291
275
  activeStep={activeStep}
292
276
  done={done}
293
277
  steps={[]}
294
- onClose={showCloseButton ? () => setClosed(true) : undefined}
278
+ onClose={showCloseButton && (() => setClosed(true))}
295
279
  onGoBack={
296
- showMobileBackButton
297
- ? () => setActiveStep(activeStep > 0 ? activeStep - 1 : 0)
298
- : undefined
280
+ showMobileBackButton && (() => setActiveStep(activeStep > 0 ? activeStep - 1 : 0))
299
281
  }
300
282
  />
301
283
  </div>
@@ -304,11 +286,11 @@ export const WithOverlayHeaderComparison = () => {
304
286
  avatar={
305
287
  showAvatar ? (
306
288
  <Avatar type={AvatarType.ICON} size={Size.MEDIUM}>
307
- {getAvatarProfile(showAvatar)}
289
+ {avatarProfiles[showAvatar]}
308
290
  </Avatar>
309
291
  ) : null
310
292
  }
311
- onClose={showCloseButton ? () => setClosed(true) : undefined}
293
+ onClose={showCloseButton && (() => setClosed(true))}
312
294
  />
313
295
  </div>
314
296
  </>
@@ -38,15 +38,15 @@ exports[`FlowNavigation on mobile renders as expected 1`] = `
38
38
  type="button"
39
39
  >
40
40
  <span
41
- aria-hidden="true"
42
41
  class="tw-icon tw-icon-cross "
43
42
  data-testid="cross-icon"
44
- role="presentation"
45
43
  >
46
44
  <svg
45
+ aria-hidden="true"
47
46
  fill="currentColor"
48
47
  focusable="false"
49
48
  height="24"
49
+ role="none"
50
50
  viewBox="0 0 24 24"
51
51
  width="24"
52
52
  >
@@ -153,15 +153,15 @@ exports[`FlowNavigation renders as expected 1`] = `
153
153
  type="button"
154
154
  >
155
155
  <span
156
- aria-hidden="true"
157
156
  class="tw-icon tw-icon-cross "
158
157
  data-testid="cross-icon"
159
- role="presentation"
160
158
  >
161
159
  <svg
160
+ aria-hidden="true"
162
161
  fill="currentColor"
163
162
  focusable="false"
164
163
  height="24"
164
+ role="none"
165
165
  viewBox="0 0 24 24"
166
166
  width="24"
167
167
  >
@@ -1,4 +1,4 @@
1
- import { render, screen } from '../test-utils';
1
+ import { render, screen, within } from '../test-utils';
2
2
 
3
3
  import InstructionsList from '.';
4
4
 
@@ -34,8 +34,16 @@ describe('InstructionsList', () => {
34
34
 
35
35
  const instructions = container.querySelectorAll('.instruction');
36
36
  expect(instructions).toHaveLength(2);
37
- expect(instructions[0]).toHaveAttribute('aria-label', dos[0]['aria-label']);
38
- expect(instructions[1]).toHaveAttribute('aria-label', donts[0]['aria-label']);
37
+ expect(
38
+ within(instructions[0] as HTMLElement).getByRole('graphics-symbol', {
39
+ name: dos[0]['aria-label'],
40
+ }),
41
+ ).toBeInTheDocument();
42
+ expect(
43
+ within(instructions[1] as HTMLElement).getByRole('graphics-symbol', {
44
+ name: donts[0]['aria-label'],
45
+ }),
46
+ ).toBeInTheDocument();
39
47
  });
40
48
 
41
49
  it('should render donts first when sort is set to `dontsFirst`', () => {
@@ -48,7 +56,15 @@ describe('InstructionsList', () => {
48
56
 
49
57
  const instructions = container.querySelectorAll('.instruction');
50
58
  expect(instructions).toHaveLength(2);
51
- expect(instructions[0]).toHaveAttribute('aria-label', donts[0]['aria-label']);
52
- expect(instructions[1]).toHaveAttribute('aria-label', dos[0]['aria-label']);
59
+ expect(
60
+ within(instructions[0] as HTMLElement).getByRole('graphics-symbol', {
61
+ name: donts[0]['aria-label'],
62
+ }),
63
+ ).toBeInTheDocument();
64
+ expect(
65
+ within(instructions[1] as HTMLElement).getByRole('graphics-symbol', {
66
+ name: dos[0]['aria-label'],
67
+ }),
68
+ ).toBeInTheDocument();
53
69
  });
54
70
  });
@@ -57,11 +57,19 @@ function Instruction({ item, type }: { item: ReactNode | InstructionNode; type:
57
57
  const isInstructionNode =
58
58
  typeof item === 'object' && item !== null && 'content' in item && 'aria-label' in item;
59
59
  return (
60
- <li className="instruction" aria-label={isInstructionNode ? item['aria-label'] : undefined}>
60
+ <li className="instruction">
61
61
  {type === 'do' ? (
62
- <DoIcon size={24} className={type} />
62
+ <DoIcon
63
+ size={24}
64
+ className={type}
65
+ title={isInstructionNode ? item['aria-label'] : undefined}
66
+ />
63
67
  ) : (
64
- <DontIcon size={24} className={type} />
68
+ <DontIcon
69
+ size={24}
70
+ className={type}
71
+ title={isInstructionNode ? item['aria-label'] : undefined}
72
+ />
65
73
  )}
66
74
  <Body className="text-primary" type={Typography.BODY_LARGE}>
67
75
  {isInstructionNode ? item.content : item}
@@ -35,15 +35,15 @@ exports[`OverlayHeader renders as expected 1`] = `
35
35
  type="button"
36
36
  >
37
37
  <span
38
- aria-hidden="true"
39
38
  class="tw-icon tw-icon-cross "
40
39
  data-testid="cross-icon"
41
- role="presentation"
42
40
  >
43
41
  <svg
42
+ aria-hidden="true"
44
43
  fill="currentColor"
45
44
  focusable="false"
46
45
  height="24"
46
+ role="none"
47
47
  viewBox="0 0 24 24"
48
48
  width="24"
49
49
  >
@@ -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, { SelectItem, SelectOptionItem } from './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<SelectOptionItem>({
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', [undefined, 'sm', 'md', 'lg'], 'md');
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', true);
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={(option) => {
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<SelectOptionItem>({
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', [undefined, 'sm', 'md', 'lg'], 'md');
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={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
- 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
- ],
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
- searchStrings: ['Isle of Man', 'United Kingdom'],
169
+ countries: 'Isle of Man United Kingdom',
200
170
  },
201
171
  {
202
172
  value: 3,
203
173
  label: 'INR',
204
174
  currency: 'INR',
205
- searchStrings: ['India'],
175
+ countries: 'India',
206
176
  },
207
177
  {
208
178
  value: 4,
209
179
  label: 'USD',
210
180
  currency: 'USD',
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
- ],
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
- searchStrings: ['United Arab Emirates'],
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
- searchStrings: ['Australia'],
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
- searchStrings: ['Bulgaria'],
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
- searchStrings: ['Brazil'],
236
+ searchable: 'Brazil',
237
+ classNames: {},
279
238
  secondary: '',
280
239
  icon: null,
240
+ selected: false,
281
241
  },
282
242
  {
283
- currency: undefined,
243
+ currency: null,
284
244
  value: 'USD',
285
245
  label: 'USD',
286
246
  note: 'United States dollar - Outside of the US',
287
- searchStrings: ['United States'],
247
+ searchable: 'United States',
248
+ classNames: {},
288
249
  secondary: '',
289
250
  icon: <GlobeIcon />,
251
+ selected: false,
290
252
  },
291
253
  ]}
292
- onChange={(option) => {
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<SelectOptionItem>({
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', [undefined, 'sm', 'md', 'lg'], 'md');
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?.toLowerCase().includes(searchValue))}
364
- onChange={(option) => {
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<SelectOptionItem>({
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', [undefined, 'sm', 'md', 'lg'], 'md');
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(null).map((x, index) => ({
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={(option) => {
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' && !!regex.test(navigator.userAgent);
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,73 +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
- const deprecatedTypes = Object.keys(deprecatedTypeMap);
27
-
28
- type EstablishNewTypeType = (
29
- originalType: Type | (string & Record<never, never>) | null,
30
- ) => `${ControlType}` | string | null;
31
-
32
- export const establishNewType: EstablishNewTypeType = (originalType) =>
33
- originalType && originalType in deprecatedTypeMap
34
- ? deprecatedTypeMap[originalType as Type]
35
- : originalType;
36
-
37
- type EstablishNewPriorityType = (
38
- originalPriority?: Priority | (string & Record<never, never>) | null,
39
- originalType?: OldTypeKeys | (string & Record<never, never>) | null,
40
- ) => `${ControlType}` | string | null | undefined;
41
-
42
- export const establishNewPriority: EstablishNewPriorityType = (originalPriority, originalType) => {
43
- const type = originalType ? establishNewType(originalType) : '';
44
-
45
- // The old SECONDARY and LINK types now map to priorities. If they're still using one of
46
- // these old types, ignore whatever priority they've passed and use this instead.
47
- if (originalType && originalType in oldTypePriorityMap) {
48
- return oldTypePriorityMap[originalType as OldTypeKeys];
49
- }
50
- // Only ControlType.ACCENT supports tertiary styles
51
- if (originalPriority === Priority.TERTIARY && type !== ControlType.ACCENT) {
52
- return Priority.SECONDARY;
53
- }
54
- return originalPriority;
55
- };
56
-
57
- type DeprecatedTypeMapMessageType = keyof typeof deprecatedTypeMapMessage;
58
- type LogDeprecationNoticesType = (params: {
59
- size: `${Size}`;
60
- type: DeprecatedTypeMapMessageType | (string & Record<never, never>) | null;
61
- }) => void;
62
- export const logDeprecationNotices: LogDeprecationNoticesType = ({ size, type }) => {
63
- logActionRequiredIf(
64
- 'Button has deprecated the `Size.EXTRA_SMALL` value for the `size` prop. Please use Size.SMALL instead.',
65
- size === Size.EXTRA_SMALL,
66
- );
67
-
68
- if (type && deprecatedTypes.includes(type) && type in deprecatedTypeMapMessage) {
69
- logActionRequired(
70
- `Button has deprecated the ${type} value for the \`type\` prop. Please update to ${deprecatedTypeMapMessage[type as DeprecatedTypeMapMessageType]}.`,
71
- );
72
- }
73
- };