@vnmfify/core
Version:
```shell npm i @vnmfify/core -S ```
82 lines (72 loc) • 3.92 kB
JavaScript
import _isPlainObject from "lodash/isPlainObject";
import _assign from "lodash/assign";
var _excluded = ["selector"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { Events } from "@vnxjs/vnmf";
import { isValidElement, useEffect } from "react";
var initialNotifyOptions = {
className: undefined,
style: undefined,
duration: undefined,
message: undefined,
color: undefined
};
var DEFAULT_NOTIFY_SELECTOR = "#notify";
var defaultNotifyOptions = {};
resetDefaultNotifyOptions();
export function setDefaultNotifyOptions(options) {
_assign(defaultNotifyOptions, options);
}
export function resetDefaultNotifyOptions() {
_assign(defaultNotifyOptions, {
selector: DEFAULT_NOTIFY_SELECTOR
});
}
var notifyEvents = new Events();
export function useNotifyOpen(cb) {
useEffect(() => {
notifyEvents.on("open", cb);
return () => {
notifyEvents.off("open", cb);
};
}, []);
}
export function useNotifyClose(cb) {
useEffect(() => {
notifyEvents.on("close", cb);
return () => {
notifyEvents.off("close", cb);
};
}, []);
}
function parseNotifyOptions(message) {
var options = ! /*#__PURE__*/isValidElement(message) && _isPlainObject(message) ? message : {
message
};
return _assign({}, initialNotifyOptions, defaultNotifyOptions, options);
}
export function openNotify(args) {
var _parseNotifyOptions = parseNotifyOptions(args),
{
selector = "#notify"
} = _parseNotifyOptions,
restOptions = _objectWithoutProperties(_parseNotifyOptions, _excluded);
notifyEvents.trigger("open", _objectSpread({
selector
}, restOptions));
}
export function createNotify(color) {
return args => {
var options = parseNotifyOptions(args);
options.color = color;
openNotify(options);
};
}
export function closeNotify(selector) {
notifyEvents.trigger("close", selector !== null && selector !== void 0 ? selector : defaultNotifyOptions.selector);
}
//# sourceMappingURL=notify.imperative.js.map