generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): Export ThemeProvider
fix #368 Signed-off-by: Antonette Caldwell <[email protected]>
- Loading branch information
1 parent
c27345f
commit 4c6864b
Showing
14 changed files
with
342 additions
and
113 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
packages/components/src/custom/Helpers/CondtionalTooltip/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
packages/components/src/theme/components/appbar.modifiter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
packages/components/src/theme/components/drawer.modifier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
packages/components/src/theme/components/svgicon.modifier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
}; | ||
}; |
Oops, something went wrong.