feat: add definitions for react-sparklines (#28640)

This commit is contained in:
Henri Normak
2018-09-11 03:03:32 +03:00
committed by Ryan Cavanaugh
parent e4e063b8bd
commit 7f376606df
4 changed files with 141 additions and 0 deletions

77
types/react-sparklines/index.d.ts vendored Normal file
View File

@@ -0,0 +1,77 @@
// Type definitions for react-sparklines 1.7
// Project: https://github.com/borisyankov/react-sparklines#readme
// Definitions by: Henri Normak <https://github.com/henrinormak>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export interface Point {
x: number;
y: number;
}
export interface SparklinesProps {
data?: number[];
limit?: number;
width?: number;
height?: number;
svgWidth?: React.SVGAttributes<React.ReactSVGElement>['width'];
svgHeight?: React.SVGAttributes<React.ReactSVGElement>['height'];
preserveAspectRatio?: React.SVGAttributes<React.ReactSVGElement>['preserveAspectRatio'];
margin?: number;
min?: number;
max?: number;
style?: React.SVGAttributes<React.ReactSVGElement>['style'];
}
export class Sparklines extends React.PureComponent<SparklinesProps> {}
export interface SparklinesBarsProps {
points?: Point[];
height?: number;
style?: React.SVGAttributes<React.ReactSVGElement>['style'];
barWidth?: number;
margin?: number;
onMouseMove?: (p: Point, event: React.MouseEvent<React.ReactSVGElement>) => void;
}
export class SparklinesBars extends React.Component<SparklinesBarsProps> {}
export interface SparklinesCurveProps {
color?: React.SVGAttributes<React.ReactSVGElement>['color'];
style?: React.SVGAttributes<React.ReactSVGElement>['style'];
}
export class SparklinesCurve extends React.Component<SparklinesCurveProps> {}
export interface SparklinesLineProps {
color?: React.SVGAttributes<React.ReactSVGElement>['color'];
style?: React.SVGAttributes<React.ReactSVGElement>['style'];
onMouseMove?: (event: 'enter' | 'click', value: number, point: Point) => void;
}
export class SparklinesLine extends React.Component<SparklinesLineProps> {}
export interface SparklinesNormalBandProps {
style?: React.SVGAttributes<React.ReactSVGElement>['style'];
}
export class SparklinesNormalBand extends React.Component<SparklinesNormalBandProps> {}
export interface SparklinesReferenceLineProps {
type?: 'max' | 'min' | 'mean' | 'avg' | 'median' | 'custom';
value?: number;
style?: React.SVGAttributes<React.ReactSVGElement>['style'];
}
export class SparklinesReferenceLine extends React.Component<SparklinesReferenceLineProps> {}
export interface SparklinesSpotsProps {
size?: number;
style?: React.SVGAttributes<React.ReactSVGElement>['style'];
spotColors?: { [change: string]: string };
}
export class SparklinesSpots extends React.Component<SparklinesSpotsProps> {}
export interface SparklinesTextProps {
text?: string;
point?: Point;
fontSize?: number;
fontFamily?: string;
}
export class SparklinesText extends React.Component<SparklinesTextProps> {}

View File

@@ -0,0 +1,39 @@
import * as React from 'react';
import {
Sparklines,
SparklinesLine,
SparklinesCurve,
SparklinesBars,
SparklinesReferenceLine,
SparklinesNormalBand,
SparklinesSpots,
SparklinesText,
} from 'react-sparklines';
class SparklinesDefaultTest extends React.Component {
render() {
return (
<Sparklines>
<SparklinesLine />
<SparklinesBars />
<SparklinesCurve />
<SparklinesReferenceLine />
<SparklinesNormalBand />
<SparklinesSpots />
<SparklinesText />
</Sparklines>
);
}
}
class SparklinesRegularTest extends React.Component {
render() {
return (
<Sparklines data={[0, 1, 2, 3, 4, 5, 10, 23, 0, 5]}>
<SparklinesBars style={{ fill: '#273e62', opacity: 0.25 }} />
<SparklinesLine color="#273e62" />
<SparklinesSpots style={{ fill: '#00aaff' }} />
</Sparklines>
);
}
}

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"jsx": "react",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"react-sparklines-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }