@transferwise/components 0.0.0-experimental-9a6de5f → 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.
Files changed (43) hide show
  1. package/build/i18n/ja.json +13 -13
  2. package/build/index.js +304 -147
  3. package/build/index.js.map +1 -1
  4. package/build/index.mjs +306 -149
  5. package/build/index.mjs.map +1 -1
  6. package/build/types/alert/Alert.d.ts +58 -47
  7. package/build/types/alert/Alert.d.ts.map +1 -1
  8. package/build/types/alert/index.d.ts +1 -2
  9. package/build/types/alert/index.d.ts.map +1 -1
  10. package/build/types/alert/withArrow/alertArrowPositions.d.ts +9 -0
  11. package/build/types/alert/withArrow/alertArrowPositions.d.ts.map +1 -0
  12. package/build/types/alert/withArrow/index.d.ts +3 -0
  13. package/build/types/alert/withArrow/index.d.ts.map +1 -0
  14. package/build/types/alert/withArrow/withArrow.d.ts +11 -0
  15. package/build/types/alert/withArrow/withArrow.d.ts.map +1 -0
  16. package/build/types/common/propsValues/sentiment.d.ts +1 -0
  17. package/build/types/common/propsValues/sentiment.d.ts.map +1 -1
  18. package/build/types/index.d.ts +1 -1
  19. package/build/types/index.d.ts.map +1 -1
  20. package/build/types/inlineAlert/InlineAlert.d.ts +4 -2
  21. package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
  22. package/build/types/provider/Provider.d.ts +1 -1
  23. package/build/types/provider/Provider.d.ts.map +1 -1
  24. package/build/types/statusIcon/StatusIcon.d.ts +1 -1
  25. package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
  26. package/package.json +1 -1
  27. package/src/alert/Alert.js +196 -0
  28. package/src/alert/{Alert.spec.tsx → Alert.spec.js} +40 -43
  29. package/src/alert/Alert.story.tsx +2 -1
  30. package/src/alert/index.js +1 -0
  31. package/src/alert/withArrow/alertArrowPositions.ts +9 -0
  32. package/src/alert/withArrow/index.js +2 -0
  33. package/src/alert/withArrow/withArrow.js +50 -0
  34. package/src/alert/withArrow/withArrow.spec.js +51 -0
  35. package/src/common/propsValues/sentiment.ts +10 -0
  36. package/src/i18n/ja.json +13 -13
  37. package/src/index.ts +1 -1
  38. package/src/inlineAlert/InlineAlert.spec.tsx +7 -0
  39. package/src/inlineAlert/InlineAlert.tsx +47 -19
  40. package/src/provider/Provider.tsx +2 -1
  41. package/src/statusIcon/StatusIcon.tsx +14 -14
  42. package/src/alert/Alert.tsx +0 -222
  43. package/src/alert/index.ts +0 -2
@@ -1,222 +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
- closeButtonReference.current &&
149
- !closeButtonReference.current.contains(event.currentTarget)
150
- ) {
151
- if (action.target === '_blank') {
152
- window.top?.open(action.href);
153
- } else {
154
- window.top?.location.assign(action.href);
155
- }
156
- }
157
- setShouldFire(false);
158
- }}
159
- onTouchMove={() => setShouldFire(false)}
160
- >
161
- <div
162
- className={classNames('alert__content', 'd-flex', 'flex-grow-1', variant)}
163
- data-testid={variant}
164
- >
165
- {icon ? (
166
- <div className="alert__icon">{icon}</div>
167
- ) : (
168
- <StatusIcon size={Size.LARGE} sentiment={resolvedType} />
169
- )}
170
- <div className="alert__message">
171
- <div role={Sentiment.NEGATIVE === resolvedType ? 'alert' : 'status'}>
172
- {title && (
173
- <Title className="m-b-1" type={Typography.TITLE_BODY}>
174
- {title}
175
- </Title>
176
- )}
177
- <Body as="span" className="d-block" type={Typography.BODY_LARGE}>
178
- {children || <InlineMarkdown>{message}</InlineMarkdown>}
179
- </Body>
180
- </div>
181
- {action && (
182
- <Link
183
- href={action.href}
184
- className="m-t-1"
185
- aria-label={action['aria-label']}
186
- target={action.target}
187
- type={Typography.LINK_LARGE}
188
- >
189
- {action.text}
190
- </Link>
191
- )}
192
- </div>
193
- </div>
194
- {onDismiss && (
195
- <CloseButton ref={closeButtonReference} className="m-l-2" onClick={onDismiss} />
196
- )}
197
- </div>
198
- );
199
- }
200
-
201
- function alertArrowClassNames(arrow: `${AlertArrowPosition}`) {
202
- if (arrow) {
203
- const classes = 'arrow';
204
-
205
- switch (arrow) {
206
- case 'down-center':
207
- return `${classes} arrow-bottom arrow-center`;
208
- case 'down-left':
209
- return `${classes} arrow-bottom arrow-left`;
210
- case 'down-right':
211
- return `${classes} arrow-bottom arrow-right`;
212
- case 'up-center':
213
- return `${classes} arrow-center`;
214
- case 'up-right':
215
- return `${classes} arrow-right`;
216
- case 'up-left':
217
- default:
218
- return classes;
219
- }
220
- }
221
- return '';
222
- }
@@ -1,2 +0,0 @@
1
- export { default } from './Alert';
2
- export type { AlertProps, AlertAction, AlertArrowPosition, AlertType } from './Alert';