Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MuiCozyTheme): Introduce
type
prop in addition to variant
To prepare the way to dark mode. `type` is set default to `light`. BREAKING CHANGE: You can't now longer rely on `theme.palette.type` to determine `normal` or `inverted` theme, you have to use `theme.palette.variant` instead.
- Loading branch information
Showing
6 changed files
with
147 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
const getThemeNodeClassName = variant => `CozyTheme--light-${variant}` | ||
const getThemeNodeClassName = (type, variant) => `CozyTheme--${type}-${variant}` | ||
|
||
const getNodeWithThemeCssVars = variant => { | ||
const className = getThemeNodeClassName(variant) | ||
const getNodeWithThemeCssVars = (type, variant) => { | ||
const className = getThemeNodeClassName(type, variant) | ||
|
||
return document.getElementsByClassName(className)[0] | ||
} | ||
|
||
export const createNodeWithThemeCssVars = variant => { | ||
if (!getNodeWithThemeCssVars(variant)) { | ||
export const createNodeWithThemeCssVars = (type, variant) => { | ||
if (!getNodeWithThemeCssVars(type, variant)) { | ||
const node = document.createElement('div') | ||
node.className = getThemeNodeClassName(variant) | ||
node.className = getThemeNodeClassName(type, variant) | ||
node.style.display = 'none' | ||
document.body.prepend(node) | ||
} | ||
} | ||
|
||
const realGetCssVariableValue = (varName, variant) => { | ||
const node = getNodeWithThemeCssVars(variant) | ||
const realGetCssVariableValue = (varName, type, variant) => { | ||
const node = getNodeWithThemeCssVars(type, variant) | ||
|
||
return window | ||
.getComputedStyle(node) | ||
.getPropertyValue(`--${varName}`) | ||
.trim() | ||
} | ||
|
||
export const getCssVariableValue = (varName, variant) => | ||
export const getCssVariableValue = (varName, type, variant) => | ||
process.env.NODE_ENV === 'test' | ||
? () => () => '#fff' | ||
: realGetCssVariableValue(varName, variant) | ||
? '#fff' | ||
: realGetCssVariableValue(varName, type, variant) |