css-modules-enhancer

1.2.1 • Public • Published

css-modules-enhancer

This library provides a wrapper for css-modules to return a function that supports the same syntax as classnames.

The library is basically just classnames/bind augmented with the css-module properties to keep backwards compatibility with normal css-modules.

Installation

npm install --save css-modules-enhancer

Usage

The idea is to provide a Webpack loader that will wrap the css-modules automatically. But until that is in place, you can use the library manually.

.square {
  border-color: darkgrey;
}

.selected {
  background: grey;
}
var cssModuleEnhancer = require('css-modules-enhancer')
var styles = cssModuleEnhancer(require('./style.css'))

element.innerHTML = '<div class="' + styles('square', { selected: true }) + '">'

The wrapped module is backwards compatible with normal css-modules.

var cssModuleEnhancer = require('css-modules-enhancer')
var styles = cssModuleEnhancer(require('./style.css'))

element.innerHTML = '<div class="' + styles.square + '">'

Notice: that css classes that conflicts with the Function prototype are not overriden. You can still access them by calling the function:

element.innerHTML = '<div class="' + styles('apply') + '">'

See the documentation for classnames for more information about what is support by the enhanced css-module.

MIT License

Copyright (c) 2016 Sune Simonsen sune@we-knowhow.dk

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i css-modules-enhancer

Weekly Downloads

1

Version

1.2.1

License

MIT

Last publish

Collaborators

  • sunesimonsen