Skip to content

Commit

Permalink
[docs] Use common strategy for lazily loading css
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 14, 2020
1 parent 1506f89 commit a3d52f0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = {
...config.module,
rules: config.module.rules.concat([
{
test: /\.(css|md)$/,
test: /\.md$/,
loader: 'raw-loader',
},
// transpile 3rd party packages with dependencies in this repository
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/src/modules/components/ThemeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useMediaQuery from '@material-ui/core/useMediaQuery';
import { enUS, zhCN, faIR, ruRU, ptBR, esES, frFR, deDE, jaJP } from '@material-ui/core/locale';
import { blue, pink } from '@material-ui/core/colors';
import { getCookie } from 'docs/src/modules/utils/helpers';
import { darkTheme, setPrismTheme } from 'docs/src/modules/components/prism';
import { loadCSS } from 'fg-loadcss/src/loadCSS';

const languageMap = {
en: enUS,
Expand Down Expand Up @@ -153,7 +153,7 @@ export function ThemeProvider(props) {
const { dense, direction, paletteColors, paletteType = preferredType, spacing } = themeOptions;

React.useEffect(() => {
setPrismTheme(darkTheme);
loadCSS('/static/styles/prism-okaidia.css', document.querySelector('#prismjs'));
}, []);

React.useEffect(() => {
Expand Down
15 changes: 0 additions & 15 deletions docs/src/modules/components/prism.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable import/no-mutable-exports, global-require */
import prism from 'prismjs';
import 'prismjs/components/prism-css';
import 'prismjs/components/prism-diff';
Expand All @@ -8,18 +7,4 @@ import 'prismjs/components/prism-jsx';
import 'prismjs/components/prism-markup';
import 'prismjs/components/prism-tsx';

let styleNode;
let darkTheme;

if (process.browser) {
darkTheme = require('./prism-okaidia.css');
styleNode = document.querySelector('#prismjs');
}

export { darkTheme };

export function setPrismTheme(theme) {
styleNode.textContent = theme;
}

export default prism;

0 comments on commit a3d52f0

Please sign in to comment.