-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathBulletText.tsx
More file actions
81 lines (74 loc) · 1.81 KB
/
Copy pathBulletText.tsx
File metadata and controls
81 lines (74 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/** @jsxImportSource @antv/infographic-jsx */
import { ComponentType, Ellipse, Group } from '@antv/infographic-jsx';
import { ItemLabel } from '../components';
import { getItemProps } from '../utils';
import { registerItem } from './registry';
import type { BaseItemProps } from './types';
export interface BulletTextProps extends BaseItemProps {
width?: number;
bulletSize?: number;
bulletType?: 'circle' | 'none';
fontSize?: number;
}
/**
* 圆点+文字列表项组件
*/
export const BulletText: ComponentType<BulletTextProps> = (props) => {
const [
{
indexes,
datum,
width = 300,
height = 30,
bulletSize = 5,
bulletType = 'circle',
fontSize = 14,
themeColors,
},
restProps,
] = getItemProps(props, [
'width',
'bulletSize',
'bulletType',
'fontSize',
'itemBackgroundAlpha',
]);
const textColor = themeColors.colorPrimary;
const bulletX = 40;
const bulletGap = bulletType !== 'none' ? bulletSize + 12 : 0;
const textX = bulletX + bulletGap;
const contentY = fontSize / 2;
const textWidth = width - 2 * bulletX - bulletGap;
return (
<Group {...restProps}>
{bulletType === 'circle' && (
<Ellipse
x={bulletX}
y={contentY}
width={bulletSize}
height={bulletSize}
fill={textColor}
/>
)}
<ItemLabel
{...restProps}
x={textX}
y={contentY - fontSize / 2}
indexes={indexes}
width={textWidth}
height={height}
fill={textColor}
fontSize={14}
fontWeight="regular"
alignHorizontal="left"
alignVertical="top"
>
{datum.label || datum.desc}
</ItemLabel>
</Group>
);
};
registerItem('bullet-text', {
component: BulletText,
composites: ['label'],
});