UNPKG

qt-public-ui

Version:

新设计规范下业务组件库

56 lines 2.17 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; var _excluded = ["title", "defaultVisible", "visible", "onVisibleChange", "className"]; import React, { useState, useEffect, useRef } from 'react'; import { Card } from 'antd'; import { IconSlim as Icon } from '..'; import classnames from 'classnames'; import './style'; var Expand = function Expand(props) { var title = props.title, defaultVisible = props.defaultVisible, visible = props.visible, onVisibleChange = props.onVisibleChange, className = props.className, cardProps = _objectWithoutPropertiesLoose(props, _excluded); var isControlled = ('visible' in props); var _useState = useState(isControlled ? visible : defaultVisible), expand = _useState[0], setExpand = _useState[1]; var _useState2 = useState(props.bodyHeight || 0), height = _useState2[0], setHeight = _useState2[1]; var contentRef = useRef(null); var onExpand = function onExpand() { onVisibleChange && onVisibleChange(!expand); !isControlled && setExpand(!expand); }; useEffect(function () { if (contentRef.current) { !height && setHeight(contentRef.current.offsetHeight || 0); } }, [expand]); useEffect(function () { isControlled && setExpand(props.visible); }, [isControlled, props.visible]); return /*#__PURE__*/React.createElement(Card, _extends({ className: classnames('umui-expand-card', className), title: /*#__PURE__*/React.createElement("span", { className: "umui-expand-controller", onClick: onExpand }, expand ? /*#__PURE__*/React.createElement(Icon, { type: "umicon-circle-up", className: "umui-expand-icon" }) : /*#__PURE__*/React.createElement(Icon, { type: "umicon-circle-down", className: "umui-expand-icon" }), title) }, cardProps), /*#__PURE__*/React.createElement("div", { ref: contentRef, className: classnames('umui-expand-wrapper-inner', { 'umui-expandless': !expand }) }, props.children)); }; Expand.displayName = 'Expand'; export default Expand;