Skip to content

Add default background colors to theme#12341

Merged
mayagbarnes merged 16 commits intodevelopfrom
default-background-colors
Sep 2, 2025
Merged

Add default background colors to theme#12341
mayagbarnes merged 16 commits intodevelopfrom
default-background-colors

Conversation

@mayagbarnes
Copy link
Copy Markdown
Collaborator

Describe your changes

Add the following main color keys, with defaults for streamlit light/dark themes:

  • redBackgroundColor
  • orangeBackgroundColor
  • yellowBackgroundColor
  • blueBackgroundColor
  • greenBackgroundColor
  • violetBackgroundColor
  • grayBackgroundColor

Background colors apply to:

  • Status element (st.warning, st.success, st.info, st.error, st.exception) backgrounds
  • Colored background in Markdown
  • st.badge background
  • st.metric delta background (red/green/gray)
  • st.metric sparkline chart → area in area chart (red/green/gray)

Updated (left) vs. Current (right):
Screenshot 2025-08-27 at 12 23 27 a mScreenshot 2025-08-27 at 12 29 47 a m

Testing Plan

  • JS Unit Tests: ✅
  • E2E Tests: ✅ Snaps updated
  • Manual Testing: ✅

@mayagbarnes mayagbarnes added security-assessment-completed change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users labels Aug 27, 2025
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Aug 27, 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
Copy Markdown
Contributor

github-actions bot commented Aug 27, 2025

✅ PR preview is ready!

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

@bew
Copy link
Copy Markdown

bew commented Aug 27, 2025

Hello, most color changes look good except for yellow where the background is much less visible now 🤔
Is that intentional?

@mayagbarnes
Copy link
Copy Markdown
Collaborator Author

Hi @bew! This was the color chosen by our design team, but this PR is part of a broader color updates project - I'll make note of this concern so we can review it and see if it should be adjusted after text color updates land 👍🏼

@sfc-gh-mbarnes sfc-gh-mbarnes force-pushed the default-background-colors branch from f3a0d57 to ace7833 Compare August 28, 2025 00:06
@sfc-gh-mbarnes sfc-gh-mbarnes force-pushed the default-background-colors branch from ace7833 to a14f6c5 Compare August 29, 2025 19:16
@mayagbarnes mayagbarnes changed the title [WIP] Add default background colors to theme Add default background colors to theme Aug 29, 2025
@mayagbarnes mayagbarnes marked this pull request as ready for review August 29, 2025 22:01
@lukasmasuch lukasmasuch requested a review from Copilot August 29, 2025 23:33
Copy link
Copy Markdown
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 default background colors to Streamlit's theme system by introducing seven new background color keys (red, orange, yellow, blue, green, violet, gray) that are used across various UI elements including status elements, markdown backgrounds, badges, and metric components.

Key changes:

  • Adds new background color properties to theme types and implementations
  • Replaces hardcoded background color calculations with centralized theme-based colors
  • Updates metric delta backgrounds and area chart colors to use the new system

Reviewed Changes

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

Show a summary per file
File Description
frontend/lib/src/theme/types.ts Adds status element background color properties to SpecialEmotionColors type
frontend/lib/src/theme/primitives/colors.ts Adds new color variants yellow65 and blue65 to the color palette
frontend/lib/src/theme/getColors.ts Centralizes background color logic and adds new utility functions
frontend/lib/src/theme/getColors.test.ts Adds comprehensive tests for new background color functions
frontend/lib/src/theme/emotionLightTheme/themeColors.ts Removes legacy background color definitions
frontend/lib/src/theme/emotionDarkTheme/themeColors.ts Implements dark theme background colors with transparency
frontend/lib/src/theme/emotionBaseTheme/themeColors.ts Implements light theme background colors with transparency
frontend/lib/src/mocks/mockTheme.ts Updates mock theme to include new background colors
frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.test.tsx Updates tests to use centralized background color functions
frontend/lib/src/components/elements/Metric/styled-components.ts Removes duplicate background color logic in favor of centralized function
frontend/lib/src/components/elements/Metric/Metric.tsx Updates metric area charts to use new background colors
frontend/lib/src/components/elements/Metric/Metric.test.tsx Updates test expectations for new background colors
e2e_playwright/st_markdown_test.py Updates E2E test expectations for new background colors

Copy link
Copy Markdown
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 👍 A couple of comments, but nothing blocking the merge.

Comment on lines +82 to +86
// Status element colors
infoBg: string
dangerBg: string
successBg: string
warningBg: string
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we even need these in our theme? I think it could simplify our theming if it only contains user-configurable colors + commonly used derived colors (borderColorLight, fadedTextXX). With the change in this PR, there isn't any difference anymore between infoBg and blueBackgroundColor. Same also applies to metricPositiveDeltaColor, metricPositiveDeltaColor and metricNeutralDeltaColor above. If we keep these colors in here it might make it a bit complicated to draw a line, e.g. when do we add a theme color vs just reuse an existing one? Why not add audioInputRecordColor? I think we might also want to enforce at some point that new configurable colors are the only allowed colors to be used within components.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Funny you mention this - already working on a follow up PR that among other things, removes these intermediate color names - they are now just duplicates and the simplification will help for custom components v2.
Will keep this in mind as I continue 👍🏼

Comment on lines 200 to 202
purplebg: transparentize(
theme.colors[lightTheme ? "purple90" : "purple80"],
colors[lightTheme ? "purple90" : "purple80"],
lightTheme ? 0.9 : 0.7
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How does the rainbow look without the purple? Maybe we can just leave out this color to simplify (since it is only used by the rainbow, right?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't make a huge difference, but personally think it looks better including the purple

With Purple:
Light - with purple
Dark - with purple

Without Purple:
Light - without
Dark - without

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Something to consider as a follow-up: Related to the comment in https://github.com/streamlit/streamlit/pull/12341/files#r2311889546, it might make sense to only keep helper methods here that are actually needed to be shared across components. With the introduction of the new configurable colors, there might not be many benefits for keeping methods like getMarkdownBgColors within the theme module.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

personal taste: as a side-by-side comparison, the background colors in dark mode seems to be a bit less "colorful" / dull / less distinguishable (also see the MultiselectColumn tags above). 20% transparency might be a bit too much, and something between 10-20% would be a bit better. cc @jrieke

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thats fair, will make a note to revisit (in any way, yellow bg was noted above as a concern)

@mayagbarnes mayagbarnes merged commit e93327e into develop Sep 2, 2025
37 checks passed
@mayagbarnes mayagbarnes deleted the default-background-colors branch September 2, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:refactor PR contains code refactoring without behavior change impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants