Skip to content

Commit

Permalink
feat: Add required label to required prop types
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 4, 2020
1 parent 307d0cb commit 87126a9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/components/PropList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@ const PropList = ({ propTypes }) => {

return (
<div>
{propTypes.map(({ name, description, type, defaultValue }) => {
return (
<div key={name} className={styles.container}>
<div className={styles.info}>
<h3>{name}</h3>
<div className={styles.type}>{type}</div>
{defaultValue !== undefined && (
<div className={styles.default}>
<p>DEFAULT</p>
<p>{String(defaultValue)}</p>
</div>
)}
{propTypes.map(
({ name, description, isRequired, type, defaultValue }) => {
return (
<div key={name} className={styles.container}>
<div className={styles.info}>
<h3>
{name}{' '}
{isRequired && (
<span className={styles.required}>required</span>
)}
</h3>
<div className={styles.type}>{type}</div>
{defaultValue !== undefined && (
<div className={styles.default}>
<p>DEFAULT</p>
<p>{String(defaultValue)}</p>
</div>
)}
</div>
<div className={styles.details}>
<ReactMarkdown source={description} />
</div>
</div>
<div className={styles.details}>
<ReactMarkdown source={description} />
</div>
</div>
);
})}
);
}
)}
</div>
);
};
Expand All @@ -38,6 +45,7 @@ PropList.propTypes = {
PropTypes.shape({
name: PropTypes.string.isRequired,
description: PropTypes.string,
isRequired: PropTypes.bool,
type: PropTypes.string,
defaultValue: PropTypes.string,
})
Expand Down
7 changes: 7 additions & 0 deletions src/components/PropList.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@
font-size: 1.25rem;
width: 70%;
}

.required {
font-size: 0.75rem;
color: var(--color-red-400);
text-transform: uppercase;
margin-left: 0.5rem;
}
1 change: 1 addition & 0 deletions src/hooks/useComponentDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const extractPropTypes = (component) => {
return {
name,
description: propDocs.text,
isRequired: propMeta.some((item) => item.name === 'isRequired'),
type: type.displayType,
defaultValue,
};
Expand Down

0 comments on commit 87126a9

Please sign in to comment.