-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCardHeader.tsx
More file actions
42 lines (35 loc) · 1.48 KB
/
CardHeader.tsx
File metadata and controls
42 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from "react";
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
import { OverviewItemDescription } from "./../OverviewItem";
import OverviewItem, { OverviewItemProps } from "./../OverviewItem/OverviewItem";
import CardOptions from "./CardOptions";
import CardTitle from "./CardTitle";
export interface CardHeaderProps extends Omit<OverviewItemProps, "densityHigh" | "hasSpacing"> {
children: React.JSX.Element | (React.JSX.Element | undefined | null)[] | null | undefined;
}
export const CardHeader = ({ children, className = "", ...otherProps }: CardHeaderProps) => {
const actions: any[] = [];
const description: any[] = [];
children &&
(Array.isArray(children) ? children : [children]).forEach((child) => {
if (typeof child === "object" && child && !!child.type) {
switch (child.type) {
case CardTitle:
description.push(child);
break;
case CardOptions:
actions.push(child);
break;
}
}
});
return (
<header>
<OverviewItem {...otherProps} className={`${eccgui}-card__header ` + className} densityHigh={true}>
{description.length > 0 && <OverviewItemDescription>{description}</OverviewItemDescription>}
{actions}
</OverviewItem>
</header>
);
};
export default CardHeader;