Skip to content

Commit

Permalink
ColorSchemeProvider: support to classic partial exclusions (#3930)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertCarreras authored Jan 8, 2025
1 parent 6b9e7ca commit 0bdbcf0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/gestalt/src/contexts/ColorSchemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type Props = {
* Sets the line height for the selected language.
*/
language?: 'default' | 'tall' | 'ck' | 'ja' | 'th' | 'vi';
__forceClassic?: boolean;
__rootSelector?: string;
};

/**
Expand All @@ -148,17 +150,21 @@ export default function ColorSchemeProvider({
fullDimensions = false,
id,
language = 'default',
__forceClassic = false,
__rootSelector = '',
}: Props) {
const [theme, setTheme] = useState(getTheme(colorScheme));
const [languageLineHeight, setLanguageLineHeight] = useState(language);

const className = id ? `__gestaltTheme${id}` : undefined;
const selector = className ? `.${className}` : ':root';
const isInExperiment = useInExperiment({
webExperimentName: 'web_gestalt_visualRefresh',
mwebExperimentName: 'web_gestalt_visualRefresh',
});

const className = id ? `__gestaltTheme${id}` : undefined;
const root = __rootSelector ? `:root .${__rootSelector}` : ':root';
const selector = className ? `.${className}` : root;

const handlePrefChange = (event: MediaQueryList) => {
setTheme(getTheme(event.matches ? 'dark' : 'light'));
};
Expand All @@ -185,10 +191,10 @@ export default function ColorSchemeProvider({
colorScheme === 'userPreference'
? `@media(prefers-color-scheme: dark) {
${selector} {
${themeToStyles(darkModeTheme, isInExperiment, languageLineHeight)} }
${themeToStyles(darkModeTheme, __forceClassic ? false : isInExperiment, languageLineHeight)} }
}`
: `${selector} {
${themeToStyles(theme, isInExperiment, languageLineHeight)} }`,
${themeToStyles(theme, __forceClassic ? false : isInExperiment, languageLineHeight)} }`,
}}
/>
<div
Expand Down

0 comments on commit 0bdbcf0

Please sign in to comment.