@transferwise/components 0.0.0-experimental-49c6983 → 0.0.0-experimental-7636184

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 (87) hide show
  1. package/build/Provider/Provider.js +4 -1
  2. package/build/Provider/Provider.js.map +1 -1
  3. package/build/Provider/Provider.mjs +4 -1
  4. package/build/Provider/Provider.mjs.map +1 -1
  5. package/build/Snackbar/Snackbar.js +136 -105
  6. package/build/Snackbar/Snackbar.js.map +1 -1
  7. package/build/Snackbar/Snackbar.mjs +137 -103
  8. package/build/Snackbar/Snackbar.mjs.map +1 -1
  9. package/build/Snackbar/SnackbarContext.js.map +1 -1
  10. package/build/Snackbar/SnackbarContext.mjs.map +1 -1
  11. package/build/Snackbar/SnackbarPortal.js +12 -0
  12. package/build/Snackbar/SnackbarPortal.js.map +1 -0
  13. package/build/Snackbar/SnackbarPortal.mjs +8 -0
  14. package/build/Snackbar/SnackbarPortal.mjs.map +1 -0
  15. package/build/Snackbar/SnackbarProvider.js +24 -28
  16. package/build/Snackbar/SnackbarProvider.js.map +1 -1
  17. package/build/Snackbar/SnackbarProvider.mjs +25 -29
  18. package/build/Snackbar/SnackbarProvider.mjs.map +1 -1
  19. package/build/Snackbar/constants.js +14 -0
  20. package/build/Snackbar/constants.js.map +1 -0
  21. package/build/Snackbar/constants.mjs +9 -0
  22. package/build/Snackbar/constants.mjs.map +1 -0
  23. package/build/Snackbar/useSnackbarAutoDismiss.js +64 -0
  24. package/build/Snackbar/useSnackbarAutoDismiss.js.map +1 -0
  25. package/build/Snackbar/useSnackbarAutoDismiss.mjs +60 -0
  26. package/build/Snackbar/useSnackbarAutoDismiss.mjs.map +1 -0
  27. package/build/Snackbar/useSnackbarManager.js +144 -0
  28. package/build/Snackbar/useSnackbarManager.js.map +1 -0
  29. package/build/Snackbar/useSnackbarManager.mjs +140 -0
  30. package/build/Snackbar/useSnackbarManager.mjs.map +1 -0
  31. package/build/Typeahead/TypeaheadInput/TypeaheadInput.js +5 -5
  32. package/build/Typeahead/TypeaheadInput/TypeaheadInput.js.map +1 -1
  33. package/build/Typeahead/TypeaheadInput/TypeaheadInput.mjs +5 -5
  34. package/build/Typeahead/TypeaheadInput/TypeaheadInput.mjs.map +1 -1
  35. package/build/main.css +131 -61
  36. package/build/styles/Snackbar/Snackbar.css +105 -54
  37. package/build/styles/Typeahead/Typeahead.css +27 -8
  38. package/build/styles/main.css +131 -61
  39. package/build/types/Provider/Provider.d.ts.map +1 -1
  40. package/build/types/Snackbar/Snackbar.d.ts +48 -9
  41. package/build/types/Snackbar/Snackbar.d.ts.map +1 -1
  42. package/build/types/Snackbar/Snackbar.types.d.ts +12 -0
  43. package/build/types/Snackbar/Snackbar.types.d.ts.map +1 -0
  44. package/build/types/Snackbar/SnackbarContext.d.ts +2 -2
  45. package/build/types/Snackbar/SnackbarContext.d.ts.map +1 -1
  46. package/build/types/Snackbar/SnackbarPortal.d.ts +4 -0
  47. package/build/types/Snackbar/SnackbarPortal.d.ts.map +1 -0
  48. package/build/types/Snackbar/SnackbarProvider.d.ts +10 -0
  49. package/build/types/Snackbar/SnackbarProvider.d.ts.map +1 -1
  50. package/build/types/Snackbar/constants.d.ts +7 -0
  51. package/build/types/Snackbar/constants.d.ts.map +1 -0
  52. package/build/types/Snackbar/index.d.ts +1 -1
  53. package/build/types/Snackbar/index.d.ts.map +1 -1
  54. package/build/types/Snackbar/useSnackbar.d.ts +1 -1
  55. package/build/types/Snackbar/useSnackbar.d.ts.map +1 -1
  56. package/build/types/Snackbar/useSnackbarAutoDismiss.d.ts +12 -0
  57. package/build/types/Snackbar/useSnackbarAutoDismiss.d.ts.map +1 -0
  58. package/build/types/Snackbar/useSnackbarManager.d.ts +20 -0
  59. package/build/types/Snackbar/useSnackbarManager.d.ts.map +1 -0
  60. package/build/types/Typeahead/TypeaheadInput/TypeaheadInput.d.ts.map +1 -1
  61. package/build/types/index.d.ts +1 -1
  62. package/build/types/index.d.ts.map +1 -1
  63. package/package.json +1 -1
  64. package/src/ListItem/_stories/ListItem.scenarios.story.tsx +13 -16
  65. package/src/Provider/Provider.tsx +2 -1
  66. package/src/Snackbar/Snackbar.css +105 -54
  67. package/src/Snackbar/Snackbar.less +124 -60
  68. package/src/Snackbar/Snackbar.test.tsx +540 -120
  69. package/src/Snackbar/Snackbar.tsx +159 -99
  70. package/src/Snackbar/Snackbar.types.ts +17 -0
  71. package/src/Snackbar/SnackbarContext.ts +2 -2
  72. package/src/Snackbar/SnackbarPortal.tsx +8 -0
  73. package/src/Snackbar/SnackbarProvider.test.tsx +577 -0
  74. package/src/Snackbar/SnackbarProvider.tsx +32 -19
  75. package/src/Snackbar/_stories/Snackbar.rtl.test.story.tsx +13 -10
  76. package/src/Snackbar/_stories/Snackbar.story.tsx +132 -39
  77. package/src/Snackbar/_stories/Snackbar.test.story.tsx +101 -35
  78. package/src/Snackbar/constants.ts +7 -0
  79. package/src/Snackbar/index.ts +1 -1
  80. package/src/Snackbar/useSnackbarAutoDismiss.ts +72 -0
  81. package/src/Snackbar/useSnackbarManager.ts +159 -0
  82. package/src/Typeahead/Typeahead.css +27 -8
  83. package/src/Typeahead/Typeahead.less +32 -9
  84. package/src/Typeahead/TypeaheadInput/TypeaheadInput.tsx +5 -5
  85. package/src/Typeahead/_stories/Typeahead.test.story.tsx +0 -65
  86. package/src/index.ts +1 -1
  87. package/src/main.css +131 -61
@@ -29,6 +29,7 @@ require('react');
29
29
  require('../common/CloseButton/CloseButton.messages.js');
30
30
  var jsxRuntime = require('react/jsx-runtime');
31
31
  var en = require('../i18n/en.json.js');
32
+ var SnackbarProvider = require('../Snackbar/SnackbarProvider.js');
32
33
  var DirectionProvider = require('./Direction/DirectionProvider.js');
33
34
 
34
35
  function Provider({
@@ -65,7 +66,9 @@ function Provider({
65
66
  locale: intlConfig.locale,
66
67
  messages: intlConfig.messages,
67
68
  defaultRichTextElements: defaultRichTextElements,
68
- children: children
69
+ children: /*#__PURE__*/jsxRuntime.jsx(SnackbarProvider.default, {
70
+ children: children
71
+ })
69
72
  })
70
73
  });
71
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sources":["../../src/Provider/Provider.tsx"],"sourcesContent":["import { IntlProvider, ResolvedIntlConfig } from 'react-intl';\n\nimport { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common';\nimport en from '../i18n/en.json';\n\nimport { DirectionProvider } from './Direction';\n\nexport interface ProviderProps {\n i18n: Pick<ResolvedIntlConfig, 'locale' | 'messages'> &\n Partial<Pick<ResolvedIntlConfig, 'defaultRichTextElements'>>;\n children?: React.ReactNode;\n}\n\nexport default function Provider({ i18n, children }: ProviderProps) {\n const { locale, messages, defaultRichTextElements } = i18n;\n const adjustedLocale = adjustLocale(locale);\n let intlConfig;\n\n if (adjustedLocale === null) {\n // eslint-disable-next-line no-console\n console.warn(\n `Unsupported locale value was provided: '${locale}', defaulting to '${DEFAULT_LOCALE}'`,\n );\n\n intlConfig = { locale: DEFAULT_LOCALE, messages: { ...en, ...messages } };\n } else {\n intlConfig = { locale: adjustedLocale, messages };\n }\n\n return (\n <DirectionProvider direction={getDirectionFromLocale(locale)}>\n <IntlProvider\n defaultLocale={DEFAULT_LOCALE}\n locale={intlConfig.locale}\n messages={intlConfig.messages}\n defaultRichTextElements={defaultRichTextElements}\n >\n {children}\n </IntlProvider>\n </DirectionProvider>\n );\n}\n"],"names":["Provider","i18n","children","locale","messages","defaultRichTextElements","adjustedLocale","adjustLocale","intlConfig","console","warn","DEFAULT_LOCALE","en","_jsx","DirectionProvider","direction","getDirectionFromLocale","IntlProvider","defaultLocale"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAac,SAAUA,QAAQA,CAAC;EAAEC,IAAI;AAAEC,EAAAA;AAAQ,CAAiB,EAAA;EAChE,MAAM;IAAEC,MAAM;IAAEC,QAAQ;AAAEC,IAAAA;AAAuB,GAAE,GAAGJ,IAAI;AAC1D,EAAA,MAAMK,cAAc,GAAGC,kBAAY,CAACJ,MAAM,CAAC;AAC3C,EAAA,IAAIK,UAAU;EAEd,IAAIF,cAAc,KAAK,IAAI,EAAE;AAC3B;IACAG,OAAO,CAACC,IAAI,CACV,CAAA,wCAAA,EAA2CP,MAAM,CAAA,kBAAA,EAAqBQ,oBAAc,GAAG,CACxF;AAEDH,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEQ,oBAAc;AAAEP,MAAAA,QAAQ,EAAE;AAAE,QAAA,GAAGQ,UAAE;QAAE,GAAGR;AAAQ;KAAI;AAC3E,EAAA,CAAC,MAAM;AACLI,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEG,cAAc;AAAEF,MAAAA;KAAU;AACnD,EAAA;EAEA,oBACES,cAAA,CAACC,mCAAiB,EAAA;AAACC,IAAAA,SAAS,EAAEC,4BAAsB,CAACb,MAAM,CAAE;IAAAD,QAAA,eAC3DW,cAAA,CAACI,sBAAY,EAAA;AACXC,MAAAA,aAAa,EAAEP,oBAAe;MAC9BR,MAAM,EAAEK,UAAU,CAACL,MAAO;MAC1BC,QAAQ,EAAEI,UAAU,CAACJ,QAAS;AAC9BC,MAAAA,uBAAuB,EAAEA,uBAAwB;AAAAH,MAAAA,QAAA,EAEhDA;KACW;AAChB,GAAmB,CAAC;AAExB;;"}
1
+ {"version":3,"file":"Provider.js","sources":["../../src/Provider/Provider.tsx"],"sourcesContent":["import { IntlProvider, ResolvedIntlConfig } from 'react-intl';\n\nimport { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common';\nimport en from '../i18n/en.json';\nimport SnackbarProvider from '../Snackbar/SnackbarProvider';\n\nimport { DirectionProvider } from './Direction';\n\nexport interface ProviderProps {\n i18n: Pick<ResolvedIntlConfig, 'locale' | 'messages'> &\n Partial<Pick<ResolvedIntlConfig, 'defaultRichTextElements'>>;\n children?: React.ReactNode;\n}\n\nexport default function Provider({ i18n, children }: ProviderProps) {\n const { locale, messages, defaultRichTextElements } = i18n;\n const adjustedLocale = adjustLocale(locale);\n let intlConfig;\n\n if (adjustedLocale === null) {\n // eslint-disable-next-line no-console\n console.warn(\n `Unsupported locale value was provided: '${locale}', defaulting to '${DEFAULT_LOCALE}'`,\n );\n\n intlConfig = { locale: DEFAULT_LOCALE, messages: { ...en, ...messages } };\n } else {\n intlConfig = { locale: adjustedLocale, messages };\n }\n\n return (\n <DirectionProvider direction={getDirectionFromLocale(locale)}>\n <IntlProvider\n defaultLocale={DEFAULT_LOCALE}\n locale={intlConfig.locale}\n messages={intlConfig.messages}\n defaultRichTextElements={defaultRichTextElements}\n >\n <SnackbarProvider>{children}</SnackbarProvider>\n </IntlProvider>\n </DirectionProvider>\n );\n}\n"],"names":["Provider","i18n","children","locale","messages","defaultRichTextElements","adjustedLocale","adjustLocale","intlConfig","console","warn","DEFAULT_LOCALE","en","_jsx","DirectionProvider","direction","getDirectionFromLocale","IntlProvider","defaultLocale","SnackbarProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcc,SAAUA,QAAQA,CAAC;EAAEC,IAAI;AAAEC,EAAAA;AAAQ,CAAiB,EAAA;EAChE,MAAM;IAAEC,MAAM;IAAEC,QAAQ;AAAEC,IAAAA;AAAuB,GAAE,GAAGJ,IAAI;AAC1D,EAAA,MAAMK,cAAc,GAAGC,kBAAY,CAACJ,MAAM,CAAC;AAC3C,EAAA,IAAIK,UAAU;EAEd,IAAIF,cAAc,KAAK,IAAI,EAAE;AAC3B;IACAG,OAAO,CAACC,IAAI,CACV,CAAA,wCAAA,EAA2CP,MAAM,CAAA,kBAAA,EAAqBQ,oBAAc,GAAG,CACxF;AAEDH,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEQ,oBAAc;AAAEP,MAAAA,QAAQ,EAAE;AAAE,QAAA,GAAGQ,UAAE;QAAE,GAAGR;AAAQ;KAAI;AAC3E,EAAA,CAAC,MAAM;AACLI,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEG,cAAc;AAAEF,MAAAA;KAAU;AACnD,EAAA;EAEA,oBACES,cAAA,CAACC,mCAAiB,EAAA;AAACC,IAAAA,SAAS,EAAEC,4BAAsB,CAACb,MAAM,CAAE;IAAAD,QAAA,eAC3DW,cAAA,CAACI,sBAAY,EAAA;AACXC,MAAAA,aAAa,EAAEP,oBAAe;MAC9BR,MAAM,EAAEK,UAAU,CAACL,MAAO;MAC1BC,QAAQ,EAAEI,UAAU,CAACJ,QAAS;AAC9BC,MAAAA,uBAAuB,EAAEA,uBAAwB;MAAAH,QAAA,eAEjDW,cAAA,CAACM,wBAAgB,EAAA;AAAAjB,QAAAA,QAAA,EAAEA;OAA2B;KAClC;AAChB,GAAmB,CAAC;AAExB;;"}
@@ -25,6 +25,7 @@ import 'react';
25
25
  import '../common/CloseButton/CloseButton.messages.mjs';
26
26
  import { jsx } from 'react/jsx-runtime';
27
27
  import en from '../i18n/en.json.mjs';
28
+ import SnackbarProvider from '../Snackbar/SnackbarProvider.mjs';
28
29
  import { DirectionProvider } from './Direction/DirectionProvider.mjs';
29
30
 
30
31
  function Provider({
@@ -61,7 +62,9 @@ function Provider({
61
62
  locale: intlConfig.locale,
62
63
  messages: intlConfig.messages,
63
64
  defaultRichTextElements: defaultRichTextElements,
64
- children: children
65
+ children: /*#__PURE__*/jsx(SnackbarProvider, {
66
+ children: children
67
+ })
65
68
  })
66
69
  });
67
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.mjs","sources":["../../src/Provider/Provider.tsx"],"sourcesContent":["import { IntlProvider, ResolvedIntlConfig } from 'react-intl';\n\nimport { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common';\nimport en from '../i18n/en.json';\n\nimport { DirectionProvider } from './Direction';\n\nexport interface ProviderProps {\n i18n: Pick<ResolvedIntlConfig, 'locale' | 'messages'> &\n Partial<Pick<ResolvedIntlConfig, 'defaultRichTextElements'>>;\n children?: React.ReactNode;\n}\n\nexport default function Provider({ i18n, children }: ProviderProps) {\n const { locale, messages, defaultRichTextElements } = i18n;\n const adjustedLocale = adjustLocale(locale);\n let intlConfig;\n\n if (adjustedLocale === null) {\n // eslint-disable-next-line no-console\n console.warn(\n `Unsupported locale value was provided: '${locale}', defaulting to '${DEFAULT_LOCALE}'`,\n );\n\n intlConfig = { locale: DEFAULT_LOCALE, messages: { ...en, ...messages } };\n } else {\n intlConfig = { locale: adjustedLocale, messages };\n }\n\n return (\n <DirectionProvider direction={getDirectionFromLocale(locale)}>\n <IntlProvider\n defaultLocale={DEFAULT_LOCALE}\n locale={intlConfig.locale}\n messages={intlConfig.messages}\n defaultRichTextElements={defaultRichTextElements}\n >\n {children}\n </IntlProvider>\n </DirectionProvider>\n );\n}\n"],"names":["Provider","i18n","children","locale","messages","defaultRichTextElements","adjustedLocale","adjustLocale","intlConfig","console","warn","DEFAULT_LOCALE","en","_jsx","DirectionProvider","direction","getDirectionFromLocale","IntlProvider","defaultLocale"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAac,SAAUA,QAAQA,CAAC;EAAEC,IAAI;AAAEC,EAAAA;AAAQ,CAAiB,EAAA;EAChE,MAAM;IAAEC,MAAM;IAAEC,QAAQ;AAAEC,IAAAA;AAAuB,GAAE,GAAGJ,IAAI;AAC1D,EAAA,MAAMK,cAAc,GAAGC,YAAY,CAACJ,MAAM,CAAC;AAC3C,EAAA,IAAIK,UAAU;EAEd,IAAIF,cAAc,KAAK,IAAI,EAAE;AAC3B;IACAG,OAAO,CAACC,IAAI,CACV,CAAA,wCAAA,EAA2CP,MAAM,CAAA,kBAAA,EAAqBQ,cAAc,GAAG,CACxF;AAEDH,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEQ,cAAc;AAAEP,MAAAA,QAAQ,EAAE;AAAE,QAAA,GAAGQ,EAAE;QAAE,GAAGR;AAAQ;KAAI;AAC3E,EAAA,CAAC,MAAM;AACLI,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEG,cAAc;AAAEF,MAAAA;KAAU;AACnD,EAAA;EAEA,oBACES,GAAA,CAACC,iBAAiB,EAAA;AAACC,IAAAA,SAAS,EAAEC,sBAAsB,CAACb,MAAM,CAAE;IAAAD,QAAA,eAC3DW,GAAA,CAACI,YAAY,EAAA;AACXC,MAAAA,aAAa,EAAEP,cAAe;MAC9BR,MAAM,EAAEK,UAAU,CAACL,MAAO;MAC1BC,QAAQ,EAAEI,UAAU,CAACJ,QAAS;AAC9BC,MAAAA,uBAAuB,EAAEA,uBAAwB;AAAAH,MAAAA,QAAA,EAEhDA;KACW;AAChB,GAAmB,CAAC;AAExB;;"}
1
+ {"version":3,"file":"Provider.mjs","sources":["../../src/Provider/Provider.tsx"],"sourcesContent":["import { IntlProvider, ResolvedIntlConfig } from 'react-intl';\n\nimport { adjustLocale, DEFAULT_LOCALE, getDirectionFromLocale } from '../common';\nimport en from '../i18n/en.json';\nimport SnackbarProvider from '../Snackbar/SnackbarProvider';\n\nimport { DirectionProvider } from './Direction';\n\nexport interface ProviderProps {\n i18n: Pick<ResolvedIntlConfig, 'locale' | 'messages'> &\n Partial<Pick<ResolvedIntlConfig, 'defaultRichTextElements'>>;\n children?: React.ReactNode;\n}\n\nexport default function Provider({ i18n, children }: ProviderProps) {\n const { locale, messages, defaultRichTextElements } = i18n;\n const adjustedLocale = adjustLocale(locale);\n let intlConfig;\n\n if (adjustedLocale === null) {\n // eslint-disable-next-line no-console\n console.warn(\n `Unsupported locale value was provided: '${locale}', defaulting to '${DEFAULT_LOCALE}'`,\n );\n\n intlConfig = { locale: DEFAULT_LOCALE, messages: { ...en, ...messages } };\n } else {\n intlConfig = { locale: adjustedLocale, messages };\n }\n\n return (\n <DirectionProvider direction={getDirectionFromLocale(locale)}>\n <IntlProvider\n defaultLocale={DEFAULT_LOCALE}\n locale={intlConfig.locale}\n messages={intlConfig.messages}\n defaultRichTextElements={defaultRichTextElements}\n >\n <SnackbarProvider>{children}</SnackbarProvider>\n </IntlProvider>\n </DirectionProvider>\n );\n}\n"],"names":["Provider","i18n","children","locale","messages","defaultRichTextElements","adjustedLocale","adjustLocale","intlConfig","console","warn","DEFAULT_LOCALE","en","_jsx","DirectionProvider","direction","getDirectionFromLocale","IntlProvider","defaultLocale","SnackbarProvider"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcc,SAAUA,QAAQA,CAAC;EAAEC,IAAI;AAAEC,EAAAA;AAAQ,CAAiB,EAAA;EAChE,MAAM;IAAEC,MAAM;IAAEC,QAAQ;AAAEC,IAAAA;AAAuB,GAAE,GAAGJ,IAAI;AAC1D,EAAA,MAAMK,cAAc,GAAGC,YAAY,CAACJ,MAAM,CAAC;AAC3C,EAAA,IAAIK,UAAU;EAEd,IAAIF,cAAc,KAAK,IAAI,EAAE;AAC3B;IACAG,OAAO,CAACC,IAAI,CACV,CAAA,wCAAA,EAA2CP,MAAM,CAAA,kBAAA,EAAqBQ,cAAc,GAAG,CACxF;AAEDH,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEQ,cAAc;AAAEP,MAAAA,QAAQ,EAAE;AAAE,QAAA,GAAGQ,EAAE;QAAE,GAAGR;AAAQ;KAAI;AAC3E,EAAA,CAAC,MAAM;AACLI,IAAAA,UAAU,GAAG;AAAEL,MAAAA,MAAM,EAAEG,cAAc;AAAEF,MAAAA;KAAU;AACnD,EAAA;EAEA,oBACES,GAAA,CAACC,iBAAiB,EAAA;AAACC,IAAAA,SAAS,EAAEC,sBAAsB,CAACb,MAAM,CAAE;IAAAD,QAAA,eAC3DW,GAAA,CAACI,YAAY,EAAA;AACXC,MAAAA,aAAa,EAAEP,cAAe;MAC9BR,MAAM,EAAEK,UAAU,CAACL,MAAO;MAC1BC,QAAQ,EAAEI,UAAU,CAACJ,QAAS;AAC9BC,MAAAA,uBAAuB,EAAEA,uBAAwB;MAAAH,QAAA,eAEjDW,GAAA,CAACM,gBAAgB,EAAA;AAAAjB,QAAAA,QAAA,EAAEA;OAA2B;KAClC;AAChB,GAAmB,CAAC;AAExB;;"}
@@ -1,128 +1,159 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
3
+ var icons = require('@transferwise/icons');
6
4
  var reactTransitionGroup = require('react-transition-group');
7
5
  var Button_resolver = require('../Button/Button.resolver.js');
8
6
  var Body = require('../Body/Body.js');
9
- var WithNextPortal = require('../WithNextPortal/WithNextPortal.js');
7
+ require('../common/theme.js');
8
+ require('../common/direction.js');
9
+ require('@transferwise/neptune-tokens');
10
+ require('../common/PropsValues/control.js');
11
+ require('../common/PropsValues/size.js');
12
+ require('../common/PropsValues/typography.js');
13
+ require('../common/PropsValues/width.js');
14
+ require('../common/PropsValues/type.js');
15
+ require('../common/PropsValues/dateMode.js');
16
+ require('../common/PropsValues/monthFormat.js');
17
+ require('../common/PropsValues/position.js');
18
+ require('../common/PropsValues/layouts.js');
19
+ require('../common/PropsValues/status.js');
20
+ require('../common/PropsValues/sentiment.js');
21
+ require('../common/PropsValues/profileType.js');
22
+ require('../common/PropsValues/variant.js');
23
+ require('../common/PropsValues/scroll.js');
24
+ require('../common/PropsValues/markdownNodeType.js');
25
+ require('../common/fileType.js');
26
+ require('@transferwise/formatting');
27
+ require('clsx');
28
+ require('react');
29
+ require('react-intl');
30
+ require('../common/CloseButton/CloseButton.messages.js');
10
31
  var jsxRuntime = require('react/jsx-runtime');
32
+ var LiveRegion = require('../common/LiveRegion/LiveRegion.js');
33
+ var PrimitivePrompt = require('../Prompt/PrimitivePrompt/PrimitivePrompt.js');
34
+ var ProcessIndicator = require('../ProcessIndicator/ProcessIndicator.js');
35
+ var StatusIcon = require('../StatusIcon/StatusIcon.js');
36
+ var constants = require('./constants.js');
37
+ var useSnackbarAutoDismiss = require('./useSnackbarAutoDismiss.js');
11
38
 
12
- const CSS_TRANSITION_DURATION = 400;
13
- const Snackbar = props => {
14
- const bodyRef = React.useRef(null);
15
- const leaveTimeout = React.useRef(0);
16
- const transitionTimeout = React.useRef(0);
17
- /** The props of the last committed render, as `this.props` was in the class component. */
18
- const committedProps = React.useRef(props);
19
- const [state, setState] = React.useState({
20
- visible: false,
21
- text: ''
39
+ const Snackbar = ({
40
+ action,
41
+ announcementKey,
42
+ duration,
43
+ loading = false,
44
+ media,
45
+ onDismissRequest,
46
+ onExited,
47
+ sentiment = 'neutral',
48
+ text,
49
+ timeout,
50
+ visible
51
+ }) => {
52
+ const {
53
+ handleBlur,
54
+ handleEntered,
55
+ handleFocus,
56
+ handleMouseEnter,
57
+ handleMouseLeave,
58
+ surfaceRef
59
+ } = useSnackbarAutoDismiss.default({
60
+ duration,
61
+ loading,
62
+ onDismissRequest,
63
+ timeout,
64
+ visible
22
65
  });
23
- React.useEffect(() => () => {
24
- window.clearTimeout(leaveTimeout.current);
25
- window.clearTimeout(transitionTimeout.current);
26
- }, []);
27
- // Runs after every render to mirror the componentDidUpdate lifecycle this component previously
28
- // relied on, including the shouldComponentUpdate guard that ignored every update without text.
29
- // Layout, not passive, so a notification is shown or replaced before the browser paints, as
30
- // componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect
31
- // and its synchronous state updates are what keep this conversion behaviour-identical.
32
- /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
33
- React.useLayoutEffect(() => {
34
- const previousProps = committedProps.current;
35
- committedProps.current = props;
36
- const {
37
- action,
38
- text,
39
- timestamp
40
- } = props;
41
- // shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the
42
- // updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is
43
- // given text again. Preserved here deliberately to keep this refactor behaviour-identical.
44
- const updateWhileTextIsPresent = update => {
45
- if (committedProps.current.text) {
46
- update();
47
- }
48
- };
49
- const setLeaveTimeout = () => {
50
- leaveTimeout.current = window.setTimeout(() => {
51
- updateWhileTextIsPresent(() => setState(current => ({
52
- ...current,
53
- visible: false
54
- })));
55
- }, committedProps.current.timeout);
56
- };
57
- const show = () => {
58
- setState(current => ({
59
- ...current,
60
- visible: true,
61
- action,
62
- text
63
- }));
64
- setLeaveTimeout();
65
- };
66
- if (!text) {
67
- return;
66
+ const handleActionClick = event => {
67
+ try {
68
+ action?.onClick?.(event);
69
+ } finally {
70
+ onDismissRequest();
68
71
  }
69
- if (!previousProps.text) {
70
- show();
71
- } else if (previousProps.timestamp !== timestamp) {
72
- window.clearTimeout(leaveTimeout.current);
73
- if (state.visible) {
74
- setState(current => ({
75
- ...current,
76
- visible: false
77
- }));
78
- transitionTimeout.current = window.setTimeout(() => {
79
- updateWhileTextIsPresent(show);
80
- }, CSS_TRANSITION_DURATION);
81
- } else {
82
- show();
83
- }
72
+ };
73
+ const renderMedia = () => {
74
+ if (loading) {
75
+ return /*#__PURE__*/jsxRuntime.jsx(ProcessIndicator.default, {
76
+ className: "wds-Snackbar__process-indicator",
77
+ "data-testid": "Snackbar_ProcessIndicator",
78
+ size: "xs"
79
+ });
84
80
  }
85
- });
86
- /* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
87
- const {
88
- action,
89
- text,
90
- visible
91
- } = state;
92
- const {
93
- timeout
94
- } = props;
81
+ if (media) {
82
+ return /*#__PURE__*/jsxRuntime.jsx("span", {
83
+ className: "wds-Snackbar__media-asset",
84
+ children: media
85
+ });
86
+ }
87
+ if (sentiment === 'proposition') {
88
+ return /*#__PURE__*/jsxRuntime.jsx("span", {
89
+ className: "wds-Snackbar__media-asset",
90
+ children: /*#__PURE__*/jsxRuntime.jsx(icons.Tags, {
91
+ "aria-hidden": true,
92
+ size: 24
93
+ })
94
+ });
95
+ }
96
+ return /*#__PURE__*/jsxRuntime.jsx(StatusIcon.default, {
97
+ sentiment: sentiment,
98
+ size: 24
99
+ });
100
+ };
95
101
  return /*#__PURE__*/jsxRuntime.jsx("div", {
96
- className: "snackbar",
97
- "aria-live": "assertive",
98
- role: "alert",
102
+ className: "wds-Snackbar",
103
+ style: {
104
+ '--Snackbar-enter-duration': `${constants.SNACKBAR_ENTER_DURATION}ms`,
105
+ '--Snackbar-exit-duration': `${constants.SNACKBAR_EXIT_DURATION}ms`
106
+ },
99
107
  children: /*#__PURE__*/jsxRuntime.jsx(reactTransitionGroup.CSSTransition, {
100
- nodeRef: bodyRef,
108
+ appear: true,
109
+ nodeRef: surfaceRef,
101
110
  in: visible,
102
- classNames: "snackbar__text-container",
111
+ classNames: "wds-Snackbar-container",
103
112
  timeout: {
104
- appear: 0,
105
- enter: timeout,
106
- exit: CSS_TRANSITION_DURATION
113
+ appear: constants.SNACKBAR_ENTER_DURATION,
114
+ enter: constants.SNACKBAR_ENTER_DURATION,
115
+ exit: constants.SNACKBAR_EXIT_DURATION
107
116
  },
108
117
  unmountOnExit: true,
109
- children: /*#__PURE__*/jsxRuntime.jsxs(Body.default, {
110
- ref: bodyRef,
111
- as: "span",
112
- className: "snackbar__text",
113
- children: [text, action ? /*#__PURE__*/jsxRuntime.jsx(Button_resolver.default, {
114
- className: "snackbar__text__action",
115
- v2: true,
116
- size: "sm",
117
- onClick: action.onClick,
118
- children: action.label
119
- }) : null]
118
+ onEntered: handleEntered,
119
+ onExited: onExited,
120
+ children: /*#__PURE__*/jsxRuntime.jsx(PrimitivePrompt.PrimitivePrompt, {
121
+ ref: surfaceRef,
122
+ className: "wds-Snackbar-container",
123
+ sentiment: loading ? 'neutral' : sentiment,
124
+ emphasis: "elevated",
125
+ media: renderMedia(),
126
+ onDismiss: onDismissRequest,
127
+ onMouseEnter: handleMouseEnter,
128
+ onMouseLeave: handleMouseLeave,
129
+ onFocus: handleFocus,
130
+ onBlur: handleBlur,
131
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
132
+ className: "wds-Snackbar__content",
133
+ children: [/*#__PURE__*/jsxRuntime.jsx(LiveRegion.LiveRegion, {
134
+ "aria-live": "polite",
135
+ announceOnChange: announcementKey,
136
+ className: "wds-Snackbar__message",
137
+ children: /*#__PURE__*/jsxRuntime.jsx(Body.default, {
138
+ as: "span",
139
+ className: "wds-Snackbar__body",
140
+ children: text
141
+ })
142
+ }), action ? /*#__PURE__*/jsxRuntime.jsx(Button_resolver.default, {
143
+ className: "wds-Snackbar__action",
144
+ v2: true,
145
+ size: "sm",
146
+ priority: "secondary",
147
+ href: action.href,
148
+ target: action.target,
149
+ onClick: handleActionClick,
150
+ children: action.label
151
+ }) : null]
152
+ })
120
153
  })
121
154
  })
122
155
  });
123
156
  };
124
- var SnackbarPortal = WithNextPortal.default(Snackbar);
125
157
 
126
158
  exports.Snackbar = Snackbar;
127
- exports.default = SnackbarPortal;
128
159
  //# sourceMappingURL=Snackbar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Snackbar.js","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from 'react';\nimport { CSSTransition } from 'react-transition-group';\n\nimport Button from '../Button';\nimport Body from '../Body';\nimport type { ThemeDark, ThemeLight } from '../common';\nimport withNextPortal from '../WithNextPortal/WithNextPortal';\n\nconst CSS_TRANSITION_DURATION = 400;\n\nexport interface SnackbarProps {\n action?: {\n label: string;\n onClick?: React.MouseEventHandler<HTMLButtonElement>;\n };\n text: React.ReactNode;\n /** @deprecated Has no effect. Snackbar theming is based on ThemeProvider. */\n theme?: ThemeLight | ThemeDark;\n timeout: number;\n timestamp: number;\n}\n\ninterface SnackbarState extends Pick<SnackbarProps, 'action' | 'text'> {\n visible: boolean;\n}\n\nexport const Snackbar = (props: SnackbarProps) => {\n const bodyRef = useRef<HTMLSpanElement>(null);\n const leaveTimeout = useRef(0);\n const transitionTimeout = useRef(0);\n /** The props of the last committed render, as `this.props` was in the class component. */\n const committedProps = useRef(props);\n\n const [state, setState] = useState<SnackbarState>({\n visible: false,\n text: '',\n });\n\n useEffect(\n () => () => {\n window.clearTimeout(leaveTimeout.current);\n window.clearTimeout(transitionTimeout.current);\n },\n [],\n );\n\n // Runs after every render to mirror the componentDidUpdate lifecycle this component previously\n // relied on, including the shouldComponentUpdate guard that ignored every update without text.\n // Layout, not passive, so a notification is shown or replaced before the browser paints, as\n // componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect\n // and its synchronous state updates are what keep this conversion behaviour-identical.\n /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n useLayoutEffect(() => {\n const previousProps = committedProps.current;\n committedProps.current = props;\n\n const { action, text, timestamp } = props;\n\n // shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the\n // updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is\n // given text again. Preserved here deliberately to keep this refactor behaviour-identical.\n const updateWhileTextIsPresent = (update: () => void) => {\n if (committedProps.current.text) {\n update();\n }\n };\n\n const setLeaveTimeout = () => {\n leaveTimeout.current = window.setTimeout(() => {\n updateWhileTextIsPresent(() => setState((current) => ({ ...current, visible: false })));\n }, committedProps.current.timeout);\n };\n\n const show = () => {\n setState((current) => ({ ...current, visible: true, action, text }));\n setLeaveTimeout();\n };\n\n if (!text) {\n return;\n }\n\n if (!previousProps.text) {\n show();\n } else if (previousProps.timestamp !== timestamp) {\n window.clearTimeout(leaveTimeout.current);\n\n if (state.visible) {\n setState((current) => ({ ...current, visible: false }));\n transitionTimeout.current = window.setTimeout(() => {\n updateWhileTextIsPresent(show);\n }, CSS_TRANSITION_DURATION);\n } else {\n show();\n }\n }\n });\n /* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */\n\n const { action, text, visible } = state;\n const { timeout } = props;\n\n return (\n <div className=\"snackbar\" aria-live=\"assertive\" role=\"alert\">\n <CSSTransition\n nodeRef={bodyRef}\n in={visible}\n classNames=\"snackbar__text-container\"\n timeout={{\n appear: 0,\n enter: timeout,\n exit: CSS_TRANSITION_DURATION,\n }}\n unmountOnExit\n >\n <Body ref={bodyRef} as=\"span\" className=\"snackbar__text\">\n {text}\n {action ? (\n <Button className=\"snackbar__text__action\" v2 size=\"sm\" onClick={action.onClick}>\n {action.label}\n </Button>\n ) : null}\n </Body>\n </CSSTransition>\n </div>\n );\n};\n\nexport default withNextPortal(Snackbar);\n"],"names":["CSS_TRANSITION_DURATION","Snackbar","props","bodyRef","useRef","leaveTimeout","transitionTimeout","committedProps","state","setState","useState","visible","text","useEffect","window","clearTimeout","current","useLayoutEffect","previousProps","action","timestamp","updateWhileTextIsPresent","update","setLeaveTimeout","setTimeout","timeout","show","_jsx","className","role","children","CSSTransition","nodeRef","in","classNames","appear","enter","exit","unmountOnExit","_jsxs","Body","ref","as","Button","v2","size","onClick","label","withNextPortal"],"mappings":";;;;;;;;;;;AAQA,MAAMA,uBAAuB,GAAG,GAAG;AAkB5B,MAAMC,QAAQ,GAAIC,KAAoB,IAAI;AAC/C,EAAA,MAAMC,OAAO,GAAGC,YAAM,CAAkB,IAAI,CAAC;AAC7C,EAAA,MAAMC,YAAY,GAAGD,YAAM,CAAC,CAAC,CAAC;AAC9B,EAAA,MAAME,iBAAiB,GAAGF,YAAM,CAAC,CAAC,CAAC;AACnC;AACA,EAAA,MAAMG,cAAc,GAAGH,YAAM,CAACF,KAAK,CAAC;AAEpC,EAAA,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGC,cAAQ,CAAgB;AAChDC,IAAAA,OAAO,EAAE,KAAK;AACdC,IAAAA,IAAI,EAAE;AACP,GAAA,CAAC;EAEFC,eAAS,CACP,MAAM,MAAK;AACTC,IAAAA,MAAM,CAACC,YAAY,CAACV,YAAY,CAACW,OAAO,CAAC;AACzCF,IAAAA,MAAM,CAACC,YAAY,CAACT,iBAAiB,CAACU,OAAO,CAAC;EAChD,CAAC,EACD,EAAE,CACH;AAED;AACA;AACA;AACA;AACA;AACA;AACAC,EAAAA,qBAAe,CAAC,MAAK;AACnB,IAAA,MAAMC,aAAa,GAAGX,cAAc,CAACS,OAAO;IAC5CT,cAAc,CAACS,OAAO,GAAGd,KAAK;IAE9B,MAAM;MAAEiB,MAAM;MAAEP,IAAI;AAAEQ,MAAAA;AAAS,KAAE,GAAGlB,KAAK;AAEzC;AACA;AACA;IACA,MAAMmB,wBAAwB,GAAIC,MAAkB,I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I,EAAE;AACR,MAAA;AACF,IAAA;AACF,EAAA,CAAC,CAAC;AACF;EAEA,MAAM;IAAEP,MAAM;IAAEP,IAAI;AAAED,IAAAA;AAAO,GAAE,GAAGH,KAAK;EACvC,MAAM;AAAEiB,IAAAA;AAAO,GAAE,GAAGvB,KAAK;AAEzB,EAAA,oBACEyB,cAAA,CAAA,KAAA,EAAA;AAAKC,IAAAA,SAAS,EAAC,UAAU;AAAC,IAAA,WAAA,EAAU,WAAW;AAACC,IAAAA,IAAI,EAAC,OAAO;IAAAC,QAAA,eAC1DH,cAAA,CAACI,kCAAa,EAAA;AACZC,MAAAA,OAAO,EAAE7B,OAAQ;AACjB8B,MAAAA,EAAE,EAAEtB,OAAQ;AACZuB,MAAAA,UAAU,EAAC,0BAA0B;AACrCT,MAAAA,OAAO,EAAE;AACPU,QAAAA,MAAM,EAAE,CAAC;AACTC,QAAAA,KAAK,EAAEX,OAAO;AACdY,QAAAA,IAAI,EAAErC;OACN;MACFsC,aAAa,EAAA,IAAA;MAAAR,QAAA,eAEbS,eAAA,CAACC,YAAI,EAAA;AAACC,QAAAA,GAAG,EAAEtC,OAAQ;AAACuC,QAAAA,EAAE,EAAC,MAAM;AAACd,QAAAA,SAAS,EAAC,gBAAgB;AAAAE,QAAAA,QAAA,GACrDlB,IAAI,EACJO,MAAM,gBACLQ,cAAA,CAACgB,uBAAM,EAAA;AAACf,UAAAA,SAAS,EAAC,wBAAwB;UAACgB,EAAE,EAAA,IAAA;AAACC,UAAAA,IAAI,EAAC,IAAI;UAACC,OAAO,EAAE3B,MAAM,CAAC2B,OAAQ;UAAAhB,QAAA,EAC7EX,MAAM,CAAC4B;SACF,CAAC,GACP,IAAI;OACJ;KACO;AACjB,GAAK,CAAC;AAEV;AAEA,qBAAeC,sBAAc,CAAC/C,QAAQ,CAAC;;;"}
1
+ {"version":3,"file":"Snackbar.js","sources":["../../src/Snackbar/Snackbar.tsx"],"sourcesContent":["import { Tags } from '@transferwise/icons';\nimport { CSSTransition } from 'react-transition-group';\n\nimport Button, { type ButtonReferenceType } from '../Button';\nimport Body from '../Body';\nimport { LiveRegion } from '../common';\nimport type { ThemeDark, ThemeLight } from '../common';\nimport { PrimitivePrompt } from '../Prompt/PrimitivePrompt';\nimport ProcessIndicator from '../ProcessIndicator';\nimport type { Sentiment } from '../SentimentSurface';\nimport StatusIcon from '../StatusIcon';\n\nimport { SNACKBAR_ENTER_DURATION, SNACKBAR_EXIT_DURATION } from './constants';\nimport type { SnackbarAction, SnackbarDuration } from './Snackbar.types';\nimport useSnackbarAutoDismiss from './useSnackbarAutoDismiss';\n\n/**\n * Props for the controlled Snackbar surface, including provider-managed lifecycle controls.\n * Use SnackbarCreationProps when creating notifications through SnackbarProvider/useSnackbar.\n */\nexport interface SnackbarProps {\n /** One optional callback or navigation action. Activating it dismisses after its callback runs. */\n action?: SnackbarAction;\n /** Changes for each new Snackbar so LiveRegion re-announces it. */\n announcementKey: number;\n /**\n * Controls auto-dismiss with a four-second, six-second or indefinite duration after entry finishes.\n * Takes precedence over the deprecated `timeout`.\n * When neither option is supplied, the default is 4000ms (previously 4500ms).\n * @default 'default'\n */\n duration?: SnackbarDuration;\n /**\n * Replaces the media with a progress indicator, uses neutral styling and prevents auto-dismiss.\n * Takes precedence over `media`, `sentiment`, `duration` and the deprecated `timeout`.\n * @default false\n */\n loading?: boolean;\n /** Overrides sentiment-derived media with content for the 24×24px media slot. */\n media?: React.ReactNode;\n /** Requests an exit; the provider retains the surface until onExited confirms it has finished. */\n onDismissRequest: () => void;\n /** Called after the exit animation so the provider can unmount active or show its replacement. */\n onExited: () => void;\n /**\n * Controls the sentiment surface and default media.\n * @default 'neutral'\n */\n sentiment?: Sentiment;\n /** Message content. Empty strings or absent text dismiss without creating a blank replacement. */\n text: React.ReactNode;\n /** @deprecated Has no effect. Snackbar theming is based on ThemeProvider. */\n theme?: ThemeLight | ThemeDark;\n /**\n * @deprecated Use `duration` instead. Explicit millisecond values remain supported and are not\n * automatically remapped when no `duration` is supplied.\n * To migrate, use `default` for 0–5000ms, `extended` for values above 5000ms, and `indefinite`\n * for intentionally persistent notifications.\n */\n timeout?: number;\n /** @deprecated Has no effect when using SnackbarProvider, which manages Snackbar identity. */\n timestamp?: number;\n /** Controls entry/exit; the surface does not manage visibility itself. */\n visible: boolean;\n}\n\nexport const Snackbar = ({\n action,\n announcementKey,\n duration,\n loading = false,\n media,\n onDismissRequest,\n onExited,\n sentiment = 'neutral',\n text,\n timeout,\n visible,\n}: SnackbarProps) => {\n const { handleBlur, handleEntered, handleFocus, handleMouseEnter, handleMouseLeave, surfaceRef } =\n useSnackbarAutoDismiss({\n duration,\n loading,\n onDismissRequest,\n timeout,\n visible,\n });\n\n const handleActionClick: React.MouseEventHandler<ButtonReferenceType> = (event) => {\n try {\n action?.onClick?.(event);\n } finally {\n onDismissRequest();\n }\n };\n\n const renderMedia = () => {\n if (loading) {\n return (\n <ProcessIndicator\n className=\"wds-Snackbar__process-indicator\"\n data-testid=\"Snackbar_ProcessIndicator\"\n size=\"xs\"\n />\n );\n }\n\n if (media) {\n return <span className=\"wds-Snackbar__media-asset\">{media}</span>;\n }\n\n if (sentiment === 'proposition') {\n return (\n <span className=\"wds-Snackbar__media-asset\">\n <Tags aria-hidden size={24} />\n </span>\n );\n }\n\n return <StatusIcon sentiment={sentiment} size={24} />;\n };\n\n return (\n <div\n className=\"wds-Snackbar\"\n style={\n {\n '--Snackbar-enter-duration': `${SNACKBAR_ENTER_DURATION}ms`,\n '--Snackbar-exit-duration': `${SNACKBAR_EXIT_DURATION}ms`,\n } as React.CSSProperties\n }\n >\n <CSSTransition\n appear\n nodeRef={surfaceRef}\n in={visible}\n classNames=\"wds-Snackbar-container\"\n timeout={{\n appear: SNACKBAR_ENTER_DURATION,\n enter: SNACKBAR_ENTER_DURATION,\n exit: SNACKBAR_EXIT_DURATION,\n }}\n unmountOnExit\n onEntered={handleEntered}\n onExited={onExited}\n >\n <PrimitivePrompt\n ref={surfaceRef}\n className=\"wds-Snackbar-container\"\n sentiment={loading ? 'neutral' : sentiment}\n emphasis=\"elevated\"\n media={renderMedia()}\n onDismiss={onDismissRequest}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n <div className=\"wds-Snackbar__content\">\n <LiveRegion\n aria-live=\"polite\"\n announceOnChange={announcementKey}\n className=\"wds-Snackbar__message\"\n >\n <Body as=\"span\" className=\"wds-Snackbar__body\">\n {text}\n </Body>\n </LiveRegion>\n {action ? (\n <Button\n className=\"wds-Snackbar__action\"\n v2\n size=\"sm\"\n priority=\"secondary\"\n href={action.href}\n target={action.target}\n onClick={handleActionClick}\n >\n {action.label}\n </Button>\n ) : null}\n </div>\n </PrimitivePrompt>\n </CSSTransition>\n </div>\n );\n};\n\nexport default Snackbar;\n"],"names":["Snackbar","action","announcementKey","duration","loading","media","onDismissRequest","onExited","sentiment","text","timeout","visible","handleBlur","handleEntered","handleFocus","handleMouseEnter","handleMouseLeave","surfaceRef","useSnackbarAutoDismiss","handleActionClick","event","onClick","renderMedia","_jsx","ProcessIndicator","className","size","children","Tags","StatusIcon","style","SNACKBAR_ENTER_DURATION","SNACKBAR_EXIT_DURATION","CSSTransition","appear","nodeRef","in","classNames","enter","exit","unmountOnExit","onEntered","PrimitivePrompt","ref","emphasis","onDismiss","onMouseEnter","onMouseLeave","onFocus","onBlur","_jsxs","LiveRegion","announceOnChange","Body","as","Button","v2","priority","href","target","label"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEO,MAAMA,QAAQ,GAAGA,CAAC;EACvBC,MAAM;EACNC,eAAe;EACfC,QAAQ;AACRC,EAAAA,OAAO,GAAG,KAAK;EACfC,KAAK;EACLC,gBAAgB;EAChBC,QAAQ;AACRC,EAAAA,SAAS,GAAG,SAAS;EACrBC,IAAI;EACJC,OAAO;AACPC,EAAAA;AAAO,CACO,KAAI;EAClB,MAAM;IAAEC,UAAU;IAAEC,aAAa;I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,CAAC8B,YAAI,EAAA;AAACC,cAAAA,EAAE,EAAC,MAAM;AAAC7B,cAAAA,SAAS,EAAC,oBAAoB;AAAAE,cAAAA,QAAA,EAC3ClB;aACG;AACR,WAAY,CACZ,EAACR,MAAM,gBACLsB,cAAA,CAACgC,uBAAM,EAAA;AACL9B,YAAAA,SAAS,EAAC,sBAAsB;YAChC+B,EAAE,EAAA,IAAA;AACF9B,YAAAA,IAAI,EAAC,IAAI;AACT+B,YAAAA,QAAQ,EAAC,WAAW;YACpBC,IAAI,EAAEzD,MAAM,CAACyD,IAAK;YAClBC,MAAM,EAAE1D,MAAM,CAAC0D,MAAO;AACtBtC,YAAAA,OAAO,EAAEF,iBAAkB;YAAAQ,QAAA,EAE1B1B,MAAM,CAAC2D;WACF,CAAC,GACP,IAAI;SACL;OACU;KACJ;AACjB,GAAK,CAAC;AAEV;;"}
@@ -1,123 +1,157 @@
1
- import { useRef, useState, useEffect, useLayoutEffect } from 'react';
1
+ import { Tags } from '@transferwise/icons';
2
2
  import { CSSTransition } from 'react-transition-group';
3
3
  import Button from '../Button/Button.resolver.mjs';
4
4
  import Body from '../Body/Body.mjs';
5
- import withNextPortalWrapper from '../WithNextPortal/WithNextPortal.mjs';
5
+ import '../common/theme.mjs';
6
+ import '../common/direction.mjs';
7
+ import '@transferwise/neptune-tokens';
8
+ import '../common/PropsValues/control.mjs';
9
+ import '../common/PropsValues/size.mjs';
10
+ import '../common/PropsValues/typography.mjs';
11
+ import '../common/PropsValues/width.mjs';
12
+ import '../common/PropsValues/type.mjs';
13
+ import '../common/PropsValues/dateMode.mjs';
14
+ import '../common/PropsValues/monthFormat.mjs';
15
+ import '../common/PropsValues/position.mjs';
16
+ import '../common/PropsValues/layouts.mjs';
17
+ import '../common/PropsValues/status.mjs';
18
+ import '../common/PropsValues/sentiment.mjs';
19
+ import '../common/PropsValues/profileType.mjs';
20
+ import '../common/PropsValues/variant.mjs';
21
+ import '../common/PropsValues/scroll.mjs';
22
+ import '../common/PropsValues/markdownNodeType.mjs';
23
+ import '../common/fileType.mjs';
24
+ import '@transferwise/formatting';
25
+ import 'clsx';
26
+ import 'react';
27
+ import 'react-intl';
28
+ import '../common/CloseButton/CloseButton.messages.mjs';
6
29
  import { jsx, jsxs } from 'react/jsx-runtime';
30
+ import { LiveRegion } from '../common/LiveRegion/LiveRegion.mjs';
31
+ import { PrimitivePrompt } from '../Prompt/PrimitivePrompt/PrimitivePrompt.mjs';
32
+ import ProcessIndicator from '../ProcessIndicator/ProcessIndicator.mjs';
33
+ import StatusIcon from '../StatusIcon/StatusIcon.mjs';
34
+ import { SNACKBAR_EXIT_DURATION, SNACKBAR_ENTER_DURATION } from './constants.mjs';
35
+ import useSnackbarAutoDismiss from './useSnackbarAutoDismiss.mjs';
7
36
 
8
- const CSS_TRANSITION_DURATION = 400;
9
- const Snackbar = props => {
10
- const bodyRef = useRef(null);
11
- const leaveTimeout = useRef(0);
12
- const transitionTimeout = useRef(0);
13
- /** The props of the last committed render, as `this.props` was in the class component. */
14
- const committedProps = useRef(props);
15
- const [state, setState] = useState({
16
- visible: false,
17
- text: ''
37
+ const Snackbar = ({
38
+ action,
39
+ announcementKey,
40
+ duration,
41
+ loading = false,
42
+ media,
43
+ onDismissRequest,
44
+ onExited,
45
+ sentiment = 'neutral',
46
+ text,
47
+ timeout,
48
+ visible
49
+ }) => {
50
+ const {
51
+ handleBlur,
52
+ handleEntered,
53
+ handleFocus,
54
+ handleMouseEnter,
55
+ handleMouseLeave,
56
+ surfaceRef
57
+ } = useSnackbarAutoDismiss({
58
+ duration,
59
+ loading,
60
+ onDismissRequest,
61
+ timeout,
62
+ visible
18
63
  });
19
- useEffect(() => () => {
20
- window.clearTimeout(leaveTimeout.current);
21
- window.clearTimeout(transitionTimeout.current);
22
- }, []);
23
- // Runs after every render to mirror the componentDidUpdate lifecycle this component previously
24
- // relied on, including the shouldComponentUpdate guard that ignored every update without text.
25
- // Layout, not passive, so a notification is shown or replaced before the browser paints, as
26
- // componentDidUpdate did. Both rules below are disabled on purpose: the dependency-less effect
27
- // and its synchronous state updates are what keep this conversion behaviour-identical.
28
- /* eslint-disable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
29
- useLayoutEffect(() => {
30
- const previousProps = committedProps.current;
31
- committedProps.current = props;
32
- const {
33
- action,
34
- text,
35
- timestamp
36
- } = props;
37
- // shouldComponentUpdate bailed out whenever the incoming text was empty. That also blocked the
38
- // updates scheduled below, so a Snackbar whose text is cleared stays on screen until it is
39
- // given text again. Preserved here deliberately to keep this refactor behaviour-identical.
40
- const updateWhileTextIsPresent = update => {
41
- if (committedProps.current.text) {
42
- update();
43
- }
44
- };
45
- const setLeaveTimeout = () => {
46
- leaveTimeout.current = window.setTimeout(() => {
47
- updateWhileTextIsPresent(() => setState(current => ({
48
- ...current,
49
- visible: false
50
- })));
51
- }, committedProps.current.timeout);
52
- };
53
- const show = () => {
54
- setState(current => ({
55
- ...current,
56
- visible: true,
57
- action,
58
- text
59
- }));
60
- setLeaveTimeout();
61
- };
62
- if (!text) {
63
- return;
64
+ const handleActionClick = event => {
65
+ try {
66
+ action?.onClick?.(event);
67
+ } finally {
68
+ onDismissRequest();
64
69
  }
65
- if (!previousProps.text) {
66
- show();
67
- } else if (previousProps.timestamp !== timestamp) {
68
- window.clearTimeout(leaveTimeout.current);
69
- if (state.visible) {
70
- setState(current => ({
71
- ...current,
72
- visible: false
73
- }));
74
- transitionTimeout.current = window.setTimeout(() => {
75
- updateWhileTextIsPresent(show);
76
- }, CSS_TRANSITION_DURATION);
77
- } else {
78
- show();
79
- }
70
+ };
71
+ const renderMedia = () => {
72
+ if (loading) {
73
+ return /*#__PURE__*/jsx(ProcessIndicator, {
74
+ className: "wds-Snackbar__process-indicator",
75
+ "data-testid": "Snackbar_ProcessIndicator",
76
+ size: "xs"
77
+ });
80
78
  }
81
- });
82
- /* eslint-enable react-hooks/exhaustive-deps, react-hooks/set-state-in-effect */
83
- const {
84
- action,
85
- text,
86
- visible
87
- } = state;
88
- const {
89
- timeout
90
- } = props;
79
+ if (media) {
80
+ return /*#__PURE__*/jsx("span", {
81
+ className: "wds-Snackbar__media-asset",
82
+ children: media
83
+ });
84
+ }
85
+ if (sentiment === 'proposition') {
86
+ return /*#__PURE__*/jsx("span", {
87
+ className: "wds-Snackbar__media-asset",
88
+ children: /*#__PURE__*/jsx(Tags, {
89
+ "aria-hidden": true,
90
+ size: 24
91
+ })
92
+ });
93
+ }
94
+ return /*#__PURE__*/jsx(StatusIcon, {
95
+ sentiment: sentiment,
96
+ size: 24
97
+ });
98
+ };
91
99
  return /*#__PURE__*/jsx("div", {
92
- className: "snackbar",
93
- "aria-live": "assertive",
94
- role: "alert",
100
+ className: "wds-Snackbar",
101
+ style: {
102
+ '--Snackbar-enter-duration': `${SNACKBAR_ENTER_DURATION}ms`,
103
+ '--Snackbar-exit-duration': `${SNACKBAR_EXIT_DURATION}ms`
104
+ },
95
105
  children: /*#__PURE__*/jsx(CSSTransition, {
96
- nodeRef: bodyRef,
106
+ appear: true,
107
+ nodeRef: surfaceRef,
97
108
  in: visible,
98
- classNames: "snackbar__text-container",
109
+ classNames: "wds-Snackbar-container",
99
110
  timeout: {
100
- appear: 0,
101
- enter: timeout,
102
- exit: CSS_TRANSITION_DURATION
111
+ appear: SNACKBAR_ENTER_DURATION,
112
+ enter: SNACKBAR_ENTER_DURATION,
113
+ exit: SNACKBAR_EXIT_DURATION
103
114
  },
104
115
  unmountOnExit: true,
105
- children: /*#__PURE__*/jsxs(Body, {
106
- ref: bodyRef,
107
- as: "span",
108
- className: "snackbar__text",
109
- children: [text, action ? /*#__PURE__*/jsx(Button, {
110
- className: "snackbar__text__action",
111
- v2: true,
112
- size: "sm",
113
- onClick: action.onClick,
114
- children: action.label
115
- }) : null]
116
+ onEntered: handleEntered,
117
+ onExited: onExited,
118
+ children: /*#__PURE__*/jsx(PrimitivePrompt, {
119
+ ref: surfaceRef,
120
+ className: "wds-Snackbar-container",
121
+ sentiment: loading ? 'neutral' : sentiment,
122
+ emphasis: "elevated",
123
+ media: renderMedia(),
124
+ onDismiss: onDismissRequest,
125
+ onMouseEnter: handleMouseEnter,
126
+ onMouseLeave: handleMouseLeave,
127
+ onFocus: handleFocus,
128
+ onBlur: handleBlur,
129
+ children: /*#__PURE__*/jsxs("div", {
130
+ className: "wds-Snackbar__content",
131
+ children: [/*#__PURE__*/jsx(LiveRegion, {
132
+ "aria-live": "polite",
133
+ announceOnChange: announcementKey,
134
+ className: "wds-Snackbar__message",
135
+ children: /*#__PURE__*/jsx(Body, {
136
+ as: "span",
137
+ className: "wds-Snackbar__body",
138
+ children: text
139
+ })
140
+ }), action ? /*#__PURE__*/jsx(Button, {
141
+ className: "wds-Snackbar__action",
142
+ v2: true,
143
+ size: "sm",
144
+ priority: "secondary",
145
+ href: action.href,
146
+ target: action.target,
147
+ onClick: handleActionClick,
148
+ children: action.label
149
+ }) : null]
150
+ })
116
151
  })
117
152
  })
118
153
  });
119
154
  };
120
- var SnackbarPortal = withNextPortalWrapper(Snackbar);
121
155
 
122
- export { Snackbar, SnackbarPortal as default };
156
+ export { Snackbar };
123
157
  //# sourceMappingURL=Snackbar.mjs.map