/
FunctionSignature.js
46 lines (41 loc) · 1.06 KB
/
FunctionSignature.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
const React = require('react');
const { bool, object, } = React.PropTypes;
const describeType = require('../utils/describeType');
const FunctionSignature = React.createClass({
propTypes: {
doc: object,
withNames: bool,
withBraces: bool,
},
getDefaultProps() {
return {
withNames: true,
withBraces: true
};
},
render() {
const { withNames } = this.props;
const html = this.props.doc.tags
.filter(function(tag) {
return tag.type === 'param' && (tag.typeInfo.name || '?').indexOf('.') === -1;
})
.map(function(param) {
if (withNames) {
return '<em>' + (param.typeInfo.name || '?') + '</em>: ' + describeType(param.typeInfo.type);
}
else {
return describeType(param.typeInfo.type);
}
}).join(', ')
;
return (
<span
className="doc-entity__function-signature"
dangerouslySetInnerHTML={{
__html: this.props.withBraces ? `(${html})` : html
}}
/>
);
}
});
module.exports = FunctionSignature;