@transferwise/components 46.8.0 → 46.9.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.
Files changed (32) hide show
  1. package/build/index.esm.js +50 -72
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +50 -72
  4. package/build/index.js.map +1 -1
  5. package/build/types/checkboxOption/CheckboxOption.d.ts +2 -2
  6. package/build/types/checkboxOption/CheckboxOption.d.ts.map +1 -1
  7. package/build/types/index.d.ts +2 -0
  8. package/build/types/index.d.ts.map +1 -1
  9. package/build/types/snackbar/Snackbar.d.ts +30 -22
  10. package/build/types/snackbar/Snackbar.d.ts.map +1 -1
  11. package/build/types/snackbar/SnackbarContext.d.ts +7 -2
  12. package/build/types/snackbar/SnackbarContext.d.ts.map +1 -1
  13. package/build/types/snackbar/SnackbarProvider.d.ts +7 -12
  14. package/build/types/snackbar/SnackbarProvider.d.ts.map +1 -1
  15. package/build/types/snackbar/index.d.ts +2 -0
  16. package/build/types/snackbar/index.d.ts.map +1 -0
  17. package/build/types/snackbar/useSnackbar.d.ts +1 -1
  18. package/build/types/snackbar/useSnackbar.d.ts.map +1 -1
  19. package/build/types/withNextPortal/withNextPortal.d.ts +1 -1
  20. package/build/types/withNextPortal/withNextPortal.d.ts.map +1 -1
  21. package/package.json +3 -3
  22. package/src/checkboxOption/CheckboxOption.tsx +2 -2
  23. package/src/index.ts +2 -0
  24. package/src/snackbar/{Snackbar.story.js → Snackbar.story.tsx} +2 -1
  25. package/src/snackbar/{Snackbar.js → Snackbar.tsx} +31 -32
  26. package/src/snackbar/SnackbarContext.ts +11 -0
  27. package/src/snackbar/SnackbarProvider.tsx +39 -0
  28. package/src/withNextPortal/withNextPortal.tsx +1 -1
  29. package/src/snackbar/SnackbarContext.js +0 -4
  30. package/src/snackbar/SnackbarProvider.js +0 -51
  31. /package/src/snackbar/{index.js → index.ts} +0 -0
  32. /package/src/snackbar/{useSnackbar.js → useSnackbar.ts} +0 -0
package/build/index.js CHANGED
@@ -2612,7 +2612,7 @@ const CheckboxOption = /*#__PURE__*/React.forwardRef(({
2612
2612
  button: /*#__PURE__*/jsxRuntime.jsx(CheckboxButton$1, {
2613
2613
  checked: checked,
2614
2614
  disabled: disabled,
2615
- onChange: () => onChange(!checked)
2615
+ onChange: () => onChange?.(!checked)
2616
2616
  })
2617
2617
  });
2618
2618
  });
@@ -11181,18 +11181,19 @@ const SegmentedControl = ({
11181
11181
 
11182
11182
  const CSS_TRANSITION_DURATION = 400;
11183
11183
  class Snackbar extends React.Component {
11184
- /** @type {RefObject<HTMLSpanElement>} */
11185
11184
  bodyRef = /*#__PURE__*/React.createRef();
11186
- constructor() {
11187
- super();
11185
+ timeout = 0;
11186
+ transitionTimeout = 0;
11187
+ constructor(props) {
11188
+ super(props);
11188
11189
  this.state = {
11189
11190
  visible: false,
11190
11191
  text: ''
11191
11192
  };
11192
11193
  }
11193
11194
  componentWillUnmount() {
11194
- clearTimeout(this.timeout);
11195
- clearTimeout(this.transitionTimeout);
11195
+ window.clearTimeout(this.timeout);
11196
+ window.clearTimeout(this.transitionTimeout);
11196
11197
  }
11197
11198
  shouldComponentUpdate(nextProps, nextState) {
11198
11199
  if (!nextProps.text) {
@@ -11207,7 +11208,7 @@ class Snackbar extends React.Component {
11207
11208
  const {
11208
11209
  timeout
11209
11210
  } = this.props;
11210
- this.timeout = setTimeout(() => {
11211
+ this.timeout = window.setTimeout(() => {
11211
11212
  this.setState({
11212
11213
  visible: false
11213
11214
  });
@@ -11230,12 +11231,12 @@ class Snackbar extends React.Component {
11230
11231
  this.setLeaveTimeout();
11231
11232
  });
11232
11233
  } else if (previousProps.timestamp !== timestamp) {
11233
- clearTimeout(this.timeout);
11234
+ window.clearTimeout(this.timeout);
11234
11235
  if (this.state.visible) {
11235
11236
  this.setState({
11236
11237
  visible: false
11237
11238
  }, () => {
11238
- this.transitionTimeout = setTimeout(() => {
11239
+ this.transitionTimeout = window.setTimeout(() => {
11239
11240
  this.setState({
11240
11241
  visible: true,
11241
11242
  action,
@@ -11260,7 +11261,7 @@ class Snackbar extends React.Component {
11260
11261
  const {
11261
11262
  action,
11262
11263
  text,
11263
- theme,
11264
+ theme = exports.Theme.LIGHT,
11264
11265
  visible
11265
11266
  } = this.state;
11266
11267
  const {
@@ -11294,74 +11295,51 @@ class Snackbar extends React.Component {
11294
11295
  }
11295
11296
  }
11296
11297
  Snackbar.contextType = DirectionContext;
11297
- Snackbar.propTypes = {
11298
- action: PropTypes__default.default.shape({
11299
- label: PropTypes__default.default.string.isRequired,
11300
- onClick: PropTypes__default.default.func
11301
- }),
11302
- text: PropTypes__default.default.node.isRequired,
11303
- theme: PropTypes__default.default.oneOf(['light', 'dark']),
11304
- timeout: PropTypes__default.default.number.isRequired,
11305
- timestamp: PropTypes__default.default.number.isRequired
11306
- };
11307
- Snackbar.defaultProps = {
11308
- action: null,
11309
- theme: exports.Theme.LIGHT
11310
- };
11311
11298
  var SnackbarPortal = withNextPortalWrapper(Snackbar);
11312
11299
 
11313
- const SnackbarContext = /*#__PURE__*/React.createContext();
11300
+ const SnackbarContext = /*#__PURE__*/React.createContext({
11301
+ createSnackbar: () => {}
11302
+ });
11314
11303
  const SnackbarConsumer = SnackbarContext.Consumer;
11315
11304
 
11316
- class SnackbarProvider extends React.Component {
11317
- constructor() {
11318
- super();
11319
- this.state = {
11320
- text: '',
11321
- timestamp: 0
11322
- };
11323
- }
11324
- create = ({
11305
+ function SnackbarProvider({
11306
+ timeout = 4500,
11307
+ children
11308
+ }) {
11309
+ const [state, setState] = React.useState({
11310
+ text: '',
11311
+ timestamp: 0
11312
+ });
11313
+ const {
11325
11314
  action,
11326
11315
  text,
11327
- theme
11328
- }) => {
11329
- this.setState({
11330
- action,
11331
- text,
11332
- theme,
11333
- timestamp: Date.now()
11334
- });
11335
- };
11336
- render() {
11337
- const {
11338
- action,
11339
- text,
11340
- theme,
11341
- timestamp
11342
- } = this.state;
11343
- return /*#__PURE__*/jsxRuntime.jsxs(SnackbarContext.Provider, {
11344
- value: {
11345
- createSnackbar: this.create
11346
- },
11347
- children: [/*#__PURE__*/jsxRuntime.jsx(SnackbarPortal, {
11348
- action: action,
11349
- text: text,
11350
- timestamp: timestamp,
11351
- timeout: this.props.timeout,
11352
- theme: theme
11353
- }), this.props.children]
11354
- });
11355
- }
11316
+ theme,
11317
+ timestamp
11318
+ } = state;
11319
+ return /*#__PURE__*/jsxRuntime.jsxs(SnackbarContext.Provider, {
11320
+ value: React.useMemo(() => ({
11321
+ createSnackbar: ({
11322
+ action,
11323
+ text,
11324
+ theme
11325
+ }) => {
11326
+ setState({
11327
+ action,
11328
+ text,
11329
+ theme,
11330
+ timestamp: Date.now()
11331
+ });
11332
+ }
11333
+ }), []),
11334
+ children: [/*#__PURE__*/jsxRuntime.jsx(SnackbarPortal, {
11335
+ action: action,
11336
+ text: text,
11337
+ timestamp: timestamp,
11338
+ timeout: timeout,
11339
+ theme: theme
11340
+ }), children]
11341
+ });
11356
11342
  }
11357
- SnackbarProvider.propTypes = {
11358
- children: PropTypes__default.default.node.isRequired,
11359
- timeout: PropTypes__default.default.number
11360
- };
11361
- SnackbarProvider.defaultProps = {
11362
- timeout: 4500
11363
- };
11364
- var SnackbarProvider$1 = SnackbarProvider;
11365
11343
 
11366
11344
  const Sticky = ({
11367
11345
  open,
@@ -15655,7 +15633,7 @@ exports.SlidingPanel = SlidingPanel$1;
15655
15633
  exports.SnackbarConsumer = SnackbarConsumer;
15656
15634
  exports.SnackbarContext = SnackbarContext;
15657
15635
  exports.SnackbarPortal = SnackbarPortal;
15658
- exports.SnackbarProvider = SnackbarProvider$1;
15636
+ exports.SnackbarProvider = SnackbarProvider;
15659
15637
  exports.StatusIcon = StatusIcon;
15660
15638
  exports.Stepper = Stepper;
15661
15639
  exports.Sticky = Sticky$1;