import React, { FC, HTMLAttributes, ReactNode, useState } from 'react' import classNames from 'classnames' import _ from 'lodash' import { Collapse } from '../collapse' import { Flex } from '../flex' import SVGUp from '../../svg/up.svg' import SVGDown from '../../svg/down.svg' interface BoxPanelSummaryData { text: string value: any } type BoxPanelSummary = BoxPanelSummaryData[] | ReactNode interface BoxPanelProps extends HTMLAttributes { title: string /* 不传就是没有此功能, false 默认收起 true 默认展开 */ collapse?: boolean right?: ReactNode summary?: BoxPanelSummary } const BoxPanel: FC = ({ title, collapse, right, summary, className, children, ...rest }) => { const hasCollapse = collapse !== undefined const [isCollapse, setIsCollapse] = useState(hasCollapse ? collapse : true) const handleCollapse = () => { setIsCollapse(!isCollapse) } return ( {hasCollapse && ( {isCollapse ? : } )} {title} {_.isArray(summary) ? ( {_.map(summary, (s: BoxPanelSummaryData, i) => { if (i < summary.length - 1) return ( {s.text}: {s.value} , ) else return ( {s.text}: {s.value} ) })} ) : ( {summary} )} {right} {children} ) } export default BoxPanel export type { BoxPanelProps }