feat: apply conditional mation styling

This commit is contained in:
Ali BARIN
2023-12-14 14:28:07 +00:00
parent f8c30c8526
commit 78ba18b176
5 changed files with 50 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ import styled from '@emotion/styled';
export const LogoImage = styled('img')(() => ({ export const LogoImage = styled('img')(() => ({
maxWidth: 200, maxWidth: 200,
maxHeight: 50, maxHeight: 22,
width: '100%', width: '100%',
height: 'auto', height: 'auto',
})); }));

View File

@@ -7,19 +7,20 @@ import * as React from 'react';
import { IJSONObject } from '@automatisch/types'; import { IJSONObject } from '@automatisch/types';
import useConfig from 'hooks/useConfig'; import useConfig from 'hooks/useConfig';
import theme from 'styles/theme'; import useAutomatischInfo from 'hooks/useAutomatischInfo';
import { defaultTheme, mationTheme } from 'styles/theme';
type ThemeProviderProps = { type ThemeProviderProps = {
children: React.ReactNode; children: React.ReactNode;
}; };
const customizeTheme = (defaultTheme: typeof theme, config: IJSONObject) => { const customizeTheme = (theme: typeof defaultTheme, config: IJSONObject) => {
// `clone` is needed so that the new theme reference triggers re-render // `clone` is needed so that the new theme reference triggers re-render
const shallowDefaultTheme = clone(defaultTheme); const shallowDefaultTheme = clone(theme);
for (const key in config) { for (const key in config) {
const value = config[key]; const value = config[key];
const exists = get(defaultTheme, key); const exists = get(theme, key);
if (exists) { if (exists) {
set(shallowDefaultTheme, key, value); set(shallowDefaultTheme, key, value);
@@ -33,18 +34,21 @@ const ThemeProvider = ({
children, children,
...props ...props
}: ThemeProviderProps): React.ReactElement => { }: ThemeProviderProps): React.ReactElement => {
const { config, loading } = useConfig(); const { isMation, loading: automatischInfoLoading } = useAutomatischInfo();
const { config, loading: configLoading } = useConfig();
const customTheme = React.useMemo(() => { const customTheme = React.useMemo(() => {
if (!config) return theme; const installationTheme = isMation ? mationTheme : defaultTheme;
const customTheme = customizeTheme(theme, config); if (configLoading || automatischInfoLoading) return installationTheme;
const customTheme = customizeTheme(installationTheme, config || {});
return customTheme; return customTheme;
}, [config]); }, [configLoading, config, isMation, automatischInfoLoading]);
// TODO: maybe a global loading state for the custom theme? // TODO: maybe a global loading state for the custom theme?
if (loading) return <></>; if (automatischInfoLoading || configLoading) return <></>;
return ( return (
<BaseThemeProvider theme={customTheme} {...props}> <BaseThemeProvider theme={customTheme} {...props}>

View File

@@ -5,11 +5,15 @@ import { GET_AUTOMATISCH_INFO } from 'graphql/queries/get-automatisch-info';
export type AutomatischInfoContextParams = { export type AutomatischInfoContextParams = {
isCloud: boolean; isCloud: boolean;
isMation: boolean;
loading: boolean;
}; };
export const AutomatischInfoContext = export const AutomatischInfoContext =
React.createContext<AutomatischInfoContextParams>({ React.createContext<AutomatischInfoContextParams>({
isCloud: false, isCloud: false,
isMation: false,
loading: true,
}); });
type AutomatischInfoProviderProps = { type AutomatischInfoProviderProps = {
@@ -23,13 +27,15 @@ export const AutomatischInfoProvider = (
const { data, loading } = useQuery(GET_AUTOMATISCH_INFO); const { data, loading } = useQuery(GET_AUTOMATISCH_INFO);
const isCloud = data?.getAutomatischInfo?.isCloud; const isCloud = data?.getAutomatischInfo?.isCloud;
const isMation = data?.getAutomatischInfo?.isMation;
const value = React.useMemo(() => { const value = React.useMemo(() => {
return { return {
isCloud, isCloud,
loading isMation,
loading,
}; };
}, [isCloud, loading]); }, [isCloud, isMation, loading]);
return ( return (
<AutomatischInfoContext.Provider value={value}> <AutomatischInfoContext.Provider value={value}>

View File

@@ -3,6 +3,8 @@ import { AutomatischInfoContext } from 'contexts/AutomatischInfo';
type UseAutomatischInfoReturn = { type UseAutomatischInfoReturn = {
isCloud: boolean; isCloud: boolean;
isMation: boolean;
loading: boolean;
}; };
export default function useAutomatischInfo(): UseAutomatischInfoReturn { export default function useAutomatischInfo(): UseAutomatischInfoReturn {
@@ -10,5 +12,7 @@ export default function useAutomatischInfo(): UseAutomatischInfoReturn {
return { return {
isCloud: automatischInfoContext.isCloud, isCloud: automatischInfoContext.isCloud,
isMation: automatischInfoContext.isMation,
loading: automatischInfoContext.loading,
}; };
} }

View File

@@ -1,3 +1,5 @@
import { deepmerge } from '@mui/utils';
import type { Theme } from '@mui/material/styles';
import { createTheme, alpha } from '@mui/material/styles'; import { createTheme, alpha } from '@mui/material/styles';
import { cardActionAreaClasses } from '@mui/material/CardActionArea'; import { cardActionAreaClasses } from '@mui/material/CardActionArea';
@@ -6,7 +8,7 @@ export const primaryMainColor = '#0059F7';
export const primaryLightColor = '#4286FF'; export const primaryLightColor = '#4286FF';
export const primaryDarkColor = '#001F52'; export const primaryDarkColor = '#001F52';
const extendedTheme = createTheme({ export const defaultTheme = createTheme({
palette: { palette: {
primary: { primary: {
main: primaryMainColor, main: primaryMainColor,
@@ -280,4 +282,24 @@ const extendedTheme = createTheme({
}, },
}); });
export default extendedTheme; export const mationTheme = createTheme(deepmerge(defaultTheme, {
palette: {
primary: {
main: '#2962FF',
light: '#448AFF',
dark: '#2962FF',
contrastText: '#fff',
},
},
components: {
MuiAppBar: {
styleOverrides: {
root: ({ theme }: { theme: Theme }) => ({
zIndex: theme.zIndex.drawer + 1,
}),
},
},
},
}));
export default defaultTheme;