Last active
April 16, 2017 13:10
-
-
Save wildcard/c74decdcd86913022ffb8ffed8bded86 to your computer and use it in GitHub Desktop.
updated for JSS version 7.0.3
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
import { endsWith, has, forEach, isString, isNumber } from 'lodash' | |
import cloneStyle from 'jss/lib/utils/cloneStyle' | |
const IMPORTANT = '!important' | |
function makeImportant(value) { | |
return endsWith(value, IMPORTANT) ? value : value + ' ' + IMPORTANT | |
} | |
export default ({important: importantByDefault = true} = {}) => { | |
return { | |
onProcessStyle: (style, rule, sheet) => { | |
let important = importantByDefault | |
if (has(style, 'important')) { | |
important = style.important | |
delete style.important | |
} else if (has(sheet, ['options', 'important'])) { | |
important = sheet.options.important | |
} | |
if (important) { | |
let _style = cloneStyle(style) | |
forEach(style, (value, key) => { | |
if (isString(value) || isNumber(value)) { | |
_style[key] = makeImportant(value) | |
} | |
}) | |
return _style | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment