import * as React from "react"; import { Button, Card } from "antd"; import "./index.css"; import { DownOutlined, RightOutlined } from "@ant-design/icons"; import { CardProps } from "antd/lib/card"; import ToolTipBar from "../../detail/tooltipbar"; import { LocaleContext } from "../../locale/LocaleProvider"; interface CollapseCardProps extends CardProps { initCollapse?: boolean; tip?: any; showRightNav?: boolean; } interface CollapseCardState { collapse?: boolean; } export default class CollapseCard extends React.PureComponent< CollapseCardProps, CollapseCardState > { state = { collapse: false, }; static contextType = LocaleContext; context: React.ContextType; componentDidMount() { const { initCollapse } = this.props; this.setState({ collapse: initCollapse, }); } componentDidUpdate(prevProps) { const { initCollapse } = this.props; if (this.props != prevProps) { this.setState({ collapse: initCollapse, }); } } cardTitle = () => { const { title, tip } = this.props; const { collapse } = this.state; const { translate } = this.context; if (!title || "null" == title) { //没title不显示card 头 ,同时不支持伸缩。 return null; } let titleBegin = null; if (collapse) { titleBegin = ( ); } else { titleBegin = ( ); } return ( <> {titleBegin} ); }; render() { const { collapse } = this.state; const { extra, title, className, initCollapse, showRightNav, ...other } = this.props; return ( {collapse ? null : this.props.children} ); } }