Skip to content

Commit

Permalink
Implement dark/light switching
Browse files Browse the repository at this point in the history
  • Loading branch information
benjervis committed Dec 14, 2023
1 parent 5fe7b64 commit 1728edf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/makeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ module.exports = async (playroomConfig, options) => {
include: path.dirname(require.resolve('codemirror/package.json')),
use: [MiniCssExtractPlugin.loader, require.resolve('css-loader')],
},
{
test: /\.png$/i,
type: 'asset/resource',
},
],
},
optimization: {
Expand All @@ -163,7 +167,7 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['index'],
filename: 'index.html',
favicon: 'images/favicon-inverted.png',
favicon: 'images/favicon.png',
base: playroomConfig.baseUrl,
}),
new HtmlWebpackPlugin({
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { renderElement } from './render';
import Playroom from './Playroom/Playroom';
import { StoreProvider } from './StoreContext/StoreContext';
import playroomConfig from './config';
import faviconPath from '../images/favicon.png';
import faviconInvertedPath from '../images/favicon-inverted.png';

const polyfillIntersectionObserver = () =>
typeof window.IntersectionObserver !== 'undefined'
Expand All @@ -14,6 +16,15 @@ polyfillIntersectionObserver().then(() => {
const outlet = document.createElement('div');
document.body.appendChild(outlet);

const selectedElement = document.head.querySelector('link[rel="icon"]');
const favicon = window.matchMedia('(prefers-color-scheme: dark)').matches
? faviconInvertedPath
: faviconPath;

if (selectedElement) {
selectedElement.setAttribute('href', favicon);
}

const renderPlayroom = ({
themes = require('./themes'),
components = require('./components'),
Expand Down

0 comments on commit 1728edf

Please sign in to comment.