-
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.
Merge pull request #99 from newrelic/jerel/all-api-docs
Add all API docs
- Loading branch information
Showing
88 changed files
with
327 additions
and
147 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
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,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ReferenceExample from './ReferenceExample'; | ||
import FunctionDefinition from './FunctionDefinition'; | ||
import Markdown from 'react-markdown'; | ||
import styles from './MethodReference.module.scss'; | ||
|
||
const MethodReference = ({ className, method }) => ( | ||
<div className={className}> | ||
<h3 className={styles.name}>{method.name}</h3> | ||
<Markdown className={styles.description} source={method.description} /> | ||
<FunctionDefinition | ||
params={method.params} | ||
returnValue={method.returnValue} | ||
/> | ||
{method.examples.map((example, i) => ( | ||
<ReferenceExample key={i} className={styles.example} example={example} /> | ||
))} | ||
</div> | ||
); | ||
|
||
MethodReference.propTypes = { | ||
className: PropTypes.string, | ||
method: PropTypes.shape({ | ||
name: PropTypes.string.isRequired, | ||
description: PropTypes.string, | ||
params: FunctionDefinition.propTypes.params, | ||
returnValue: FunctionDefinition.propTypes.returnValue, | ||
examples: PropTypes.arrayOf(ReferenceExample.propTypes.example), | ||
}), | ||
}; | ||
|
||
export default MethodReference; |
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,15 @@ | ||
.name { | ||
padding: 0.125rem 0.25rem; | ||
display: inline; | ||
color: var(--color-teal-500); | ||
background: var(--color-teal-050); | ||
} | ||
|
||
.description { | ||
margin-top: 1rem; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
.example:not(:last-child) { | ||
margin-bottom: 2rem; | ||
} |
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useMemo } from 'react'; | ||
|
||
const IGNORED_METHODS = [ | ||
'prototype', | ||
'length', | ||
'name', | ||
'propTypes', | ||
'getDerivedStateFromProps', | ||
'defaultProps', | ||
]; | ||
|
||
const useApiDoc = (name) => { | ||
if (typeof window === 'undefined') global.window = {}; | ||
|
||
return useMemo(() => { | ||
const sdk = window.__NR1_SDK__?.default ?? {}; | ||
const api = sdk[name]; | ||
|
||
if (!api) { | ||
return null; | ||
} | ||
|
||
const apiDocs = api?.__docs__; | ||
|
||
return { | ||
description: apiDocs?.text, | ||
usage: `import { ${name} } from 'nr1'`, | ||
methods: Object.getOwnPropertyNames(api) | ||
.filter( | ||
(member) => | ||
!IGNORED_METHODS.includes(member) && | ||
typeof api[member] === 'function' | ||
) | ||
.map((member) => { | ||
const methodDocs = api[member].__docs__; | ||
|
||
return { | ||
name: `${name}.${member}`, | ||
description: methodDocs?.text, | ||
returnValue: methodDocs?.tags.return?.[0] ?? { type: 'undefined' }, | ||
params: methodDocs?.tags.param ?? [], | ||
examples: methodDocs?.tags.examples ?? [], | ||
}; | ||
}), | ||
}; | ||
}, [name, window?.__NR1_SDK__]); | ||
}; | ||
|
||
export default useApiDoc; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
path: '/apis/logger' | ||
title: 'PlatformStateContext' | ||
description: 'A logger component!' | ||
api: 'logger' | ||
template: 'ApiReferenceTemplate' | ||
--- |
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,7 @@ | ||
--- | ||
path: '/apis/nerdlet' | ||
title: 'Nerdlet' | ||
description: 'The nerdlet API' | ||
api: 'nerdlet' | ||
template: 'ApiReferenceTemplate' | ||
--- |
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
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
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
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
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
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
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
Oops, something went wrong.