e52fe65985
* Add identicons package * Tidy up styling and move methods into component directories with better naming * Add mixnode status colours to theme * Mixnode status and icon components * Add status to mixnode types * Add API method to get mixnode details * Add mixnode details to state * Add status and name+description section to mixnode detail page * Wrap with div instead of p * Limit width of description and link to new tab * Limit length of link button and truncate with elipsis * Replace `filter` with `find` * Move mix node detail components to a location that is better named * Refactor mixnode detail state and separate into an independent context from main state. This prevents the mixnode detail page from showing stale data when switching between mix nodes. * Tidy up mixnode detail page adding new state provider and a guard component to handle loading, error and not found states * Layout changes to mixnode description header section * Add methods to Explorer API client to get a mixnode by id, active set by status and overview summary * Add color prop to StatsCard and make count optional * Add optional start and end children to TableToolbar * Tidy up naming * Add summary overview and getting mixnodes by active set status to main state * Add mix node status overview cards * Add mix node status to routes * Mixnode list has a dropdown component to select the active set status * Clean up caching code * Add resource to get a single mixnode by id * Add API resources to get `active`, `inactive` and `standby` mixnodes * Add mixnode summary to API * Add overview summary endpoint to API * Fix OpenAPI/swagger base url * Make clippy happy * Add method to get validators * Add methods to get active and rewarded mixnodes * Fix naming * Move client creation to crate root * Move cache to module * Delete unused files * Add validators API resource * Add gateways API resource * Move tasks to crate root * Add new HTTP resources for validators and gateways to routes * Tidy up naming and locations for mixnodes * Add validator and gateways to state, and tidy up naming * Add gateways and validator modules to main * Overview shows validator and gateway summaries from state * Bundle variable weight Open Sans fonts * Fix up font weights and sizes * Fix up typing * Fix up social icons * Fix navbar colour * Fix paper colour in dark mode and border radius * Fix up stats card * Tidy up Nym icons * Fix up overview * Fix up spacing and padding for overview * Add light mode shades that are darker for mixnode status values * Review feedback
282 lines
6.0 KiB
TypeScript
282 lines
6.0 KiB
TypeScript
import { PaletteMode } from '@mui/material';
|
|
import {
|
|
PaletteOptions,
|
|
NymPalette,
|
|
NetworkExplorerPalette,
|
|
ThemeOptions,
|
|
createTheme,
|
|
NymPaletteVariant,
|
|
} from '@mui/material/styles';
|
|
|
|
//-----------------------------------------------------------------------------------------------
|
|
// Nym palette type definitions
|
|
//
|
|
|
|
/**
|
|
* The Nym palette.
|
|
*
|
|
* IMPORTANT: do not export this constant, always use the MUI `useTheme` hook to get the correct
|
|
* colours for dark/light mode.
|
|
*/
|
|
const nymPalette: NymPalette = {
|
|
/** emphasises important elements */
|
|
highlight: '#FB6E4E',
|
|
text: {
|
|
nav: '#F2F2F2',
|
|
/** footer text colour */
|
|
footer: '#666B77',
|
|
},
|
|
};
|
|
|
|
const darkMode: NymPaletteVariant = {
|
|
mode: 'dark',
|
|
background: {
|
|
main: '#111826',
|
|
paper: '#242C3D',
|
|
},
|
|
text: {
|
|
main: '#F2F2F2',
|
|
},
|
|
topNav: {
|
|
background: '#111826',
|
|
},
|
|
nav: {
|
|
background: '#242C3D',
|
|
hover: '#111826',
|
|
},
|
|
mixnodes: {
|
|
status: {
|
|
active: '#20D073',
|
|
standby: '#5FD7EF',
|
|
},
|
|
},
|
|
};
|
|
|
|
const lightMode: NymPaletteVariant = {
|
|
mode: 'light',
|
|
background: {
|
|
main: '#F2F2F2',
|
|
paper: '#FFFFFF',
|
|
},
|
|
text: {
|
|
main: '#666666',
|
|
},
|
|
topNav: {
|
|
background: '#111826',
|
|
},
|
|
nav: {
|
|
background: '#242C3D',
|
|
hover: '#111826',
|
|
},
|
|
mixnodes: {
|
|
status: {
|
|
active: '#1CBB67',
|
|
standby: '#55C1D7',
|
|
},
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Nym palette specific to the Network Explorer
|
|
*
|
|
* IMPORTANT: do not export this constant, always use the MUI `useTheme` hook to get the correct
|
|
* colours for dark/light mode.
|
|
*/
|
|
const networkExplorerPalette = (
|
|
variant: NymPaletteVariant,
|
|
): NetworkExplorerPalette => ({
|
|
networkExplorer: {
|
|
/** world map styles */
|
|
map: {
|
|
stroke: '#333333',
|
|
fills: ['#EFEFEF', '#FBE7E1', '#F7D1C6', '#F09379'],
|
|
},
|
|
background: {
|
|
tertiary: variant.mode === 'light' ? '#F4F8FA' : '#323C51',
|
|
},
|
|
/** left nav styles */
|
|
nav: {
|
|
selected: {
|
|
main: '#111826',
|
|
nested: '#3C4558',
|
|
},
|
|
background: variant.nav.background,
|
|
hover: variant.nav.hover,
|
|
text: nymPalette.text.nav,
|
|
},
|
|
topNav: {
|
|
...variant.topNav,
|
|
appBar: '#080715',
|
|
socialIcons: '#F2F2F2',
|
|
},
|
|
footer: {
|
|
socialIcons:
|
|
variant.mode === 'light' ? nymPalette.text.footer : darkMode.text.main,
|
|
},
|
|
mixnodes: {
|
|
status: {
|
|
active: variant.mixnodes.status.active,
|
|
standby: variant.mixnodes.status.standby,
|
|
inactive: variant.text.main,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
//-----------------------------------------------------------------------------------------------
|
|
// Nym palettes for light and dark mode
|
|
//
|
|
|
|
/**
|
|
* Map a Nym palette variant onto the MUI palette
|
|
*/
|
|
const variantToMUIPalette = (variant: NymPaletteVariant): PaletteOptions => ({
|
|
text: {
|
|
primary: variant.text.main,
|
|
},
|
|
primary: {
|
|
main: nymPalette.highlight,
|
|
contrastText: '#fff',
|
|
},
|
|
background: {
|
|
default: variant.background.main,
|
|
paper: variant.background.paper,
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Returns the Network Explorer palette for light mode.
|
|
*/
|
|
const createLightModePalette = (): PaletteOptions => ({
|
|
nym: {
|
|
...nymPalette,
|
|
...networkExplorerPalette(lightMode),
|
|
},
|
|
...variantToMUIPalette(lightMode),
|
|
});
|
|
|
|
/**
|
|
* Returns the Network Explorer palette for dark mode.
|
|
*/
|
|
const createDarkModePalette = (): PaletteOptions => ({
|
|
nym: {
|
|
...nymPalette,
|
|
...networkExplorerPalette(darkMode),
|
|
},
|
|
...variantToMUIPalette(darkMode),
|
|
});
|
|
|
|
/**
|
|
* IMPORTANT: if you need to get the default MUI theme, use the following
|
|
*
|
|
* import { createTheme as systemCreateTheme } from '@mui/system';
|
|
*
|
|
* // get the MUI system defaults for light mode
|
|
* const systemTheme = systemCreateTheme({ palette: { mode: 'light' } });
|
|
*
|
|
*
|
|
* return {
|
|
* // change `primary` to default MUI `success`
|
|
* primary: {
|
|
* main: systemTheme.palette.success.main,
|
|
* },
|
|
* nym: {
|
|
* ...nymPalette,
|
|
* ...networkExplorerPalette,
|
|
* },
|
|
* };
|
|
*/
|
|
|
|
//-----------------------------------------------------------------------------------------------
|
|
// Nym theme overrides
|
|
//
|
|
|
|
/**
|
|
* Gets the theme options to be passed to `createTheme`.
|
|
*
|
|
* Based on pattern from https://mui.com/customization/dark-mode/#dark-mode-with-custom-palette.
|
|
*
|
|
* @param mode The theme mode: 'light' or 'dark'
|
|
*/
|
|
export const getDesignTokens = (mode: PaletteMode): ThemeOptions => {
|
|
// first, create the palette from user's choice of light or dark mode
|
|
const { palette } = createTheme({
|
|
palette: {
|
|
mode,
|
|
...(mode === 'light'
|
|
? createLightModePalette()
|
|
: createDarkModePalette()),
|
|
},
|
|
});
|
|
|
|
// then customise theme and components
|
|
return {
|
|
typography: {
|
|
fontFamily: [
|
|
'Open Sans',
|
|
'sans-serif',
|
|
'BlinkMacSystemFont',
|
|
'Roboto',
|
|
'Oxygen',
|
|
'Ubuntu',
|
|
'Helvetica Neue',
|
|
].join(','),
|
|
fontSize: 14,
|
|
fontWeightRegular: 400,
|
|
},
|
|
transitions: {
|
|
duration: {
|
|
shortest: 150,
|
|
shorter: 200,
|
|
short: 250,
|
|
standard: 300,
|
|
complex: 375,
|
|
enteringScreen: 225,
|
|
leavingScreen: 195,
|
|
},
|
|
easing: {
|
|
easeIn: 'cubic-bezier(0.4, 0, 1, 1)',
|
|
},
|
|
},
|
|
components: {
|
|
MuiCardHeader: {
|
|
styleOverrides: {
|
|
title: {
|
|
fontSize: 16,
|
|
fontWeight: 600,
|
|
},
|
|
},
|
|
},
|
|
MuiDrawer: {
|
|
styleOverrides: {
|
|
paper: {
|
|
background: palette.secondary.dark,
|
|
marginTop: 64,
|
|
},
|
|
},
|
|
},
|
|
MuiListItem: {
|
|
styleOverrides: {
|
|
root: {
|
|
background: palette.secondary.dark,
|
|
},
|
|
},
|
|
},
|
|
MuiPaper: {
|
|
styleOverrides: {
|
|
root: {
|
|
borderRadius: '10px',
|
|
},
|
|
elevation1: {
|
|
backgroundImage: mode === 'dark' ? 'none' : undefined,
|
|
},
|
|
elevation2: {
|
|
backgroundImage: mode === 'dark' ? 'none' : undefined,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
palette,
|
|
};
|
|
};
|