postcss-sparrow-clamp-fallback

0.1.2 • Public • Published

PostCSS Sparrow Clamp Fallback

Known Vulnerabilities Maintainability Test Coverage Codacy Badge

A PostCSS plugin that creates fallback of clamp() for you.

/* Before transformations */
.foo {
  font-size: clamp(20px2vw40px);
}
/* After transformations */
/* If you set fallback: "media" */
/* Coming soon */
@media (width <= 1000px) {
  .foo{
   font-size: 20px; /*min*/
  }
}
 
.foo{
  font-size: 2vw;
}
 
@media (width >= 2000px) {
.foo{
   font-size: 40px; /*max*/
  }
}
/* After transformations */
/* If you set fallback: "minmax" */
.foo {
  font-size: max(20px, min(2vw40px));
}

Why do I need this plugin?

clamp() is a very powerful tool for creating a responsive design. Nevertheless, its support is limited at the moment. As of Sept 2020, this rule is only supported by 77% of all browsers.

This plugin will help you transform clamp() with the combination of min() and max() or media queries for more browser support.

Browser support for various fallback

Installation

This plugin require you to use PostCSS Sparrow for matching with selectors you want.

Download both postcss-sparrow and this plugin through NPM.

npm i postcss postcss-sparrow postcss-sparrow-clamp-fallback

Then import this plugin as the callback for PostCSS Sparrow.

//postcss.config.js
module.exports = {
  plugins: [
    //Other plugins...
 
    require('postcss-sparrow')({
      transformations: [
        {
          selectors: ['*'],
          inclusion: true,
          callbacks: [
            require('postcss-sparrow-clamp-fallback')({
              fallback: 'minmax'
            })
          ]
        }
      ]
    })
  ]
}

API Reference

options.fallback : String

Choose the way to fallback clamp(). Set it to 'minmax' to fallback with the combination of min() and max(); set it to 'media' to fallback with media queries.

This option is default to 'minmax'.

Option for 'media' coming soon.

Package Sidebar

Install

npm i postcss-sparrow-clamp-fallback

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

29.1 kB

Total Files

4

Last publish

Collaborators

  • johnwinston0410