Skip to content

Commit fdd67dc

Browse files
feat: implemented material components provided and replaced it with theme container
1 parent 5734282 commit fdd67dc

File tree

5 files changed

+53
-39
lines changed

5 files changed

+53
-39
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, {createContext, type ReactNode} from 'react';
2+
3+
import type {Theme} from '../theme/theme.types';
4+
import {LightTheme} from '../theme/build-theme';
5+
import {materialTypography} from '../typography/typography.styles';
6+
import type {MaterialTypography} from '../typography/typography.types';
7+
8+
interface MaterialComponentsContextType {
9+
theme: Theme;
10+
typography: MaterialTypography;
11+
}
12+
13+
export const MaterialComponentsContext = createContext<MaterialComponentsContextType>({theme: LightTheme, typography: materialTypography});
14+
15+
export interface MaterialComponentsProviderProps {
16+
children: ReactNode;
17+
18+
theme?: Theme;
19+
typography?: MaterialTypography;
20+
}
21+
22+
export const MaterialComponentsProvider: React.FC<MaterialComponentsProviderProps> = ({
23+
children,
24+
theme = LightTheme,
25+
typography = materialTypography,
26+
}) => <MaterialComponentsContext.Provider value={{theme, typography}}>{children}</MaterialComponentsContext.Provider>;

src/theme/Theme.context.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/theme/build-theme.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {MaterialTheme} from './theme';
2+
import {getPalette} from './get-palette';
3+
import type {ThemeColors} from './theme.types';
4+
5+
export const defaultThemeColors: ThemeColors = {
6+
primary: '#6750A4',
7+
secondary: '#625B71',
8+
tertiary: '#7D5260',
9+
error: '#B3261E',
10+
neutral: '#605D64',
11+
neutralVariant: '#605D66',
12+
};
13+
14+
export const buildThemesFromColors = (themeColors: ThemeColors) => {
15+
const palette = getPalette(themeColors);
16+
17+
const lightTheme = MaterialTheme.generateLightTheme(palette);
18+
const darkTheme = MaterialTheme.generateDarkTheme(palette);
19+
20+
return {lightTheme, darkTheme};
21+
};
22+
23+
export const {lightTheme: LightTheme, darkTheme: DarkTheme} = buildThemesFromColors(defaultThemeColors);

src/theme/theme.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
import {getPalette} from './get-palette';
1+
import {type Theme} from './theme.types';
22
import {type Palette} from './palette.types';
3-
import {type Theme, type ThemeColors} from './theme.types';
43

5-
export const buildThemesFromColors = (themeColors: ThemeColors) => {
6-
const palette = getPalette(themeColors);
7-
8-
const lightTheme = MaterialTheme.generateLightTheme(palette);
9-
const darkTheme = MaterialTheme.generateDarkTheme(palette);
10-
11-
return {lightTheme, darkTheme};
12-
};
13-
14-
class MaterialTheme {
4+
export class MaterialTheme {
155
public static readonly generateLightTheme = (palette: Palette): Theme => ({
166
primary: {
177
background: palette.primary40,

src/theme/useTheme.hook.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {useContext} from 'react';
22

3-
import {ThemeContext} from './Theme.context';
3+
import {MaterialComponentsContext} from '../provider/MaterialComponents.context';
44

55
export const useTheme = () => {
6-
const theme = useContext(ThemeContext);
6+
const {theme} = useContext(MaterialComponentsContext);
77

88
return theme;
99
};

0 commit comments

Comments
 (0)