Skip to content

Commit aa3d00c

Browse files
authored
Merge pull request #1138 from layer5io/branded-theme
Make theme Brandable and customizable
2 parents d954a95 + 7fd9bdb commit aa3d00c

File tree

5 files changed

+461
-43
lines changed

5 files changed

+461
-43
lines changed

src/custom/Modal/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const FullscreenExitButton = styled(FullScreenExitIcon)(({ theme }) => ({
7474
}));
7575

7676
export const ModalStyledHeader = styled('div')(({ theme }) => ({
77-
background: theme.palette.mode === 'light' ? lightModalGradient.header : darkModalGradient.header,
77+
background: theme.palette.surface.tint,
7878
color: '#eee',
7979
display: 'flex',
8080
justifyContent: 'space-between',
@@ -119,7 +119,7 @@ export const useModal = ({ headerIcon }: { headerIcon: React.ReactNode }): UseMo
119119

120120
export const ModalBody = styled(Paper)(({ theme }) => ({
121121
padding: '1rem',
122-
backgroundColor: theme.palette.background.surfaces,
122+
backgroundColor: theme.palette.surface.primary,
123123
overflowY: 'auto',
124124
height: '100%',
125125
scrollbarWidth: 'none',
@@ -134,9 +134,7 @@ const StyledFooter = styled('div', {
134134
})<ModalFooterProps>(({ theme, variant, hasHelpText }) => ({
135135
background:
136136
variant === 'filled'
137-
? theme.palette.mode === 'light'
138-
? lightModalGradient.fotter
139-
: darkModalGradient.fotter
137+
? (theme.palette.surface.tint)
140138
: 'transparent',
141139
display: 'flex',
142140
alignItems: 'center',

src/theme/ThemeProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EmotionCache } from '@emotion/react';
2-
import { CssBaseline, Interactiveness, PaletteMode, Theme, ThemeProvider } from '@mui/material';
2+
import { CssBaseline, PaletteMode, Theme, ThemeProvider } from '@mui/material';
33
import React from 'react';
4-
import { createCustomTheme } from './theme';
4+
import { createCustomTheme,PrimitivePalette } from './theme';
55

66
interface SistentProviderContextType {
77
emotionCache?: EmotionCache;
@@ -13,7 +13,7 @@ export interface SistentThemeProviderProps {
1313
children: React.ReactNode;
1414
emotionCache?: EmotionCache;
1515
initialMode?: PaletteMode;
16-
customTheme?: Interactiveness;
16+
customTheme?: PrimitivePalette;
1717
}
1818

1919
function SistentThemeProvider({
@@ -23,7 +23,7 @@ function SistentThemeProvider({
2323
customTheme
2424
}: SistentThemeProviderProps): JSX.Element {
2525
const theme = React.useMemo<Theme>(
26-
() => createCustomTheme(initialMode, customTheme),
26+
() => createCustomTheme(initialMode, customTheme ),
2727
[initialMode, customTheme]
2828
);
2929
return (

src/theme/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from '@mui/material';
1212
export { darkModePalette, lightModePalette } from './palette';
1313
export { typography } from './typography';
14-
14+
export {type PrimitivePalette} from "./theme";
1515
export * from './colors';
1616
export {
1717
default as SistentThemeProvider,

src/theme/palette.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ declare module '@mui/material/styles' {
4747
error?: Interactiveness;
4848
code?: string;
4949
surfaces?: string;
50+
51+
appNavigationBar?: string;
52+
secondaryAppNavigationBar?: string;
5053
}
5154

5255
// Defines the extended text color options used in the palette.
@@ -141,6 +144,9 @@ declare module '@mui/material/styles' {
141144
To define any additional custom color options, you can extend the interface here.
142145
*/
143146
interface Palette {
147+
surface: SurfaceTokens;
148+
interactive: InteractiveTokens;
149+
navigation: NavigationTokens;
144150
border: {
145151
default: string;
146152
strong: string;
@@ -164,9 +170,74 @@ declare module '@mui/material/styles' {
164170
};
165171
};
166172
}
173+
174+
// surface tokens need to have enough contrast
175+
// with text and interactive elements
176+
type SurfaceTokens = {
177+
178+
/** main page background, content containers (pure bg color) */
179+
primary: string;
180+
181+
/** secondary surfaces (slightly darker bg) */
182+
secondary: string;
183+
184+
/** tertiary surfaces (even darker bg) */
185+
tertiary: string;
186+
187+
/** floating elements with depth (bg + shadow) */
188+
elevated: string;
189+
190+
/** modal backdrops (semi-transparent bg) */
191+
overlay: string;
192+
193+
/** highlight surfaces (eg. modal headers , tabs, ) */
194+
tint: string;
195+
196+
/** high contrast alternative (fg as bg) */
197+
inverse: string;
198+
}
199+
200+
type InteractiveTokens = {
201+
/** default interactive elements (primary color) */
202+
primary: string;
203+
204+
/** hover state for interactive elements (primary hover tint) */
205+
hover: string;
206+
207+
/** disabled state for interactive elements (primary disabled tint) */
208+
disabled?: string;
209+
210+
/** pressed state for interactive elements (primary pressed tint) */
211+
pressed: string;
212+
213+
/** secondary interactive elements (secondary color) */
214+
secondary: string;
215+
216+
/** tertiary interactive elements (tertiary color) */
217+
tertiary: string;
218+
};
219+
220+
type NavigationTokens = {
221+
/** main navigation bar background */
222+
primary: string;
223+
224+
/** secondary navigation bar background */
225+
secondary: string;
226+
227+
/** active navigation item background */
228+
active: string;
229+
230+
/** hover state for navigation items */
231+
hover: string;
232+
};
167233

168234
// Defines the options available for the palette.
169235
interface PaletteOptions {
236+
237+
surface: SurfaceTokens;
238+
interactive: InteractiveTokens;
239+
navigation: NavigationTokens;
240+
170241
border: {
171242
default: string;
172243
strong: string;
@@ -177,8 +248,11 @@ declare module '@mui/material/styles' {
177248
alt: string;
178249
};
179250
};
251+
180252
icon: {
181253
default: string;
254+
dualTone?: string; // For icons with two colors
255+
dualToneInverse?: string; // For icons with two colors in inverse mode (eg on primary colored bg)
182256
secondary: string;
183257
brand: string;
184258
inverse: string;
@@ -192,7 +266,38 @@ declare module '@mui/material/styles' {
192266
}
193267
}
194268

269+
export type ThemePalette = PaletteOptions
270+
271+
272+
195273
export const lightModePalette: PaletteOptions = {
274+
275+
surface: {
276+
primary: Colors.charcoal[100],
277+
secondary: Colors.charcoal[90],
278+
tertiary: Colors.charcoal[80],
279+
elevated: Colors.WHITE,
280+
overlay: alpha(Colors.charcoal[90], 0.8),
281+
inverse: Colors.charcoal[10],
282+
tint: `linear-gradient(90deg, ${Colors.TEAL_BLUE} 0%, ${Colors.DARK_TEAL} 100%)`
283+
} ,
284+
285+
interactive: {
286+
primary: Colors.KEPPEL,
287+
hover: Colors.keppel[50],
288+
disabled: Colors.charcoal[90],
289+
pressed: Colors.keppel[60],
290+
secondary: Colors.keppel[40],
291+
tertiary: Colors.keppel[70]
292+
},
293+
294+
navigation: {
295+
primary: "#252e31",
296+
secondary: "#294957",
297+
active: Colors.KEPPEL,
298+
hover: Colors.keppel[50]
299+
},
300+
196301
primary: {
197302
main: Colors.KEPPEL
198303
},
@@ -305,6 +410,8 @@ export const lightModePalette: PaletteOptions = {
305410
},
306411
icon: {
307412
default: Colors.accentGrey[10],
413+
dualTone: Colors.KEPPEL,
414+
dualToneInverse: Colors.charcoal[10],
308415
secondary: Colors.charcoal[40],
309416
brand: Colors.keppel[40],
310417
inverse: Colors.charcoal[100],
@@ -318,6 +425,32 @@ export const lightModePalette: PaletteOptions = {
318425
};
319426

320427
export const darkModePalette: PaletteOptions = {
428+
429+
surface: {
430+
primary: Colors.charcoal[10],
431+
secondary: Colors.charcoal[20],
432+
tertiary: Colors.charcoal[30],
433+
elevated: Colors.charcoal[40],
434+
overlay: alpha(Colors.charcoal[20], 0.8),
435+
inverse: Colors.WHITE,
436+
tint: `linear-gradient(90deg, ${Colors.charcoal[30]} 0%, ${Colors.accentGrey[30]} 100%)`,
437+
},
438+
interactive: {
439+
primary: Colors.KEPPEL,
440+
hover: Colors.keppel[50],
441+
disabled: Colors.charcoal[30],
442+
pressed: Colors.keppel[60],
443+
secondary: Colors.keppel[20],
444+
tertiary: Colors.keppel[10]
445+
},
446+
447+
navigation: {
448+
primary: Colors.charcoal[10],
449+
secondary: Colors.charcoal[20],
450+
active: Colors.KEPPEL,
451+
hover: Colors.keppel[50]
452+
},
453+
321454
primary: {
322455
main: Colors.KEPPEL
323456
},
@@ -430,6 +563,8 @@ export const darkModePalette: PaletteOptions = {
430563
icon: {
431564
default: Colors.charcoal[80],
432565
secondary: Colors.charcoal[70],
566+
dualTone: Colors.KEPPEL,
567+
dualToneInverse: Colors.charcoal[100],
433568
brand: Colors.keppel[40],
434569
inverse: Colors.charcoal[10],
435570
weather: Colors.saffron[40],

0 commit comments

Comments
 (0)