This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/shared/components/Breadcrumb.js

107 lines
2.4 KiB
JavaScript
Raw Normal View History

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';
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,
onlyText: boolean,
2018-07-01 16:16:38 +00:00
};
const Breadcrumb = observer(({ document, collections, onlyText }: Props) => {
const collection = collections.get(document.collectionId);
if (!collection) return null;
2018-11-14 04:54:18 +00:00
const path = collection.pathToDocument(document).slice(0, -1);
2018-07-01 16:16:38 +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)}>
{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 => (
<React.Fragment key={n.id}>
<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
`;
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);