Skip to content

Commit

Permalink
Fix theme change bugs and update colour palette
Browse files Browse the repository at this point in the history
  • Loading branch information
Genne23v committed Nov 19, 2022
1 parent 82a0fda commit 009225d
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 74 deletions.
Binary file modified src/web/app/public/colorThemes/dark-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/web/app/public/colorThemes/dark-dim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/web/app/public/colorThemes/light-contrast.png
Binary file not shown.
Binary file modified src/web/app/public/colorThemes/light-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/web/app/src/components/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { lightTheme } from '../theme';

type ThemeContextType = {
theme: Theme;
preferredTheme: String | undefined;
preferredTheme: String;
changeTheme: (themeId: String) => void;
};

Expand Down
120 changes: 72 additions & 48 deletions src/web/app/src/components/ThemeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import {
IconButton,
Popover,
Typography,
Button,
Paper,
Tooltip,
Zoom,
Divider,
MenuList,
MenuItem,
ListItemText,
Radio,
} from '@material-ui/core';
import ColorLensIcon from '@mui/icons-material/ColorLens';
import { List, ListSubheader } from '@mui/material';
import PaletteIcon from '@mui/icons-material/Palette';
import { makeStyles, withStyles } from '@material-ui/core/styles';
import { useTheme } from './ThemeProvider';

const lightDefaultLogoUrl = '/colorThemes/light-default.png';
const darkDefaultLogoUrl = '/colorThemes/dark-default.png';
const lightContrastLogoUrl = '/colorThemes/light-contrast.png';
const lightContrastLogoUrl = '/colorThemes/light-high-contrast.png';
const darkDimLogoUrl = '/colorThemes/dark-dim.png';
const themes = [
{ title: 'Light Default', id: 'light-default', image: lightDefaultLogoUrl },
Expand All @@ -30,13 +29,30 @@ const themes = [
];

const useStyles = makeStyles((theme) => ({
changeThemeMenu: {
menuSubheader: {
color: theme.palette.text.primary,
backgroundColor: 'transparent',
},
popoverPaper: {
color: theme.palette.text.primary,
backgroundColor: theme.palette.background.paper,
},
themeSelectButton: {
'&:hover': {
color: theme.palette.action.active,
},
},
themeSelectorButton: {
color: theme.palette.primary.main,
'&:hover': {
backgroundColor: 'transparent',
color: theme.palette.text.primary,
},
},
selected: {
color: 'black',
backgroundColor: '#A9A9A9 !important',
},
}));

const ButtonTooltip = withStyles({
Expand Down Expand Up @@ -67,52 +83,60 @@ const ThemeSelector = () => {
const id = open ? 'simple-popover' : undefined;

return (
<ButtonTooltip title="Change Colour Theme" arrow placement="top" TransitionComponent={Zoom}>
<IconButton>
<Button id="test" aria-describedby={id} onClick={handleClick}>
<ColorLensIcon fontSize="large" className={classes.changeThemeMenu} />
</Button>
<div>
<ButtonTooltip
title="Change Colour Theme"
arrow
placement="top"
TransitionComponent={Zoom}
onClick={handleClick}
>
<IconButton className={classes.themeSelectorButton}>
<PaletteIcon fontSize="large" />
</IconButton>
</ButtonTooltip>

<Popover
id={id}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
PaperProps={{
style: { width: '200px' },
}}
>
<Paper>
<Popover
id={id}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
PaperProps={{
style: { width: '240px' },
}}
>
<Paper className={classes.popoverPaper}>
<List>
<ListSubheader className={classes.menuSubheader}>
<Typography variant="h6" gutterBottom>
Change Colour Theme
</Typography>
</ListSubheader>
<Divider />
<MenuList>
<MenuItem>
<Typography variant="h6">Change Colour Theme</Typography>
</MenuItem>
<Divider />
<MenuList>
{themes.map((theme) => {
return (
<MenuItem key={theme.id}>
<ListItemText>{theme.title}</ListItemText>
<img src={theme.image} alt={theme.title} />
<Radio
key={theme.id}
value={theme.title}
checked={preferredTheme === theme.id}
onClick={() => handleChange(theme.id)}
/>
</MenuItem>
);
})}
</MenuList>
{themes.map((theme) => {
return (
<MenuItem
key={theme.id}
onClick={() => handleChange(theme.id)}
selected={preferredTheme === theme.id}
className={classes.themeSelectButton}
classes={{ selected: classes.selected }}
>
<ListItemText>{theme.title}</ListItemText>
<img src={theme.image} className="palette-preview" alt={theme.title} />
</MenuItem>
);
})}
</MenuList>
</Paper>
</Popover>
</IconButton>
</ButtonTooltip>
</List>
</Paper>
</Popover>
</div>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/web/app/src/hooks/use-preferred-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useLocalStorage } from 'react-use';
* loads of the app, and initial logic to get the browser's preferred colour.
*/
export default function usePreferredTheme() {
const [preferredTheme, setPreferredTheme] = useLocalStorage<String | undefined>(
const [preferredTheme, setPreferredTheme] = useLocalStorage<String>(
'preference:theme',
'light-default'
);
Expand Down
2 changes: 2 additions & 0 deletions src/web/app/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const App = ({ Component, pageProps }: AppProps) => {
theme = darkDimTheme;
break;
default:
setPreferredTheme('light-default');
theme = lightTheme;
break;
}
Expand Down Expand Up @@ -59,6 +60,7 @@ const App = ({ Component, pageProps }: AppProps) => {
break;
default:
console.warn('no theme is selected');
themeId = 'light-default';
break;
}
setPreferredTheme(themeId);
Expand Down
21 changes: 12 additions & 9 deletions src/web/app/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import SEO from '../components/SEO';
import Banner from '../components/Banner';
import Posts from '../components/Posts';
import NavBar from '../components/NavBar';
import { StyledEngineProvider } from '@mui/material';

const Home = () => {
const [bannerVisible, setBannerVisibility] = useState(true);
return (
<>
<SEO pageTitle="Telescope" />
<Banner
onVisibilityChange={(visible) => setBannerVisibility(visible)}
bannerVisible={bannerVisible}
/>
<main className="main">
<NavBar disabled={bannerVisible} />
<Posts />
</main>
<StyledEngineProvider injectFirst>
<SEO pageTitle="Telescope" />
<Banner
onVisibilityChange={(visible) => setBannerVisibility(visible)}
bannerVisible={bannerVisible}
/>
<main className="main">
<NavBar disabled={bannerVisible} />
<Posts />
</main>
</StyledEngineProvider>
</>
);
};
Expand Down
4 changes: 0 additions & 4 deletions src/web/app/src/styles/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@
height: 1em;
}

#simple-popover {
width: 460px;
}

@media (max-width: 600px) {
.grid {
width: 100%;
Expand Down
4 changes: 4 additions & 0 deletions src/web/app/src/styles/telescope-post-content.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
height: 100%;
}

.palette-preview {
border: 1px solid dimgray;
}

@keyframes scaleFadeIn {
from {
opacity: 0;
Expand Down
22 changes: 11 additions & 11 deletions src/web/app/src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ export const lightHighContrastTheme: Theme = createTheme({
palette: {
type: 'light',
primary: {
main: '#000E54',
light: '#128FDB',
dark: '#CECDC8',
main: '#050133',
light: '#1364D8',
dark: '#B7B7B6',
},
secondary: {
main: '#6BCCFC',
main: '#30A5FC',
},
error: {
main: '#F70315',
light: '#4d4d4d',
main: '#C4051C',
light: '#195E02',
},
background: {
default: '#FFFFFF',
paper: '#D1D1D1',
},
text: {
primary: '#000000',
secondary: '#000E54',
secondary: '#050133',
},
action: {
active: '#0F59B2',
selected: '#E003CB',
active: '#03407C',
selected: '#9B0494',
},
border: {
main: 'rgba(240,246,252,0.5)',
},
info: {
main: '#000E54',
light: '#074787 ',
main: '#050133',
light: '#01333F ',
},
},
});
Expand Down

0 comments on commit 009225d

Please sign in to comment.