UNPKG

@geezee/react-ui

Version:

Modern and minimalist React UI library.

45 lines (38 loc) 1.36 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _extends from "@babel/runtime/helpers/esm/extends"; import { useCfxUIContext } from '../utils/use-cfx-ui-context'; import { getId } from '../utils/collections'; var defaultNotification = { delay: 2000, color: 'default', closeable: true, shadow: true, className: '', title: '', content: '', placement: 'right-start' }; var useNotifications = function useNotifications() { var _useCfxUIContext = useCfxUIContext(), updateNotifications = _useCfxUIContext.updateNotifications, notifications = _useCfxUIContext.notifications; var setNotification = function setNotification(notification) { var id = "notification-".concat(getId()); var destroy = function destroy(id) { updateNotifications(function (currentNotifications) { return currentNotifications.filter(function (item) { return item.id !== id; }); }); }; updateNotifications(function (currentNotifications) { var newNotification = _extends(_extends({}, defaultNotification), {}, { id: id, destroy: destroy }, notification); return [].concat(_toConsumableArray(currentNotifications), [newNotification]); }); }; return [notifications, setNotification]; }; export default useNotifications;