-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix regression in visibility of st.code's copy-to-clipboard button
#6498
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
Conversation
|
TODO: write e2e test such that Cypress hovers over the code block (so the copy button is visible) and then takes snapshots. |
|
We have two usages of the streamlit/frontend/src/components/core/Block/ElementNodeRenderer.tsx Lines 640 to 645 in 4289ea8
streamlit/frontend/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx Lines 273 to 275 in 4289ea8
In both cases we need these buttons, so I think we can move this code inside the StreamlitSyntaxHighlighter component to avoid code duplication.
|
…enderer.tsx and StreamlitMarkdown.tsx to StreamlitSyntaxHighlighter.tsx
Thanks for that insight, @sfc-gh-kbregula! Fixed on 42a1a3a. There was also a bug in my initial fix: for
|
|
@snehankekre Do you need help with tests? I'll be happy to deal with it. |
…ed StyledCodeBlock
|
@sfc-gh-kbregula that would be awesome, thank you! 🙏 Reading the Cypress docs on how to hover and then write tests would take me a couple hours.. time I could instead spend on |
st.code copy button and update ElementNodeRendererst.code's copy-to-clipboard button
|
@snehankekre I added E2E tests. |
|
LGTM, thanks Kamil! |
|
@snehankekre Do you need any more help with this PR? Is there anything left to do? |
|
All that's left for this PR is code review. |
frontend/src/components/elements/CodeBlock/styled-components.ts
Outdated
Show resolved
Hide resolved
* develop: Removing viz-1.8.0.min.js (streamlit#6520) st.experimental_connection: The big merge (streamlit#6487) Add additional attributions (streamlit#6536) Fix code block font change (streamlit#6535) Fully remove email from new session message (streamlit#6516) Clarify what telemetry data our backend stores (streamlit#6463) Update emojis to latest state (streamlit#6532) Add support for pandas 2.0 (streamlit#6507) Fix regression in visibility of `st.code`'s copy-to-clipboard button (streamlit#6498) Fix E2E image (streamlit#6524) Add tenacity as dependency (streamlit#6529)
📚 Context
Fixes #6490. PR #6042, while refactoring
st.codeto be markdown independent, likely introduced a regression inst.code, where the copy button does not appear when you hover over code blocks. This issue was caused by missing CSS hover rules and the way the hover effect was implemented. The button is now restored and appears on hover as expected.What kind of change does this PR introduce?
🧠 Description of Changes
Modified
StreamlitSyntaxHighlighter.tsxto include theStyledCopyButtonContainerandStyledCodeBlockcomponents, which were previously missing.Updated the
StyledCopyButtonContainerinstyled-components.tsto set the correct opacity, width, and pointerEvents properties, ensuring that the copy button is correctly rendered forst.code.Added the necessary hover and active states to
StyledCopyButtoninstyled-components.ts.Removed the redundant
StyledCopyButtonContainerimport and usage fromStreamlitMarkdown.tsx, as it's now integrated intoStreamlitSyntaxHighlighter.Revised:
Current:
🧪 Testing Done
🌐 References
Does this depend on other work, documents, or tickets?
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.