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

frontend: use mui theming #2851

Merged
merged 28 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
553b231
use mui theming
jecr Nov 16, 2023
814d002
update tests
jecr Nov 16, 2023
b156baa
fix theme typing
jecr Nov 30, 2023
e5922df
add contrast color
jecr Dec 4, 2023
ee86ed2
augment emotion theme with mui's
jecr Dec 5, 2023
de59ef5
frontend: leverage theme palette for Feedback components (#2857)
lucechal14 Dec 6, 2023
e67a4c0
frontend: leverage theme palette for AppLayout components (#2852)
jecr Dec 7, 2023
0ac0f44
frontend: leverage theme palette for input components (#2860)
lucechal14 Dec 12, 2023
4f17a8d
frontend: leverage theme palette for NPS components (#2862)
lucechal14 Dec 12, 2023
f464530
frontend: leverage theme palette for misc components (#2861)
jecr Dec 13, 2023
d58fd00
fix test, update snaps
jecr Dec 13, 2023
6472fd5
add customized useTheme hook and adjust usage
jecr Dec 14, 2023
2e37e3b
Fix import in storybook
jecr Dec 15, 2023
045ac7a
frontend: leverage theme palette for misc components (#2863)
jecr Dec 19, 2023
3452d48
frontend: leverage theme palette for workflows components (#2864)
lucechal14 Dec 19, 2023
fdf5b77
fontend: leverage theme palette for misc components (#2871)
jecr Dec 20, 2023
3fe6f20
frontend: update useTheme imports for workflows (#2887)
lucechal14 Jan 6, 2024
cb5fc28
frontend: Updating bg color on tab component for active state (#2895)
lucechal14 Jan 10, 2024
dbc9d95
frontend: fix component theming issues (#2894)
jecr Jan 11, 2024
f2278df
frontend: fix component theming issues (#2897)
lucechal14 Jan 12, 2024
1a4158c
frontend: fix workflows theming issues (#2898)
jecr Jan 12, 2024
3025f75
fix tests snaps
jecr Jan 15, 2024
2bfe3c5
frontend: update black and white colors to use contrast color from th…
lucechal14 Jan 17, 2024
1318418
frontend: point to error palette (#2903)
jecr Jan 19, 2024
147989f
frontend: type instances of theme in styled components (#2904)
jecr Jan 19, 2024
f93d94f
update snapshots
jecr Jan 19, 2024
1100d3c
frontend: adjust tab hover color (#2911)
jecr Jan 25, 2024
4e800ce
frontend: bump clutch core version (#2919)
jecr Feb 1, 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
10 changes: 5 additions & 5 deletions frontend/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Theme } from "./../packages/core/src/AppProvider/themes";
import Theme from "./../packages/core/src/AppProvider/themes";

export const decorators = [
(Story) => (
Expand All @@ -9,7 +9,7 @@ export const decorators = [
),
];

export const parameters = {
export const parameters = {
backgrounds: {
default: "clutch",
values: [
Expand All @@ -21,6 +21,6 @@ export const parameters = {
name: "light",
value: "#ffffff",
},
]
}
};
],
},
};
4 changes: 0 additions & 4 deletions frontend/packages/app/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ html, body, #root, #App {
min-height: 100vh;
}

#App {
background-color: #f9fafe;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
Expand Down
6 changes: 2 additions & 4 deletions frontend/packages/core/src/AppProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import NotFound from "../not-found";
import { registeredWorkflows } from "./registrar";
import ShortLinkProxy, { ShortLinkBaseRoute } from "./short-link-proxy";
import ShortLinkStateHydrator from "./short-link-state-hydrator";
import { Theme } from "./themes";
import Theme from "./themes";
import type { ConfiguredRoute, Workflow, WorkflowConfiguration } from "./workflow";
import ErrorBoundary from "./workflow";

Expand Down Expand Up @@ -160,9 +160,7 @@ const ClutchApp = ({

return (
<Router>
{/* TODO: use the ThemeProvider for proper theming in the future
See https://github.com/lyft/clutch/commit/f6c6706b9ba29c4d4c3e5d0ac0c5d0f038203937 */}
<Theme variant="light">
<Theme>
<div id="App">
<ApplicationContext.Provider value={appContextValue}>
<UserPreferencesProvider>
Expand Down
147 changes: 20 additions & 127 deletions frontend/packages/core/src/AppProvider/themes.tsx
Original file line number Diff line number Diff line change
@@ -1,140 +1,33 @@
import React from "react";
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
import type { Theme as MuiTheme } from "@mui/material";
import {
CssBaseline,
DeprecatedThemeOptions,
StyledEngineProvider,
ThemeProvider,
} from "@mui/material";
import { createTheme, PaletteOptions, useTheme as useMuiTheme } from "@mui/material/styles";
import { CssBaseline, StyledEngineProvider } from "@mui/material";
import { StylesProvider } from "@mui/styles";

declare module "@mui/styles/defaultTheme" {
interface DefaultTheme extends MuiTheme {}
}

interface ClutchPalette extends PaletteOptions {
accent: {
main: string;
};
destructive: {
main: string;
};
}

interface ClutchTheme extends DeprecatedThemeOptions {
palette: ClutchPalette;
}

const WHITE = "#ffffff";
const GRAY = "#D7DADB";
const TEAL = "#02acbe";
const RED = "#EF474D";
const NAVY = "#2D3F50";

const lightPalette = (): ClutchPalette => {
return {
accent: {
main: TEAL,
},
destructive: {
main: RED,
},
primary: {
main: WHITE,
},
secondary: {
main: NAVY,
},
background: {
default: WHITE,
paper: WHITE,
},
text: {
primary: NAVY,
secondary: GRAY,
},
};
};

const lightTheme = createTheme({
// adaptV4Theme({
palette: lightPalette(),
transitions: {
// https://material-ui.com/getting-started/faq/#how-can-i-disable-transitions-globally
create: () => "none",
},
components: {
MuiButtonBase: {
// https://material-ui.com/getting-started/faq/#how-can-i-disable-the-ripple-effect-globally
defaultProps: {
disableRipple: true,
},
},
MuiCssBaseline: {
styleOverrides: {
body: {
// Default as MUI changed fontSize to 1rem
fontSize: "0.875rem",
},
},
},
MuiSelect: {
styleOverrides: {
select: {
fontSize: "0.875rem",
height: "20px",
},
},
},
MuiAccordion: {
styleOverrides: {
root: {
"&$expanded": {
// remove the additional margin rule when expanded so the original margin is used.
margin: null,
},
},
},
},
MuiTypography: {
styleOverrides: {
root: {
colorPrimary: {
color: NAVY,
},
colorSecondary: {
color: GRAY,
},
},
},
},
},
});

const useTheme = () => {
return useMuiTheme() as ClutchTheme;
};
import { ThemeProvider } from "../Theme";
import type { ClutchColors } from "../Theme/types";

interface ThemeProps {
// disabling temporarily as we figure out theming
// eslint-disable-next-line react/no-unused-prop-types
variant?: "light";
declare module "@mui/material/styles" {
interface Theme {
colors: ClutchColors;
}
interface ThemeOptions {
colors?: ClutchColors;
}
}

const Theme: React.FC<ThemeProps> = ({ children }) => {
const theme = lightTheme;
const Theme: React.FC = ({ children }) => {
// Uncomment to use dark mode
/* // Detect system color mode
const prefersDarkMode =
window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; */
const prefersDarkMode = false;
return (
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<EmotionThemeProvider theme={theme}>
<CssBaseline />
<StylesProvider>{children}</StylesProvider>
</EmotionThemeProvider>
<ThemeProvider variant={prefersDarkMode ? "dark" : "light"}>
<CssBaseline />
<StylesProvider>{children}</StylesProvider>
</ThemeProvider>
</StyledEngineProvider>
);
};

export { Theme, useTheme };
export default Theme;
3 changes: 0 additions & 3 deletions frontend/packages/core/src/Theme/colors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ export const STATE_OPACITY: { [key in ComponentState]: number } = {
const clutchColors = (variant: ThemeVariant) => {
const colors = variant === "light" ? LIGHT_COLORS : DARK_COLORS;
return {
typography: {},
stroke: {},
background: {},
...colors,
};
};
Expand Down
20 changes: 4 additions & 16 deletions frontend/packages/core/src/Theme/palette.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PaletteOptions as MuiPaletteOptions } from "@mui/material/styles";
import { alpha, TypeText } from "@mui/material/styles";

import { DARK_COLORS, LIGHT_COLORS, STATE_OPACITY } from "./colors";
import { DARK_COLORS, LIGHT_COLORS } from "./colors";
import type { ClutchColors, ThemeVariant } from "./types";

interface PaletteOptions extends MuiPaletteOptions {
Expand All @@ -25,11 +25,11 @@ const darkText: Partial<TypeText> = {
const palette = (variant: ThemeVariant): PaletteOptions => {
const isLightMode = variant === "light";
const color = (isLightMode ? LIGHT_COLORS : DARK_COLORS) as ClutchColors;
const inverseColor = (isLightMode ? DARK_COLORS : LIGHT_COLORS) as ClutchColors;

// TODO: add all clutch colors to "common colors"
return {
type: variant,
mode: variant,
primary: color.blue,
secondary: color.neutral,
error: color.red,
Expand All @@ -38,22 +38,10 @@ const palette = (variant: ThemeVariant): PaletteOptions => {
success: color.green,
grey: color.neutral,
background: {
default: inverseColor.neutral[900],
// secondary
default: color.blue[50],
paper: isLightMode ? color.neutral.A100 : "#1c1e3c",
},
text: isLightMode ? lightText : darkText,
action: {
active: color.blue[600],
activatedOpacity: STATE_OPACITY.pressed,
hover: color.blue[600],
hoverOpacity: STATE_OPACITY.hover,
selected: color.blue[600],
selectedOpacity: STATE_OPACITY.selected,
focus: color.blue[600],
focusOpacity: STATE_OPACITY.focused,
disabled: color.neutral[900],
disabledOpacity: STATE_OPACITY.disabled,
},
};
};

Expand Down
52 changes: 31 additions & 21 deletions frontend/packages/core/src/Theme/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from "react";
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
import type { Theme as MuiTheme } from "@mui/material";
import {
adaptV4Theme,
createTheme as createMuiTheme,
CssBaseline,
StyledEngineProvider,
Expand All @@ -20,23 +18,22 @@ declare module "@mui/styles/defaultTheme" {

// Create a Material UI theme is propagated to all children.
const createTheme = (variant: ThemeVariant): MuiTheme => {
return createMuiTheme(
adaptV4Theme({
// inject in custom colors
...clutchColors(variant),
palette: palette(variant),
transitions: {
// https://material-ui.com/getting-started/faq/#how-can-i-disable-transitions-globally
create: () => "none",
},
props: {
MuiButtonBase: {
return createMuiTheme({
colors: clutchColors(variant),
palette: palette(variant),
transitions: {
// https://material-ui.com/getting-started/faq/#how-can-i-disable-transitions-globally
create: () => "none",
},
components: {
MuiButtonBase: {
defaultProps: {
// https://material-ui.com/getting-started/faq/#how-can-i-disable-the-ripple-effect-globally
disableRipple: true,
},
},
overrides: {
MuiAccordion: {
MuiAccordion: {
styleOverrides: {
root: {
"&$expanded": {
// remove the additional margin rule when expanded so the original margin is used.
Expand All @@ -45,8 +42,23 @@ const createTheme = (variant: ThemeVariant): MuiTheme => {
},
},
},
})
);
MuiCssBaseline: {
styleOverrides: {
body: {
fontSize: "0.875rem",
},
},
},
MuiSelect: {
styleOverrides: {
select: {
fontSize: "0.875rem",
height: "20px",
},
},
},
},
});
};

interface ThemeProps {
Expand All @@ -57,10 +69,8 @@ interface ThemeProps {
const ThemeProvider = ({ children, variant = "light" }: ThemeProps) => (
<StyledEngineProvider injectFirst>
<MuiThemeProvider theme={createTheme(variant)}>
<EmotionThemeProvider theme={createTheme(variant)}>
<CssBaseline />
<StylesProvider injectFirst>{children}</StylesProvider>
</EmotionThemeProvider>
<CssBaseline />
<StylesProvider injectFirst>{children}</StylesProvider>
</MuiThemeProvider>
</StyledEngineProvider>
);
Expand Down
1 change: 0 additions & 1 deletion frontend/packages/core/src/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useAppContext } from "./Contexts";
import { useNavigate } from "./navigation";

const StyledLanding = styled.div({
backgroundColor: "#f9f9fe",
display: "flex",
flexDirection: "column",
flexGrow: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`renders correctly 1`] = `
<DocumentFragment>
<div
class="css-1j9gnva"
class="css-wwjiyw"
id="landing"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`renders correctly 1`] = `
class="MuiGrid-root MuiGrid-item css-13i4rnv-MuiGrid-root"
>
<h3
class="MuiTypography-root MuiTypography-h3 MuiTypography-alignCenter css-x6fgw-MuiTypography-root"
class="MuiTypography-root MuiTypography-h3 MuiTypography-alignCenter css-1gpd3y6-MuiTypography-root"
>
<div
class="MuiGrid-root MuiGrid-item css-13i4rnv-MuiGrid-root"
Expand All @@ -39,7 +39,7 @@ exports[`renders correctly 1`] = `
</div>
</h3>
<h6
class="MuiTypography-root MuiTypography-h6 MuiTypography-alignCenter css-1n1umxm-MuiTypography-root"
class="MuiTypography-root MuiTypography-h6 MuiTypography-alignCenter css-1yp68kf-MuiTypography-root"
>
&lt; 404 Not Found &gt;
</h6>
Expand Down
Loading