Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Add very basic sidebar implementation
Browse files Browse the repository at this point in the history
Missing stuff that would be supported in readme:
- external links
- children docs
- grouping by tags

I think this is fine for now.
  • Loading branch information
Dom Harrington committed Sep 24, 2018
1 parent 918e32a commit 3bc0684
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions example/preview/src/Preview.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const React = require('react');
const ReactDOM = require('react-dom');
const PropTypes = require('prop-types');
const extensions = require('../../../packages/oas-extensions/');

const Sidebar = require('./Sidebar');
const ApiExplorer = require('../../../packages/api-explorer/src');
const withSpecFetching = require('../../src/SpecFetcher');

Expand Down Expand Up @@ -32,6 +34,7 @@ class Preview extends React.Component {
</div>

{ status.length ? <pre style={{ marginLeft: '20px' }}>{status.join('\n')}</pre> : null }
{ status.length === 0 && oas.info && <Sidebar title={oas.info.title} docs={docs} /> }
{
status.length === 0 && (
<ApiExplorer
Expand Down
26 changes: 26 additions & 0 deletions example/preview/src/Sidebar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const React = require('react');
const ReactDOM = require('react-dom');

function Doc({ doc }) {
return (
<li className="hub-sidebar-page subnav-expanded">
<a className="text-overflow" href={`#${doc.slug}`}>
<span className={`pg-type type-${doc.api.method}`}>{doc.api.method}</span>
{doc.title}
</a>
</li>
);
}

function Sidebar({ title, docs }) {
return ReactDOM.createPortal((
<div className="hub-sidebar-category">
<h3>{title}</h3>
<ul>
{ docs.map(doc => <Doc key={doc._id} doc={doc} />) }
</ul>
</div>
), document.getElementById('hub-sidebar-content'));
}

module.exports = Sidebar;

0 comments on commit 3bc0684

Please sign in to comment.