import { ComponentType, Defs, Group, Rect } from '../../jsx'; import { ItemDesc, ItemLabel } from '../components'; import { DropShadow, LinearGradient } from '../defs'; import { getItemProps } from '../utils'; import { registerItem } from './registry'; import type { BaseItemProps } from './types'; export interface PillBadgeProps extends BaseItemProps { width?: number; pillWidth?: number; pillHeight?: number; gap?: number; } export const PillBadge: ComponentType = (props) => { const [ { datum, indexes, width = 300, pillWidth = 120, pillHeight = 36, gap = 16, positionH = 'normal', themeColors, }, restProps, ] = getItemProps(props, ['width', 'pillWidth', 'pillHeight', 'gap']); // Optimize: when no description, use pillWidth as component width const hasDesc = !!datum.desc; const componentWidth = hasDesc ? width : pillWidth; // Calculate pill position based on alignment const pillX = hasDesc ? positionH === 'center' ? (componentWidth - pillWidth) / 2 : positionH === 'flipped' ? componentWidth - pillWidth : 0 : 0; // Always 0 when no description const pillY = 0; // Calculate content position (only needed when hasDesc is true) const contentX = hasDesc ? positionH === 'center' ? 0 : positionH === 'flipped' ? 0 : 0 : 0; const contentY = pillHeight + gap; const contentWidth = componentWidth; const dropShadowId = `drop-shadow-${themeColors.colorPrimary}`; const linearGradientId = `linear-gradient-white-top-bottom`; return ( {/* Pill-shaped badge */} {/* Pill label */} {datum.label} {/* Description below */} {datum.desc && ( {datum.desc} )} ); }; registerItem('pill-badge', { component: PillBadge, composites: ['label', 'desc'], });