Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VE-252 Combine dark and light themes for mui v6 #1009

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3861160
trying combined theme
m4manjesh Dec 4, 2024
264fb14
sort -order fix
m4manjesh Dec 4, 2024
ba38641
useColorTheme hook from mui
mattcorner Dec 4, 2024
b5a45bb
Merge branch 'enhancement/ve-252-combine-theme-for-mui-v6' of https:/…
m4manjesh Dec 4, 2024
b19b8df
fixing test to use useColorScheme
m4manjesh Dec 4, 2024
c254436
removing context for use theme
m4manjesh Dec 4, 2024
4a9ab81
fixing warning
m4manjesh Dec 4, 2024
8a12323
adding missing tokens
m4manjesh Dec 4, 2024
4bab5b4
updating props to correct values
m4manjesh Dec 4, 2024
07fd7ec
Merge branch 'migrate-depricated-apis-to-v6' into enhancement/ve-252-…
m4manjesh Dec 10, 2024
f0935bb
fix test
m4manjesh Dec 10, 2024
e4d7efd
fix sorting
m4manjesh Dec 10, 2024
9993061
adding the color schemes
m4manjesh Dec 10, 2024
0f7089a
10.0.0-3
m4manjesh Dec 10, 2024
e5313f4
updating colors and unwanted space removed
m4manjesh Dec 10, 2024
4add550
change the prefix to ipg
m4manjesh Dec 10, 2024
f88a2af
update theme color prefix
m4manjesh Dec 10, 2024
a067452
10.0.0-4
m4manjesh Dec 10, 2024
913d61e
update hook comments
m4manjesh Dec 10, 2024
13bb88e
remove commented code
m4manjesh Dec 10, 2024
db855f7
Merge branch 'release/v10.0.0' into enhancement/ve-252-combine-theme-…
m4manjesh Dec 10, 2024
c507a4e
set mode to light when theme mode is system
m4manjesh Dec 12, 2024
3c8608d
fix type values
m4manjesh Dec 12, 2024
15df447
set defaultComponents
m4manjesh Dec 12, 2024
ec2aae7
10.0.0-5
m4manjesh Dec 12, 2024
a0a443d
Convert VirtoLogo to typescript
m4manjesh Dec 12, 2024
190b5c5
10.0.0-6
m4manjesh Dec 13, 2024
d1ad40a
fixing font picker
m4manjesh Dec 16, 2024
0c01d06
using grid2 and updated border color
m4manjesh Dec 16, 2024
4294cc2
fixed/added broken theme definitions
m4manjesh Dec 16, 2024
0a72cfc
rename and update doc
m4manjesh Dec 16, 2024
18a10b8
fixing tests
m4manjesh Dec 16, 2024
e0072d4
enable themeCssVarsAugmentation and update interfaces
m4manjesh Dec 16, 2024
a18e56b
using old theme colors
m4manjesh Dec 16, 2024
74f22fe
fixing the colors
m4manjesh Dec 16, 2024
d235e5c
adding grey bg color to story
m4manjesh Dec 17, 2024
87d45b6
using theme colors for buttons
m4manjesh Dec 17, 2024
0079504
remove console log
m4manjesh Dec 17, 2024
f65f34e
setting mode to correct local storage
m4manjesh Dec 17, 2024
47d7b5e
10.0.0-7
m4manjesh Dec 17, 2024
3a2a01c
fixing the icon button color
m4manjesh Dec 17, 2024
f508bcd
fixing the label color
m4manjesh Dec 17, 2024
a0ff0d3
fixing the missing spacing by moving font family to allVariants
m4manjesh Dec 17, 2024
7247bca
button colour use default action.active
m4manjesh Dec 17, 2024
6971838
label color to text secondary
m4manjesh Dec 17, 2024
c972d9d
removing hardcoded color for close buttons
m4manjesh Dec 18, 2024
55a6e6f
fixing font
m4manjesh Dec 18, 2024
4fda39d
10.0.0-8
m4manjesh Dec 18, 2024
1364279
fixing the font for step icon text
m4manjesh Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions .storybook/styles.css
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
.dark {
background: #1b1c1d;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added background , this was getting overwritten by dark color-scheme from mui


.sb-nopreview_main {
background: #1B1C1D;
background: #1b1c1d;
}

.sb-nopreview_heading {
text-align: center;
text-align: center;
}

.sb-errordisplay {
background: #2c2f33;
color: white;
background: #2c2f33;
color: white;
}

.sb-errordisplay_main {
background: #1e1e1e;
box-shadow: 0 0 64px rgba(255, 255, 255, 0.1);
background: #1e1e1e;
box-shadow: 0 0 64px rgba(255, 255, 255, 0.1);
}

.sb-errordisplay_code {
background: #1c1c1c;
color: #d4d4d4;
background: #1c1c1c;
color: #d4d4d4;
}

.sb-preparing-story,
.sb-preparing-docs {
background-color: #1B1C1D;
background-color: #1b1c1d;
}

.sb-loader {
border-color: rgba(158, 158, 158, 0.29);
border-color: rgba(158, 158, 158, 0.29);
}

.sb-previewBlock {
background: #2c2f33;
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: rgba(255, 255, 255, 0.1) 0 1px 3px 0;
background: #2c2f33;
border: 1px solid rgba(255, 255, 255, 0.1);
box-shadow: rgba(255, 255, 255, 0.1) 0 1px 3px 0;
}

.sb-previewBlock_header {
box-shadow: rgba(255, 255, 255, 0.1) 0 -1px 0 0 inset;
box-shadow: rgba(255, 255, 255, 0.1) 0 -1px 0 0 inset;
}

.sb-previewBlock_icon {
background: #3c3f43;
background: #3c3f43;
}

.sb-argstableBlock th span,
.sb-argstableBlock td span {
background-color: rgba(255, 255, 255, 0.1);
background-color: rgba(255, 255, 255, 0.1);
}

.sb-argstableBlock-body {
box-shadow:
rgba(255, 255, 255, 0.1) 0 1px 3px 1px,
rgba(255, 255, 255, 0.065) 0 0 0 1px;
box-shadow:
rgba(255, 255, 255, 0.1) 0 1px 3px 1px,
rgba(255, 255, 255, 0.065) 0 0 0 1px;
}

.sb-argstableBlock-body tr:not(:first-child) {
border-top: 1px solid #3c3f43;
border-top: 1px solid #3c3f43;
}

.sb-argstableBlock-body td {
background: #1B1C1D;
background: #1b1c1d;
}

.sb-argstableBlock-body button {
background-color: rgba(255, 255, 255, 0.1);
background-color: rgba(255, 255, 255, 0.1);
}
}
10 changes: 9 additions & 1 deletion src/Filter/SidebarFilter/SidebarFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ export function SidebarFilter({
<IconButton
data-testid="filter-close-button"
onClick={() => setOpen(false)}
sx={{ position: "absolute", right: 12, top: 12 }}
sx={theme => ({
color: "#9e9e9e",
position: "absolute",
right: 12,
top: 12,
...theme.applyStyles("dark", {
color: "#ffffff"
})
})}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you introducing more hardcoded colours? Lets not add to the problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligned with @Sowbhagya-ipg to go with default action.active for icon buttons

>
<Close />
</IconButton>
Expand Down
20 changes: 12 additions & 8 deletions src/FontPicker/FontPicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default function FontPicker({
required={required}
variant={variant}
slotProps={{
input: {
htmlInput: {
...params.inputProps,
sx: {
fontFamily: `${value}, Arial, sans-serif`
Expand All @@ -203,13 +203,17 @@ export default function FontPicker({
}}
/>
)}
renderOption={(props, option) => (
<Box {...props}>
<Typography sx={{ fontFamily: `${option}, Arial, sans-serif` }}>
{option}
</Typography>
</Box>
)}
renderOption={(props, option) => {
// Destructure to separate key
const { key, ...otherProps } = props;
return (
<Box {...otherProps} key={key}>
<Typography sx={{ fontFamily: `${option}, Arial, sans-serif` }}>
{option}
</Typography>
</Box>
);
}}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/LazyLoadImage/LazyLoadImage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Grid, Typography } from "@mui/material";
import { Box, Grid2 as Grid, Typography } from "@mui/material";
import { Meta, StoryFn } from "@storybook/react";

import LazyLoadImage from "./LazyLoadImage";
Expand Down Expand Up @@ -126,7 +126,7 @@ const FlexSizeComponent: StoryFn<LazyLoadImageProps> = args => {
transition: "color 0.1s"
},
backgroundColor: theme.palette.background.paper,
border: `1px solid`,
border: `1px solid ${theme.palette.divider}`,
borderRadius: "6px",
mattcorner marked this conversation as resolved.
Show resolved Hide resolved
cursor: "pointer",
height: "238px",
Expand Down
14 changes: 12 additions & 2 deletions src/MultiText/MultiText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export default function LabelSetter({ onChange = () => {}, rows = [] }) {
headerName: "Action",
renderCell: params => (
<IconButton
color="primary"
sx={theme => ({
color: "#9e9e9e",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the hardcoded colour?

...theme.applyStyles("dark", {
color: theme.palette.primary.main
})
})}
data-testid="deleteButton"
onClick={event => handleOnDeleteClick(event, params)}
>
Expand Down Expand Up @@ -98,7 +103,12 @@ export default function LabelSetter({ onChange = () => {}, rows = [] }) {
/>
<Box>
<IconButton
color="primary"
sx={theme => ({
color: "#9e9e9e",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the hardcoded colour?

...theme.applyStyles("dark", {
color: theme.palette.primary.main
})
})}
data-testid="addButton"
onClick={handleOnAddClick}
>
Expand Down
11 changes: 9 additions & 2 deletions src/ThemeProvider/ThemeProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("ThemeProvider", () => {
test("renders light theme by default", () => {
// render the component
render(
<ThemeProvider theme="light">
<ThemeProvider>
<ThemeText />
</ThemeProvider>
);
Expand Down Expand Up @@ -73,9 +73,16 @@ describe("ThemeProvider", () => {
// set the theme in local storage
window.localStorage.setItem("mui-theme", mode);

// get the theme from local storage
const defaultMode = window.localStorage.getItem("mui-theme") as
| "light"
| "dark";

console.log(defaultMode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover console.log


// render the component
render(
<ThemeProvider theme={mode}>
<ThemeProvider theme={defaultMode}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't pass the mode into ThemeProvider. The original behaviour of this test was that it passed no props in and the ThemeProvider read localStorage itself.

<ThemeText />
</ThemeProvider>
);
Expand Down
79 changes: 49 additions & 30 deletions src/ThemeProvider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-undef */

import type {} from "@mui/x-data-grid/themeAugmentation";
import type {} from "@mui/material/themeCssVarsAugmentation";

import {
ThemeProvider as MuiThemeProvider,
Expand All @@ -17,14 +18,6 @@ import darkScrollbar from "@mui/material/darkScrollbar";
// extend the theme to include custom properties
// https://mui.com/material-ui/customization/theming/#custom-variables
declare module "@mui/material/styles" {
// eslint-disable-next-line no-unused-vars
interface Theme {
layout: {
content: {
maxWidth: number;
};
};
}
// allow configuration using `createTheme`
// eslint-disable-next-line no-unused-vars
interface ThemeOptions {
Expand All @@ -33,17 +26,21 @@ declare module "@mui/material/styles" {
maxWidth?: number;
};
};
colorSchemes?: {
dark?: ThemeOptions;
light?: ThemeOptions;
};
}
// eslint-disable-next-line no-unused-vars
interface Theme {
colorSchemes: {
light: ThemeOptions;
dark: ThemeOptions;
layout: {
content: {
maxWidth: number;
};
};
}
interface ThemeOptions {
colorSchemes?: {
light?: ThemeOptions;
dark?: ThemeOptions;
light?: ThemeOptions;
};
}
}
Expand Down Expand Up @@ -82,6 +79,15 @@ const defaultComponents = {
}
}
},
MuiFormControl: {
styleOverrides: {
root: {
"& .MuiFormLabel-root, .MuiFormHelperText-root ": {
color: "var(--ipg-palette-text-secondary)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using palette-text-secondary as per discussion with @Sowbhagya-ipg

}
}
}
},
MuiFormLabel: {
styleOverrides: {
asterisk: {
Expand All @@ -93,7 +99,8 @@ const defaultComponents = {
styleOverrides: {
tooltip: {
fontFamily: "Montserrat, Arial, sans-serif",
fontSize: "12px"
fontSize: "12px",
fontWeight: 400
}
}
}
Expand All @@ -119,6 +126,16 @@ const mainTheme: ThemeOptions = {
}
}
},
MuiAutocomplete: {
styleOverrides: {
clearIndicator: {
color: "#ffffff"
},
popupIndicator: {
color: "#ffffff"
}
}
},
MuiCssBaseline: {
styleOverrides: {
body: darkScrollbar()
Expand Down Expand Up @@ -151,7 +168,6 @@ const mainTheme: ThemeOptions = {
})
}
},
MuiIconButton: { styleOverrides: { root: { color: "#9e9e9e" } } },
MuiStepper: {
styleOverrides: {
root: {
Expand Down Expand Up @@ -179,8 +195,7 @@ const mainTheme: ThemeOptions = {
},
"&:hover": {
backgroundColor: "rgba(0, 95, 168, 0.15)"
},
borderColor: "rgb(196, 196, 196)"
}
}
}
}
Expand Down Expand Up @@ -233,30 +248,34 @@ export default function ThemeProvider({
}: ThemeProviderProps) {
// wrap mui theme provider and children in theme context
return (
<MuiThemeProvider theme={mainThemeWithColorSchemes}>
<ChildWrapper theme={controlledTheme}>{children}</ChildWrapper>
<MuiThemeProvider theme={mainThemeWithColorSchemes} defaultMode="light">
<ControlledThemeWrapper theme={controlledTheme}>
{children}
</ControlledThemeWrapper>
</MuiThemeProvider>
);
}

/**
* Child wrapper to handle controlled theme changes
* ControlledThemeWrapper Component
*
* This component is used to enforce a specific theme mode (`light` or `dark`)
* for its child components based on the `controlledTheme` prop. It synchronizes
* the theme mode with the provided value and ensures the children use the correct
* theme. The wrapper relies on MuI's `useColorScheme` hook for theme mode management.
*
* @param props.children - The child components to render inside the wrapper.
* @param props.theme - The desired theme mode (`light` or `dark`) to enforce.
*
* @returns The wrapped children with the enforced theme mode.
*/
function ChildWrapper({
function ControlledThemeWrapper({
children,
theme: controlledTheme
}: ThemeProviderProps) {
// use hook from MUI to get and set the theme mode
const { mode, setMode } = useColorScheme();

// update the theme mode to "light" if current mode is "system"
useEffect(() => {
if (mode === "system") {
setMode("light");
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mode]);

// update the theme mode when the controlled theme changes
useEffect(() => {
if (controlledTheme && mode !== controlledTheme) {
Expand Down
2 changes: 1 addition & 1 deletion src/VirtoAppLayout/VirtoAppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Layout({
</Box>
<Box
sx={{
background: `var(--ipg-palette-background-paper)`,
background: theme => theme.vars.palette.background.default,
display: "flex",
flexDirection: "column",
flexGrow: 1
Expand Down
Loading