/
index.js
158 lines (139 loc) · 3.92 KB
/
index.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"use strict";
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/* @flow */
require("./styles.css");
var React = require("react");
var Autodoc = React.createClass({
displayName: "Autodoc",
renderDocs: function renderDocs() {
var docString = this.props.component.docString;
if (typeof docString === "undefined") {
return null;
}return React.createElement(
"p",
{ className: "Autodoc-description" },
docString
);
},
renderPropType: function renderPropType(propType) {
if (typeof propType === "undefined") {
return;
}
if (Array.isArray(propType)) {
return propType.map(function (p) {
return React.createElement(
"span",
{ className: "Autodoc-type is-enum" },
p
);
});
}
if (typeof propType === "object") {
return React.createElement(
"pre",
{ className: "Autodoc-type is-shape" },
"interface " + String.fromCharCode(123) + "\n",
Object.keys(propType).map(function (k) {
return [React.createElement(
"span",
{ className: "Autodoc-interface-key" },
" ",
k,
": "
), React.createElement(
"span",
{ className: "Autodoc-interface-type Autodoc-type is-" + propType[k] },
propType[k]
), "\n"];
}),
"" + String.fromCharCode(125)
);
}
return React.createElement(
"span",
{ className: "Autodoc-type is-" + propType },
propType
);
},
renderProps: function renderProps() {
var _this = this;
var propTypes = this.props.component.propTypes;
if (typeof propTypes === "undefined") {
return null;
}return React.createElement(
"table",
_extends({ className: "Autodoc-table" }, this.props),
React.createElement(
"thead",
null,
React.createElement(
"tr",
null,
React.createElement(
"td",
null,
"Property"
),
React.createElement(
"td",
null,
"Type"
)
)
),
React.createElement(
"tbody",
null,
Object.keys(propTypes).filter(function (p) {
return propTypes[p].annotation;
}).map(function (p) {
var _propTypes$p$annotation = propTypes[p].annotation;
var propType = _propTypes$p$annotation.propType;
var isRequired = _propTypes$p$annotation.isRequired;
var defaultValue = _propTypes$p$annotation.defaultValue;
isRequired = isRequired ? "Required" : "Optional";
return React.createElement(
"tr",
{ key: p },
React.createElement(
"th",
{ className: "Autodoc-property" },
p,
React.createElement(
"span",
{ className: "Autodoc-required is-" + isRequired },
isRequired
)
),
React.createElement(
"td",
null,
_this.renderPropType(propType)
),
React.createElement(
"td",
{ className: "Autodoc-default" },
defaultValue
)
);
})
)
);
},
render: function render() {
var displayName = this.props.component.displayName;
return React.createElement(
"div",
{ className: "Autodoc" },
React.createElement(
"h2",
{ className: "Autodoc-title" },
"Autodoc for ",
displayName
),
this.renderDocs(),
this.renderProps()
);
}
});
module.exports = Autodoc;