@transferwise/components 0.0.0-experimental-d73d39f → 0.0.0-experimental-807a5a3

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 (116) hide show
  1. package/build/common/hooks/useContainerSize.js +30 -0
  2. package/build/common/hooks/useContainerSize.js.map +1 -0
  3. package/build/common/hooks/useContainerSize.mjs +28 -0
  4. package/build/common/hooks/useContainerSize.mjs.map +1 -0
  5. package/build/common/hooks/useResizeObserver.js +3 -3
  6. package/build/common/hooks/useResizeObserver.js.map +1 -1
  7. package/build/common/hooks/useResizeObserver.mjs +3 -3
  8. package/build/common/hooks/useResizeObserver.mjs.map +1 -1
  9. package/build/field/Field.js +3 -2
  10. package/build/field/Field.js.map +1 -1
  11. package/build/field/Field.mjs +3 -2
  12. package/build/field/Field.mjs.map +1 -1
  13. package/build/i18n/en.json +2 -0
  14. package/build/i18n/en.json.js +2 -0
  15. package/build/i18n/en.json.js.map +1 -1
  16. package/build/i18n/en.json.mjs +2 -0
  17. package/build/i18n/en.json.mjs.map +1 -1
  18. package/build/index.js +2 -0
  19. package/build/index.js.map +1 -1
  20. package/build/index.mjs +1 -0
  21. package/build/index.mjs.map +1 -1
  22. package/build/listItem/Prompt/ListItemPrompt.js +3 -2
  23. package/build/listItem/Prompt/ListItemPrompt.js.map +1 -1
  24. package/build/listItem/Prompt/ListItemPrompt.mjs +3 -2
  25. package/build/listItem/Prompt/ListItemPrompt.mjs.map +1 -1
  26. package/build/main.css +164 -29
  27. package/build/prompt/ActionPrompt/ActionPrompt.js +8 -40
  28. package/build/prompt/ActionPrompt/ActionPrompt.js.map +1 -1
  29. package/build/prompt/ActionPrompt/ActionPrompt.mjs +8 -40
  30. package/build/prompt/ActionPrompt/ActionPrompt.mjs.map +1 -1
  31. package/build/prompt/CriticalBanner/CriticalBanner.js +142 -0
  32. package/build/prompt/CriticalBanner/CriticalBanner.js.map +1 -0
  33. package/build/prompt/CriticalBanner/CriticalBanner.mjs +140 -0
  34. package/build/prompt/CriticalBanner/CriticalBanner.mjs.map +1 -0
  35. package/build/prompt/CriticalBanner/helpers.js +29 -0
  36. package/build/prompt/CriticalBanner/helpers.js.map +1 -0
  37. package/build/prompt/CriticalBanner/helpers.mjs +26 -0
  38. package/build/prompt/CriticalBanner/helpers.mjs.map +1 -0
  39. package/build/prompt/PrimitivePrompt/PrimitivePrompt.js +11 -4
  40. package/build/prompt/PrimitivePrompt/PrimitivePrompt.js.map +1 -1
  41. package/build/prompt/PrimitivePrompt/PrimitivePrompt.mjs +11 -4
  42. package/build/prompt/PrimitivePrompt/PrimitivePrompt.mjs.map +1 -1
  43. package/build/prompt/common/Expander/Expander.js +35 -0
  44. package/build/prompt/common/Expander/Expander.js.map +1 -0
  45. package/build/prompt/common/Expander/Expander.messages.js +17 -0
  46. package/build/prompt/common/Expander/Expander.messages.js.map +1 -0
  47. package/build/prompt/common/Expander/Expander.messages.mjs +13 -0
  48. package/build/prompt/common/Expander/Expander.messages.mjs.map +1 -0
  49. package/build/prompt/common/Expander/Expander.mjs +33 -0
  50. package/build/prompt/common/Expander/Expander.mjs.map +1 -0
  51. package/build/prompt/helpers/promptMedia.js +52 -0
  52. package/build/prompt/helpers/promptMedia.js.map +1 -0
  53. package/build/prompt/helpers/promptMedia.mjs +50 -0
  54. package/build/prompt/helpers/promptMedia.mjs.map +1 -0
  55. package/build/styles/main.css +164 -29
  56. package/build/styles/prompt/CriticalBanner/CriticalBanner.css +108 -0
  57. package/build/styles/prompt/CriticalBanner/CriticalBanner.vars.css +0 -0
  58. package/build/styles/prompt/common/Expander/Expander.css +8 -0
  59. package/build/typeahead/Typeahead.js +3 -2
  60. package/build/typeahead/Typeahead.js.map +1 -1
  61. package/build/typeahead/Typeahead.mjs +3 -2
  62. package/build/typeahead/Typeahead.mjs.map +1 -1
  63. package/build/types/common/hooks/useContainerSize.d.ts +14 -0
  64. package/build/types/common/hooks/useContainerSize.d.ts.map +1 -0
  65. package/build/types/common/hooks/useResizeObserver.d.ts +1 -1
  66. package/build/types/common/hooks/useResizeObserver.d.ts.map +1 -1
  67. package/build/types/index.d.ts +2 -2
  68. package/build/types/index.d.ts.map +1 -1
  69. package/build/types/prompt/ActionPrompt/ActionPrompt.d.ts +2 -11
  70. package/build/types/prompt/ActionPrompt/ActionPrompt.d.ts.map +1 -1
  71. package/build/types/prompt/CriticalBanner/CriticalBanner.d.ts +39 -0
  72. package/build/types/prompt/CriticalBanner/CriticalBanner.d.ts.map +1 -0
  73. package/build/types/prompt/CriticalBanner/helpers.d.ts +18 -0
  74. package/build/types/prompt/CriticalBanner/helpers.d.ts.map +1 -0
  75. package/build/types/prompt/CriticalBanner/index.d.ts +3 -0
  76. package/build/types/prompt/CriticalBanner/index.d.ts.map +1 -0
  77. package/build/types/prompt/PrimitivePrompt/PrimitivePrompt.d.ts +35 -3
  78. package/build/types/prompt/PrimitivePrompt/PrimitivePrompt.d.ts.map +1 -1
  79. package/build/types/prompt/common/Expander/Expander.d.ts +20 -0
  80. package/build/types/prompt/common/Expander/Expander.d.ts.map +1 -0
  81. package/build/types/prompt/common/Expander/Expander.messages.d.ts +14 -0
  82. package/build/types/prompt/common/Expander/Expander.messages.d.ts.map +1 -0
  83. package/build/types/prompt/helpers/promptMedia.d.ts +22 -0
  84. package/build/types/prompt/helpers/promptMedia.d.ts.map +1 -0
  85. package/build/types/prompt/index.d.ts +2 -0
  86. package/build/types/prompt/index.d.ts.map +1 -1
  87. package/build/types/test-utils/index.d.ts +4 -0
  88. package/build/types/test-utils/index.d.ts.map +1 -1
  89. package/package.json +3 -3
  90. package/src/common/hooks/useContainerSize.test.tsx +121 -0
  91. package/src/common/hooks/useContainerSize.ts +32 -0
  92. package/src/common/hooks/useResizeObserver.ts +3 -2
  93. package/src/i18n/en.json +2 -0
  94. package/src/index.ts +2 -2
  95. package/src/main.css +164 -29
  96. package/src/main.less +3 -1
  97. package/src/prompt/ActionPrompt/ActionPrompt.tsx +9 -62
  98. package/src/prompt/CriticalBanner/CriticalBanner.accessibility.docs.mdx +113 -0
  99. package/src/prompt/CriticalBanner/CriticalBanner.css +108 -0
  100. package/src/prompt/CriticalBanner/CriticalBanner.less +127 -0
  101. package/src/prompt/CriticalBanner/CriticalBanner.story.tsx +633 -0
  102. package/src/prompt/CriticalBanner/CriticalBanner.test.story.tsx +422 -0
  103. package/src/prompt/CriticalBanner/CriticalBanner.tsx +178 -0
  104. package/src/prompt/CriticalBanner/CriticalBanner.vars.css +0 -0
  105. package/src/prompt/CriticalBanner/CriticalBanner.vars.less +6 -0
  106. package/src/prompt/CriticalBanner/helpers.ts +39 -0
  107. package/src/prompt/CriticalBanner/index.ts +2 -0
  108. package/src/prompt/PrimitivePrompt/PrimitivePrompt.tsx +56 -40
  109. package/src/prompt/common/Expander/Expander.css +8 -0
  110. package/src/prompt/common/Expander/Expander.less +9 -0
  111. package/src/prompt/common/Expander/Expander.messages.ts +14 -0
  112. package/src/prompt/common/Expander/Expander.test.tsx +167 -0
  113. package/src/prompt/common/Expander/Expander.tsx +83 -0
  114. package/src/prompt/helpers/promptMedia.tsx +79 -0
  115. package/src/prompt/index.ts +4 -0
  116. package/src/sentimentSurface/SentimentSurface.story.tsx +43 -17
@@ -0,0 +1,121 @@
1
+ import React, { act } from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+
4
+ import { mockResizeObserver } from '../../test-utils/window-mock';
5
+
6
+ import { useContainerSize } from './useContainerSize';
7
+
8
+ mockResizeObserver();
9
+
10
+ describe('useContainerSize', () => {
11
+ let resizeObserverCallback: ResizeObserverCallback | null = null;
12
+
13
+ beforeEach(() => {
14
+ resizeObserverCallback = null;
15
+
16
+ // Capture the ResizeObserver callback for testing
17
+ const OriginalResizeObserver = global.ResizeObserver;
18
+ global.ResizeObserver = jest.fn().mockImplementation((callback: ResizeObserverCallback) => {
19
+ resizeObserverCallback = callback;
20
+ const instance = new OriginalResizeObserver(callback);
21
+ return instance;
22
+ }) as unknown as typeof ResizeObserver;
23
+ });
24
+
25
+ // Helper to create a test component
26
+ function TestComponent({
27
+ breakpoint,
28
+ onStateChange,
29
+ }: {
30
+ breakpoint: number;
31
+ onStateChange: (state: boolean) => void;
32
+ }) {
33
+ const [ref, isAboveBreakpoint] = useContainerSize(breakpoint);
34
+
35
+ // Call the callback whenever state changes
36
+ React.useEffect(() => {
37
+ onStateChange(isAboveBreakpoint);
38
+ }, [isAboveBreakpoint, onStateChange]);
39
+
40
+ return (
41
+ <div ref={ref} data-testid="container">
42
+ Test
43
+ </div>
44
+ );
45
+ }
46
+
47
+ // Helper to simulate container resize
48
+ function simulateResize(width: number, options?: { noBorderBoxSize?: boolean }) {
49
+ const container = screen.getByTestId('container');
50
+
51
+ act(() => {
52
+ if (resizeObserverCallback) {
53
+ const entry = {
54
+ target: container,
55
+ borderBoxSize: options?.noBorderBoxSize
56
+ ? undefined
57
+ : [{ inlineSize: width, blockSize: 100 }],
58
+ contentRect: {
59
+ width,
60
+ height: 100,
61
+ x: 0,
62
+ y: 0,
63
+ top: 0,
64
+ right: width,
65
+ bottom: 100,
66
+ left: 0,
67
+ toJSON: () => ({}),
68
+ },
69
+ contentBoxSize: [{ inlineSize: width, blockSize: 100 }],
70
+ devicePixelContentBoxSize: [{ inlineSize: width, blockSize: 100 }],
71
+ } as ResizeObserverEntry;
72
+
73
+ resizeObserverCallback([entry], {} as ResizeObserver);
74
+ }
75
+ });
76
+ }
77
+
78
+ it('returns initial state as false', () => {
79
+ const onStateChange = jest.fn();
80
+ render(<TestComponent breakpoint={480} onStateChange={onStateChange} />);
81
+
82
+ // Initial call with false
83
+ expect(onStateChange).toHaveBeenCalledWith(false);
84
+ });
85
+
86
+ it('updates to true when container width is above breakpoint', () => {
87
+ const onStateChange = jest.fn();
88
+ render(<TestComponent breakpoint={480} onStateChange={onStateChange} />);
89
+
90
+ simulateResize(600);
91
+ expect(onStateChange).toHaveBeenCalledWith(true);
92
+ });
93
+
94
+ it('remains false when container width is below breakpoint', () => {
95
+ const onStateChange = jest.fn();
96
+ render(<TestComponent breakpoint={480} onStateChange={onStateChange} />);
97
+
98
+ simulateResize(400);
99
+ expect(onStateChange).toHaveBeenCalledWith(false);
100
+ expect(onStateChange).not.toHaveBeenCalledWith(true);
101
+ });
102
+
103
+ it('returns true when container width equals breakpoint', () => {
104
+ const onStateChange = jest.fn();
105
+ render(<TestComponent breakpoint={480} onStateChange={onStateChange} />);
106
+
107
+ simulateResize(480);
108
+ expect(onStateChange).toHaveBeenCalledWith(true);
109
+ });
110
+
111
+ it('updates state when container crosses breakpoint from below to above', () => {
112
+ const onStateChange = jest.fn();
113
+ render(<TestComponent breakpoint={480} onStateChange={onStateChange} />);
114
+
115
+ simulateResize(400);
116
+ expect(onStateChange).toHaveBeenCalledWith(false);
117
+
118
+ simulateResize(600);
119
+ expect(onStateChange).toHaveBeenCalledWith(true);
120
+ });
121
+ });
@@ -0,0 +1,32 @@
1
+ import { useRef, useState } from 'react';
2
+
3
+ import { useResizeObserver } from './useResizeObserver';
4
+
5
+ /**
6
+ * Hook that returns a ref and a boolean indicating if the container
7
+ * has a width >= the specified breakpoint.
8
+ *
9
+ * Useful for synchronizing React state with CSS container queries.
10
+ *
11
+ * Uses content-box measurements to match CSS container query behavior
12
+ * (excludes padding and border).
13
+ *
14
+ * @param breakpoint - Minimum width in pixels
15
+ * @returns [ref, isAboveBreakpoint] tuple
16
+ */
17
+ export function useContainerSize(breakpoint: number): [React.RefObject<HTMLDivElement>, boolean] {
18
+ const ref = useRef<HTMLDivElement>(null);
19
+ const [isAboveBreakpoint, setIsAboveBreakpoint] = useState(false);
20
+
21
+ useResizeObserver(
22
+ ref,
23
+ (entry) => {
24
+ // Use contentRect.width to match CSS container query box model (content-box)
25
+ const inlineSize = entry.contentRect.width;
26
+ setIsAboveBreakpoint(inlineSize >= breakpoint);
27
+ },
28
+ 'content-box',
29
+ );
30
+
31
+ return [ref, isAboveBreakpoint];
32
+ }
@@ -5,6 +5,7 @@ import { useEffectEvent } from './useEffectEvent';
5
5
  export function useResizeObserver(
6
6
  ref: React.MutableRefObject<Element | null>,
7
7
  callback: (entry: ResizeObserverEntry) => void,
8
+ box: ResizeObserverBoxOptions = 'border-box',
8
9
  ) {
9
10
  const handleCallback = useEffectEvent(callback);
10
11
  useEffect(() => {
@@ -12,11 +13,11 @@ export function useResizeObserver(
12
13
  const resizeObserver = new ResizeObserver(([entry]) => {
13
14
  handleCallback(entry);
14
15
  });
15
- resizeObserver.observe(ref.current, { box: 'border-box' });
16
+ resizeObserver.observe(ref.current, { box });
16
17
  return () => {
17
18
  resizeObserver.disconnect();
18
19
  };
19
20
  }
20
21
  return () => {};
21
- }, [handleCallback, ref]);
22
+ }, [handleCallback, ref, box]);
22
23
  }
package/src/i18n/en.json CHANGED
@@ -16,6 +16,8 @@
16
16
  "neptune.DateLookup.selected": "selected",
17
17
  "neptune.DateLookup.twentyYears": "20 years",
18
18
  "neptune.DateLookup.year": "year",
19
+ "neptune.Expander.collapseAriaLabel": "Collapse",
20
+ "neptune.Expander.expandAriaLabel": "Expand",
19
21
  "neptune.ExpressiveMoneyInput.currency.search.placeholder": "Type a currency / country",
20
22
  "neptune.ExpressiveMoneyInput.currency.select.currency": "Select currency",
21
23
  "neptune.FlowNavigation.back": "back to previous step",
package/src/index.ts CHANGED
@@ -35,7 +35,7 @@ export type { HeaderProps } from './header';
35
35
  export type { EmphasisProps } from './emphasis';
36
36
  export type { FieldProps } from './field/Field';
37
37
  export type { InfoProps } from './info';
38
- export type { InlinePromptProps, ActionPromptProps } from './prompt';
38
+ export type { InlinePromptProps, ActionPromptProps, CriticalBannerProps } from './prompt';
39
39
  export type { InfoPromptProps, InfoPromptAction, InfoPromptMedia } from './prompt';
40
40
  export type { InputWithDisplayFormatProps } from './inputWithDisplayFormat';
41
41
  export type { InputProps } from './inputs/Input';
@@ -173,7 +173,7 @@ export { default as Header } from './header';
173
173
  export { default as Image } from './image';
174
174
  export { default as Info } from './info';
175
175
  export { default as InlineAlert } from './inlineAlert';
176
- export { InfoPrompt, InlinePrompt, ActionPrompt } from './prompt';
176
+ export { InfoPrompt, InlinePrompt, ActionPrompt, CriticalBanner } from './prompt';
177
177
  export { default as InputWithDisplayFormat } from './inputWithDisplayFormat';
178
178
  export { Input } from './inputs/Input';
179
179
  export { InputGroup } from './inputs/InputGroup';
package/src/main.css CHANGED
@@ -32187,6 +32187,170 @@ html:not([dir="rtl"]) .np-navigation-option {
32187
32187
  padding: 0;
32188
32188
  }
32189
32189
 
32190
+ .wds-action-prompt {
32191
+ --Prompt-padding: var(--size-16);
32192
+ --Prompt-actions-gap: var(--size-8);
32193
+ --Prompt-gap: var(--size-10) var(--size-16);
32194
+ --Prompt-border-radius: var(--radius-large);
32195
+ }
32196
+
32197
+ .wds-action-prompt--media-image {
32198
+ width: 48px;
32199
+ width: var(--size-48);
32200
+ height: 48px;
32201
+ height: var(--size-48);
32202
+ -o-object-fit: contain;
32203
+ object-fit: contain;
32204
+ }
32205
+
32206
+ @media (max-width: 767px) {
32207
+ .wds-action-prompt--with-two-actions .wds-prompt__actions-wrapper .wds-Button {
32208
+ flex: 1 1 calc(50% - (var(--Prompt-actions-gap) / 2));
32209
+ min-width: -moz-fit-content;
32210
+ min-width: fit-content;
32211
+ }
32212
+ }
32213
+
32214
+ .wds-action-prompt__content {
32215
+ max-width: calc(48px * 10);
32216
+ max-width: calc(var(--size-48) * 10);
32217
+ }
32218
+
32219
+ .wds-critical-banner {
32220
+ --Prompt-padding: var(--size-16);
32221
+ --Prompt-actions-gap: var(--size-8);
32222
+ --Prompt-gap: var(--size-10) var(--size-16);
32223
+ --Prompt-border-radius: 0;
32224
+ container-type: inline-size;
32225
+ --critical-banner-easing: cubic-bezier(0.9, 0, 0.7, 1);
32226
+ --critical-banner-duration: 150ms;
32227
+ /* Override PrimitivePrompt's --screen-sm-max actions behaviour:
32228
+ actions only go full-width below mobile-max token (container query) */
32229
+ }
32230
+
32231
+ .wds-critical-banner--media-image {
32232
+ width: 48px;
32233
+ width: var(--size-48);
32234
+ height: 48px;
32235
+ height: var(--size-48);
32236
+ -o-object-fit: contain;
32237
+ object-fit: contain;
32238
+ }
32239
+
32240
+ .wds-critical-banner--collapsed .wds-critical-banner__title {
32241
+ display: -webkit-box;
32242
+ -webkit-line-clamp: 2;
32243
+ line-clamp: 2;
32244
+ -webkit-box-orient: vertical;
32245
+ overflow: hidden;
32246
+ }
32247
+
32248
+ .wds-critical-banner__description {
32249
+ max-height: 30vh;
32250
+ opacity: 1;
32251
+ overflow: hidden;
32252
+ transition: max-height var(--critical-banner-duration) var(--critical-banner-easing), opacity var(--critical-banner-duration) var(--critical-banner-easing);
32253
+ }
32254
+
32255
+ .wds-critical-banner--collapsed .wds-critical-banner__description--with-title {
32256
+ max-height: 0;
32257
+ opacity: 0;
32258
+ }
32259
+
32260
+ .wds-critical-banner--collapsed .wds-critical-banner__description:not(.wds-critical-banner__description--with-title) {
32261
+ display: -webkit-box;
32262
+ -webkit-line-clamp: 2;
32263
+ line-clamp: 2;
32264
+ -webkit-box-orient: vertical;
32265
+ overflow: hidden;
32266
+ }
32267
+
32268
+ .wds-critical-banner .wds-prompt__content-wrapper {
32269
+ grid-template-columns: auto 1fr auto;
32270
+ align-items: flex-start;
32271
+ transition: row-gap var(--critical-banner-duration) var(--critical-banner-easing);
32272
+ }
32273
+
32274
+ .wds-critical-banner--collapsed .wds-prompt__content-wrapper {
32275
+ row-gap: 0;
32276
+ }
32277
+
32278
+ .wds-critical-banner__text-wrapper {
32279
+ display: flex;
32280
+ flex-direction: column;
32281
+ justify-content: center;
32282
+ min-width: 0;
32283
+ max-width: 480px;
32284
+ height: 100%;
32285
+ }
32286
+
32287
+ .wds-critical-banner__toggle {
32288
+ flex-shrink: 0;
32289
+ transition: transform var(--critical-banner-duration) var(--critical-banner-easing);
32290
+ }
32291
+
32292
+ .wds-critical-banner__toggle--collapsed {
32293
+ transform: rotate(180deg);
32294
+ }
32295
+
32296
+ @container (min-width: 768px) {
32297
+ .wds-critical-banner__toggle {
32298
+ display: none;
32299
+ }
32300
+ }
32301
+
32302
+ .wds-critical-banner .wds-prompt__actions-wrapper {
32303
+ grid-column-start: 2;
32304
+ grid-column-end: 3;
32305
+ max-height: 200px;
32306
+ opacity: 1;
32307
+ overflow: visible;
32308
+ }
32309
+
32310
+ @container (max-width: 480px) {
32311
+ .wds-critical-banner .wds-prompt__actions-wrapper {
32312
+ grid-column: span 3;
32313
+ width: 100%;
32314
+ }
32315
+ .wds-critical-banner .wds-prompt__actions-wrapper .wds-Button {
32316
+ flex: 1 1 100%;
32317
+ width: 100%;
32318
+ }
32319
+ }
32320
+
32321
+ .wds-critical-banner--collapsed .wds-prompt__actions-wrapper {
32322
+ max-height: 0;
32323
+ opacity: 0;
32324
+ overflow: hidden;
32325
+ pointer-events: none;
32326
+ }
32327
+
32328
+ @container (max-width: 480px) {
32329
+ .wds-critical-banner--with-two-actions .wds-prompt__actions-wrapper .wds-Button {
32330
+ flex: 1 1 calc(50% - (var(--Prompt-actions-gap) / 2));
32331
+ min-width: -moz-fit-content;
32332
+ min-width: fit-content;
32333
+ }
32334
+ }
32335
+
32336
+ @media (prefers-reduced-motion: reduce) {
32337
+ .wds-critical-banner__description,
32338
+ .wds-critical-banner .wds-prompt__content-wrapper,
32339
+ .wds-critical-banner__toggle {
32340
+ transition: none !important;
32341
+ }
32342
+ }
32343
+
32344
+ .wds-expander-toggle {
32345
+ align-self: flex-start;
32346
+ flex-shrink: 0;
32347
+ transition: transform 0.2s ease-in-out;
32348
+ }
32349
+
32350
+ .wds-expander-toggle--collapsed {
32351
+ transform: rotate(180deg);
32352
+ }
32353
+
32190
32354
  .wds-radio-group .np-radio:last-child label {
32191
32355
  margin-bottom: 0;
32192
32356
  }
@@ -34612,32 +34776,3 @@ html:not([dir="rtl"]) .np-navigation-option {
34612
34776
  .np-list-item__action {
34613
34777
  flex-shrink: 0;
34614
34778
  }
34615
-
34616
- .wds-action-prompt {
34617
- --Prompt-padding: var(--size-16);
34618
- --Prompt-actions-gap: var(--size-8);
34619
- --Prompt-gap: var(--size-10) var(--size-16);
34620
- --Prompt-border-radius: var(--radius-large);
34621
- }
34622
-
34623
- .wds-action-prompt--media-image {
34624
- width: 48px;
34625
- width: var(--size-48);
34626
- height: 48px;
34627
- height: var(--size-48);
34628
- -o-object-fit: contain;
34629
- object-fit: contain;
34630
- }
34631
-
34632
- @media (max-width: 767px) {
34633
- .wds-action-prompt--with-two-actions .wds-prompt__actions-wrapper .wds-Button {
34634
- flex: 1 1 calc(50% - (var(--Prompt-actions-gap) / 2));
34635
- min-width: -moz-fit-content;
34636
- min-width: fit-content;
34637
- }
34638
- }
34639
-
34640
- .wds-action-prompt__content {
34641
- max-width: calc(48px * 10);
34642
- max-width: calc(var(--size-48) * 10);
34643
- }
package/src/main.less CHANGED
@@ -66,6 +66,9 @@
66
66
  @import "./prompt/PrimitivePrompt/PrimitivePrompt.less";
67
67
  @import "./prompt/InlinePrompt/InlinePrompt.less";
68
68
  @import "./prompt/InfoPrompt/InfoPrompt.less";
69
+ @import "./prompt/ActionPrompt/ActionPrompt.less";
70
+ @import "./prompt/CriticalBanner/CriticalBanner.less";
71
+ @import "./prompt/common/Expander/Expander.less";
69
72
  @import "./radioGroup/RadioGroup.less";
70
73
  @import "./section/Section.less";
71
74
  @import "./slidingPanel/SlidingPanel.less";
@@ -90,7 +93,6 @@
90
93
  @import "./progress/Progress.less";
91
94
  @import "./progressBar/ProgressBar.less";
92
95
  @import "./legacylistItem/LegacyListItem.less";
93
- @import "./prompt/ActionPrompt/ActionPrompt.less";
94
96
 
95
97
  // List all less files in src in alphabetical order: find -s src -type f -name '*.less' ! -name 'main.less'
96
98
  // Make sure you are not referencing main.less itself in this file!
@@ -1,31 +1,19 @@
1
1
  import { AriaAttributes, ReactNode, useId } from 'react';
2
2
  import { clsx } from 'clsx';
3
3
 
4
- import StatusIcon from '../../statusIcon';
5
4
  import Body from '../../body';
6
5
  import Button from '../../button';
7
6
  import { Breakpoint, Typography } from '../../common';
8
- import AvatarView, { AvatarViewProps } from '../../avatarView';
9
- import Image from '../../image';
10
7
  import { ButtonProps } from '../../button/Button.types';
11
8
  import { PrimitivePrompt, PrimitivePromptProps } from '../PrimitivePrompt';
12
- import { BadgeAssetsProps } from '../../badge';
13
- import { GiftBox } from '@transferwise/icons';
14
9
  import { useScreenSize } from '../../common/hooks/useScreenSize';
10
+ import { renderPromptMedia, PromptMedia } from '../helpers/promptMedia';
15
11
 
16
12
  export type ActionPromptProps = {
17
13
  title: ReactNode;
18
14
  description?: ReactNode;
19
15
  /** @default {} */
20
- media?: {
21
- imgSrc?: string;
22
- avatar?: Pick<AvatarViewProps, 'imgSrc' | 'profileName' | 'profileType'> & {
23
- asset?: AvatarViewProps['children'];
24
- badge?: Pick<BadgeAssetsProps, 'flagCode'>;
25
- };
26
- 'aria-label'?: string;
27
- 'aria-hidden'?: boolean;
28
- };
16
+ media?: PromptMedia;
29
17
  action: Pick<ButtonProps, 'onClick' | 'href' | 'target'> & {
30
18
  label: ButtonProps['children'];
31
19
  };
@@ -74,54 +62,13 @@ export const ActionPrompt = ({
74
62
  .filter(Boolean)
75
63
  .join(' ');
76
64
 
77
- const renderMedia = () => {
78
- if (media?.imgSrc) {
79
- return (
80
- <Image
81
- id={mediaId}
82
- src={media.imgSrc}
83
- className="wds-action-prompt--media-image"
84
- alt={media['aria-label'] ?? ''}
85
- />
86
- );
87
- }
88
- if (media?.avatar) {
89
- const badge = media.avatar.badge
90
- ? media.avatar.badge
91
- : sentiment === 'proposition'
92
- ? {}
93
- : { status: sentiment };
94
- return (
95
- <AvatarView
96
- {...media.avatar}
97
- badge={badge}
98
- aria-label={media['aria-label']}
99
- aria-hidden={media['aria-hidden']}
100
- id={mediaId}
101
- size={48}
102
- >
103
- {media.avatar.asset}
104
- </AvatarView>
105
- );
106
- }
107
- return sentiment === 'proposition' ? (
108
- <AvatarView
109
- id={mediaId}
110
- size={48}
111
- aria-label={media['aria-label']}
112
- aria-hidden={media['aria-hidden']}
113
- >
114
- <GiftBox />
115
- </AvatarView>
116
- ) : (
117
- <StatusIcon
118
- id={mediaId}
119
- size={48}
120
- sentiment={sentiment}
121
- iconLabel={media['aria-hidden'] ? null : media['aria-label']}
122
- />
123
- );
124
- };
65
+ const renderMedia = () =>
66
+ renderPromptMedia({
67
+ media,
68
+ sentiment,
69
+ mediaId,
70
+ imgClassName: 'wds-action-prompt--media-image',
71
+ });
125
72
 
126
73
  return (
127
74
  <PrimitivePrompt
@@ -0,0 +1,113 @@
1
+ import { Meta, Source, Canvas } from '@storybook/addon-docs/blocks';
2
+ import * as CriticalBannerStories from './CriticalBanner.story';
3
+
4
+ <Meta title="Prompts/CriticalBanner/Accessibility" tags={['new']} />
5
+
6
+ # Accessibility
7
+
8
+ Under the hood, `CriticalBanner` is marked as `role="region"` for a section of content that users might want to navigate to directly.
9
+
10
+ By default, it's labelled by the `title` and described by the `description`.
11
+
12
+ ## Announcement Behavior
13
+
14
+ `CriticalBanner` is designed for critical messages that require immediate attention. It always uses **`aria-live="assertive"`** to immediately interrupt and announce changes to screen readers.
15
+
16
+ Unlike `InfoPrompt` which offers configurable politeness levels, `CriticalBanner` is always assertive because it communicates critical, time-sensitive information that users must be aware of immediately.
17
+
18
+ ### What Gets Announced
19
+
20
+ The component intelligently announces only **visible content**, respecting the collapsed/expanded state:
21
+
22
+ - **Collapsed with title**: Announces title only (description is hidden)
23
+ - **Collapsed without title**: Announces description only (visible up to 2 lines)
24
+ - **Expanded**: Announces title, description, and action button labels (all visible)
25
+
26
+ <Source
27
+ dark
28
+ code={`
29
+ // Collapsed with title - announces: "Your account requires verification"
30
+ <CriticalBanner
31
+ title="Your account requires verification"
32
+ description="Please verify your identity to continue"
33
+ action={{ label: "Verify now", onClick: handleVerify }}
34
+ expanded={false}
35
+ onToggle={handleToggle}
36
+ />
37
+
38
+ // Expanded - announces: "Your account requires verification | Please verify your identity to continue | Verify now | Learn more"
39
+
40
+ <CriticalBanner
41
+ title="Your account requires verification"
42
+ description="Please verify your identity to continue"
43
+ action={{ label: 'Verify now', onClick: handleVerify }}
44
+ actionSecondary={{ label: 'Learn more', onClick: handleLearnMore }}
45
+ expanded={true}
46
+ onToggle={handleToggle}
47
+ />
48
+
49
+ // Collapsed without title - announces: "Your verification is pending..."
50
+
51
+ <CriticalBanner
52
+ description="Your verification is pending. We'll notify you once complete."
53
+ expanded={false}
54
+ onToggle={handleToggle}
55
+ />
56
+ `}
57
+ />
58
+
59
+ ### When Announcements Trigger
60
+
61
+ Screen readers announce the banner content whenever:
62
+
63
+ - The banner first appears in the DOM
64
+ - The user toggles between collapsed and expanded states
65
+ - The content (title, description, or action labels) changes
66
+
67
+ ## Media
68
+
69
+ Custom media icons should include their own accessibility attributes. Use the `title` prop on icons to provide accessible names for screen readers:
70
+
71
+ <Source
72
+ dark
73
+ code={`
74
+ import { Bank, AlertCircle } from '@transferwise/icons';
75
+
76
+ <CriticalBanner
77
+ title="Bank connection required"
78
+ description="Connect your bank account to continue"
79
+ media={{ avatar: { asset: <Bank title="Bank account" /> } }}
80
+ action={{ label: 'Connect now', onClick: handleConnect }}
81
+ expanded={false}
82
+ onToggle={handleToggle}
83
+ />
84
+
85
+ <CriticalBanner
86
+ title="Verification required"
87
+ description="We need to verify your identity"
88
+ media={{ avatar: { asset: <AlertCircle title="Alert" /> } }}
89
+ action={{ label: "Start verification", onClick: handleVerify }}
90
+ expanded={false}
91
+ onToggle={handleToggle}
92
+ />
93
+ `}
94
+ />
95
+
96
+ Alternatively, you can use `media['aria-label']` to provide a label for custom images:
97
+
98
+ <Source
99
+ dark
100
+ code={`
101
+ <CriticalBanner
102
+ title="Card blocked"
103
+ description="Your card has been blocked for security reasons"
104
+ media={{
105
+ imgSrc: '/wise-card.svg',
106
+ 'aria-label': 'Wise debit card'
107
+ }}
108
+ action={{ label: "Unblock card", onClick: handleUnblock }}
109
+ expanded={false}
110
+ onToggle={handleToggle}
111
+ />
112
+ `}
113
+ />