Files
outline/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js
T
Jori Lallo 8b3b3222b7 Swapped Flex to homegrown component
No more element prop warnings!
2017-07-07 00:04:12 -07:00

67 lines
1.4 KiB
JavaScript

// @flow
import React from 'react';
import Flex from 'components/Flex';
import styled from 'styled-components';
import SidebarLink from '../SidebarLink';
import Collection from 'models/Collection';
import Document from 'models/Document';
import type { NavigationNode } from 'types';
type Props = {
collection: ?Collection,
document: ?Document,
};
class SidebarCollection extends React.Component {
props: Props;
renderDocuments(documentList: Array<NavigationNode>) {
const { document } = this.props;
if (document) {
return documentList.map(doc => (
<Flex column key={doc.id}>
<SidebarLink key={doc.id} to={doc.url}>
{doc.title}
</SidebarLink>
{(document.pathToDocument.includes(doc.id) ||
document.id === doc.id) &&
<Children column>
{doc.children && this.renderDocuments(doc.children)}
</Children>}
</Flex>
));
}
}
render() {
const { collection } = this.props;
if (collection) {
return (
<Flex column>
<Header>{collection.name}</Header>
{this.renderDocuments(collection.documents)}
</Flex>
);
}
return null;
}
}
const Header = styled(Flex)`
font-size: 11px;
font-weight: 500;
text-transform: uppercase;
color: #9FA6AB;
letter-spacing: 0.04em;
`;
const Children = styled(Flex)`
margin-left: 20px;
`;
export default SidebarCollection;