UNPKG

@trap_stevo/legendarybuilderproreact-ui

Version:

The legendary UI & utility API that makes your application a legendary application. ~ Created by Steven Compton

87 lines 3.96 kB
import _extends from "@babel/runtime/helpers/extends"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["children"]; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React, { createContext, useContext, useState, useEffect } from 'react'; import { HUDUniversalHUDUtilityManager, Delay } from "../HUDManagers/HUDUniversalHUDUtilityManager.js"; import HUDNotification from "./HUDNotification.js"; var NotificationContext = /*#__PURE__*/createContext(); export var HUDNotificationProvider = function HUDNotificationProvider(_ref) { var children = _ref.children, rest = _objectWithoutProperties(_ref, _excluded); var _useState = useState({}), _useState2 = _slicedToArray(_useState, 2), currentNotificationData = _useState2[0], setCurrentNotificationData = _useState2[1]; var _useState3 = useState( /*#__PURE__*/React.createElement(React.Fragment, null)), _useState4 = _slicedToArray(_useState3, 2), currentNotification = _useState4[0], setCurrentNotification = _useState4[1]; var _useState5 = useState(false), _useState6 = _slicedToArray(_useState5, 2), activateNotification = _useState6[0], setActivateNotification = _useState6[1]; var _useState7 = useState("info"), _useState8 = _slicedToArray(_useState7, 2), notificationType = _useState8[0], setNotificationType = _useState8[1]; var _useState9 = useState(""), _useState10 = _slicedToArray(_useState9, 2), notificationText = _useState10[0], setNotificationText = _useState10[1]; var displayNotification = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(text, type, notificationSettings) { var displayedNotification; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: displayedNotification = /*#__PURE__*/React.createElement(HUDNotification, _extends({ message: text, type: type, motionDirection: "horizontal" }, notificationSettings)); setActivateNotification(true); setCurrentNotification(displayedNotification); _context.next = 5; return Delay(notificationSettings.duration ? notificationSettings.duration + 869 : 3869); case 5: setActivateNotification(false); return _context.abrupt("return"); case 7: case "end": return _context.stop(); } }, _callee); })); return function displayNotification(_x, _x2, _x3) { return _ref2.apply(this, arguments); }; }(); useEffect(function () { if (notificationText === "") { return function () {}; } displayNotification(notificationText, notificationType, currentNotificationData); }, [currentNotificationData, notificationText, notificationType]); return /*#__PURE__*/React.createElement(NotificationContext.Provider, { value: { currentNotification: currentNotification, currentNotificationData: currentNotificationData, setCurrentNotificationData: setCurrentNotificationData, notificationText: notificationText, setNotificationText: setNotificationText, notificationType: notificationType, setNotificationType: setNotificationType, displayNotification: displayNotification } }, children, activateNotification ? currentNotification : /*#__PURE__*/React.createElement(React.Fragment, null)); }; export var useHUDNotification = function useHUDNotification() { var context = useContext(NotificationContext); if (!context) { throw new Error('Must use within an NotificationProvider'); } return context; };