Skip to content

[Code] Add highlightLine prop to CodeBlock #48230

Merged
rylnd merged 6 commits intoelastic:masterfrom
rylnd:highlight-code-lines
Oct 15, 2019
Merged

[Code] Add highlightLine prop to CodeBlock #48230
rylnd merged 6 commits intoelastic:masterfrom
rylnd:highlight-code-lines

Conversation

@rylnd
Copy link
Copy Markdown
Contributor

@rylnd rylnd commented Oct 15, 2019

Summary

Addresses elastic/code#1685. Motivated by #47974

  • Adds highlightLine prop to highlight full lines more subtly than individual symbols
  • Refactors CodeBlock to accept an array of strings (lines), rather than a newline-separated string (content)
  • Updates mock data to depend on data from the Typescript-Node-Starter repository, rather than a nonstandard one

Kibana

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

rylnd added 5 commits October 15, 2019 08:35
Rather than do the splitting up of lines (for highlighting, numbering)
internally, it makes a bit more sense to have the consumer provide an
array of strings to be rendered.

The biggest win here is the disambiguation of our upcoming
`highlightLine` prop: were we to accept an array of line indices,
it's unclear whether those should correspond to the monaco index
(1-based), internal index (0-based), or formatted (passed through
`lineNumber)`. Better to standardize on the lineIndex argument parameter
already used for lineNumber, and simply ask the consumer to return a
boolean for any given line.
Allows consumers to declare which lines should be highlighted with the
more subtle, full-width coloring.

* Refactors decoration generation into private methods
* Simplifies both lineNumber and highlightLine to be invoked with _just_
the lineIndex, as consumers will now have the array to index into
themselves, if necessary.
Because of the way we're currently using Monaco, we need to apply all
three of these options to our line decorations. However, all we really
need to do is set the background-color.

As such, we can remove these redundant/unused css classes and reduce the
noise around this functionality. Also, BEM.
This selector is meant to move the folding button over to account for
the extra width taken by the Blame sidebar.

However, `.code-line-decoration` is the only class that is applied to
the blame view, and the selector in question was in fact incorrectly
moving the folding button off the screen on any foldable line that was
also highlighted.

The bug was fixed in the previous commit that removed this class, but
this was the last mention of it.
So that we don't have to import a non-standard repo to view the full
functionality of this page.
@rylnd rylnd added Team:Code release_note:skip Skip the PR/issue when compiling release notes v7.5.0 labels Oct 15, 2019
@rylnd rylnd requested a review from a team as a code owner October 15, 2019 13:46
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/code (Team:Code)

@rylnd rylnd changed the title [Code] Add highlightLines prop to CodeBlock [Code] Add highlightLine prop to CodeBlock Oct 15, 2019
@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

Copy link
Copy Markdown
Contributor

@mw-ding mw-ding left a comment

Choose a reason for hiding this comment

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

LGTM

@rylnd
Copy link
Copy Markdown
Contributor Author

rylnd commented Oct 15, 2019

retest

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@rylnd
Copy link
Copy Markdown
Contributor Author

rylnd commented Oct 15, 2019

@elasticmachine merge upstream

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@rylnd rylnd merged commit 1354369 into elastic:master Oct 15, 2019
rylnd added a commit to rylnd/kibana that referenced this pull request Oct 15, 2019
* CodeBlock accepts an array of strings, rather than a single string

Rather than do the splitting up of lines (for highlighting, numbering)
internally, it makes a bit more sense to have the consumer provide an
array of strings to be rendered.

The biggest win here is the disambiguation of our upcoming
`highlightLine` prop: were we to accept an array of line indices,
it's unclear whether those should correspond to the monaco index
(1-based), internal index (0-based), or formatted (passed through
`lineNumber)`. Better to standardize on the lineIndex argument parameter
already used for lineNumber, and simply ask the consumer to return a
boolean for any given line.

* Add highlightLine prop to CodeBlock

Allows consumers to declare which lines should be highlighted with the
more subtle, full-width coloring.

* Refactors decoration generation into private methods
* Simplifies both lineNumber and highlightLine to be invoked with _just_
the lineIndex, as consumers will now have the array to index into
themselves, if necessary.

* Simplify CSS related to line highlighting

Because of the way we're currently using Monaco, we need to apply all
three of these options to our line decorations. However, all we really
need to do is set the background-color.

As such, we can remove these redundant/unused css classes and reduce the
noise around this functionality. Also, BEM.

* Remove errant CSS rule

This selector is meant to move the folding button over to account for
the extra width taken by the Blame sidebar.

However, `.code-line-decoration` is the only class that is applied to
the blame view, and the selector in question was in fact incorrectly
moving the folding button off the screen on any foldable line that was
also highlighted.

The bug was fixed in the previous commit that removed this class, but
this was the last mention of it.

* Update mock data to depend on Typescript-Node-Starter repo

So that we don't have to import a non-standard repo to view the full
functionality of this page.
@rylnd rylnd deleted the highlight-code-lines branch October 15, 2019 23:28
rylnd added a commit that referenced this pull request Oct 16, 2019
* CodeBlock accepts an array of strings, rather than a single string

Rather than do the splitting up of lines (for highlighting, numbering)
internally, it makes a bit more sense to have the consumer provide an
array of strings to be rendered.

The biggest win here is the disambiguation of our upcoming
`highlightLine` prop: were we to accept an array of line indices,
it's unclear whether those should correspond to the monaco index
(1-based), internal index (0-based), or formatted (passed through
`lineNumber)`. Better to standardize on the lineIndex argument parameter
already used for lineNumber, and simply ask the consumer to return a
boolean for any given line.

* Add highlightLine prop to CodeBlock

Allows consumers to declare which lines should be highlighted with the
more subtle, full-width coloring.

* Refactors decoration generation into private methods
* Simplifies both lineNumber and highlightLine to be invoked with _just_
the lineIndex, as consumers will now have the array to index into
themselves, if necessary.

* Simplify CSS related to line highlighting

Because of the way we're currently using Monaco, we need to apply all
three of these options to our line decorations. However, all we really
need to do is set the background-color.

As such, we can remove these redundant/unused css classes and reduce the
noise around this functionality. Also, BEM.

* Remove errant CSS rule

This selector is meant to move the folding button over to account for
the extra width taken by the Blame sidebar.

However, `.code-line-decoration` is the only class that is applied to
the blame view, and the selector in question was in fact incorrectly
moving the folding button off the screen on any foldable line that was
also highlighted.

The bug was fixed in the previous commit that removed this class, but
this was the last mention of it.

* Update mock data to depend on Typescript-Node-Starter repo

So that we don't have to import a non-standard repo to view the full
functionality of this page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes v7.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants