Skip to content

Commit 142818d

Browse files
authored
feat(theme): removed broken styles, make the page inset a token (#925)
* feat(theme): removed broken styles, make the page inset a token * feat(theme): add new global header styles * feat(theme): use margin instead of border for inset * fix(theme): align border radius with pf6
1 parent 13dd7b1 commit 142818d

6 files changed

Lines changed: 74 additions & 16 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+
Added `theme.rhdh.general.pageInset` option for easier customizability. Removed broken global header styles.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface RHDHThemePalette {
6060
};
6161
// (undocumented)
6262
general: {
63+
pageInset: string;
6364
disabled: string;
6465
disabledBackground: string;
6566
paperBackgroundImage: string;
@@ -80,6 +81,7 @@ export interface RHDHThemePalette {
8081
tableBackgroundColor: string;
8182
tabsLinkHoverBackgroundColor: string;
8283
contrastText: string;
84+
appBarBackgroundScheme: 'light' | 'dark';
8385
appBarBackgroundColor: string;
8486
appBarForegroundColor: string;
8587
appBarBackgroundImage: string;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const darkThemeOverrides: Partial<ThemeConfigPalette> = {
4848
},
4949
rhdh: {
5050
general: {
51+
pageInset: '1.5rem',
52+
5153
disabled: '#AAABAC',
5254
disabledBackground: '#444548',
5355

@@ -78,6 +80,8 @@ export const darkThemeOverrides: Partial<ThemeConfigPalette> = {
7880

7981
contrastText: '#FFF',
8082

83+
appBarBackgroundScheme: 'dark',
84+
8185
appBarBackgroundColor: '#151515',
8286
appBarForegroundColor: '#ffffff',
8387
appBarBackgroundImage: 'none',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const lightThemeOverrides: Partial<ThemeConfigPalette> = {
4848
},
4949
rhdh: {
5050
general: {
51+
pageInset: '1.5rem',
52+
5153
disabled: '#6A6E73',
5254
disabledBackground: '#D2D2D2',
5355

@@ -78,6 +80,8 @@ export const lightThemeOverrides: Partial<ThemeConfigPalette> = {
7880

7981
contrastText: '#FFF',
8082

83+
appBarBackgroundScheme: 'light',
84+
8185
appBarBackgroundColor: '#f2f2f2',
8286
appBarForegroundColor: '#1f1f1f',
8387
appBarBackgroundImage: 'none',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export type BackstageThemePalette = UnifiedThemeOptions['palette'];
2020

2121
export interface RHDHThemePalette {
2222
general: {
23+
pageInset: string;
24+
2325
disabled: string;
2426
disabledBackground: string;
2527

@@ -48,6 +50,8 @@ export interface RHDHThemePalette {
4850

4951
contrastText: string;
5052

53+
appBarBackgroundScheme: 'light' | 'dark';
54+
5155
appBarBackgroundColor: string;
5256
appBarForegroundColor: string;
5357
appBarBackgroundImage: string;

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

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export type Components = UnifiedThemeOptions['components'] & {
4141
BackstageTableToolbar?: Component;
4242
CatalogReactUserListPicker?: Component;
4343
PrivateTabIndicator?: Component;
44+
RHDHPageWithoutFixHeight?: Component;
4445
};
4546

4647
export const createComponents = (themeConfig: ThemeConfig): Components => {
@@ -95,9 +96,15 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
9596
if (options.buttons !== 'mui') {
9697
components.MuiTypography = {
9798
styleOverrides: {
98-
button: {
99-
textTransform: 'none',
99+
root: {
100+
fontFamily: redHatFonts.text,
100101
fontWeight: 'normal',
102+
letterSpacing: '0.01em',
103+
// This is required to override the default MUI styles
104+
// that set the `font-weight` to `500` for the `h1` element.
105+
'&.MuiTypography-h1': {
106+
fontWeight: 'normal',
107+
},
101108
},
102109
},
103110
};
@@ -626,6 +633,10 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
626633
borderRadius: '6px',
627634
width: 'calc(100% - 0.5rem) !important',
628635
marginLeft: '0.5rem !important',
636+
textDecorationLine: 'none',
637+
'&:hover, &:focus-visible': {
638+
backgroundColor: general.sidebarItemSelectedBackgroundColor,
639+
},
629640
},
630641
label: {
631642
'&[class*="MuiTypography-subtitle2"]': {
@@ -683,30 +694,58 @@ export const createComponents = (themeConfig: ThemeConfig): Components => {
683694
}
684695

685696
if (options.pages !== 'mui') {
697+
components.RHDHPageWithoutFixHeight = {
698+
styleOverrides: {
699+
root: {
700+
// Cancel out the spacing produced by the page inset border when
701+
// the global header is present in the above-sidebar position.
702+
'@media (min-width: 600px)': {
703+
'#above-sidebar-header-container:has(*) ~ [class*="sidebarLayout"]':
704+
{
705+
"& [class*='BackstagePage-root'], & [class*='MuiLinearProgress-root']":
706+
{
707+
marginTop: '0 !important',
708+
},
709+
},
710+
},
711+
},
712+
sidebarLayout: {
713+
// Cancel out the spacing produced by the page inset border when
714+
// the global header is present in the above-main-content position.
715+
'@media (min-width: 600px)': {
716+
'#above-main-content-header-container:has(*)': {
717+
"& ~ [class*='BackstagePage-root'], & ~ [class*='MuiLinearProgress-root']":
718+
{
719+
marginTop: '0 !important',
720+
},
721+
},
722+
},
723+
},
724+
},
725+
};
686726
components.BackstageSidebarPage = {
687727
styleOverrides: {
688728
root: {
689729
// Controls the page inset as in PF6 -- only in desktop view
690730
'@media (min-width: 600px)': {
691-
// The size of the page inset border
692-
'--rhdh-v1-page-inset': '1.5rem',
693731
backgroundColor: general.sidebarBackgroundColor,
694-
// Cancel out the spacing produced by the page inset border when
695-
// the global header is present
696-
"& #global-header ~ main, & #global-header ~ [class*='MuiLinearProgress-root'], & #above-main-content-header-container ~ main, & #above-main-content-header-container ~ [class*='MuiLinearProgress-root']":
697-
{
698-
marginTop: 'calc(-1 * var(--rhdh-v1-page-inset))',
699-
},
732+
// Prevents the main content from scrolling weird
733+
overflowY: 'auto',
700734
// Cancel out the spacing produced by the page inset border when
701735
// the sidebar is present
702-
"& nav ~ main, & nav ~ [class*='MuiLinearProgress-root']": {
703-
marginLeft: 'calc(-1 * var(--rhdh-v1-page-inset))',
736+
'& nav': {
737+
"& ~ main, & ~ [class*='MuiLinearProgress-root']": {
738+
marginLeft: '0 !important',
739+
},
704740
},
705-
// The border + border radius emulates the PF6 page inset look without
706-
// needing to change the markup
707741
"& > [class*='MuiLinearProgress-root'], & > main": {
708-
borderRadius: 'calc(1rem + var(--rhdh-v1-page-inset))',
709-
border: `var(--rhdh-v1-page-inset) solid ${general.sidebarBackgroundColor}`,
742+
// clip-path clips the scrollbar properly in Chrome compared to
743+
// border-radius. 1rem is the hardcoded border-radius of the page content.
744+
clipPath: 'rect(0 100% 100% 0 round 1rem)',
745+
// Emulate the PatternFly 6 page inset using a margin
746+
margin: general.pageInset,
747+
// Prevent overflow in the main container due to the margin
748+
maxHeight: `calc(100vh - 2 * ${general.pageInset})`,
710749
},
711750
// The Backstage suspense is an MUI LinearProgress that is not wrapped by
712751
// a `main`. We need to give it 100vh height to fill the page for the page

0 commit comments

Comments
 (0)