Improved sidebar selected styling, simplified logic and css

This commit is contained in:
Tom Moor
2019-01-06 16:12:07 -08:00
parent 12e324d34c
commit b9765fb59e
11 changed files with 188 additions and 176 deletions

View File

@@ -18,9 +18,11 @@ const Wrapper = styled.div`
color: ${props => props.theme.white};
background: ${props => props.theme.slateDark};
display: inline-block;
min-width: 15px;
padding: 0 5px;
font-feature-settings: "tnum";
font-weight: 500;
font-size: 10px;
min-width: 15px;
padding: 0 4px;
position: relative;
top: -2px;
left: 2px;

View File

@@ -3,7 +3,6 @@ import * as React from 'react';
import { observer } from 'mobx-react';
import { observable } from 'mobx';
import { CollectionIcon, PrivateCollectionIcon } from 'outline-icons';
import styled from 'styled-components';
import Collection from 'models/Collection';
import Document from 'models/Document';
import CollectionMenu from 'menus/CollectionMenu';
@@ -56,23 +55,10 @@ class CollectionLink extends React.Component<Props> {
)
}
iconColor={collection.color}
expand={expanded}
hideExpandToggle
expanded={expanded}
hideDisclosure
menuOpen={this.menuOpen}
expandedContent={
<CollectionChildren column>
{collection.documents.map(document => (
<DocumentLink
key={document.id}
history={history}
document={document}
activeDocument={activeDocument}
prefetchDocument={prefetchDocument}
depth={0}
/>
))}
</CollectionChildren>
}
label={collection.name}
menu={
<CollectionMenu
history={history}
@@ -82,23 +68,22 @@ class CollectionLink extends React.Component<Props> {
/>
}
>
<CollectionName justify="space-between">
{collection.name}
</CollectionName>
<Flex column>
{collection.documents.map(document => (
<DocumentLink
key={document.id}
history={history}
document={document}
activeDocument={activeDocument}
prefetchDocument={prefetchDocument}
depth={1.5}
/>
))}
</Flex>
</SidebarLink>
</DropToImport>
);
}
}
const CollectionName = styled(Flex)`
padding: 0 0 4px;
`;
const CollectionChildren = styled(Flex)`
margin-top: -4px;
margin-left: 36px;
padding-bottom: 4px;
`;
export default CollectionLink;

View File

@@ -50,9 +50,8 @@ class Collections extends React.Component<Props> {
<SidebarLink
onClick={this.props.onCreateCollection}
icon={<PlusIcon />}
>
New collection
</SidebarLink>
label="New collection…"
/>
</Flex>
);

View File

@@ -46,6 +46,7 @@ class DocumentLink extends React.Component<Props> {
.includes(document.id) ||
isActiveDocument)
);
const hasChildren = !!document.children.length;
return (
<Flex
@@ -64,27 +65,24 @@ class DocumentLink extends React.Component<Props> {
pathname: document.url,
state: { title: document.title },
}}
expand={showChildren}
expandedContent={
document.children.length ? (
<DocumentChildren column>
{document.children.map(childDocument => (
<DocumentLink
key={childDocument.id}
history={history}
document={childDocument}
activeDocument={activeDocument}
prefetchDocument={prefetchDocument}
depth={depth + 1}
/>
))}
</DocumentChildren>
) : (
undefined
)
}
expanded={showChildren}
label={document.title}
depth={depth}
>
{document.title}
{hasChildren && (
<DocumentChildren column>
{document.children.map(childDocument => (
<DocumentLink
key={childDocument.id}
history={history}
document={childDocument}
activeDocument={activeDocument}
prefetchDocument={prefetchDocument}
depth={depth + 1}
/>
))}
</DocumentChildren>
)}
</SidebarLink>
</DropToImport>
</Flex>
@@ -92,9 +90,6 @@ class DocumentLink extends React.Component<Props> {
}
}
const DocumentChildren = styled(Flex)`
margin-top: -4px;
margin-left: 12px;
`;
const DocumentChildren = styled(Flex)``;
export default DocumentLink;

View File

@@ -8,7 +8,7 @@ const Header = styled(Flex)`
text-transform: uppercase;
color: ${props => props.theme.slateDark};
letter-spacing: 0.04em;
margin-bottom: 4px;
margin: 4px 16px;
`;
export default Header;

View File

@@ -0,0 +1,11 @@
// @flow
import styled from 'styled-components';
import Flex from 'shared/components/Flex';
const Section = styled(Flex)`
position: relative;
flex-direction: column;
margin: 24px 8px;
`;
export default Section;

View File

@@ -7,78 +7,52 @@ import { CollapsedIcon } from 'outline-icons';
import styled, { withTheme } from 'styled-components';
import Flex from 'shared/components/Flex';
const StyledGoTo = styled(CollapsedIcon)`
margin-bottom: -4px;
margin-left: 1px;
margin-right: -3px;
${({ expanded }) => !expanded && 'transform: rotate(-90deg);'};
`;
const IconWrapper = styled.span`
margin-left: -4px;
margin-right: 4px;
height: 24px;
`;
const StyledNavLink = styled(NavLink)`
display: flex;
width: 100%;
position: relative;
overflow: hidden;
text-overflow: ellipsis;
padding: 4px 0;
margin-left: ${props => (props.icon ? '-20px;' : '0')};
color: ${props => props.theme.slateDark};
font-size: 15px;
cursor: pointer;
&:hover {
color: ${props => props.theme.text};
}
`;
type Props = {
to?: string | Object,
onClick?: (SyntheticEvent<*>) => *,
children?: React.Node,
icon?: React.Node,
expand?: boolean,
expandedContent?: React.Node,
expanded?: boolean,
label?: React.Node,
menu?: React.Node,
menuOpen?: boolean,
hideExpandToggle?: boolean,
hideDisclosure?: boolean,
iconColor?: string,
active?: boolean,
theme: Object,
exact?: boolean,
depth?: number,
};
@observer
class SidebarLink extends React.Component<Props> {
@observable expanded: boolean = false;
activeStyle: Object;
@observable expanded: boolean;
constructor(props) {
super(props);
style = {
paddingLeft: `${(this.props.depth || 0) * 16 + 16}px`,
};
this.activeStyle = {
color: props.theme.black,
fontWeight: 500,
};
}
activeStyle = {
color: this.props.theme.text,
background: 'rgba(0, 0, 0, 0.05)',
fontWeight: 600,
...this.style,
};
componentDidMount() {
if (this.props.expand) this.handleExpand();
if (this.props.expanded) this.handleExpand();
}
componentWillReceiveProps(nextProps: Props) {
if (nextProps.expand) this.handleExpand();
if (nextProps.expanded !== undefined) {
this.expanded = nextProps.expanded;
}
}
@action
handleClick = (event: SyntheticEvent<*>) => {
event.preventDefault();
event.stopPropagation();
handleClick = (ev: SyntheticEvent<*>) => {
ev.preventDefault();
ev.stopPropagation();
this.expanded = !this.expanded;
};
@@ -93,47 +67,69 @@ class SidebarLink extends React.Component<Props> {
children,
onClick,
to,
expandedContent,
expand,
label,
active,
menu,
menuOpen,
hideExpandToggle,
hideDisclosure,
exact,
} = this.props;
const showExpandIcon =
expandedContent && !hideExpandToggle ? true : undefined;
const showDisclosure = !!children && !hideDisclosure;
return (
<Wrapper menuOpen={menuOpen} column>
<StyledNavLink
icon={showExpandIcon}
activeStyle={this.activeStyle}
style={active ? this.activeStyle : undefined}
style={active ? this.activeStyle : this.style}
onClick={onClick}
exact={exact !== false}
to={to}
as={to ? undefined : 'div'}
>
{icon && <IconWrapper>{icon}</IconWrapper>}
{showExpandIcon && (
<StyledGoTo expanded={this.expanded} onClick={this.handleClick} />
)}
<Content onClick={this.handleExpand}>{children}</Content>
<Label onClick={this.handleExpand}>
{showDisclosure && (
<Disclosure expanded={this.expanded} onClick={this.handleClick} />
)}
{label}
</Label>
</StyledNavLink>
{/* Collection */ expand && hideExpandToggle && expandedContent}
{/* Document */ this.expanded && !hideExpandToggle && expandedContent}
{this.expanded && children}
{menu && <Action>{menu}</Action>}
</Wrapper>
);
}
}
// accounts for whitespace around icon
const IconWrapper = styled.span`
margin-left: -4px;
margin-right: 4px;
height: 24px;
`;
const StyledNavLink = styled(NavLink)`
display: flex;
position: relative;
overflow: hidden;
text-overflow: ellipsis;
padding: 4px 16px;
border-radius: 4px;
color: ${props => props.theme.slateDark};
font-size: 15px;
cursor: pointer;
&:hover {
color: ${props => props.theme.text};
}
`;
const Action = styled.span`
position: absolute;
right: 0;
top: 2px;
top: 4px;
right: 4px;
color: ${props => props.theme.slate};
svg {
opacity: 0.75;
}
@@ -159,9 +155,17 @@ const Wrapper = styled(Flex)`
}
`;
const Content = styled.div`
const Label = styled.div`
position: relative;
width: 100%;
max-height: 4em;
max-height: 4.4em;
`;
const Disclosure = styled(CollapsedIcon)`
position: absolute;
left: -24px;
${({ expanded }) => !expanded && 'transform: rotate(-90deg);'};
`;
export default withRouter(withTheme(SidebarLink));