From 9dd513752ddb1847a55ef4e2a715511224ff5d95 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Sun, 7 Jun 2020 01:53:47 -0700 Subject: [PATCH] feat: Render function definition for func prop types --- src/components/FunctionDefinition.js | 18 ++++++++++++------ src/components/PropTypeInfo.js | 15 +++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/FunctionDefinition.js b/src/components/FunctionDefinition.js index 70833c266..610cf3b7d 100644 --- a/src/components/FunctionDefinition.js +++ b/src/components/FunctionDefinition.js @@ -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 }) => ( - - {'//'} {children} - -); +const ParamDescription = ({ children, ...props }) => { + if (Children.toArray(children).length === 0) { + return null; + } + + return ( + + {'//'} {children} + + ); +}; ParamDescription.propTypes = { children: PropTypes.node, diff --git a/src/components/PropTypeInfo.js b/src/components/PropTypeInfo.js index c178083db..3a75b64af 100644 --- a/src/components/PropTypeInfo.js +++ b/src/components/PropTypeInfo.js @@ -1,10 +1,16 @@ import React from 'react'; import PropTypes from 'prop-types'; +import FunctionDefinition from './FunctionDefinition'; const PropTypeInfo = ({ type }) => { - switch (type.name) { - case 'function': - return
func
; + switch (type.raw) { + case 'func': + return ( + + ); default: return null; } @@ -12,7 +18,8 @@ const PropTypeInfo = ({ type }) => { PropTypeInfo.propTypes = { type: PropTypes.shape({ - name: PropTypes.string.isRequired, + raw: PropTypes.string.isRequired, + meta: PropTypes.object, }), };