Skip to content

Commit

Permalink
Add logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Jul 23, 2020
1 parent 47a669d commit c95cc9b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
26 changes: 25 additions & 1 deletion index.js
@@ -1,5 +1,29 @@
let postcss = require('postcss')

module.exports = postcss.plugin('postcss-100vh-fix', () => {
return () => {}
return root => {
root.walkDecls(/(min-|max-)?height/, decl => {
if (decl.value !== '100vh') return
let rule = decl.parent

let media = postcss.atRule({
name: 'supports',
params: '(-webkit-touch-callout: none)'
// source: decl.source
})
rule.after(media)

let clonedRule = postcss.rule({
selector: rule.selector
// source: rule.source
})
media.append(clonedRule)

clonedRule.append({
prop: decl.prop,
value: '-webkit-fill-available'
// source: decl.source
})
})
}
})
31 changes: 29 additions & 2 deletions index.test.js
Expand Up @@ -8,6 +8,33 @@ function run (input, output) {
expect(result.warnings()).toHaveLength(0)
}

it('does nothing', () => {
run('a{}', 'a{}')
it('adds -webkit-fill-available', () => {
run(
'@media (max-width: 600px) { body { height: 100vh } }',
'@media (max-width: 600px) { body { height: 100vh } ' +
'@supports (-webkit-touch-callout: none) { ' +
'body { height: -webkit-fill-available } } }'
)
})

it('supports min-height', () => {
run(
'.min { min-height: 100vh }',
'.min { min-height: 100vh }\n' +
'@supports (-webkit-touch-callout: none) {\n' +
' .min { min-height: -webkit-fill-available } }'
)
})

it('supports max-height', () => {
run(
'.max { max-height: 100vh }',
'.max { max-height: 100vh }\n' +
'@supports (-webkit-touch-callout: none) {\n' +
' .max { max-height: -webkit-fill-available } }'
)
})

it('ignores non-100vh height', () => {
run('body { max-height: 100% }', 'body { max-height: 100% }')
})

0 comments on commit c95cc9b

Please sign in to comment.