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

Add vertical scroll and text highlighting for functions #3918

Merged
merged 6 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions src-docs/src/components/guide_section/_guide_section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
.guideSection__space {
height: $euiSizeL;
}

.guideSection__table-row {
overflow: auto;
}
50 changes: 47 additions & 3 deletions src-docs/src/components/guide_section/guide_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ export class GuideSection extends Component {

const humanizedType = humanizeType(type);

const functionMatches = [
...humanizedType.matchAll(/\([^=]*\) =>\s\w*\)*/g),
];
const types = humanizedType.split(/\([^=]*\) =>\s\w*\)*/);

const typeMarkup = (
<span className="eui-textBreakNormal">{markup(humanizedType)}</span>
);
Expand All @@ -335,13 +340,52 @@ export class GuideSection extends Component {
defaultValueMarkup.push(`(${defaultValue.comment})`);
}
}

let defaultTypeCell = (
<EuiTableRowCell
className="guideSection__table-row"
key="type"
header="Type">
<EuiCode>{typeMarkup}</EuiCode>
</EuiTableRowCell>
);
if (functionMatches.length > 0) {
const elements = [];
let j = 0;
for (let i = 0; i < types.length; i++) {
if (functionMatches[j]) {
elements.push(
<EuiCode>
<span className="eui-textBreakNormal">{types[i]}</span>
</EuiCode>
);
elements.push(
<EuiCode language="ts">{functionMatches[j][0]}</EuiCode>
);
j++;
} else {
elements.push(
<EuiCode>
<span className="eui-textBreakNormal">{types[i]}</span>
</EuiCode>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on a direct fix for the overflow stuff, but can you help me better understand when each of these get displayed? Like what does functionMatches do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my idea actually here is to find all functions and display them inline using horizontal scroll as suggested here #3554 (review) under long type rendering. I wasn't able to achieve that due to word-wraps. so that I commented it here but unfortunately. I used vertical instead of horizontal and messed things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attached screenshot as comment link seems not working as it was a review

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on a direct fix for the overflow stuff, but can you help me better understand when each of these get displayed? Like what does functionMatches do?

Also functions may appear sometimes in enums also so in that case i tried to extract functions from those enums using regex also

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, so we want the multiple version to horizontally scroll. Ok, let me actually keep playing with my branch off of yours.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, that was the idea.

}
defaultTypeCell = (
<EuiTableRowCell
className="guideSection__table-row"
key="type"
header="Type">
{elements}
</EuiTableRowCell>
);
}

const cells = [
<EuiTableRowCell key="name" header="Prop">
{humanizedName}
</EuiTableRowCell>,
<EuiTableRowCell key="type" header="Type">
<EuiCode>{typeMarkup}</EuiCode>
</EuiTableRowCell>,
defaultTypeCell,
<EuiTableRowCell
key="defaultValue"
header="Default"
Expand Down