Skip to content

Commit

Permalink
Add experimental support for dark mode
Browse files Browse the repository at this point in the history
Add experimental support for enabling dark mode display of the
Dashboard UI. This doesn't affect the header/nav which are already
using a dark presentation, but updates the rest of the UI to adopt
a dark look and feel using Carbon's gray 90 theme.

For this initial version, dark mode can be enabled by setting a flag
in local storage, e.g. `localStorage.setItem('tkn-theme', 'dark')`

Supported values are:
- `light` which is the default and current theme
- `dark` which enables the dark theme
- `system` which enables/disables dark theme according to the user's
  OS settings (uses the `prefers-color-scheme: dark` media query)
  • Loading branch information
AlanGreene authored and tekton-robot committed May 5, 2021
1 parent db0e9f1 commit bfa79e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Tekton Authors
Copyright 2019-2021 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -11,6 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
/* istanbul ignore file */

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
Expand All @@ -32,6 +33,11 @@ const store = configureStore({ webSocket });

store.dispatch(setLocale(navigator.language));

const theme = localStorage.getItem('tkn-theme');
if (['dark', 'system'].includes(theme)) {
document.body.classList.add(`tkn--theme-${theme}`);
}

ReactDOM.render(
<Provider store={store}>
<App onUnload={closeSocket} />
Expand Down
22 changes: 19 additions & 3 deletions src/scss/_carbon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ $feature-flags: (
);

@import '~@carbon/themes/scss/themes';
@import '~carbon-components/scss/globals/scss/component-tokens';
@import '~carbon-components/scss/components/notification/tokens';
@import '~carbon-components/scss/components/tag/tokens';

:root {
:root, .tkn--theme-light {
@include carbon--theme($carbon--theme--g10, true);
}

body.tkn--dark-theme {
@include carbon--theme($carbon--theme--g90, true);
@mixin tkn--theme-dark {
@include carbon--theme($carbon--theme--g90, true) {
@include emit-component-tokens($notification-colors);
@include emit-component-tokens($tag-colors);
};
}

.tkn--theme-dark {
@include tkn--theme-dark;
}

@media (prefers-color-scheme: dark) {
.tkn--theme-system {
@include tkn--theme-dark;
}
}

@import '~carbon-components/scss/globals/scss/vars';
Expand Down

0 comments on commit bfa79e5

Please sign in to comment.