Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Darkmode #932

Merged
merged 13 commits into from
Aug 3, 2022
75 changes: 75 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"react-hook-form": "^3.29.4",
"react-i18next": "^11.16.7",
"react-page-visibility": "^7.0.0",
"react-responsive": "^8.2.0",
LukasKalbertodt marked this conversation as resolved.
Show resolved Hide resolved
"react-router-dom": "^5.3.1",
"react-scripts": "^4.0.3",
"theme-ui": "^0.3.5",
Expand Down
9 changes: 8 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//; -*- mode: rjsx;-*-
/** @jsx jsx */
import { jsx } from 'theme-ui';
import { jsx, useColorMode } from 'theme-ui';
import { useMediaQuery } from 'react-responsive';

import { Flex } from '@theme-ui/components';
import { useState, Fragment } from 'react';
Expand All @@ -21,6 +22,12 @@ import Warnings from './ui/warnings';

function App({ settingsManager, userHasWebcam }) {
const settings = useSettings();
const [, setColorMode] = useColorMode();

useMediaQuery({
query: '(prefers-color-scheme: dark)',
}, undefined, (isDarkPrefered) => setColorMode(isDarkPrefered ? 'dark' : 'light'))

return (
<Router basename={process.env.PUBLIC_URL || '/'}>
<Global styles={settings.theme?.customCSS || ''}/>
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@
"warning-missing-connection-settings": "Die Verbindung zum Opencast Server wurde noch nicht vollständig hergestellt. Bitte konfigurieren Sie die Verbindung in <1>den Einstellungen</1> (die Aufnahme geht nicht verloren).",

"settings-back-to-recording": "Zurück zur Aufnahme",
"settings-theme-appearance": "Aussehen",
"settings-theme-dark": "Zum dunklen Design wechseln",
"settings-theme-light": "Zum hellen Design wechseln",

"video-settings-open": "Videoeinstellungen öffnen",
"video-settings-close": "Videoeinstellungen schließen"

narickmann marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 5 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,9 @@
"settings-back-to-recording": "Back to recording",

"video-settings-open": "Open video settings",
"video-settings-close": "Close video settings"
"video-settings-close": "Close video settings",

"settings-theme-appearance": "Appearance",
"settings-theme-dark": "Switch to Darkmode",
"settings-theme-light": "Switch to Lightmode"
}
25 changes: 24 additions & 1 deletion src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const base = {
heights: {
headerHeight: '3em'
},
useColorSchemeMediaQuery: true,
colors: {
text: '#000',
background: '#fff',
Expand All @@ -54,7 +55,25 @@ const base = {
highlight: '#3498db',
error: '#f14668',
gray: ['#363636', '#666666', '#aaaaaa', '#dddddd', '#f5f5f5'],
videoOverlay: 'rgba(255, 255, 255, 0.2)'
videoOverlay: 'rgba(255, 255, 255, 0.2)',
element_bg: '#fff',
notification_text: '#fff',
modes: {
dark: {
text: 'rgba(255, 255, 255, 0.87)',
background: '#1C1C1E',
button_fg: '#fff',
primary: '#47af7a',
secondary: '#30c',
muted: '#888888',
highlight: '#3498db',
error: 'rgba(241, 70, 104, 0.8)',
gray: ['#f5f5f5', '#dddddd', '#aaaaaa', '#666666', '#363636'],
videoOverlay: 'rgba(255, 255, 255, 0.2)',
element_bg: '#363636',
notification_text: 'rgba(255, 255, 255, 0.9)'
}
}
},
text: {
text: {
Expand Down Expand Up @@ -177,6 +196,8 @@ const base = {
maxWidth: '100%'
},
input: {
backgroundColor: 'element_bg',
color: 'text',
borderWidth: 1,
borderStyle: 'solid',
borderColor: 'gray.2',
Expand All @@ -198,6 +219,8 @@ const base = {
}
},
select: {
backgroundColor: 'element_bg',
color: 'text',
height: '2rem',
fontSize: '14pt',
outline: 'none',
Expand Down
15 changes: 9 additions & 6 deletions src/ui/header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//; -*- mode: rjsx;-*-
/** @jsx jsx */
import { jsx } from 'theme-ui';
import { jsx, useColorMode } from 'theme-ui';

import { Link, NavLink, useLocation } from 'react-router-dom';
import { Fragment, useState } from 'react';
Expand All @@ -20,6 +20,7 @@ import { useStudioState } from '../studio-state';
// The header, including a logo on the left and the navigation on the right.
export default function Header() {
const { isRecording } = useStudioState();
const [ colorMode ] = useColorMode();

return (
<header
Expand All @@ -37,7 +38,7 @@ export default function Header() {
the parent element, as the navigation overlay would otherwise occlude
this background color */}
<div sx={{
backgroundColor: 'gray.0',
backgroundColor: colorMode === 'dark' ? 'gray.4' : 'gray.0',
position: 'absolute',
zIndex: -3,
height: '100%',
Expand All @@ -47,7 +48,7 @@ export default function Header() {
{/* This div is an overlay that is shown when a recording is currently active.
This prevents the user from visiting other pages while recording. */}
{ isRecording && <div sx={{
backgroundColor: 'gray.0',
backgroundColor: colorMode === 'dark' ? 'gray.4' : 'gray.0',
position: 'absolute',
zIndex: 20,
height: '100%',
Expand Down Expand Up @@ -93,6 +94,7 @@ const Brand = () => {
const NavElement = ({ target, children, icon, ...rest }) => {
const location = useLocation();
const { isRecording } = useStudioState();
const [ colorMode ] = useColorMode();

return (
<NavLink
Expand All @@ -112,12 +114,12 @@ const NavElement = ({ target, children, icon, ...rest }) => {
textDecoration: 'none',
fontSize: '18px',
height: ['auto', '100%'],
borderLeft: ['none', theme => `1px solid ${theme.colors.gray[3]}`],
borderLeft: ['none', theme => `1px solid ${theme.colors.gray[colorMode === 'dark' ? 1 : 3]}`],
display: ['block', 'inline-block'],
width: ['100%', 'auto'],

'&:hover': {
backgroundColor: 'gray.1',
backgroundColor: colorMode === 'dark' ? 'gray.3' : 'gray.1',
},
':focus-visible': {
outline: '5px solid #8ec8aa !important',
Expand Down Expand Up @@ -145,6 +147,7 @@ const Navigation = props => {
const toggleMenu = () => updateIsOpened(!isOpened);
const closeMenu = () => updateIsOpened(false);
const { t } = useTranslation();
const [colorMode] = useColorMode();

return (
<Fragment>
Expand Down Expand Up @@ -193,7 +196,7 @@ const Navigation = props => {
top: [theme => theme.heights.headerHeight, theme => theme.heights.headerHeight, 0],
position: ['absolute', 'static'],
width: ['100%', 'auto'],
backgroundColor: ['gray.0', 'none'],
backgroundColor: [colorMode === 'dark' ? 'gray.4' : 'gray.0', 'none'],
transition: ['height 0.25s ease-out 0s', 'none'],
scrollX: ['none', 'auto'],
}}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Notification = ({isDanger, ...rest}) => (
sx={{
':not(:last-child)': { marginBottom: '1.5rem' },
backgroundColor: isDanger ? 'error' : 'gray.3',
color: isDanger ? 'background' : 'currentColor',
color: isDanger ? 'notification_text' : 'currentColor',
borderRadius: 2,
padding: 3,
position: 'relative'
Expand Down
47 changes: 47 additions & 0 deletions src/ui/settings/colorMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//; -*- mode: rjsx;-*-
/** @jsx jsx */

import { jsx, useColorMode } from 'theme-ui';
import { Button } from '@theme-ui/components';
import { useTranslation } from 'react-i18next';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faMoon, faSun } from "@fortawesome/free-solid-svg-icons";
narickmann marked this conversation as resolved.
Show resolved Hide resolved

import { SettingsSection } from './elements';

const ColorModeSettings = () => {
const { t } = useTranslation();
const [colorMode, setColorMode] = useColorMode();

const dark = t('settings-theme-dark');
const light = t('settings-theme-light');

return (
<SettingsSection title={t('settings-theme-appearance')}>
<Button
onClick={() => setColorMode(colorMode === 'dark' ? 'light' : 'dark')}>
{colorMode === 'dark' ? light : dark}
<ThemeIcon/>
</Button>
</SettingsSection>
);
};

const ThemeIcon = () => {
const [colorMode] = useColorMode();

return(
<div
sx={{
color: '#ffd983',
narickmann marked this conversation as resolved.
Show resolved Hide resolved
width: '10px',
display: 'inline-block',
ml: 2,
}}
>
<FontAwesomeIcon icon={colorMode === 'dark' ? faSun : faMoon} />
narickmann marked this conversation as resolved.
Show resolved Hide resolved
</div>
)
};

export default ColorModeSettings;
Loading