Skip to content

Commit a9de0c2

Browse files
committed
Add gradient background support to oxygen-ui
1 parent 4774939 commit a9de0c2

File tree

3 files changed

+85
-9
lines changed

3 files changed

+85
-9
lines changed

.changeset/thick-bugs-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@wso2/oxygen-ui': patch
3+
---
4+
5+
Add gradient backgound style

packages/oxygen-ui/src/contexts/OxygenUIThemeProvider/OxygenUIThemeProvider.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,35 @@
1616
* under the License.
1717
*/
1818

19-
import { ThemeProvider as MUIThemeProvider, StyledEngineProvider, Theme } from '@mui/material/styles';
19+
import { useMemo } from 'react';
20+
import { ThemeProvider as MUIThemeProvider, StyledEngineProvider, Theme, createTheme } from '@mui/material/styles';
2021
import { CssBaseline } from '@mui/material';
21-
import OxygenTheme from '../../styles/OxygenTheme/OxygenTheme';
22+
import OxygenTheme, { RadialBodyBackgroundDesign } from '../../styles/OxygenTheme/OxygenTheme';
23+
24+
interface OxygenUIThemeProviderProps {
25+
children: React.ReactNode;
26+
theme?: Theme;
27+
radialBackground?: boolean;
28+
}
29+
30+
export default function OxygenUIThemeProvider({
31+
children,
32+
theme,
33+
radialBackground = false
34+
}: OxygenUIThemeProviderProps) {
35+
36+
const resolvedTheme = useMemo(() => {
37+
if (theme) return theme;
38+
39+
if (!radialBackground) return OxygenTheme;
40+
41+
// Create a new Oxygen UI theme with CssBaseline overrides with radial background
42+
return createTheme(OxygenTheme, RadialBodyBackgroundDesign);
43+
}, [theme, radialBackground]);
2244

23-
export default function OxygenUIThemeProvider({ children, theme }: { children: React.ReactNode, theme?: Theme }) {
2445
return (
2546
<StyledEngineProvider injectFirst>
26-
<MUIThemeProvider theme={theme ?? OxygenTheme}>
47+
<MUIThemeProvider theme={resolvedTheme}>
2748
<CssBaseline />
2849
{children}
2950
</MUIThemeProvider>

packages/oxygen-ui/src/styles/OxygenTheme/OxygenTheme.ts

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ import type {} from '@mui/x-data-grid/themeAugmentation';
2222

2323
const noShadows = Array(25).fill('none') as Shadows;
2424

25+
export const RadialBodyBackgroundDesign = {
26+
components: {
27+
MuiCssBaseline: {
28+
styleOverrides: {
29+
"html[data-color-scheme='dark'] body": {
30+
backgroundAttachment: 'fixed',
31+
backgroundImage: `
32+
radial-gradient(circle at 65% 30%, rgba(255, 116, 0, 0.12) 10%, rgba(0, 0, 0, 0) 60% 40%),
33+
radial-gradient(circle at 15% 50%, rgba(74, 41, 165, 0.2) 1%, rgba(0, 0, 0, 0) 40% 70%),
34+
radial-gradient(circle at center, rgba(0, 0, 0, 0.6) 0%, var(--mui-palette-background-default) 100%)
35+
`,
36+
backgroundBlendMode: 'screen',
37+
},
38+
"html[data-color-scheme='light'] body": {
39+
backgroundAttachment: 'fixed',
40+
backgroundImage: `
41+
radial-gradient(circle at 65% 30%, rgba(255, 116, 0, 0.1) 10%, rgba(255, 255, 255, 0) 40% 40%),
42+
radial-gradient(circle at 15% 50%, rgba(74, 41, 165, 0.1) 1%, rgba(255, 255, 255, 0) 40% 70%),
43+
radial-gradient(circle at center, rgba(255, 255, 255, 0.6) 0%, var(--mui-palette-background-default) 100%)
44+
`,
45+
backgroundBlendMode: 'normal',
46+
},
47+
},
48+
},
49+
},
50+
};
51+
2552
const OxygenTheme = createTheme({
2653
typography: {
2754
fontFamily: "'Inter Variable', sans-serif",
@@ -36,7 +63,7 @@ const OxygenTheme = createTheme({
3663
},
3764
shadows: noShadows,
3865
shape: {
39-
borderRadius: 20,
66+
borderRadius: 15,
4067
},
4168
cssVariables: {
4269
colorSchemeSelector: 'data-color-scheme',
@@ -84,6 +111,20 @@ const OxygenTheme = createTheme({
84111
},
85112
},
86113
components: {
114+
MuiAvatar: {
115+
styleOverrides: {
116+
root: ({ theme }) => ({
117+
...theme.applyStyles('light', {
118+
backgroundColor: '#ebebeb',
119+
color: '#40404B',
120+
}),
121+
...theme.applyStyles('dark', {
122+
backgroundColor: '#3c3c3c',
123+
color: '#D0D3E2',
124+
}),
125+
}),
126+
},
127+
},
87128
MuiButton: {
88129
styleOverrides: {
89130
root: {
@@ -101,17 +142,27 @@ const OxygenTheme = createTheme({
101142
},
102143
},
103144
},
145+
MuiDrawer: {
146+
styleOverrides: {
147+
paper: ({ theme }) => ({
148+
...theme.applyStyles('dark', {
149+
background: 'transparent',
150+
}),
151+
}),
152+
},
153+
},
104154
MuiFormLabel: {
105155
styleOverrides: {
106156
root: ({ theme }) => ({
107157
fontSize: theme.typography.body2.fontSize,
108-
marginBottom: '4px'
158+
marginBottom: '6px'
109159
}),
110160
},
111161
},
112162
MuiPaper: {
113163
styleOverrides: {
114164
root: ({ theme }) => ({
165+
borderRadius: theme.shape.borderRadius,
115166
WebkitBackdropFilter: 'blur(3px)',
116167
backdropFilter: 'blur(3px)',
117168
...theme.applyStyles('light', {
@@ -124,7 +175,7 @@ const OxygenTheme = createTheme({
124175
}),
125176
...theme.applyStyles('dark', {
126177
border: '1px solid #d2d2d20f',
127-
background: 'rgb(230 230 230 / 5%)',
178+
background: 'rgb(230 230 230 / 1%)',
128179
boxShadow:
129180
'0 24px 32px 0 rgba(6, 6, 14, 0.70),' +
130181
'0 24px 48px 0 rgba(199, 211, 234, 0.05) inset,' +
@@ -196,7 +247,7 @@ const OxygenTheme = createTheme({
196247
MuiListItemButton: {
197248
styleOverrides: {
198249
root: ({ theme }) => ({
199-
borderRadius: '8px',
250+
borderRadius: 8,
200251
'&.Mui-selected': {
201252
...theme.applyStyles('light', {
202253
backgroundColor: theme.palette.action.selected,
@@ -221,7 +272,6 @@ const OxygenTheme = createTheme({
221272
root: ({ theme }) => ({
222273
border: 'none',
223274
backgroundColor: 'transparent',
224-
borderRadius: '8px',
225275
overflow: 'hidden',
226276
'& .MuiDataGrid-columnHeaders': {
227277
backgroundColor: '#ffffff0a',

0 commit comments

Comments
 (0)