Files
SCM-Manager/scm-ui/ui-components/src/CardColumn.js

109 lines
2.5 KiB
JavaScript
Raw Normal View History

//@flow
import * as React from "react";
import classNames from "classnames";
import styled from "styled-components";
import { Link } from "react-router-dom";
type Props = {
title: string,
description: string,
avatar: React.Node,
contentRight?: React.Node,
footerLeft: React.Node,
footerRight: React.Node,
link?: string,
action?: () => void,
className?: string
};
const NoEventWrapper = styled.article`
2019-10-10 16:38:24 +02:00
position: relative;
pointer-events: none;
z-index: 1;
`;
const AvatarWrapper = styled.figure`
margin-top: 0.8em;
margin-left: 1em !important;
`;
const FlexFullHeight = styled.div`
flex-direction: column;
justify-content: space-around;
align-self: stretch;
`;
const FooterWrapper = styled.div`
padding-bottom: 1rem;
`;
const ContentLeft = styled.div`
margin-bottom: 0 !important;
overflow: hidden;
`;
const ContentRight = styled.div`
margin-left: auto;
`;
export default class CardColumn extends React.Component<Props> {
createLink = () => {
const { link, action } = this.props;
if (link) {
return <Link className="overlay-column" to={link} />;
} else if (action) {
return (
<a
className="overlay-column"
onClick={e => {
e.preventDefault();
action();
}}
href="#"
/>
);
}
return null;
};
render() {
const {
avatar,
title,
description,
contentRight,
footerLeft,
footerRight,
2019-09-16 15:31:02 +02:00
className
} = this.props;
const link = this.createLink();
return (
<>
{link}
2019-10-10 16:38:24 +02:00
<NoEventWrapper className={classNames("media", className)}>
<AvatarWrapper className="media-left">{avatar}</AvatarWrapper>
<FlexFullHeight
className={classNames("media-content", "text-box", "is-flex")}
>
<div className="is-flex">
<ContentLeft className="content">
<p className="shorten-text is-marginless">
<strong>{title}</strong>
</p>
<p className="shorten-text">{description}</p>
</ContentLeft>
2019-10-11 14:56:11 +02:00
<ContentRight>{contentRight}</ContentRight>
</div>
<FooterWrapper className={classNames("level", "is-flex")}>
<div className="level-left is-hidden-mobile">{footerLeft}</div>
<div className="level-right is-mobile is-marginless">
{footerRight}
</div>
</FooterWrapper>
</FlexFullHeight>
</NoEventWrapper>
</>
);
}
}