Skip to content

Commit

Permalink
Fix theme missing theme highlight. Fixes #4641
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 16, 2024
1 parent 5e592b1 commit 2d52a06
Showing 1 changed file with 28 additions and 50 deletions.
78 changes: 28 additions & 50 deletions packages/core/ui/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const midnight = '#0D233F'
const grape = '#721E63'
const forest = refTheme.palette.augmentColor({ color: { main: '#135560' } })
const mandarin = refTheme.palette.augmentColor({ color: { main: '#FFB11D' } })
const lightgrey = refTheme.palette.augmentColor({ color: { main: '#aaa' } })
const bases = {
A: refTheme.palette.augmentColor({ color: green }),
C: refTheme.palette.augmentColor({ color: blue }),
Expand Down Expand Up @@ -468,66 +469,43 @@ export function createJBrowseTheme(
return createTheme(
createJBrowseBaseTheme(
themeName === 'default'
? deepmerge(themes.default!, augmentTheme(configTheme), {
? deepmerge(themes.default!, augmentThemeColors(configTheme), {
arrayMerge: overwriteArrayMerge,
})
: augmentThemePlus(themes[themeName]),
: addMissingColors(themes[themeName]),
),
)
}

function augmentTheme(theme: ThemeOptions = {}) {
if (theme.palette?.tertiary) {
theme = deepmerge(theme, {
palette: {
tertiary: refTheme.palette.augmentColor(
'color' in theme.palette.tertiary
? (theme.palette.tertiary as PaletteAugmentColorOptions)
: { color: theme.palette.tertiary },
),
},
})
}

if (theme.palette?.quaternary) {
theme = deepmerge(theme, {
palette: {
quaternary: refTheme.palette.augmentColor(
'color' in theme.palette.quaternary
? (theme.palette.quaternary as PaletteAugmentColorOptions)
: { color: theme.palette.quaternary },
),
},
})
// MUI by default allows strings like '#f00' for primary and secondary and
// augments them to have light and dark variants but not for anything else, so
// we augment them here
function augmentThemeColors(theme: ThemeOptions = {}) {
for (const entry of ['tertiary', 'quaternary', 'highlight'] as const) {
if (theme.palette?.[entry]) {
theme = deepmerge(theme, {
palette: {
[entry]: refTheme.palette.augmentColor(
'color' in theme.palette[entry]
? (theme.palette[entry] as PaletteAugmentColorOptions)
: { color: theme.palette[entry] },
),
},
})
}
}

return theme
}

// creates some blank quaternary/tertiary colors if unsupplied by a user theme
function augmentThemePlus(theme: ThemeOptions = {}) {
theme = augmentTheme(theme)
if (!theme.palette?.quaternary) {
theme = deepmerge(theme, {
// adds missing colors to users theme
function addMissingColors(theme: ThemeOptions = {}) {
return augmentThemeColors(
deepmerge(theme, {
palette: {
quaternary: refTheme.palette.augmentColor({
color: {
main: '#aaa',
},
}),
},
})
}
if (!theme.palette?.tertiary) {
theme = deepmerge(theme, {
palette: {
tertiary: refTheme.palette.augmentColor({
color: {
main: '#aaa',
},
}),
quaternary: theme.palette?.quaternary || lightgrey,
tertiary: theme.palette?.tertiary || lightgrey,
highlight: theme.palette?.highlight || mandarin,
},
})
}
return theme
}),
)
}

0 comments on commit 2d52a06

Please sign in to comment.