Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui-presets / dist / presets / AutoDismissingSnackBar / AutoDismissingSnackBar.js
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const tslib_1 = require("tslib");

const react_1 = tslib_1.__importDefault(require("react"));

const mobx_react_1 = require("xmobx/mobx-react");

const mobx_1 = require("xmobx/mobx");

const exotic_1 = require("exotic");

const common_1 = require("@skava/ui/dist/state/common");

const utils_1 = require("@skava/utils");

const deps_1 = require("./deps");

const renderProps_1 = require("./renderProps");

let AutoDismissingSnackBar = class AutoDismissingSnackBar extends react_1.default.Component {
  constructor() {
    super(...arguments);
    this.observableState = common_1.toCommonState(this.props);

    this.onAfterClose = () => {
      console.info('[AutoDismissingSnackBar] onAfterClose');
      const {
        onAutoDismiss,
        animationDuration
      } = this.props;
      this.observableState.hide(); // run onRequestClose, delayed by animation timing

      this.postCloseAnimationTimer = window.setTimeout(onAutoDismiss, animationDuration);
    };

    this.handleClose = () => {
      const {
        autoDismissingDuration
      } = this.props;

      if (this.observableState.isVisible === false) {
        console.warn('[AutoDismissingSnackBar] handle close called, but it is not visible');
        return;
      } // clear any old timers


      if (this.delayedCloseTimer !== undefined) {
        window.clearTimeout(this.delayedCloseTimer);
      }

      this.delayedCloseTimer = window.setTimeout(this.onAfterClose, autoDismissingDuration);
    };
  } // when it changes, then start a timeout


  componentDidMount() {
    console.info('[AutoDismissingSnackBar] observing');
    this.disposer = mobx_1.observe(this.observableState, 'isVisible', this.handleClose);
  }

  componentWillUnmount() {
    if (exotic_1.isFunction(this.disposer)) {
      this.disposer();
    }
  }

  render() {
    console.debug('[AutoDismissingSnackBar] render'); // could put in deps as toAutoDismissingSnackBarRemainingProps

    const remainingProps = utils_1.omit(this.props, deps_1.KNOWN_PROPS);
    return this.props.renderSnackBar(remainingProps, this.observableState);
  }

};
AutoDismissingSnackBar.defaultProps = {
  isVisible: true,
  onAutoDismiss: deps_1.ON_AUTO_DISMISS_DEFAULT,
  autoDismissingDuration: 3000,
  animationDuration: 300,
  renderSnackBar: renderProps_1.defaultRenderSnackBar
};
AutoDismissingSnackBar = tslib_1.__decorate([mobx_react_1.observer], AutoDismissingSnackBar);
exports.AutoDismissingSnackBar = AutoDismissingSnackBar;
exports.default = AutoDismissingSnackBar;