Skip to content

Commit

Permalink
refactor: Move PropTypeInfo into PropList because of recursiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 8, 2020
1 parent bc5e17a commit 44b55ce
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 53 deletions.
41 changes: 40 additions & 1 deletion src/components/PropList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import React from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import PropTypeInfo from './PropTypeInfo';
import FunctionDefinition from './FunctionDefinition';
import Markdown from 'react-markdown';
import styles from './PropList.module.scss';
import { format } from 'date-fns';

const PropTypeInfo = ({ type }) => {
switch (type.raw) {
case 'func':
return (
<FunctionDefinition
returnValue={type.meta.returnValue}
params={type.meta.params}
/>
);
case 'oneOf':
return (
<div className={styles.listLike}>
<div>{'<One of'}</div>
<div className={styles.arg}>
{type.meta.constants.map((constant) => (
<div key={constant}>{constant},</div>
))}
</div>
<div>{'>'}</div>
</div>
);
case 'oneOfType':
return type.meta.types.map((type, idx) => (
<PropTypeInfo key={idx} type={type} />
));
case 'shape':
return <div>Shape</div>;
default:
return null;
}
};

PropTypeInfo.propTypes = {
type: PropTypes.shape({
raw: PropTypes.string.isRequired,
meta: PropTypes.object,
}),
};

const PropList = ({ propTypes }) => {
if (propTypes.length === 0) {
return <p>There are no props for this component.</p>;
Expand Down
10 changes: 10 additions & 0 deletions src/components/PropList.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@
text-transform: uppercase;
margin-left: 0.5rem;
}

.arg {
padding-left: 1rem;
}

.listLike {
font-family: var(--code-font);
font-size: 0.875rem;
color: var(--color-neutrals-600);
}
43 changes: 0 additions & 43 deletions src/components/PropTypeInfo.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/PropTypeInfo.module.scss

This file was deleted.

0 comments on commit 44b55ce

Please sign in to comment.