@transferwise/components 0.0.0-experimental-a656242 → 0.0.0-experimental-887f2e6

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 (154) hide show
  1. package/build/avatarLayout/AvatarLayout.js +9 -2
  2. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  3. package/build/avatarLayout/AvatarLayout.mjs +9 -2
  4. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  5. package/build/avatarView/AvatarView.js +1 -12
  6. package/build/avatarView/AvatarView.js.map +1 -1
  7. package/build/avatarView/AvatarView.mjs +1 -12
  8. package/build/avatarView/AvatarView.mjs.map +1 -1
  9. package/build/button/Button.js +78 -79
  10. package/build/button/Button.js.map +1 -1
  11. package/build/button/Button.mjs +79 -80
  12. package/build/button/Button.mjs.map +1 -1
  13. package/build/button/Button.resolver.js +78 -0
  14. package/build/button/Button.resolver.js.map +1 -0
  15. package/build/button/Button.resolver.mjs +76 -0
  16. package/build/button/Button.resolver.mjs.map +1 -0
  17. package/build/button/LegacyButton.js +114 -0
  18. package/build/button/LegacyButton.js.map +1 -0
  19. package/build/button/LegacyButton.mjs +112 -0
  20. package/build/button/LegacyButton.mjs.map +1 -0
  21. package/build/circularButton/CircularButton.js +21 -18
  22. package/build/circularButton/CircularButton.js.map +1 -1
  23. package/build/circularButton/CircularButton.mjs +22 -19
  24. package/build/circularButton/CircularButton.mjs.map +1 -1
  25. package/build/criticalBanner/CriticalCommsBanner.js +2 -2
  26. package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
  27. package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
  28. package/build/definitionList/DefinitionList.js.map +1 -1
  29. package/build/definitionList/DefinitionList.mjs.map +1 -1
  30. package/build/header/Header.js +2 -2
  31. package/build/header/Header.js.map +1 -1
  32. package/build/header/Header.mjs +1 -1
  33. package/build/i18n/de.json +0 -1
  34. package/build/i18n/de.json.js +0 -1
  35. package/build/i18n/de.json.js.map +1 -1
  36. package/build/i18n/de.json.mjs +0 -1
  37. package/build/i18n/de.json.mjs.map +1 -1
  38. package/build/i18n/it.json +0 -1
  39. package/build/i18n/it.json.js +0 -1
  40. package/build/i18n/it.json.js.map +1 -1
  41. package/build/i18n/it.json.mjs +0 -1
  42. package/build/i18n/it.json.mjs.map +1 -1
  43. package/build/i18n/th.json +0 -1
  44. package/build/i18n/th.json.js +0 -1
  45. package/build/i18n/th.json.js.map +1 -1
  46. package/build/i18n/th.json.mjs +0 -1
  47. package/build/i18n/th.json.mjs.map +1 -1
  48. package/build/index.js +2 -2
  49. package/build/index.mjs +1 -1
  50. package/build/link/Link.js +8 -3
  51. package/build/link/Link.js.map +1 -1
  52. package/build/link/Link.mjs +8 -3
  53. package/build/link/Link.mjs.map +1 -1
  54. package/build/main.css +416 -17
  55. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +1 -3
  56. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
  57. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +1 -3
  58. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
  59. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +1 -4
  60. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
  61. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +1 -4
  62. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
  63. package/build/select/Select.js +5 -3
  64. package/build/select/Select.js.map +1 -1
  65. package/build/select/Select.mjs +4 -2
  66. package/build/select/Select.mjs.map +1 -1
  67. package/build/styles/avatarLayout/AvatarLayout.css +11 -0
  68. package/build/styles/button/Button.css +240 -16
  69. package/build/styles/button/Button.vars.css +55 -0
  70. package/build/styles/button/LegacyButton.css +23 -0
  71. package/build/styles/circularButton/CircularButton.css +158 -17
  72. package/build/styles/main.css +416 -17
  73. package/build/types/avatarLayout/AvatarLayout.d.ts +1 -2
  74. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  75. package/build/types/avatarLayout/index.d.ts +1 -0
  76. package/build/types/avatarLayout/index.d.ts.map +1 -1
  77. package/build/types/avatarView/AvatarView.d.ts.map +1 -1
  78. package/build/types/button/Button.d.ts +1 -23
  79. package/build/types/button/Button.d.ts.map +1 -1
  80. package/build/types/button/Button.resolver.d.ts +31 -0
  81. package/build/types/button/Button.resolver.d.ts.map +1 -0
  82. package/build/types/button/Button.types.d.ts +67 -0
  83. package/build/types/button/Button.types.d.ts.map +1 -0
  84. package/build/types/button/LegacyButton.d.ts +30 -0
  85. package/build/types/button/LegacyButton.d.ts.map +1 -0
  86. package/build/types/button/index.d.ts +2 -2
  87. package/build/types/button/index.d.ts.map +1 -1
  88. package/build/types/circularButton/CircularButton.d.ts +4 -11
  89. package/build/types/circularButton/CircularButton.d.ts.map +1 -1
  90. package/build/types/definitionList/DefinitionList.d.ts +2 -1
  91. package/build/types/definitionList/DefinitionList.d.ts.map +1 -1
  92. package/build/types/link/Link.d.ts +2 -2
  93. package/build/types/link/Link.d.ts.map +1 -1
  94. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
  95. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +1 -1
  96. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
  97. package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
  98. package/build/types/select/Select.d.ts.map +1 -1
  99. package/build/upload/steps/completeStep/completeStep.js +2 -2
  100. package/build/upload/steps/completeStep/completeStep.js.map +1 -1
  101. package/build/upload/steps/completeStep/completeStep.mjs +1 -1
  102. package/build/upload/steps/processingStep/processingStep.js +2 -2
  103. package/build/upload/steps/processingStep/processingStep.js.map +1 -1
  104. package/build/upload/steps/processingStep/processingStep.mjs +1 -1
  105. package/build/uploadInput/UploadInput.js +3 -3
  106. package/build/uploadInput/UploadInput.js.map +1 -1
  107. package/build/uploadInput/UploadInput.mjs +1 -1
  108. package/package.json +3 -3
  109. package/src/avatarLayout/AvatarLayout.css +11 -0
  110. package/src/avatarLayout/AvatarLayout.less +18 -1
  111. package/src/avatarLayout/AvatarLayout.tsx +11 -3
  112. package/src/avatarLayout/index.ts +1 -0
  113. package/src/avatarView/AvatarView.tsx +1 -15
  114. package/src/button/Button.css +240 -16
  115. package/src/button/Button.less +208 -14
  116. package/src/button/Button.resolver.tsx +120 -0
  117. package/src/button/Button.spec.tsx +54 -231
  118. package/src/button/Button.story.tsx +610 -137
  119. package/src/button/Button.tsx +88 -132
  120. package/src/button/Button.types.ts +88 -0
  121. package/src/button/Button.vars.css +55 -0
  122. package/src/button/Button.vars.less +69 -0
  123. package/src/button/LegacyButton.css +23 -0
  124. package/src/button/LegacyButton.less +24 -0
  125. package/src/button/LegacyButton.spec.tsx +146 -0
  126. package/src/button/LegacyButton.story.tsx +224 -0
  127. package/src/button/LegacyButton.tsx +161 -0
  128. package/src/button/index.ts +2 -3
  129. package/src/circularButton/CircularButton.css +158 -17
  130. package/src/circularButton/CircularButton.less +91 -22
  131. package/src/circularButton/CircularButton.story.tsx +24 -45
  132. package/src/circularButton/CircularButton.tsx +25 -38
  133. package/src/circularButton/_button-label-states.less +34 -0
  134. package/src/definitionList/DefinitionList.spec.js +91 -0
  135. package/src/definitionList/DefinitionList.story.tsx +57 -57
  136. package/src/definitionList/DefinitionList.tsx +1 -1
  137. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -1
  138. package/src/i18n/de.json +0 -1
  139. package/src/i18n/it.json +0 -1
  140. package/src/i18n/th.json +0 -1
  141. package/src/iconButton/IconButton.story.tsx +6 -6
  142. package/src/inputs/SelectInput.story.tsx +1 -1
  143. package/src/link/Link.tsx +15 -6
  144. package/src/main.css +416 -17
  145. package/src/main.less +1 -0
  146. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +1 -7
  147. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +1 -1
  148. package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -3
  149. package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +1 -8
  150. package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +2 -5
  151. package/src/select/Select.tsx +1 -0
  152. package/src/slidingPanel/SlidingPanel.spec.js +56 -0
  153. package/src/button/__snapshots__/Button.spec.tsx.snap +0 -309
  154. package/src/slidingPanel/SlidingPanel.spec.tsx +0 -69
@@ -1,246 +1,69 @@
1
- import { createRef } from 'react';
2
-
3
- import { ControlType, Type, Priority, Size } from '../common';
4
- import { render, screen, userEvent } from '../test-utils';
5
-
6
- import Button from '.';
7
- import messages from '../i18n/commonMessages/Button.messages';
8
- import { ButtonReferenceType } from './Button';
9
-
10
- const { ACCENT, POSITIVE, NEGATIVE } = ControlType;
11
- const { PAY, LINK, DANGER } = Type;
12
- const { PRIMARY, SECONDARY, TERTIARY } = Priority;
13
- const { SMALL, MEDIUM, LARGE } = Size;
1
+ import { render, screen } from '../test-utils';
2
+ import Button, { ButtonProps } from './Button.resolver';
14
3
 
15
4
  describe('Button', () => {
16
- // eslint-disable-next-line no-console
17
- const originalWarn = console.warn;
18
- let mockedWarn: typeof originalWarn;
19
-
20
- const props = {
21
- onClick: jest.fn(),
22
- onFocus: jest.fn(),
23
- onBlur: jest.fn(),
24
- children: 'Send money',
5
+ const legacyProps: ButtonProps = {
6
+ as: 'button',
7
+ priority: 'primary',
8
+ size: 'md',
9
+ type: 'accent',
25
10
  };
26
11
 
27
- beforeAll(() => {
28
- mockedWarn = jest.fn().mockImplementation((args) => {
29
- if (typeof args !== 'string' || !args.startsWith('Button has deprecated the')) {
30
- originalWarn(args);
31
- }
32
- });
33
- // eslint-disable-next-line no-console
34
- console.warn = mockedWarn;
35
- });
36
-
37
- beforeEach(jest.clearAllMocks);
38
-
39
- afterAll(() => {
40
- // eslint-disable-next-line no-console
41
- console.warn = originalWarn;
42
- });
43
-
44
- describe('by default', () => {
45
- it('renders the text', () => {
46
- render(<Button {...props} />);
47
- expect(screen.getByText(props.children)).toBeInTheDocument();
48
- });
49
-
50
- it('set `ref` to be true on Button', () => {
51
- const reference = createRef<ButtonReferenceType>();
52
-
53
- expect(reference.current).toBeFalsy();
54
- render(<Button ref={reference}>Click me!</Button>);
55
- expect(reference.current).toBeTruthy();
56
- });
57
-
58
- it('is not disabled', () => {
59
- render(<Button {...props} />);
60
- expect(screen.getByRole('button')).toBeEnabled();
61
- });
62
-
63
- it('renders a medium button of type accent and priority primary', () => {
64
- expect(render(<Button {...props} />).container).toMatchSnapshot();
65
- });
66
-
67
- it('renders an anchor tag with button styles of type accent and priority primary', () => {
68
- expect(render(<Button {...props} as="a" href="#" />).container).toMatchSnapshot();
69
- });
70
- });
71
-
72
- describe('button attributes', () => {
73
- it('sets the htmlType if set', () => {
74
- render(<Button {...props} htmlType="submit" />);
75
- expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
76
- });
77
-
78
- it('passes through custom classes if set', () => {
79
- render(<Button {...props} className="donkeysarethebest" />);
80
- expect(screen.getByRole('button')).toHaveClass('donkeysarethebest');
81
- });
82
-
83
- it('passes through aria-label if set', () => {
84
- render(<Button {...props} aria-label="unique label" />);
85
- const loadingButton = screen.getByLabelText('unique label');
86
- expect(loadingButton).toBeInTheDocument();
87
- });
88
- });
89
-
90
- describe('onClick', () => {
91
- it('calls onClick when clicked', async () => {
92
- render(<Button {...props} />);
93
- await userEvent.click(screen.getByRole('button'));
94
- expect(props.onClick).toHaveBeenCalledTimes(1);
95
- });
96
-
97
- it('does not call onClick when clicked if disabled', async () => {
98
- render(<Button {...props} disabled />);
99
- await userEvent.click(screen.getByRole('button'));
100
- expect(props.onClick).toHaveBeenCalledTimes(0);
101
- });
102
-
103
- it('does not call onClick when clicked if loading', async () => {
104
- render(<Button {...props} loading />);
105
- await userEvent.click(screen.getByRole('button'));
106
- expect(props.onClick).toHaveBeenCalledTimes(0);
107
- });
108
- });
109
-
110
- describe('onFocus and onBlur', () => {
111
- it('calls both handlers by default', async () => {
112
- render(<Button {...props} />);
113
- await userEvent.tab();
114
- expect(props.onFocus).toHaveBeenCalledTimes(1);
115
- await userEvent.tab();
116
- expect(props.onFocus).toHaveBeenCalledTimes(1);
117
- });
118
-
119
- it('does not call either handler if disabled', async () => {
120
- render(<Button {...props} disabled />);
121
- await userEvent.tab();
122
- expect(props.onFocus).not.toHaveBeenCalled();
123
- await userEvent.tab();
124
- expect(props.onFocus).not.toHaveBeenCalled();
125
- });
126
-
127
- it('calls both handlers if loading', async () => {
128
- render(<Button {...props} loading />);
129
- await userEvent.tab();
130
- expect(props.onFocus).toHaveBeenCalledTimes(1);
131
- await userEvent.tab();
132
- expect(props.onFocus).toHaveBeenCalledTimes(1);
133
- });
134
- });
135
-
136
- describe('sizes', () => {
137
- it('renders small buttons', () => {
138
- expect(render(<Button {...props} size={SMALL} />).container).toMatchSnapshot();
139
- });
140
-
141
- it('renders medium buttons', () => {
142
- expect(render(<Button {...props} size={MEDIUM} />).container).toMatchSnapshot();
143
- });
12
+ const newProps: ButtonProps = {
13
+ as: 'button',
14
+ v2: true,
15
+ priority: 'primary',
16
+ size: 'md',
17
+ type: 'accent',
18
+ testId: 'new-button',
19
+ };
144
20
 
145
- it('renders large buttons', () => {
146
- expect(render(<Button {...props} size={LARGE} />).container).toMatchSnapshot();
147
- });
21
+ it('renders LegacyButton when v2 is false', () => {
22
+ render(<Button {...legacyProps}>Legacy Button</Button>);
23
+ const button = screen.getByText('Legacy Button');
24
+ expect(button).toBeInTheDocument();
25
+ expect(button).toHaveClass('btn btn-md np-btn np-btn-md btn-accent btn-priority-1');
148
26
  });
149
27
 
150
- describe('types', () => {
151
- it('renders accent buttons', () => {
152
- expect(render(<Button {...props} type={ACCENT} />).container).toMatchSnapshot();
153
- });
154
-
155
- it('renders positive buttons', () => {
156
- expect(render(<Button {...props} type={POSITIVE} />).container).toMatchSnapshot();
157
- });
158
-
159
- it('renders negative buttons', () => {
160
- expect(render(<Button {...props} type={NEGATIVE} />).container).toMatchSnapshot();
161
- });
28
+ it('renders the new Button when v2 is true', () => {
29
+ render(<Button {...newProps}>New Button</Button>);
30
+ const button = screen.getByTestId('new-button');
31
+ expect(button).toBeInTheDocument();
32
+ expect(button).toHaveClass('wds-Button wds-Button--medium wds-Button--primary');
162
33
  });
163
34
 
164
- describe('priorities', () => {
165
- it('renders primary buttons', () => {
166
- [ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
167
- expect(
168
- render(<Button {...props} priority={PRIMARY} type={type} />).container,
169
- ).toMatchSnapshot(),
170
- );
171
- });
172
-
173
- it('renders secondary buttons', () => {
174
- [ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
175
- expect(
176
- render(<Button {...props} priority={SECONDARY} type={type} />).container,
177
- ).toMatchSnapshot(),
178
- );
179
- });
180
-
181
- it('renders tertiary buttons', () => {
182
- expect(
183
- render(<Button {...props} priority={TERTIARY} type={ACCENT} />).container,
184
- ).toMatchSnapshot();
185
- });
186
-
187
- it('defaults tertiary buttons to secondary for positive buttons', () => {
188
- [POSITIVE, NEGATIVE].forEach((type) =>
189
- expect(
190
- render(<Button {...props} priority={TERTIARY} type={type} />).container,
191
- ).toMatchSnapshot(),
192
- );
193
- });
35
+ it('renders a button with href when as is "a"', () => {
36
+ const linkProps: ButtonProps = {
37
+ ...legacyProps,
38
+ as: 'a',
39
+ href: 'https://example.com',
40
+ target: '_blank',
41
+ };
42
+ render(<Button {...linkProps}>Legacy Button</Button>);
43
+ const linkButton = screen.getByText('Legacy Button');
44
+ expect(linkButton).toBeInTheDocument();
45
+ expect(linkButton).toHaveAttribute('href', 'https://example.com');
194
46
  });
195
47
 
196
- describe('other states', () => {
197
- it('renders as loading if `loading` is true', () => {
198
- render(<Button {...props} loading />);
199
- const button = screen.queryByRole('button', {
200
- name: messages.loadingAriaLabel.defaultMessage,
201
- });
202
- expect(button).toBeInTheDocument();
203
- expect(button).toBeEnabled();
204
- expect(button).toHaveClass('btn-loading');
205
- expect(button).toHaveAttribute('aria-disabled', 'true');
206
- expect(button).toHaveAttribute('aria-busy', 'true');
207
- expect(button).toHaveAttribute('aria-live', 'polite');
208
- expect(screen.getByTestId('ButtonProgressIndicator')).toBeInTheDocument();
209
- });
210
-
211
- it('disables the button', () => {
212
- render(<Button {...props} disabled />);
213
- const button = screen.queryByRole('button');
214
- expect(button).toBeDisabled();
215
- expect(button).toHaveClass('disabled');
216
- expect(button).toHaveAttribute('aria-disabled', 'false');
217
- expect(button).toHaveAttribute('aria-busy', 'false');
218
- expect(button).toHaveAttribute('aria-live', 'off');
219
- });
220
-
221
- it('renders as block if block is true', () => {
222
- expect(render(<Button {...props} block />).container).toMatchSnapshot();
223
- });
48
+ it('does not set type when type is in LegacyButtonType', () => {
49
+ const legacyTypeProps: ButtonProps = {
50
+ ...newProps,
51
+ type: 'accent',
52
+ };
53
+ render(<Button {...legacyTypeProps}>Button Type</Button>);
54
+ const button = screen.getByTestId('new-button');
55
+ expect(button).toBeInTheDocument();
56
+ expect(button).not.toHaveAttribute('type');
224
57
  });
225
58
 
226
- describe('deprecated types', () => {
227
- it('renders primary as accent buttons and logs a warning', () => {
228
- expect(render(<Button {...props} type={PRIMARY} />).container).toMatchSnapshot();
229
- expect(mockedWarn).toHaveBeenCalledTimes(1);
230
- });
231
-
232
- it('renders pay as positive buttons and logs a warning', () => {
233
- expect(render(<Button {...props} type={PAY} />).container).toMatchSnapshot();
234
- expect(mockedWarn).toHaveBeenCalledTimes(1);
235
- });
236
-
237
- it('renders danger as negative buttons with priority secondary and logs a warning', () => {
238
- expect(render(<Button {...props} type={DANGER} />).container).toMatchSnapshot();
239
- expect(mockedWarn).toHaveBeenCalledTimes(1);
240
- });
241
-
242
- it('renders link as accent buttons with priority tertiary and logs a warning', () => {
243
- expect(render(<Button {...props} type={LINK} />).container).toMatchSnapshot();
244
- });
59
+ it('sets type when type is not in LegacyButtonType', () => {
60
+ const buttonTypeProps: ButtonProps = {
61
+ ...newProps,
62
+ type: 'submit',
63
+ };
64
+ render(<Button {...buttonTypeProps}>Submit Button</Button>);
65
+ const button = screen.getByTestId('new-button');
66
+ expect(button).toBeInTheDocument();
67
+ expect(button).toHaveAttribute('type', 'submit');
245
68
  });
246
69
  });