import React, { FC, useRef, useEffect, useState } from 'react' import classNames from 'classnames' import _ from 'lodash' import { Flex } from '../flex' import { Popover } from '../popover' import { List } from '../list' import Label, { LabelType } from '../label' import SVGMore from '../../svg/more.svg' import FromCard, { FromCardProps } from './form_card' interface CardActions { text: string onClick(): void } interface CardProps extends FromCardProps { title?: string labelType?: LabelType labelText?: string topLabelText?: string inactive?: boolean onClick?(...args: any[]): any /** 右上角功能定义 */ className?: string actions?: CardActions[] } const Card: FC = (props) => { const { className, title, actions, labelType, labelText, topLabelText, children, inactive, onClick, type, ...rest } = props const popoverRef = useRef(null) const moreList = _.map(actions || [], (v, i) => ({ value: i, text: v.text })) const handleSelect = (value: number): void => { popoverRef.current!.apiDoSetActive(false) actions && actions[value].onClick() } // 老Card不能支撑起业务, 以后尽量用FromCard if (type === 'form-card') return return (
{topLabelText && ( )} {actions && ( } >
)}
{labelText && ( )} {title || '-'}
} >
{title || '-'}
{children}
) } const TopLabel: FC<{ text: string }> = ({ text }) => { const ref = useRef(null) const [width, setWidth] = useState(0) useEffect(() => { if (ref.current) { setWidth(ref.current.getBoundingClientRect().width) } }, [ref]) return (
{text}
) } export default Card export type { CardProps }