@transferwise/components 46.168.0 → 46.168.2
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/ListItem/ListItem.js +32 -2
- package/build/ListItem/ListItem.js.map +1 -1
- package/build/ListItem/ListItem.mjs +33 -3
- package/build/ListItem/ListItem.mjs.map +1 -1
- package/build/Prompt/Snackbar/Snackbar.js +11 -9
- package/build/Prompt/Snackbar/Snackbar.js.map +1 -1
- package/build/Prompt/Snackbar/Snackbar.mjs +7 -8
- package/build/Prompt/Snackbar/Snackbar.mjs.map +1 -1
- package/build/Prompt/Snackbar/SnackbarProvider.js +2 -2
- package/build/Prompt/Snackbar/SnackbarProvider.js.map +1 -1
- package/build/Prompt/Snackbar/SnackbarProvider.mjs +2 -2
- package/build/Prompt/Snackbar/SnackbarProvider.mjs.map +1 -1
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.js +33 -46
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.js.map +1 -1
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.mjs +34 -47
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.mjs.map +1 -1
- package/build/Provider/Provider.js +1 -24
- package/build/Provider/Provider.js.map +1 -1
- package/build/Provider/Provider.mjs +1 -24
- package/build/Provider/Provider.mjs.map +1 -1
- package/build/WithDisplayFormat/WithDisplayFormat.js +20 -8
- package/build/WithDisplayFormat/WithDisplayFormat.js.map +1 -1
- package/build/WithDisplayFormat/WithDisplayFormat.mjs +20 -8
- package/build/WithDisplayFormat/WithDisplayFormat.mjs.map +1 -1
- package/build/i18n/cs.json +1 -0
- package/build/i18n/cs.json.js +1 -0
- package/build/i18n/cs.json.js.map +1 -1
- package/build/i18n/cs.json.mjs +1 -0
- package/build/i18n/cs.json.mjs.map +1 -1
- package/build/i18n/de.json +1 -0
- package/build/i18n/de.json.js +1 -0
- package/build/i18n/de.json.js.map +1 -1
- package/build/i18n/de.json.mjs +1 -0
- package/build/i18n/de.json.mjs.map +1 -1
- package/build/i18n/es.json +1 -0
- package/build/i18n/es.json.js +1 -0
- package/build/i18n/es.json.js.map +1 -1
- package/build/i18n/es.json.mjs +1 -0
- package/build/i18n/es.json.mjs.map +1 -1
- package/build/i18n/hu.json +1 -0
- package/build/i18n/hu.json.js +1 -0
- package/build/i18n/hu.json.js.map +1 -1
- package/build/i18n/hu.json.mjs +1 -0
- package/build/i18n/hu.json.mjs.map +1 -1
- package/build/i18n/id.json +1 -0
- package/build/i18n/id.json.js +1 -0
- package/build/i18n/id.json.js.map +1 -1
- package/build/i18n/id.json.mjs +1 -0
- package/build/i18n/id.json.mjs.map +1 -1
- package/build/i18n/it.json +1 -0
- package/build/i18n/it.json.js +1 -0
- package/build/i18n/it.json.js.map +1 -1
- package/build/i18n/it.json.mjs +1 -0
- package/build/i18n/it.json.mjs.map +1 -1
- package/build/i18n/ja.json +1 -0
- package/build/i18n/ja.json.js +1 -0
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +1 -0
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/nl.json +1 -0
- package/build/i18n/nl.json.js +1 -0
- package/build/i18n/nl.json.js.map +1 -1
- package/build/i18n/nl.json.mjs +1 -0
- package/build/i18n/nl.json.mjs.map +1 -1
- package/build/i18n/pl.json +1 -0
- package/build/i18n/pl.json.js +1 -0
- package/build/i18n/pl.json.js.map +1 -1
- package/build/i18n/pl.json.mjs +1 -0
- package/build/i18n/pl.json.mjs.map +1 -1
- package/build/i18n/pt.json +1 -0
- package/build/i18n/pt.json.js +1 -0
- package/build/i18n/pt.json.js.map +1 -1
- package/build/i18n/pt.json.mjs +1 -0
- package/build/i18n/pt.json.mjs.map +1 -1
- package/build/i18n/ro.json +1 -0
- package/build/i18n/ro.json.js +1 -0
- package/build/i18n/ro.json.js.map +1 -1
- package/build/i18n/ro.json.mjs +1 -0
- package/build/i18n/ro.json.mjs.map +1 -1
- package/build/i18n/ru.json +1 -0
- package/build/i18n/ru.json.js +1 -0
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +1 -0
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/th.json +1 -0
- package/build/i18n/th.json.js +1 -0
- package/build/i18n/th.json.js.map +1 -1
- package/build/i18n/th.json.mjs +1 -0
- package/build/i18n/th.json.mjs.map +1 -1
- package/build/i18n/uk.json +1 -0
- package/build/i18n/uk.json.js +1 -0
- package/build/i18n/uk.json.js.map +1 -1
- package/build/i18n/uk.json.mjs +1 -0
- package/build/i18n/uk.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +1 -0
- package/build/i18n/zh-HK.json.js +1 -0
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +1 -0
- package/build/i18n/zh-HK.json.mjs.map +1 -1
- package/build/main.css +12 -16
- package/build/styles/Inputs/InputGroup/InputGroup.css +1 -0
- package/build/styles/Prompt/ActionPrompt/ActionPrompt.css +10 -2
- package/build/styles/Prompt/CriticalBanner/CriticalBanner.css +1 -5
- package/build/styles/Prompt/PrimitivePrompt/PrimitivePrompt.css +0 -9
- package/build/styles/Prompt/PrimitivePrompt/PrimitivePrompt.vars.css +0 -0
- package/build/styles/main.css +12 -16
- package/build/test-utils/assets/apple-pay-logo.svg +0 -0
- package/build/types/ListItem/ListItem.d.ts +2 -0
- package/build/types/ListItem/ListItem.d.ts.map +1 -1
- package/build/types/Prompt/Snackbar/Snackbar.d.ts +2 -1
- package/build/types/Prompt/Snackbar/Snackbar.d.ts.map +1 -1
- package/build/types/Prompt/Snackbar/useSnackbarSwipeDismiss.d.ts +6 -8
- package/build/types/Prompt/Snackbar/useSnackbarSwipeDismiss.d.ts.map +1 -1
- package/build/types/WithDisplayFormat/WithDisplayFormat.d.ts +6 -4
- package/build/types/WithDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/InputWithDisplayFormat/_stories/InputWithDisplayFormat.story.tsx +39 -0
- package/src/Inputs/InputGroup/InputGroup.css +1 -0
- package/src/Inputs/InputGroup/InputGroup.less +1 -0
- package/src/Inputs/InputGroup/_stories/InputGroup.test.story.tsx +16 -0
- package/src/Inputs/SearchInput/_stories/SearchInput.test.story.tsx +9 -0
- package/src/Inputs/SelectInput/_stories/SelectInput.test.story.tsx +12 -0
- package/src/ListItem/ListItem.ssr.test.tsx +115 -0
- package/src/ListItem/ListItem.test.tsx +42 -0
- package/src/ListItem/ListItem.tsx +23 -2
- package/src/MoneyInput/_stories/MoneyInput.test.story.tsx +11 -0
- package/src/PhoneNumberInput/_stories/PhoneNumberInput.test.story.tsx +30 -0
- package/src/Prompt/ActionPrompt/ActionPrompt.css +10 -2
- package/src/Prompt/ActionPrompt/ActionPrompt.less +17 -2
- package/src/Prompt/ActionPrompt/_stories/ActionPrompt.test.story.tsx +29 -29
- package/src/Prompt/CriticalBanner/CriticalBanner.css +1 -5
- package/src/Prompt/CriticalBanner/CriticalBanner.less +3 -6
- package/src/Prompt/CriticalBanner/CriticalBanner.vars.less +3 -3
- package/src/Prompt/PrimitivePrompt/PrimitivePrompt.css +0 -9
- package/src/Prompt/PrimitivePrompt/PrimitivePrompt.less +0 -9
- package/src/Prompt/PrimitivePrompt/PrimitivePrompt.vars.css +0 -0
- package/src/Prompt/PrimitivePrompt/PrimitivePrompt.vars.less +2 -0
- package/src/Prompt/Snackbar/Snackbar.test.tsx +1 -69
- package/src/Prompt/Snackbar/Snackbar.tsx +6 -7
- package/src/Prompt/Snackbar/SnackbarProvider.tsx +2 -2
- package/src/Prompt/Snackbar/useSnackbarSwipeDismiss.ts +39 -54
- package/src/Provider/Provider.tsx +1 -1
- package/src/WithDisplayFormat/WithDisplayFormat.test.js +90 -7
- package/src/WithDisplayFormat/WithDisplayFormat.tsx +30 -9
- package/src/i18n/cs.json +1 -0
- package/src/i18n/de.json +1 -0
- package/src/i18n/es.json +1 -0
- package/src/i18n/hu.json +1 -0
- package/src/i18n/id.json +1 -0
- package/src/i18n/it.json +1 -0
- package/src/i18n/ja.json +1 -0
- package/src/i18n/nl.json +1 -0
- package/src/i18n/pl.json +1 -0
- package/src/i18n/pt.json +1 -0
- package/src/i18n/ro.json +1 -0
- package/src/i18n/ru.json +1 -0
- package/src/i18n/th.json +1 -0
- package/src/i18n/uk.json +1 -0
- package/src/i18n/zh-HK.json +1 -0
- package/src/main.css +12 -16
- package/src/test-utils/assets/apple-pay-logo.svg +0 -0
- package/build/Prompt/Snackbar/SnackbarPortal.js +0 -12
- package/build/Prompt/Snackbar/SnackbarPortal.js.map +0 -1
- package/build/Prompt/Snackbar/SnackbarPortal.mjs +0 -8
- package/build/Prompt/Snackbar/SnackbarPortal.mjs.map +0 -1
- package/build/types/Prompt/Snackbar/SnackbarPortal.d.ts +0 -4
- package/build/types/Prompt/Snackbar/SnackbarPortal.d.ts.map +0 -1
- package/src/Prompt/Snackbar/SnackbarPortal.tsx +0 -8
|
@@ -232,37 +232,37 @@ export const TinyScreen: Story = {
|
|
|
232
232
|
};
|
|
233
233
|
|
|
234
234
|
/**
|
|
235
|
-
* ActionPrompt adapts its layout
|
|
236
|
-
*
|
|
235
|
+
* ActionPrompt adapts its layout to its own width (container queries), not the viewport.
|
|
236
|
+
* Below a 600px content width the buttons go full width, otherwise they sit side by side.
|
|
237
237
|
*/
|
|
238
238
|
export const Responsiveness: Story = {
|
|
239
|
-
render: (
|
|
240
|
-
<div
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
239
|
+
render: () => (
|
|
240
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
|
|
241
|
+
{[
|
|
242
|
+
{ width: 320, layout: 'Full width' },
|
|
243
|
+
{ width: 480, layout: 'Full width' },
|
|
244
|
+
{ width: 800, layout: 'Side by side' },
|
|
245
|
+
].map(({ width, layout }) => (
|
|
246
|
+
<div key={width} style={{ width }}>
|
|
247
|
+
<ActionPrompt
|
|
248
|
+
sentiment="proposition"
|
|
249
|
+
title={`${layout} (${width}px)`}
|
|
250
|
+
description={lorem10}
|
|
251
|
+
media={{ avatar: { asset: <Suitcase /> } }}
|
|
252
|
+
action={{ label: 'Primary action', onClick: fn() }}
|
|
253
|
+
actionSecondary={{ label: 'Secondary', onClick: fn() }}
|
|
254
|
+
onDismiss={fn()}
|
|
255
|
+
/>
|
|
256
|
+
</div>
|
|
257
|
+
))}
|
|
258
|
+
<div style={{ width: 320 }}>
|
|
259
|
+
<ActionPrompt
|
|
260
|
+
sentiment="neutral"
|
|
261
|
+
title="Single action, full width (320px)"
|
|
262
|
+
description={lorem10}
|
|
263
|
+
action={{ label: 'Primary action', onClick: fn() }}
|
|
264
|
+
/>
|
|
265
|
+
</div>
|
|
266
266
|
</div>
|
|
267
267
|
),
|
|
268
268
|
parameters: {
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
position: relative;
|
|
12
12
|
--critical-banner-easing: cubic-bezier(0.9, 0, 0.7, 1);
|
|
13
13
|
--critical-banner-duration: 150ms;
|
|
14
|
-
/* Override PrimitivePrompt's --screen-sm-max actions behaviour:
|
|
15
|
-
actions only go full-width below mobile-max token (container query) */
|
|
16
14
|
}
|
|
17
15
|
.wds-critical-banner.wds-prompt--neutral {
|
|
18
16
|
--critical-banner-background-base: var(--color-background-elevated);
|
|
@@ -91,13 +89,11 @@
|
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
.wds-critical-banner .wds-prompt__actions-wrapper {
|
|
94
|
-
grid-column-start: 2;
|
|
95
|
-
grid-column-end: 3;
|
|
96
92
|
max-block-size: 200px;
|
|
97
93
|
opacity: 1;
|
|
98
94
|
overflow: visible;
|
|
99
95
|
}
|
|
100
|
-
@container (
|
|
96
|
+
@container (width < 600px) {
|
|
101
97
|
.wds-critical-banner .wds-prompt__actions-wrapper {
|
|
102
98
|
grid-column: span 3;
|
|
103
99
|
inline-size: 100%;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@import (reference) "@transferwise/neptune-tokens/breakpoints.less";
|
|
2
|
+
@import (reference) "../PrimitivePrompt/PrimitivePrompt.vars.less";
|
|
2
3
|
@import (reference) "./CriticalBanner.vars.less";
|
|
3
4
|
|
|
4
5
|
.wds-critical-banner {
|
|
@@ -114,16 +115,12 @@
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
/* Override PrimitivePrompt's --screen-sm-max actions behaviour:
|
|
118
|
-
actions only go full-width below mobile-max token (container query) */
|
|
119
118
|
.wds-prompt__actions-wrapper {
|
|
120
|
-
grid-column-start: 2;
|
|
121
|
-
grid-column-end: 3;
|
|
122
119
|
max-height: 200px;
|
|
123
120
|
opacity: 1;
|
|
124
121
|
overflow: visible;
|
|
125
122
|
|
|
126
|
-
@container (
|
|
123
|
+
@container (width < @wds-prompt-actions-full-width-max) {
|
|
127
124
|
grid-column: span 3;
|
|
128
125
|
width: 100%;
|
|
129
126
|
|
|
@@ -142,7 +139,7 @@
|
|
|
142
139
|
}
|
|
143
140
|
|
|
144
141
|
&--with-two-actions .wds-prompt__actions-wrapper {
|
|
145
|
-
@container (max-width: @wds-
|
|
142
|
+
@container (max-width: @wds-prompt-actions-full-width-max) {
|
|
146
143
|
.wds-Button {
|
|
147
144
|
flex: 1 1 calc(50% - (var(--Prompt-actions-gap) / 2));
|
|
148
145
|
min-width: fit-content;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// CriticalBanner has 2 layout modes managed through container queries:
|
|
2
|
-
// * buttons are full width below
|
|
3
|
-
// * collapse toggle is visible below collapsible-max token
|
|
2
|
+
// * buttons are full width below @wds-prompt-actions-full-width-max
|
|
3
|
+
// * collapse toggle is visible below @wds-critical-banner-collapsible-max token
|
|
4
4
|
// At some point in the not too distant future hopefully these two value will be the same but because of launchpad quirks, for now they'll be different
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
@wds-critical-banner-mobile-overhang-max: 600px;
|
|
7
7
|
@wds-critical-banner-collapsible-max: 768px;
|
|
@@ -35,15 +35,6 @@
|
|
|
35
35
|
grid-column-start: 2;
|
|
36
36
|
grid-column-end: 3;
|
|
37
37
|
}
|
|
38
|
-
@media (max-width: 599.98px) {
|
|
39
|
-
.wds-prompt__actions-wrapper {
|
|
40
|
-
grid-column: span 2;
|
|
41
|
-
inline-size: 100%;
|
|
42
|
-
}
|
|
43
|
-
.wds-prompt__content-wrapper--with-dismiss .wds-prompt__actions-wrapper {
|
|
44
|
-
grid-column: span 3;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
38
|
.wds-prompt__dismiss {
|
|
48
39
|
position: relative;
|
|
49
40
|
}
|
|
@@ -37,15 +37,6 @@
|
|
|
37
37
|
gap: var(--Prompt-actions-gap, var(--size-8));
|
|
38
38
|
grid-column-start: 2;
|
|
39
39
|
grid-column-end: 3;
|
|
40
|
-
|
|
41
|
-
@media (--screen-xs-max) {
|
|
42
|
-
grid-column: span 2;
|
|
43
|
-
width: 100%;
|
|
44
|
-
|
|
45
|
-
.wds-prompt__content-wrapper--with-dismiss & {
|
|
46
|
-
grid-column: span 3;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
40
|
}
|
|
50
41
|
|
|
51
42
|
&__dismiss {
|
|
File without changes
|
|
@@ -770,7 +770,6 @@ describe('Snackbar swipe dismissal', () => {
|
|
|
770
770
|
|
|
771
771
|
await user.pointer({ keys: '[/MouseLeft]', coords: { clientX: 0, clientY: 200 } });
|
|
772
772
|
|
|
773
|
-
expect(capture.releasePointerCapture).toHaveBeenCalledWith(1);
|
|
774
773
|
expect(snackbarProps.onDismissRequest).toHaveBeenCalledTimes(1);
|
|
775
774
|
expect(container).toHaveStyle({ transform: 'translateY(200px)' });
|
|
776
775
|
});
|
|
@@ -892,7 +891,7 @@ describe('Snackbar swipe dismissal', () => {
|
|
|
892
891
|
expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
|
|
893
892
|
});
|
|
894
893
|
|
|
895
|
-
it.each(['pointercancel'
|
|
894
|
+
it.each(['pointercancel'])('restores the position on %s', async (type) => {
|
|
896
895
|
const { surface, container, snackbarProps } = setupSwipe();
|
|
897
896
|
mockPointerCapture(surface);
|
|
898
897
|
await user.pointer([
|
|
@@ -911,59 +910,6 @@ describe('Snackbar swipe dismissal', () => {
|
|
|
911
910
|
expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
|
|
912
911
|
});
|
|
913
912
|
|
|
914
|
-
it('recovers when a captured child is removed and capture loss fires on its document', async () => {
|
|
915
|
-
const { surface, container, rerender, snackbarProps } = setupSwipe({
|
|
916
|
-
media: <span>Drag me</span>,
|
|
917
|
-
});
|
|
918
|
-
const child = screen.getByText('Drag me');
|
|
919
|
-
mockPointerCapture(child);
|
|
920
|
-
await user.pointer([
|
|
921
|
-
{ keys: '[MouseLeft>]', target: child, coords: { clientX: 0, clientY: 0 } },
|
|
922
|
-
{ coords: { clientX: 0, clientY: 30 } },
|
|
923
|
-
]);
|
|
924
|
-
expect(container).toHaveStyle({ transform: 'translateY(30px)' });
|
|
925
|
-
|
|
926
|
-
// An unrelated pointer losing capture must not cancel the active gesture.
|
|
927
|
-
const unrelatedLoss = new Event('lostpointercapture', { bubbles: true });
|
|
928
|
-
Object.defineProperty(unrelatedLoss, 'pointerId', { value: 2 });
|
|
929
|
-
fireEvent(surface.ownerDocument, unrelatedLoss);
|
|
930
|
-
expect(container).toHaveStyle({ transform: 'translateY(30px)' });
|
|
931
|
-
|
|
932
|
-
rerender(<Snackbar {...snackbarProps} media={undefined} />);
|
|
933
|
-
expect(child).not.toBeInTheDocument();
|
|
934
|
-
const captureLoss = new Event('lostpointercapture', { bubbles: true });
|
|
935
|
-
Object.defineProperty(captureLoss, 'pointerId', { value: 1 });
|
|
936
|
-
fireEvent(surface.ownerDocument, captureLoss);
|
|
937
|
-
|
|
938
|
-
expect(container).toHaveStyle({ transform: '' });
|
|
939
|
-
expect(container).toHaveClass('wds-Snackbar--swipe-settle');
|
|
940
|
-
expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
|
|
941
|
-
await user.pointer({ keys: '[/MouseLeft]', target: document.body });
|
|
942
|
-
await user.pointer([
|
|
943
|
-
{ keys: '[MouseLeft>]', target: surface, coords: { clientX: 0, clientY: 0 } },
|
|
944
|
-
{ coords: { clientX: 0, clientY: 50 } },
|
|
945
|
-
'[/MouseLeft]',
|
|
946
|
-
]);
|
|
947
|
-
expect(snackbarProps.onDismissRequest).toHaveBeenCalledTimes(1);
|
|
948
|
-
});
|
|
949
|
-
|
|
950
|
-
it('removes its document capture-loss listener on unmount', () => {
|
|
951
|
-
const addListener = jest.spyOn(document, 'addEventListener');
|
|
952
|
-
const removeListener = jest.spyOn(document, 'removeEventListener');
|
|
953
|
-
try {
|
|
954
|
-
const { unmount } = setupSwipe();
|
|
955
|
-
const listener = addListener.mock.calls.find(([type]) => type === 'lostpointercapture')?.[1];
|
|
956
|
-
expect(listener).toEqual(expect.any(Function));
|
|
957
|
-
|
|
958
|
-
unmount();
|
|
959
|
-
|
|
960
|
-
expect(removeListener).toHaveBeenCalledWith('lostpointercapture', listener);
|
|
961
|
-
} finally {
|
|
962
|
-
addListener.mockRestore();
|
|
963
|
-
removeListener.mockRestore();
|
|
964
|
-
}
|
|
965
|
-
});
|
|
966
|
-
|
|
967
913
|
it('ignores secondary pointers while retaining the primary gesture', async () => {
|
|
968
914
|
const { surface, container, snackbarProps } = setupSwipe();
|
|
969
915
|
const capture = mockPointerCapture(surface);
|
|
@@ -995,20 +941,6 @@ describe('Snackbar swipe dismissal', () => {
|
|
|
995
941
|
expect(snackbarProps.onDismissRequest).not.toHaveBeenCalled();
|
|
996
942
|
});
|
|
997
943
|
|
|
998
|
-
it('clears the drag state after the exit finishes', async () => {
|
|
999
|
-
const { surface, container, rerender, snackbarProps } = setupSwipe();
|
|
1000
|
-
await user.pointer([
|
|
1001
|
-
{ keys: '[MouseLeft>]', target: surface, coords: { clientX: 0, clientY: 0 } },
|
|
1002
|
-
{ coords: { clientX: 0, clientY: 50 } },
|
|
1003
|
-
'[/MouseLeft]',
|
|
1004
|
-
]);
|
|
1005
|
-
rerender(<Snackbar {...snackbarProps} visible={false} />);
|
|
1006
|
-
advanceTimers(SNACKBAR_EXIT_DURATION);
|
|
1007
|
-
expect(container).toHaveStyle({ transform: '' });
|
|
1008
|
-
expect(container).not.toHaveClass('wds-Snackbar--swipe-dismiss');
|
|
1009
|
-
expect(snackbarProps.onExited).toHaveBeenCalledTimes(1);
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
944
|
it('keeps dragging across a render and uses the latest dismissal callback', async () => {
|
|
1013
945
|
const { surface, container, rerender, snackbarProps } = setupSwipe();
|
|
1014
946
|
await user.pointer([
|
|
@@ -11,6 +11,7 @@ import { PrimitivePrompt } from '../PrimitivePrompt';
|
|
|
11
11
|
import ProcessIndicator from '../../ProcessIndicator';
|
|
12
12
|
import type { Sentiment } from '../../SentimentSurface';
|
|
13
13
|
import StatusIcon from '../../StatusIcon';
|
|
14
|
+
import withNextPortal from '../../WithNextPortal/WithNextPortal';
|
|
14
15
|
|
|
15
16
|
import { SNACKBAR_ENTER_DURATION, SNACKBAR_EXIT_DURATION } from './constants';
|
|
16
17
|
import messages from './Snackbar.messages';
|
|
@@ -105,14 +106,14 @@ export const Snackbar = ({
|
|
|
105
106
|
visible,
|
|
106
107
|
});
|
|
107
108
|
const {
|
|
108
|
-
|
|
109
|
+
cancelSwipe,
|
|
109
110
|
containerRef,
|
|
110
111
|
handleClickCapture,
|
|
111
112
|
handlePointerCancel,
|
|
112
113
|
handlePointerDown,
|
|
113
114
|
handlePointerMove,
|
|
114
115
|
handlePointerUp,
|
|
115
|
-
} = useSnackbarSwipeDismiss({ onDismissRequest, onSwipeChange: setSwiping
|
|
116
|
+
} = useSnackbarSwipeDismiss({ onDismissRequest, onSwipeChange: setSwiping });
|
|
116
117
|
|
|
117
118
|
useEffect(() => {
|
|
118
119
|
if (!visible) {
|
|
@@ -187,10 +188,8 @@ export const Snackbar = ({
|
|
|
187
188
|
}}
|
|
188
189
|
unmountOnExit
|
|
189
190
|
onEntered={handleEntered}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
onExited();
|
|
193
|
-
}}
|
|
191
|
+
onExit={cancelSwipe}
|
|
192
|
+
onExited={onExited}
|
|
194
193
|
>
|
|
195
194
|
<PrimitivePrompt
|
|
196
195
|
ref={surfaceRef}
|
|
@@ -242,4 +241,4 @@ export const Snackbar = ({
|
|
|
242
241
|
);
|
|
243
242
|
};
|
|
244
243
|
|
|
245
|
-
export default Snackbar;
|
|
244
|
+
export default withNextPortal(Snackbar);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import Snackbar from './Snackbar';
|
|
4
4
|
import { SnackbarContext } from './SnackbarContext';
|
|
5
5
|
import useSnackbarManager from './useSnackbarManager';
|
|
6
6
|
|
|
@@ -24,7 +24,7 @@ export default function SnackbarProvider({ timeout, children }: SnackbarProvider
|
|
|
24
24
|
return (
|
|
25
25
|
<SnackbarContext.Provider value={contextValue}>
|
|
26
26
|
{active ? (
|
|
27
|
-
<
|
|
27
|
+
<Snackbar
|
|
28
28
|
// Each instance gets a fresh appear transition and live-region announcement.
|
|
29
29
|
key={active.id}
|
|
30
30
|
{...active.props}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
import { SNACKBAR_SWIPE_DISMISS_THRESHOLD } from './constants';
|
|
4
4
|
|
|
@@ -14,47 +14,42 @@ type SwipePointer = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
* Release dismisses at half the surface height; shorter
|
|
19
|
-
*
|
|
20
|
-
* follow-up click so dragging from the action cannot activate it.
|
|
17
|
+
* Follows one primary pointer's downward, mostly vertical movement without re-rendering.
|
|
18
|
+
* Release dismisses at half the surface height; shorter or cancelled gestures settle back.
|
|
19
|
+
* A drag consumes its follow-up click, so dragging from the action cannot activate it.
|
|
21
20
|
*/
|
|
22
21
|
const useSnackbarSwipeDismiss = ({
|
|
23
22
|
onDismissRequest,
|
|
24
23
|
onSwipeChange,
|
|
25
|
-
visible,
|
|
26
24
|
}: {
|
|
27
25
|
onDismissRequest: () => void;
|
|
28
26
|
/** Reports when a gesture starts and ends so auto-dismiss can pause beneath the pointer. */
|
|
29
27
|
onSwipeChange: (swiping: boolean) => void;
|
|
30
|
-
visible: boolean;
|
|
31
28
|
}) => {
|
|
32
29
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
33
30
|
const pointerRef = useRef<SwipePointer | null>(null);
|
|
34
31
|
const suppressClick = useRef(false);
|
|
35
32
|
|
|
36
|
-
const
|
|
37
|
-
const pointer = pointerRef.current;
|
|
33
|
+
const endGesture = () => {
|
|
38
34
|
pointerRef.current = null;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
suppressClick.current = false;
|
|
46
|
-
containerRef.current?.classList.remove(DISMISS_CLASS, SETTLE_CLASS);
|
|
35
|
+
onSwipeChange(false);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const settle = () => {
|
|
39
|
+
containerRef.current?.classList.add(SETTLE_CLASS);
|
|
47
40
|
containerRef.current?.style.removeProperty('transform');
|
|
48
|
-
}
|
|
41
|
+
};
|
|
49
42
|
|
|
50
43
|
const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
51
44
|
if (event.button !== 0 || !event.isPrimary || pointerRef.current) {
|
|
52
45
|
return;
|
|
53
46
|
}
|
|
54
47
|
|
|
55
|
-
clearSwipePosition();
|
|
56
48
|
const target = event.target as Element;
|
|
49
|
+
// Keeps move/up events coming when a mouse leaves the Snackbar mid-drag.
|
|
57
50
|
target.setPointerCapture?.(event.pointerId);
|
|
51
|
+
containerRef.current?.classList.remove(DISMISS_CLASS, SETTLE_CLASS);
|
|
52
|
+
suppressClick.current = false;
|
|
58
53
|
pointerRef.current = {
|
|
59
54
|
id: event.pointerId,
|
|
60
55
|
target,
|
|
@@ -86,13 +81,12 @@ const useSnackbarSwipeDismiss = ({
|
|
|
86
81
|
return;
|
|
87
82
|
}
|
|
88
83
|
|
|
84
|
+
endGesture();
|
|
89
85
|
const offsetY = event.clientY - pointer.startY;
|
|
90
86
|
const offsetX = event.clientX - pointer.startX;
|
|
91
87
|
const container = containerRef.current;
|
|
92
|
-
const bounds = pointer.target.closest('a, button')?.getBoundingClientRect();
|
|
93
|
-
clearSwipePosition();
|
|
94
|
-
|
|
95
88
|
if (offsetY >= pointer.threshold && offsetY > Math.abs(offsetX)) {
|
|
89
|
+
suppressClick.current = true;
|
|
96
90
|
if (container) {
|
|
97
91
|
// Include wrapper padding and the safe area, not only the surface, to clear the viewport.
|
|
98
92
|
container.classList.add(DISMISS_CLASS);
|
|
@@ -101,10 +95,11 @@ const useSnackbarSwipeDismiss = ({
|
|
|
101
95
|
`translateY(${Math.max(offsetY, container.offsetHeight)}px)`,
|
|
102
96
|
);
|
|
103
97
|
}
|
|
104
|
-
suppressClick.current = true;
|
|
105
98
|
onDismissRequest();
|
|
106
99
|
} else {
|
|
107
|
-
// Capture retargets
|
|
100
|
+
// Capture retargets the click to the pressed control even when released outside it,
|
|
101
|
+
// unlike a native button; cancel it in that case.
|
|
102
|
+
const bounds = pointer.target.closest('a, button')?.getBoundingClientRect();
|
|
108
103
|
suppressClick.current =
|
|
109
104
|
!!bounds &&
|
|
110
105
|
(offsetX !== 0 || offsetY !== 0) &&
|
|
@@ -112,40 +107,30 @@ const useSnackbarSwipeDismiss = ({
|
|
|
112
107
|
event.clientX > bounds.right ||
|
|
113
108
|
event.clientY < bounds.top ||
|
|
114
109
|
event.clientY > bounds.bottom);
|
|
115
|
-
|
|
110
|
+
settle();
|
|
116
111
|
}
|
|
117
112
|
};
|
|
118
113
|
|
|
119
|
-
const handlePointerCancel =
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
const handlePointerCancel = (event: React.PointerEvent<HTMLDivElement>) => {
|
|
115
|
+
if (pointerRef.current?.id !== event.pointerId) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
endGesture();
|
|
120
|
+
settle();
|
|
121
|
+
};
|
|
124
122
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
useEffect(() => {
|
|
132
|
-
if (visible) {
|
|
133
|
-
clearSwipePosition();
|
|
134
|
-
} else if (pointerRef.current) {
|
|
135
|
-
// An exit starting mid-gesture (timeout, Escape, replacement) ends it without dismissing again.
|
|
136
|
-
handlePointerCancel({ pointerId: pointerRef.current.id });
|
|
123
|
+
/** Ends a gesture still in progress when the Snackbar starts exiting for another reason. */
|
|
124
|
+
const cancelSwipe = () => {
|
|
125
|
+
const pointer = pointerRef.current;
|
|
126
|
+
if (!pointer) {
|
|
127
|
+
return;
|
|
137
128
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
ownerDocument?.addEventListener('lostpointercapture', handlePointerCancel);
|
|
144
|
-
return () => {
|
|
145
|
-
ownerDocument?.removeEventListener('lostpointercapture', handlePointerCancel);
|
|
146
|
-
clearSwipePosition();
|
|
147
|
-
};
|
|
148
|
-
}, [clearSwipePosition, handlePointerCancel]);
|
|
129
|
+
|
|
130
|
+
pointer.target.releasePointerCapture?.(pointer.id);
|
|
131
|
+
endGesture();
|
|
132
|
+
settle();
|
|
133
|
+
};
|
|
149
134
|
|
|
150
135
|
const handleClickCapture = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
151
136
|
if (suppressClick.current && event.detail > 0) {
|
|
@@ -156,7 +141,7 @@ const useSnackbarSwipeDismiss = ({
|
|
|
156
141
|
};
|
|
157
142
|
|
|
158
143
|
return {
|
|
159
|
-
|
|
144
|
+
cancelSwipe,
|
|
160
145
|
containerRef,
|
|
161
146
|
handleClickCapture,
|
|
162
147
|
handlePointerCancel,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IntlProvider, ResolvedIntlConfig } from 'react-intl';
|
|
2
2
|
|
|
3
|
-
import { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common';
|
|
3
|
+
import { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common/Locale';
|
|
4
4
|
import en from '../i18n/en.json';
|
|
5
5
|
|
|
6
6
|
import { DirectionProvider } from './Direction';
|
|
@@ -5,13 +5,11 @@ import WithDisplayFormat from '.';
|
|
|
5
5
|
|
|
6
6
|
const user = userEvent;
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
render(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/>,
|
|
14
|
-
);
|
|
8
|
+
const renderInput = (props) => (
|
|
9
|
+
<WithDisplayFormat {...props} render={(renderProps) => <Input {...renderProps} name="input" />} />
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const setup = (props) => render(renderInput(props));
|
|
15
13
|
|
|
16
14
|
describe('InputWithTextFormat (React Testing Library)', () => {
|
|
17
15
|
const initialProps = {
|
|
@@ -26,6 +24,91 @@ describe('InputWithTextFormat (React Testing Library)', () => {
|
|
|
26
24
|
jest.clearAllMocks();
|
|
27
25
|
});
|
|
28
26
|
|
|
27
|
+
it('updates the displayed value when the value prop changes', () => {
|
|
28
|
+
const { rerender } = setup({ ...initialProps, value: '123' });
|
|
29
|
+
|
|
30
|
+
expect(screen.getByRole('textbox')).toHaveValue('12-3');
|
|
31
|
+
|
|
32
|
+
rerender(renderInput({ ...initialProps, value: '456' }));
|
|
33
|
+
|
|
34
|
+
expect(screen.getByRole('textbox')).toHaveValue('45-6');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('preserves the current value and resets undo history when the pattern changes', async () => {
|
|
38
|
+
const props = { ...initialProps, displayPattern: '**-**' };
|
|
39
|
+
const { rerender } = setup(props);
|
|
40
|
+
const input = screen.getByRole('textbox');
|
|
41
|
+
|
|
42
|
+
await user.type(input, '123');
|
|
43
|
+
rerender(renderInput({ ...props, displayPattern: '**/**' }));
|
|
44
|
+
|
|
45
|
+
expect(input).toHaveValue('12/3');
|
|
46
|
+
await user.keyboard('{Control>}z{/Control}');
|
|
47
|
+
expect(input).toHaveValue('12/3');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('uses the incoming value when the value and pattern change together', () => {
|
|
51
|
+
const props = { ...initialProps, value: '123', displayPattern: '**-**' };
|
|
52
|
+
const { rerender } = setup(props);
|
|
53
|
+
|
|
54
|
+
rerender(renderInput({ ...props, value: '4567', displayPattern: '**/**' }));
|
|
55
|
+
|
|
56
|
+
expect(screen.getByRole('textbox')).toHaveValue('45/67');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('resets undo history when the value prop changes externally', async () => {
|
|
60
|
+
const props = { ...initialProps, displayPattern: '**-**' };
|
|
61
|
+
const { rerender } = setup(props);
|
|
62
|
+
const input = screen.getByRole('textbox');
|
|
63
|
+
|
|
64
|
+
await user.type(input, '123');
|
|
65
|
+
rerender(renderInput({ ...props, value: '456' }));
|
|
66
|
+
|
|
67
|
+
expect(input).toHaveValue('45-6');
|
|
68
|
+
await user.keyboard('{Control>}z{/Control}');
|
|
69
|
+
expect(input).toHaveValue('45-6');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('preserves undo history when the parent echoes an onChange value', async () => {
|
|
73
|
+
const ControlledInput = () => {
|
|
74
|
+
const [value, setValue] = React.useState('');
|
|
75
|
+
return renderInput({ ...initialProps, value, displayPattern: '***', onChange: setValue });
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
render(<ControlledInput />);
|
|
79
|
+
const input = screen.getByRole('textbox');
|
|
80
|
+
|
|
81
|
+
await user.type(input, '123');
|
|
82
|
+
await user.keyboard('{Control>}z{/Control}');
|
|
83
|
+
|
|
84
|
+
expect(input).toHaveValue('12');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('reformats a pasted value when the parent removes spaces from the onChange value', async () => {
|
|
88
|
+
const ControlledInput = () => {
|
|
89
|
+
const [value, setValue] = React.useState('');
|
|
90
|
+
|
|
91
|
+
const handleChange = (nextValue) => {
|
|
92
|
+
setValue(nextValue.replaceAll(' ', ''));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return renderInput({
|
|
96
|
+
...initialProps,
|
|
97
|
+
value,
|
|
98
|
+
displayPattern: '**-**-**',
|
|
99
|
+
onChange: handleChange,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
render(<ControlledInput />);
|
|
104
|
+
const input = screen.getByRole('textbox');
|
|
105
|
+
|
|
106
|
+
await user.click(input);
|
|
107
|
+
await user.paste('00 00 00');
|
|
108
|
+
|
|
109
|
+
await waitFor(() => expect(input).toHaveValue('00-00-00'));
|
|
110
|
+
});
|
|
111
|
+
|
|
29
112
|
[
|
|
30
113
|
{ value: '123', expectedValue: '12-3', displayPattern: '**-**-**' },
|
|
31
114
|
{ value: '1234', expectedValue: '12-34', displayPattern: '**-**-**' },
|