Skip to content

Commit

Permalink
Added props-doc to the TableOfRecords example (#2)
Browse files Browse the repository at this point in the history
- since the default props docs don't support rich props hierarchy, we construct the docgen info ourselves.
- changes the styling of the props docs
- introduced a special `_euiObjectType` field in docgenInfo "mark" the documented component as a "type" rather than a react component
- added internal links between the different types
  • Loading branch information
uboness committed Jan 26, 2018
1 parent 0d40058 commit 4da4fdf
Show file tree
Hide file tree
Showing 4 changed files with 450 additions and 4 deletions.
27 changes: 24 additions & 3 deletions src-docs/src/components/guide_section/guide_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
EuiText,
EuiTextColor,
EuiTitle,
EuiLink
} from '../../../../src/components';


Expand Down Expand Up @@ -139,7 +140,7 @@ export class GuideSection extends Component {
}

const docgenInfo = Array.isArray(component.__docgenInfo) ? component.__docgenInfo[0] : component.__docgenInfo;
const { description, props } = docgenInfo;
const { _euiObjectType, description, props } = docgenInfo;

if (!props && !description) {
return;
Expand Down Expand Up @@ -169,14 +170,30 @@ export class GuideSection extends Component {

const humanizedType = humanizeType(type);

function markup(text) {
const regex = /(#[a-zA-Z]+)/;
return text.split(regex).map(token => {
if (!token.startsWith('#')) {
return token;
}
const id = token.substring(1);
const onClick = () => {
document.getElementById(id).scrollIntoView();
};
return <EuiLink onClick={onClick}>{id}</EuiLink>;
});
}

const typeMarkup = markup(humanizedType);

const cells = [
(
<EuiTableRowCell key="name">
{humanizedName}
</EuiTableRowCell>
), (
<EuiTableRowCell key="type">
<EuiCode>{humanizedType}</EuiCode>
<EuiCode>{typeMarkup}</EuiCode>
</EuiTableRowCell>
), (
<EuiTableRowCell key="defaultValue">
Expand All @@ -196,6 +213,10 @@ export class GuideSection extends Component {
);
});

const title = _euiObjectType === 'type' ?
<EuiCode id={componentName}>{componentName}</EuiCode> :
<EuiText color="accent">{componentName}</EuiText>;

let descriptionElement;

if (description) {
Expand Down Expand Up @@ -241,7 +262,7 @@ export class GuideSection extends Component {

return [
<EuiSpacer size="m" key={`propsSpacer-${componentName}-1`} />,
<EuiTitle size="s" key={`propsName-${componentName}`}><h3>Props for {componentName}</h3></EuiTitle>,
<EuiTitle size="s" key={`propsName-${componentName}`}><h3>{title}</h3></EuiTitle>,
<EuiSpacer size="s" key={`propsSpacer-${componentName}-2`} />,
descriptionElement,
table,
Expand Down
Loading

0 comments on commit 4da4fdf

Please sign in to comment.