Add support for object based custom media queries
This commit is contained in:
parent
ac77724081
commit
ddaaa2a7f8
1 changed files with 15 additions and 1 deletions
|
|
@ -27,9 +27,23 @@ function findMixin(css, mixin) {
|
|||
}
|
||||
|
||||
function addCustomMediaQueries(css, breakpoints) {
|
||||
function buildMediaQuery(breakpoint) {
|
||||
if (_.isString(breakpoint)) {
|
||||
breakpoint = { min: breakpoint }
|
||||
}
|
||||
return _(breakpoint).toPairs().map(([feature, value]) => {
|
||||
feature = _.get({
|
||||
min: 'min-width',
|
||||
max: 'max-width',
|
||||
}, feature, feature)
|
||||
|
||||
return `(${feature}: ${value})`
|
||||
}).join(' and ')
|
||||
}
|
||||
|
||||
Object.keys(breakpoints).forEach(breakpoint => {
|
||||
const variableName = `--breakpoint-${breakpoint}`
|
||||
const mediaQuery = `(min-width: ${breakpoints[breakpoint]})`
|
||||
const mediaQuery = buildMediaQuery(breakpoints[breakpoint])
|
||||
const rule = postcss.atRule({
|
||||
name: 'custom-media',
|
||||
params: `${variableName} ${mediaQuery}`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue