@transferwise/components 0.0.0-experimental-4c79cff → 0.0.0-experimental-28a3dd5

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 (183) hide show
  1. package/build/avatarLayout/AvatarLayout.js +10 -4
  2. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  3. package/build/avatarLayout/AvatarLayout.mjs +10 -4
  4. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  5. package/build/button/Button.js +86 -79
  6. package/build/button/Button.js.map +1 -1
  7. package/build/button/Button.mjs +87 -80
  8. package/build/button/Button.mjs.map +1 -1
  9. package/build/button/Button.resolver.js +74 -0
  10. package/build/button/Button.resolver.js.map +1 -0
  11. package/build/button/Button.resolver.mjs +72 -0
  12. package/build/button/Button.resolver.mjs.map +1 -0
  13. package/build/button/LegacyButton.js +114 -0
  14. package/build/button/LegacyButton.js.map +1 -0
  15. package/build/button/LegacyButton.mjs +112 -0
  16. package/build/button/LegacyButton.mjs.map +1 -0
  17. package/build/criticalBanner/CriticalCommsBanner.js +2 -2
  18. package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
  19. package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
  20. package/build/header/Header.js +2 -2
  21. package/build/header/Header.js.map +1 -1
  22. package/build/header/Header.mjs +1 -1
  23. package/build/i18n/ja.json +0 -1
  24. package/build/i18n/ja.json.js +0 -1
  25. package/build/i18n/ja.json.js.map +1 -1
  26. package/build/i18n/ja.json.mjs +0 -1
  27. package/build/i18n/ja.json.mjs.map +1 -1
  28. package/build/i18n/pt.json +0 -1
  29. package/build/i18n/pt.json.js +0 -1
  30. package/build/i18n/pt.json.js.map +1 -1
  31. package/build/i18n/pt.json.mjs +0 -1
  32. package/build/i18n/pt.json.mjs.map +1 -1
  33. package/build/i18n/ru.json +0 -1
  34. package/build/i18n/ru.json.js +0 -1
  35. package/build/i18n/ru.json.js.map +1 -1
  36. package/build/i18n/ru.json.mjs +0 -1
  37. package/build/i18n/ru.json.mjs.map +1 -1
  38. package/build/i18n/zh-HK.json +0 -1
  39. package/build/i18n/zh-HK.json.js +0 -1
  40. package/build/i18n/zh-HK.json.js.map +1 -1
  41. package/build/i18n/zh-HK.json.mjs +0 -1
  42. package/build/i18n/zh-HK.json.mjs.map +1 -1
  43. package/build/index.js +2 -4
  44. package/build/index.js.map +1 -1
  45. package/build/index.mjs +1 -2
  46. package/build/index.mjs.map +1 -1
  47. package/build/link/Link.js +8 -3
  48. package/build/link/Link.js.map +1 -1
  49. package/build/link/Link.mjs +8 -3
  50. package/build/link/Link.mjs.map +1 -1
  51. package/build/main.css +227 -13
  52. package/build/nudge/Nudge.js.map +1 -1
  53. package/build/nudge/Nudge.mjs.map +1 -1
  54. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +2 -4
  55. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
  56. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +2 -4
  57. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
  58. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +3 -5
  59. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
  60. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +3 -5
  61. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
  62. package/build/select/Select.js +2 -2
  63. package/build/select/Select.js.map +1 -1
  64. package/build/select/Select.mjs +1 -1
  65. package/build/styles/avatarLayout/AvatarLayout.css +12 -2
  66. package/build/styles/button/Button.css +207 -15
  67. package/build/styles/button/Button.vars.css +46 -0
  68. package/build/styles/button/LegacyButton.css +23 -0
  69. package/build/styles/main.css +227 -13
  70. package/build/styles/nudge/Nudge.css +0 -11
  71. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  72. package/build/types/button/Button.d.ts +2 -23
  73. package/build/types/button/Button.d.ts.map +1 -1
  74. package/build/types/button/Button.resolver.d.ts +33 -0
  75. package/build/types/button/Button.resolver.d.ts.map +1 -0
  76. package/build/types/button/Button.types.d.ts +67 -0
  77. package/build/types/button/Button.types.d.ts.map +1 -0
  78. package/build/types/button/LegacyButton.d.ts +30 -0
  79. package/build/types/button/LegacyButton.d.ts.map +1 -0
  80. package/build/types/button/index.d.ts +2 -2
  81. package/build/types/button/index.d.ts.map +1 -1
  82. package/build/types/index.d.ts +0 -2
  83. package/build/types/index.d.ts.map +1 -1
  84. package/build/types/link/Link.d.ts +2 -2
  85. package/build/types/link/Link.d.ts.map +1 -1
  86. package/build/types/nudge/Nudge.d.ts +1 -1
  87. package/build/types/nudge/Nudge.d.ts.map +1 -1
  88. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
  89. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +6 -2
  90. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
  91. package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
  92. package/build/types/test-utils/story-config.d.ts +1 -1
  93. package/build/types/test-utils/story-config.d.ts.map +1 -1
  94. package/build/types/uploadInput/uploadButton/getAllowedFileTypes.d.ts.map +1 -1
  95. package/build/upload/steps/completeStep/completeStep.js +2 -2
  96. package/build/upload/steps/completeStep/completeStep.js.map +1 -1
  97. package/build/upload/steps/completeStep/completeStep.mjs +1 -1
  98. package/build/upload/steps/processingStep/processingStep.js +2 -2
  99. package/build/upload/steps/processingStep/processingStep.js.map +1 -1
  100. package/build/upload/steps/processingStep/processingStep.mjs +1 -1
  101. package/build/uploadInput/UploadInput.js +3 -3
  102. package/build/uploadInput/UploadInput.js.map +1 -1
  103. package/build/uploadInput/UploadInput.mjs +1 -1
  104. package/build/uploadInput/uploadButton/getAllowedFileTypes.js +3 -23
  105. package/build/uploadInput/uploadButton/getAllowedFileTypes.js.map +1 -1
  106. package/build/uploadInput/uploadButton/getAllowedFileTypes.mjs +3 -23
  107. package/build/uploadInput/uploadButton/getAllowedFileTypes.mjs.map +1 -1
  108. package/package.json +3 -3
  109. package/src/alert/Alert.tests.story.tsx +1 -1
  110. package/src/avatarLayout/AvatarLayout.css +12 -2
  111. package/src/avatarLayout/AvatarLayout.less +19 -2
  112. package/src/avatarLayout/AvatarLayout.tsx +10 -3
  113. package/src/button/Button.css +207 -15
  114. package/src/button/Button.less +214 -14
  115. package/src/button/Button.resolver.tsx +73 -0
  116. package/src/button/Button.spec.tsx +188 -224
  117. package/src/button/Button.story.tsx +701 -135
  118. package/src/button/Button.tests.story.tsx +27 -0
  119. package/src/button/Button.tsx +99 -131
  120. package/src/button/Button.types.ts +94 -0
  121. package/src/button/Button.vars.css +46 -0
  122. package/src/button/Button.vars.less +60 -0
  123. package/src/button/LegacyButton.css +23 -0
  124. package/src/button/LegacyButton.less +24 -0
  125. package/src/button/LegacyButton.spec.tsx +147 -0
  126. package/src/button/LegacyButton.story.tsx +220 -0
  127. package/src/button/LegacyButton.tsx +160 -0
  128. package/src/button/index.ts +2 -3
  129. package/src/drawer/Drawer.rtl.spec.tsx +59 -0
  130. package/src/drawer/Drawer.spec.js +101 -0
  131. package/src/drawer/__snapshots__/Drawer.rtl.spec.tsx.snap +55 -0
  132. package/src/field/Field.story.tsx +1 -1
  133. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -2
  134. package/src/i18n/ja.json +0 -1
  135. package/src/i18n/pt.json +0 -1
  136. package/src/i18n/ru.json +0 -1
  137. package/src/i18n/zh-HK.json +0 -1
  138. package/src/index.ts +0 -12
  139. package/src/inputs/SelectInput.story.tsx +1 -1
  140. package/src/label/Label.story.tsx +1 -1
  141. package/src/link/Link.tsx +15 -6
  142. package/src/main.css +227 -13
  143. package/src/main.less +1 -0
  144. package/src/nudge/Nudge.css +0 -11
  145. package/src/nudge/Nudge.less +0 -3
  146. package/src/nudge/Nudge.story.tsx +0 -10
  147. package/src/nudge/Nudge.tsx +1 -2
  148. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +2 -8
  149. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +7 -2
  150. package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -3
  151. package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +4 -12
  152. package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +16 -13
  153. package/src/test-utils/Parameters.d.ts +9 -1
  154. package/src/test-utils/story-config.ts +10 -1
  155. package/src/uploadInput/UploadInput.tests.story.tsx +5 -5
  156. package/src/uploadInput/uploadButton/getAllowedFileTypes.spec.ts +0 -12
  157. package/src/uploadInput/uploadButton/getAllowedFileTypes.ts +7 -33
  158. package/build/table/Table.js +0 -166
  159. package/build/table/Table.js.map +0 -1
  160. package/build/table/Table.messages.js +0 -24
  161. package/build/table/Table.messages.js.map +0 -1
  162. package/build/table/Table.messages.mjs +0 -22
  163. package/build/table/Table.messages.mjs.map +0 -1
  164. package/build/table/Table.mjs +0 -164
  165. package/build/table/Table.mjs.map +0 -1
  166. package/build/table/TableCell.js +0 -86
  167. package/build/table/TableCell.js.map +0 -1
  168. package/build/table/TableCell.mjs +0 -84
  169. package/build/table/TableCell.mjs.map +0 -1
  170. package/build/table/TableHeader.js +0 -57
  171. package/build/table/TableHeader.js.map +0 -1
  172. package/build/table/TableHeader.mjs +0 -55
  173. package/build/table/TableHeader.mjs.map +0 -1
  174. package/build/table/TableRow.js +0 -85
  175. package/build/table/TableRow.js.map +0 -1
  176. package/build/table/TableRow.mjs +0 -83
  177. package/build/table/TableRow.mjs.map +0 -1
  178. package/build/table/TableStatusText.js +0 -54
  179. package/build/table/TableStatusText.js.map +0 -1
  180. package/build/table/TableStatusText.mjs +0 -52
  181. package/build/table/TableStatusText.mjs.map +0 -1
  182. package/src/button/__snapshots__/Button.spec.tsx.snap +0 -309
  183. package/src/drawer/Drawer.spec.tsx +0 -93
@@ -0,0 +1,27 @@
1
+ import { Meta } from '@storybook/react';
2
+ import Button from './Button.resolver';
3
+ import { expect, userEvent, within } from '@storybook/test';
4
+ import { storyConfig } from '../test-utils';
5
+
6
+ const meta: Meta<typeof Button> = {
7
+ component: Button,
8
+ title: 'Actions/Button/Tests',
9
+ };
10
+ export default meta;
11
+
12
+ export const FocusMinimal = storyConfig(
13
+ {
14
+ render: () => (
15
+ <Button v2 priority="minimal">
16
+ Focus has underline
17
+ </Button>
18
+ ),
19
+ },
20
+ {},
21
+ );
22
+ FocusMinimal.play = async ({ canvasElement }) => {
23
+ await userEvent.tab();
24
+ const canvas = within(canvasElement);
25
+ const buttonElement: HTMLButtonElement = canvas.getByRole('button');
26
+ await expect(buttonElement).toHaveFocus();
27
+ };
@@ -1,154 +1,122 @@
1
- import { clsx } from 'clsx';
2
- import { ElementType, forwardRef, MouseEvent } from 'react';
3
- import { useIntl } from 'react-intl';
4
-
1
+ /* eslint-disable react/display-name */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ import { forwardRef } from 'react';
5
4
  import {
6
- Size,
7
- ControlType,
8
- Priority,
9
- ControlTypeAccent,
10
- ControlTypeNegative,
11
- ControlTypePositive,
12
- PriorityPrimary,
13
- PrioritySecondary,
14
- PriorityTertiary,
15
- SizeExtraSmall,
16
- SizeSmall,
17
- SizeMedium,
18
- SizeLarge,
19
- } from '../common';
5
+ AnchorElementProps,
6
+ ButtonReferenceType,
7
+ ButtonProps as NewButtonProps,
8
+ } from './Button.types';
9
+ import { PrimitiveAnchor, PrimitiveButton } from '../primitives';
10
+ import AvatarLayout from '../avatarLayout';
20
11
  import ProcessIndicator from '../processIndicator';
12
+ import { clsx } from 'clsx';
13
+ import { Typography } from '../common';
14
+ import Body from '../body';
21
15
 
22
- import messages from '../i18n/commonMessages/Button.messages';
23
- import { typeClassMap, priorityClassMap } from './classMap';
24
- import { establishNewPriority, establishNewType, logDeprecationNotices } from './legacyUtils';
25
-
26
- /** @deprecated */
27
- type DeprecatedTypes = 'primary' | 'pay' | 'secondary' | 'danger' | 'link';
28
-
29
- /** @deprecated */
30
- type DeprecatedSizes = SizeExtraSmall;
31
-
32
- type CommonProps = {
33
- block?: boolean;
34
- disabled?: boolean;
35
- loading?: boolean;
36
- type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes | null;
37
- priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary | null;
38
- size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;
39
- };
40
-
41
- type ButtonProps = CommonProps &
42
- Omit<React.ComponentPropsWithRef<'button'>, 'type'> & {
43
- as?: 'button';
44
- htmlType?: 'submit' | 'reset' | 'button';
45
- };
46
-
47
- type AnchorProps = CommonProps &
48
- Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {
49
- as?: 'a';
50
- };
51
-
52
- export type Props = ButtonProps | AnchorProps;
53
-
54
- export type ButtonReferenceType = HTMLButtonElement | HTMLAnchorElement;
55
-
56
- const Button = forwardRef<ButtonReferenceType, Props>(
16
+ const Button = forwardRef<ButtonReferenceType, NewButtonProps>(
57
17
  (
58
18
  {
59
- as: component,
60
- block = false,
19
+ as = 'button',
61
20
  children,
62
21
  className,
63
- disabled,
22
+ size = 'lg',
23
+ href,
24
+ disabled = false,
25
+ priority = 'primary',
26
+ sentiment = 'default',
27
+ // iconStart: IconStart,
28
+ // iconEnd: IconEnd,
29
+ // avatars,
30
+ addonStart,
31
+ addonEnd,
32
+ // @ts-expect-error NewButtonProps has `type` prop
33
+ type = 'button',
64
34
  loading = false,
65
- priority = Priority.PRIMARY,
66
- size = Size.MEDIUM,
67
- type = ControlType.ACCENT,
68
- onClick,
69
- ...rest
70
- }: Props,
71
- reference,
35
+ block = false,
36
+ v2,
37
+ ...props
38
+ },
39
+ ref,
72
40
  ) => {
73
- const intl = useIntl();
74
-
75
- logDeprecationNotices({ size, type });
76
-
77
- const newType = establishNewType(type);
78
- const newPriority = establishNewPriority(priority, type);
79
-
80
- const classes = clsx(
81
- `btn btn-${size}`,
82
- `np-btn np-btn-${size}`,
41
+ const classNames = clsx(
42
+ 'wds-Button',
83
43
  {
84
- 'btn-loading': loading,
85
- 'btn-block np-btn-block': block,
86
- disabled,
44
+ [`wds-Button--block`]: block,
45
+ [`wds-Button--disabled`]: disabled,
46
+ [`wds-Button--loading`]: loading,
87
47
  },
88
- // @ts-expect-error fix when refactor `typeClassMap` to TypeScript
89
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
90
- typeClassMap[newType],
91
- // @ts-expect-error fix when refactor `typeClassMap` to TypeScript
92
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
93
- priorityClassMap[newPriority],
48
+ `wds-Button--${{ sm: 'small', md: 'medium', lg: 'large' }[size]}`,
49
+ `wds-Button--${priority}`,
50
+ `wds-Button--${sentiment}`,
94
51
  className,
95
52
  );
96
53
 
97
- function processIndicatorSize() {
98
- return ['sm', 'xs'].includes(size) ? 'xxs' : 'xs';
99
- }
100
-
101
- const Element = (component as ElementType) ?? 'button';
102
- let props;
103
-
104
- if (Element === 'button') {
105
- const { htmlType = 'button', ...restProps } = rest as ButtonProps;
106
- props = {
107
- ...restProps,
108
- disabled,
109
- 'aria-disabled': loading,
110
- type: htmlType,
111
- };
112
- } else {
113
- props = {
114
- ...rest,
115
- 'aria-disabled': loading,
116
- } as AnchorProps;
117
- }
118
-
119
- /**
120
- * Ensures that the button cannot be activated in loading or disabled mode,
121
- * when `aria-disabled` might be used over the `disabled` HTML attribute
122
- */
123
- const handleClick =
124
- (handler: Props['onClick']) =>
125
- (event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {
126
- if (disabled || loading) {
127
- event.preventDefault();
128
- } else if (typeof handler === 'function') {
129
- handler(event);
130
- }
131
- };
54
+ const contentClassNames = clsx('wds-Button-content', {
55
+ [`wds-Button-content--loading`]: loading,
56
+ });
132
57
 
133
- return (
134
- <Element
135
- ref={reference}
136
- className={classes}
137
- onClick={handleClick(onClick)}
138
- {...props}
139
- aria-live={loading ? 'polite' : 'off'}
140
- aria-busy={loading}
141
- aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}
58
+ const content = (
59
+ <Body
60
+ as="span"
61
+ type={size === 'sm' ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_LARGE_BOLD}
62
+ className={contentClassNames}
142
63
  >
143
- {children}
144
64
  {loading && (
145
65
  <ProcessIndicator
146
- size={processIndicatorSize()}
147
- className="btn-loader"
148
- data-testid="ButtonProgressIndicator"
66
+ size={size === 'sm' ? 'xxs' : 'xs'}
67
+ className="wds-Button-loader"
68
+ data-testid="button-loader-indicator"
149
69
  />
150
70
  )}
151
- </Element>
71
+ <span className="wds-Button-label" aria-hidden={loading}>
72
+ {size === 'lg' ? (
73
+ children
74
+ ) : (
75
+ <>
76
+ {size === 'md' && addonStart?.avatars && (
77
+ <span className="wds-Button-avatars">
78
+ <AvatarLayout orientation="horizontal" avatars={addonStart?.avatars} size={24} />
79
+ </span>
80
+ )}
81
+ {!addonStart?.avatars && addonStart?.icon && (
82
+ <span className="wds-Button-icon wds-Button-icon--start">{addonStart.icon}</span>
83
+ )}
84
+ {children}
85
+ {addonEnd?.icon && (
86
+ <span className="wds-Button-icon wds-Button-icon--end">{addonEnd.icon}</span>
87
+ )}
88
+ </>
89
+ )}
90
+ </span>
91
+ </Body>
92
+ );
93
+
94
+ if (href || as === 'a') {
95
+ return (
96
+ <PrimitiveAnchor
97
+ ref={ref as React.Ref<HTMLAnchorElement>}
98
+ {...(props as any)}
99
+ href={href}
100
+ className={classNames}
101
+ disabled={disabled || loading}
102
+ aria-busy={loading || undefined}
103
+ >
104
+ {content}
105
+ </PrimitiveAnchor>
106
+ );
107
+ }
108
+
109
+ return (
110
+ <PrimitiveButton
111
+ ref={ref as React.Ref<HTMLButtonElement>}
112
+ {...(props as any)}
113
+ className={classNames}
114
+ disabled={disabled}
115
+ loading={loading}
116
+ type={type}
117
+ >
118
+ {content}
119
+ </PrimitiveButton>
152
120
  );
153
121
  },
154
122
  );
@@ -0,0 +1,94 @@
1
+ import { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from 'react';
2
+ import type { PrimitiveButtonProps, PrimitiveAnchorProps } from '../primitives';
3
+ import type { AvatarLayoutProps } from '../avatarLayout';
4
+
5
+ export type ButtonSentiment = 'default' | 'negative';
6
+ export type ButtonPriority = 'primary' | 'secondary' | 'tertiary' | 'minimal';
7
+ export type ButtonSize = 'sm' | 'md' | 'lg';
8
+ export type ButtonReferenceType = HTMLButtonElement | HTMLAnchorElement;
9
+
10
+ /**
11
+ * Common properties for the Button component.
12
+ */
13
+ export interface CommonProps {
14
+ v2: true;
15
+
16
+ /**
17
+ * The HTML element to render
18
+ * @default 'button'
19
+ **/
20
+ as?: 'button' | 'a';
21
+
22
+ /** Additional class name(s) to apply to the button */
23
+ className?: string;
24
+
25
+ /**
26
+ * @default false
27
+ **/
28
+ disabled?: boolean;
29
+
30
+ href?: string;
31
+
32
+ /**
33
+ * @default false
34
+ * */
35
+ loading?: boolean;
36
+
37
+ /** Whether the button should take up the full width of its container */
38
+ block?: boolean;
39
+
40
+ /**
41
+ * Size of the button
42
+ * @default lg
43
+ * */
44
+ size?: ButtonSize;
45
+
46
+ /**
47
+ * Priority of the button
48
+ * @default "primary"
49
+ */
50
+ priority?: ButtonPriority;
51
+
52
+ /**
53
+ * Sentiment of the button
54
+ * @default default
55
+ */
56
+ sentiment?: ButtonSentiment;
57
+
58
+ /** Icon to be displayed on the left side of the button */
59
+ iconStart?: React.ElementType;
60
+
61
+ /** Icon to be displayed on the right side of the button */
62
+ iconEnd?: React.ElementType;
63
+
64
+ /** Media to be displayed on the left side of the button */
65
+ avatars?: AvatarLayoutProps['avatars'];
66
+
67
+ /** Content to be displayed inside the button */
68
+ children?: ReactNode;
69
+
70
+ addonStart?: ButtonAddonStart;
71
+ addonEnd?: ButtonAddonEnd;
72
+ }
73
+
74
+ type ButtonAddonStart = {
75
+ icon?: React.ReactNode;
76
+ avatars?: AvatarLayoutProps['avatars'];
77
+ };
78
+
79
+ type ButtonAddonEnd = {
80
+ icon?: React.ReactNode;
81
+ };
82
+
83
+ export type ButtonElementProps = Omit<
84
+ ButtonHTMLAttributes<HTMLButtonElement>,
85
+ 'disabled' | 'className'
86
+ > &
87
+ CommonProps;
88
+ export type AnchorElementProps = Omit<
89
+ AnchorHTMLAttributes<HTMLAnchorElement>,
90
+ 'type' | 'disabled' | 'href' | 'className'
91
+ > &
92
+ CommonProps;
93
+
94
+ export type ButtonProps = ButtonElementProps | AnchorElementProps;
@@ -0,0 +1,46 @@
1
+ .wds-Button {
2
+ --Button-background: var(--color-interactive-accent);
3
+ --Button-background-hover: var(--color-interactive-accent-hover);
4
+ --Button-background-active: var(--color-interactive-accent-active);
5
+ --Button-color: var(--color-interactive-control);
6
+ --Button-border-radius: var(--radius-full);
7
+ --Button-label-gap: var(--size-4);
8
+ --Button-large-padding: var(--size-12) var(--size-16);
9
+ --Button-medium-padding: var(--size-8) var(--size-12);
10
+ --Button-small-padding: calc(var(--size-10) * 0.5) var(--size-12);
11
+ --Button-avatar-border-color: var(--color-border-neutral);
12
+ --Button-transition-duration: 150ms;
13
+ --Button-transition-easing: ease-in-out;
14
+ --Button-secondary-background: var(--color-interactive-neutral);
15
+ --Button-secondary-background-hover: var(--color-interactive-neutral-hover);
16
+ --Button-secondary-background-active: var(--color-interactive-neutral-active);
17
+ --Button-secondary-color: var(--color-interactive-primary);
18
+ --Button-tertiary-background: var(--color-background-neutral);
19
+ --Button-tertiary-background-hover: var(--color-background-neutral-hover);
20
+ --Button-tertiary-background-active: var(--color-background-neutral-active);
21
+ --Button-tertiary-color: var(--color-content-primary);
22
+ --Button-minimal-background: transparent;
23
+ --Button-minimal-background-hover: var(--color-background-screen-hover);
24
+ --Button-minimal-background-active: var(--color-background-screen-active);
25
+ --Button-minimal-color: var(--color-interactive-primary);
26
+ --Button-primary-negative-background: var(--color-sentiment-negative-primary);
27
+ --Button-primary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
28
+ --Button-primary-negative-background-active: var(--color-sentiment-negative-primary-active);
29
+ --Button-primary-negative-color: var(--color-contrast-overlay);
30
+ --Button-secondary-negative-background: var(--color-sentiment-negative-secondary);
31
+ --Button-secondary-negative-background-hover: var(--color-sentiment-negative-secondary-hover);
32
+ --Button-secondary-negative-background-active: var(--color-sentiment-negative-secondary-active);
33
+ --Button-secondary-negative-color: var(--color-sentiment-negative-primary);
34
+ }
35
+ .np-theme-personal--bright-green .wds-Button {
36
+ --Button-primary-negative-color: var(--color-white);
37
+ --Button-secondary-color: var(--color-interactive-control);
38
+ --Button-secondary-negative-color: var(--color-white);
39
+ }
40
+ .np-theme-personal--forest-green .wds-Button {
41
+ --Button-secondary-background: var(--color-interactive-neutral);
42
+ --Button-secondary-negative-background: var(--color-sentiment-negative-primary);
43
+ --Button-secondary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
44
+ --Button-secondary-negative-background-active: var(--color-sentiment-negative-primary-active);
45
+ --Button-secondary-negative-color: var(--color-contrast-overlay);
46
+ }
@@ -0,0 +1,60 @@
1
+ .wds-Button {
2
+ --Button-background: var(--color-interactive-accent);
3
+ --Button-background-hover: var(--color-interactive-accent-hover);
4
+ --Button-background-active: var(--color-interactive-accent-active);
5
+ --Button-color: var(--color-interactive-control);
6
+ --Button-border-radius: var(--radius-full);
7
+ --Button-label-gap: var(--size-4);
8
+
9
+ --Button-large-padding: var(--size-12) var(--size-16);
10
+ --Button-medium-padding: var(--size-8) var(--size-12);
11
+ // 5px is required by design
12
+ --Button-small-padding: calc(var(--size-10) * .5) var(--size-12);
13
+
14
+ --Button-avatar-border-color: var(--color-border-neutral);
15
+ --Button-transition-duration: 150ms;
16
+ --Button-transition-easing: ease-in-out;
17
+
18
+ --Button-secondary-background: var(--color-interactive-neutral);
19
+ --Button-secondary-background-hover: var(--color-interactive-neutral-hover);
20
+ --Button-secondary-background-active: var(--color-interactive-neutral-active);
21
+ --Button-secondary-color: var(--color-interactive-primary);
22
+
23
+ --Button-tertiary-background: var(--color-background-neutral);
24
+ --Button-tertiary-background-hover: var(--color-background-neutral-hover);
25
+ --Button-tertiary-background-active: var(--color-background-neutral-active);
26
+ --Button-tertiary-color: var(--color-content-primary);
27
+
28
+ --Button-minimal-background: transparent;
29
+ --Button-minimal-background-hover: var(--color-background-screen-hover);
30
+ --Button-minimal-background-active: var(--color-background-screen-active);
31
+ --Button-minimal-color: var(--color-interactive-primary);
32
+
33
+ --Button-primary-negative-background: var(--color-sentiment-negative-primary);
34
+ --Button-primary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
35
+ --Button-primary-negative-background-active: var(--color-sentiment-negative-primary-active);
36
+ --Button-primary-negative-color: var(--color-contrast-overlay);
37
+
38
+ --Button-secondary-negative-background: var(--color-sentiment-negative-secondary);
39
+ --Button-secondary-negative-background-hover: var(--color-sentiment-negative-secondary-hover);
40
+ --Button-secondary-negative-background-active: var(--color-sentiment-negative-secondary-active);
41
+ --Button-secondary-negative-color: var(--color-sentiment-negative-primary);
42
+
43
+
44
+ .np-theme-personal--bright-green & {
45
+ --Button-primary-negative-color: var(--color-white);
46
+ --Button-secondary-color: var(--color-interactive-control);
47
+ --Button-secondary-negative-color: var(--color-white);
48
+ }
49
+
50
+
51
+ .np-theme-personal--forest-green & {
52
+ --Button-secondary-background: var(--color-interactive-neutral);
53
+ --Button-secondary-negative-background: var(--color-sentiment-negative-primary);
54
+ --Button-secondary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
55
+ --Button-secondary-negative-background-active: var(--color-sentiment-negative-primary-active);
56
+ --Button-secondary-negative-color: var(--color-contrast-overlay);
57
+ }
58
+ }
59
+
60
+
@@ -0,0 +1,23 @@
1
+ .np-btn {
2
+ position: relative;
3
+ }
4
+ .np-btn.np-btn-block > span.btn-loader {
5
+ position: absolute;
6
+ left: 24px;
7
+ left: var(--size-24);
8
+ }
9
+ [dir="rtl"] .np-btn.np-btn-block > span.btn-loader {
10
+ right: 24px;
11
+ right: var(--size-24);
12
+ left: auto;
13
+ left: initial;
14
+ }
15
+ .np-btn.np-btn-xs > span.btn-loader {
16
+ background-size: 16px 16px;
17
+ }
18
+ .np-btn.np-btn-xs.btn-block > span.btn-loader {
19
+ top: 0;
20
+ }
21
+ .np-btn.disabled[class] {
22
+ pointer-events: auto;
23
+ }
@@ -0,0 +1,24 @@
1
+ @import (reference) "../../node_modules/@transferwise/neptune-css/src/less/mixins/_logical-properties.less";
2
+
3
+ .np-btn {
4
+ position: relative;
5
+
6
+ &.np-btn-block > span.btn-loader {
7
+ position: absolute;
8
+ .left(var(--size-24));
9
+ }
10
+
11
+ &.np-btn-xs > span.btn-loader {
12
+ background-size: 16px 16px;
13
+ }
14
+
15
+ &.np-btn-xs.btn-block > span.btn-loader {
16
+ top: 0;
17
+ }
18
+
19
+ // we do not want pointer events disabled as that
20
+ // prevents the custom cursor to be shown
21
+ &.disabled[class] {
22
+ pointer-events: auto;
23
+ }
24
+ }
@@ -0,0 +1,147 @@
1
+ import { createRef } from 'react';
2
+
3
+ import { render, screen, userEvent } from '../test-utils';
4
+
5
+ import LegacyButton from './LegacyButton';
6
+ import messages from '../i18n/commonMessages/Button.messages';
7
+ import { ButtonReferenceType } from './Button.types';
8
+
9
+ describe('LegacyButton', () => {
10
+ // eslint-disable-next-line no-console
11
+ const originalWarn = console.warn;
12
+ let mockedWarn: typeof originalWarn;
13
+
14
+ const props = {
15
+ onClick: jest.fn(),
16
+ onFocus: jest.fn(),
17
+ onBlur: jest.fn(),
18
+ children: 'Send money',
19
+ };
20
+
21
+ beforeAll(() => {
22
+ mockedWarn = jest.fn().mockImplementation((args) => {
23
+ if (typeof args !== 'string' || !args.startsWith('Button has deprecated the')) {
24
+ originalWarn(args);
25
+ }
26
+ });
27
+ // eslint-disable-next-line no-console
28
+ console.warn = mockedWarn;
29
+ });
30
+
31
+ beforeEach(jest.clearAllMocks);
32
+
33
+ afterAll(() => {
34
+ // eslint-disable-next-line no-console
35
+ console.warn = originalWarn;
36
+ });
37
+
38
+ describe('by default', () => {
39
+ it('renders the text', () => {
40
+ render(<LegacyButton {...props} />);
41
+ expect(screen.getByText(props.children)).toBeInTheDocument();
42
+ });
43
+
44
+ it('set `ref` to be true on Button', () => {
45
+ const reference = createRef<ButtonReferenceType>();
46
+
47
+ expect(reference.current).toBeFalsy();
48
+ render(<LegacyButton ref={reference}>Click me!</LegacyButton>);
49
+ expect(reference.current).toBeTruthy();
50
+ });
51
+
52
+ it('is not disabled', () => {
53
+ render(<LegacyButton {...props} />);
54
+ expect(screen.getByRole('button')).toBeEnabled();
55
+ });
56
+ });
57
+
58
+ describe('button attributes', () => {
59
+ it('sets the htmlType if set', () => {
60
+ render(<LegacyButton {...props} htmlType="submit" />);
61
+ expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
62
+ });
63
+
64
+ it('passes through custom classes if set', () => {
65
+ render(<LegacyButton {...props} className="donkeysarethebest" />);
66
+ expect(screen.getByRole('button')).toHaveClass('donkeysarethebest');
67
+ });
68
+
69
+ it('passes through aria-label if set', () => {
70
+ render(<LegacyButton {...props} aria-label="unique label" />);
71
+ const loadingButton = screen.getByLabelText('unique label');
72
+ expect(loadingButton).toBeInTheDocument();
73
+ });
74
+ });
75
+
76
+ describe('onClick', () => {
77
+ it('calls onClick when clicked', async () => {
78
+ render(<LegacyButton {...props} />);
79
+ await userEvent.click(screen.getByRole('button'));
80
+ expect(props.onClick).toHaveBeenCalledTimes(1);
81
+ });
82
+
83
+ it('does not call onClick when clicked if disabled', async () => {
84
+ render(<LegacyButton {...props} disabled />);
85
+ await userEvent.click(screen.getByRole('button'));
86
+ expect(props.onClick).toHaveBeenCalledTimes(0);
87
+ });
88
+
89
+ it('does not call onClick when clicked if loading', async () => {
90
+ render(<LegacyButton {...props} loading />);
91
+ await userEvent.click(screen.getByRole('button'));
92
+ expect(props.onClick).toHaveBeenCalledTimes(0);
93
+ });
94
+ });
95
+
96
+ describe('onFocus and onBlur', () => {
97
+ it('calls both handlers by default', async () => {
98
+ render(<LegacyButton {...props} />);
99
+ await userEvent.tab();
100
+ expect(props.onFocus).toHaveBeenCalledTimes(1);
101
+ await userEvent.tab();
102
+ expect(props.onFocus).toHaveBeenCalledTimes(1);
103
+ });
104
+
105
+ it('does not call either handler if disabled', async () => {
106
+ render(<LegacyButton {...props} disabled />);
107
+ await userEvent.tab();
108
+ expect(props.onFocus).not.toHaveBeenCalled();
109
+ await userEvent.tab();
110
+ expect(props.onFocus).not.toHaveBeenCalled();
111
+ });
112
+
113
+ it('calls both handlers if loading', async () => {
114
+ render(<LegacyButton {...props} loading />);
115
+ await userEvent.tab();
116
+ expect(props.onFocus).toHaveBeenCalledTimes(1);
117
+ await userEvent.tab();
118
+ expect(props.onFocus).toHaveBeenCalledTimes(1);
119
+ });
120
+ });
121
+
122
+ describe('other states', () => {
123
+ it('renders as loading if `loading` is true', () => {
124
+ render(<LegacyButton {...props} loading />);
125
+ const button = screen.queryByRole('button', {
126
+ name: messages.loadingAriaLabel.defaultMessage,
127
+ });
128
+ expect(button).toBeInTheDocument();
129
+ expect(button).toBeEnabled();
130
+ expect(button).toHaveClass('btn-loading');
131
+ expect(button).toHaveAttribute('aria-disabled', 'true');
132
+ expect(button).toHaveAttribute('aria-busy', 'true');
133
+ expect(button).toHaveAttribute('aria-live', 'polite');
134
+ expect(screen.getByTestId('ButtonProgressIndicator')).toBeInTheDocument();
135
+ });
136
+
137
+ it('disables the button', () => {
138
+ render(<LegacyButton {...props} disabled />);
139
+ const button = screen.queryByRole('button');
140
+ expect(button).toBeDisabled();
141
+ expect(button).toHaveClass('disabled');
142
+ expect(button).toHaveAttribute('aria-disabled', 'false');
143
+ expect(button).toHaveAttribute('aria-busy', 'false');
144
+ expect(button).toHaveAttribute('aria-live', 'off');
145
+ });
146
+ });
147
+ });