Skip to content

Commit

Permalink
feat: Render function definition for func prop types
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 7, 2020
1 parent bd79ea7 commit 9dd5137
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
18 changes: 12 additions & 6 deletions src/components/FunctionDefinition.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import React from 'react';
import React, { Children } from 'react';
import PropTypes from 'prop-types';
import Markdown from 'react-markdown';
import styles from './FunctionDefinition.module.scss';

const ParamDescription = ({ children, ...props }) => (
<span {...props} className={styles.paramDescription}>
{'//'} {children}
</span>
);
const ParamDescription = ({ children, ...props }) => {
if (Children.toArray(children).length === 0) {
return null;
}

return (
<span {...props} className={styles.paramDescription}>
{'//'} {children}
</span>
);
};

ParamDescription.propTypes = {
children: PropTypes.node,
Expand Down
15 changes: 11 additions & 4 deletions src/components/PropTypeInfo.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';
import FunctionDefinition from './FunctionDefinition';

const PropTypeInfo = ({ type }) => {
switch (type.name) {
case 'function':
return <div>func</div>;
switch (type.raw) {
case 'func':
return (
<FunctionDefinition
returnValue={type.meta.returnValue}
params={type.meta.params}
/>
);
default:
return null;
}
};

PropTypeInfo.propTypes = {
type: PropTypes.shape({
name: PropTypes.string.isRequired,
raw: PropTypes.string.isRequired,
meta: PropTypes.object,
}),
};

Expand Down

0 comments on commit 9dd5137

Please sign in to comment.