forked from canpolatoral/boa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
props-table.js
67 lines (56 loc) · 2.09 KB
/
props-table.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
/* eslint-disable no-useless-concat */
import React from 'react';
import PropTypes from 'prop-types';
import { DocViewer } from '@kuveytturk/boa-components/DocViewer';
import * as Utils from './utils';
export default class PropsTable extends React.Component {
static propTypes = {
doc: PropTypes.any,
};
prepareData = doc => {
let docString = '## Props';
if (doc.composes && doc.composes.length > 0) {
docString += '\n';
docString = `${docString}The ${doc.displayName} propTypes have spread attribute from: `;
const composes = doc.composes.map(compose => {
return `\`${Utils.parseComponent(compose)}\``;
});
docString = `${docString + composes.join(', ')}\n`;
}
const propTable = propMetaData => {
let docTable = '';
docTable = `${docTable}\n` + '| gray |' + '\n' + '| Name | Type | Default | Description |';
docTable = `${docTable}\n` + '|---|----|----|----:|';
Object.keys(propMetaData)
.sort()
.forEach(key => {
const prop = propMetaData[key];
if (prop.description && prop.description.includes('@ignore')) return;
if (prop.type && prop.type.name === 'func') return;
// eslint-disable-next-line max-len
docTable =
`${docTable}\n` +
`|${Utils.getPropName(prop, key)}|${Utils.getPropType(
prop,
)}|${Utils.getDefaultValueForMarkdown(prop)}|${Utils.getPropDescription(prop)}|`;
});
return docTable;
};
docString += propTable(doc.props);
if (doc.composeProps) {
Object.keys(doc.composeProps).forEach(composeName => {
const composeClassPath = composeName.split('/');
const composeClass = composeClassPath[composeClassPath.length - 2];
docString += '\n';
docString += `## ${composeClass} Props`;
docString += '\n';
docString += propTable(doc.composeProps[composeName]);
});
}
return docString;
};
render() {
const data = this.prepareData(this.props.doc);
return <DocViewer content={data} editorType="github" />;
}
}