2018-07-01 16:16:38 +00:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2018-07-01 18:54:24 +00:00
|
|
|
import { observer, inject } from 'mobx-react';
|
2018-07-01 17:20:57 +00:00
|
|
|
import breakpoint from 'styled-components-breakpoint';
|
2018-07-01 16:16:38 +00:00
|
|
|
import styled from 'styled-components';
|
|
|
|
import { Link } from 'react-router-dom';
|
2019-01-05 21:37:33 +00:00
|
|
|
import { CollectionIcon, PrivateCollectionIcon, GoToIcon } from 'outline-icons';
|
2018-07-01 16:16:38 +00:00
|
|
|
|
2018-07-01 18:54:24 +00:00
|
|
|
import Document from 'models/Document';
|
|
|
|
import CollectionsStore from 'stores/CollectionsStore';
|
2018-07-01 16:16:38 +00:00
|
|
|
import { collectionUrl } from 'utils/routeHelpers';
|
|
|
|
import Flex from 'shared/components/Flex';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
document: Document,
|
2018-07-01 18:54:24 +00:00
|
|
|
collections: CollectionsStore,
|
2019-04-06 23:45:08 +00:00
|
|
|
onlyText: boolean,
|
2018-07-01 16:16:38 +00:00
|
|
|
};
|
|
|
|
|
2019-04-06 23:45:08 +00:00
|
|
|
const Breadcrumb = observer(({ document, collections, onlyText }: Props) => {
|
2019-04-18 02:11:23 +00:00
|
|
|
const collection = collections.get(document.collectionId);
|
|
|
|
if (!collection) return null;
|
2018-11-14 04:54:18 +00:00
|
|
|
|
2019-04-18 02:11:23 +00:00
|
|
|
const path = collection.pathToDocument(document).slice(0, -1);
|
2018-07-01 16:16:38 +00:00
|
|
|
|
2019-04-06 23:45:08 +00:00
|
|
|
if (onlyText === true) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{collection.name}
|
|
|
|
{path.map(n => (
|
|
|
|
<React.Fragment key={n.id}>
|
|
|
|
<SmallSlash />
|
|
|
|
{n.title}
|
|
|
|
</React.Fragment>
|
|
|
|
))}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-01 16:16:38 +00:00
|
|
|
return (
|
|
|
|
<Wrapper justify="flex-start" align="center">
|
2018-07-01 18:54:24 +00:00
|
|
|
<CollectionName to={collectionUrl(collection.id)}>
|
2019-01-05 21:37:33 +00:00
|
|
|
{collection.private ? (
|
|
|
|
<PrivateCollectionIcon color={collection.color} expanded />
|
|
|
|
) : (
|
|
|
|
<CollectionIcon color={collection.color} expanded />
|
|
|
|
)}{' '}
|
2018-07-01 18:54:24 +00:00
|
|
|
<span>{collection.name}</span>
|
2018-07-01 16:16:38 +00:00
|
|
|
</CollectionName>
|
|
|
|
{path.map(n => (
|
2018-07-02 02:56:58 +00:00
|
|
|
<React.Fragment key={n.id}>
|
2019-01-07 00:12:07 +00:00
|
|
|
<Slash />{' '}
|
|
|
|
<Crumb to={n.url} title={n.title}>
|
|
|
|
{n.title}
|
|
|
|
</Crumb>
|
2018-07-01 16:16:38 +00:00
|
|
|
</React.Fragment>
|
|
|
|
))}
|
|
|
|
</Wrapper>
|
|
|
|
);
|
2018-07-01 18:54:24 +00:00
|
|
|
});
|
2018-07-01 16:16:38 +00:00
|
|
|
|
|
|
|
const Wrapper = styled(Flex)`
|
|
|
|
width: 33.3%;
|
2018-07-01 17:20:57 +00:00
|
|
|
display: none;
|
|
|
|
|
|
|
|
${breakpoint('tablet')`
|
|
|
|
display: flex;
|
|
|
|
`};
|
2018-07-01 16:16:38 +00:00
|
|
|
`;
|
|
|
|
|
2019-04-06 23:45:08 +00:00
|
|
|
const SmallSlash = styled(GoToIcon)`
|
|
|
|
width: 15px;
|
|
|
|
height: 10px;
|
|
|
|
flex-shrink: 0;
|
|
|
|
opacity: 0.25;
|
|
|
|
`;
|
|
|
|
|
2018-07-01 16:16:38 +00:00
|
|
|
const Slash = styled(GoToIcon)`
|
2018-07-01 18:54:24 +00:00
|
|
|
flex-shrink: 0;
|
2018-07-01 16:16:38 +00:00
|
|
|
opacity: 0.25;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Crumb = styled(Link)`
|
|
|
|
color: ${props => props.theme.text};
|
|
|
|
font-size: 15px;
|
|
|
|
height: 24px;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const CollectionName = styled(Link)`
|
2018-07-01 18:54:24 +00:00
|
|
|
display: flex;
|
|
|
|
flex-shrink: 0;
|
2018-07-01 16:16:38 +00:00
|
|
|
color: ${props => props.theme.text};
|
|
|
|
font-size: 15px;
|
|
|
|
font-weight: 500;
|
2018-07-01 18:54:24 +00:00
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
2018-07-01 16:16:38 +00:00
|
|
|
`;
|
|
|
|
|
2018-07-01 18:54:24 +00:00
|
|
|
export default inject('collections')(Breadcrumb);
|