import React, { Component } from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
import { showMenu } from "../layout/ContextMenu";
import { MenuButton } from "../inputs/Button";
import StylableContextMenuTrigger from "./StylableContextMenuTrigger";
import { EllipsisV } from "@styled-icons/fa-solid/EllipsisV";
/**
*
* @author Robert Long
* @param {any} project
* @returns
*/
function collectMenuProps({ project }) {
return { project };
}
/**
*
* @author Robert Long
*/
const StyledProjectGridItem = styled.div`
display: flex;
flex-direction: column;
height: 220px;
border-radius: 6px;
background-color: ${props => props.theme.toolbar};
text-decoration: none;
border: 1px solid transparent;
&:hover {
color: inherit;
border-color: ${props => props.theme.selected};
}
`;
/**
*
* @author Robert Long
*/
const StyledContextMenuTrigger = styled(StylableContextMenuTrigger)`
display: flex;
flex-direction: column;
flex: 1;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
`;
/**
*
* @author Robert Long
*/
const TitleContainer = styled.div`
display: flex;
height: 50px;
align-items: center;
padding: 0 16px;
h3 {
font-size: 16px;
}
button {
margin-left: auto;
svg {
width: 1em;
height: 1em;
}
}
`;
/**
*
* @author Robert Long
*/
const ThumbnailContainer = styled.div`
display: flex;
flex: 1 0 auto;
justify-content: center;
align-items: stretch;
background-color: ${props => props.theme.panel};
overflow: hidden;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
`;
/**
*
* @author Robert Long
*/
const Thumbnail = styled.div<{ src: string }>`
display: flex;
flex: 1;
background-size: cover;
background-position: 50%;
background-repeat: no-repeat;
background-image: url(${props => props.src});
`;
/**
*
* @author Robert Long
*/
const Col = styled.div`
display: flex;
flex-direction: column;
p {
color: ${props => props.theme.text2};
}
`;
/**
*
* @author Robert Long
*/
export class ProjectGridItem extends Component<{ contextMenuId: string, project: any }> {
static propTypes = {
contextMenuId: PropTypes.string,
project: PropTypes.object.isRequired
};
onShowMenu = event => {
event.preventDefault();
event.stopPropagation();
const x = event.clientX || (event.touches && event.touches[0].pageX);
const y = event.clientY || (event.touches && event.touches[0].pageY);
showMenu({
position: { x, y },
target: event.currentTarget,
id: this.props.contextMenuId,
data: {
project: this.props.project
}
});
};
render() {
const { project, contextMenuId } = this.props as any;
const content = (
<>
{project.thumbnailUrl && }
{project.name}
{contextMenuId && (
)}
>
);
if (contextMenuId) {
return (
{/* @ts-ignore */}
);
} else {
return {content};
}
}
}
export default ProjectGridItem;