Skip to content

Add support for source directly in theming font configs#12239

Merged
mayagbarnes merged 10 commits intodevelopfrom
google-fonts
Aug 25, 2025
Merged

Add support for source directly in theming font configs#12239
mayagbarnes merged 10 commits intodevelopfrom
google-fonts

Conversation

@mayagbarnes
Copy link
Copy Markdown
Collaborator

@mayagbarnes mayagbarnes commented Aug 15, 2025

Describe your changes

Allow theming font configs: font, codeFont & headingFont to accept both a font family name and an optional source url to support sourcing from Google Fonts, Adobe Fonts, etc.

Note the format is <font_family_name_here>:<font_source_url_here>

[theme]
# Adobe Font example
font="playwrite-cc-za:https://use.typekit.net/eor5wum.css"
# Google Font Examples
codeFont="Tagesschrift:https://fonts.googleapis.com/css2?family=Tagesschrift&display=swap"
headingFont="Mozilla Headline:https://fonts.googleapis.com/css2?family=Mozilla+Headline&display=swap"

Testing Plan

  • Unit Tests (JS and/or Python): ✅ Added/Updated
  • E2E Tests: ✅ Added
  • Manual Testing: ✅

@mayagbarnes mayagbarnes added security-assessment-completed change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Aug 15, 2025
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Aug 15, 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 15, 2025

✅ PR preview is ready!

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

@mayagbarnes mayagbarnes changed the title [WIP] Add support for source directly in theming font configs Add support for source directly in theming font configs Aug 22, 2025
@streamlit streamlit locked and limited conversation to collaborators Aug 22, 2025
@streamlit streamlit unlocked this conversation Aug 22, 2025
@sfc-gh-bnisco sfc-gh-bnisco requested a review from Copilot August 25, 2025 16:42
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 support for specifying font sources directly in Streamlit's theming configuration, allowing users to load fonts from external sources like Google Fonts and Adobe Fonts. The implementation uses a new format <font_family_name>:<source_url> for font configuration options.

Key changes:

  • Adds a new FontSource protobuf message to store font source URLs alongside configuration names
  • Implements parsing logic to extract font names and source URLs from theme configuration
  • Integrates react-helmet-async to dynamically inject font source <link> tags into the document head

Reviewed Changes

Copilot reviewed 17 out of 21 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
proto/streamlit/proto/NewSession.proto Adds FontSource message and font_sources field to CustomThemeConfig
lib/streamlit/runtime/theme_util.py New utility module for parsing font configurations with source URLs
lib/streamlit/runtime/app_session.py Updates theme population to use the new font parsing utility
frontend/app/src/util/useThemeManager.ts Extends theme manager to handle font sources and returns them as state
frontend/app/src/components/FontSources/ New component to render font source link tags using react-helmet-async
frontend/app/src/ThemedApp.tsx Integrates FontSources component into the app structure
frontend/app/package.json Adds react-helmet-async dependencies
Various test files Comprehensive test coverage for the new functionality

@mayagbarnes mayagbarnes marked this pull request as ready for review August 25, 2025 16:48
@mayagbarnes mayagbarnes requested a review from a team as a code owner August 25, 2025 16:48
@mayagbarnes mayagbarnes merged commit 439c1c1 into develop Aug 25, 2025
37 checks passed
@mayagbarnes mayagbarnes deleted the google-fonts branch August 25, 2025 23:35
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants