-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathSimpleIllusItem.tsx
More file actions
77 lines (69 loc) · 1.92 KB
/
Copy pathSimpleIllusItem.tsx
File metadata and controls
77 lines (69 loc) · 1.92 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
/** @jsxImportSource @antv/infographic-jsx */
import { ComponentType, getElementBounds, Group } from '@antv/infographic-jsx';
import { Illus, ItemDesc, ItemLabel } from '../components';
import { getItemProps } from '../utils';
import { registerItem } from './registry';
import type { BaseItemProps } from './types';
export interface SimpleIllusItemProps extends BaseItemProps {
width?: number;
illusSize?: number;
gap?: number;
}
export const SimpleIllusItem: ComponentType<SimpleIllusItemProps> = (props) => {
const [
{ indexes, datum, width = 180, illusSize = width, gap = 8, themeColors },
restProps,
] = getItemProps(props, ['width', 'illusSize', 'gap']);
const { label, desc } = datum;
const labelContent = (
<ItemLabel
indexes={indexes}
width={width}
alignHorizontal="center"
alignVertical="center"
fill={themeColors.colorText}
>
{label}
</ItemLabel>
);
const labelBounds = getElementBounds(labelContent);
return (
<Group {...restProps}>
{/* Illus - centered */}
<Illus
indexes={indexes}
x={(width - illusSize) / 2}
y={0}
width={illusSize}
height={illusSize}
/>
{/* ItemLabel - centered below Illus */}
<ItemLabel
indexes={indexes}
width={width}
y={illusSize + gap}
alignHorizontal="center"
alignVertical="center"
fill={themeColors.colorText}
>
{label}
</ItemLabel>
{/* ItemDesc - centered below Label */}
<ItemDesc
indexes={indexes}
width={width}
y={illusSize + gap + labelBounds.height + gap}
alignHorizontal="center"
alignVertical="top"
fill={themeColors.colorTextSecondary}
lineNumber={3}
>
{desc}
</ItemDesc>
</Group>
);
};
registerItem('simple-illus', {
component: SimpleIllusItem,
composites: ['illus', 'label', 'desc'],
});