Skip to content

Instantly share code, notes, and snippets.

@wildcard
Last active April 16, 2017 13:10
Show Gist options
  • Save wildcard/c74decdcd86913022ffb8ffed8bded86 to your computer and use it in GitHub Desktop.
Save wildcard/c74decdcd86913022ffb8ffed8bded86 to your computer and use it in GitHub Desktop.
updated for JSS version 7.0.3
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