UNPKG

@trap_stevo/legendarybuilderproreact-ui

Version:

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

104 lines 4.83 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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 { useEffect, useMemo, createRef, isValidElement, cloneElement } from "react"; import { TransitionGroup, Transition } from "react-transition-group"; import { useLocation, useRoutes } from "react-router-dom"; var defaultTransitionDuration = 127.69; var defaultBaseSettings = function defaultBaseSettings(duration) { return { transition: "opacity ".concat(duration, "ms ease-in-out, filter ").concat(duration, "ms ease-in-out"), filter: "blur(20px)", opacity: 0 }; }; var defaultStateSettings = { entering: { filter: "blur(20px)", opacity: 0 }, entered: { filter: "blur(0px)", opacity: 1 }, exiting: { filter: "blur(10px)", opacity: 1 }, exited: { filter: "blur(20px)", opacity: 0 } }; var DefaultPanel = function DefaultPanel() { return /*#__PURE__*/React.createElement("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", fontSize: "1.5rem", color: "#ffffff", height: "100vh" } }, "Welcome!"); }; function HUDRouter(_ref) { var _ref$transitionDurati = _ref.transitionDuration, transitionDuration = _ref$transitionDurati === void 0 ? defaultTransitionDuration : _ref$transitionDurati, _ref$baseTransitionSe = _ref.baseTransitionSettings, baseTransitionSettings = _ref$baseTransitionSe === void 0 ? defaultBaseSettings(defaultTransitionDuration) : _ref$baseTransitionSe, _ref$transitionStateS = _ref.transitionStateSettings, transitionStateSettings = _ref$transitionStateS === void 0 ? defaultStateSettings : _ref$transitionStateS, _ref$styleOverrides = _ref.styleOverrides, styleOverrides = _ref$styleOverrides === void 0 ? {} : _ref$styleOverrides, _ref$routes = _ref.routes, routes = _ref$routes === void 0 ? [{ path: "*", element: /*#__PURE__*/React.createElement(DefaultPanel, null) }] : _ref$routes, _ref$getBackgroundCol = _ref.getBackgroundColor, getBackgroundColor = _ref$getBackgroundCol === void 0 ? function () { return "#0e0e0e"; } : _ref$getBackgroundCol, _ref$layoutWrapper = _ref.layoutWrapper, layoutWrapper = _ref$layoutWrapper === void 0 ? null : _ref$layoutWrapper; var location = useLocation(); var element = useRoutes(routes, location); var nodeRef = useMemo(function () { return /*#__PURE__*/createRef(); }, [location.key]); var matchedRoute = routes.find(function (route) { return route.path === location.pathname || route.path === "*"; }); var customTransitionSettings = useMemo(function () { return (matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.transitionSettings) || {}; }, [matchedRoute]); useEffect(function () { var color = getBackgroundColor(location.pathname); document.documentElement.style.backgroundColor = color; document.documentElement.style.transition = "background-color ".concat(transitionDuration, "ms ease-in-out"); document.documentElement.style.height = "100%"; document.body.style.backgroundColor = color; document.body.style.transition = "background-color ".concat(transitionDuration, "ms ease-in-out"); document.body.style.height = "100%"; document.body.style.margin = "0"; }, [location.pathname]); return /*#__PURE__*/React.createElement(TransitionGroup, { component: null }, /*#__PURE__*/React.createElement(Transition, { key: location.key, timeout: transitionDuration, nodeRef: nodeRef, unmountOnExit: true, mountOnEnter: true }, function (state) { var combinedStyle = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, baseTransitionSettings), transitionStateSettings[state]), customTransitionSettings[state]), styleOverrides); var content = /*#__PURE__*/React.createElement("div", { ref: nodeRef, style: combinedStyle }, element); return layoutWrapper ? /*#__PURE__*/isValidElement(layoutWrapper) ? /*#__PURE__*/cloneElement(layoutWrapper, {}, content) : layoutWrapper(content) : content; })); } ; export default HUDRouter;