Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Nov 28, 2025

Describe your changes

Adds support for setting delta_color of st.metric to any of the colors from our configurable color palette.

GitHub Issue Link (if applicable)

Testing Plan

  • Added unit & e2e tests.

Contribution License Agreement

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

Copilot AI review requested due to automatic review settings November 28, 2025 11:15
@lukasmasuch lukasmasuch requested a review from a team as a code owner November 28, 2025 11:15
@snyk-io
Copy link
Contributor

snyk-io bot commented Nov 28, 2025

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

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 28, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13153/streamlit-1.51.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13153.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch changed the title Add support for setting delta colors from color palette Add support for setting metric delta colors from color palette Nov 28, 2025
@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR impact:users PR changes affect end users change:feature PR contains new feature or enhancement implementation labels Nov 28, 2025
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 support for setting delta colors from the color palette in st.metric, expanding the delta_color parameter beyond the existing "normal", "inverse", and "off" modes to include eight additional named colors: "red", "orange", "yellow", "green", "blue", "violet", "gray"/"grey", and "primary".

Key Changes

  • Extended the delta_color parameter to accept named color values from the basic color palette
  • Maintains backward compatibility with existing "normal", "inverse", and "off" modes
  • Added comprehensive unit tests and visual E2E tests for the new color options

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
proto/streamlit/proto/Metric.proto Added 5 new enum values (ORANGE, YELLOW, BLUE, VIOLET, PRIMARY) to MetricColor enum for protobuf communication
lib/streamlit/elements/metric.py Extended DeltaColor TypeAlias, added color-to-proto mapping dict, updated validation logic and parameter documentation
lib/tests/streamlit/elements/metric_test.py Added parameterized tests for all 9 named colors, updated invalid color test to use partial string matching
frontend/lib/src/theme/getColors.ts Extended getMetricColor, getMetricBackgroundColor, and getMetricTextColor functions to handle new color values
frontend/lib/src/theme/getColors.test.ts Refactored tests to use it.each parameterization, added coverage for all new color values including special handling for PRIMARY
e2e_playwright/st_metric.py Added two metrics with custom delta colors (yellow and primary) for visual testing
e2e_playwright/st_metric_test.py Added snapshot test for custom delta color rendering in both light and dark themes

delta: Delta,
) -> MetricColorAndDirection:
if delta_color not in {"normal", "inverse", "off"}:
if delta_color not in _VALID_DELTA_COLORS:
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Maybe use:

if delta_color not in _DELTA_COLOR_TO_PROTO and delta_color not in ["normal", "inverse", "off"]:
   ... 

or similar just to avoid having two lists of valid color names that should be in sync.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, updated the set above to use the keys from _DELTA_COLOR_TO_PROTO

@sfc-gh-lwilby
Copy link
Collaborator

LGTM, just one suggestion.

@lukasmasuch lukasmasuch enabled auto-merge (squash) December 3, 2025 14:48
@lukasmasuch lukasmasuch merged commit cdc9848 into develop Dec 3, 2025
43 checks passed
@lukasmasuch lukasmasuch deleted the feature/custom-delta-colors branch December 3, 2025 15:02
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.

Add Yellow color to st.metric

3 participants