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

[docs-infra] Fix RTL dark mode #41803

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
}
}
Loading