From 1c9ca912112d8748b5ceda0b5bda54a5d2894e8b Mon Sep 17 00:00:00 2001 From: Jori Lallo Date: Wed, 27 Sep 2017 00:21:40 -0700 Subject: [PATCH] Added sidebar chevrons --- frontend/components/Layout/Layout.js | 1 + .../Layout/components/SidebarCollections.js | 60 +++++++++++-------- .../Layout/components/SidebarLink.js | 35 ++++++++++- 3 files changed, 68 insertions(+), 28 deletions(-) diff --git a/frontend/components/Layout/Layout.js b/frontend/components/Layout/Layout.js index c3ab6d95..df446d60 100644 --- a/frontend/components/Layout/Layout.js +++ b/frontend/components/Layout/Layout.js @@ -173,6 +173,7 @@ const Sidebar = styled(Flex)` const LinkSection = styled(Flex)` flex-direction: column; margin: 24px 0; + padding: 0 ${layout.hpadding}; position: relative; `; diff --git a/frontend/components/Layout/components/SidebarCollections.js b/frontend/components/Layout/components/SidebarCollections.js index 3544e304..eb5b8802 100644 --- a/frontend/components/Layout/components/SidebarCollections.js +++ b/frontend/components/Layout/components/SidebarCollections.js @@ -87,16 +87,19 @@ type Props = { /> } + {collection.id === ui.activeCollectionId && - collection.documents.map(document => ( - - ))} + + {collection.documents.map(document => ( + + ))} + } ); @@ -111,27 +114,32 @@ type DocumentLinkProps = { }; const DocumentLink = observer((props: DocumentLinkProps) => { - const { history, document, activeDocument, depth } = props; - const canDropToImport = depth === 0; + const { document, activeDocument, depth } = props; + + const showChildren = + activeDocument && + (activeDocument.pathToDocument + .map(entry => entry.id) + .includes(document.id) || + activeDocument.id === document.id); return ( - {canDropToImport && - + 0} + expanded={showChildren} > - {document.title} - } - {!canDropToImport && - {document.title}} + {document.title} + + - {activeDocument && - (activeDocument.pathToDocument - .map(entry => entry.id) - .includes(document.id) || - activeDocument.id === document.id) && + {showChildren && {document.children && document.children.map(childDocument => ( @@ -139,6 +147,7 @@ const DocumentLink = observer((props: DocumentLinkProps) => { key={childDocument.id} history={history} document={childDocument} + activeDocument={activeDocument} depth={depth + 1} /> ))} @@ -153,7 +162,6 @@ const Header = styled(Flex)` text-transform: uppercase; color: ${color.slate}; letter-spacing: 0.04em; - padding: 0 24px; `; const CollectionAction = styled.a` diff --git a/frontend/components/Layout/components/SidebarLink.js b/frontend/components/Layout/components/SidebarLink.js index 1516db63..0b2162d5 100644 --- a/frontend/components/Layout/components/SidebarLink.js +++ b/frontend/components/Layout/components/SidebarLink.js @@ -4,6 +4,9 @@ import { NavLink } from 'react-router-dom'; import { color, fontWeight } from 'styles/constants'; import styled from 'styled-components'; +import Flex from 'components/Flex'; +import ChevronIcon from 'components/Icon/ChevronIcon'; + const activeStyle = { color: color.black, fontWeight: fontWeight.semiBold, @@ -14,9 +17,11 @@ const StyleableDiv = props =>
; const styleComponent = component => styled(component)` display: block; + width: 100%; overflow: hidden; text-overflow: ellipsis; - margin: 5px 24px; + margin: 5px 0; + margin-left: ${({ hasChildren }) => (hasChildren ? '-20px;' : '0')}; color: ${color.slateDark}; font-size: 15px; cursor: pointer; @@ -24,11 +29,37 @@ const styleComponent = component => styled(component)` &:hover { color: ${color.text}; } + + &.active svg { + fill: ${activeStyle.color}; + } `; function SidebarLink(props: Object) { const Component = styleComponent(props.to ? NavLink : StyleableDiv); - return ; + + return ( + + + {props.hasChildren && } + {props.children} + + + ); } +const StyledChevron = styled(ChevronIcon)` + margin-right: -10px; + + svg { + height: 18px; + margin-bottom: -4px; + margin-right: 6px; + + fill: ${color.slateDark}; + + ${({ expanded }) => expanded && 'transform: rotate(90deg);'} + } +`; + export default SidebarLink;