@trap_stevo/legendarybuilderproreact-ui
Version:
The legendary UI & utility API that makes your application a legendary application. ~ Created by Steven Compton
287 lines • 16.3 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import * as React from 'react';
import { useState, useEffect, useRef, useCallback } from 'react';
import { HUDUniversalHUDUtilityManager, Delay } from "../HUDManagers/HUDUniversalHUDUtilityManager.js";
import { useTimeout } from "../HUDManagers/HUDUniversalHUDEventEffectsManager.js";
import { motion } from "framer-motion";
import HUDTyper from "./HUDTyper.js";
import HUDIcon from "./HUDIcon.js";
function HUDNotificationBanner(_ref) {
var _ref$notificationBann = _ref.notificationBannerClosingInitialAnimationConfigurationSettings,
notificationBannerClosingInitialAnimationConfigurationSettings = _ref$notificationBann === void 0 ? {} : _ref$notificationBann,
_ref$notificationBann2 = _ref.notificationBannerAnimationTransitionConfigurationSettings,
notificationBannerAnimationTransitionConfigurationSettings = _ref$notificationBann2 === void 0 ? {} : _ref$notificationBann2,
_ref$notificationBann3 = _ref.notificationBannerClosingAnimationConfigurationSettings,
notificationBannerClosingAnimationConfigurationSettings = _ref$notificationBann3 === void 0 ? {} : _ref$notificationBann3,
_ref$notificationBann4 = _ref.notificationBannerInitialAnimationConfigurationSettings,
notificationBannerInitialAnimationConfigurationSettings = _ref$notificationBann4 === void 0 ? {} : _ref$notificationBann4,
_ref$notificationBann5 = _ref.notificationBannerMessageContentConfigurationSettings,
notificationBannerMessageContentConfigurationSettings = _ref$notificationBann5 === void 0 ? {} : _ref$notificationBann5,
_ref$navigationBanner = _ref.navigationBannerCloseButtonHoverConfigurationSettings,
navigationBannerCloseButtonHoverConfigurationSettings = _ref$navigationBanner === void 0 ? {} : _ref$navigationBanner,
_ref$navigationBanner2 = _ref.navigationBannerCloseButtonConfigurationSettings,
navigationBannerCloseButtonConfigurationSettings = _ref$navigationBanner2 === void 0 ? {} : _ref$navigationBanner2,
_ref$notificationBann6 = _ref.notificationBannerAnimationConfigurationSettings,
notificationBannerAnimationConfigurationSettings = _ref$notificationBann6 === void 0 ? {} : _ref$notificationBann6,
_ref$notificationBann7 = _ref.notificationBannerContentConfigurationSettings,
notificationBannerContentConfigurationSettings = _ref$notificationBann7 === void 0 ? {} : _ref$notificationBann7,
_ref$notificationBann8 = _ref.notificationBannerConfigurationSettings,
notificationBannerConfigurationSettings = _ref$notificationBann8 === void 0 ? {} : _ref$notificationBann8,
_ref$notificationBann9 = _ref.notificationBannerMessageContentConfigurations,
notificationBannerMessageContentConfigurations = _ref$notificationBann9 === void 0 ? {} : _ref$notificationBann9,
_ref$notificationBann10 = _ref.notificationBannerCloseButtonConfigurations,
notificationBannerCloseButtonConfigurations = _ref$notificationBann10 === void 0 ? {} : _ref$notificationBann10,
_ref$notificationBann11 = _ref.notificationBannerContentConfigurations,
notificationBannerContentConfigurations = _ref$notificationBann11 === void 0 ? {} : _ref$notificationBann11,
_ref$notificationBann12 = _ref.notificationBannerIconConfigurations,
notificationBannerIconConfigurations = _ref$notificationBann12 === void 0 ? {} : _ref$notificationBann12,
_ref$notificationBann13 = _ref.notificationBannerConfigurations,
notificationBannerConfigurations = _ref$notificationBann13 === void 0 ? {} : _ref$notificationBann13,
_ref$onNotificationBa = _ref.onNotificationBannerClick,
onNotificationBannerClick = _ref$onNotificationBa === void 0 ? null : _ref$onNotificationBa,
_ref$onNotificationAc = _ref.onNotificationAction,
onNotificationAction = _ref$onNotificationAc === void 0 ? null : _ref$onNotificationAc,
_ref$onClose = _ref.onClose,
onClose = _ref$onClose === void 0 ? null : _ref$onClose,
_ref$onOpen = _ref.onOpen,
onOpen = _ref$onOpen === void 0 ? null : _ref$onOpen,
_ref$notificationBann14 = _ref.notificationBannerCloseButtonHoverColor,
notificationBannerCloseButtonHoverColor = _ref$notificationBann14 === void 0 ? "#ffffff" : _ref$notificationBann14,
_ref$notificationBann15 = _ref.notificationBannerCloseButtonColor,
notificationBannerCloseButtonColor = _ref$notificationBann15 === void 0 ? "#fcfbfa" : _ref$notificationBann15,
_ref$notificationBann16 = _ref.notificationBannerBackgroundHoverColor,
notificationBannerBackgroundHoverColor = _ref$notificationBann16 === void 0 ? "#ff936b" : _ref$notificationBann16,
_ref$notificationBann17 = _ref.notificationBannerForegroundHoverColor,
notificationBannerForegroundHoverColor = _ref$notificationBann17 === void 0 ? "#ffffff" : _ref$notificationBann17,
_ref$notificationBann18 = _ref.notificationBannerBackgroundColor,
notificationBannerBackgroundColor = _ref$notificationBann18 === void 0 ? "#FF7F50" : _ref$notificationBann18,
_ref$notificationBann19 = _ref.notificationBannerForegroundColor,
notificationBannerForegroundColor = _ref$notificationBann19 === void 0 ? "#fcfbfa" : _ref$notificationBann19,
_ref$notificationBann20 = _ref.notificationBannerIconHoverColor,
notificationBannerIconHoverColor = _ref$notificationBann20 === void 0 ? "#ffffff" : _ref$notificationBann20,
_ref$notificationBann21 = _ref.notificationBannerIconColor,
notificationBannerIconColor = _ref$notificationBann21 === void 0 ? "#fcfbfa" : _ref$notificationBann21,
_ref$notificationIcon = _ref.notificationIcon,
notificationIcon = _ref$notificationIcon === void 0 ? "exclamation-triangle" : _ref$notificationIcon,
_ref$notificationClos = _ref.notificationCloseButtonIcon,
notificationCloseButtonIcon = _ref$notificationClos === void 0 ? "times" : _ref$notificationClos,
_ref$initialMessageCo = _ref.initialMessageContent,
initialMessageContent = _ref$initialMessageCo === void 0 ? null : _ref$initialMessageCo,
_ref$notificationDura = _ref.notificationDuration,
notificationDuration = _ref$notificationDura === void 0 ? null : _ref$notificationDura,
_ref$activateNotifica = _ref.activateNotificationActionInterval,
activateNotificationActionInterval = _ref$activateNotifica === void 0 ? true : _ref$activateNotifica,
_ref$notificationActi = _ref.notificationActionIntervalCount,
notificationActionIntervalCount = _ref$notificationActi === void 0 ? Infinity : _ref$notificationActi,
_ref$notificationActi2 = _ref.notificationActionInterval,
notificationActionInterval = _ref$notificationActi2 === void 0 ? 5000 : _ref$notificationActi2,
_ref$notificationClos2 = _ref.notificationClosesAfter,
notificationClosesAfter = _ref$notificationClos2 === void 0 ? 1269 : _ref$notificationClos2,
_ref$notificationOpen = _ref.notificationOpensAfter,
notificationOpensAfter = _ref$notificationOpen === void 0 ? 169 : _ref$notificationOpen,
_ref$notificationDeci = _ref.notificationDecidesWhenToAppear,
notificationDecidesWhenToAppear = _ref$notificationDeci === void 0 ? true : _ref$notificationDeci,
_ref$showNotification = _ref.showNotificationOnRender,
showNotificationOnRender = _ref$showNotification === void 0 ? false : _ref$showNotification,
_ref$showCloseButton = _ref.showCloseButton,
showCloseButton = _ref$showCloseButton === void 0 ? true : _ref$showCloseButton,
_ref$closeNotificatio = _ref.closeNotification,
closeNotification = _ref$closeNotificatio === void 0 ? false : _ref$closeNotificatio,
_ref$openNotification = _ref.openNotification,
openNotification = _ref$openNotification === void 0 ? false : _ref$openNotification;
var _useTimeout = useTimeout({
multiple: true
}),
schedule = _useTimeout.schedule;
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
navigationBannerCloseButtonHover = _useState2[0],
setNavigationBannerCloseButtonHover = _useState2[1];
var _useState3 = useState(false),
_useState4 = _slicedToArray(_useState3, 2),
notificationBannerHover = _useState4[0],
setNotificationBannerHover = _useState4[1];
var _useState5 = useState(initialMessageContent),
_useState6 = _slicedToArray(_useState5, 2),
messageContent = _useState6[0],
setMessageContent = _useState6[1];
var _useState7 = useState(false),
_useState8 = _slicedToArray(_useState7, 2),
notificationClosing = _useState8[0],
setNotificationClosing = _useState8[1];
var _useState9 = useState(true),
_useState10 = _slicedToArray(_useState9, 2),
notificationClosed = _useState10[0],
setNotificationClosed = _useState10[1];
var currentNotificationActionIntervalCount = useRef(0);
var notificationActionIntervalID = useRef(null);
var notificationActionLoaded = useRef(false);
var handleClose = useCallback(function (e) {
if (e) {
e.stopPropagation();
}
setNotificationBannerHover(false);
setNotificationClosing(true);
schedule(function () {
setNotificationClosing(false);
setNotificationClosed(true);
if (onClose) {
onClose();
}
}, notificationClosesAfter);
}, [notificationClosesAfter, onClose]);
var handleOpen = useCallback(function (e) {
schedule(function () {
setNotificationClosed(false);
if (onOpen) {
onOpen();
}
}, notificationOpensAfter);
}, [notificationOpensAfter, onOpen]);
var handleNotificationBannerClick = useCallback(function (e) {
if (onNotificationBannerClick) {
onNotificationBannerClick(e, handleClose);
}
}, [onNotificationBannerClick]);
useEffect(function () {
if (!showNotificationOnRender || !notificationClosed) {
return;
}
handleOpen();
}, [notificationClosed, showNotificationOnRender, notificationOpensAfter, handleOpen]);
useEffect(function () {
setMessageContent(initialMessageContent);
}, [initialMessageContent]);
useEffect(function () {
if (!notificationDecidesWhenToAppear || !onNotificationAction || notificationActionLoaded.current) {
return;
}
if (activateNotificationActionInterval) {
onNotificationAction(notificationClosed, setMessageContent, handleOpen, handleClose);
notificationActionIntervalID.current = setInterval(function () {
if (currentNotificationActionIntervalCount.current >= notificationActionIntervalCount) {
clearInterval(notificationActionIntervalID.current);
return;
}
onNotificationAction(notificationClosed, setMessageContent, handleOpen, handleClose);
currentNotificationActionIntervalCount.current += 1;
}, notificationActionInterval);
notificationActionLoaded.current = true;
return;
}
onNotificationAction(notificationClosed, setMessageContent, handleOpen, handleClose);
notificationActionLoaded.current = true;
}, [notificationClosed, notificationDecidesWhenToAppear, onNotificationAction, activateNotificationActionInterval, notificationActionIntervalCount, notificationActionInterval, setMessageContent, handleOpen, handleClose]);
useEffect(function () {
if (notificationDuration === null || notificationDuration === undefined || typeof notificationDuration !== "number" || notificationClosed) {
return;
}
schedule(function () {
handleClose();
}, notificationDuration);
}, [notificationClosed, notificationDuration, handleClose]);
useEffect(function () {
if (!closeNotification || notificationClosed) {
return;
}
handleClose();
}, [notificationClosed, closeNotification, handleClose]);
useEffect(function () {
if (!openNotification || !notificationClosed) {
return;
}
handleOpen();
}, [notificationClosed, openNotification, handleOpen]);
return /*#__PURE__*/React.createElement(React.Fragment, null, !notificationClosed ? /*#__PURE__*/React.createElement(motion.div, _extends({
initial: notificationClosing ? _objectSpread({
y: 0
}, notificationBannerClosingInitialAnimationConfigurationSettings) : _objectSpread({
x: 5000
}, notificationBannerInitialAnimationConfigurationSettings),
animate: notificationClosing ? _objectSpread({
y: -500
}, notificationBannerClosingAnimationConfigurationSettings) : _objectSpread({
x: 0
}, notificationBannerAnimationConfigurationSettings),
transition: _objectSpread({
x: {
duration: 0.69,
animate: "easeOut"
}
}, notificationBannerAnimationTransitionConfigurationSettings),
style: _objectSpread({
position: "fixed",
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
userSelect: "none",
cursor: "pointer",
transition: "all 0.69s ease",
borderRadius: "0.169rem",
background: notificationBannerHover ? notificationBannerBackgroundHoverColor : notificationBannerBackgroundColor,
color: notificationBannerHover ? notificationBannerForegroundHoverColor : notificationBannerForegroundColor,
width: "100vw",
zIndex: 9999999,
paddingBottom: "3.69px",
paddingTop: "3.69px",
top: 0
}, notificationBannerConfigurationSettings),
onMouseLeave: function onMouseLeave() {
setNotificationBannerHover(false);
},
onMouseEnter: function onMouseEnter() {
setNotificationBannerHover(true);
},
onClick: handleNotificationBannerClick
}, notificationBannerConfigurations), /*#__PURE__*/React.createElement("div", _extends({
style: _objectSpread({
position: "relative",
display: "flex",
flexDirection: "row",
alignItems: "center",
overflowX: "auto",
msOverflowStyle: "none",
scrollbarWidth: "none",
maxWidth: "91.69vw",
gap: "0.69rem",
marginLeft: "0.769rem"
}, notificationBannerContentConfigurationSettings)
}, notificationBannerContentConfigurations), /*#__PURE__*/React.createElement(HUDIcon, _extends({
iconConfigurationSettings: {
fontSize: "1.269rem"
},
color: notificationBannerHover ? notificationBannerIconHoverColor : notificationBannerIconColor,
name: notificationIcon
}, notificationBannerIconConfigurations)), /*#__PURE__*/React.createElement("span", _extends({
style: _objectSpread({
display: "flex",
flexDirection: "column",
fontSize: "0.869rem",
maxWidth: "calc(100%)"
}, notificationBannerMessageContentConfigurationSettings)
}, notificationBannerMessageContentConfigurations), messageContent)), showCloseButton ? /*#__PURE__*/React.createElement(HUDIcon, _extends({
iconConfigurationSettings: navigationBannerCloseButtonHover ? _objectSpread({
scale: "1.069",
marginRight: "0.769rem"
}, navigationBannerCloseButtonHoverConfigurationSettings) : _objectSpread({
scale: "1",
marginRight: "0.769rem"
}, navigationBannerCloseButtonConfigurationSettings),
color: navigationBannerCloseButtonHover ? notificationBannerCloseButtonHoverColor : notificationBannerCloseButtonColor,
name: notificationCloseButtonIcon,
onMouseLeave: function onMouseLeave() {
return setNavigationBannerCloseButtonHover(false);
},
onMouseEnter: function onMouseEnter() {
return setNavigationBannerCloseButtonHover(true);
},
onClick: handleClose
}, notificationBannerCloseButtonConfigurations)) : null) : null);
}
;
export default HUDNotificationBanner;