import React, { useState } from 'react'; import classNames from 'classnames'; import { BadgeStatus } from '@/components'; import { StatusColorEnum } from '@/components/BadgeStatus'; import type { StatusColorType } from '@/components/BadgeStatus'; import './index.less'; export interface TableCardProps { className?: string; showStatus?: boolean; showTool?: boolean; showMask?: boolean; detail?: React.ReactNode; status?: string | number; statusText?: React.ReactNode; statusNames?: Record; children?: React.ReactNode; actions?: React.ReactNode[]; contentClassName?: string; } function getAction(actions: React.ReactNode[]) { return actions .filter((item) => item) .map((item: any) => { return (
{item}
); }); } export default (props: TableCardProps) => { const [maskShow, setMaskShow] = useState(false); const handleStatusColor = (data: TableCardProps): StatusColorType | undefined => { if ('statusNames' in data && data.status !== undefined) { return data.statusNames![data.status]; } return StatusColorEnum.default; }; const statusNode = props.showStatus === false ? null : (
); const maskClassName = classNames('card-mask', { show: maskShow }); const maskNode = props.showMask === false ? null :
{props.detail}
; const toolNode = props.showTool === false ? null : (
{props.actions && props.actions.length ? getAction(props.actions) : null}
); return (
{ setMaskShow(true); }} onMouseLeave={() => { setMaskShow(false); }} > {props.children} {statusNode} {maskNode}
{toolNode}
); };