import { ComponentType, Ellipse, getElementBounds, Rect, Text, } from '../../jsx'; import { Gap, ItemDesc, ItemIconCircle, ItemLabel } from '../components'; import { AlignLayout, FlexLayout } from '../layouts'; import { getItemProps } from '../utils'; import { registerItem } from './registry'; import type { BaseItemProps } from './types'; export interface HorizontalIconLineProps extends BaseItemProps { width?: number; } export const HorizontalIconLine: ComponentType = ( props, ) => { const [ { indexes, datum, width = 160, themeColors, positionH = 'center', positionV = 'normal', }, restProps, ] = getItemProps(props, ['width']); const textAlignHorizontal = positionH === 'normal' ? 'left' : positionH === 'flipped' ? 'right' : 'center'; const label = ( {datum.label} ); const labelBounds = getElementBounds(label); const desc = datum.desc ? ( {datum.desc} ) : null; const descBounds = getElementBounds(desc); const iconSize = 45; const icon = datum.icon ? ( ) : null; const iconBounds = getElementBounds(icon); const time = datum.time ? ( {datum.time} ) : null; const timeBounds = getElementBounds(time); const lineHeight = 18; const line = ( ); const textSideHeight = labelBounds.height + descBounds.height; const iconSideHeight = iconBounds.height + timeBounds.height + 5; // 平衡line两侧高度,使 line 位于垂直居中位置 const heightDiff = Math.abs(iconSideHeight - textSideHeight); const topBalance = iconSideHeight > textSideHeight ? heightDiff : 0; const bottomBalance = textSideHeight > iconSideHeight ? heightDiff : 0; if (positionV === 'flipped') { return ( {time} {icon} {line} {label} {desc} ); } return ( {label} {desc} {line} {icon} {time} ); }; registerItem('horizontal-icon-line', { component: HorizontalIconLine, composites: ['icon', 'label', 'desc'], });