Skip to content

Commit

Permalink
fix(react-docs: oneoftype support): (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuler authored and amarie401 committed Oct 9, 2018
1 parent 2abbdb0 commit 91c5f31
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export const PropsTable = ({ name, props, enumValues }) => (
<Row key={propName}>
<TD>{propName}</TD>
<TD>
<div className={css(styles.enumValues)}>
{propDef.type.name}
{getEnumValue(propDef, enumValues)}
</div>
<div className={css(styles.enumValues)}>{getEnumValue(propDef, enumValues)}</div>
</TD>
<TD align="center">{propDef.required && <ExclamationCircleIcon />}</TD>
<TD>{Boolean(propDef.defaultValue) && propDef.defaultValue.value}</TD>
Expand All @@ -59,11 +56,16 @@ export const PropsTable = ({ name, props, enumValues }) => (
);

function getEnumValue(prop, enumValues) {
const values = Array.isArray(prop.type.value) ? prop.type.value.map(v => v.value) : enumValues[prop.type.value];
if (!values) {
return '';
let returnValue = '';
let values;
if (prop.type.name === 'union') {
values = prop.type.value.map(v => v.name);
returnValue = `${values.join(' | ')}`;
} else {
values = Array.isArray(prop.type.value) ? prop.type.value.map(v => v.value) : enumValues[prop.type.value];
returnValue = values ? `${prop.type.name}: ${values.join(', ')}` : prop.type.name;
}
return `: ${values.join(', ')}`;
return returnValue;
}

PropsTable.propTypes = propTypes;
Expand Down

0 comments on commit 91c5f31

Please sign in to comment.