@transferwise/components 0.0.0-experimental-e7eccea → 0.0.0-experimental-328f2cc
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 +2 -9
- package/build/avatarLayout/AvatarLayout.js.map +1 -1
- package/build/avatarLayout/AvatarLayout.mjs +2 -9
- package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
- package/build/button/Button.js +79 -78
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +80 -79
- package/build/button/Button.mjs.map +1 -1
- 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/index.js +2 -2
- package/build/index.mjs +1 -1
- package/build/link/Link.js +3 -8
- package/build/link/Link.js.map +1 -1
- package/build/link/Link.mjs +3 -8
- package/build/link/Link.mjs.map +1 -1
- package/build/main.css +11 -219
- package/build/nudge/Nudge.js.map +1 -1
- package/build/nudge/Nudge.mjs.map +1 -1
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +3 -1
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +3 -1
- package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +4 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +4 -1
- package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
- package/build/select/Select.js +2 -2
- package/build/select/Select.js.map +1 -1
- package/build/select/Select.mjs +1 -1
- package/build/styles/avatarLayout/AvatarLayout.css +0 -11
- package/build/styles/button/Button.css +15 -200
- package/build/styles/main.css +11 -219
- package/build/styles/nudge/Nudge.css +11 -0
- package/build/types/avatarLayout/AvatarLayout.d.ts +2 -1
- package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
- package/build/types/avatarLayout/index.d.ts +0 -1
- package/build/types/avatarLayout/index.d.ts.map +1 -1
- package/build/types/button/Button.d.ts +23 -1
- package/build/types/button/Button.d.ts.map +1 -1
- 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/nudge/Nudge.d.ts +1 -1
- package/build/types/nudge/Nudge.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 +1 -5
- 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/test-utils/story-config.d.ts +1 -1
- package/build/types/test-utils/story-config.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/alert/Alert.tests.story.tsx +1 -1
- package/src/avatarLayout/AvatarLayout.css +0 -11
- package/src/avatarLayout/AvatarLayout.less +1 -18
- package/src/avatarLayout/AvatarLayout.tsx +3 -11
- package/src/avatarLayout/index.ts +0 -1
- package/src/button/Button.css +15 -200
- package/src/button/Button.less +14 -207
- package/src/button/Button.spec.tsx +227 -75
- package/src/button/Button.story.tsx +135 -729
- package/src/button/Button.tsx +132 -88
- package/src/button/__snapshots__/Button.spec.tsx.snap +309 -0
- package/src/button/index.ts +3 -2
- package/src/field/Field.story.tsx +1 -1
- package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -1
- package/src/inputs/SelectInput.story.tsx +1 -1
- package/src/label/Label.story.tsx +1 -1
- package/src/link/Link.tsx +6 -15
- package/src/main.css +11 -219
- package/src/main.less +0 -1
- package/src/nudge/Nudge.css +11 -0
- package/src/nudge/Nudge.less +3 -0
- package/src/nudge/Nudge.story.tsx +10 -0
- package/src/nudge/Nudge.tsx +2 -1
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +7 -1
- package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +1 -6
- package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +3 -1
- package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +8 -1
- package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +5 -2
- package/src/test-utils/Parameters.d.ts +1 -9
- package/src/test-utils/story-config.ts +1 -10
- package/build/button/Button.resolver.js +0 -86
- package/build/button/Button.resolver.js.map +0 -1
- package/build/button/Button.resolver.mjs +0 -84
- package/build/button/Button.resolver.mjs.map +0 -1
- package/build/button/LegacyButton.js +0 -114
- package/build/button/LegacyButton.js.map +0 -1
- package/build/button/LegacyButton.mjs +0 -112
- package/build/button/LegacyButton.mjs.map +0 -1
- package/build/styles/button/Button.vars.css +0 -39
- package/build/styles/button/LegacyButton.css +0 -23
- package/build/types/button/Button.resolver.d.ts +0 -31
- package/build/types/button/Button.resolver.d.ts.map +0 -1
- package/build/types/button/Button.types.d.ts +0 -65
- package/build/types/button/Button.types.d.ts.map +0 -1
- package/build/types/button/LegacyButton.d.ts +0 -30
- package/build/types/button/LegacyButton.d.ts.map +0 -1
- package/src/button/Button.resolver.tsx +0 -134
- package/src/button/Button.tests.story.tsx +0 -27
- package/src/button/Button.types.ts +0 -86
- package/src/button/Button.vars.css +0 -39
- package/src/button/Button.vars.less +0 -50
- package/src/button/LegacyButton.css +0 -23
- package/src/button/LegacyButton.less +0 -24
- package/src/button/LegacyButton.spec.tsx +0 -146
- package/src/button/LegacyButton.story.tsx +0 -225
- package/src/button/LegacyButton.tsx +0 -161
|
@@ -1,86 +0,0 @@
|
|
|
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';
|
|
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;
|
|
@@ -1,39 +0,0 @@
|
|
|
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);
|
|
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
|
-
--color-contrast: #FFFFFF;
|
|
37
|
-
--Button-secondary-color: var(--color-interactive-control);
|
|
38
|
-
--Button-secondary-negative-color: var(--color-contrast);
|
|
39
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
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);
|
|
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
|
-
.wds-Button {
|
|
46
|
-
--color-contrast: #FFFFFF;
|
|
47
|
-
--Button-secondary-color: var(--color-interactive-control);
|
|
48
|
-
--Button-secondary-negative-color: var(--color-contrast);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { userEvent, within, fn, expect } from '@storybook/test';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
|
|
5
|
-
import Button from '.';
|
|
6
|
-
|
|
7
|
-
const withContainer = (Story: any) => (
|
|
8
|
-
<div
|
|
9
|
-
style={{
|
|
10
|
-
display: 'flex',
|
|
11
|
-
flexDirection: 'initial',
|
|
12
|
-
justifyContent: 'center',
|
|
13
|
-
flexFlow: 'column',
|
|
14
|
-
alignItems: 'center',
|
|
15
|
-
}}
|
|
16
|
-
>
|
|
17
|
-
<Story />
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const meta: Meta<typeof Button> = {
|
|
22
|
-
component: Button,
|
|
23
|
-
title: 'Actions/Button/Legacy',
|
|
24
|
-
args: {
|
|
25
|
-
children: 'Button text',
|
|
26
|
-
loading: false,
|
|
27
|
-
type: undefined,
|
|
28
|
-
onClick: fn(),
|
|
29
|
-
onBlur: fn(),
|
|
30
|
-
onFocus: fn(),
|
|
31
|
-
href: 'https://example.com',
|
|
32
|
-
as: undefined,
|
|
33
|
-
},
|
|
34
|
-
argTypes: {
|
|
35
|
-
as: {
|
|
36
|
-
control: {
|
|
37
|
-
name: 'enum',
|
|
38
|
-
options: ['button', 'a'],
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
type: {
|
|
42
|
-
type: {
|
|
43
|
-
name: 'enum',
|
|
44
|
-
value: ['accent', 'positive', 'negative'],
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
size: {
|
|
48
|
-
type: {
|
|
49
|
-
name: 'enum',
|
|
50
|
-
value: ['xs', 'sm', 'md', 'lg'],
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
priority: {
|
|
54
|
-
type: {
|
|
55
|
-
name: 'enum',
|
|
56
|
-
value: ['primary', 'secondary', 'tertiary'],
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
sentiment: {
|
|
60
|
-
table: {
|
|
61
|
-
disable: true,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
iconStart: {
|
|
65
|
-
table: {
|
|
66
|
-
disable: true,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
iconEnd: {
|
|
70
|
-
table: {
|
|
71
|
-
disable: true,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
avatars: {
|
|
75
|
-
table: {
|
|
76
|
-
disable: true,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
'data-testid': {
|
|
80
|
-
table: {
|
|
81
|
-
disable: true,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
tags: ['autodocs'],
|
|
86
|
-
decorators: [withContainer],
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export default meta;
|
|
90
|
-
|
|
91
|
-
type Story = StoryObj<typeof Button>;
|
|
92
|
-
|
|
93
|
-
export const Basic: Story = {};
|
|
94
|
-
|
|
95
|
-
export const Secondary: Story = {
|
|
96
|
-
args: {
|
|
97
|
-
type: 'accent',
|
|
98
|
-
priority: 'secondary',
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export const Tertiary: Story = {
|
|
103
|
-
args: {
|
|
104
|
-
type: 'accent',
|
|
105
|
-
priority: 'tertiary',
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export const Negative: Story = {
|
|
110
|
-
args: {
|
|
111
|
-
type: 'negative',
|
|
112
|
-
priority: 'primary',
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export const Loading: Story = {
|
|
117
|
-
args: {
|
|
118
|
-
loading: true,
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export const Variants: Story = {
|
|
123
|
-
render: () => {
|
|
124
|
-
return (
|
|
125
|
-
<div className="d-flex flex-column p-b-2 align-items-start">
|
|
126
|
-
<div className="d-flex flex-row p-b-2" style={{ gap: 'var(--size-16)' }}>
|
|
127
|
-
<Button type="accent" priority="primary">
|
|
128
|
-
Primary Accent
|
|
129
|
-
</Button>
|
|
130
|
-
<Button type="accent" priority="secondary">
|
|
131
|
-
Secondary Accent
|
|
132
|
-
</Button>
|
|
133
|
-
<Button type="accent" priority="tertiary">
|
|
134
|
-
Tertiary Accent
|
|
135
|
-
</Button>
|
|
136
|
-
</div>
|
|
137
|
-
<div className="d-flex flex-row p-b-2" style={{ gap: 'var(--size-16)' }}>
|
|
138
|
-
<Button type="positive" priority="primary">
|
|
139
|
-
Primary Positive
|
|
140
|
-
</Button>
|
|
141
|
-
<Button type="positive" priority="secondary">
|
|
142
|
-
Secondary Accent
|
|
143
|
-
</Button>
|
|
144
|
-
</div>
|
|
145
|
-
<div className="d-flex flex-row flex- p-b-2" style={{ gap: 'var(--size-16)' }}>
|
|
146
|
-
<Button type="negative" priority="primary">
|
|
147
|
-
Primary Negative
|
|
148
|
-
</Button>
|
|
149
|
-
<Button type="negative" priority="secondary">
|
|
150
|
-
Secondary Negative
|
|
151
|
-
</Button>
|
|
152
|
-
</div>
|
|
153
|
-
<div className="d-flex flex-row p-b-1" style={{ gap: 'var(--size-16)' }}>
|
|
154
|
-
<Button type="accent" priority="primary" disabled>
|
|
155
|
-
Button Disabled
|
|
156
|
-
</Button>
|
|
157
|
-
<Button type="accent" priority="secondary" disabled>
|
|
158
|
-
Button Disabled
|
|
159
|
-
</Button>
|
|
160
|
-
<Button type="accent" priority="tertiary" disabled>
|
|
161
|
-
Button Disabled
|
|
162
|
-
</Button>
|
|
163
|
-
</div>
|
|
164
|
-
</div>
|
|
165
|
-
);
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const wait = async (duration = 500) =>
|
|
170
|
-
new Promise<void>((resolve) => {
|
|
171
|
-
setTimeout(resolve, duration);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
export const Focused: Story = {
|
|
175
|
-
play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
|
|
176
|
-
const canvas = within(canvasElement);
|
|
177
|
-
const button = canvas.getByRole('button');
|
|
178
|
-
await userEvent.tab();
|
|
179
|
-
await expect(button).toHaveFocus();
|
|
180
|
-
await expect(button).toHaveTextContent('Focused!');
|
|
181
|
-
},
|
|
182
|
-
render: function Render(args: React.ComponentProps<typeof Button>) {
|
|
183
|
-
const [focused, setFocused] = useState(false);
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<Button {...args} onFocus={() => setFocused(true)}>
|
|
187
|
-
{focused ? 'Focused!' : 'Button text'}
|
|
188
|
-
</Button>
|
|
189
|
-
);
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export const SocialMedia: Story = {
|
|
194
|
-
render: () => {
|
|
195
|
-
return (
|
|
196
|
-
<>
|
|
197
|
-
<div className="m-b-2">
|
|
198
|
-
<button type="button" className="btn btn-google">
|
|
199
|
-
Login with Google
|
|
200
|
-
</button>
|
|
201
|
-
</div>
|
|
202
|
-
<div className="m-b-2">
|
|
203
|
-
<button type="button" className="btn btn-facebook">
|
|
204
|
-
Login with Facebook
|
|
205
|
-
</button>
|
|
206
|
-
</div>
|
|
207
|
-
<div className="m-b-2">
|
|
208
|
-
<button type="button" className="btn btn-lg btn-facebook">
|
|
209
|
-
Large Button
|
|
210
|
-
</button>
|
|
211
|
-
</div>
|
|
212
|
-
<div className="m-b-2">
|
|
213
|
-
<button type="button" className="btn btn-block btn-facebook">
|
|
214
|
-
Block Button
|
|
215
|
-
</button>
|
|
216
|
-
</div>
|
|
217
|
-
<div className="m-b-2">
|
|
218
|
-
<button type="button" className="btn btn-lg btn-block btn-facebook">
|
|
219
|
-
Large Block Button
|
|
220
|
-
</button>
|
|
221
|
-
</div>
|
|
222
|
-
</>
|
|
223
|
-
);
|
|
224
|
-
},
|
|
225
|
-
};
|