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/frontend/components/DocumentPreview/DocumentPreview.js

115 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-05-12 00:23:56 +00:00
// @flow
import React, { Component } from 'react';
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';
import styled from 'styled-components';
import { color } from 'styles/constants';
2017-09-04 20:23:20 +00:00
import Icon from 'components/Icon';
import PublishingInfo from './components/PublishingInfo';
type Props = {
document: Document,
2017-07-09 18:26:17 +00:00
highlight?: ?string,
showCollection?: boolean,
innerRef?: Function,
};
2017-09-11 07:15:27 +00:00
const StyledStar = styled(({ solid, ...props }) => <Icon {...props} />).attrs({
2017-09-04 20:23:20 +00:00
type: 'Star',
color: color.text,
})`
2017-09-12 05:08:47 +00:00
width: 16px;
height: 16px;
top: 1px;
margin-left: 4px;
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;
2017-09-11 06:23:28 +00:00
${props => props.solid && 'polygon { fill: #000};'}
2017-10-01 23:00:18 +00:00
&:hover {
transform: scale(1.1);
}
&:active {
transform: scale(0.95);
}
`;
const DocumentLink = styled(Link)`
display: block;
2017-06-26 03:32:05 +00:00
margin: 0 -16px;
padding: 10px 16px;
border-radius: 8px;
border: 2px solid transparent;
max-height: 50vh;
min-width: 100%;
overflow: hidden;
&:hover,
&:active,
&:focus {
background: ${color.smokeLight};
border: 2px solid ${color.smoke};
outline: none;
2017-09-03 01:43:12 +00:00
${StyledStar} {
2017-09-04 20:23:20 +00:00
opacity: .5;
2017-09-03 01:43:12 +00:00
&:hover {
opacity: 1;
}
}
}
&:focus {
border: 2px solid ${color.slateDark};
}
2017-06-26 03:32:05 +00:00
h3 {
margin-top: 0;
margin-bottom: .25em;
}
`;
@observer class DocumentPreview extends Component {
props: Props;
star = (ev: SyntheticEvent) => {
ev.preventDefault();
ev.stopPropagation();
this.props.document.star();
};
unstar = (ev: SyntheticEvent) => {
ev.preventDefault();
ev.stopPropagation();
this.props.document.unstar();
};
render() {
const { document, showCollection, innerRef, ...rest } = this.props;
return (
<DocumentLink to={document.url} innerRef={innerRef} {...rest}>
<h3>
{document.title}
{document.starred
2017-09-04 19:14:18 +00:00
? <a onClick={this.unstar}>
2017-09-04 20:23:20 +00:00
<StyledStar solid />
2017-09-04 19:14:18 +00:00
</a>
: <a onClick={this.star}>
2017-09-04 20:23:20 +00:00
<StyledStar />
2017-09-04 19:14:18 +00:00
</a>}
</h3>
<PublishingInfo
document={document}
collection={showCollection ? document.collection : undefined}
/>
</DocumentLink>
);
}
}
export default DocumentPreview;