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

[EuiCodeBlock] Highlight line ranges #5207

Merged
merged 11 commits into from
Sep 28, 2021

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Sep 21, 2021

Summary

Adds the ability to visually highlight line ranges within EuiCodeBlock. Extends the lineNumbers prop to accept a comma-separated list of line number(s) or range(s) ({ highlight: '1, 5-10, 20-30, 40' }).

Amsterdam:
image

v7:
image

Also fixes a row height bug for virtualized blocks noticed during this work.

Checklist

  • Check against all themes for compatibility in both light and dark modes

- [ ] Checked in mobile

  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately
  • Revert 2b9eee0

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/

@thompsongl thompsongl marked this pull request as ready for review September 21, 2021 22:37
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/

@miukimiu
Copy link
Contributor

It's looking good @thompsongl,

I just found some small design issues. When the transparentBackground is set to true the numbers still have a background. We missed that on the PR that introduced the line numbers. For this scenario, we should remove the background.

Screenshot 2021-09-22 at 20 02 57

But if we remove this background the line number is highlighted and it doesn't pass the a11y contrast check (4.3). To solve this we can make the number with more contrast (maybe using the Sass function makeHighContrastColor) or we just remove the highlight for line numbers. What do you think?

Screenshot 2021-09-22 at 20 04 32

Then, on the following section we should also explain that we can also highlight the numbers.

Screenshot 2021-09-23 at 11 35 53

@thompsongl
Copy link
Contributor Author

Good catch with transparentBackground; I didn't realize that was a prop that EuiCodeBlock accepted. Checking on options to resolve it.

Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

Logic LGTM! I have some minor comments/suggestions but none of them are blockers. I didn't look too closely at the documentation/examples/design, since Elizabet is on it 🎉

src/components/code/utils.tsx Outdated Show resolved Hide resolved
src/components/code/utils.tsx Outdated Show resolved Hide resolved
src/components/code/utils.tsx Outdated Show resolved Hide resolved
src/components/code/utils.tsx Outdated Show resolved Hide resolved
src/components/code/utils.tsx Outdated Show resolved Hide resolved
src/components/code/utils.tsx Outdated Show resolved Hide resolved
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/

@thompsongl
Copy link
Contributor Author

Resolved all review comments, @miukimiu @constancecchen 🙇

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5207/

Copy link
Member

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

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

Changes for my feedback look great - thanks for the super thorough unit tests!! 🎉

Copy link
Contributor

@miukimiu miukimiu left a comment

Choose a reason for hiding this comment

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

Thanks, @thompsongl for making the changes. LGTM! 🎉

@snide
Copy link
Contributor

snide commented Sep 28, 2021

This PR is great! cc @goodroot as this is useful for document work. We'll probably want to add a more robust wrapper for the docs system at some point.

@thompsongl thompsongl merged commit 702f3c1 into elastic:master Sep 28, 2021
@thompsongl
Copy link
Contributor Author

I forgot to revert 2b9eee0 🤦

@goodroot
Copy link

OOh yeah this is real slick. Thanks for the awareness.

@jackamondo
Copy link

Apologies for the necro on a merged topic, I'm using this component currently and I'm just wondering if anyone knows if it would be possible to dynamically highlight code? I have some json i'm displaying in the code block and ideally I want to highlight sections that match a certain syntax or result (i.e. only highlight objects with type "error"?) or is there any way to expose the API for prism? I'd massively appreciate if anyone could point me in the right direction!

@miukimiu
Copy link
Contributor

miukimiu commented Apr 1, 2022

Hi, @jackamondo I don't think is possible right now to dynamically highlight code that matches a certain syntax. Not sure @thompsongl can point out a workaround.

But there is a discussion with some feature requests for the EuiCodeBlock where you can comment there and propose the enhancements you would like to see: #5609.

@thompsongl
Copy link
Contributor Author

I don't think is possible right now to dynamically highlight code that matches a certain syntax. Not sure @thompsongl can point out a workaround.

No workround at the moment unless you write a script that manipulates the DOM (not actually sure how this would work). I see you've added to the discussion, so that's best course right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants