import { ComponentType, Defs, Group, Rect } from '../../jsx'; import { ItemDesc, ItemIcon, ItemLabel, ItemValue } from '../components'; import { FlexLayout } from '../layouts'; import { getItemProps } from '../utils'; import { registerItem } from './registry'; import type { BaseItemProps } from './types'; export interface CompactCardProps extends BaseItemProps { width?: number; height?: number; iconSize?: number; gap?: number; } export const CompactCard: ComponentType = (props) => { const [ { datum, indexes, width = 200, height = 60, iconSize = 20, gap = 8, positionH = 'normal', themeColors, valueFormatter, }, restProps, ] = getItemProps(props, ['width', 'height', 'iconSize', 'gap']); const value = datum.value; const hasValue = value !== undefined && value !== null; const shadowId = 'compact-shadow'; const iconX = positionH === 'flipped' ? width - gap - iconSize : gap; const textStartX = positionH === 'flipped' ? gap : iconSize + 2 * gap; const textWidth = width - iconSize - 3 * gap; // 为 Label 和 Value 分配空间 const labelWidth = hasValue ? textWidth * 0.8 : textWidth; const valueWidth = hasValue ? textWidth * 0.2 : 0; return ( {/* 背景 */} {/* 侧边色条 */} {/* 图标 */} {/* 标签和数值所在行 */} {/* 标签 - 始终左对齐 */} {datum.label} {/* 数值 - 始终右对齐 */} {hasValue && ( )} {/* 描述 - 第二行 */} {datum.desc} ); }; registerItem('compact-card', { component: CompactCard, composites: ['icon', 'label', 'value', 'desc'], });