@transferwise/components 0.0.0-experimental-bc13343 → 0.0.0-experimental-739bfcf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/avatarLayout/AvatarLayout.js +9 -2
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +9 -2
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/button/Button.js +78 -79
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +79 -80
- package/build/button/Button.mjs.map +1 -1
- package/build/button/Button.resolver.js +78 -0
- package/build/button/Button.resolver.js.map +1 -0
- package/build/button/Button.resolver.mjs +76 -0
- package/build/button/Button.resolver.mjs.map +1 -0
- package/build/button/LegacyButton.js +114 -0
- package/build/button/LegacyButton.js.map +1 -0
- package/build/button/LegacyButton.mjs +112 -0
- package/build/button/LegacyButton.mjs.map +1 -0
- package/build/criticalBanner/CriticalCommsBanner.js +2 -2
- package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
- package/build/header/Header.js +2 -2
- package/build/header/Header.js.map +1 -1
- package/build/header/Header.mjs +1 -1
- package/build/i18n/ja.json +0 -1
- package/build/i18n/ja.json.js +0 -1
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +0 -1
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/pt.json +0 -1
- package/build/i18n/pt.json.js +0 -1
- package/build/i18n/pt.json.js.map +1 -1
- package/build/i18n/pt.json.mjs +0 -1
- package/build/i18n/pt.json.mjs.map +1 -1
- package/build/i18n/ru.json +0 -1
- package/build/i18n/ru.json.js +0 -1
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +0 -1
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +0 -1
- package/build/i18n/zh-HK.json.js +0 -1
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +0 -1
- package/build/i18n/zh-HK.json.mjs.map +1 -1
- package/build/index.js +2 -2
- package/build/index.mjs +1 -1
- package/build/link/Link.js +8 -3
- package/build/link/Link.js.map +1 -1
- package/build/link/Link.mjs +8 -3
- package/build/link/Link.mjs.map +1 -1
- package/build/main.css +250 -0
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +1 -3
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +1 -3
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +1 -4
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +1 -4
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
- package/build/select/Select.js +5 -3
- package/build/select/Select.js.map +1 -1
- package/build/select/Select.mjs +4 -2
- package/build/select/Select.mjs.map +1 -1
- package/build/styles/avatarLayout/AvatarLayout.css +11 -0
- package/build/styles/button/Button.css +231 -15
- package/build/styles/button/Button.vars.css +38 -0
- package/build/styles/button/LegacyButton.css +23 -0
- package/build/styles/main.css +250 -0
- package/build/types/avatarLayout/AvatarLayout.d.ts +1 -2
- package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
- package/build/types/avatarLayout/index.d.ts +1 -0
- package/build/types/avatarLayout/index.d.ts.map +1 -1
- package/build/types/button/Button.d.ts +1 -23
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/button/Button.resolver.d.ts +31 -0
- package/build/types/button/Button.resolver.d.ts.map +1 -0
- package/build/types/button/Button.types.d.ts +65 -0
- package/build/types/button/Button.types.d.ts.map +1 -0
- package/build/types/button/LegacyButton.d.ts +30 -0
- package/build/types/button/LegacyButton.d.ts.map +1 -0
- package/build/types/button/index.d.ts +2 -2
- package/build/types/button/index.d.ts.map +1 -1
- package/build/types/link/Link.d.ts +2 -2
- package/build/types/link/Link.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +5 -1
- package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
- package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
- package/build/types/select/Select.d.ts.map +1 -1
- package/build/upload/steps/completeStep/completeStep.js +2 -2
- package/build/upload/steps/completeStep/completeStep.js.map +1 -1
- package/build/upload/steps/completeStep/completeStep.mjs +1 -1
- package/build/upload/steps/processingStep/processingStep.js +2 -2
- package/build/upload/steps/processingStep/processingStep.js.map +1 -1
- package/build/upload/steps/processingStep/processingStep.mjs +1 -1
- package/build/uploadInput/UploadInput.js +3 -3
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/package.json +3 -3
- package/src/avatarLayout/AvatarLayout.css +11 -0
- package/src/avatarLayout/AvatarLayout.less +18 -1
- package/src/avatarLayout/AvatarLayout.tsx +11 -3
- package/src/avatarLayout/index.ts +1 -0
- package/src/button/Button.css +231 -15
- package/src/button/Button.less +232 -14
- package/src/button/Button.resolver.tsx +120 -0
- package/src/button/Button.spec.tsx +54 -231
- package/src/button/Button.story.tsx +612 -137
- package/src/button/Button.tsx +88 -132
- package/src/button/Button.types.ts +86 -0
- package/src/button/Button.vars.css +38 -0
- package/src/button/Button.vars.less +46 -0
- package/src/button/LegacyButton.css +23 -0
- package/src/button/LegacyButton.less +24 -0
- package/src/button/LegacyButton.spec.tsx +146 -0
- package/src/button/LegacyButton.story.tsx +224 -0
- package/src/button/LegacyButton.tsx +161 -0
- package/src/button/index.ts +2 -3
- package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -1
- package/src/i18n/ja.json +0 -1
- package/src/i18n/pt.json +0 -1
- package/src/i18n/ru.json +0 -1
- package/src/i18n/zh-HK.json +0 -1
- package/src/inputs/SelectInput.story.tsx +1 -1
- package/src/link/Link.tsx +15 -6
- package/src/main.css +250 -0
- package/src/main.less +1 -0
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +1 -7
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +6 -1
- package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -3
- package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +1 -8
- package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +2 -5
- package/src/select/Select.tsx +1 -0
- package/src/button/__snapshots__/Button.spec.tsx.snap +0 -309
package/src/button/Button.tsx
CHANGED
|
@@ -1,154 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
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';
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
import { ButtonProps as NewButtonProps } from './Button.types';
|
|
4
|
+
import { PrimitiveAnchor, PrimitiveButton } from '../primitives';
|
|
5
|
+
import AvatarLayout from '../avatarLayout';
|
|
20
6
|
import ProcessIndicator from '../processIndicator';
|
|
7
|
+
import { clsx } from 'clsx';
|
|
8
|
+
import { Typography } from '../common';
|
|
9
|
+
import Body from '../body';
|
|
21
10
|
|
|
22
|
-
|
|
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>(
|
|
11
|
+
const Button = forwardRef<HTMLButtonElement | HTMLAnchorElement, NewButtonProps>(
|
|
57
12
|
(
|
|
58
13
|
{
|
|
59
|
-
as
|
|
60
|
-
block = false,
|
|
14
|
+
as = 'button',
|
|
61
15
|
children,
|
|
62
16
|
className,
|
|
63
|
-
|
|
17
|
+
size = 'lg',
|
|
18
|
+
href,
|
|
19
|
+
disabled = false,
|
|
20
|
+
priority = 'primary',
|
|
21
|
+
sentiment = 'default',
|
|
22
|
+
iconStart: IconStart,
|
|
23
|
+
iconEnd: IconEnd,
|
|
24
|
+
avatars,
|
|
25
|
+
type = 'button',
|
|
64
26
|
loading = false,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
...rest
|
|
70
|
-
}: Props,
|
|
71
|
-
reference,
|
|
27
|
+
block = false,
|
|
28
|
+
...props
|
|
29
|
+
},
|
|
30
|
+
ref,
|
|
72
31
|
) => {
|
|
73
|
-
const
|
|
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}`,
|
|
32
|
+
const classNames = clsx(
|
|
33
|
+
'wds-Button',
|
|
83
34
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
35
|
+
[`wds-Button--block`]: block,
|
|
36
|
+
[`wds-Button--disabled`]: disabled,
|
|
37
|
+
[`wds-Button--loading`]: loading,
|
|
87
38
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// @ts-expect-error fix when refactor `typeClassMap` to TypeScript
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
93
|
-
priorityClassMap[newPriority],
|
|
39
|
+
`wds-Button--${{ sm: 'small', md: 'medium', lg: 'large' }[size]}`,
|
|
40
|
+
`wds-Button--${priority}`,
|
|
41
|
+
`wds-Button--${sentiment}`,
|
|
94
42
|
className,
|
|
95
43
|
);
|
|
96
44
|
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
};
|
|
45
|
+
const contentClassNames = clsx('wds-Button-content', {
|
|
46
|
+
[`wds-Button-content--loading`]: loading,
|
|
47
|
+
});
|
|
132
48
|
|
|
133
|
-
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{...props}
|
|
139
|
-
aria-live={loading ? 'polite' : 'off'}
|
|
140
|
-
aria-busy={loading}
|
|
141
|
-
aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}
|
|
49
|
+
const content = (
|
|
50
|
+
<Body
|
|
51
|
+
as="span"
|
|
52
|
+
type={size === 'sm' ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_LARGE_BOLD}
|
|
53
|
+
className={contentClassNames}
|
|
142
54
|
>
|
|
143
|
-
{children}
|
|
144
55
|
{loading && (
|
|
145
56
|
<ProcessIndicator
|
|
146
|
-
size=
|
|
147
|
-
className="
|
|
148
|
-
data-testid="
|
|
57
|
+
size="xs"
|
|
58
|
+
className="wds-Button-loader"
|
|
59
|
+
data-testid="button-loader-indicator"
|
|
149
60
|
/>
|
|
150
61
|
)}
|
|
151
|
-
|
|
62
|
+
<span className="wds-Button-label" aria-hidden={loading}>
|
|
63
|
+
{size === 'lg' ? (
|
|
64
|
+
children
|
|
65
|
+
) : (
|
|
66
|
+
<>
|
|
67
|
+
{size === 'md' && avatars && (
|
|
68
|
+
<span className="wds-Button-avatars">
|
|
69
|
+
<AvatarLayout orientation="horizontal" avatars={avatars} size={24} />
|
|
70
|
+
</span>
|
|
71
|
+
)}
|
|
72
|
+
{!avatars && IconStart && (
|
|
73
|
+
<IconStart className="wds-Button-icon wds-Button-icon--start" />
|
|
74
|
+
)}
|
|
75
|
+
{children}
|
|
76
|
+
{IconEnd && <IconEnd className="wds-Button-icon wds-Button-icon--end" />}
|
|
77
|
+
</>
|
|
78
|
+
)}
|
|
79
|
+
</span>
|
|
80
|
+
</Body>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (as === 'a') {
|
|
84
|
+
return (
|
|
85
|
+
<PrimitiveAnchor
|
|
86
|
+
ref={ref as React.Ref<HTMLAnchorElement>}
|
|
87
|
+
{...(props as any)}
|
|
88
|
+
href={href}
|
|
89
|
+
className={classNames}
|
|
90
|
+
disabled={disabled}
|
|
91
|
+
>
|
|
92
|
+
{content}
|
|
93
|
+
</PrimitiveAnchor>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<PrimitiveButton
|
|
99
|
+
ref={ref as React.Ref<HTMLButtonElement>}
|
|
100
|
+
{...(props as any)}
|
|
101
|
+
className={classNames}
|
|
102
|
+
disabled={disabled}
|
|
103
|
+
loading={loading}
|
|
104
|
+
type={type}
|
|
105
|
+
>
|
|
106
|
+
{content}
|
|
107
|
+
</PrimitiveButton>
|
|
152
108
|
);
|
|
153
109
|
},
|
|
154
110
|
);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
PrimitiveButtonProps,
|
|
4
|
+
PrimitiveAnchorProps,
|
|
5
|
+
PrimitiveButtonElementRef,
|
|
6
|
+
PrimitiveAnchorElementRef,
|
|
7
|
+
} from '../primitives';
|
|
8
|
+
import type { SingleAvatarType } from '../avatarLayout';
|
|
9
|
+
|
|
10
|
+
export type ButtonSentiment = 'default' | 'negative';
|
|
11
|
+
export type ButtonPriority = 'primary' | 'secondary' | 'tertiary' | 'minimal';
|
|
12
|
+
export type ButtonType = 'button' | 'submit' | 'reset';
|
|
13
|
+
export type ButtonSize = 'sm' | 'md' | 'lg';
|
|
14
|
+
export type ButtonRefType = PrimitiveButtonElementRef | PrimitiveAnchorElementRef;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Common properties for the Button component.
|
|
18
|
+
*/
|
|
19
|
+
export interface CommonButtonProps {
|
|
20
|
+
/**
|
|
21
|
+
* If set, toggles the new Button API
|
|
22
|
+
* @default false
|
|
23
|
+
* */
|
|
24
|
+
v2?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The HTML element to render
|
|
28
|
+
* @default 'button'
|
|
29
|
+
**/
|
|
30
|
+
as?: 'button' | 'a' | null;
|
|
31
|
+
|
|
32
|
+
/** Additional class name(s) to apply to the button */
|
|
33
|
+
className?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @default false
|
|
37
|
+
**/
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
|
|
40
|
+
href?: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @default false
|
|
44
|
+
* */
|
|
45
|
+
loading?: boolean;
|
|
46
|
+
|
|
47
|
+
/** Whether the button should take up the full width of its container */
|
|
48
|
+
block?: boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Size of the button
|
|
52
|
+
* @default lg
|
|
53
|
+
* */
|
|
54
|
+
size?: ButtonSize;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Priority of the button
|
|
58
|
+
* @default "primary"
|
|
59
|
+
*/
|
|
60
|
+
priority?: ButtonPriority;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Sentiment of the button
|
|
64
|
+
* @default default
|
|
65
|
+
*/
|
|
66
|
+
sentiment?: ButtonSentiment;
|
|
67
|
+
|
|
68
|
+
/** Icon to be displayed on the left side of the button */
|
|
69
|
+
iconStart?: React.ElementType;
|
|
70
|
+
|
|
71
|
+
/** Icon to be displayed on the right side of the button */
|
|
72
|
+
iconEnd?: React.ElementType;
|
|
73
|
+
|
|
74
|
+
/** Media to be displayed on the left side of the button */
|
|
75
|
+
avatars?: SingleAvatarType[];
|
|
76
|
+
|
|
77
|
+
/** Optional property to provide component Ref */
|
|
78
|
+
ref?: ButtonRefType;
|
|
79
|
+
|
|
80
|
+
/** Content to be displayed inside the button */
|
|
81
|
+
children?: ReactNode;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type ButtonElementProps = PrimitiveButtonProps & CommonButtonProps;
|
|
85
|
+
export type AnchorElementProps = PrimitiveAnchorProps & CommonButtonProps;
|
|
86
|
+
export type ButtonProps = ButtonElementProps | AnchorElementProps;
|
|
@@ -0,0 +1,38 @@
|
|
|
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-padding: var(--size-8) var(--size-12);
|
|
7
|
+
--Button-border-radius: var(--radius-full);
|
|
8
|
+
--Button-size-small-padding: 5px var(--size-12);
|
|
9
|
+
--Button-size-medium-padding: var(--size-8) var(--size-12);
|
|
10
|
+
--Button-size-large-padding: var(--size-12) var(--size-16);
|
|
11
|
+
--Button-transition-duration: 150ms;
|
|
12
|
+
--Button-transition-easing: ease-in-out;
|
|
13
|
+
--Button-secondary-background: var(--color-interactive-neutral);
|
|
14
|
+
--Button-secondary-background-hover: var(--color-interactive-neutral-hover);
|
|
15
|
+
--Button-secondary-background-active: var(--color-interactive-neutral-active);
|
|
16
|
+
--Button-secondary-color: var(--color-interactive-primary);
|
|
17
|
+
--Button-tertiary-background: var(--color-background-neutral);
|
|
18
|
+
--Button-tertiary-background-hover: var(--color-background-neutral-hover);
|
|
19
|
+
--Button-tertiary-background-active: var(--color-background-neutral-active);
|
|
20
|
+
--Button-tertiary-color: var(--color-content-primary);
|
|
21
|
+
--Button-minimal-background: transparent;
|
|
22
|
+
--Button-minimal-background-hover: var(--color-background-screen-hover);
|
|
23
|
+
--Button-minimal-background-active: var(--color-background-screen-active);
|
|
24
|
+
--Button-minimal-color: var(--color-interactive-primary);
|
|
25
|
+
--Button-primary-negative-background: var(--color-sentiment-negative-primary);
|
|
26
|
+
--Button-primary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
|
|
27
|
+
--Button-primary-negative-background-active: var(--color-sentiment-negative-primary-active);
|
|
28
|
+
--Button-primary-negative-color: var(--color-contrast);
|
|
29
|
+
--Button-secondary-negative-background: var(--color-sentiment-negative-secondary);
|
|
30
|
+
--Button-secondary-negative-background-hover: var(--color-sentiment-negative-secondary-hover);
|
|
31
|
+
--Button-secondary-negative-background-active: var(--color-sentiment-negative-secondary-active);
|
|
32
|
+
--Button-secondary-negative-color: var(--color-sentiment-negative-primary);
|
|
33
|
+
}
|
|
34
|
+
.np-theme-personal--bright-green .wds-Button {
|
|
35
|
+
--color-contrast: #FFFFFF;
|
|
36
|
+
--Button-secondary-color: var(--color-interactive-control);
|
|
37
|
+
--Button-secondary-negative-color: var(--color-contrast);
|
|
38
|
+
}
|
|
@@ -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-padding: var(--size-8) var(--size-12);
|
|
7
|
+
--Button-border-radius: var(--radius-full);
|
|
8
|
+
--Button-size-small-padding: 5px var(--size-12);
|
|
9
|
+
--Button-size-medium-padding: var(--size-8) var(--size-12);
|
|
10
|
+
--Button-size-large-padding: var(--size-12) var(--size-16);
|
|
11
|
+
--Button-transition-duration: 150ms;
|
|
12
|
+
--Button-transition-easing: ease-in-out;
|
|
13
|
+
|
|
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
|
+
|
|
19
|
+
--Button-tertiary-background: var(--color-background-neutral);
|
|
20
|
+
--Button-tertiary-background-hover: var(--color-background-neutral-hover);
|
|
21
|
+
--Button-tertiary-background-active: var(--color-background-neutral-active);
|
|
22
|
+
--Button-tertiary-color: var(--color-content-primary);
|
|
23
|
+
|
|
24
|
+
--Button-minimal-background: transparent;
|
|
25
|
+
--Button-minimal-background-hover: var(--color-background-screen-hover);
|
|
26
|
+
--Button-minimal-background-active: var(--color-background-screen-active);
|
|
27
|
+
--Button-minimal-color: var(--color-interactive-primary);
|
|
28
|
+
|
|
29
|
+
--Button-primary-negative-background: var(--color-sentiment-negative-primary);
|
|
30
|
+
--Button-primary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
|
|
31
|
+
--Button-primary-negative-background-active: var(--color-sentiment-negative-primary-active);
|
|
32
|
+
--Button-primary-negative-color: var(--color-contrast);
|
|
33
|
+
|
|
34
|
+
--Button-secondary-negative-background: var(--color-sentiment-negative-secondary);
|
|
35
|
+
--Button-secondary-negative-background-hover: var(--color-sentiment-negative-secondary-hover);
|
|
36
|
+
--Button-secondary-negative-background-active: var(--color-sentiment-negative-secondary-active);
|
|
37
|
+
--Button-secondary-negative-color: var(--color-sentiment-negative-primary);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.np-theme-personal--bright-green {
|
|
41
|
+
.wds-Button {
|
|
42
|
+
--color-contrast: #FFFFFF;
|
|
43
|
+
--Button-secondary-color: var(--color-interactive-control);
|
|
44
|
+
--Button-secondary-negative-color: var(--color-contrast);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -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,146 @@
|
|
|
1
|
+
import { createRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { render, screen, userEvent } from '../test-utils';
|
|
4
|
+
|
|
5
|
+
import LegacyButton, { ButtonReferenceType } from './LegacyButton';
|
|
6
|
+
import messages from '../i18n/commonMessages/Button.messages';
|
|
7
|
+
|
|
8
|
+
describe('LegacyButton', () => {
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
const originalWarn = console.warn;
|
|
11
|
+
let mockedWarn: typeof originalWarn;
|
|
12
|
+
|
|
13
|
+
const props = {
|
|
14
|
+
onClick: jest.fn(),
|
|
15
|
+
onFocus: jest.fn(),
|
|
16
|
+
onBlur: jest.fn(),
|
|
17
|
+
children: 'Send money',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
beforeAll(() => {
|
|
21
|
+
mockedWarn = jest.fn().mockImplementation((args) => {
|
|
22
|
+
if (typeof args !== 'string' || !args.startsWith('Button has deprecated the')) {
|
|
23
|
+
originalWarn(args);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.warn = mockedWarn;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
beforeEach(jest.clearAllMocks);
|
|
31
|
+
|
|
32
|
+
afterAll(() => {
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
console.warn = originalWarn;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('by default', () => {
|
|
38
|
+
it('renders the text', () => {
|
|
39
|
+
render(<LegacyButton {...props} />);
|
|
40
|
+
expect(screen.getByText(props.children)).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('set `ref` to be true on Button', () => {
|
|
44
|
+
const reference = createRef<ButtonReferenceType>();
|
|
45
|
+
|
|
46
|
+
expect(reference.current).toBeFalsy();
|
|
47
|
+
render(<LegacyButton ref={reference}>Click me!</LegacyButton>);
|
|
48
|
+
expect(reference.current).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('is not disabled', () => {
|
|
52
|
+
render(<LegacyButton {...props} />);
|
|
53
|
+
expect(screen.getByRole('button')).toBeEnabled();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('button attributes', () => {
|
|
58
|
+
it('sets the htmlType if set', () => {
|
|
59
|
+
render(<LegacyButton {...props} htmlType="submit" />);
|
|
60
|
+
expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('passes through custom classes if set', () => {
|
|
64
|
+
render(<LegacyButton {...props} className="donkeysarethebest" />);
|
|
65
|
+
expect(screen.getByRole('button')).toHaveClass('donkeysarethebest');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('passes through aria-label if set', () => {
|
|
69
|
+
render(<LegacyButton {...props} aria-label="unique label" />);
|
|
70
|
+
const loadingButton = screen.getByLabelText('unique label');
|
|
71
|
+
expect(loadingButton).toBeInTheDocument();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('onClick', () => {
|
|
76
|
+
it('calls onClick when clicked', async () => {
|
|
77
|
+
render(<LegacyButton {...props} />);
|
|
78
|
+
await userEvent.click(screen.getByRole('button'));
|
|
79
|
+
expect(props.onClick).toHaveBeenCalledTimes(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('does not call onClick when clicked if disabled', async () => {
|
|
83
|
+
render(<LegacyButton {...props} disabled />);
|
|
84
|
+
await userEvent.click(screen.getByRole('button'));
|
|
85
|
+
expect(props.onClick).toHaveBeenCalledTimes(0);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('does not call onClick when clicked if loading', async () => {
|
|
89
|
+
render(<LegacyButton {...props} loading />);
|
|
90
|
+
await userEvent.click(screen.getByRole('button'));
|
|
91
|
+
expect(props.onClick).toHaveBeenCalledTimes(0);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('onFocus and onBlur', () => {
|
|
96
|
+
it('calls both handlers by default', async () => {
|
|
97
|
+
render(<LegacyButton {...props} />);
|
|
98
|
+
await userEvent.tab();
|
|
99
|
+
expect(props.onFocus).toHaveBeenCalledTimes(1);
|
|
100
|
+
await userEvent.tab();
|
|
101
|
+
expect(props.onFocus).toHaveBeenCalledTimes(1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('does not call either handler if disabled', async () => {
|
|
105
|
+
render(<LegacyButton {...props} disabled />);
|
|
106
|
+
await userEvent.tab();
|
|
107
|
+
expect(props.onFocus).not.toHaveBeenCalled();
|
|
108
|
+
await userEvent.tab();
|
|
109
|
+
expect(props.onFocus).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('calls both handlers if loading', async () => {
|
|
113
|
+
render(<LegacyButton {...props} loading />);
|
|
114
|
+
await userEvent.tab();
|
|
115
|
+
expect(props.onFocus).toHaveBeenCalledTimes(1);
|
|
116
|
+
await userEvent.tab();
|
|
117
|
+
expect(props.onFocus).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('other states', () => {
|
|
122
|
+
it('renders as loading if `loading` is true', () => {
|
|
123
|
+
render(<LegacyButton {...props} loading />);
|
|
124
|
+
const button = screen.queryByRole('button', {
|
|
125
|
+
name: messages.loadingAriaLabel.defaultMessage,
|
|
126
|
+
});
|
|
127
|
+
expect(button).toBeInTheDocument();
|
|
128
|
+
expect(button).toBeEnabled();
|
|
129
|
+
expect(button).toHaveClass('btn-loading');
|
|
130
|
+
expect(button).toHaveAttribute('aria-disabled', 'true');
|
|
131
|
+
expect(button).toHaveAttribute('aria-busy', 'true');
|
|
132
|
+
expect(button).toHaveAttribute('aria-live', 'polite');
|
|
133
|
+
expect(screen.getByTestId('ButtonProgressIndicator')).toBeInTheDocument();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('disables the button', () => {
|
|
137
|
+
render(<LegacyButton {...props} disabled />);
|
|
138
|
+
const button = screen.queryByRole('button');
|
|
139
|
+
expect(button).toBeDisabled();
|
|
140
|
+
expect(button).toHaveClass('disabled');
|
|
141
|
+
expect(button).toHaveAttribute('aria-disabled', 'false');
|
|
142
|
+
expect(button).toHaveAttribute('aria-busy', 'false');
|
|
143
|
+
expect(button).toHaveAttribute('aria-live', 'off');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|