website : Add copy to clipboard and language banner for code snippets#4393
website : Add copy to clipboard and language banner for code snippets#4393HeythisisSud wants to merge 1 commit into
Conversation
Signed-off-by: Sudhanshu <sudhanshumani94@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @HeythisisSud. Thanks for your PR. I'm waiting for a kubeflow member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
🚫 This command cannot be processed. Only organization members or owners can use the commands. |
Description of Changes
What was changed:
assets/js/click-to-copy.js — Rewrote the existing (disabled) copy-to-clipboard script with a new, dependency-free implementation that:
Injects a header bar (.c2c-header) at the top of each .highlight code block containing a language label (e.g. "Terminal", "YAML", "Python") and a copy icon button.
Automatically wraps any bare pre tag elements in a .highlight container so all code blocks render consistently.
Uses the modern navigator.clipboard API with a legacy execCommand fallback for broader browser support.
Switches the button to a checkmark icon with a "Copied!" tooltip on success, reverting after 2 seconds.
assets/scss/_styles_project.scss — Added styles for the copy button feature:
Converts .td-content .highlight to a flex column so the header sits above the pre tag block.
Styles the .c2c-header bar with a language badge on the left and copy button on the right.
Full light and dark theme support using @at-root [data-theme="light/dark"] to correctly target the site's theme attribute.
Resets browser default styles (appearance: none; background: none) to prevent unstyled grey button rendering.
Includes a smooth floating tooltip and keyboard accessibility (focus-visible outline).
layouts/partials/scripts.html — Enabled the click-to-copy script, which was previously gated behind a hardcoded false condition.
Design decisions:
The copy button is placed in a dedicated header bar above the code, so it never overlaps or obscures code text.
Button opacity and hover states follow the existing Kubeflow brand color (#4279f4).
Success state uses green (#10b981 light / #34d399 dark) consistent with standard UX conventions.
No external dependencies added (no Popper.js, no extra libraries).
Related Issues
Closes: #4327 #4328 #4210