Skip to content

Add styles for inline badges #304

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add styles for inline badges #304

wants to merge 1 commit into from

Conversation

JakeSCahill
Copy link
Contributor

This pull request introduces enhancements to the user interface and tooltip functionality, including new badge styles, improved tooltip initialization, and dynamic beta text for tooltips. The changes are grouped into three themes: badge styles, tooltip improvements, and dynamic beta text.

Badge Styles:

  • Added a new badges.css file with base styles for badges, including variations for large badges and beta badges. These styles improve consistency and usability across the application. (src/css/badges.css, src/css/badges.cssR1-R33)
  • Updated site.css to import the new badges.css file, ensuring the badge styles are applied globally. (src/css/site.css, src/css/site.cssR8)

Tooltip Improvements:

  • Modified tooltips.css to ensure consistent font sizes for tooltips in headers (h1 through h6). (src/css/tooltips.css, src/css/tooltips.cssR11-R19)
  • Enhanced the tooltip initialization logic in 12-activate-tooltips.js to support custom tooltips using data-tooltip attributes, alongside the existing data-tippy-content attributes. (src/js/12-activate-tooltips.js, src/js/12-activate-tooltips.jsL6-R27)

Dynamic Beta Text:

  • Updated article.hbs to use dynamic beta text from page.attributes.beta-text, allowing for customizable beta feature descriptions in tooltips. (src/partials/article.hbs, [1] [2]

Copy link

netlify bot commented Jun 20, 2025

Deploy Preview for docs-ui ready!

Name Link
🔨 Latest commit 7d8e1fa
🔍 Latest deploy log https://app.netlify.com/projects/docs-ui/deploys/68555d3fb429e4000826ba14
😎 Deploy Preview https://deploy-preview-304--docs-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

📝 Walkthrough

Walkthrough

A new CSS file for badge styling has been introduced, providing base and modifier classes for different badge types and sizes. The site-wide CSS imports have been updated to include this new stylesheet. Cursor styles for certain beta label elements have been changed from pointer to help. Tooltip styles have been updated to enforce consistent font size within headings. Tooltip initialization in JavaScript now includes a guard for the tippy function and adds support for tooltips on elements with a data-tooltip attribute. The tooltip content for beta badges in the article template is now dynamically sourced from a page attribute.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Page
    participant BadgeCSS
    participant TooltipJS
    participant TippyLib

    User->>Page: Loads page
    Page->>BadgeCSS: Loads badge styles via site.css
    Page->>TooltipJS: Executes tooltip activation script
    TooltipJS->>TippyLib: Checks if tippy is a function
    alt tippy is a function
        TooltipJS->>TippyLib: Initialize tooltips for [data-tippy-content]
        TooltipJS->>TippyLib: Initialize tooltips for [data-tooltip]
    end
    Page->>User: Renders badges and tooltips with dynamic content
Loading

Assessment against linked issues

Objective Addressed Explanation
Support inline beta badge for sections on a page (DOC-1440) The changes introduce badge styles and tooltip enhancements, but there is no evidence of a macro or mechanism for inserting inline beta badges in page sections.

Suggested reviewers

  • kbatuigas

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn ERESOLVE overriding peer dependency
npm warn While resolving: @typescript-eslint/[email protected]
npm warn Found: [email protected]
npm warn node_modules/eslint
npm warn dev eslint@"~6.8" from the root project
npm warn 8 more (@typescript-eslint/experimental-utils, ...)
npm warn
npm warn Could not resolve dependency:
npm warn peer eslint@"^5.0.0" from @typescript-eslint/[email protected]
npm warn node_modules/@typescript-eslint/parser
npm warn @typescript-eslint/parser@"^1.10.2" from [email protected]
npm warn node_modules/prettier-eslint
npm warn
npm warn Conflicting peer dependency: [email protected]
npm warn node_modules/eslint
npm warn peer eslint@"^5.0.0" from @typescript-eslint/[email protected]
npm warn node_modules/@typescript-eslint/parser
npm warn @typescript-eslint/parser@"^1.10.2" from [email protected]
npm warn node_modules/prettier-eslint
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-20T13_09_05_762Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/css/badges.css (2)

1-7: Consider setting display and alignment on base badge
Currently .badge relies on its host element’s display. For consistent box behavior (vertical centering, padding), you may want to add:

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* existing styles… */
}

17-21: Use CSS variables for fallback badge colors
The hard-coded #e0e0e0 and #1f1f1f reduce theme flexibility. Consider introducing --badge-label-background and --badge-label-color variables so site-wide theming can override these defaults.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3145bc1 and 7d8e1fa.

📒 Files selected for processing (6)
  • src/css/badges.css (1 hunks)
  • src/css/context-switcher.css (2 hunks)
  • src/css/site.css (1 hunks)
  • src/css/tooltips.css (1 hunks)
  • src/js/12-activate-tooltips.js (1 hunks)
  • src/partials/article.hbs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (8)
src/css/tooltips.css (1)

11-19: Enforce consistent tooltip font size in headings
The new rule correctly targets popper roots inside all heading levels and uses !important to override inline styles from Tippy. This ensures tooltips match body copy sizing for readability.

src/css/badges.css (2)

9-15: Large badge variant is well scoped
The .badge--large rules properly ensure minimum size and centering. Using inline-flex here is ideal for icon or text alignment.


30-33: Large beta badge colors are correct
The .badge--large.badge--beta selector properly applies the intended background and text colors via --beta-label-* variables, matching design tokens.

src/css/site.css (1)

8-8: Import badges.css for global badge styling
The import location (after body.css) integrates the badge definitions site-wide. Path and order appear correct.

src/css/context-switcher.css (2)

16-18: Change beta-label hover cursor to help
Switching from pointer to help better communicates informational intent for beta badges.


58-58: Apply help cursor to nav-beta-label
Using cursor: help; on the navigation badge aligns UX consistency with other beta indicators.

src/js/12-activate-tooltips.js (2)

6-6: Excellent defensive programming practice!

The guard clause prevents runtime errors if the tippy library fails to load. This is a good defensive programming approach.


8-15: Good code organization with helpful comments.

The comment clarifies the purpose of this initialization block, making the code more maintainable.

Comment on lines +23 to +28
/* Beta */
.badge--beta {
color: var(--beta-label-background);
font-weight: bold;
background-color: var(--link-highlight-background-color);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent CSS variable usage for small beta badge
The small .badge--beta is using var(--beta-label-background) for text and var(--link-highlight-background-color) for its background, but the large variant flips those. This likely inverts your intended palette.

A fix could be:

 .badge--beta {
-  color: var(--beta-label-background);
-  background-color: var(--link-highlight-background-color);
+  color: var(--beta-label-color);
+  background-color: var(--beta-label-background);
   font-weight: bold;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/* Beta */
.badge--beta {
color: var(--beta-label-background);
font-weight: bold;
background-color: var(--link-highlight-background-color);
}
/* Beta */
.badge--beta {
color: var(--beta-label-color);
background-color: var(--beta-label-background);
font-weight: bold;
}
🤖 Prompt for AI Agents
In src/css/badges.css between lines 23 and 28, the small .badge--beta uses
inconsistent CSS variables for color and background compared to the large
variant, causing a palette inversion. To fix this, swap the CSS variables so
that the text color uses var(--link-highlight-background-color) and the
background uses var(--beta-label-background), aligning the small badge styling
with the large variant.

Comment on lines +33 to 34
"{{page.attributes.beta-text}}",
animation: "scale",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Sanitize dynamic beta-text to prevent XSS
Injecting page.attributes.beta-text into tippy(..., allowHTML: true) without sanitization exposes an XSS vector if that attribute contains malicious HTML. Ensure the source is trusted or run it through a sanitizer. If only plain text is needed, toggle off allowHTML.

Also applies to: 42-43

🤖 Prompt for AI Agents
In src/partials/article.hbs around lines 33-34 and 42-43, the dynamic insertion
of page.attributes.beta-text into tippy with allowHTML: true poses an XSS risk.
To fix this, either sanitize the beta-text content before passing it to tippy or
disable allowHTML if only plain text is required. Ensure that any HTML content
is from a trusted source or properly sanitized to prevent injection attacks.

Comment on lines +17 to +27
// Initialize tippy for custom data-tooltip elements
document.querySelectorAll('[data-tooltip]').forEach((el) => {
tippy(el, {
content: el.getAttribute('data-tooltip'),
animation: 'scale',
theme: 'redpanda-term',
touch: 'hold',
interactive: true,
allowHTML: true,
})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Potential duplicate initialization issue and code duplication.

The new custom tooltip functionality is well-implemented, but there are a couple of concerns:

  1. Duplicate initialization: If an element has both data-tippy-content and data-tooltip attributes, tippy will be initialized twice on the same element, which could cause unexpected behavior.

  2. Configuration duplication: The tooltip configuration is duplicated across both initialization blocks.

Consider this refactor to address both issues:

-    // Initialize tippy for elements with built-in data-tippy-content
-    tippy('[data-tippy-content]', {
-      animation: 'scale',
-      theme: 'redpanda-term',
-      touch: 'hold',
-      interactive: true,
-      allowHTML: true,
-    })
-
-    // Initialize tippy for custom data-tooltip elements
-    document.querySelectorAll('[data-tooltip]').forEach((el) => {
-      tippy(el, {
-        content: el.getAttribute('data-tooltip'),
-        animation: 'scale',
-        theme: 'redpanda-term',
-        touch: 'hold',
-        interactive: true,
-        allowHTML: true,
-      })
-    })
+    // Shared tooltip configuration
+    const tooltipConfig = {
+      animation: 'scale',
+      theme: 'redpanda-term',
+      touch: 'hold',
+      interactive: true,
+      allowHTML: true,
+    }
+
+    // Initialize tippy for elements with built-in data-tippy-content
+    tippy('[data-tippy-content]:not([data-tooltip])', tooltipConfig)
+
+    // Initialize tippy for custom data-tooltip elements
+    document.querySelectorAll('[data-tooltip]').forEach((el) => {
+      tippy(el, {
+        ...tooltipConfig,
+        content: el.getAttribute('data-tooltip'),
+      })
+    })

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/js/12-activate-tooltips.js around lines 17 to 27, there is a risk of
initializing tippy twice on elements that have both data-tippy-content and
data-tooltip attributes, and the tooltip configuration is duplicated in both
initialization blocks. To fix this, consolidate the initialization logic by
merging the selectors and applying a single tippy initialization with a shared
configuration object. Use a conditional to determine the content source
(data-tippy-content or data-tooltip) to avoid duplicate initialization and
remove redundant configuration code.

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.

1 participant