-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathTestReactComponent.react.js
104 lines (87 loc) · 3.09 KB
/
TestReactComponent.react.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from 'react';
// A react component with all of the available proptypes to run tests over
/**
* This is a description of the component.
* It's multiple lines long.
*/
class ReactComponent extends Component {
render() {
return '';
}
}
ReactComponent.propTypes = {
/**
* Description of optionalArray
*/
optionalArray: React.PropTypes.array,
optionalBool: React.PropTypes.bool,
optionalFunc: React.PropTypes.func,
optionalNumber: React.PropTypes.number,
optionalObject: React.PropTypes.object,
optionalString: React.PropTypes.string,
optionalSymbol: React.PropTypes.symbol,
// Anything that can be rendered: numbers, strings, elements or an array
// (or fragment) containing these types.
optionalNode: React.PropTypes.node,
// A React element.
optionalElement: React.PropTypes.element,
// You can also declare that a prop is an instance of a class. This uses
// JS's instanceof operator.
optionalMessage: React.PropTypes.instanceOf(Message),
// You can ensure that your prop is limited to specific values by treating
// it as an enum.
optionalEnum: React.PropTypes.oneOf(['News', 'Photos']),
// An object that could be one of many types
optionalUnion: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number,
React.PropTypes.instanceOf(Message)
]),
// An array of a certain type
optionalArrayOf: React.PropTypes.arrayOf(React.PropTypes.number),
// An object with property values of a certain type
optionalObjectOf: React.PropTypes.objectOf(React.PropTypes.number),
// An object taking on a particular shape
optionalObjectWithShapeAndNestedDescription: React.PropTypes.shape({
color: React.PropTypes.string,
fontSize: React.PropTypes.number,
/**
* Figure is a plotly graph object
*/
figure: React.PropTypes.shape({
/**
* data is a collection of traces
*/
data: React.PropTypes.arrayOf(React.PropTypes.object),
/**
* layout describes the rest of the figure
*/
layout: React.PropTypes.object
})
}),
// A value of any data type
optionalAny: React.PropTypes.any,
customProp: function(props, propName, componentName) {
if (!/matchme/.test(props[propName])) {
return new Error(
'Invalid prop `' + propName + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
}
},
customArrayProp: React.PropTypes.arrayOf(function(propValue, key, componentName, location, propFullName) {
if (!/matchme/.test(propValue[key])) {
return new Error(
'Invalid prop `' + propFullName + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
}
}),
children: React.PropTypes.node,
id: React.PropTypes.string,
};
ReactComponent.defaultProps = {
optionalNumber: 42,
optionalString: 'hello world'
};
export default ReactComponent;