Files
outline/app/components/Sidebar/components/CollectionLink.js
Mateusz Sapielak 8ea1323a7c fix: Ensure menus are always kept on the screen (#1036)
* ensuring dropdowns fit on the screen

* refactoring

* fix flow types

* no longer fixing the elements which should resolve scrolling issues

* fix menus that should be fixed

* styled-components syntax was wrong

* account for fixed dropdowns when handling overflowing menus

* Update app/components/DropdownMenu/DropdownMenu.js

Co-Authored-By: Tom Moor <tom.moor@gmail.com>
2019-10-12 20:21:48 -07:00

92 lines
2.5 KiB
JavaScript

// @flow
import * as React from 'react';
import { observer } from 'mobx-react';
import { observable } from 'mobx';
import { CollectionIcon, PrivateCollectionIcon } from 'outline-icons';
import Collection from 'models/Collection';
import Document from 'models/Document';
import CollectionMenu from 'menus/CollectionMenu';
import UiStore from 'stores/UiStore';
import DocumentsStore from 'stores/DocumentsStore';
import SidebarLink from './SidebarLink';
import DocumentLink from './DocumentLink';
import DropToImport from 'components/DropToImport';
import Flex from 'shared/components/Flex';
type Props = {
collection: Collection,
ui: UiStore,
documents: DocumentsStore,
activeDocument: ?Document,
prefetchDocument: (id: string) => Promise<void>,
};
@observer
class CollectionLink extends React.Component<Props> {
@observable menuOpen = false;
render() {
const {
collection,
documents,
activeDocument,
prefetchDocument,
ui,
} = this.props;
const expanded = collection.id === ui.activeCollectionId;
return (
<DropToImport
key={collection.id}
collectionId={collection.id}
activeClassName="activeDropZone"
>
<SidebarLink
key={collection.id}
to={collection.url}
icon={
collection.private ? (
<PrivateCollectionIcon
expanded={expanded}
color={collection.color}
/>
) : (
<CollectionIcon expanded={expanded} color={collection.color} />
)
}
iconColor={collection.color}
expanded={expanded}
hideDisclosure
menuOpen={this.menuOpen}
label={collection.name}
exact={false}
menu={
<CollectionMenu
position="right"
collection={collection}
onOpen={() => (this.menuOpen = true)}
onClose={() => (this.menuOpen = false)}
/>
}
>
<Flex column>
{collection.documents.map(node => (
<DocumentLink
key={node.id}
node={node}
documents={documents}
collection={collection}
activeDocument={activeDocument}
prefetchDocument={prefetchDocument}
depth={1.5}
/>
))}
</Flex>
</SidebarLink>
</DropToImport>
);
}
}
export default CollectionLink;