2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2022-11-10 11:44:53 +01:00
|
|
|
import React, { ReactNode, useCallback } from "react";
|
2019-10-20 16:59:02 +02:00
|
|
|
import classNames from "classnames";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { Link } from "react-router-dom";
|
2019-07-09 13:29:25 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2020-04-08 15:20:35 +02:00
|
|
|
link?: string;
|
|
|
|
|
avatar?: ReactNode;
|
2020-03-19 13:12:03 +01:00
|
|
|
title: ReactNode;
|
2020-01-08 12:38:21 +01:00
|
|
|
description?: string;
|
2019-10-20 16:59:02 +02:00
|
|
|
contentRight?: ReactNode;
|
|
|
|
|
footerLeft: ReactNode;
|
|
|
|
|
footerRight: ReactNode;
|
2019-10-19 16:38:07 +02:00
|
|
|
action?: () => void;
|
|
|
|
|
className?: string;
|
2019-07-09 13:29:25 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-08 16:42:08 +02:00
|
|
|
const NoEventWrapper = styled.article`
|
2019-10-10 16:38:24 +02:00
|
|
|
position: relative;
|
2019-10-08 16:42:08 +02:00
|
|
|
pointer-events: none;
|
|
|
|
|
z-index: 1;
|
|
|
|
|
`;
|
|
|
|
|
|
2020-04-03 00:21:26 +02:00
|
|
|
const InheritFlexShrinkDiv = styled.div`
|
|
|
|
|
flex-shrink: inherit;
|
2020-04-09 09:31:13 +02:00
|
|
|
pointer-events: all;
|
2020-04-03 00:21:26 +02:00
|
|
|
`;
|
|
|
|
|
|
2021-11-16 14:55:06 +01:00
|
|
|
const InvisibleButton = styled.button`
|
|
|
|
|
background: none;
|
|
|
|
|
border: none;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
`;
|
|
|
|
|
|
2022-11-10 11:44:53 +01:00
|
|
|
const CardColumn = React.forwardRef<HTMLElement, Props>(
|
|
|
|
|
({ link, avatar, title, description, contentRight, footerLeft, footerRight, action, className }, ref) => {
|
|
|
|
|
const renderAvatar = avatar ? <figure className="media-left mt-3 ml-4">{avatar}</figure> : null;
|
|
|
|
|
const renderDescription = description ? <p className="shorten-text">{description}</p> : null;
|
|
|
|
|
const renderContentRight = contentRight ? <div className="ml-auto">{contentRight}</div> : null;
|
|
|
|
|
const executeRef = useCallback(
|
|
|
|
|
(el: HTMLButtonElement | HTMLAnchorElement | null) => {
|
|
|
|
|
if (typeof ref === "function") {
|
|
|
|
|
ref(el);
|
|
|
|
|
} else if (ref) {
|
|
|
|
|
ref.current = el;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[ref]
|
2019-07-09 13:29:25 +02:00
|
|
|
);
|
2020-04-08 15:20:35 +02:00
|
|
|
|
2022-11-10 11:44:53 +01:00
|
|
|
let createLink = null;
|
|
|
|
|
if (link) {
|
|
|
|
|
createLink = <Link ref={executeRef} className="overlay-column" to={link} />;
|
|
|
|
|
} else if (action) {
|
|
|
|
|
createLink = (
|
|
|
|
|
<InvisibleButton
|
|
|
|
|
ref={executeRef}
|
|
|
|
|
className="overlay-column"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
action();
|
|
|
|
|
}}
|
|
|
|
|
tabIndex={0}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{createLink}
|
|
|
|
|
<NoEventWrapper className={classNames("media", className)}>
|
|
|
|
|
{renderAvatar}
|
|
|
|
|
<div
|
|
|
|
|
className={classNames(
|
|
|
|
|
"media-content",
|
|
|
|
|
"text-box",
|
|
|
|
|
"is-flex",
|
|
|
|
|
"is-flex-direction-column",
|
|
|
|
|
"is-justify-content-space-around",
|
|
|
|
|
"is-align-self-stretch"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<div className="is-flex">
|
|
|
|
|
<div className="is-clipped mb-0">
|
|
|
|
|
<p className="shorten-text m-0">{title}</p>
|
|
|
|
|
{renderDescription}
|
|
|
|
|
</div>
|
|
|
|
|
{renderContentRight}
|
|
|
|
|
</div>
|
|
|
|
|
<div className={classNames("level", "is-flex", "pb-4")}>
|
|
|
|
|
<div className={classNames("level-left", "is-hidden-mobile", "mr-2")}>{footerLeft}</div>
|
|
|
|
|
<InheritFlexShrinkDiv className="level-right is-block is-mobile m-0 shorten-text">
|
|
|
|
|
{footerRight}
|
|
|
|
|
</InheritFlexShrinkDiv>
|
2021-06-15 09:29:24 +02:00
|
|
|
</div>
|
2021-09-15 17:40:08 +02:00
|
|
|
</div>
|
2022-11-10 11:44:53 +01:00
|
|
|
</NoEventWrapper>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2020-04-08 15:20:35 +02:00
|
|
|
|
|
|
|
|
export default CardColumn;
|