Skip to content

Commit

Permalink
feat: Polish styles on method references
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 15, 2020
1 parent 742cce1 commit 52e0c85
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/components/FunctionDefinition.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Children } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import Markdown from 'react-markdown';
import styles from './FunctionDefinition.module.scss';

Expand All @@ -19,9 +20,9 @@ ParamDescription.propTypes = {
children: PropTypes.node,
};

const FunctionDefinition = ({ params, returnValue }) => {
const FunctionDefinition = ({ className, params, returnValue }) => {
return (
<div className={styles.container}>
<div className={cx(styles.container, className)}>
<span className={styles.keyword}>
{params.length > 0 ? 'function (' : 'function ()'}
</span>
Expand All @@ -48,6 +49,7 @@ const FunctionDefinition = ({ params, returnValue }) => {
};

FunctionDefinition.propTypes = {
className: PropTypes.string,
params: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
Expand Down
1 change: 1 addition & 0 deletions src/components/MethodReference.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const MethodReference = ({ className, method }) => (
<h3 className={styles.name}>{method.name}</h3>
<Markdown className={styles.description} source={method.description} />
<FunctionDefinition
className={styles.functionDefinition}
params={method.params}
returnValue={method.returnValue}
/>
Expand Down
9 changes: 7 additions & 2 deletions src/components/MethodReference.module.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
.name {
font-family: var(--code-font);
display: inline-block;
padding: 0.125rem 0.25rem;
display: inline;
color: var(--color-teal-500);
background: var(--color-teal-050);
margin-bottom: 1rem;
}

.description {
margin-top: 1rem;
margin-bottom: 1rem;
}

.example:not(:last-child) {
margin-bottom: 2rem;
}

.functionDefinition {
margin-bottom: 1rem;
}
10 changes: 6 additions & 4 deletions src/components/PropList.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ const PropList = ({ propTypes }) => {
/>
</div>
)}
<Markdown
className={cx(styles.details, styles.markdownContainer)}
source={description}
/>
{description && (
<Markdown
className={cx(styles.details, styles.markdownContainer)}
source={description}
/>
)}
<PropTypeInfo type={type} />
{examples.map((example, idx) => (
<ReferenceExample key={idx} example={example} />
Expand Down
30 changes: 20 additions & 10 deletions src/templates/ApiReferenceTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,39 @@ const ApiReferenceTemplate = ({ data }) => {
<SEO title={title} description={description} />
<PageTitle>{api}</PageTitle>

<section
className={cx(templateStyles.section, templateStyles.description)}
>
<ReactMarkdown source={apiDescription} />
</section>
{apiDescription && (
<section
className={cx(
templateStyles.section,
templateStyles.description,
'intro-text'
)}
>
<ReactMarkdown source={apiDescription} />
</section>
)}

<section className={templateStyles.section}>
<h2>Usage</h2>
<h2 className={templateStyles.sectionTitle}>Usage</h2>
<InlineCodeSnippet language="js">{usage}</InlineCodeSnippet>
</section>

{methods.length > 0 && (
<section className={templateStyles.section}>
<h2>API methods</h2>
<h2 className={templateStyles.sectionTitle}>API methods</h2>
{methods.map((method, i) => (
<MethodReference key={i} method={method} />
<MethodReference
key={i}
method={method}
className={templateStyles.section}
/>
))}
</section>
)}

{typeDefs.length > 0 && (
<section className={templateStyles.section}>
<h2>Type definitions</h2>
<h2 className={templateStyles.sectionTitle}>Type definitions</h2>
{typeDefs.map((typeDef, i) => (
<TypeDefReference key={i} typeDef={typeDef} />
))}
Expand All @@ -62,7 +72,7 @@ const ApiReferenceTemplate = ({ data }) => {

{constants.length > 0 && (
<section className={templateStyles.section}>
<h2>Constants</h2>
<h2 className={templateStyles.sectionTitle}>Constants</h2>
{constants.map((constant, i) => (
<ConstantReference key={i} constant={constant} />
))}
Expand Down
14 changes: 10 additions & 4 deletions src/templates/ComponentReferenceTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ const ComponentReferenceTemplate = ({ data }) => {
<ReactMarkdown source={componentDescription} />
</section>

<section className={templateStyles.section}>
<h2 className={templateStyles.sectionTitle}>Usage</h2>
<InlineCodeSnippet language="js">{usage}</InlineCodeSnippet>
</section>

{examples.length > 0 && (
<section className={templateStyles.section}>
<div>
<h2 className={templateStyles.sectionTitle}>Examples</h2>
<div className={templateStyles.section}>
<InlineCodeSnippet language="js">{usage}</InlineCodeSnippet>
</div>
{examples.map((example, i) => (
<ReferenceExample
key={i}
Expand Down Expand Up @@ -85,7 +87,11 @@ const ComponentReferenceTemplate = ({ data }) => {
<section className={templateStyles.section}>
<h2 className={templateStyles.sectionTitle}>Methods</h2>
{methods.map((method, i) => (
<MethodReference key={i} method={method} />
<MethodReference
key={i}
method={method}
className={styles.section}
/>
))}
</section>
)}
Expand Down

0 comments on commit 52e0c85

Please sign in to comment.