Skip to content

Commit

Permalink
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/FunctionDefinition.js
Original file line number Diff line number Diff line change
@@ -4,10 +4,14 @@ import CodeDef from './CodeDef';
import { graphql } from 'gatsby';

const FunctionDefinition = ({ className, arguments: params, returnValue }) => {
if (!params.length && !returnValue.length) {
if (!params.length && !returnValue && !returnValue.length) {
return null;
}

if (!Array.isArray(returnValue)) {
returnValue = [returnValue];
}

return (
<CodeDef className={className}>
<CodeDef.Keyword>function</CodeDef.Keyword>{' '}
@@ -30,14 +34,19 @@ const FunctionDefinition = ({ className, arguments: params, returnValue }) => {
{params.length > 0 && <CodeDef.Bracket>)</CodeDef.Bracket>}
{returnValue.length > 0 && (
<>
<CodeDef.Operator> => </CodeDef.Operator>
<CodeDef.Operator> =&gt; </CodeDef.Operator>
<CodeDef.Type>{returnValue[0].type}</CodeDef.Type>
</>
)}
</CodeDef>
);
};

const ReturnValueType = PropTypes.shape({
type: PropTypes.string,
description: PropTypes.string,
});

FunctionDefinition.propTypes = {
className: PropTypes.string,
arguments: PropTypes.arrayOf(
@@ -47,12 +56,10 @@ FunctionDefinition.propTypes = {
description: PropTypes.string,
})
).isRequired,
returnValue: PropTypes.arrayOf(
PropTypes.shape({
type: PropTypes.string,
description: PropTypes.string,
})
).isRequired,
returnValue: PropTypes.oneOfType([
ReturnValueType,
PropTypes.arrayOf(ReturnValueType),
]).isRequired,
};

export const query = graphql`

0 comments on commit 55af575

Please sign in to comment.