@transferwise/components 46.33.0 → 46.34.0
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/index.js +25 -8
- package/build/index.js.map +1 -1
- package/build/index.mjs +25 -8
- package/build/index.mjs.map +1 -1
- package/build/types/alert/Alert.d.ts +3 -2
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/alert/Alert.spec.tsx +12 -0
- package/src/alert/Alert.story.tsx +11 -1
- package/src/alert/Alert.tsx +33 -14
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import { Sentiment, Size, Variant } from '../common';
|
|
3
3
|
export type AlertAction = {
|
|
4
4
|
'aria-label'?: string;
|
|
5
|
-
href
|
|
5
|
+
href?: string;
|
|
6
6
|
target?: string;
|
|
7
7
|
text: React.ReactNode;
|
|
8
|
+
onClick?: () => void;
|
|
8
9
|
};
|
|
9
10
|
/** @deprecated Use `"top" | "bottom"` instead. */
|
|
10
11
|
type AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;
|
|
@@ -26,7 +27,7 @@ export interface AlertProps {
|
|
|
26
27
|
icon?: React.ReactElement;
|
|
27
28
|
/** Title for the alert component */
|
|
28
29
|
title?: string;
|
|
29
|
-
/** The main body of the alert. Accepts plain text and bold words specified with **double stars*/
|
|
30
|
+
/** The main body of the alert. Accepts plain text and bold words specified with **double stars */
|
|
30
31
|
message?: string;
|
|
31
32
|
/** The presence of the onDismiss handler will trigger the visibility of the close button */
|
|
32
33
|
onDismiss?: React.MouseEventHandler<HTMLButtonElement>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.d.ts","sourceRoot":"","sources":["../../../src/alert/Alert.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAc,OAAO,EAAE,MAAM,WAAW,CAAC;AASjE,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,CAA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BAAiB,CAAC,iBAAiB,CAAC,CAAC;IACvD,2DAA2D;IAC3D,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;IACvB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,GAAG,kBAAkB,EAAE,CAAC;IAChC,oHAAoH;IACpH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2FAA2F;IAC3F,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC;CAClB;AAeD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAC5B,KAAK,EACL,MAAM,EACN,QAAQ,EACR,SAAS,EACT,WAAW,EACX,IAAI,EACJ,SAAS,EACT,OAAO,EACP,IAAI,EACJ,KAAK,EACL,IAAgB,EAChB,OAAmB,GACpB,EAAE,UAAU,+BAqGZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.34.0",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -97,8 +97,8 @@
|
|
|
97
97
|
"rollup": "^4.17.2",
|
|
98
98
|
"storybook": "^7.6.19",
|
|
99
99
|
"@transferwise/less-config": "3.1.0",
|
|
100
|
-
"@
|
|
101
|
-
"@
|
|
100
|
+
"@wise/components-theming": "1.2.2",
|
|
101
|
+
"@transferwise/neptune-css": "14.10.0"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"@transferwise/icons": "^3.7.0",
|
package/src/alert/Alert.spec.tsx
CHANGED
|
@@ -175,6 +175,18 @@ describe('Alert', () => {
|
|
|
175
175
|
expect(element).not.toHaveAttribute('target');
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
+
it('sets text and onClick', () => {
|
|
179
|
+
action = {
|
|
180
|
+
onClick: jest.fn(),
|
|
181
|
+
text: 'Learn more',
|
|
182
|
+
};
|
|
183
|
+
render(<Alert action={action} message={message} />);
|
|
184
|
+
|
|
185
|
+
userEvent.click(screen.getByText('Learn more'));
|
|
186
|
+
|
|
187
|
+
expect(action.onClick).toHaveBeenCalled();
|
|
188
|
+
});
|
|
189
|
+
|
|
178
190
|
it('adds additional attributes', () => {
|
|
179
191
|
action = {
|
|
180
192
|
'aria-label': 'Learn more about fluffy kittens',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-alert */
|
|
2
2
|
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { action } from '@storybook/addon-actions';
|
|
3
4
|
import { ClockBorderless } from '@transferwise/icons';
|
|
4
5
|
|
|
5
6
|
import { Sentiment } from '../common';
|
|
@@ -46,7 +47,7 @@ export const Basic: Story = {
|
|
|
46
47
|
},
|
|
47
48
|
};
|
|
48
49
|
|
|
49
|
-
export const
|
|
50
|
+
export const WithLinkAction: Story = {
|
|
50
51
|
args: {
|
|
51
52
|
action: {
|
|
52
53
|
href: '/',
|
|
@@ -55,6 +56,15 @@ export const WithAction: Story = {
|
|
|
55
56
|
},
|
|
56
57
|
};
|
|
57
58
|
|
|
59
|
+
export const WithButtonAction: Story = {
|
|
60
|
+
args: {
|
|
61
|
+
action: {
|
|
62
|
+
onClick: action('alert action clicked'),
|
|
63
|
+
text: 'Open',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
58
68
|
export const WithArrow: Story = {
|
|
59
69
|
args: {
|
|
60
70
|
arrow: AlertArrowPosition.TOP_LEFT,
|
package/src/alert/Alert.tsx
CHANGED
|
@@ -13,9 +13,10 @@ import InlineMarkdown from './inlineMarkdown';
|
|
|
13
13
|
|
|
14
14
|
export type AlertAction = {
|
|
15
15
|
'aria-label'?: string;
|
|
16
|
-
href
|
|
16
|
+
href?: string;
|
|
17
17
|
target?: string;
|
|
18
18
|
text: React.ReactNode;
|
|
19
|
+
onClick?: () => void;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
/** @deprecated Use `"top" | "bottom"` instead. */
|
|
@@ -44,7 +45,7 @@ export interface AlertProps {
|
|
|
44
45
|
icon?: React.ReactElement;
|
|
45
46
|
/** Title for the alert component */
|
|
46
47
|
title?: string;
|
|
47
|
-
/** The main body of the alert. Accepts plain text and bold words specified with **double stars*/
|
|
48
|
+
/** The main body of the alert. Accepts plain text and bold words specified with **double stars */
|
|
48
49
|
message?: string;
|
|
49
50
|
/** The presence of the onDismiss handler will trigger the visibility of the close button */
|
|
50
51
|
onDismiss?: React.MouseEventHandler<HTMLButtonElement>;
|
|
@@ -144,7 +145,7 @@ export default function Alert({
|
|
|
144
145
|
onTouchEnd={(event) => {
|
|
145
146
|
if (
|
|
146
147
|
shouldFire &&
|
|
147
|
-
action &&
|
|
148
|
+
action?.href &&
|
|
148
149
|
// Check if current event is triggered from closeButton
|
|
149
150
|
event.target instanceof Node &&
|
|
150
151
|
closeButtonReference.current &&
|
|
@@ -180,17 +181,7 @@ export default function Alert({
|
|
|
180
181
|
{children || <InlineMarkdown>{message}</InlineMarkdown>}
|
|
181
182
|
</Body>
|
|
182
183
|
</div>
|
|
183
|
-
{action &&
|
|
184
|
-
<Link
|
|
185
|
-
href={action.href}
|
|
186
|
-
className="m-t-1"
|
|
187
|
-
aria-label={action['aria-label']}
|
|
188
|
-
target={action.target}
|
|
189
|
-
type={Typography.LINK_LARGE}
|
|
190
|
-
>
|
|
191
|
-
{action.text}
|
|
192
|
-
</Link>
|
|
193
|
-
)}
|
|
184
|
+
{action && <Action action={action} />}
|
|
194
185
|
</div>
|
|
195
186
|
</div>
|
|
196
187
|
{onDismiss && (
|
|
@@ -217,3 +208,31 @@ function alertArrowClassNames(arrow: `${AlertArrowPosition}`) {
|
|
|
217
208
|
return 'arrow';
|
|
218
209
|
}
|
|
219
210
|
}
|
|
211
|
+
|
|
212
|
+
function Action({ action }: { action: AlertAction }) {
|
|
213
|
+
if ('href' in action) {
|
|
214
|
+
return (
|
|
215
|
+
<Link
|
|
216
|
+
href={action.href}
|
|
217
|
+
className="m-t-1"
|
|
218
|
+
aria-label={action['aria-label']}
|
|
219
|
+
target={action.target}
|
|
220
|
+
type={Typography.LINK_LARGE}
|
|
221
|
+
onClick={action.onClick}
|
|
222
|
+
>
|
|
223
|
+
{action.text}
|
|
224
|
+
</Link>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<button
|
|
230
|
+
type="button"
|
|
231
|
+
aria-label={action['aria-label']}
|
|
232
|
+
className="btn-unstyled np-text-link-large m-t-1"
|
|
233
|
+
onClick={action.onClick}
|
|
234
|
+
>
|
|
235
|
+
{action.text}
|
|
236
|
+
</button>
|
|
237
|
+
);
|
|
238
|
+
}
|