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] Add line numbers #4993

Merged
merged 22 commits into from
Sep 13, 2021
Merged

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Jul 29, 2021

Summary

Closes #3140 by adding an option to render line numbers in EuiCodeBlock. Works with virtualization and fullscreen, and does not impact copy functionality.

image

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 the 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 fec4925

@thompsongl
Copy link
Contributor Author

@miukimiu Would you please take a look at this from a design perspective before I open for full review?

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

Weird thing in Safari. Copying the selection as shown in the image does not actually copy the line numbers; it just appears as though they are selected. Have not been able to prevent apparent selection.

Screen Shot 2021-07-29 at 12 57 31 PM

@kibanamachine
Copy link

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

@cchaos
Copy link
Contributor

cchaos commented Jul 29, 2021

I'm pretty sure that would be the behavior that we want (not copying the line-numbers). So perhaps there's a setting that is actually only working in Safari? You can also pass user-select: none to the line-numbers to ensure they're not highlighted.

@thompsongl
Copy link
Contributor Author

thompsongl commented Jul 29, 2021

I'm pretty sure that would be the behavior that we want (not copying the line-numbers)

Yes, I think I worded that poorly. All browsers do not copy the line numbers, which is good. Safari is the only browser that makes it appear as though the line numbers are selected.

Other browsers:

image

user-select: none

This is there already but has no effect on what Safari does.

@cchaos
Copy link
Contributor

cchaos commented Jul 29, 2021

Looks like it's because it's technically still highlighting the generic row. What you'll need to do is apply the setting the whole wrapper, then add it back on with auto on .euiCodeBlock__line__text.

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

Opening this up for review, but very much open to design changes 🙇‍♂️

@thompsongl thompsongl marked this pull request as ready for review August 10, 2021 15:07
@cchaos cchaos requested a review from elizabetdev August 17, 2021 19:42
@kibanamachine
Copy link

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

Copy link
Contributor

@elizabetdev elizabetdev left a comment

Choose a reason for hiding this comment

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

This is a great feature, and it's looking good! 😍

I found a few issues.

When we have a non-virtualized code block and a vertical scrollbar appears the line numbers get out of the container:

Screenshot 2021-09-09 at 15 05 18

I used the following example in eui/src-docs/src/views/code/code_block.js: https://gist.github.com/miukimiu/4c01830ecaa0dd2e442780ba16c98a5b.

Screen size 1440 x 1024.

Another issue is when we have a whiteSpace="pre". All the content scrolls and the numbers overlap the text.

Screenshot 2021-09-09 at 14 51 37

Ideally, the horizontal scrollbar should start after the line numbers:

Screen.Recording.2021-09-09.at.03.18.PM.mov

src/components/code/_code_block.scss Outdated Show resolved Hide resolved
@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

Copy link
Contributor

@elizabetdev elizabetdev left a comment

Choose a reason for hiding this comment

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

Looks good @thompsongl! 🎉

Tested again in Chrome, Safari, Edge, and Firefox.

@thompsongl thompsongl requested a review from cee-chen September 10, 2021 14:40
Copy link
Contributor

@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.

Sorry for the millions of questions, it's my first time looking at this component so I have a lot of really annoying q's/comments 😅 QA itself looks great and amazing, so mostly just very nitty stuff from me

src-docs/src/views/code/line_numbers.js Outdated Show resolved Hide resolved
src-docs/src/views/code/line_numbers.js Outdated Show resolved Hide resolved
src-docs/src/views/code/code_block_pre.js Outdated Show resolved Hide resolved
src-docs/src/views/code/code_example.js Outdated Show resolved Hide resolved
src-docs/src/views/code/line_numbers.js Outdated Show resolved Hide resolved
src/components/code/_code_block.tsx 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 Show resolved Hide resolved
src/components/code/_code_block.tsx Show resolved Hide resolved
@kibanamachine
Copy link

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

},
children: [],
},
{
type: 'element',
tagName: 'span',
properties: {
style: { marginLeft: width + 8 }, // 8px is $euiSizeS
className: ['euiCodeBlock__line__text'],
style: { marginLeft: width + $euiSizeS },
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL variables can start with a special character! Awesome 🤯

Copy link
Contributor

@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 and a quick QA of the docs look great! 🎉 My above unit testing comment is 100% optional

@thompsongl thompsongl enabled auto-merge (squash) September 13, 2021 18:14
@kibanamachine
Copy link

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

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.

[EuiCodeBlock] Possibility to show line numbers
5 participants