Added type definitions for react-addons

This commit is contained in:
Austen Talbot
2014-10-01 18:38:22 -07:00
parent bf5cd4b9b1
commit c01768cc27
3 changed files with 199 additions and 16 deletions

View File

@@ -105,3 +105,29 @@ var Timer = React.createClass({displayName: 'Timer',
});
React.renderComponent(Timer(null), mountNode);
// TestUtils
var that: React.Component<any, any>;
var node = that.refs['input'].getDOMNode();
React.addons.TestUtils.Simulate.click(node);
React.addons.TestUtils.Simulate.change(node);
React.addons.TestUtils.Simulate.keyDown(node, {key: "Enter"});
var GoodbyeMessage = React.createClass({displayName: 'GoodbyeMessage',
render: function() {
return React.DOM.div(null, "Goodbye ", (<React.Component<{name: string}, any>>this).props.name);
}
});
React.addons.TestUtils.renderIntoDocument(GoodbyeMessage({name: "John"}));
var isImportant: boolean;
var isRead: boolean;
var cx = React.addons.classSet;
var classes = cx({
'message': true,
'message-important': isImportant,
'message-read': isRead
});

View File

@@ -10,5 +10,162 @@ declare module "react/addons" {
}
declare module React {
export var addons: {};
}
export var addons: {
classSet: (classes: {[key: string]: boolean}) => string;
cloneWithProps: CloneWithProps<any>;
CSSTransitionGroup: Factory<CSSTransitionGroupProps>;
LinkedStateMixin: LinkedStateMixin<any, any>;
Perf: Perf;
PureRenderMixin: Mixin<any, any>;
TestUtils: TestUtils;
TransitionGroup: Factory<any>;
update(object: Object, changes: Object): Object;
};
export interface CloneWithProps<P> {
(instance: Descriptor<P>, extraProps?: P): Descriptor<P>;
}
export interface ReactLink<T> {
value: T;
requestChange(newValue: T): void;
}
export interface LinkedStateMixin<P, S> extends Mixin<P, S> {
linkState<T>(key: string): ReactLink<T>;
}
export interface ComponentPerfContext {
current: string;
owner: string;
}
export interface CSSTransitionGroupProps {
transitionName: string;
}
export interface TransitionsSpecification<P, S> extends Specification<P, S> {
componentWillEnter?(callback: () => void): void;
componentDidEnter?(): void;
componentWillLeave?(callback: () => void): void;
componentDidLeave?(): void;
}
export interface NumericPerfContext {
[key: string]: number;
}
export interface Measurements {
exclusive: NumericPerfContext;
inclusive: NumericPerfContext;
render: NumericPerfContext;
counts: NumericPerfContext;
writes: NumericPerfContext;
displayNames: {
[key: string]: ComponentPerfContext;
};
totalTime: number;
}
export interface Perf {
start(): void;
stop(): void;
printInclusive(measurements: Measurements[]): void;
printExclusive(measurements: Measurements[]): void;
printWasted(measurements: Measurements[]): void;
printDOM(measurements: Measurements[]): void;
getLastMeasurements(): Measurements[];
}
export interface TestUtils {
Simulate: Simulate;
renderIntoDocument(instance: Descriptor<any>): Descriptor<any>;
mockComponent(componentClass: Factory<any>, mockTagName?: string): TestUtils;
isDescriptorOfType(descriptor: Descriptor<any>, componentClass: Factory<any>): boolean;
isDOMComponent(instance: Descriptor<any>): boolean;
isCompositeComponent(instance: Descriptor<any>): boolean;
isCompositeComponentWithType(instance: Descriptor<any>, componentClass: Function): boolean;
isTextComponent(instance: Descriptor<any>): boolean;
findAllInRenderedTree(tree: Descriptor<any>, test: Function): Descriptor<any>[];
scryRenderedDOMComponentsWithClass(tree: Descriptor<any>, className: string): Descriptor<any>[];
findRenderedDOMComponentWithClass(tree: Descriptor<any>, className: string): Descriptor<any>;
scryRenderedDOMComponentsWithTag(tree: Descriptor<any>, className: string): Descriptor<any>[];
findRenderedDOMComponentWithTag(tree: Descriptor<any>, tagName: string): Descriptor<any>;
scryFindRenderedComponentsWithTag(tree: Descriptor<any>, componentClass: Function): Descriptor<any>[];
findRenderedComponentWithType(tree: Descriptor<any>, componentClass: Function): Descriptor<any>;
}
export interface SyntheticEventData {
altKey?: boolean;
button?: number;
buttons?: number;
clientX?: number;
clientY?: number;
changedTouches?: TouchList;
charCode?: boolean;
clipboardData?: DataTransfer;
ctrlKey?: boolean;
deltaMode?: number;
deltaX?: number;
deltaY?: number;
deltaZ?: number;
detail?: number;
getModifierState?(key: string): boolean;
key?: string;
keyCode?: number;
locale?: string;
location?: number;
metaKey?: boolean;
pageX?: number;
pageY?: number;
relatedTarget?: EventTarget;
repeat?: boolean;
screenX?: number;
screenY?: number;
shiftKey?: boolean;
targetTouches?: TouchList;
touches?: TouchList;
view?: AbstractView;
which?: number;
}
export interface EventSimulator {
(element: Element, eventData?: SyntheticEventData): void;
}
export interface Simulate {
blur: EventSimulator;
change: EventSimulator;
click: EventSimulator;
cut: EventSimulator;
doubleClick: EventSimulator;
drag: EventSimulator;
dragEnd: EventSimulator;
dragEnter: EventSimulator;
dragExit: EventSimulator;
dragLeave: EventSimulator;
dragOver: EventSimulator;
dragStart: EventSimulator;
drop: EventSimulator;
focus: EventSimulator;
input: EventSimulator;
keyDown: EventSimulator;
keyPress: EventSimulator;
keyUp: EventSimulator;
mouseDown: EventSimulator;
mouseEnter: EventSimulator;
mouseLeave: EventSimulator;
mouseMove: EventSimulator;
mouseOut: EventSimulator;
mouseOver: EventSimulator;
mouseUp: EventSimulator;
paste: EventSimulator;
scroll: EventSimulator;
submit: EventSimulator;
touchCancel: EventSimulator;
touchEnd: EventSimulator;
touchMove: EventSimulator;
touchStart: EventSimulator;
wheel: EventSimulator;
}
}

28
react/react.d.ts vendored
View File

@@ -54,8 +54,8 @@ declare module React {
render(): Descriptor<any>;
}
interface DomReferencer {
getDomNode(): Element;
export interface DomReferencer {
getDOMNode(): Element;
}
export interface Component<P, S> extends DomReferencer {
@@ -73,19 +73,19 @@ declare module React {
replaceProps(nextProps: P, callback?: () => void): void;
}
interface Constructable {
export interface Constructable {
new(): any;
}
interface Validator<P> {
export interface Validator<P> {
(props: P, propName: string, componentName: string): Error;
}
interface Requireable<P> extends Validator<P> {
export interface Requireable<P> extends Validator<P> {
isRequired: Validator<P>;
}
interface ValidationMap<P> {
export interface ValidationMap<P> {
[key: string]: Validator<P>;
}
@@ -116,12 +116,12 @@ declare module React {
// Browser Interfaces
// Taken from https://github.com/nikeee/2048-typescript/blob/master/2048/js/touch.d.ts
interface AbstractView {
export interface AbstractView {
styleMedia: StyleMedia;
document: Document;
}
interface Touch {
export interface Touch {
identifier: number;
target: EventTarget;
screenX: number;
@@ -132,7 +132,7 @@ declare module React {
pageY: number;
}
interface TouchList {
export interface TouchList {
[index: number]: Touch;
length: number;
item(index: number): Touch;
@@ -218,7 +218,7 @@ declare module React {
}
// Attributes
interface EventAttributes {
export interface EventAttributes {
onCopy?: (event: ClipboardEvent) => void;
onCut?: (event: ClipboardEvent) => void;
onPaste?: (event: ClipboardEvent) => void;
@@ -255,7 +255,7 @@ declare module React {
onWheel?: (event: WheelEvent) => void;
}
interface DomAttributes extends EventAttributes {
export interface DomAttributes extends EventAttributes {
// HTML Attributes
accept?: any;
accessKey?: any;
@@ -351,7 +351,7 @@ declare module React {
wmode?: any;
}
interface SvgAttributes extends EventAttributes {
export interface SvgAttributes extends EventAttributes {
cx?: any;
cy?: any;
d?: any;
@@ -397,10 +397,10 @@ declare module React {
y?: any;
}
interface DomElement extends Factory<DomAttributes> {
export interface DomElement extends Factory<DomAttributes> {
}
interface SvgElement extends Factory<SvgAttributes> {
export interface SvgElement extends Factory<SvgAttributes> {
}
export var DOM: {