@zohodesk/docs-builder
Version:
docs-builder is used to build your own docs
74 lines (68 loc) • 2.11 kB
JavaScript
import React from "react";
import "./Docs.plain.css";
import { HashRouter as Router, Route, Switch, Redirect } from "react-router-dom";
import Main from "./components/Main/Main";
function PreviewRenderer(props) {
const {
Components,
Decorators,
match
} = props;
const {
componentName
} = match.params;
if (!Components[componentName]) {
return /*#__PURE__*/React.createElement(Redirect, {
to: "/all"
});
}
const Docsss = Components[componentName];
return Decorators ? /*#__PURE__*/React.createElement(Decorators, null, " ", /*#__PURE__*/React.createElement(Docsss, null), " ") : /*#__PURE__*/React.createElement(Docsss, null);
}
export default function Docs(props) {
const {
Components,
docsConfig
} = props;
return /*#__PURE__*/React.createElement(Router, null, /*#__PURE__*/React.createElement(Switch, null, /*#__PURE__*/React.createElement(Route, {
path: "/all/:componentName",
render: routeProps => {
const {
componentName
} = routeProps.match.params;
if (!Components[componentName]) {
return /*#__PURE__*/React.createElement(Redirect, {
to: "/all"
});
}
return /*#__PURE__*/React.createElement(Main, {
componentName: componentName,
component: Components,
docsConfig: docsConfig
});
}
}), /*#__PURE__*/React.createElement(Route, {
path: "/all",
render: () => /*#__PURE__*/React.createElement(Main, {
componentName: false,
component: Components,
docsConfig: docsConfig
})
}), /*#__PURE__*/React.createElement(Route, {
path: "/preview/:componentName",
render: routeProps => /*#__PURE__*/React.createElement(PreviewRenderer, { ...routeProps,
...props
})
}), /*#__PURE__*/React.createElement(Route, {
exact: true,
path: "/",
render: routeProps => {
routeProps.history.push('/all');
return 'Will be Redirected';
}
}), /*#__PURE__*/React.createElement(Route, {
render: () => /*#__PURE__*/React.createElement(Redirect, {
to: "/all"
})
})));
}