Added: New document icon / menu to Dashboard screen
This commit is contained in:
@ -5,6 +5,7 @@ import styled from 'styled-components';
|
|||||||
type Props = {
|
type Props = {
|
||||||
onClick?: (SyntheticEvent<*>) => *,
|
onClick?: (SyntheticEvent<*>) => *,
|
||||||
children?: React.Node,
|
children?: React.Node,
|
||||||
|
disabled?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DropdownMenuItem = ({ onClick, children, ...rest }: Props) => {
|
const DropdownMenuItem = ({ onClick, children, ...rest }: Props) => {
|
||||||
@ -21,24 +22,32 @@ const MenuItem = styled.a`
|
|||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
|
|
||||||
color: ${props => props.theme.slateDark};
|
color: ${props =>
|
||||||
|
props.disabled ? props.theme.slate : props.theme.slateDark};
|
||||||
justify-content: left;
|
justify-content: left;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
cursor: pointer;
|
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
cursor: default;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${props =>
|
||||||
|
props.disabled
|
||||||
|
? ''
|
||||||
|
: `
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: ${props => props.theme.white};
|
color: ${props.theme.white};
|
||||||
background: ${props => props.theme.primary};
|
background: ${props.theme.primary};
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
fill: ${props => props.theme.white};
|
fill: ${props.theme.white};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
`};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default DropdownMenuItem;
|
export default DropdownMenuItem;
|
||||||
|
53
app/menus/NewDocumentMenu.js
Normal file
53
app/menus/NewDocumentMenu.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// @flow
|
||||||
|
import * as React from 'react';
|
||||||
|
import { withRouter } from 'react-router-dom';
|
||||||
|
import { inject } from 'mobx-react';
|
||||||
|
import { MoreIcon, CollectionIcon } from 'outline-icons';
|
||||||
|
|
||||||
|
import { newDocumentUrl } from 'utils/routeHelpers';
|
||||||
|
import CollectionsStore from 'stores/CollectionsStore';
|
||||||
|
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
label?: React.Node,
|
||||||
|
history: Object,
|
||||||
|
collections: CollectionsStore,
|
||||||
|
};
|
||||||
|
|
||||||
|
class NewDocumentMenu extends React.Component<Props> {
|
||||||
|
handleNewDocument = collection => {
|
||||||
|
this.props.history.push(newDocumentUrl(collection));
|
||||||
|
};
|
||||||
|
|
||||||
|
onOpen = () => {
|
||||||
|
const { collections } = this.props;
|
||||||
|
|
||||||
|
if (collections.orderedData.length === 1) {
|
||||||
|
this.handleNewDocument(collections.orderedData[0]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { collections, label, history, ...rest } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu
|
||||||
|
label={label || <MoreIcon />}
|
||||||
|
onOpen={this.onOpen}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
<DropdownMenuItem disabled>Choose a collection…</DropdownMenuItem>
|
||||||
|
{collections.orderedData.map(collection => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={collection.id}
|
||||||
|
onClick={() => this.handleNewDocument(collection)}
|
||||||
|
>
|
||||||
|
<CollectionIcon color={collection.color} /> {collection.name}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default withRouter(inject('collections')(NewDocumentMenu));
|
@ -2,8 +2,11 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
import { observer, inject } from 'mobx-react';
|
import { observer, inject } from 'mobx-react';
|
||||||
|
import { NewDocumentIcon } from 'outline-icons';
|
||||||
|
|
||||||
|
import NewDocumentMenu from 'menus/NewDocumentMenu';
|
||||||
import DocumentsStore from 'stores/DocumentsStore';
|
import DocumentsStore from 'stores/DocumentsStore';
|
||||||
|
import Actions, { Action } from 'components/Actions';
|
||||||
import CenteredContent from 'components/CenteredContent';
|
import CenteredContent from 'components/CenteredContent';
|
||||||
import DocumentList from 'components/DocumentList';
|
import DocumentList from 'components/DocumentList';
|
||||||
import PageTitle from 'components/PageTitle';
|
import PageTitle from 'components/PageTitle';
|
||||||
@ -42,22 +45,31 @@ class Dashboard extends React.Component<Props> {
|
|||||||
<PageTitle title="Home" />
|
<PageTitle title="Home" />
|
||||||
<h1>Home</h1>
|
<h1>Home</h1>
|
||||||
{showContent ? (
|
{showContent ? (
|
||||||
<span>
|
<React.Fragment>
|
||||||
{hasRecentlyViewed && [
|
{hasRecentlyViewed && (
|
||||||
<Subheading key="viewed">Recently viewed</Subheading>,
|
<React.Fragment>
|
||||||
|
<Subheading key="viewed">Recently viewed</Subheading>
|
||||||
<DocumentList
|
<DocumentList
|
||||||
key="viewedDocuments"
|
key="viewedDocuments"
|
||||||
documents={documents.recentlyViewed}
|
documents={documents.recentlyViewed}
|
||||||
/>,
|
/>
|
||||||
]}
|
</React.Fragment>
|
||||||
{hasRecentlyEdited && [
|
)}
|
||||||
<Subheading key="edited">Recently edited</Subheading>,
|
{hasRecentlyEdited && (
|
||||||
|
<React.Fragment>
|
||||||
|
<Subheading key="edited">Recently edited</Subheading>
|
||||||
<DocumentList
|
<DocumentList
|
||||||
key="editedDocuments"
|
key="editedDocuments"
|
||||||
documents={documents.recentlyEdited}
|
documents={documents.recentlyEdited}
|
||||||
/>,
|
/>
|
||||||
]}
|
</React.Fragment>
|
||||||
</span>
|
)}
|
||||||
|
<Actions align="center" justify="flex-end">
|
||||||
|
<Action>
|
||||||
|
<NewDocumentMenu label={<NewDocumentIcon />} />
|
||||||
|
</Action>
|
||||||
|
</Actions>
|
||||||
|
</React.Fragment>
|
||||||
) : (
|
) : (
|
||||||
<ListPlaceholder count={5} />
|
<ListPlaceholder count={5} />
|
||||||
)}
|
)}
|
||||||
|
Reference in New Issue
Block a user