Skip to content

Commit 8754b21

Browse files
pick the navigation or rhdh colors based on user's config (#2870)
Signed-off-by: Karthik <karthik.jk11@gmail.com>
1 parent 00d5f11 commit 8754b21

8 files changed

Lines changed: 337 additions & 59 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-theme': patch
3+
---
4+
5+
Align the navigation sidebar with merged `palette.navigation` and `rhdh.general` colors, including submenu rows and selected/active `BackstageSidebarItem` states. Add `rhdh.general.pageInsetBackgroundColor` so the page inset shell can use its own color (defaults match the previous app bar fill; falls back to `appBarBackgroundColor` when unset). Main content area remains on `mainSectionBackgroundColor`.

workspaces/theme/plugins/theme/report.api.md

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,51 +54,52 @@ export const lightThemeProvider: (props: {
5454

5555
// @public (undocumented)
5656
export interface RHDHThemePalette {
57-
// (undocumented)
58-
cards?: {
59-
headerTextColor: string;
60-
headerBackgroundColor: string;
61-
headerBackgroundImage: string;
62-
};
63-
// (undocumented)
64-
general: {
65-
pageInset: string;
66-
disabled: string;
67-
disabledBackground: string;
68-
paperBackgroundImage: string;
69-
paperBorderColor: string;
70-
popoverBoxShadow: string;
71-
cardBackgroundColor: string;
72-
cardBorderColor: string;
73-
mainSectionBackgroundColor: string;
74-
formControlBackgroundColor: string;
75-
sidebarBackgroundColor: string;
76-
sidebarDividerColor: string;
77-
sidebarItemSelectedBackgroundColor: string;
78-
tableTitleColor: string;
79-
tableSubtitleColor: string;
80-
tableColumnTitleColor: string;
81-
tableRowHover: string;
82-
tableBorderColor: string;
83-
tableBackgroundColor: string;
84-
tabsLinkHoverBackgroundColor: string;
85-
contrastText: string;
86-
appBarBackgroundScheme: 'light' | 'dark';
87-
appBarBackgroundColor: string;
88-
appBarForegroundColor: string;
89-
appBarBackgroundImage: string;
90-
starredItemsColor: string;
91-
};
92-
// (undocumented)
93-
primary: {
94-
main: string;
95-
focusVisibleBorder: string;
96-
};
97-
// (undocumented)
98-
secondary: {
99-
main: string;
100-
focusVisibleBorder: string;
101-
};
57+
// (undocumented)
58+
cards?: {
59+
headerTextColor: string;
60+
headerBackgroundColor: string;
61+
headerBackgroundImage: string;
62+
};
63+
// (undocumented)
64+
general: {
65+
pageInset: string;
66+
pageInsetBackgroundColor: string;
67+
disabled: string;
68+
disabledBackground: string;
69+
paperBackgroundImage: string;
70+
paperBorderColor: string;
71+
popoverBoxShadow: string;
72+
cardBackgroundColor: string;
73+
cardBorderColor: string;
74+
mainSectionBackgroundColor: string;
75+
formControlBackgroundColor: string;
76+
sidebarBackgroundColor: string;
77+
sidebarDividerColor: string;
78+
sidebarItemSelectedBackgroundColor: string;
79+
tableTitleColor: string;
80+
tableSubtitleColor: string;
81+
tableColumnTitleColor: string;
82+
tableRowHover: string;
83+
tableBorderColor: string;
84+
tableBackgroundColor: string;
85+
tabsLinkHoverBackgroundColor: string;
86+
contrastText: string;
87+
appBarBackgroundScheme: 'light' | 'dark';
88+
appBarBackgroundColor: string;
89+
appBarForegroundColor: string;
90+
appBarBackgroundImage: string;
91+
starredItemsColor: string;
92+
};
93+
// (undocumented)
94+
primary: {
95+
main: string;
96+
focusVisibleBorder: string;
97+
};
98+
// (undocumented)
99+
secondary: {
100+
main: string;
101+
focusVisibleBorder: string;
102+
};
102103
}
103104

104105
// @public (undocumented)

workspaces/theme/plugins/theme/src/darkTheme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const darkThemeOverrides: Partial<ThemeConfigPalette> = {
4949
rhdh: {
5050
general: {
5151
pageInset: '1.5rem',
52+
pageInsetBackgroundColor: '#151515',
5253

5354
disabled: '#AAABAC',
5455
disabledBackground: '#444548',

workspaces/theme/plugins/theme/src/lightTheme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const lightThemeOverrides: Partial<ThemeConfigPalette> = {
2727
main: '#0066CC',
2828
},
2929
navigation: {
30-
background: '#222427',
30+
background: '#f2f2f2',
3131
indicator: 'transparent',
3232
color: '#151515',
3333
selectedColor: '#151515',
@@ -49,6 +49,7 @@ export const lightThemeOverrides: Partial<ThemeConfigPalette> = {
4949
rhdh: {
5050
general: {
5151
pageInset: '1.5rem',
52+
pageInsetBackgroundColor: '#f2f2f2',
5253

5354
disabled: '#6A6E73',
5455
disabledBackground: '#D2D2D2',

workspaces/theme/plugins/theme/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type BackstageThemePalette = UnifiedThemeOptions['palette'];
2121
export interface RHDHThemePalette {
2222
general: {
2323
pageInset: string;
24+
pageInsetBackgroundColor: string;
2425

2526
disabled: string;
2627
disabledBackground: string;

workspaces/theme/plugins/theme/src/utils/createComponents.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { type CSSObject } from '@mui/material/styles';
2222

2323
import { ThemeConfig, ThemeConfigOptions, RHDHThemePalette } from '../types';
2424
import { redHatFontFaces, redHatFonts } from '../fonts';
25+
import { resolveNavigationSidebarColors } from './navigationSidebarColors';
2526

2627
export type Component = {
2728
defaultProps?: unknown;
@@ -617,16 +618,33 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
617618
}
618619

619620
if (options.sidebars !== 'mui') {
621+
const {
622+
sidebarBackgroundColor,
623+
sidebarItemInteractionBackgroundColor,
624+
navigationItemColor,
625+
navigationSelectedColor,
626+
} = resolveNavigationSidebarColors(themeConfig);
627+
620628
components.BackstageSidebar = {
621629
styleOverrides: {
622630
drawer: {
623631
gap: '0.25rem',
624-
borderRight: `0.5rem solid ${general.sidebarBackgroundColor}`,
632+
borderRight: `0.5rem solid ${sidebarBackgroundColor}`,
625633
paddingBottom: '1.5rem',
626-
backgroundColor: general.sidebarBackgroundColor,
634+
backgroundColor: sidebarBackgroundColor,
627635
'& hr': {
628636
backgroundColor: general.sidebarDividerColor,
629637
},
638+
'& [class*="BackstageSidebarItem-selected-"][class*="BackstageSidebarItem-root-"]':
639+
{
640+
backgroundColor: `${sidebarItemInteractionBackgroundColor} !important`,
641+
color: `${navigationSelectedColor} !important`,
642+
},
643+
644+
'& [class*="BackstageSidebarSubmenuItem-selected-"]': {
645+
background: `${sidebarItemInteractionBackgroundColor} !important`,
646+
color: `${navigationSelectedColor} !important`,
647+
},
630648
},
631649
},
632650
};
@@ -638,7 +656,7 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
638656
marginLeft: '0.5rem !important',
639657
textDecorationLine: 'none',
640658
'&:hover, &:focus-visible': {
641-
backgroundColor: general.sidebarItemSelectedBackgroundColor,
659+
backgroundColor: sidebarItemInteractionBackgroundColor,
642660
},
643661
},
644662
label: {
@@ -647,15 +665,16 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
647665
},
648666
},
649667
selected: {
650-
backgroundColor: general.sidebarItemSelectedBackgroundColor,
668+
backgroundColor: sidebarItemInteractionBackgroundColor,
669+
color: navigationSelectedColor,
651670
},
652671
},
653672
};
654673
components.MuiBottomNavigation = {
655674
styleOverrides: {
656675
root: {
657-
backgroundColor: `${general.sidebarBackgroundColor} !important`,
658-
borderColor: `${general.sidebarBackgroundColor} !important`,
676+
backgroundColor: `${sidebarBackgroundColor} !important`,
677+
borderColor: `${sidebarBackgroundColor} !important`,
659678
},
660679
},
661680
};
@@ -665,19 +684,19 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
665684
},
666685
styleOverrides: {
667686
root: {
668-
color: `${palette.text?.primary} !important`,
669-
backgroundColor: `${general.sidebarBackgroundColor} !important`,
687+
color: `${navigationItemColor} !important`,
688+
backgroundColor: `${sidebarBackgroundColor} !important`,
670689
borderRadius: '6px',
671690
borderTop: '3px solid transparent !important', // default mui selected styling
672691
paddingTop: '6px !important', // default mui selected styling
673692
marginTop: '-1px !important', // default mui selected styling
674693
'&:hover, &:focus-visible': {
675-
backgroundColor: `${general.sidebarItemSelectedBackgroundColor} !important`,
694+
backgroundColor: `${sidebarItemInteractionBackgroundColor} !important`,
676695
},
677696
},
678697
selected: {
679-
backgroundColor: `${general.sidebarItemSelectedBackgroundColor} !important`,
680-
color: `${palette.text?.primary} !important`,
698+
backgroundColor: `${sidebarItemInteractionBackgroundColor} !important`,
699+
color: `${navigationSelectedColor} !important`,
681700
},
682701
},
683702
};
@@ -686,7 +705,7 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
686705
root: {
687706
// undocumented Backstage makeStyles
688707
"& [class*='makeStyles-overlay-']": {
689-
backgroundColor: `${general.sidebarBackgroundColor} !important`,
708+
backgroundColor: `${sidebarBackgroundColor} !important`,
690709
},
691710
'& hr': {
692711
backgroundColor: general.sidebarDividerColor,
@@ -729,7 +748,8 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
729748
root: {
730749
// Controls the page inset as in PF6 -- only in desktop view
731750
'@media (min-width: 600px)': {
732-
backgroundColor: general.sidebarBackgroundColor,
751+
backgroundColor:
752+
general.pageInsetBackgroundColor ?? general.appBarBackgroundColor,
733753
// Prevents the main content from scrolling weird
734754
overflowY: 'auto',
735755
// Cancel out the spacing produced by the page inset border when
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import type { ThemeConfig } from '../types';
18+
import { getDefaultThemeConfig } from '../rhdh';
19+
import { resolveNavigationSidebarColors } from './navigationSidebarColors';
20+
21+
describe('resolveNavigationSidebarChrome', () => {
22+
const defaultLight = getDefaultThemeConfig('light');
23+
24+
it('matches baseline defaults', () => {
25+
const c = resolveNavigationSidebarColors(defaultLight);
26+
expect(c.sidebarBackgroundColor).toBe(
27+
defaultLight.palette?.rhdh?.general?.sidebarBackgroundColor,
28+
);
29+
expect(c.sidebarItemInteractionBackgroundColor).toBe(
30+
defaultLight.palette?.rhdh?.general?.sidebarItemSelectedBackgroundColor,
31+
);
32+
expect(c.navigationItemColor).toBe(defaultLight.palette?.navigation?.color);
33+
expect(c.navigationSelectedColor).toBe(
34+
defaultLight.palette?.navigation?.selectedColor,
35+
);
36+
});
37+
38+
it('uses palette.navigation.background when only that differs from baseline', () => {
39+
const config = {
40+
...defaultLight,
41+
palette: {
42+
...defaultLight.palette,
43+
navigation: {
44+
...defaultLight.palette?.navigation,
45+
background: '#aabbcc',
46+
},
47+
},
48+
} as ThemeConfig;
49+
expect(resolveNavigationSidebarColors(config).sidebarBackgroundColor).toBe(
50+
'#aabbcc',
51+
);
52+
});
53+
54+
it('uses rhdh.general.sidebarBackgroundColor when only that differs from baseline', () => {
55+
const config = {
56+
...defaultLight,
57+
palette: {
58+
...defaultLight.palette,
59+
rhdh: {
60+
...defaultLight.palette?.rhdh,
61+
general: {
62+
...defaultLight.palette?.rhdh?.general,
63+
sidebarBackgroundColor: '#ddeeff',
64+
},
65+
},
66+
},
67+
} as ThemeConfig;
68+
expect(resolveNavigationSidebarColors(config).sidebarBackgroundColor).toBe(
69+
'#ddeeff',
70+
);
71+
});
72+
73+
it('uses palette.navigation.navItem.hoverBackground when only that differs from baseline', () => {
74+
const config = {
75+
...defaultLight,
76+
palette: {
77+
...defaultLight.palette,
78+
navigation: {
79+
...defaultLight.palette?.navigation,
80+
navItem: {
81+
...defaultLight.palette?.navigation?.navItem,
82+
hoverBackground: '#0a0b0c',
83+
},
84+
},
85+
},
86+
} as ThemeConfig;
87+
expect(
88+
resolveNavigationSidebarColors(config)
89+
.sidebarItemInteractionBackgroundColor,
90+
).toBe('#0a0b0c');
91+
});
92+
});

0 commit comments

Comments
 (0)