-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a FunctionDefinition component and render the function def …
…for a method
- Loading branch information
1 parent
d4d0180
commit 9c7674d
Showing
5 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React 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> | ||
); | ||
|
||
ParamDescription.propTypes = { | ||
children: PropTypes.node, | ||
}; | ||
|
||
const FunctionDefinition = ({ params, returnValue }) => { | ||
return ( | ||
<div className={styles.container}> | ||
<span className={styles.keyword}> | ||
{params.length > 0 ? 'function (' : 'function ()'} | ||
</span> | ||
{params.map((param, i) => ( | ||
<div key={i} className={styles.param}> | ||
<span className={styles.paramName}>{param.name}: </span> | ||
<span className={styles.type}>{param.type} </span> | ||
<Markdown | ||
source={param.description} | ||
renderers={{ | ||
root: ParamDescription, | ||
}} | ||
/> | ||
</div> | ||
))} | ||
{params.length > 0 && <span className={styles.keyword}>) </span>} | ||
<span className={styles.keyword}>=> </span> | ||
<span className={styles.type}>{returnValue.type}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
FunctionDefinition.propTypes = { | ||
params: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
name: PropTypes.string, | ||
type: PropTypes.string, | ||
description: PropTypes.string, | ||
}) | ||
), | ||
returnValue: PropTypes.shape({ | ||
type: PropTypes.string.isRequired, | ||
}), | ||
}; | ||
|
||
export default FunctionDefinition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.container { | ||
font-family: 'Menlo', 'Consolas', monospace; | ||
font-size: 0.875rem; | ||
line-height: 1.5; | ||
} | ||
|
||
.line:not(:last-child) { | ||
margin-bottom: 0.5rem; | ||
} | ||
|
||
.param { | ||
margin-left: 1rem; | ||
} | ||
|
||
.paramName { | ||
color: var(--color-neutrals-700); | ||
} | ||
|
||
.paramDescription { | ||
color: var(--color-neutrals-500); | ||
|
||
> p { | ||
color: inherit; | ||
display: inline; | ||
} | ||
} | ||
|
||
.keyword { | ||
color: var(--color-neutrals-600); | ||
} | ||
|
||
.type { | ||
color: var(--color-green-6); | ||
background: var(--color-green-1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters