diff --git a/src/components/MethodReference.js b/src/components/MethodReference.js new file mode 100644 index 000000000..76b3e552f --- /dev/null +++ b/src/components/MethodReference.js @@ -0,0 +1,37 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import ComponentExample from './ComponentExample'; +import FunctionDefinition from './FunctionDefinition'; +import Markdown from 'react-markdown'; +import styles from './MethodReference.module.scss'; + +const MethodReference = ({ className, method }) => ( +
+

{method.name}

+ + + {method.examples.map((example, i) => ( + + ))} +
+); + +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(ComponentExample.propTypes.example), + }), +}; + +export default MethodReference; diff --git a/src/components/MethodReference.module.scss b/src/components/MethodReference.module.scss new file mode 100644 index 000000000..03d8e0ff1 --- /dev/null +++ b/src/components/MethodReference.module.scss @@ -0,0 +1,11 @@ +.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; +} diff --git a/src/templates/ApiDocTemplate.js b/src/templates/ApiDocTemplate.js index 4f5dbd812..7ddbb21af 100644 --- a/src/templates/ApiDocTemplate.js +++ b/src/templates/ApiDocTemplate.js @@ -1,13 +1,12 @@ -import React, { Fragment, useState } from 'react'; +import React, { useState } from 'react'; import cx from 'classnames'; import { graphql } from 'gatsby'; import PropTypes from 'prop-types'; import InlineCodeSnippet from '../components/InlineCodeSnippet'; import ReactMarkdown from 'react-markdown'; import Container from '../components/Container'; -import ComponentExample from '../components/ComponentExample'; -import FunctionDefinition from '../components/FunctionDefinition'; import Layout from '../components/Layout'; +import MethodReference from '../components/MethodReference'; import Sidebar from '../components/Sidebar'; import SEO from '../components/Seo'; import pages from '../data/sidenav.json'; @@ -48,24 +47,7 @@ const ApiDocTemplate = ({ data }) => {

API methods

{methods.map((method, i) => ( - -

{method.name}

- - - {method.examples.map((example, i) => ( - - ))} -
+ ))}
)} diff --git a/src/templates/ComponentDocTemplate.js b/src/templates/ComponentDocTemplate.js index 68390eba4..f591c9172 100644 --- a/src/templates/ComponentDocTemplate.js +++ b/src/templates/ComponentDocTemplate.js @@ -1,4 +1,4 @@ -import React, { Fragment, useState } from 'react'; +import React, { useState } from 'react'; import cx from 'classnames'; import { graphql } from 'gatsby'; import PropTypes from 'prop-types'; @@ -6,8 +6,8 @@ import InlineCodeSnippet from '../components/InlineCodeSnippet'; import ReactMarkdown from 'react-markdown'; import Container from '../components/Container'; import ComponentExample from '../components/ComponentExample'; -import FunctionDefinition from '../components/FunctionDefinition'; import Layout from '../components/Layout'; +import MethodReference from '../components/MethodReference'; import Sidebar from '../components/Sidebar'; import SEO from '../components/Seo'; import PropList from '../components/PropList'; @@ -84,24 +84,7 @@ const ComponentDocTemplate = ({ data }) => {

Methods

{methods.map((method, i) => ( - -

{method.name}

- - - {method.examples.map((example, i) => ( - - ))} -
+ ))}
)}