@transferwise/components 0.0.0-experimental-5a0aa47 → 0.0.0-experimental-0b80b83
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/i18n/ja.json +13 -13
- package/build/index.js +304 -147
- package/build/index.js.map +1 -1
- package/build/index.mjs +306 -149
- package/build/index.mjs.map +1 -1
- package/build/types/alert/Alert.d.ts +58 -47
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/build/types/alert/index.d.ts +1 -2
- package/build/types/alert/index.d.ts.map +1 -1
- package/build/types/alert/withArrow/alertArrowPositions.d.ts +9 -0
- package/build/types/alert/withArrow/alertArrowPositions.d.ts.map +1 -0
- package/build/types/alert/withArrow/index.d.ts +3 -0
- package/build/types/alert/withArrow/index.d.ts.map +1 -0
- package/build/types/alert/withArrow/withArrow.d.ts +11 -0
- package/build/types/alert/withArrow/withArrow.d.ts.map +1 -0
- package/build/types/common/propsValues/sentiment.d.ts +1 -0
- package/build/types/common/propsValues/sentiment.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inlineAlert/InlineAlert.d.ts +4 -2
- package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
- package/build/types/provider/Provider.d.ts +1 -1
- package/build/types/provider/Provider.d.ts.map +1 -1
- package/build/types/statusIcon/StatusIcon.d.ts +1 -1
- package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/alert/Alert.js +196 -0
- package/src/alert/{Alert.spec.tsx → Alert.spec.js} +40 -43
- package/src/alert/Alert.story.tsx +2 -1
- package/src/alert/index.js +1 -0
- package/src/alert/withArrow/alertArrowPositions.ts +9 -0
- package/src/alert/withArrow/index.js +2 -0
- package/src/alert/withArrow/withArrow.js +50 -0
- package/src/alert/withArrow/withArrow.spec.js +51 -0
- package/src/common/propsValues/sentiment.ts +10 -0
- package/src/i18n/ja.json +13 -13
- package/src/index.ts +1 -1
- package/src/inlineAlert/InlineAlert.spec.tsx +7 -0
- package/src/inlineAlert/InlineAlert.tsx +47 -19
- package/src/provider/Provider.tsx +2 -1
- package/src/statusIcon/StatusIcon.tsx +14 -14
- package/src/alert/Alert.tsx +0 -223
- package/src/alert/index.ts +0 -2
package/src/alert/Alert.tsx
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import { useState, useRef, useEffect } from 'react';
|
|
3
|
-
|
|
4
|
-
import Body from '../body/Body';
|
|
5
|
-
import { Sentiment, Size, Typography, Variant } from '../common';
|
|
6
|
-
import { CloseButton } from '../common/closeButton';
|
|
7
|
-
import Link from '../link';
|
|
8
|
-
import StatusIcon from '../statusIcon';
|
|
9
|
-
import Title from '../title/Title';
|
|
10
|
-
import { logActionRequired } from '../utilities';
|
|
11
|
-
|
|
12
|
-
import InlineMarkdown from './inlineMarkdown';
|
|
13
|
-
|
|
14
|
-
export type AlertAction = {
|
|
15
|
-
'aria-label'?: string;
|
|
16
|
-
href: string;
|
|
17
|
-
target?: string;
|
|
18
|
-
text: React.ReactNode;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/** @deprecated Use `"top" | "bottom"` instead. */
|
|
22
|
-
type AlertTypeDeprecated = `${Sentiment.SUCCESS | Sentiment.INFO | Sentiment.ERROR}`;
|
|
23
|
-
type AlertTypeResolved = `${
|
|
24
|
-
| Sentiment.POSITIVE
|
|
25
|
-
| Sentiment.NEUTRAL
|
|
26
|
-
| Sentiment.WARNING
|
|
27
|
-
| Sentiment.NEGATIVE}`;
|
|
28
|
-
export type AlertType = AlertTypeResolved | AlertTypeDeprecated;
|
|
29
|
-
|
|
30
|
-
export enum AlertArrowPosition {
|
|
31
|
-
TOP_LEFT = 'up-left',
|
|
32
|
-
TOP = 'up-center',
|
|
33
|
-
TOP_RIGHT = 'up-right',
|
|
34
|
-
BOTTOM_LEFT = 'down-left',
|
|
35
|
-
BOTTOM = 'down-center',
|
|
36
|
-
BOTTOM_RIGHT = 'down-right',
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface AlertProps {
|
|
40
|
-
/** An optional call to action to sit under the main body of the alert. If your label is short, use aria-label to provide more context */
|
|
41
|
-
action?: AlertAction;
|
|
42
|
-
className?: string;
|
|
43
|
-
/** An optional icon. If not provided, we will default the icon to something appropriate for the type */
|
|
44
|
-
icon?: React.ReactElement;
|
|
45
|
-
/** Title for the alert component */
|
|
46
|
-
title?: string;
|
|
47
|
-
/** The main body of the alert. Accepts plain text and bold words specified with **double stars*/
|
|
48
|
-
message?: string;
|
|
49
|
-
/** The presence of the onDismiss handler will trigger the visibility of the close button */
|
|
50
|
-
onDismiss?: React.MouseEventHandler<HTMLButtonElement>;
|
|
51
|
-
/** The type dictates which icon and colour will be used */
|
|
52
|
-
type?: AlertType;
|
|
53
|
-
variant?: `${Variant}`;
|
|
54
|
-
/** @deprecated Use `InlineAlert` instead. */
|
|
55
|
-
arrow?: `${AlertArrowPosition}`;
|
|
56
|
-
/** @deprecated Use `message` instead. Be aware `message` only accepts plain text or text with **bold** markdown. */
|
|
57
|
-
children?: React.ReactNode;
|
|
58
|
-
/** @deprecated Use `onDismiss` instead. */
|
|
59
|
-
dismissible?: boolean;
|
|
60
|
-
/** @deprecated Alert component doesn't support `size` anymore, please remove this prop. */
|
|
61
|
-
size?: `${Size}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function resolveType(type: AlertType): AlertTypeResolved {
|
|
65
|
-
switch (type) {
|
|
66
|
-
case 'success':
|
|
67
|
-
return 'positive';
|
|
68
|
-
case 'info':
|
|
69
|
-
return 'neutral';
|
|
70
|
-
case 'error':
|
|
71
|
-
return 'negative';
|
|
72
|
-
}
|
|
73
|
-
return type;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export default function Alert({
|
|
77
|
-
arrow,
|
|
78
|
-
action,
|
|
79
|
-
children,
|
|
80
|
-
className,
|
|
81
|
-
dismissible,
|
|
82
|
-
icon,
|
|
83
|
-
onDismiss,
|
|
84
|
-
message,
|
|
85
|
-
size,
|
|
86
|
-
title,
|
|
87
|
-
type = 'neutral',
|
|
88
|
-
variant = 'desktop',
|
|
89
|
-
}: AlertProps) {
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (arrow !== undefined) {
|
|
92
|
-
logActionRequired(
|
|
93
|
-
"Alert component doesn't support 'arrow' anymore, use 'InlineAlert' instead.",
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}, [arrow]);
|
|
97
|
-
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
if (children !== undefined) {
|
|
100
|
-
logActionRequired(
|
|
101
|
-
"Alert component doesn't support 'children' anymore, use 'message' instead.",
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}, [children]);
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
if (dismissible !== undefined) {
|
|
108
|
-
logActionRequired(
|
|
109
|
-
"Alert component doesn't support 'dismissible' anymore, use 'onDismiss' instead.",
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}, [dismissible]);
|
|
113
|
-
|
|
114
|
-
useEffect(() => {
|
|
115
|
-
if (size !== undefined) {
|
|
116
|
-
logActionRequired("Alert component doesn't support 'size' anymore, please remove that prop.");
|
|
117
|
-
}
|
|
118
|
-
}, [size]);
|
|
119
|
-
|
|
120
|
-
const resolvedType = resolveType(type);
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (resolvedType !== type) {
|
|
123
|
-
logActionRequired(
|
|
124
|
-
`Alert component has deprecated '${type}' value for the 'type' prop. Please use '${resolvedType}' instead.`,
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}, [resolvedType, type]);
|
|
128
|
-
|
|
129
|
-
const [shouldFire, setShouldFire] = useState(false);
|
|
130
|
-
|
|
131
|
-
const closeButtonReference = useRef<HTMLButtonElement>(null);
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div
|
|
135
|
-
className={classNames(
|
|
136
|
-
'alert d-flex',
|
|
137
|
-
`alert-${resolvedType}`,
|
|
138
|
-
arrow != null && alertArrowClassNames(arrow),
|
|
139
|
-
className,
|
|
140
|
-
)}
|
|
141
|
-
data-testid="alert"
|
|
142
|
-
onTouchStart={() => setShouldFire(true)}
|
|
143
|
-
onTouchEnd={(event) => {
|
|
144
|
-
if (
|
|
145
|
-
shouldFire &&
|
|
146
|
-
action &&
|
|
147
|
-
// Check if current event is triggered from closeButton
|
|
148
|
-
event.target instanceof Node &&
|
|
149
|
-
closeButtonReference.current &&
|
|
150
|
-
!closeButtonReference.current.contains(event.target)
|
|
151
|
-
) {
|
|
152
|
-
if (action.target === '_blank') {
|
|
153
|
-
window.top?.open(action.href);
|
|
154
|
-
} else {
|
|
155
|
-
window.top?.location.assign(action.href);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
setShouldFire(false);
|
|
159
|
-
}}
|
|
160
|
-
onTouchMove={() => setShouldFire(false)}
|
|
161
|
-
>
|
|
162
|
-
<div
|
|
163
|
-
className={classNames('alert__content', 'd-flex', 'flex-grow-1', variant)}
|
|
164
|
-
data-testid={variant}
|
|
165
|
-
>
|
|
166
|
-
{icon ? (
|
|
167
|
-
<div className="alert__icon">{icon}</div>
|
|
168
|
-
) : (
|
|
169
|
-
<StatusIcon size={Size.LARGE} sentiment={resolvedType} />
|
|
170
|
-
)}
|
|
171
|
-
<div className="alert__message">
|
|
172
|
-
<div role={Sentiment.NEGATIVE === resolvedType ? 'alert' : 'status'}>
|
|
173
|
-
{title && (
|
|
174
|
-
<Title className="m-b-1" type={Typography.TITLE_BODY}>
|
|
175
|
-
{title}
|
|
176
|
-
</Title>
|
|
177
|
-
)}
|
|
178
|
-
<Body as="span" className="d-block" type={Typography.BODY_LARGE}>
|
|
179
|
-
{children || <InlineMarkdown>{message}</InlineMarkdown>}
|
|
180
|
-
</Body>
|
|
181
|
-
</div>
|
|
182
|
-
{action && (
|
|
183
|
-
<Link
|
|
184
|
-
href={action.href}
|
|
185
|
-
className="m-t-1"
|
|
186
|
-
aria-label={action['aria-label']}
|
|
187
|
-
target={action.target}
|
|
188
|
-
type={Typography.LINK_LARGE}
|
|
189
|
-
>
|
|
190
|
-
{action.text}
|
|
191
|
-
</Link>
|
|
192
|
-
)}
|
|
193
|
-
</div>
|
|
194
|
-
</div>
|
|
195
|
-
{onDismiss && (
|
|
196
|
-
<CloseButton ref={closeButtonReference} className="m-l-2" onClick={onDismiss} />
|
|
197
|
-
)}
|
|
198
|
-
</div>
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function alertArrowClassNames(arrow: `${AlertArrowPosition}`) {
|
|
203
|
-
if (arrow) {
|
|
204
|
-
const classes = 'arrow';
|
|
205
|
-
|
|
206
|
-
switch (arrow) {
|
|
207
|
-
case 'down-center':
|
|
208
|
-
return `${classes} arrow-bottom arrow-center`;
|
|
209
|
-
case 'down-left':
|
|
210
|
-
return `${classes} arrow-bottom arrow-left`;
|
|
211
|
-
case 'down-right':
|
|
212
|
-
return `${classes} arrow-bottom arrow-right`;
|
|
213
|
-
case 'up-center':
|
|
214
|
-
return `${classes} arrow-center`;
|
|
215
|
-
case 'up-right':
|
|
216
|
-
return `${classes} arrow-right`;
|
|
217
|
-
case 'up-left':
|
|
218
|
-
default:
|
|
219
|
-
return classes;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return '';
|
|
223
|
-
}
|
package/src/alert/index.ts
DELETED