Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jrieke
Copy link
Collaborator

@jrieke jrieke commented Jun 18, 2025

Describe your changes

Slightly changes the design of st.metric to add a background color behind the delta. Colors are the same as for background colored Markdown text.

Before:
Screenshot 2025-06-18 at 02 38 37

After:
Screenshot 2025-06-20 at 01 28 12

GitHub Issue Link (if applicable)

Testing Plan

  • Updated existing JS unit tests that check for colors to also check for background colors.
  • Updated snapshots. Note that a lot of unrelated snapshots for st_columns.py were updated because st.metric is used in the st.columns tests, so the change here pushed the rest of the page down a bit.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Jun 18, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Contributor

github-actions bot commented Jun 18, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11678/streamlit-1.45.1-py3-none-any.whl
🕹️ Preview app pr-11678.streamlit.app (☁️ Deploy here if not accessible)

@jrieke jrieke added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Jun 18, 2025
@jrieke jrieke requested a review from Copilot June 18, 2025 02:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a semi-transparent background behind the delta value in st.metric, matching the existing Markdown background colors.

  • Introduces getMetricBackgroundColor to compute delta backgrounds based on theme and delta color.
  • Updates the styled delta component to include background color, padding, and rounded corners.
  • Adjusts the metric arrow icon size and updates unit tests to assert the new background styles.

Reviewed Changes

Copilot reviewed 110 out of 110 changed files in this pull request and generated 2 comments.

File Description
frontend/lib/src/components/elements/Metric/styled-components.ts Added getMetricBackgroundColor and applied background styling to StyledMetricDeltaText
frontend/lib/src/components/elements/Metric/Metric.tsx Changed delta icon size from "lg" to "md"
frontend/lib/src/components/elements/Metric/Metric.test.tsx Updated tests to verify the new background-color style for deltas
Comments suppressed due to low confidence (1)

frontend/lib/src/components/elements/Metric/Metric.test.tsx:118

  • [nitpick] Current tests only cover the light theme background color. Consider adding a test using the dark-mode fixture (e.g., themed_app) to verify that the delta background renders correctly in dark mode.
    )

case MetricProto.MetricColor.RED:
return transparentize(
theme.colors[lightTheme ? "red80" : "red60"],
lightTheme ? 0.9 : 0.7
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

[nitpick] The opacity values 0.9 and 0.7 are magic numbers. Consider defining named constants or theme variables for these alpha values to improve readability and maintainability.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should do this as part of refactoring when we tackle these color values in advanced theming.

@jrieke jrieke marked this pull request as ready for review June 18, 2025 13:45
Copy link
Collaborator

@lukasmasuch lukasmasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@jrieke jrieke enabled auto-merge (squash) June 20, 2025 01:27
@jrieke jrieke merged commit 08a3f03 into develop Jun 20, 2025
37 checks passed
@jrieke jrieke deleted the feature/metric-delta-background branch June 20, 2025 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants