UNPKG

2.31 kBTypeScriptView Raw
1/**
2 * @fileOverview Default Legend Content
3 */
4import React, { PureComponent, ReactNode, MouseEvent, ReactElement } from 'react';
5import { DataKey, LegendType, LayoutType, PresentationAttributesAdaptChildEvent } from '../util/types';
6export type ContentType = ReactElement | ((props: Props) => ReactNode);
7export type IconType = Exclude<LegendType, 'none'>;
8export type HorizontalAlignmentType = 'center' | 'left' | 'right';
9export type VerticalAlignmentType = 'top' | 'bottom' | 'middle';
10export type Formatter = (value: any, entry: {
11 value: any;
12 id?: string;
13 type?: LegendType;
14 color?: string;
15 payload?: {
16 strokeDasharray: string | number;
17 value?: any;
18 };
19}, index: number) => ReactNode;
20export interface Payload {
21 value: any;
22 id?: string;
23 type?: LegendType;
24 color?: string;
25 payload?: {
26 strokeDasharray: string | number;
27 value?: any;
28 };
29 formatter?: Formatter;
30 inactive?: boolean;
31 legendIcon?: ReactElement<SVGElement>;
32 dataKey?: DataKey<any>;
33}
34interface InternalProps {
35 content?: ContentType;
36 iconSize?: number;
37 iconType?: IconType;
38 layout?: LayoutType;
39 align?: HorizontalAlignmentType;
40 verticalAlign?: VerticalAlignmentType;
41 payload?: Array<Payload>;
42 inactiveColor?: string;
43 formatter?: Formatter;
44 onMouseEnter?: (data: Payload, index: number, event: MouseEvent) => void;
45 onMouseLeave?: (data: Payload, index: number, event: MouseEvent) => void;
46 onClick?: (data: Payload, index: number, event: MouseEvent) => void;
47}
48export type Props = InternalProps & Omit<PresentationAttributesAdaptChildEvent<any, ReactElement>, keyof InternalProps>;
49export declare class DefaultLegendContent extends PureComponent<Props> {
50 static displayName: string;
51 static defaultProps: {
52 iconSize: number;
53 layout: string;
54 align: string;
55 verticalAlign: string;
56 inactiveColor: string;
57 };
58 /**
59 * Render the path of icon
60 * @param {Object} data Data of each legend item
61 * @return {String} Path element
62 */
63 renderIcon(data: Payload): React.JSX.Element;
64 /**
65 * Draw items of legend
66 * @return {ReactElement} Items
67 */
68 renderItems(): React.JSX.Element[];
69 render(): React.JSX.Element;
70}
71export {};