2017-05-12 00:23:56 +00:00
|
|
|
// @flow
|
2018-05-05 23:16:08 +00:00
|
|
|
import * as React from 'react';
|
2017-08-03 03:45:09 +00:00
|
|
|
import { observer } from 'mobx-react';
|
2017-05-17 07:11:13 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
2017-06-28 05:15:29 +00:00
|
|
|
import Document from 'models/Document';
|
2017-05-25 07:07:41 +00:00
|
|
|
import styled from 'styled-components';
|
2017-10-27 05:42:08 +00:00
|
|
|
import { color } from 'shared/styles/constants';
|
2018-03-01 07:28:36 +00:00
|
|
|
import Flex from 'shared/components/Flex';
|
2017-11-25 23:44:10 +00:00
|
|
|
import Highlight from 'components/Highlight';
|
2018-05-03 04:51:39 +00:00
|
|
|
import { StarredIcon } from 'outline-icons';
|
2017-09-04 00:26:57 +00:00
|
|
|
import PublishingInfo from './components/PublishingInfo';
|
2018-03-01 07:28:36 +00:00
|
|
|
import DocumentMenu from 'menus/DocumentMenu';
|
2017-05-25 07:07:41 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
document: Document,
|
2017-07-09 18:26:17 +00:00
|
|
|
highlight?: ?string,
|
2017-07-15 05:15:56 +00:00
|
|
|
showCollection?: boolean,
|
2017-06-01 03:23:09 +00:00
|
|
|
innerRef?: Function,
|
2017-05-25 07:07:41 +00:00
|
|
|
};
|
|
|
|
|
2017-10-21 22:34:00 +00:00
|
|
|
const StyledStar = styled(({ solid, ...props }) => (
|
|
|
|
<StarredIcon color={solid ? color.black : color.text} {...props} />
|
|
|
|
))`
|
2017-09-03 01:43:12 +00:00
|
|
|
opacity: ${props => (props.solid ? '1 !important' : 0)};
|
2017-10-01 23:00:18 +00:00
|
|
|
transition: all 100ms ease-in-out;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
transform: scale(1.1);
|
|
|
|
}
|
|
|
|
&:active {
|
|
|
|
transform: scale(0.95);
|
|
|
|
}
|
2017-08-03 03:45:09 +00:00
|
|
|
`;
|
|
|
|
|
2018-03-01 07:28:36 +00:00
|
|
|
const StyledDocumentMenu = styled(DocumentMenu)`
|
|
|
|
position: absolute;
|
|
|
|
right: 16px;
|
|
|
|
top: 50%;
|
|
|
|
transform: translateY(-50%);
|
|
|
|
`;
|
|
|
|
|
2017-05-26 04:59:35 +00:00
|
|
|
const DocumentLink = styled(Link)`
|
|
|
|
display: block;
|
2017-06-26 03:32:05 +00:00
|
|
|
margin: 0 -16px;
|
2017-08-03 03:45:09 +00:00
|
|
|
padding: 10px 16px;
|
2017-05-26 04:59:35 +00:00
|
|
|
border-radius: 8px;
|
2017-06-01 03:23:09 +00:00
|
|
|
border: 2px solid transparent;
|
|
|
|
max-height: 50vh;
|
2017-06-26 00:21:33 +00:00
|
|
|
min-width: 100%;
|
2017-06-01 03:23:09 +00:00
|
|
|
overflow: hidden;
|
2018-03-01 07:28:36 +00:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
${StyledDocumentMenu} {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
2017-05-26 04:59:35 +00:00
|
|
|
|
2017-06-01 03:23:09 +00:00
|
|
|
&:hover,
|
|
|
|
&:active,
|
|
|
|
&:focus {
|
|
|
|
background: ${color.smokeLight};
|
|
|
|
border: 2px solid ${color.smoke};
|
|
|
|
outline: none;
|
2017-09-03 01:43:12 +00:00
|
|
|
|
2018-03-01 07:28:36 +00:00
|
|
|
${StyledStar}, ${StyledDocumentMenu} {
|
2017-11-10 22:14:30 +00:00
|
|
|
opacity: 0.5;
|
2017-09-03 01:43:12 +00:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 04:59:35 +00:00
|
|
|
}
|
|
|
|
|
2017-06-01 03:23:09 +00:00
|
|
|
&:focus {
|
|
|
|
border: 2px solid ${color.slateDark};
|
|
|
|
}
|
2018-03-01 07:28:36 +00:00
|
|
|
`;
|
2017-06-01 03:23:09 +00:00
|
|
|
|
2018-03-01 07:28:36 +00:00
|
|
|
const Heading = styled.h3`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
height: 24px;
|
|
|
|
margin-top: 0;
|
|
|
|
margin-bottom: 0.25em;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const Actions = styled(Flex)`
|
|
|
|
margin-left: 4px;
|
|
|
|
align-items: center;
|
2017-05-26 04:59:35 +00:00
|
|
|
`;
|
|
|
|
|
2017-11-10 22:14:30 +00:00
|
|
|
@observer
|
2018-05-05 23:16:08 +00:00
|
|
|
class DocumentPreview extends React.Component<Props> {
|
|
|
|
star = (ev: SyntheticEvent<*>) => {
|
2017-08-03 03:45:09 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
this.props.document.star();
|
|
|
|
};
|
|
|
|
|
2018-05-05 23:16:08 +00:00
|
|
|
unstar = (ev: SyntheticEvent<*>) => {
|
2017-08-03 03:45:09 +00:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
this.props.document.unstar();
|
|
|
|
};
|
|
|
|
|
2017-06-01 03:23:09 +00:00
|
|
|
render() {
|
2017-11-25 23:44:10 +00:00
|
|
|
const {
|
|
|
|
document,
|
|
|
|
showCollection,
|
|
|
|
innerRef,
|
|
|
|
highlight,
|
|
|
|
...rest
|
|
|
|
} = this.props;
|
2017-06-01 03:23:09 +00:00
|
|
|
|
|
|
|
return (
|
2018-05-13 04:01:17 +00:00
|
|
|
<DocumentLink
|
|
|
|
to={{
|
|
|
|
pathname: document.url,
|
|
|
|
state: { title: document.title },
|
|
|
|
}}
|
|
|
|
innerRef={innerRef}
|
|
|
|
{...rest}
|
|
|
|
>
|
2018-03-01 07:28:36 +00:00
|
|
|
<Heading>
|
2017-11-25 23:44:10 +00:00
|
|
|
<Highlight text={document.title} highlight={highlight} />
|
2018-03-01 07:28:36 +00:00
|
|
|
{document.publishedAt && (
|
|
|
|
<Actions>
|
|
|
|
{document.starred ? (
|
|
|
|
<StyledStar onClick={this.unstar} solid />
|
|
|
|
) : (
|
|
|
|
<StyledStar onClick={this.star} />
|
|
|
|
)}
|
|
|
|
</Actions>
|
|
|
|
)}
|
|
|
|
<StyledDocumentMenu document={document} />
|
|
|
|
</Heading>
|
2017-05-26 04:59:35 +00:00
|
|
|
<PublishingInfo
|
2017-07-16 16:24:45 +00:00
|
|
|
document={document}
|
2017-07-15 05:15:56 +00:00
|
|
|
collection={showCollection ? document.collection : undefined}
|
2017-05-26 04:59:35 +00:00
|
|
|
/>
|
|
|
|
</DocumentLink>
|
2017-06-01 03:23:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 16:02:39 +00:00
|
|
|
|
2017-05-25 07:07:41 +00:00
|
|
|
export default DocumentPreview;
|