2018-07-01 16:16:38 +00:00
|
|
|
// @flow
|
2020-06-23 04:29:21 +00:00
|
|
|
import * as React from "react";
|
|
|
|
import { observer, inject } from "mobx-react";
|
|
|
|
import breakpoint from "styled-components-breakpoint";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import { Link } from "react-router-dom";
|
|
|
|
import { PadlockIcon, GoToIcon, MoreIcon } from "outline-icons";
|
|
|
|
|
|
|
|
import Document from "models/Document";
|
|
|
|
import CollectionsStore from "stores/CollectionsStore";
|
|
|
|
import { collectionUrl } from "utils/routeHelpers";
|
|
|
|
import Flex from "shared/components/Flex";
|
|
|
|
import BreadcrumbMenu from "./BreadcrumbMenu";
|
|
|
|
import CollectionIcon from "components/CollectionIcon";
|
2018-07-01 16:16:38 +00:00
|
|
|
|
|
|
|
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);
|
2019-10-06 01:42:03 +00:00
|
|
|
if (!collection) return <div />;
|
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>
|
2019-08-29 04:41:40 +00:00
|
|
|
{collection.private && (
|
|
|
|
<React.Fragment>
|
2020-06-23 04:29:21 +00:00
|
|
|
<SmallPadlockIcon color="currentColor" size={16} />{" "}
|
2019-08-29 04:41:40 +00:00
|
|
|
</React.Fragment>
|
|
|
|
)}
|
2019-04-06 23:45:08 +00:00
|
|
|
{collection.name}
|
|
|
|
{path.map(n => (
|
|
|
|
<React.Fragment key={n.id}>
|
|
|
|
<SmallSlash />
|
|
|
|
{n.title}
|
|
|
|
</React.Fragment>
|
|
|
|
))}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-26 06:21:04 +00:00
|
|
|
const isNestedDocument = path.length > 1;
|
|
|
|
const lastPath = path.length ? path[path.length - 1] : undefined;
|
|
|
|
const menuPath = isNestedDocument ? path.slice(0, -1) : [];
|
|
|
|
|
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)}>
|
2020-06-23 04:29:21 +00:00
|
|
|
<CollectionIcon collection={collection} expanded />{" "}
|
2018-07-01 18:54:24 +00:00
|
|
|
<span>{collection.name}</span>
|
2018-07-01 16:16:38 +00:00
|
|
|
</CollectionName>
|
2019-06-26 06:21:04 +00:00
|
|
|
{isNestedDocument && (
|
|
|
|
<React.Fragment>
|
|
|
|
<Slash /> <BreadcrumbMenu label={<Overflow />} path={menuPath} />
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
{lastPath && (
|
|
|
|
<React.Fragment>
|
2020-06-23 04:29:21 +00:00
|
|
|
<Slash />{" "}
|
2019-06-26 06:21:04 +00:00
|
|
|
<Crumb to={lastPath.url} title={lastPath.title}>
|
|
|
|
{lastPath.title}
|
2019-01-07 00:12:07 +00:00
|
|
|
</Crumb>
|
2018-07-01 16:16:38 +00:00
|
|
|
</React.Fragment>
|
2019-06-26 06:21:04 +00:00
|
|
|
)}
|
2018-07-01 16:16:38 +00:00
|
|
|
</Wrapper>
|
|
|
|
);
|
2018-07-01 18:54:24 +00:00
|
|
|
});
|
2018-07-01 16:16:38 +00:00
|
|
|
|
|
|
|
const Wrapper = styled(Flex)`
|
2018-07-01 17:20:57 +00:00
|
|
|
display: none;
|
|
|
|
|
2020-06-23 04:29:21 +00:00
|
|
|
${breakpoint("tablet")`
|
2018-07-01 17:20:57 +00:00
|
|
|
display: flex;
|
|
|
|
`};
|
2018-07-01 16:16:38 +00:00
|
|
|
`;
|
|
|
|
|
2019-08-29 04:41:40 +00:00
|
|
|
const SmallPadlockIcon = styled(PadlockIcon)`
|
|
|
|
display: inline-block;
|
|
|
|
vertical-align: sub;
|
|
|
|
`;
|
|
|
|
|
2019-04-06 23:45:08 +00:00
|
|
|
const SmallSlash = styled(GoToIcon)`
|
|
|
|
width: 15px;
|
|
|
|
height: 10px;
|
|
|
|
flex-shrink: 0;
|
|
|
|
opacity: 0.25;
|
|
|
|
`;
|
|
|
|
|
2020-04-05 19:22:26 +00:00
|
|
|
export const Slash = styled(GoToIcon)`
|
2018-07-01 18:54:24 +00:00
|
|
|
flex-shrink: 0;
|
2020-05-20 05:34:04 +00:00
|
|
|
fill: ${props => props.theme.divider};
|
2018-07-01 16:16:38 +00:00
|
|
|
`;
|
|
|
|
|
2019-06-26 06:21:04 +00:00
|
|
|
const Overflow = styled(MoreIcon)`
|
|
|
|
flex-shrink: 0;
|
|
|
|
opacity: 0.25;
|
|
|
|
transition: opacity 100ms ease-in-out;
|
|
|
|
|
|
|
|
&:hover,
|
|
|
|
&:active {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-07-01 16:16:38 +00:00
|
|
|
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
|
|
|
`;
|
|
|
|
|
2020-06-23 04:29:21 +00:00
|
|
|
export default inject("collections")(Breadcrumb);
|