@transferwise/components 46.167.0 → 46.168.0
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/README.md +1 -1
- package/build/Link/Link.js.map +1 -1
- package/build/Link/Link.mjs.map +1 -1
- package/build/Loader/Loader.js.map +1 -1
- package/build/Loader/Loader.mjs.map +1 -1
- package/build/Prompt/PrimitivePrompt/PrimitivePrompt.js +2 -1
- package/build/Prompt/PrimitivePrompt/PrimitivePrompt.js.map +1 -1
- package/build/Prompt/PrimitivePrompt/PrimitivePrompt.mjs +2 -1
- package/build/Prompt/PrimitivePrompt/PrimitivePrompt.mjs.map +1 -1
- package/build/Prompt/Snackbar/Snackbar.js +205 -0
- package/build/Prompt/Snackbar/Snackbar.js.map +1 -0
- package/build/Prompt/Snackbar/Snackbar.messages.js +14 -0
- package/build/Prompt/Snackbar/Snackbar.messages.js.map +1 -0
- package/build/Prompt/Snackbar/Snackbar.messages.mjs +10 -0
- package/build/Prompt/Snackbar/Snackbar.messages.mjs.map +1 -0
- package/build/Prompt/Snackbar/Snackbar.mjs +203 -0
- package/build/Prompt/Snackbar/Snackbar.mjs.map +1 -0
- package/build/Prompt/Snackbar/SnackbarContext.js.map +1 -0
- package/build/Prompt/Snackbar/SnackbarContext.mjs.map +1 -0
- package/build/Prompt/Snackbar/SnackbarPortal.js +12 -0
- package/build/Prompt/Snackbar/SnackbarPortal.js.map +1 -0
- package/build/Prompt/Snackbar/SnackbarPortal.mjs +8 -0
- package/build/Prompt/Snackbar/SnackbarPortal.mjs.map +1 -0
- package/build/Prompt/Snackbar/SnackbarProvider.js +42 -0
- package/build/Prompt/Snackbar/SnackbarProvider.js.map +1 -0
- package/build/Prompt/Snackbar/SnackbarProvider.mjs +38 -0
- package/build/Prompt/Snackbar/SnackbarProvider.mjs.map +1 -0
- package/build/Prompt/Snackbar/constants.js +17 -0
- package/build/Prompt/Snackbar/constants.js.map +1 -0
- package/build/Prompt/Snackbar/constants.mjs +11 -0
- package/build/Prompt/Snackbar/constants.mjs.map +1 -0
- package/build/Prompt/Snackbar/useSnackbar.js.map +1 -0
- package/build/Prompt/Snackbar/useSnackbar.mjs.map +1 -0
- package/build/Prompt/Snackbar/useSnackbarAutoDismiss.js +66 -0
- package/build/Prompt/Snackbar/useSnackbarAutoDismiss.js.map +1 -0
- package/build/Prompt/Snackbar/useSnackbarAutoDismiss.mjs +62 -0
- package/build/Prompt/Snackbar/useSnackbarAutoDismiss.mjs.map +1 -0
- package/build/Prompt/Snackbar/useSnackbarManager.js +153 -0
- package/build/Prompt/Snackbar/useSnackbarManager.js.map +1 -0
- package/build/Prompt/Snackbar/useSnackbarManager.mjs +149 -0
- package/build/Prompt/Snackbar/useSnackbarManager.mjs.map +1 -0
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.js +135 -0
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.js.map +1 -0
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.mjs +131 -0
- package/build/Prompt/Snackbar/useSnackbarSwipeDismiss.mjs.map +1 -0
- package/build/Section/Section.js.map +1 -1
- package/build/Section/Section.mjs.map +1 -1
- package/build/_deprecated/Select/Select.js +1 -1
- package/build/_deprecated/Select/Select.js.map +1 -1
- package/build/_deprecated/Select/Select.mjs +1 -1
- package/build/_deprecated/Select/Select.mjs.map +1 -1
- package/build/common/BottomSheet/BottomSheet.js +1 -3
- package/build/common/BottomSheet/BottomSheet.js.map +1 -1
- package/build/common/BottomSheet/BottomSheet.mjs +1 -3
- package/build/common/BottomSheet/BottomSheet.mjs.map +1 -1
- package/build/i18n/en.json +1 -0
- package/build/i18n/en.json.js +1 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +1 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/index.js +3 -3
- package/build/index.mjs +3 -3
- package/build/main.css +137 -75
- package/build/styles/IconButton/IconButton.css +3 -4
- package/build/styles/Prompt/Snackbar/Snackbar.css +134 -0
- package/build/styles/main.css +137 -75
- package/build/types/Link/Link.d.ts +1 -1
- package/build/types/Loader/Loader.d.ts +1 -1
- package/build/types/Prompt/PrimitivePrompt/PrimitivePrompt.d.ts +11 -0
- package/build/types/Prompt/PrimitivePrompt/PrimitivePrompt.d.ts.map +1 -1
- package/build/types/Prompt/Snackbar/Snackbar.d.ts +62 -0
- package/build/types/Prompt/Snackbar/Snackbar.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/Snackbar.messages.d.ts +9 -0
- package/build/types/Prompt/Snackbar/Snackbar.messages.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/Snackbar.types.d.ts +12 -0
- package/build/types/Prompt/Snackbar/Snackbar.types.d.ts.map +1 -0
- package/build/types/{Snackbar → Prompt/Snackbar}/SnackbarContext.d.ts +2 -2
- package/build/types/Prompt/Snackbar/SnackbarContext.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/SnackbarPortal.d.ts +4 -0
- package/build/types/Prompt/Snackbar/SnackbarPortal.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/SnackbarProvider.d.ts +13 -0
- package/build/types/Prompt/Snackbar/SnackbarProvider.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/constants.d.ts +9 -0
- package/build/types/Prompt/Snackbar/constants.d.ts.map +1 -0
- package/build/types/{Snackbar → Prompt/Snackbar}/index.d.ts +1 -1
- package/build/types/Prompt/Snackbar/index.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/useSnackbar.d.ts +3 -0
- package/build/types/Prompt/Snackbar/useSnackbar.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/useSnackbarAutoDismiss.d.ts +13 -0
- package/build/types/Prompt/Snackbar/useSnackbarAutoDismiss.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/useSnackbarManager.d.ts +20 -0
- package/build/types/Prompt/Snackbar/useSnackbarManager.d.ts.map +1 -0
- package/build/types/Prompt/Snackbar/useSnackbarSwipeDismiss.d.ts +22 -0
- package/build/types/Prompt/Snackbar/useSnackbarSwipeDismiss.d.ts.map +1 -0
- package/build/types/Section/Section.d.ts +1 -1
- package/build/types/_deprecated/Select/Select.d.ts +1 -1
- package/build/types/common/BottomSheet/BottomSheet.d.ts +1 -3
- package/build/types/common/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/build/types/index.d.ts +5 -5
- package/build/types/index.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +2 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/IconButton/IconButton.css +3 -4
- package/src/IconButton/IconButton.less +14 -1
- package/src/Link/Link.tsx +1 -1
- package/src/ListItem/AdditionalInfo/_stories/ListItemAdditionalInfo.story.tsx +1 -1
- package/src/ListItem/AvatarView/_stories/ListItemAvatarView.story.tsx +3 -3
- package/src/ListItem/_stories/ListItem.disabled.story.tsx +1 -1
- package/src/ListItem/_stories/ListItem.scenarios.story.tsx +2 -2
- package/src/Loader/Loader.tsx +1 -1
- package/src/Prompt/PrimitivePrompt/PrimitivePrompt.test.tsx +24 -1
- package/src/Prompt/PrimitivePrompt/PrimitivePrompt.tsx +8 -2
- package/src/Prompt/Snackbar/Snackbar.css +134 -0
- package/src/Prompt/Snackbar/Snackbar.less +159 -0
- package/src/Prompt/Snackbar/Snackbar.messages.ts +9 -0
- package/src/Prompt/Snackbar/Snackbar.test.tsx +1079 -0
- package/src/Prompt/Snackbar/Snackbar.tsx +245 -0
- package/src/Prompt/Snackbar/Snackbar.types.ts +17 -0
- package/src/{Snackbar → Prompt/Snackbar}/SnackbarContext.ts +2 -2
- package/src/Prompt/Snackbar/SnackbarPortal.tsx +8 -0
- package/src/Prompt/Snackbar/SnackbarProvider.test.tsx +783 -0
- package/src/Prompt/Snackbar/SnackbarProvider.tsx +41 -0
- package/src/Prompt/Snackbar/_stories/Snackbar.accessibility.docs.mdx +58 -0
- package/src/{Snackbar → Prompt/Snackbar}/_stories/Snackbar.rtl.test.story.tsx +17 -9
- package/src/Prompt/Snackbar/_stories/Snackbar.story.tsx +416 -0
- package/src/Prompt/Snackbar/_stories/Snackbar.test.story.tsx +263 -0
- package/src/Prompt/Snackbar/constants.ts +10 -0
- package/src/{Snackbar → Prompt/Snackbar}/index.ts +1 -1
- package/src/Prompt/Snackbar/useSnackbarAutoDismiss.ts +74 -0
- package/src/Prompt/Snackbar/useSnackbarManager.ts +169 -0
- package/src/Prompt/Snackbar/useSnackbarSwipeDismiss.ts +169 -0
- package/src/Section/Section.tsx +1 -1
- package/src/_deprecated/Select/Select.tsx +1 -1
- package/src/_deprecated/Select/_stories/Select.story.tsx +1 -1
- package/src/common/BottomSheet/BottomSheet.tsx +1 -3
- package/src/i18n/en.json +1 -0
- package/src/index.ts +5 -5
- package/src/main.css +137 -75
- package/src/main.less +1 -1
- package/build/Snackbar/Snackbar.js +0 -128
- package/build/Snackbar/Snackbar.js.map +0 -1
- package/build/Snackbar/Snackbar.mjs +0 -123
- package/build/Snackbar/Snackbar.mjs.map +0 -1
- package/build/Snackbar/SnackbarContext.js.map +0 -1
- package/build/Snackbar/SnackbarContext.mjs.map +0 -1
- package/build/Snackbar/SnackbarProvider.js +0 -46
- package/build/Snackbar/SnackbarProvider.js.map +0 -1
- package/build/Snackbar/SnackbarProvider.mjs +0 -42
- package/build/Snackbar/SnackbarProvider.mjs.map +0 -1
- package/build/Snackbar/useSnackbar.js.map +0 -1
- package/build/Snackbar/useSnackbar.mjs.map +0 -1
- package/build/styles/Snackbar/Snackbar.css +0 -71
- package/build/types/Snackbar/Snackbar.d.ts +0 -16
- package/build/types/Snackbar/Snackbar.d.ts.map +0 -1
- package/build/types/Snackbar/SnackbarContext.d.ts.map +0 -1
- package/build/types/Snackbar/SnackbarProvider.d.ts +0 -6
- package/build/types/Snackbar/SnackbarProvider.d.ts.map +0 -1
- package/build/types/Snackbar/index.d.ts.map +0 -1
- package/build/types/Snackbar/useSnackbar.d.ts +0 -3
- package/build/types/Snackbar/useSnackbar.d.ts.map +0 -1
- package/src/Snackbar/Snackbar.css +0 -71
- package/src/Snackbar/Snackbar.less +0 -80
- package/src/Snackbar/Snackbar.test.tsx +0 -206
- package/src/Snackbar/Snackbar.tsx +0 -129
- package/src/Snackbar/SnackbarProvider.tsx +0 -33
- package/src/Snackbar/_stories/Snackbar.story.tsx +0 -89
- package/src/Snackbar/_stories/Snackbar.test.story.tsx +0 -139
- /package/build/{Snackbar → Prompt/Snackbar}/SnackbarContext.js +0 -0
- /package/build/{Snackbar → Prompt/Snackbar}/SnackbarContext.mjs +0 -0
- /package/build/{Snackbar → Prompt/Snackbar}/useSnackbar.js +0 -0
- /package/build/{Snackbar → Prompt/Snackbar}/useSnackbar.mjs +0 -0
- /package/src/{Snackbar → Prompt/Snackbar}/useSnackbar.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnackbarProvider.js","sources":["../../src/Snackbar/SnackbarProvider.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\n\nimport SnackbarPortal, { SnackbarProps } from './Snackbar';\nimport { SnackbarContext } from './SnackbarContext';\n\nexport interface SnackbarProviderProps {\n timeout?: number;\n children?: React.ReactNode;\n}\n\nexport default function SnackbarProvider({ timeout = 4500, children }: SnackbarProviderProps) {\n const [state, setState] = useState<Omit<SnackbarProps, 'timeout'>>({\n text: '',\n timestamp: 0,\n });\n const { action, text, timestamp } = state;\n\n return (\n <SnackbarContext.Provider\n value={useMemo(\n () => ({\n createSnackbar: ({ action, text }) => {\n setState({ action, text, timestamp: Date.now() });\n },\n }),\n [],\n )}\n >\n <SnackbarPortal action={action} text={text} timestamp={timestamp} timeout={timeout} />\n {children}\n </SnackbarContext.Provider>\n );\n}\n"],"names":["SnackbarProvider","timeout","children","state","setState","useState","text","timestamp","action","_jsxs","SnackbarContext","Provider","value","useMemo","createSnackbar","Date","now","_jsx","SnackbarPortal"],"mappings":";;;;;;;;;AAUc,SAAUA,gBAAgBA,CAAC;AAAEC,EAAAA,OAAO,GAAG,IAAI;AAAEC,EAAAA;AAAQ,CAAyB,EAAA;AAC1F,EAAA,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAQ,CAAiC;AACjEC,IAAAA,IAAI,EAAE,EAAE;AACRC,IAAAA,SAAS,EAAE;AACZ,GAAA,CAAC;EACF,MAAM;IAAEC,MAAM;IAAEF,IAAI;AAAEC,IAAAA;AAAS,GAAE,GAAGJ,KAAK;AAEzC,EAAA,oBACEM,eAAA,CAACC,+BAAe,CAACC,QAAQ,EAAA;IACvBC,KAAK,EAAEC,aAAO,CACZ,OAAO;AACLC,MAAAA,cAAc,EAAEA,CAAC;QAAEN,MAAM;AAAEF,QAAAA;AAAI,OAAE,KAAI;AACnCF,QAAAA,QAAQ,CAAC;UAAEI,MAAM;UAAEF,IAAI;AAAEC,UAAAA,SAAS,EAAEQ,IAAI,CAACC,GAAG;AAAE,SAAE,CAAC;AACnD,MAAA;KACD,CAAC,EACF,EAAE,CACF;IAAAd,QAAA,EAAA,cAEFe,cAAA,CAACC,gBAAc,EAAA;AAACV,MAAAA,MAAM,EAAEA,MAAO;AAACF,MAAAA,IAAI,EAAEA,IAAK;AAACC,MAAAA,SAAS,EAAEA,SAAU;AAACN,MAAAA,OAAO,EAAEA;KAAQ,CACnF,EAACC,QAAQ;AAAA,GACe,CAAC;AAE/B;;"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useState, useMemo } from 'react';
|
|
2
|
-
import SnackbarPortal from './Snackbar.mjs';
|
|
3
|
-
import { SnackbarContext } from './SnackbarContext.mjs';
|
|
4
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
-
|
|
6
|
-
function SnackbarProvider({
|
|
7
|
-
timeout = 4500,
|
|
8
|
-
children
|
|
9
|
-
}) {
|
|
10
|
-
const [state, setState] = useState({
|
|
11
|
-
text: '',
|
|
12
|
-
timestamp: 0
|
|
13
|
-
});
|
|
14
|
-
const {
|
|
15
|
-
action,
|
|
16
|
-
text,
|
|
17
|
-
timestamp
|
|
18
|
-
} = state;
|
|
19
|
-
return /*#__PURE__*/jsxs(SnackbarContext.Provider, {
|
|
20
|
-
value: useMemo(() => ({
|
|
21
|
-
createSnackbar: ({
|
|
22
|
-
action,
|
|
23
|
-
text
|
|
24
|
-
}) => {
|
|
25
|
-
setState({
|
|
26
|
-
action,
|
|
27
|
-
text,
|
|
28
|
-
timestamp: Date.now()
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}), []),
|
|
32
|
-
children: [/*#__PURE__*/jsx(SnackbarPortal, {
|
|
33
|
-
action: action,
|
|
34
|
-
text: text,
|
|
35
|
-
timestamp: timestamp,
|
|
36
|
-
timeout: timeout
|
|
37
|
-
}), children]
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { SnackbarProvider as default };
|
|
42
|
-
//# sourceMappingURL=SnackbarProvider.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnackbarProvider.mjs","sources":["../../src/Snackbar/SnackbarProvider.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\n\nimport SnackbarPortal, { SnackbarProps } from './Snackbar';\nimport { SnackbarContext } from './SnackbarContext';\n\nexport interface SnackbarProviderProps {\n timeout?: number;\n children?: React.ReactNode;\n}\n\nexport default function SnackbarProvider({ timeout = 4500, children }: SnackbarProviderProps) {\n const [state, setState] = useState<Omit<SnackbarProps, 'timeout'>>({\n text: '',\n timestamp: 0,\n });\n const { action, text, timestamp } = state;\n\n return (\n <SnackbarContext.Provider\n value={useMemo(\n () => ({\n createSnackbar: ({ action, text }) => {\n setState({ action, text, timestamp: Date.now() });\n },\n }),\n [],\n )}\n >\n <SnackbarPortal action={action} text={text} timestamp={timestamp} timeout={timeout} />\n {children}\n </SnackbarContext.Provider>\n );\n}\n"],"names":["SnackbarProvider","timeout","children","state","setState","useState","text","timestamp","action","_jsxs","SnackbarContext","Provider","value","useMemo","createSnackbar","Date","now","_jsx","SnackbarPortal"],"mappings":";;;;;AAUc,SAAUA,gBAAgBA,CAAC;AAAEC,EAAAA,OAAO,GAAG,IAAI;AAAEC,EAAAA;AAAQ,CAAyB,EAAA;AAC1F,EAAA,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGC,QAAQ,CAAiC;AACjEC,IAAAA,IAAI,EAAE,EAAE;AACRC,IAAAA,SAAS,EAAE;AACZ,GAAA,CAAC;EACF,MAAM;IAAEC,MAAM;IAAEF,IAAI;AAAEC,IAAAA;AAAS,GAAE,GAAGJ,KAAK;AAEzC,EAAA,oBACEM,IAAA,CAACC,eAAe,CAACC,QAAQ,EAAA;IACvBC,KAAK,EAAEC,OAAO,CACZ,OAAO;AACLC,MAAAA,cAAc,EAAEA,CAAC;QAAEN,MAAM;AAAEF,QAAAA;AAAI,OAAE,KAAI;AACnCF,QAAAA,QAAQ,CAAC;UAAEI,MAAM;UAAEF,IAAI;AAAEC,UAAAA,SAAS,EAAEQ,IAAI,CAACC,GAAG;AAAE,SAAE,CAAC;AACnD,MAAA;KACD,CAAC,EACF,EAAE,CACF;IAAAd,QAAA,EAAA,cAEFe,GAAA,CAACC,cAAc,EAAA;AAACV,MAAAA,MAAM,EAAEA,MAAO;AAACF,MAAAA,IAAI,EAAEA,IAAK;AAACC,MAAAA,SAAS,EAAEA,SAAU;AAACN,MAAAA,OAAO,EAAEA;KAAQ,CACnF,EAACC,QAAQ;AAAA,GACe,CAAC;AAE/B;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSnackbar.js","sources":["../../src/Snackbar/useSnackbar.ts"],"sourcesContent":["import { useContext } from 'react';\n\nimport { SnackbarContext } from './SnackbarContext';\n\nfunction useSnackbar() {\n const { createSnackbar } = useContext(SnackbarContext);\n\n return createSnackbar;\n}\n\nexport default useSnackbar;\n"],"names":["useSnackbar","createSnackbar","useContext","SnackbarContext"],"mappings":";;;;;;;AAIA,SAASA,WAAWA,GAAA;EAClB,MAAM;AAAEC,IAAAA;AAAc,GAAE,GAAGC,gBAAU,CAACC,+BAAe,CAAC;AAEtD,EAAA,OAAOF,cAAc;AACvB;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSnackbar.mjs","sources":["../../src/Snackbar/useSnackbar.ts"],"sourcesContent":["import { useContext } from 'react';\n\nimport { SnackbarContext } from './SnackbarContext';\n\nfunction useSnackbar() {\n const { createSnackbar } = useContext(SnackbarContext);\n\n return createSnackbar;\n}\n\nexport default useSnackbar;\n"],"names":["useSnackbar","createSnackbar","useContext","SnackbarContext"],"mappings":";;;AAIA,SAASA,WAAWA,GAAA;EAClB,MAAM;AAAEC,IAAAA;AAAc,GAAE,GAAGC,UAAU,CAACC,eAAe,CAAC;AAEtD,EAAA,OAAOF,cAAc;AACvB;;"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
.snackbar {
|
|
2
|
-
text-align: center;
|
|
3
|
-
position: fixed;
|
|
4
|
-
inset-block-end: 0;
|
|
5
|
-
inset-inline-start: 0;
|
|
6
|
-
inset-inline-end: 0;
|
|
7
|
-
z-index: 1060;
|
|
8
|
-
}
|
|
9
|
-
.snackbar__text {
|
|
10
|
-
background: #37517e;
|
|
11
|
-
color: #ffffff;
|
|
12
|
-
display: inline-flex;
|
|
13
|
-
border-radius: 2px;
|
|
14
|
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
|
|
15
|
-
align-items: center;
|
|
16
|
-
justify-content: space-between;
|
|
17
|
-
text-align: start;
|
|
18
|
-
font-size: var(--wds-font-size-body);
|
|
19
|
-
margin-block: 0;
|
|
20
|
-
margin-inline: var(--size-16);
|
|
21
|
-
padding-block: var(--size-8);
|
|
22
|
-
padding-inline: var(--size-16);
|
|
23
|
-
inline-size: calc(100% - var(--size-32));
|
|
24
|
-
transition: 400ms cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
25
|
-
}
|
|
26
|
-
.np-theme-personal .snackbar__text {
|
|
27
|
-
box-shadow: 0 2px 4px 0 rgba(69, 71, 69, 0.35);
|
|
28
|
-
position: relative;
|
|
29
|
-
background: var(--color-contrast-theme);
|
|
30
|
-
border-radius: var(--radius-small);
|
|
31
|
-
color: var(--color-contrast-overlay);
|
|
32
|
-
}
|
|
33
|
-
.np-theme-personal .snackbar__text::after {
|
|
34
|
-
display: block;
|
|
35
|
-
border-radius: inherit;
|
|
36
|
-
block-size: 100%;
|
|
37
|
-
inline-size: 100%;
|
|
38
|
-
content: "";
|
|
39
|
-
position: absolute;
|
|
40
|
-
inset-inline-start: 0;
|
|
41
|
-
inset-block-start: 0;
|
|
42
|
-
z-index: -1;
|
|
43
|
-
background-color: var(--color-background-neutral);
|
|
44
|
-
}
|
|
45
|
-
.np-theme-personal--dark .snackbar__text,
|
|
46
|
-
.np-theme-personal--forest-green .snackbar__text {
|
|
47
|
-
box-shadow: none;
|
|
48
|
-
}
|
|
49
|
-
@media (min-width: 600px) {
|
|
50
|
-
.snackbar__text {
|
|
51
|
-
inline-size: auto;
|
|
52
|
-
max-inline-size: 600px;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
.snackbar__text__action {
|
|
56
|
-
flex-shrink: 0;
|
|
57
|
-
margin-inline-start: var(--size-16);
|
|
58
|
-
}
|
|
59
|
-
.snackbar__text-container-enter,
|
|
60
|
-
.snackbar__text-container-exit {
|
|
61
|
-
transform: translateY(calc(100% + 10px));
|
|
62
|
-
}
|
|
63
|
-
.snackbar__text-container-enter-active {
|
|
64
|
-
transform: translateY(-16px);
|
|
65
|
-
transform: translateY(calc(-16px - env(safe-area-inset-bottom)));
|
|
66
|
-
}
|
|
67
|
-
@media (min-width: 600px) {
|
|
68
|
-
.snackbar__text-container-enter-active {
|
|
69
|
-
transform: translateY(-24px);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ThemeDark, ThemeLight } from '../common';
|
|
2
|
-
export interface SnackbarProps {
|
|
3
|
-
action?: {
|
|
4
|
-
label: string;
|
|
5
|
-
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
6
|
-
};
|
|
7
|
-
text: React.ReactNode;
|
|
8
|
-
/** @deprecated Has no effect. Snackbar theming is based on ThemeProvider. */
|
|
9
|
-
theme?: ThemeLight | ThemeDark;
|
|
10
|
-
timeout: number;
|
|
11
|
-
timestamp: number;
|
|
12
|
-
}
|
|
13
|
-
export declare const Snackbar: (props: SnackbarProps) => import("react").JSX.Element;
|
|
14
|
-
declare const _default: (props: SnackbarProps) => import("react").ReactPortal | null;
|
|
15
|
-
export default _default;
|
|
16
|
-
//# sourceMappingURL=Snackbar.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Snackbar.d.ts","sourceRoot":"","sources":["../../../src/Snackbar/Snackbar.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAKvD,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;KACtD,CAAC;IACF,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;IACtB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,eAAO,MAAM,QAAQ,GAAI,OAAO,aAAa,gCAoG5C,CAAC;;AAEF,wBAAwC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnackbarContext.d.ts","sourceRoot":"","sources":["../../../src/Snackbar/SnackbarContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,cAAc,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,WAAW,CAAC,KAAK,IAAI,CAAC;CAC/E,CAAC;AAEF,eAAO,MAAM,eAAe,8CAAmE,CAAC;AAEhG,eAAO,MAAM,gBAAgB,+CAA2B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnackbarProvider.d.ts","sourceRoot":"","sources":["../../../src/Snackbar/SnackbarProvider.tsx"],"names":[],"mappings":"AAKA,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EAAE,OAAc,EAAE,QAAQ,EAAE,EAAE,qBAAqB,+BAsB3F"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Snackbar/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSnackbar.d.ts","sourceRoot":"","sources":["../../../src/Snackbar/useSnackbar.ts"],"names":[],"mappings":"AAIA,iBAAS,WAAW,uFAInB;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
.snackbar {
|
|
2
|
-
text-align: center;
|
|
3
|
-
position: fixed;
|
|
4
|
-
inset-block-end: 0;
|
|
5
|
-
inset-inline-start: 0;
|
|
6
|
-
inset-inline-end: 0;
|
|
7
|
-
z-index: 1060;
|
|
8
|
-
}
|
|
9
|
-
.snackbar__text {
|
|
10
|
-
background: #37517e;
|
|
11
|
-
color: #ffffff;
|
|
12
|
-
display: inline-flex;
|
|
13
|
-
border-radius: 2px;
|
|
14
|
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
|
|
15
|
-
align-items: center;
|
|
16
|
-
justify-content: space-between;
|
|
17
|
-
text-align: start;
|
|
18
|
-
font-size: var(--wds-font-size-body);
|
|
19
|
-
margin-block: 0;
|
|
20
|
-
margin-inline: var(--size-16);
|
|
21
|
-
padding-block: var(--size-8);
|
|
22
|
-
padding-inline: var(--size-16);
|
|
23
|
-
inline-size: calc(100% - var(--size-32));
|
|
24
|
-
transition: 400ms cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
25
|
-
}
|
|
26
|
-
.np-theme-personal .snackbar__text {
|
|
27
|
-
box-shadow: 0 2px 4px 0 rgba(69, 71, 69, 0.35);
|
|
28
|
-
position: relative;
|
|
29
|
-
background: var(--color-contrast-theme);
|
|
30
|
-
border-radius: var(--radius-small);
|
|
31
|
-
color: var(--color-contrast-overlay);
|
|
32
|
-
}
|
|
33
|
-
.np-theme-personal .snackbar__text::after {
|
|
34
|
-
display: block;
|
|
35
|
-
border-radius: inherit;
|
|
36
|
-
block-size: 100%;
|
|
37
|
-
inline-size: 100%;
|
|
38
|
-
content: "";
|
|
39
|
-
position: absolute;
|
|
40
|
-
inset-inline-start: 0;
|
|
41
|
-
inset-block-start: 0;
|
|
42
|
-
z-index: -1;
|
|
43
|
-
background-color: var(--color-background-neutral);
|
|
44
|
-
}
|
|
45
|
-
.np-theme-personal--dark .snackbar__text,
|
|
46
|
-
.np-theme-personal--forest-green .snackbar__text {
|
|
47
|
-
box-shadow: none;
|
|
48
|
-
}
|
|
49
|
-
@media (min-width: 600px) {
|
|
50
|
-
.snackbar__text {
|
|
51
|
-
inline-size: auto;
|
|
52
|
-
max-inline-size: 600px;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
.snackbar__text__action {
|
|
56
|
-
flex-shrink: 0;
|
|
57
|
-
margin-inline-start: var(--size-16);
|
|
58
|
-
}
|
|
59
|
-
.snackbar__text-container-enter,
|
|
60
|
-
.snackbar__text-container-exit {
|
|
61
|
-
transform: translateY(calc(100% + 10px));
|
|
62
|
-
}
|
|
63
|
-
.snackbar__text-container-enter-active {
|
|
64
|
-
transform: translateY(-16px);
|
|
65
|
-
transform: translateY(calc(-16px - env(safe-area-inset-bottom)));
|
|
66
|
-
}
|
|
67
|
-
@media (min-width: 600px) {
|
|
68
|
-
.snackbar__text-container-enter-active {
|
|
69
|
-
transform: translateY(-24px);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
@import (reference) "./../styles/variables/zindex.less";
|
|
2
|
-
@import (reference) "./../styles/variables/neptune-tokens.less";
|
|
3
|
-
|
|
4
|
-
.snackbar {
|
|
5
|
-
text-align: center;
|
|
6
|
-
position: fixed;
|
|
7
|
-
bottom: 0;
|
|
8
|
-
left: 0;
|
|
9
|
-
|
|
10
|
-
right: 0;
|
|
11
|
-
|
|
12
|
-
z-index: @zindex-mobile-nav;
|
|
13
|
-
|
|
14
|
-
&__text {
|
|
15
|
-
background: @color-navy-background-elevated;
|
|
16
|
-
color: @color-navy-content-primary;
|
|
17
|
-
display: inline-flex;
|
|
18
|
-
border-radius: 2px;
|
|
19
|
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
|
|
20
|
-
align-items: center;
|
|
21
|
-
justify-content: space-between;
|
|
22
|
-
text-align: left;
|
|
23
|
-
|
|
24
|
-
font-size: var(--wds-font-size-body);
|
|
25
|
-
margin: 0 var(--size-16);
|
|
26
|
-
padding: var(--size-8) var(--size-16);
|
|
27
|
-
width: calc(100% - var(--size-32));
|
|
28
|
-
transition: 400ms cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
29
|
-
|
|
30
|
-
.np-theme-personal & {
|
|
31
|
-
box-shadow: 0 2px 4px 0 rgba(69, 71, 69, 0.35);
|
|
32
|
-
position: relative;
|
|
33
|
-
background: var(--color-contrast-theme);
|
|
34
|
-
border-radius: var(--radius-small);
|
|
35
|
-
color: var(--color-contrast-overlay);
|
|
36
|
-
|
|
37
|
-
&::after {
|
|
38
|
-
display: block;
|
|
39
|
-
border-radius: inherit;
|
|
40
|
-
height: 100%;
|
|
41
|
-
width: 100%;
|
|
42
|
-
content: "";
|
|
43
|
-
position: absolute;
|
|
44
|
-
left: 0;
|
|
45
|
-
top: 0;
|
|
46
|
-
z-index: -1;
|
|
47
|
-
background-color: var(--color-background-neutral);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.np-theme-personal--dark &,
|
|
52
|
-
.np-theme-personal--forest-green & {
|
|
53
|
-
box-shadow: none;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@media (--screen-sm) {
|
|
57
|
-
width: auto;
|
|
58
|
-
max-width: 600px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
&__action {
|
|
62
|
-
flex-shrink: 0;
|
|
63
|
-
margin-left: var(--size-16);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
&-container-enter,
|
|
67
|
-
&-container-exit {
|
|
68
|
-
transform: translateY(calc(100% + 10px));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
&-container-enter-active {
|
|
72
|
-
transform: translateY(-16px);
|
|
73
|
-
transform: translateY(calc(-16px - env(safe-area-inset-bottom)));
|
|
74
|
-
|
|
75
|
-
@media (--screen-sm) {
|
|
76
|
-
transform: translateY(-24px);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { act, render, screen, userEvent } from '../test-utils';
|
|
2
|
-
import Button from '../Button';
|
|
3
|
-
|
|
4
|
-
import { Snackbar, type SnackbarProps } from './Snackbar';
|
|
5
|
-
import { SnackbarConsumer } from './SnackbarContext';
|
|
6
|
-
import SnackbarProvider from './SnackbarProvider';
|
|
7
|
-
|
|
8
|
-
const CSS_TRANSITION_DURATION = 400;
|
|
9
|
-
const TIMEOUT = 4000;
|
|
10
|
-
|
|
11
|
-
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTimeAsync });
|
|
12
|
-
|
|
13
|
-
const advanceTimers = (duration: number) => {
|
|
14
|
-
act(() => {
|
|
15
|
-
jest.advanceTimersByTime(duration);
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const renderSnackbar = (props: Partial<SnackbarProps> = {}) =>
|
|
20
|
-
render(<Snackbar text="" timeout={TIMEOUT} timestamp={0} {...props} />);
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
jest.useFakeTimers();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
jest.clearAllTimers();
|
|
28
|
-
jest.useRealTimers();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('Snackbar', () => {
|
|
32
|
-
it('renders the live region wrapper even while no notification is shown', () => {
|
|
33
|
-
renderSnackbar();
|
|
34
|
-
|
|
35
|
-
expect(screen.getByRole('alert')).toHaveAttribute('aria-live', 'assertive');
|
|
36
|
-
expect(screen.getByRole('alert')).toHaveClass('snackbar');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('does not show a notification that is already present on mount', () => {
|
|
40
|
-
renderSnackbar({ text: 'Changes saved', timestamp: 1 });
|
|
41
|
-
|
|
42
|
-
expect(screen.queryByText('Changes saved')).not.toBeInTheDocument();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('shows the notification once text arrives after mount', () => {
|
|
46
|
-
const { rerender } = renderSnackbar();
|
|
47
|
-
|
|
48
|
-
rerender(<Snackbar text="Changes saved" timeout={TIMEOUT} timestamp={1} />);
|
|
49
|
-
|
|
50
|
-
expect(screen.getByText('Changes saved')).toBeInTheDocument();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('renders an action and calls its onClick handler', async () => {
|
|
54
|
-
const onClick = jest.fn();
|
|
55
|
-
const { rerender } = renderSnackbar();
|
|
56
|
-
|
|
57
|
-
rerender(
|
|
58
|
-
<Snackbar
|
|
59
|
-
action={{ label: 'View', onClick }}
|
|
60
|
-
text="Transfer completed"
|
|
61
|
-
timeout={TIMEOUT}
|
|
62
|
-
timestamp={1}
|
|
63
|
-
/>,
|
|
64
|
-
);
|
|
65
|
-
await user.click(screen.getByRole('button', { name: 'View' }));
|
|
66
|
-
|
|
67
|
-
expect(onClick).toHaveBeenCalledTimes(1);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('dismisses the notification once the timeout elapses', () => {
|
|
71
|
-
const { rerender } = renderSnackbar();
|
|
72
|
-
|
|
73
|
-
rerender(<Snackbar text="Changes saved" timeout={TIMEOUT} timestamp={1} />);
|
|
74
|
-
|
|
75
|
-
advanceTimers(TIMEOUT - 1);
|
|
76
|
-
expect(screen.getByText('Changes saved')).toBeInTheDocument();
|
|
77
|
-
|
|
78
|
-
advanceTimers(1);
|
|
79
|
-
advanceTimers(CSS_TRANSITION_DURATION);
|
|
80
|
-
expect(screen.queryByText('Changes saved')).not.toBeInTheDocument();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('exits the current notification before entering the next one', () => {
|
|
84
|
-
const { rerender } = renderSnackbar();
|
|
85
|
-
|
|
86
|
-
rerender(<Snackbar text="First message" timeout={TIMEOUT} timestamp={1} />);
|
|
87
|
-
rerender(<Snackbar text="Second message" timeout={TIMEOUT} timestamp={2} />);
|
|
88
|
-
|
|
89
|
-
advanceTimers(CSS_TRANSITION_DURATION - 1);
|
|
90
|
-
expect(screen.queryByText('Second message')).not.toBeInTheDocument();
|
|
91
|
-
|
|
92
|
-
advanceTimers(1);
|
|
93
|
-
expect(screen.getByText('Second message')).toBeInTheDocument();
|
|
94
|
-
expect(screen.queryByText('First message')).not.toBeInTheDocument();
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('shows the next notification immediately when the previous one has already been dismissed', () => {
|
|
98
|
-
const { rerender } = renderSnackbar();
|
|
99
|
-
|
|
100
|
-
rerender(<Snackbar text="First message" timeout={TIMEOUT} timestamp={1} />);
|
|
101
|
-
advanceTimers(TIMEOUT + CSS_TRANSITION_DURATION);
|
|
102
|
-
|
|
103
|
-
rerender(<Snackbar text="Second message" timeout={TIMEOUT} timestamp={2} />);
|
|
104
|
-
expect(screen.getByText('Second message')).toBeInTheDocument();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('restarts the timeout for a replacing notification', () => {
|
|
108
|
-
const { rerender } = renderSnackbar();
|
|
109
|
-
|
|
110
|
-
rerender(<Snackbar text="First message" timeout={TIMEOUT} timestamp={1} />);
|
|
111
|
-
advanceTimers(TIMEOUT - 100);
|
|
112
|
-
|
|
113
|
-
rerender(<Snackbar text="Second message" timeout={TIMEOUT} timestamp={2} />);
|
|
114
|
-
advanceTimers(CSS_TRANSITION_DURATION);
|
|
115
|
-
expect(screen.getByText('Second message')).toBeInTheDocument();
|
|
116
|
-
|
|
117
|
-
advanceTimers(TIMEOUT - 1);
|
|
118
|
-
expect(screen.getByText('Second message')).toBeInTheDocument();
|
|
119
|
-
|
|
120
|
-
advanceTimers(1);
|
|
121
|
-
advanceTimers(CSS_TRANSITION_DURATION);
|
|
122
|
-
expect(screen.queryByText('Second message')).not.toBeInTheDocument();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('dismisses a delayed replacement on the timeout current when it appears', () => {
|
|
126
|
-
const { rerender } = renderSnackbar();
|
|
127
|
-
|
|
128
|
-
rerender(<Snackbar text="First message" timeout={TIMEOUT} timestamp={1} />);
|
|
129
|
-
rerender(<Snackbar text="Second message" timeout={TIMEOUT} timestamp={2} />);
|
|
130
|
-
// Shortened while the replacement is still waiting out the exit transition.
|
|
131
|
-
rerender(<Snackbar text="Second message" timeout={1000} timestamp={2} />);
|
|
132
|
-
|
|
133
|
-
advanceTimers(CSS_TRANSITION_DURATION);
|
|
134
|
-
expect(screen.getByText('Second message')).toBeInTheDocument();
|
|
135
|
-
|
|
136
|
-
advanceTimers(1000);
|
|
137
|
-
advanceTimers(CSS_TRANSITION_DURATION);
|
|
138
|
-
expect(screen.queryByText('Second message')).not.toBeInTheDocument();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
// Documents existing behaviour rather than endorsing it: clearing the text leaves the notification
|
|
142
|
-
// on screen indefinitely, because the previous shouldComponentUpdate blocked the dismissal too.
|
|
143
|
-
it('keeps the notification visible for as long as text is empty', () => {
|
|
144
|
-
const { rerender } = renderSnackbar();
|
|
145
|
-
|
|
146
|
-
rerender(<Snackbar text="Changes saved" timeout={TIMEOUT} timestamp={1} />);
|
|
147
|
-
rerender(<Snackbar text="" timeout={TIMEOUT} timestamp={2} />);
|
|
148
|
-
|
|
149
|
-
advanceTimers(TIMEOUT + CSS_TRANSITION_DURATION);
|
|
150
|
-
expect(screen.getByText('Changes saved')).toBeInTheDocument();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('ignores a repeated timestamp', () => {
|
|
154
|
-
const { rerender } = renderSnackbar();
|
|
155
|
-
|
|
156
|
-
rerender(<Snackbar text="First message" timeout={TIMEOUT} timestamp={1} />);
|
|
157
|
-
rerender(<Snackbar text="Second message" timeout={TIMEOUT} timestamp={1} />);
|
|
158
|
-
|
|
159
|
-
advanceTimers(CSS_TRANSITION_DURATION);
|
|
160
|
-
expect(screen.getByText('First message')).toBeInTheDocument();
|
|
161
|
-
expect(screen.queryByText('Second message')).not.toBeInTheDocument();
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('clears its pending dismissal timer on unmount', () => {
|
|
165
|
-
const { rerender, unmount } = renderSnackbar();
|
|
166
|
-
|
|
167
|
-
rerender(<Snackbar text="Changes saved" timeout={TIMEOUT} timestamp={1} />);
|
|
168
|
-
const pendingTimers = jest.getTimerCount();
|
|
169
|
-
unmount();
|
|
170
|
-
|
|
171
|
-
// The timer left behind belongs to CSSTransition's enter timeout, not to Snackbar.
|
|
172
|
-
expect(jest.getTimerCount()).toBe(pendingTimers - 1);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('Snackbar created through SnackbarProvider', () => {
|
|
177
|
-
const renderProvider = () =>
|
|
178
|
-
render(
|
|
179
|
-
<SnackbarProvider timeout={TIMEOUT}>
|
|
180
|
-
<SnackbarConsumer>
|
|
181
|
-
{({ createSnackbar }) => (
|
|
182
|
-
<Button onClick={() => createSnackbar({ text: 'Changes saved' })}>Show</Button>
|
|
183
|
-
)}
|
|
184
|
-
</SnackbarConsumer>
|
|
185
|
-
</SnackbarProvider>,
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
it('shows a notification created through the context', async () => {
|
|
189
|
-
renderProvider();
|
|
190
|
-
|
|
191
|
-
await user.click(screen.getByRole('button', { name: 'Show' }));
|
|
192
|
-
|
|
193
|
-
expect(screen.getByText('Changes saved')).toBeInTheDocument();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it('shows only one notification when the trigger is clicked repeatedly', async () => {
|
|
197
|
-
renderProvider();
|
|
198
|
-
|
|
199
|
-
const trigger = screen.getByRole('button', { name: 'Show' });
|
|
200
|
-
await user.click(trigger);
|
|
201
|
-
await user.click(trigger);
|
|
202
|
-
await user.click(trigger);
|
|
203
|
-
|
|
204
|
-
expect(screen.getAllByRole('alert')).toHaveLength(1);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
-
import { CSSTransition } from 'react-transition-group';
|
|
3
|
-
|
|
4
|
-
import Button from '../Button';
|
|
5
|
-
import Body from '../Body';
|
|
6
|
-
import type { ThemeDark, ThemeLight } from '../common';
|
|
7
|
-
import withNextPortal from '../WithNextPortal/WithNextPortal';
|
|
8
|
-
|
|
9
|
-
const CSS_TRANSITION_DURATION = 400;
|
|
10
|
-
|
|
11
|
-
export interface SnackbarProps {
|
|
12
|
-
action?: {
|
|
13
|
-
label: string;
|
|
14
|
-
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
15
|
-
};
|
|
16
|
-
text: React.ReactNode;
|
|
17
|
-
/** @deprecated Has no effect. Snackbar theming is based on ThemeProvider. */
|
|
18
|
-
theme?: ThemeLight | ThemeDark;
|
|
19
|
-
timeout: number;
|
|
20
|
-
timestamp: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface SnackbarState extends Pick<SnackbarProps, 'action' | 'text'> {
|
|
24
|
-
visible: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const Snackbar = (props: SnackbarProps) => {
|
|
28
|
-
const bodyRef = useRef<HTMLSpanElement>(null);
|
|
29
|
-
const leaveTimeout = useRef(0);
|
|
30
|
-
const transitionTimeout = useRef(0);
|
|
31
|
-
/** The props of the last committed render, as `this.props` was in the class component. */
|
|
32
|
-
const committedProps = useRef(props);
|
|
33
|
-
|
|
34
|
-
const [state, setState] = useState<SnackbarState>({
|
|
35
|
-
visible: false,
|
|
36
|
-
text: '',
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
useEffect(
|
|
40
|
-
() => () => {
|
|
41
|
-
window.clearTimeout(leaveTimeout.current);
|
|
42
|
-
window.clearTimeout(transitionTimeout.current);
|
|
43
|
-
},
|
|
44
|
-
[],
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
// Runs after every render to mirror the componentDidUpdate lifecycle this component previously
|
|
48
|
-
// relied on, including the shouldComponentUpdate guard that ignored every update without text.
|
|
49
|
-
// Layout, not passive, so a notification is shown or replaced before the browser paints, as
|
|
50
|
-
// componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect
|
|
51
|
-
// and its synchronous state updates are what keep this conversion behaviour-identical.
|
|
52
|
-
/* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
|
|
53
|
-
useLayoutEffect(() => {
|
|
54
|
-
const previousProps = committedProps.current;
|
|
55
|
-
committedProps.current = props;
|
|
56
|
-
|
|
57
|
-
const { action, text, timestamp } = props;
|
|
58
|
-
|
|
59
|
-
// shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the
|
|
60
|
-
// updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is
|
|
61
|
-
// given text again. Preserved here deliberately to keep this refactor behaviour-identical.
|
|
62
|
-
const updateWhileTextIsPresent = (update: () => void) => {
|
|
63
|
-
if (committedProps.current.text) {
|
|
64
|
-
update();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const setLeaveTimeout = () => {
|
|
69
|
-
leaveTimeout.current = window.setTimeout(() => {
|
|
70
|
-
updateWhileTextIsPresent(() => setState((current) => ({ ...current, visible: false })));
|
|
71
|
-
}, committedProps.current.timeout);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const show = () => {
|
|
75
|
-
setState((current) => ({ ...current, visible: true, action, text }));
|
|
76
|
-
setLeaveTimeout();
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
if (!text) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!previousProps.text) {
|
|
84
|
-
show();
|
|
85
|
-
} else if (previousProps.timestamp !== timestamp) {
|
|
86
|
-
window.clearTimeout(leaveTimeout.current);
|
|
87
|
-
|
|
88
|
-
if (state.visible) {
|
|
89
|
-
setState((current) => ({ ...current, visible: false }));
|
|
90
|
-
transitionTimeout.current = window.setTimeout(() => {
|
|
91
|
-
updateWhileTextIsPresent(show);
|
|
92
|
-
}, CSS_TRANSITION_DURATION);
|
|
93
|
-
} else {
|
|
94
|
-
show();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
/* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
|
|
99
|
-
|
|
100
|
-
const { action, text, visible } = state;
|
|
101
|
-
const { timeout } = props;
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<div className="snackbar" aria-live="assertive" role="alert">
|
|
105
|
-
<CSSTransition
|
|
106
|
-
nodeRef={bodyRef}
|
|
107
|
-
in={visible}
|
|
108
|
-
classNames="snackbar__text-container"
|
|
109
|
-
timeout={{
|
|
110
|
-
appear: 0,
|
|
111
|
-
enter: timeout,
|
|
112
|
-
exit: CSS_TRANSITION_DURATION,
|
|
113
|
-
}}
|
|
114
|
-
unmountOnExit
|
|
115
|
-
>
|
|
116
|
-
<Body ref={bodyRef} as="span" className="snackbar__text">
|
|
117
|
-
{text}
|
|
118
|
-
{action ? (
|
|
119
|
-
<Button className="snackbar__text__action" v2 size="sm" onClick={action.onClick}>
|
|
120
|
-
{action.label}
|
|
121
|
-
</Button>
|
|
122
|
-
) : null}
|
|
123
|
-
</Body>
|
|
124
|
-
</CSSTransition>
|
|
125
|
-
</div>
|
|
126
|
-
);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export default withNextPortal(Snackbar);
|