MCPcopy
hub / github.com/streamlit/streamlit / processThemeInput

Method processThemeInput

frontend/app/src/App.tsx:1522–1587  ·  view source on GitHub ↗
(themeInput: CustomThemeConfig)

Source from the content-addressed store, hash-verified

1520 }
1521
1522 processThemeInput(themeInput: CustomThemeConfig): void {
1523 const themeHash = this.createThemeHash(themeInput)
1524 if (themeHash === this.state.themeHash) {
1525 return
1526 }
1527 this.setState({ themeHash })
1528
1529 const usingCustomTheme = !isPresetTheme(this.props.theme.activeTheme)
1530 if (themeInput) {
1531 // createCustomThemes can return either 1 theme ("Custom Theme")
1532 // or 3 themes ("Custom Theme Light", "Custom Theme Dark", and "Custom Theme Auto")
1533 const customThemes = createCustomThemes(themeInput)
1534
1535 // Add the new custom themes to the theme manager and remove the preset themes
1536 this.props.theme.addThemes(customThemes, { keepPresetThemes: false })
1537
1538 const mappedTheme = getPreferredTheme(customThemes)
1539 if (mappedTheme) {
1540 // User has a mappable preference - apply the full server config
1541 // while preserving their light/dark selection
1542 this.setAndSendTheme(mappedTheme)
1543 } else {
1544 // No mappable preference - set to default custom theme
1545 // This handles cases where:
1546 // - No user preference exists (userPreference === null)
1547 // - User has a preset theme cached but custom themes are now available
1548 // - User has an old custom theme that no longer matches
1549 if (customThemes.length > 1) {
1550 // When Custom Theme Light & Custom Theme Dark present, we create an auto theme based
1551 // on the system preference and set this as the active theme
1552 const autoThemeIndex = customThemes.findIndex(
1553 theme => theme.name === CUSTOM_THEME_AUTO_NAME
1554 )
1555 this.setAndSendTheme(customThemes[autoThemeIndex])
1556 } else {
1557 // Set to singular Custom Theme
1558 this.setAndSendTheme(customThemes[0])
1559 }
1560 }
1561 } else {
1562 // Remove the custom theme menu option.
1563 this.props.theme.addThemes([])
1564
1565 if (usingCustomTheme) {
1566 const presetThemes = [lightTheme, darkTheme]
1567 const mappedTheme = getPreferredTheme(presetThemes)
1568
1569 if (mappedTheme) {
1570 // User had a custom theme preference that maps to a preset - preserve their choice
1571 this.setAndSendTheme(mappedTheme)
1572 } else {
1573 // Reset to the auto theme
1574 this.setAndSendTheme(createAutoTheme())
1575 }
1576 }
1577 }
1578
1579 if (

Callers 1

AppClass · 0.95

Calls 4

isPresetThemeFunction · 0.90
createCustomThemesFunction · 0.90
getPreferredThemeFunction · 0.90
createAutoThemeFunction · 0.90

Tested by

no test coverage detected