Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly improve how the props table is generated. #2508

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions docs/src/app/components/PropTypeDescription.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function generatePropType(type) {
return type.raw;

case 'enum':
const values = type.value.map(v => v.value).join(', ');
return `enum[${values}]`;
const values = type.value.map(v => v.value).join('<br>&nbsp;');
return `enum:<br>&nbsp;${values}<br>`;

default:
return type.name;
Expand All @@ -42,7 +42,7 @@ const PropTypeDescription = React.createClass({
} = this.props;

let text = `${header}
| Name | Type | Default | Description|
| Name | Type | Default | Description |
|:-----|:-----|:-----|:-----|\n`;

const componentInfo = parse(code);
Expand All @@ -56,11 +56,15 @@ const PropTypeDescription = React.createClass({
defaultValue = prop.defaultValue.value;
}

const description = (prop.required ? '**required**' : '*optional*') +
'. ' + prop.description.replace(/\n/g, '<br>');
const requirement = `${prop.required ? '**required**' : '*optional*'}.`;

text += `| ${key} | ${generatePropType(prop.type)} |`;
text += `${defaultValue} |${description} |\n`;
// two new lines result in a newline in the table. all other new lines
// must be eliminated to prevent markdown mayhem.
const jsDocText = prop.description.replace(/\n\n/g, '<br>').replace(/\n/g, ' ');

const description = `${requirement} ${jsDocText}`;

text += `| ${key} | ${generatePropType(prop.type)} | ${defaultValue} | ${description} |\n`;
}

return (
Expand Down