/
Title.tsx
42 lines (35 loc) · 1.09 KB
/
Title.tsx
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
import type {ReactElement, ReactNode} from 'react';
import type {Position, Series} from './types';
import React from 'react';
import {getCoords, isFunction, isString} from './helpers';
import {Style} from './types';
export type TitleProps = {
children: ReactNode | ((props: TitleProps) => ReactNode);
textAnchor?: 'start' | 'middle' | 'end';
className?: string;
style?: Style;
width?: number;
height?: number;
position?: Position;
layerWidth?: number;
layerHeight?: number,
series?: Series[]
}
export function Title(props: TitleProps): ReactElement {
const {style, className, children} = props;
const {x, y} = getCoords(
props.position,
props.layerWidth, props.layerHeight,
props.width, props.height
);
return (
<g
className={className}
transform={`translate(${x} ${y})`}
style={style}>
{isString(children)
? <text textAnchor={props.textAnchor}>{children}</text>
: (isFunction(children) ? children(props) : children)}
</g>
);
}