@transferwise/components 0.0.0-experimental-6f41b35 → 0.0.0-experimental-452dddd

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 (52) hide show
  1. package/build/field/Field.js +1 -0
  2. package/build/field/Field.js.map +1 -1
  3. package/build/field/Field.mjs +1 -0
  4. package/build/field/Field.mjs.map +1 -1
  5. package/build/index.js +2 -0
  6. package/build/index.js.map +1 -1
  7. package/build/index.mjs +1 -0
  8. package/build/index.mjs.map +1 -1
  9. package/build/listItem/Prompt/ListItemPrompt.js +1 -0
  10. package/build/listItem/Prompt/ListItemPrompt.js.map +1 -1
  11. package/build/listItem/Prompt/ListItemPrompt.mjs +1 -0
  12. package/build/listItem/Prompt/ListItemPrompt.mjs.map +1 -1
  13. package/build/main.css +31 -0
  14. package/build/prompt/InfoPrompt/InfoPrompt.js +113 -0
  15. package/build/prompt/InfoPrompt/InfoPrompt.js.map +1 -0
  16. package/build/prompt/InfoPrompt/InfoPrompt.mjs +111 -0
  17. package/build/prompt/InfoPrompt/InfoPrompt.mjs.map +1 -0
  18. package/build/prompt/PrimitivePrompt/PrimitivePrompt.js.map +1 -1
  19. package/build/prompt/PrimitivePrompt/PrimitivePrompt.mjs.map +1 -1
  20. package/build/styles/main.css +31 -0
  21. package/build/styles/prompt/InfoPrompt/InfoPrompt.css +31 -0
  22. package/build/typeahead/Typeahead.js +1 -0
  23. package/build/typeahead/Typeahead.js.map +1 -1
  24. package/build/typeahead/Typeahead.mjs +1 -0
  25. package/build/typeahead/Typeahead.mjs.map +1 -1
  26. package/build/types/index.d.ts +2 -1
  27. package/build/types/index.d.ts.map +1 -1
  28. package/build/types/prompt/InfoPrompt/InfoPrompt.d.ts +56 -0
  29. package/build/types/prompt/InfoPrompt/InfoPrompt.d.ts.map +1 -0
  30. package/build/types/prompt/InfoPrompt/index.d.ts +3 -0
  31. package/build/types/prompt/InfoPrompt/index.d.ts.map +1 -0
  32. package/build/types/prompt/PrimitivePrompt/PrimitivePrompt.d.ts +5 -5
  33. package/build/types/prompt/PrimitivePrompt/PrimitivePrompt.d.ts.map +1 -1
  34. package/build/types/prompt/index.d.ts +2 -0
  35. package/build/types/prompt/index.d.ts.map +1 -1
  36. package/package.json +1 -1
  37. package/src/index.ts +2 -1
  38. package/src/main.css +31 -0
  39. package/src/main.less +2 -1
  40. package/src/prompt/ActionPrompt/ActionPrompt.less +1 -1
  41. package/src/prompt/ActionPrompt/ActionPrompt.test.tsx +2 -7
  42. package/src/prompt/InfoPrompt/InfoPrompt.css +31 -0
  43. package/src/prompt/InfoPrompt/InfoPrompt.less +37 -0
  44. package/src/prompt/InfoPrompt/InfoPrompt.story.tsx +312 -0
  45. package/src/prompt/InfoPrompt/InfoPrompt.test.story.tsx +246 -0
  46. package/src/prompt/InfoPrompt/InfoPrompt.test.tsx +224 -0
  47. package/src/prompt/InfoPrompt/InfoPrompt.tsx +148 -0
  48. package/src/prompt/InfoPrompt/index.ts +2 -0
  49. package/src/prompt/PrimitivePrompt/PrimitivePrompt.less +1 -1
  50. package/src/prompt/PrimitivePrompt/PrimitivePrompt.tsx +5 -5
  51. package/src/prompt/index.ts +5 -0
  52. package/src/ssr.test.tsx +1 -0
@@ -0,0 +1,224 @@
1
+ import { fireEvent, mockMatchMedia, render, screen, userEvent } from '../../test-utils';
2
+ import { InfoPrompt, InfoPromptProps } from './InfoPrompt';
3
+
4
+ mockMatchMedia();
5
+
6
+ const CUSTOM_MEDIA = <span data-testid="custom-media">Custom Media</span>;
7
+
8
+ describe('InfoPrompt', () => {
9
+ const defaultProps: InfoPromptProps = {
10
+ description: 'Prompt description',
11
+ };
12
+
13
+ it('renders description', () => {
14
+ render(<InfoPrompt {...defaultProps} />);
15
+ expect(screen.getByText('Prompt description')).toBeInTheDocument();
16
+ });
17
+
18
+ it('renders title when provided', () => {
19
+ render(<InfoPrompt {...defaultProps} title="Test Title" />);
20
+ expect(screen.getByText('Test Title')).toBeInTheDocument();
21
+ expect(screen.getByText('Prompt description')).toBeInTheDocument();
22
+ });
23
+
24
+ it('renders with GiftBox icon as default for `proposition` sentiment', () => {
25
+ render(<InfoPrompt {...defaultProps} sentiment="proposition" data-testid="info-prompt" />);
26
+ expect(screen.getByText('Prompt description')).toBeInTheDocument();
27
+ // GiftBox icon should be rendered for proposition sentiment
28
+ const prompt = screen.getByTestId('info-prompt');
29
+ expect(prompt.querySelector('svg')).toBeInTheDocument();
30
+ });
31
+
32
+ describe('sentiments', () => {
33
+ [
34
+ { sentiment: 'negative' as const, surfaceClass: 'wds-prompt--negative' },
35
+ { sentiment: 'warning' as const, surfaceClass: 'wds-prompt--warning' },
36
+ { sentiment: 'neutral' as const, surfaceClass: 'wds-prompt--neutral' },
37
+ { sentiment: 'success' as const, surfaceClass: 'wds-prompt--success' },
38
+ { sentiment: 'proposition' as const, surfaceClass: 'wds-prompt--proposition' },
39
+ ].forEach(({ sentiment, surfaceClass }) => {
40
+ describe(sentiment, () => {
41
+ it('should apply correct styles', () => {
42
+ render(<InfoPrompt {...defaultProps} sentiment={sentiment} data-testid="info-prompt" />);
43
+ expect(screen.getByTestId('info-prompt')).toHaveClass(surfaceClass);
44
+ });
45
+ });
46
+ });
47
+ });
48
+
49
+ describe('custom media', () => {
50
+ it('should render custom media when provided', () => {
51
+ render(<InfoPrompt {...defaultProps} media={{ asset: CUSTOM_MEDIA }} />);
52
+ expect(screen.getByTestId('custom-media')).toBeInTheDocument();
53
+ });
54
+
55
+ it('should render custom media for any sentiment', () => {
56
+ render(<InfoPrompt {...defaultProps} sentiment="neutral" media={{ asset: CUSTOM_MEDIA }} />);
57
+ expect(screen.getByTestId('custom-media')).toBeInTheDocument();
58
+ });
59
+ });
60
+
61
+ describe('action', () => {
62
+ it('should render action link when action is provided with href', () => {
63
+ render(
64
+ <InfoPrompt {...defaultProps} action={{ label: 'Learn more', href: '/learn-more' }} />,
65
+ );
66
+ const actionLink = screen.getByRole('link', { name: 'Learn more' });
67
+ expect(actionLink).toBeInTheDocument();
68
+ expect(actionLink).toHaveAttribute('href', '/learn-more');
69
+ });
70
+
71
+ it('should render action link with target when provided', () => {
72
+ render(
73
+ <InfoPrompt
74
+ {...defaultProps}
75
+ action={{ label: 'External link', href: 'https://example.com', target: '_blank' }}
76
+ />,
77
+ );
78
+ const actionLink = screen.getByRole('link', { name: /External link/i });
79
+ expect(actionLink).toHaveAttribute('target', '_blank');
80
+ });
81
+
82
+ it('should call onClick when action button is clicked', async () => {
83
+ const user = userEvent.setup();
84
+ const onClick = jest.fn();
85
+ render(<InfoPrompt {...defaultProps} action={{ label: 'Click me', onClick }} />);
86
+ const actionButton = screen.getByRole('button', { name: 'Click me' });
87
+ await user.click(actionButton);
88
+ expect(onClick).toHaveBeenCalledTimes(1);
89
+ });
90
+
91
+ it('should not render action when not provided', () => {
92
+ render(<InfoPrompt {...defaultProps} />);
93
+ expect(screen.queryByRole('link', { name: 'Learn more' })).not.toBeInTheDocument();
94
+ });
95
+ });
96
+
97
+ describe('HTML attributes', () => {
98
+ it('applies custom className, id, and data-testid', () => {
99
+ render(
100
+ <InfoPrompt
101
+ {...defaultProps}
102
+ className="custom-class"
103
+ id="custom-id"
104
+ data-testid="custom-test"
105
+ />,
106
+ );
107
+ const el = screen.getByTestId('custom-test');
108
+ expect(el).toHaveClass('custom-class');
109
+ expect(el).toHaveAttribute('id', 'custom-id');
110
+ });
111
+ });
112
+
113
+ describe('SentimentSurface integration', () => {
114
+ it('maps success sentiment correctly for SentimentSurface', () => {
115
+ render(<InfoPrompt {...defaultProps} sentiment="success" data-testid="prompt" />);
116
+ const el = screen.getByTestId('prompt');
117
+ expect(el).toHaveClass('wds-prompt--success');
118
+ expect(el).toHaveClass('wds-sentiment-surface');
119
+ });
120
+
121
+ it('passes through other sentiments unchanged', () => {
122
+ render(<InfoPrompt {...defaultProps} sentiment="negative" data-testid="prompt" />);
123
+ const el = screen.getByTestId('prompt');
124
+ expect(el).toHaveClass('wds-prompt--negative');
125
+ expect(el).toHaveClass('wds-sentiment-surface');
126
+ });
127
+ });
128
+
129
+ describe('touch interactions', () => {
130
+ const originalLocation = window.location;
131
+
132
+ beforeAll(() => {
133
+ jest.spyOn(window, 'open').mockImplementation();
134
+ Object.defineProperty(window, 'location', {
135
+ configurable: true,
136
+ value: {
137
+ ...originalLocation,
138
+ assign: jest.fn(),
139
+ },
140
+ });
141
+ });
142
+
143
+ afterEach(() => {
144
+ jest.clearAllMocks();
145
+ });
146
+
147
+ afterAll(() => {
148
+ Object.defineProperty(window, 'location', {
149
+ configurable: true,
150
+ value: originalLocation,
151
+ });
152
+ });
153
+
154
+ it('should navigate to action href on touch tap', () => {
155
+ render(
156
+ <InfoPrompt
157
+ {...defaultProps}
158
+ action={{ label: 'Learn more', href: '/learn-more' }}
159
+ data-testid="prompt"
160
+ />,
161
+ );
162
+ const prompt = screen.getByTestId('prompt');
163
+
164
+ fireEvent.touchStart(prompt);
165
+ expect(window.location.assign).not.toHaveBeenCalled();
166
+ fireEvent.touchEnd(prompt);
167
+ expect(window.location.assign).toHaveBeenCalledWith('/learn-more');
168
+ });
169
+
170
+ it('should open in new tab when action target is _blank', () => {
171
+ render(
172
+ <InfoPrompt
173
+ {...defaultProps}
174
+ action={{ label: 'External link', href: 'https://example.com', target: '_blank' }}
175
+ data-testid="prompt"
176
+ />,
177
+ );
178
+ const prompt = screen.getByTestId('prompt');
179
+
180
+ fireEvent.touchStart(prompt);
181
+ expect(window.open).not.toHaveBeenCalled();
182
+ fireEvent.touchEnd(prompt);
183
+ expect(window.open).toHaveBeenCalledWith(
184
+ 'https://example.com',
185
+ '_blank',
186
+ 'noopener, noreferrer',
187
+ );
188
+ });
189
+
190
+ it('should not navigate if touch move occurs (scrolling)', () => {
191
+ render(
192
+ <InfoPrompt
193
+ {...defaultProps}
194
+ action={{ label: 'Learn more', href: '/learn-more' }}
195
+ data-testid="prompt"
196
+ />,
197
+ );
198
+ const prompt = screen.getByTestId('prompt');
199
+
200
+ fireEvent.touchStart(prompt);
201
+ expect(window.location.assign).not.toHaveBeenCalled();
202
+ fireEvent.touchMove(prompt);
203
+ expect(window.location.assign).not.toHaveBeenCalled();
204
+ fireEvent.touchEnd(prompt);
205
+ expect(window.location.assign).not.toHaveBeenCalled();
206
+ });
207
+
208
+ it('should not navigate if no action href is provided', () => {
209
+ render(
210
+ <InfoPrompt
211
+ {...defaultProps}
212
+ action={{ label: 'Click me', onClick: jest.fn() }}
213
+ data-testid="prompt"
214
+ />,
215
+ );
216
+ const prompt = screen.getByTestId('prompt');
217
+
218
+ fireEvent.touchStart(prompt);
219
+ fireEvent.touchEnd(prompt);
220
+ expect(window.location.assign).not.toHaveBeenCalled();
221
+ expect(window.open).not.toHaveBeenCalled();
222
+ });
223
+ });
224
+ });
@@ -0,0 +1,148 @@
1
+ import { HTMLAttributes, ReactNode, useState } from 'react';
2
+ import { Sentiment, Typography } from '../../common';
3
+ import { GiftBox } from '@transferwise/icons';
4
+ import type { Sentiment as SurfaceSentiment } from '../../sentimentSurface';
5
+ import StatusIcon from '../../statusIcon';
6
+ import { clsx } from 'clsx';
7
+ import Body from '../../body';
8
+ import Link, { LinkProps } from '../../link';
9
+ import { PrimitivePrompt, PrimitivePromptProps } from '../PrimitivePrompt';
10
+
11
+ export type InfoPromptAction = Pick<LinkProps, 'href' | 'target' | 'onClick'> & {
12
+ /**
13
+ * The label text for the action link
14
+ */
15
+ label: string;
16
+ };
17
+
18
+ export type InfoPromptMedia = {
19
+ /**
20
+ * The icon/image asset to display.
21
+ * The asset should include its own accessibility attributes (e.g. title, aria-label)
22
+ * if it conveys meaning, or aria-hidden="true" if decorative.
23
+ */
24
+ asset: ReactNode;
25
+ };
26
+
27
+ export type InfoPromptProps = Omit<HTMLAttributes<HTMLDivElement>, 'title'> &
28
+ Pick<PrimitivePromptProps, 'data-testid'> & {
29
+ /**
30
+ * The sentiment determines the colour scheme
31
+ * @default 'neutral'
32
+ */
33
+ sentiment?: SurfaceSentiment;
34
+ /**
35
+ * Handler called when the close button is clicked.
36
+ * If not provided, the close button is hidden.
37
+ */
38
+ onDismiss?: () => void;
39
+ /**
40
+ * Custom media to override the default status icon.
41
+ * Success and proposition sentiments support 2 status variations: standard checkmark & confetti.
42
+ */
43
+ media?: InfoPromptMedia;
44
+ /**
45
+ * Action link to be displayed below the description
46
+ */
47
+ action?: InfoPromptAction;
48
+ /**
49
+ * Title content for the prompt
50
+ */
51
+ title?: string;
52
+ /**
53
+ * Description text for the prompt (required)
54
+ */
55
+ description: string;
56
+ };
57
+
58
+ /**
59
+ * InfoPrompt displays important contextual messages to users within a screen.
60
+ * It provides a visually distinct way to communicate information, warnings, errors,
61
+ * or positive feedback with optional actions and dismissal capabilities.
62
+ *
63
+ * Use this component to replace the deprecated Alert component.
64
+ */
65
+ export const InfoPrompt = ({
66
+ sentiment = 'neutral',
67
+ onDismiss,
68
+ media,
69
+ action,
70
+ title,
71
+ description,
72
+ className,
73
+ 'data-testid': dataTestId,
74
+ ...restProps
75
+ }: InfoPromptProps) => {
76
+ const [shouldFire, setShouldFire] = useState<boolean>();
77
+ const statusIconSentiment =
78
+ sentiment === 'success'
79
+ ? Sentiment.POSITIVE
80
+ : (sentiment as Exclude<SurfaceSentiment, 'proposition'>);
81
+
82
+ const handleTouchStart = () => {
83
+ setShouldFire(true);
84
+ };
85
+
86
+ const handleTouchEnd = () => {
87
+ if (shouldFire && action?.href) {
88
+ if (action.target === '_blank') {
89
+ window.top?.open(action.href, '_blank', 'noopener, noreferrer');
90
+ } else {
91
+ window.top?.location.assign(action.href);
92
+ }
93
+ }
94
+ setShouldFire(false);
95
+ };
96
+
97
+ const handleTouchMove = () => {
98
+ setShouldFire(false);
99
+ };
100
+
101
+ const renderMedia = () => {
102
+ if (media) {
103
+ return <span className="wds-info-prompt__media">{media.asset}</span>;
104
+ }
105
+
106
+ if (sentiment === 'proposition') {
107
+ return <GiftBox size={24} />;
108
+ }
109
+
110
+ return <StatusIcon size={24} sentiment={statusIconSentiment} />;
111
+ };
112
+
113
+ return (
114
+ <PrimitivePrompt
115
+ sentiment={sentiment}
116
+ media={renderMedia()}
117
+ data-testid={dataTestId}
118
+ className={clsx('wds-info-prompt', className)}
119
+ {...restProps}
120
+ onTouchStart={handleTouchStart}
121
+ onTouchEnd={handleTouchEnd}
122
+ onTouchMove={handleTouchMove}
123
+ onDismiss={onDismiss}
124
+ >
125
+ <div className="wds-info-prompt__content">
126
+ {title && (
127
+ <Body className="wds-info-prompt__title" type={Typography.BODY_LARGE_BOLD} as="span">
128
+ {title}
129
+ </Body>
130
+ )}
131
+ <Body as="span" className="wds-info-prompt__description">
132
+ {description}
133
+ </Body>
134
+ {action && (
135
+ <Link
136
+ href={action.href}
137
+ target={action.target}
138
+ type={Typography.LINK_DEFAULT}
139
+ className="wds-info-prompt__action"
140
+ onClick={action.onClick}
141
+ >
142
+ {action.label}
143
+ </Link>
144
+ )}
145
+ </div>
146
+ </PrimitivePrompt>
147
+ );
148
+ };
@@ -0,0 +1,2 @@
1
+ export type { InfoPromptProps, InfoPromptAction, InfoPromptMedia } from './InfoPrompt';
2
+ export { InfoPrompt } from './InfoPrompt';
@@ -44,4 +44,4 @@
44
44
  }
45
45
  }
46
46
  }
47
- }
47
+ }
@@ -4,9 +4,9 @@ import SentimentSurface, { Sentiment } from '../../sentimentSurface';
4
4
  import IconButton from '../../iconButton';
5
5
  import { useIntl } from 'react-intl';
6
6
  import closeBtnMessages from '../../common/closeButton/CloseButton.messages';
7
- import { ReactNode } from 'react';
7
+ import { HTMLAttributes, ReactNode } from 'react';
8
8
 
9
- export type PrimitivePromptProps = {
9
+ export type PrimitivePromptProps = HTMLAttributes<HTMLDivElement> & {
10
10
  /**
11
11
  * The sentiment determines the colour scheme
12
12
  * @default success
@@ -24,10 +24,10 @@ export type PrimitivePromptProps = {
24
24
  * Handler called when the close button is clicked. If not provided, then the close button is hidden.
25
25
  */
26
26
  onDismiss?: () => void;
27
- id?: string;
28
- className?: string;
27
+ /**
28
+ * Test ID for testing tools
29
+ */
29
30
  'data-testid'?: string;
30
- children: ReactNode;
31
31
  };
32
32
 
33
33
  /**
@@ -5,5 +5,10 @@
5
5
  export type { InlinePromptProps } from './InlinePrompt';
6
6
  export { InlinePrompt } from './InlinePrompt';
7
7
 
8
+ // ActionPrompt
8
9
  export type { ActionPromptProps } from './ActionPrompt';
9
10
  export { ActionPrompt } from './ActionPrompt';
11
+
12
+ // InfoPrompt
13
+ export type { InfoPromptProps, InfoPromptAction, InfoPromptMedia } from './InfoPrompt';
14
+ export { InfoPrompt } from './InfoPrompt';
package/src/ssr.test.tsx CHANGED
@@ -91,6 +91,7 @@ describe('Server side rendering', () => {
91
91
 
92
92
  // stick all possible properties we might need to render all components in here
93
93
  const allProps: Record<string, unknown> = {
94
+ actionPrimary: { label: 'Action', onClick: jest.fn(), href: '#' },
94
95
  currencies: [],
95
96
  currencySelector: { options: [] },
96
97
  steps: [],