@intuitionrobotics/thunderstorm
Version:
69 lines • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultRouteNode = exports.defaultLinkNode = exports.defaultNavLinkNode = exports.RoutePath = void 0;
const React = require("react");
const react_router_dom_1 = require("react-router-dom");
const ReactEntryComponentInjector_1 = require("../component-loader/ReactEntryComponentInjector");
class RoutePath {
constructor(key, route, component) {
this.exact = false;
this.visible = () => !!this.label;
this.key = key;
this.path = route;
this.component = component;
}
setLogMessage(logMessage) {
this.logMessage = logMessage;
return this;
}
setLabel(label) {
this.label = label;
return this;
}
setVisible(visible) {
this.visible = visible;
return this;
}
setEnabled(enabled) {
this.enabled = enabled;
return this;
}
setExact(exact) {
this.exact = exact;
return this;
}
compose(params) {
const paramsAsString = RoutePath.composeStringQuery(params);
return this.path + paramsAsString;
}
static composeStringQuery(params) {
let paramsAsString = "";
if (params)
paramsAsString = Object.keys(params).reduce((toRet, key) => {
let param = params[key];
if (typeof param === "function")
param = param();
return `${toRet}&${key}=${param}`;
}, paramsAsString);
if (paramsAsString.length > 0)
paramsAsString = `?${paramsAsString.substring(1)}`;
return paramsAsString;
}
}
exports.RoutePath = RoutePath;
const activeStyle = { color: 'blue' };
const defaultNavLinkNode = (route) => {
return React.createElement(react_router_dom_1.NavLink, { key: route.key, to: route.path, activeStyle: activeStyle }, route.label);
};
exports.defaultNavLinkNode = defaultNavLinkNode;
const defaultLinkNode = (route, node) => {
return React.createElement(react_router_dom_1.Link, { key: route.key, to: route.path }, node || route.label || route.key);
};
exports.defaultLinkNode = defaultLinkNode;
const defaultRouteNode = (route) => {
if (typeof route.component === "string")
return React.createElement(ReactEntryComponentInjector_1.ReactEntryComponentInjector, { src: route.component });
return React.createElement(react_router_dom_1.Route, { exact: route.exact, key: route.key, path: route.path, component: route.component });
};
exports.defaultRouteNode = defaultRouteNode;
//# sourceMappingURL=route.js.map