@transferwise/components 0.0.0-experimental-53c607c → 0.0.0-experimental-b002e6f

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 (130) hide show
  1. package/build/avatarLayout/AvatarLayout.js +2 -9
  2. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  3. package/build/avatarLayout/AvatarLayout.mjs +2 -9
  4. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  5. package/build/button/Button.js +97 -74
  6. package/build/button/Button.js.map +1 -1
  7. package/build/button/Button.mjs +98 -75
  8. package/build/button/Button.mjs.map +1 -1
  9. package/build/common/action/Action.js +1 -1
  10. package/build/common/action/Action.js.map +1 -1
  11. package/build/common/action/Action.mjs +1 -1
  12. package/build/common/action/Action.mjs.map +1 -1
  13. package/build/criticalBanner/CriticalCommsBanner.js +2 -2
  14. package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
  15. package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
  16. package/build/definitionList/DefinitionList.js.map +1 -1
  17. package/build/definitionList/DefinitionList.mjs.map +1 -1
  18. package/build/header/Header.js +2 -2
  19. package/build/header/Header.js.map +1 -1
  20. package/build/header/Header.mjs +1 -1
  21. package/build/index.js +2 -2
  22. package/build/index.mjs +1 -1
  23. package/build/link/Link.js +3 -8
  24. package/build/link/Link.js.map +1 -1
  25. package/build/link/Link.mjs +3 -8
  26. package/build/link/Link.mjs.map +1 -1
  27. package/build/main.css +0 -269
  28. package/build/nudge/Nudge.js +1 -1
  29. package/build/nudge/Nudge.js.map +1 -1
  30. package/build/nudge/Nudge.mjs +1 -1
  31. package/build/nudge/Nudge.mjs.map +1 -1
  32. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +3 -1
  33. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
  34. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +3 -1
  35. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
  36. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +4 -1
  37. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
  38. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +4 -1
  39. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
  40. package/build/select/Select.js +3 -5
  41. package/build/select/Select.js.map +1 -1
  42. package/build/select/Select.mjs +2 -4
  43. package/build/select/Select.mjs.map +1 -1
  44. package/build/styles/avatarLayout/AvatarLayout.css +0 -11
  45. package/build/styles/button/Button.css +16 -251
  46. package/build/styles/main.css +0 -269
  47. package/build/types/avatarLayout/AvatarLayout.d.ts +2 -1
  48. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  49. package/build/types/avatarLayout/index.d.ts +0 -1
  50. package/build/types/avatarLayout/index.d.ts.map +1 -1
  51. package/build/types/button/Button.d.ts +23 -1
  52. package/build/types/button/Button.d.ts.map +1 -1
  53. package/build/types/button/index.d.ts +2 -2
  54. package/build/types/button/index.d.ts.map +1 -1
  55. package/build/types/definitionList/DefinitionList.d.ts +1 -2
  56. package/build/types/definitionList/DefinitionList.d.ts.map +1 -1
  57. package/build/types/link/Link.d.ts +2 -2
  58. package/build/types/link/Link.d.ts.map +1 -1
  59. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
  60. package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
  61. package/build/types/select/Select.d.ts.map +1 -1
  62. package/build/types/test-utils/index.d.ts.map +1 -1
  63. package/build/upload/steps/completeStep/completeStep.js +2 -2
  64. package/build/upload/steps/completeStep/completeStep.js.map +1 -1
  65. package/build/upload/steps/completeStep/completeStep.mjs +1 -1
  66. package/build/upload/steps/processingStep/processingStep.js +2 -2
  67. package/build/upload/steps/processingStep/processingStep.js.map +1 -1
  68. package/build/upload/steps/processingStep/processingStep.mjs +1 -1
  69. package/build/uploadInput/UploadInput.js +3 -3
  70. package/build/uploadInput/UploadInput.js.map +1 -1
  71. package/build/uploadInput/UploadInput.mjs +1 -1
  72. package/package.json +3 -3
  73. package/src/avatarLayout/AvatarLayout.css +0 -11
  74. package/src/avatarLayout/AvatarLayout.less +1 -18
  75. package/src/avatarLayout/AvatarLayout.tsx +3 -11
  76. package/src/avatarLayout/index.ts +0 -1
  77. package/src/avatarWrapper/AvatarWrapper.story.tsx +0 -2
  78. package/src/button/Button.css +16 -251
  79. package/src/button/Button.less +14 -214
  80. package/src/button/Button.spec.tsx +231 -54
  81. package/src/button/Button.story.tsx +136 -287
  82. package/src/button/Button.tsx +131 -86
  83. package/src/button/__snapshots__/{LegacyButton.spec.tsx.snap → Button.spec.tsx.snap} +22 -22
  84. package/src/button/index.ts +3 -2
  85. package/src/common/action/Action.tsx +1 -1
  86. package/src/definitionList/DefinitionList.story.tsx +57 -57
  87. package/src/definitionList/DefinitionList.tsx +1 -1
  88. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -1
  89. package/src/iconButton/IconButton.less +1 -1
  90. package/src/inputs/SelectInput.story.tsx +1 -1
  91. package/src/link/Link.tsx +6 -15
  92. package/src/main.css +0 -269
  93. package/src/main.less +0 -1
  94. package/src/nudge/Nudge.tsx +1 -1
  95. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +7 -1
  96. package/src/primitives/PrimitiveAnchor/stories/PrimitiveAnchor.story.tsx +1 -1
  97. package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +3 -1
  98. package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +8 -1
  99. package/src/primitives/PrimitiveButton/stories/PrimitiveButton.story.tsx +1 -1
  100. package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +5 -2
  101. package/src/select/Select.tsx +0 -1
  102. package/src/slidingPanel/SlidingPanel.spec.tsx +69 -0
  103. package/src/test-utils/index.tsx +1 -0
  104. package/build/button/Button.resolver.js +0 -67
  105. package/build/button/Button.resolver.js.map +0 -1
  106. package/build/button/Button.resolver.mjs +0 -65
  107. package/build/button/Button.resolver.mjs.map +0 -1
  108. package/build/button/LegacyButton.js +0 -114
  109. package/build/button/LegacyButton.js.map +0 -1
  110. package/build/button/LegacyButton.mjs +0 -112
  111. package/build/button/LegacyButton.mjs.map +0 -1
  112. package/build/styles/button/Button.vars.css +0 -57
  113. package/build/styles/button/LegacyButton.css +0 -23
  114. package/build/types/button/Button.resolver.d.ts +0 -31
  115. package/build/types/button/Button.resolver.d.ts.map +0 -1
  116. package/build/types/button/Button.types.d.ts +0 -50
  117. package/build/types/button/Button.types.d.ts.map +0 -1
  118. package/build/types/button/LegacyButton.d.ts +0 -30
  119. package/build/types/button/LegacyButton.d.ts.map +0 -1
  120. package/src/button/Button.resolver.tsx +0 -113
  121. package/src/button/Button.types.ts +0 -70
  122. package/src/button/Button.vars.css +0 -57
  123. package/src/button/Button.vars.less +0 -71
  124. package/src/button/LegacyButton.css +0 -23
  125. package/src/button/LegacyButton.less +0 -24
  126. package/src/button/LegacyButton.spec.tsx +0 -245
  127. package/src/button/LegacyButton.story.tsx +0 -224
  128. package/src/button/LegacyButton.tsx +0 -161
  129. package/src/definitionList/DefinitionList.spec.js +0 -91
  130. package/src/slidingPanel/SlidingPanel.spec.js +0 -56
@@ -1,57 +0,0 @@
1
- :root {
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-font-size: var(--font-size-16);
9
- --Button-line-height: var(--size-24);
10
- --Button-font-weight: var(--font-weight-semi-bold);
11
- --Button-letter-spacing: -0.011em;
12
- --Button-size-small-padding: 5px var(--size-12);
13
- --Button-size-medium-padding: var(--size-8) var(--size-12);
14
- --Button-size-large-padding: var(--size-12) var(--size-16);
15
- --Button-avatar-border-color: var(--color-border-neutral);
16
- --Button-secondary-background: var(--color-interactive-neutral);
17
- --Button-secondary-background-hover: var(--color-interactive-neutral-hover);
18
- --Button-secondary-background-active: var(--color-interactive-neutral-active);
19
- --Button-secondary-color: var(--color-interactive-primary);
20
- --Button-tertiary-background: var(--color-background-neutral);
21
- --Button-tertiary-background-hover: var(--color-background-neutral-hover);
22
- --Button-tertiary-background-active: var(--color-background-neutral-active);
23
- --Button-tertiary-color: var(--color-content-primary);
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
- --Button-primary-negative-background: var(--color-sentiment-negative-primary);
29
- --Button-primary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
30
- --Button-primary-negative-background-active: var(--color-sentiment-negative-primary-active);
31
- --Button-primary-negative-color: var(--color-contrast);
32
- --Button-primary-netative-avatar-border-color: rgba(255,255,255,0.2);
33
- --Button-secondary-negative-background: var(--color-sentiment-negative-secondary);
34
- --Button-secondary-negative-background-hover: var(--color-sentiment-negative-secondary-hover);
35
- --Button-secondary-negative-background-active: var(--color-sentiment-negative-secondary-active);
36
- --Button-secondary-negative-color: var(--color-sentiment-negative-primary);
37
- --Button-secondary-netative-avatar-border-color: rgba(168,32,13,0.12157);
38
- }
39
- .np-theme-personal--dark .wds-Button {
40
- --Button-primary-netative-avatar-border-color: rgba(14,15,12,0.12157);
41
- }
42
- .np-theme-personal--forest-green .wds-Button {
43
- --color-interactive-neutral: rgba(159,232,112,0.2);
44
- --color-interactive-neutral-hover: rgba(205,255,173,0.2);
45
- --color-interactive-neutral-active: rgba(236,255,224,0.2);
46
- --color-sentiment-negative-secondary: rgba(255,196,194,0.2);
47
- --color-sentiment-negative-secondary-hover: rgba(255,220,219,0.2);
48
- --color-sentiment-negative-secondary-active: rgba(255,235,235,0.2);
49
- --Button-primary-netative-avatar-border-color: rgba(14,15,12,0.12157);
50
- --Button-secondary-netative-avatar-border-color: rgba(14,15,12,0.12157);
51
- }
52
- .np-theme-personal--bright-green .wds-Button {
53
- --color-contrast: #FFFFFF;
54
- --Button-secondary-color: var(--color-interactive-control);
55
- --Button-secondary-negative-color: var(--color-contrast);
56
- --Button-secondary-netative-avatar-border-color: var(--Button-primary-netative-avatar-border-color);
57
- }
@@ -1,71 +0,0 @@
1
- :root {
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-font-size: var(--font-size-16);
9
- --Button-line-height: var(--size-24);
10
- --Button-font-weight: var(--font-weight-semi-bold);
11
- --Button-letter-spacing: -0.011em;
12
- --Button-size-small-padding: 5px var(--size-12);
13
- --Button-size-medium-padding: var(--size-8) var(--size-12);
14
- --Button-size-large-padding: var(--size-12) var(--size-16);
15
- --Button-avatar-border-color: var(--color-border-neutral);
16
-
17
- --Button-secondary-background: var(--color-interactive-neutral);
18
- --Button-secondary-background-hover: var(--color-interactive-neutral-hover);
19
- --Button-secondary-background-active: var(--color-interactive-neutral-active);
20
- --Button-secondary-color: var(--color-interactive-primary);
21
-
22
- --Button-tertiary-background: var(--color-background-neutral);
23
- --Button-tertiary-background-hover: var(--color-background-neutral-hover);
24
- --Button-tertiary-background-active: var(--color-background-neutral-active);
25
- --Button-tertiary-color: var(--color-content-primary);
26
-
27
- --Button-minimal-background: transparent;
28
- --Button-minimal-background-hover: var(--color-background-screen-hover);
29
- --Button-minimal-background-active: var(--color-background-screen-active);
30
- --Button-minimal-color: var(--color-interactive-primary);
31
-
32
- --Button-primary-negative-background: var(--color-sentiment-negative-primary);
33
- --Button-primary-negative-background-hover: var(--color-sentiment-negative-primary-hover);
34
- --Button-primary-negative-background-active: var(--color-sentiment-negative-primary-active);
35
- --Button-primary-negative-color: var(--color-contrast);
36
- --Button-primary-netative-avatar-border-color: #FFFFFF33;
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
- --Button-secondary-netative-avatar-border-color: #A8200D1F;
43
- }
44
-
45
- .np-theme-personal--dark {
46
- .wds-Button {
47
- --Button-primary-netative-avatar-border-color: #0E0F0C1F;
48
- }
49
- }
50
-
51
- .np-theme-personal--forest-green {
52
- .wds-Button {
53
- --color-interactive-neutral: #9FE87033;
54
- --color-interactive-neutral-hover: #CDFFAD33;
55
- --color-interactive-neutral-active: #ECFFE033;
56
- --color-sentiment-negative-secondary: #FFC4C233;
57
- --color-sentiment-negative-secondary-hover: #FFDCDB33;
58
- --color-sentiment-negative-secondary-active: #FFEBEB33;
59
- --Button-primary-netative-avatar-border-color: #0E0F0C1F;
60
- --Button-secondary-netative-avatar-border-color: #0E0F0C1F;
61
- }
62
- }
63
-
64
- .np-theme-personal--bright-green {
65
- .wds-Button {
66
- --color-contrast: #FFFFFF;
67
- --Button-secondary-color: var(--color-interactive-control);
68
- --Button-secondary-negative-color: var(--color-contrast);
69
- --Button-secondary-netative-avatar-border-color: var(--Button-primary-netative-avatar-border-color);
70
- }
71
- }
@@ -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,245 +0,0 @@
1
- import { createRef } from 'react';
2
-
3
- import { ControlType, Type, Priority, Size } from '../common';
4
- import { render, screen, userEvent } from '../test-utils';
5
-
6
- import LegacyButton, { ButtonReferenceType } from './LegacyButton';
7
- import messages from '../i18n/commonMessages/Button.messages';
8
-
9
- const { ACCENT, POSITIVE, NEGATIVE } = ControlType;
10
- const { PAY, LINK, DANGER } = Type;
11
- const { PRIMARY, SECONDARY, TERTIARY } = Priority;
12
- const { SMALL, MEDIUM, LARGE } = Size;
13
-
14
- describe('LegacyButton', () => {
15
- // eslint-disable-next-line no-console
16
- const originalWarn = console.warn;
17
- let mockedWarn: typeof originalWarn;
18
-
19
- const props = {
20
- onClick: jest.fn(),
21
- onFocus: jest.fn(),
22
- onBlur: jest.fn(),
23
- children: 'Send money',
24
- };
25
-
26
- beforeAll(() => {
27
- mockedWarn = jest.fn().mockImplementation((args) => {
28
- if (typeof args !== 'string' || !args.startsWith('Button has deprecated the')) {
29
- originalWarn(args);
30
- }
31
- });
32
- // eslint-disable-next-line no-console
33
- console.warn = mockedWarn;
34
- });
35
-
36
- beforeEach(jest.clearAllMocks);
37
-
38
- afterAll(() => {
39
- // eslint-disable-next-line no-console
40
- console.warn = originalWarn;
41
- });
42
-
43
- describe('by default', () => {
44
- it('renders the text', () => {
45
- render(<LegacyButton {...props} />);
46
- expect(screen.getByText(props.children)).toBeInTheDocument();
47
- });
48
-
49
- it('set `ref` to be true on Button', () => {
50
- const reference = createRef<ButtonReferenceType>();
51
-
52
- expect(reference.current).toBeFalsy();
53
- render(<LegacyButton ref={reference}>Click me!</LegacyButton>);
54
- expect(reference.current).toBeTruthy();
55
- });
56
-
57
- it('is not disabled', () => {
58
- render(<LegacyButton {...props} />);
59
- expect(screen.getByRole('button')).toBeEnabled();
60
- });
61
-
62
- it('renders a medium button of type accent and priority primary', () => {
63
- expect(render(<LegacyButton {...props} />).container).toMatchSnapshot();
64
- });
65
-
66
- it('renders an anchor tag with button styles of type accent and priority primary', () => {
67
- expect(render(<LegacyButton {...props} as="a" href="#" />).container).toMatchSnapshot();
68
- });
69
- });
70
-
71
- describe('button attributes', () => {
72
- it('sets the htmlType if set', () => {
73
- render(<LegacyButton {...props} htmlType="submit" />);
74
- expect(screen.getByRole('button')).toHaveAttribute('type', 'submit');
75
- });
76
-
77
- it('passes through custom classes if set', () => {
78
- render(<LegacyButton {...props} className="donkeysarethebest" />);
79
- expect(screen.getByRole('button')).toHaveClass('donkeysarethebest');
80
- });
81
-
82
- it('passes through aria-label if set', () => {
83
- render(<LegacyButton {...props} aria-label="unique label" />);
84
- const loadingButton = screen.getByLabelText('unique label');
85
- expect(loadingButton).toBeInTheDocument();
86
- });
87
- });
88
-
89
- describe('onClick', () => {
90
- it('calls onClick when clicked', async () => {
91
- render(<LegacyButton {...props} />);
92
- await userEvent.click(screen.getByRole('button'));
93
- expect(props.onClick).toHaveBeenCalledTimes(1);
94
- });
95
-
96
- it('does not call onClick when clicked if disabled', async () => {
97
- render(<LegacyButton {...props} disabled />);
98
- await userEvent.click(screen.getByRole('button'));
99
- expect(props.onClick).toHaveBeenCalledTimes(0);
100
- });
101
-
102
- it('does not call onClick when clicked if loading', async () => {
103
- render(<LegacyButton {...props} loading />);
104
- await userEvent.click(screen.getByRole('button'));
105
- expect(props.onClick).toHaveBeenCalledTimes(0);
106
- });
107
- });
108
-
109
- describe('onFocus and onBlur', () => {
110
- it('calls both handlers by default', async () => {
111
- render(<LegacyButton {...props} />);
112
- await userEvent.tab();
113
- expect(props.onFocus).toHaveBeenCalledTimes(1);
114
- await userEvent.tab();
115
- expect(props.onFocus).toHaveBeenCalledTimes(1);
116
- });
117
-
118
- it('does not call either handler if disabled', async () => {
119
- render(<LegacyButton {...props} disabled />);
120
- await userEvent.tab();
121
- expect(props.onFocus).not.toHaveBeenCalled();
122
- await userEvent.tab();
123
- expect(props.onFocus).not.toHaveBeenCalled();
124
- });
125
-
126
- it('calls both handlers if loading', async () => {
127
- render(<LegacyButton {...props} loading />);
128
- await userEvent.tab();
129
- expect(props.onFocus).toHaveBeenCalledTimes(1);
130
- await userEvent.tab();
131
- expect(props.onFocus).toHaveBeenCalledTimes(1);
132
- });
133
- });
134
-
135
- describe('sizes', () => {
136
- it('renders small buttons', () => {
137
- expect(render(<LegacyButton {...props} size={SMALL} />).container).toMatchSnapshot();
138
- });
139
-
140
- it('renders medium buttons', () => {
141
- expect(render(<LegacyButton {...props} size={MEDIUM} />).container).toMatchSnapshot();
142
- });
143
-
144
- it('renders large buttons', () => {
145
- expect(render(<LegacyButton {...props} size={LARGE} />).container).toMatchSnapshot();
146
- });
147
- });
148
-
149
- describe('types', () => {
150
- it('renders accent buttons', () => {
151
- expect(render(<LegacyButton {...props} type={ACCENT} />).container).toMatchSnapshot();
152
- });
153
-
154
- it('renders positive buttons', () => {
155
- expect(render(<LegacyButton {...props} type={POSITIVE} />).container).toMatchSnapshot();
156
- });
157
-
158
- it('renders negative buttons', () => {
159
- expect(render(<LegacyButton {...props} type={NEGATIVE} />).container).toMatchSnapshot();
160
- });
161
- });
162
-
163
- describe('priorities', () => {
164
- it('renders primary buttons', () => {
165
- [ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
166
- expect(
167
- render(<LegacyButton {...props} priority={PRIMARY} type={type} />).container,
168
- ).toMatchSnapshot(),
169
- );
170
- });
171
-
172
- it('renders secondary buttons', () => {
173
- [ACCENT, POSITIVE, NEGATIVE].forEach((type) =>
174
- expect(
175
- render(<LegacyButton {...props} priority={SECONDARY} type={type} />).container,
176
- ).toMatchSnapshot(),
177
- );
178
- });
179
-
180
- it('renders tertiary buttons', () => {
181
- expect(
182
- render(<LegacyButton {...props} priority={TERTIARY} type={ACCENT} />).container,
183
- ).toMatchSnapshot();
184
- });
185
-
186
- it('defaults tertiary buttons to secondary for positive buttons', () => {
187
- [POSITIVE, NEGATIVE].forEach((type) =>
188
- expect(
189
- render(<LegacyButton {...props} priority={TERTIARY} type={type} />).container,
190
- ).toMatchSnapshot(),
191
- );
192
- });
193
- });
194
-
195
- describe('other states', () => {
196
- it('renders as loading if `loading` is true', () => {
197
- render(<LegacyButton {...props} loading />);
198
- const button = screen.queryByRole('button', {
199
- name: messages.loadingAriaLabel.defaultMessage,
200
- });
201
- expect(button).toBeInTheDocument();
202
- expect(button).toBeEnabled();
203
- expect(button).toHaveClass('btn-loading');
204
- expect(button).toHaveAttribute('aria-disabled', 'true');
205
- expect(button).toHaveAttribute('aria-busy', 'true');
206
- expect(button).toHaveAttribute('aria-live', 'polite');
207
- expect(screen.getByTestId('ButtonProgressIndicator')).toBeInTheDocument();
208
- });
209
-
210
- it('disables the button', () => {
211
- render(<LegacyButton {...props} disabled />);
212
- const button = screen.queryByRole('button');
213
- expect(button).toBeDisabled();
214
- expect(button).toHaveClass('disabled');
215
- expect(button).toHaveAttribute('aria-disabled', 'false');
216
- expect(button).toHaveAttribute('aria-busy', 'false');
217
- expect(button).toHaveAttribute('aria-live', 'off');
218
- });
219
-
220
- it('renders as block if block is true', () => {
221
- expect(render(<LegacyButton {...props} block />).container).toMatchSnapshot();
222
- });
223
- });
224
-
225
- describe('deprecated types', () => {
226
- it('renders primary as accent buttons and logs a warning', () => {
227
- expect(render(<LegacyButton {...props} type={PRIMARY} />).container).toMatchSnapshot();
228
- expect(mockedWarn).toHaveBeenCalledTimes(1);
229
- });
230
-
231
- it('renders pay as positive buttons and logs a warning', () => {
232
- expect(render(<LegacyButton {...props} type={PAY} />).container).toMatchSnapshot();
233
- expect(mockedWarn).toHaveBeenCalledTimes(1);
234
- });
235
-
236
- it('renders danger as negative buttons with priority secondary and logs a warning', () => {
237
- expect(render(<LegacyButton {...props} type={DANGER} />).container).toMatchSnapshot();
238
- expect(mockedWarn).toHaveBeenCalledTimes(1);
239
- });
240
-
241
- it('renders link as accent buttons with priority tertiary and logs a warning', () => {
242
- expect(render(<LegacyButton {...props} type={LINK} />).container).toMatchSnapshot();
243
- });
244
- });
245
- });
@@ -1,224 +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
- },
33
- argTypes: {
34
- as: {
35
- control: {
36
- type: 'select',
37
- options: ['button', 'a'],
38
- },
39
- },
40
- type: {
41
- type: {
42
- name: 'enum',
43
- value: ['accent', 'positive', 'negative'],
44
- },
45
- },
46
- size: {
47
- type: {
48
- name: 'enum',
49
- value: ['xs', 'sm', 'md', 'lg'],
50
- },
51
- },
52
- priority: {
53
- type: {
54
- name: 'enum',
55
- value: ['primary', 'secondary', 'tertiary'],
56
- },
57
- },
58
- appearance: {
59
- table: {
60
- disable: true,
61
- },
62
- },
63
- iconStart: {
64
- table: {
65
- disable: true,
66
- },
67
- },
68
- iconEnd: {
69
- table: {
70
- disable: true,
71
- },
72
- },
73
- avatars: {
74
- table: {
75
- disable: true,
76
- },
77
- },
78
- 'data-testid': {
79
- table: {
80
- disable: true,
81
- },
82
- },
83
- },
84
- tags: ['autodocs'],
85
- decorators: [withContainer],
86
- };
87
-
88
- export default meta;
89
-
90
- type Story = StoryObj<typeof Button>;
91
-
92
- export const Basic: Story = {};
93
-
94
- export const Secondary: Story = {
95
- args: {
96
- type: 'accent',
97
- priority: 'secondary',
98
- },
99
- };
100
-
101
- export const Tertiary: Story = {
102
- args: {
103
- type: 'accent',
104
- priority: 'tertiary',
105
- },
106
- };
107
-
108
- export const Negative: Story = {
109
- args: {
110
- type: 'negative',
111
- priority: 'primary',
112
- },
113
- };
114
-
115
- export const Loading: Story = {
116
- args: {
117
- loading: true,
118
- },
119
- };
120
-
121
- export const Variants: Story = {
122
- render: () => {
123
- return (
124
- <div className="d-flex flex-column p-b-2 align-items-start">
125
- <div className="d-flex flex-row p-b-2" style={{ gap: 'var(--size-16)' }}>
126
- <Button type="accent" priority="primary">
127
- Primary Accent
128
- </Button>
129
- <Button type="accent" priority="secondary">
130
- Secondary Accent
131
- </Button>
132
- <Button type="accent" priority="tertiary">
133
- Tertiary Accent
134
- </Button>
135
- </div>
136
- <div className="d-flex flex-row p-b-2" style={{ gap: 'var(--size-16)' }}>
137
- <Button type="positive" priority="primary">
138
- Primary Positive
139
- </Button>
140
- <Button type="positive" priority="secondary">
141
- Secondary Accent
142
- </Button>
143
- </div>
144
- <div className="d-flex flex-row flex- p-b-2" style={{ gap: 'var(--size-16)' }}>
145
- <Button type="negative" priority="primary">
146
- Primary Negative
147
- </Button>
148
- <Button type="negative" priority="secondary">
149
- Secondary Negative
150
- </Button>
151
- </div>
152
- <div className="d-flex flex-row p-b-1" style={{ gap: 'var(--size-16)' }}>
153
- <Button type="accent" priority="primary" disabled>
154
- Button Disabled
155
- </Button>
156
- <Button type="accent" priority="secondary" disabled>
157
- Button Disabled
158
- </Button>
159
- <Button type="accent" priority="tertiary" disabled>
160
- Button Disabled
161
- </Button>
162
- </div>
163
- </div>
164
- );
165
- },
166
- };
167
-
168
- const wait = async (duration = 500) =>
169
- new Promise<void>((resolve) => {
170
- setTimeout(resolve, duration);
171
- });
172
-
173
- export const Focused: Story = {
174
- play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
175
- const canvas = within(canvasElement);
176
- const button = canvas.getByRole('button');
177
- await userEvent.tab();
178
- await expect(button).toHaveFocus();
179
- await expect(button).toHaveTextContent('Focused!');
180
- },
181
- render: function Render(args: React.ComponentProps<typeof Button>) {
182
- const [focused, setFocused] = useState(false);
183
-
184
- return (
185
- <Button {...args} onFocus={() => setFocused(true)}>
186
- {focused ? 'Focused!' : 'Button text'}
187
- </Button>
188
- );
189
- },
190
- };
191
-
192
- export const SocialMedia: Story = {
193
- render: () => {
194
- return (
195
- <>
196
- <div className="m-b-2">
197
- <button type="button" className="btn btn-google">
198
- Login with Google
199
- </button>
200
- </div>
201
- <div className="m-b-2">
202
- <button type="button" className="btn btn-facebook">
203
- Login with Facebook
204
- </button>
205
- </div>
206
- <div className="m-b-2">
207
- <button type="button" className="btn btn-lg btn-facebook">
208
- Large Button
209
- </button>
210
- </div>
211
- <div className="m-b-2">
212
- <button type="button" className="btn btn-block btn-facebook">
213
- Block Button
214
- </button>
215
- </div>
216
- <div className="m-b-2">
217
- <button type="button" className="btn btn-lg btn-block btn-facebook">
218
- Large Block Button
219
- </button>
220
- </div>
221
- </>
222
- );
223
- },
224
- };