Skip to content

Commit

Permalink
feat(components): Export ThemeProvider
Browse files Browse the repository at this point in the history
fix #368

Signed-off-by: Antonette Caldwell <[email protected]>
  • Loading branch information
nebula-aac committed Dec 13, 2023
1 parent c27345f commit 4c6864b
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { ConditionalTooltip } from './tooltip-for-desc';
import ConditionalTooltip from './tooltip-for-desc';
export { ConditionalTooltip };
8 changes: 7 additions & 1 deletion packages/components/src/custom/TooltipIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ interface TooltipIconProps {
style?: React.CSSProperties;
}

export function TooltipIcon({ title, onClick, icon, style, arrow = false }: TooltipIconProps) {
export function TooltipIcon({
title,
onClick,
icon,
style,
arrow = false
}: TooltipIconProps): JSX.Element {
return (
<Tooltip title={title} arrow={arrow}>
<IconButton
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ export {
type FilterColumn,
type UniversalFilterProps
} from './custom/UniversalFilter';
export { default as SistentProvider } from './theme/SistentProvider';
12 changes: 7 additions & 5 deletions packages/components/src/patches/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export interface ChildrenPropType<T> {
export const Tooltip = React.forwardRef<
HTMLDivElement,
TooltipProps & ChildrenPropType<React.ReactNode>
>((props, ref) => (
<MuiTooltip {...props} ref={ref}>
<span>{props.children}</span>
</MuiTooltip>
));
>(
(props, ref): JSX.Element => (
<MuiTooltip {...props} ref={ref}>
<span>{props.children}</span>
</MuiTooltip>
)
);

export default Tooltip;
35 changes: 35 additions & 0 deletions packages/components/src/theme/SistentProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { CacheProvider, EmotionCache } from '@emotion/react';
import { CssBaseline, PaletteMode, Theme, ThemeProvider } from '@mui/material';
import React from 'react';
import createEmotionCache from './createEmotionCache';
import { createCustomTheme } from './theme';

const clientSideEmotionCache = createEmotionCache();

interface SistentProviderProps {
children: React.ReactNode;
emotionCache?: EmotionCache;
}

function SistentProvider({
children,
emotionCache = clientSideEmotionCache
}: SistentProviderProps): JSX.Element {
const initialMode = 'light';
const [mode] = React.useState<PaletteMode>(initialMode);

const theme = React.useMemo<Theme>(() => createCustomTheme(mode), [mode]);

return (
<CacheProvider value={emotionCache}>
<ThemeProvider theme={theme}>
<CssBaseline />
{children}
</ThemeProvider>
</CacheProvider>
);
}

export default SistentProvider;

export { SistentProvider };
10 changes: 10 additions & 0 deletions packages/components/src/theme/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Components, Theme } from '@mui/material';
import { MuiAppBar } from './components/appbar.modifiter';
import { MuiDrawer } from './components/drawer.modifier';
import { MuiSvgIcon } from './components/svgicon.modifier';

export const components: Components<Theme> = {
MuiAppBar,
MuiDrawer,
MuiSvgIcon
};
20 changes: 20 additions & 0 deletions packages/components/src/theme/components/appbar.modifiter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Components, Theme } from '@mui/material';
import { drawerWidth } from '../theme';

export const MuiAppBar: Components<Theme>['MuiAppBar'] = {
styleOverrides: {
root: ({ theme }) => {
const {
palette: {
primary: { main }
}
} = theme;
return {
width: `calc(100% - ${drawerWidth}px)`,
ml: { sm: `${drawerWidth}px` },
elevation: 2,
background: main
};
}
}
};
22 changes: 22 additions & 0 deletions packages/components/src/theme/components/drawer.modifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Components, Theme } from '@mui/material';
import { drawerWidth } from '../theme';

export const MuiDrawer: Components<Theme>['MuiDrawer'] = {
styleOverrides: {
root: ({ theme }) => {
const {
palette: {
primary: { main }
}
} = theme;
return {
width: drawerWidth,
'& .MuiDrawer-paper': {
width: drawerWidth,
boxSize: 'border-box',
background: main
}
};
}
}
};
10 changes: 10 additions & 0 deletions packages/components/src/theme/components/svgicon.modifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Components, Theme } from '@mui/material';

export const MuiSvgIcon: Components<Theme>['MuiSvgIcon'] = {
styleOverrides: {
root: {
height: 24,
width: 24
}
}
};
7 changes: 7 additions & 0 deletions packages/components/src/theme/createEmotionCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import createCache from '@emotion/cache';

// prepend: true moves MUI styles to the top of the <head> so they're loaded first.
// It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
export default function createEmotionCache() {
return createCache({ key: 'css', prepend: true });
}
35 changes: 35 additions & 0 deletions packages/components/src/theme/palette.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PaletteOptions } from '@mui/material';
import { blueGrey } from '@mui/material/colors';

declare module '@mui/material/styles' {
interface PaletteColor {
darker?: string;
}
interface SimplePaletteColorOptions {
darker?: string;
}
interface Palette {
neutral?: Palette['primary'];
}
interface PaletteOptions {
neutral?: PaletteOptions['primary'];
}
}

export const lightModePalette: PaletteOptions = {
primary: {
main: blueGrey[600],
light: blueGrey[400],
dark: blueGrey[700]
},
secondary: {
main: '#EE5351'
},
neutral: {}
};

export const darkModePalette: PaletteOptions = {
primary: {},
secondary: {},
neutral: {}
};
43 changes: 43 additions & 0 deletions packages/components/src/theme/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { PaletteMode, createTheme } from '@mui/material';
import { components } from './components';
import { darkModePalette, lightModePalette } from './palette';
import { typography } from './typography';

export const drawerWidth = 240;

export const createCustomTheme = (paletteType: PaletteMode) => {
const palette = paletteType === 'light' ? lightModePalette : darkModePalette;

const theme = createTheme({
palette,
components,
typography: typography(paletteType),
breakpoints: {}
});

return theme;
};

/*
const commonPalette = {
palette: {
paletteType,
...(paletteType === 'light' ? lightModePalette : darkModePalette)
}
};
const palette =
paletteType === 'dark'
? {
mode: 'dark',
...commonPalette,
text: {
main: '#FFFFFF'
}
}
: {
mode: 'light',
...commonPalette
};
*/
16 changes: 16 additions & 0 deletions packages/components/src/theme/typography.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PaletteMode } from '@mui/material';
import { TypographyOptions } from '@mui/material/styles/createTypography';

export const typography = (paletteType: PaletteMode): TypographyOptions => {
return {
// fontFamily: QanelasSoftFont.style.fontFamily,
// body1: { fontFamily: QanelasSoftFont.style.fontFamily },
// body2: { fontFamily: QanelasSoftFont.style.fontFamily },
h5: {
color: paletteType === 'light' ? '#000000' : '#FFFFFF'
},
h6: {
color: paletteType === 'light' ? '#000000' : '#FFFFFF'
}
};
};
Loading

0 comments on commit 4c6864b

Please sign in to comment.