flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
50
VISUALIZACION/node_modules/polished/lib/helpers/cssVar.js.flow
generated
vendored
Executable file
50
VISUALIZACION/node_modules/polished/lib/helpers/cssVar.js.flow
generated
vendored
Executable file
|
|
@ -0,0 +1,50 @@
|
|||
// @flow
|
||||
import PolishedError from '../internalHelpers/_errors'
|
||||
|
||||
const cssVariableRegex = /--[\S]*/g
|
||||
|
||||
/**
|
||||
* Fetches the value of a passed CSS Variable in the :root scope, or otherwise returns a defaultValue if provided.
|
||||
*
|
||||
* @example
|
||||
* // Styles as object usage
|
||||
* const styles = {
|
||||
* 'background': cssVar('--background-color'),
|
||||
* }
|
||||
*
|
||||
* // styled-components usage
|
||||
* const div = styled.div`
|
||||
* background: ${cssVar('--background-color')};
|
||||
* `
|
||||
*
|
||||
* // CSS in JS Output
|
||||
*
|
||||
* element {
|
||||
* 'background': 'red'
|
||||
* }
|
||||
*/
|
||||
export default function cssVar(
|
||||
cssVariable: string,
|
||||
defaultValue?: string | number,
|
||||
): string | number {
|
||||
if (!cssVariable || !cssVariable.match(cssVariableRegex)) {
|
||||
throw new PolishedError(73)
|
||||
}
|
||||
|
||||
let variableValue
|
||||
|
||||
/* eslint-disable */
|
||||
/* istanbul ignore next */
|
||||
if (typeof document !== 'undefined' && document.documentElement !== null) {
|
||||
variableValue = getComputedStyle(document.documentElement).getPropertyValue(cssVariable)
|
||||
}
|
||||
/* eslint-enable */
|
||||
|
||||
if (variableValue) {
|
||||
return variableValue.trim()
|
||||
} else if (defaultValue) {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
throw new PolishedError(74)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue