Skip to content

Commit

Permalink
[docs-infra] Fix RTL dark mode (mui#41803)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Dec 4, 2024
1 parent c328fe4 commit e2ba426
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
19 changes: 2 additions & 17 deletions docs/src/createEmotionCache.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
/* eslint-disable default-case */
import createCache from '@emotion/cache';
import { prefixer, Element, RULESET } from 'stylis';

// A workaround to https://github.com/emotion-js/emotion/issues/2836
// to be able to use `:where` selector for styling.
function globalSelector(element: Element) {
switch (element.type) {
case RULESET:
element.props = (element.props as string[]).map((value: any) => {
if (value.match(/(:where|:is)\(/)) {
value = value.replace(/\.[^:]+(:where|:is)/, '$1');
return value;
}
return value;
});
}
}
import { prefixer } from 'stylis';
import globalSelector from './modules/utils/globalSelector';

export default function createEmotionCache() {
// TODO remove prepend: true once JSS is out
Expand Down
3 changes: 2 additions & 1 deletion docs/src/modules/utils/StyledEngineProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import createCache from '@emotion/cache';
import { prefixer } from 'stylis';
import rtlPlugin from 'stylis-plugin-rtl';
import { useTheme } from '@mui/material/styles';
import globalSelector from './globalSelector';

// Cache for the rtl version of the styles
const cacheRtl = createCache({
key: 'rtl',
prepend: true,
stylisPlugins: [prefixer, rtlPlugin],
stylisPlugins: [prefixer, rtlPlugin, globalSelector],
});

export default function StyledEngineProvider(props) {
Expand Down
17 changes: 17 additions & 0 deletions docs/src/modules/utils/globalSelector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable default-case */
import { Element, RULESET } from 'stylis';

// A workaround to https://github.com/emotion-js/emotion/issues/2836
// to be able to use `:where` selector for styling.
export default function globalSelector(element: Element) {
switch (element.type) {
case RULESET:
element.props = (element.props as string[]).map((value: any) => {
if (value.match(/(:where|:is)\(/)) {
value = value.replace(/\.[^:]+(:where|:is)/, '$1');
return value;
}
return value;
});
}
}

0 comments on commit e2ba426

Please sign in to comment.