2021-04-20 23:22:31 +00:00
|
|
|
import React, {isValidElement} from "react"
|
2021-04-20 23:03:59 +00:00
|
|
|
import Style from "./BoxWithHeader.module.css"
|
|
|
|
import classNames from "classnames"
|
2021-04-20 23:22:31 +00:00
|
|
|
import isString from "is-string"
|
2021-04-20 23:03:59 +00:00
|
|
|
|
|
|
|
|
2021-04-20 23:22:31 +00:00
|
|
|
export default function BoxWithHeader({ header, body, children, className, ...props }) {
|
|
|
|
|
|
|
|
if(isValidElement(header) || isString(header)) {
|
|
|
|
header = {
|
|
|
|
children: header
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isValidElement(body) || isString(body)) {
|
|
|
|
body = {
|
|
|
|
children: body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:55:57 +00:00
|
|
|
if(header === undefined) {
|
|
|
|
header = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(body === undefined) {
|
|
|
|
body = {}
|
|
|
|
}
|
|
|
|
|
2021-04-20 23:22:31 +00:00
|
|
|
if(children) {
|
2021-04-21 00:55:57 +00:00
|
|
|
|
2021-04-20 23:22:31 +00:00
|
|
|
if(body.children) {
|
|
|
|
throw new Error("If directly passing `children` to BoxWithHeader, body.children should not be set.")
|
|
|
|
}
|
|
|
|
|
|
|
|
body["children"] = children
|
|
|
|
}
|
|
|
|
|
2021-04-20 23:03:59 +00:00
|
|
|
return (
|
|
|
|
<div className={classNames(Style.BoxWithHeader, className)} {...props}>
|
|
|
|
<div className={classNames(Style.BoxHeader, header.className)}>
|
|
|
|
{header.children}
|
|
|
|
</div>
|
|
|
|
<div className={classNames(Style.BoxBody, body.className)}>
|
|
|
|
{body.children}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|