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,
|
2018-07-01 16:16:38 +00:00
|
|
|
};
|
|
|
|
|
2018-07-01 18:54:24 +00:00
|
|
|
const Breadcrumb = observer(({ document, collections }: Props) => {
|
2018-07-01 16:16:38 +00:00
|
|
|
const path = document.pathToDocument.slice(0, -1);
|
2018-11-14 04:54:18 +00:00
|
|
|
if (!document.collection) return null;
|
|
|
|
|
2018-07-01 18:54:24 +00:00
|
|
|
const collection =
|
2018-12-05 06:24:30 +00:00
|
|
|
collections.data.get(document.collection.id) || document.collection;
|
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}>
|
2018-07-01 16:16:38 +00:00
|
|
|
<Slash /> <Crumb to={n.url}>{n.title}</Crumb>
|
|
|
|
</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
|
|
|
`;
|
|
|
|
|
|
|
|
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);
|