2019-09-26 18:07:11 +02:00
|
|
|
// @flow
|
|
|
|
import type { Node } from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
|
|
|
|
type Props = {
|
2019-09-27 20:56:15 +02:00
|
|
|
title?: string | Node,
|
2019-09-26 18:07:11 +02:00
|
|
|
subtitle?: string | Node,
|
|
|
|
body?: string | Node,
|
|
|
|
actions?: string | Node,
|
|
|
|
icon?: string,
|
2019-11-22 22:13:00 +01:00
|
|
|
className?: string,
|
2020-04-01 20:43:50 +02:00
|
|
|
isPageTitle?: boolean,
|
|
|
|
isBodyTable?: boolean,
|
2019-11-22 22:13:00 +01:00
|
|
|
actionIconPadding?: boolean,
|
2019-09-26 18:07:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function Card(props: Props) {
|
2020-04-01 20:43:50 +02:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
subtitle,
|
|
|
|
body,
|
|
|
|
actions,
|
|
|
|
icon,
|
|
|
|
className,
|
|
|
|
isPageTitle = false,
|
|
|
|
isBodyTable = false,
|
|
|
|
actionIconPadding = true,
|
|
|
|
} = props;
|
2019-09-26 18:07:11 +02:00
|
|
|
return (
|
2019-11-22 22:13:00 +01:00
|
|
|
<section className={classnames(className, 'card')}>
|
2020-02-13 19:04:50 +01:00
|
|
|
{(title || subtitle) && (
|
2019-09-27 20:56:15 +02:00
|
|
|
<div className="card__header">
|
2020-04-01 20:43:50 +02:00
|
|
|
{icon && <Icon sectionIcon icon={icon} />}
|
|
|
|
<div>
|
|
|
|
{isPageTitle && <h1 className="card__title">{title}</h1>}
|
|
|
|
{!isPageTitle && <h2 className="card__title">{title}</h2>}
|
|
|
|
{subtitle && <div className="card__subtitle">{subtitle}</div>}
|
2019-09-26 18:07:11 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-27 20:56:15 +02:00
|
|
|
)}
|
2019-09-26 18:07:11 +02:00
|
|
|
|
2020-04-01 20:43:50 +02:00
|
|
|
{body && (
|
|
|
|
<div
|
|
|
|
className={classnames('card__body', {
|
|
|
|
'card__body--with-icon': icon,
|
|
|
|
'card__body--no-title': !title && !subtitle,
|
|
|
|
'card__body--table': isBodyTable,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{body}
|
|
|
|
</div>
|
|
|
|
)}
|
2019-09-26 18:07:11 +02:00
|
|
|
{actions && (
|
2019-11-22 22:13:00 +01:00
|
|
|
<div
|
|
|
|
className={classnames('card__main-actions', { 'card__main-actions--with-icon': icon && actionIconPadding })}
|
|
|
|
>
|
|
|
|
{actions}
|
|
|
|
</div>
|
2019-09-26 18:07:11 +02:00
|
|
|
)}
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|