pouncejs
Version:
A collection of UI components from Panther labs
30 lines (27 loc) • 1.06 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import React from 'react';
import ControlledAlert from '../utils/ControlledAlert';
/**
* A Snackbar is a special version of Alert that gets shown as a response to a user's action in
* order to provide feedback about the outcome of his action
*/
var Snackbar = function Snackbar(_ref) {
var destroy = _ref.destroy,
_ref$duration = _ref.duration,
duration = _ref$duration === void 0 ? 6000 : _ref$duration,
rest = _objectWithoutPropertiesLoose(_ref, ["destroy", "duration"]);
var timeoutRef = React.useRef();
React.useEffect(function () {
timeoutRef.current = setTimeout(destroy, duration);
return function () {
return clearTimeout(timeoutRef.current);
};
}, [duration]);
return /*#__PURE__*/React.createElement(ControlledAlert, _extends({}, rest, {
open: true,
onClose: destroy,
variantBackgroundStyle: "solid"
}));
};
export default Snackbar;