Giter VIP home page Giter VIP logo

postcss-icss-composes's Introduction

postcss-icss-composes Build Status

PostCSS plugin for css modules to compose local-scope classes

Usage

postcss([require('postcss-icss-composes')])

See PostCSS docs for examples for your environment.

Local class composition

composes and compose-with combines specified class name with rule class name.

.buttonStyle {
  background: #fff;
}
.buttonStyle:hover {
  box-shadow: 0 0 4px -2px;
}
.cellStyle {
  margin: 10px;
}
.addButton {
  composes: buttonStyle cellStyle;
  color: green;
}

/* becomes */

:export {
  buttonStyle: buttonStyle;
  cellStyle: cellStyle;
  addButton: addButton buttonStyle cellStyle
}
.buttonStyle {
  background: #fff;
}
.buttonStyle:hover {
  box-shadow: 0 0 4px -2px;
}
.cellStyle {
  margin: 10px;
}
.addButton {
  color: green;
}

Global class composition

You may use any identifier for composition

.addButton {
  composes: globalButtonStyle;
  background: #000;
}

/* becomes */
:export {
  addButton: addButton globalButtonStyle
}
.addButton {
  background: #000;
}

Scoping class names

postcss-icss-selectors plugin allows to local-scope classes.

.buttonStyle {
  background: #fff;
}
.addButton {
  composes: buttonStyle;
  border: 1px solid #000;
}

/* becomes */

:export {
  buttonStyle: __scope__buttonStyle;
  addButton: __scope__addButton __scope__buttonStyle
}
.__scope__buttonStyle {
  background: #fff;
}
.__scope__addButton {
  border: 1px solid #000;
}

External composition

/* compositions.css */
.button {
  background: #fff;
  border: 1px solid #000;
}
.cell {
  margin: 10px;
}

/* main.css */
.addButton {
  composes: button cell from './composition.css';
  font-size: 20px;
}

Messages

postcss-icss-composes passes result.messages for each composed class name

{
  plugin: 'postcss-icss-composes',
  type: 'icss-composed',
  name: string, // rule class name
  value: string // composed class name
}

License

MIT © Glen Maddern and Bogdan Chadkin, 2015

postcss-icss-composes's People

Contributors

chentsulin avatar geelen avatar greenkeeperio-bot avatar joshwnj avatar just-boris avatar sokra avatar timdorr avatar trysound avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

postcss-icss-composes's Issues

Eslint config tweak

  "eslintConfig": {
    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module"
    },
    "env": {
      "es6": true
    },
    "extends": "eslint:recommended"
  },

replace with

  "eslintConfig": {
    "parserOptions": {
      "sourceType": "module"
    },
    "env": {
      "es6": true
    },
    "extends": "eslint:recommended"
  },

Consider split keyframes handling

  1. Will be better for performance to process only two properties (animation, animation-frame) instead of all.
  2. Splitting in separate module will let to remove some stuff from local-by-default and this plugins and just use new module without ugly _colon_local stuff.

/cc @sullenor @geelen

Ambiguous error messages

This module throws some very hard-to-decipher error messages, such as:

composition is only allowed when selector is single :local class name not in ":local(.input):local(.thin-size)"
or
composition is only allowed when selector is single :local class name not in XXX, YYY is weird

I think there are some commas missing, which make all of this very hard to understand. I mean, I get the 'general' idea, but what am I (as a developer) supposed to do about it? and what does the "... is weird" mean?

Also, https://github.com/css-modules/postcss-modules-scope/blob/42708f1298fa0e7515d5006d7c00d1f07cef9e9e/src/index.js#L23 says in the comment that "// 'id' is not possible, because you can't compose ids". I think that's a better error message for that case than the current one.

Document global composition

It looks like the ability to compose a global class landed in d476194, but it's not currently documented anywhere. Is this intended to be a public feature? It's super useful for interop with third-party libraries.

Ignoring leading dot class name

Using the replaceDeclarations feature of postcss-nested-ancestors you can reference parent selectors of nested blocks not only in your selectors themselves, but also in your declarations. For example:

.cell {
  padding: .5em;

  &--id {
    composes: ^&; /* replaced with `composes: .cell;` */
    font-weight: 500;
  }

  &--value {
    composes: ^&; /* replaced with `composes: .cell;` */
    font-style: italic;
  }
}

This would enable pretty straight forward BEM-ish composition, where the user only needs to add a modifier class (.cell--id) and the base class (.cell) gets applied automatically.

However, the replacement composes declaration is invalid, since the class name is prefixed with a dot.

Build Error (CSSModules) in foo.css:27:5
postcss-modules-scope: referenced class name ".cell" in composes not found

I could write a postcss plugin that removes the leading dots automatically or adds an unclass(^&) function or something like that, but this seems like a rather simple change that could be made in this plugin, possibly behind a flag.

Child Selectors

Currently child selectors aren't picked up properly. Take this input file for example:

.simple {
  color: red;
}

.simple h1 {
  color: blue;
}

It yields:

._child_selectors__simple {
  color: red;
}

:local(.simple) h1 {
  color: blue;
}

When I'd expect the result to be:

._child_selectors__simple {
  color: red;
}

._child_selectors__simple h1 {
  color: blue;
}

Hopefully I'll get a chance to send through a PR sometime soon but if not here's a heads up :) Thanks!

CSS generation configurable

Need a nice default (BEM-ish), but also the ability to override this somehow. It could be used for minification/obfuscation at this level (although alternatively a separate obfuscator could run over the generated CSS as a final step.

Handle multiple selectors

.global,:local(.exportMe) { } is a right pain. What if you use extends: in there? It makes no sense for .global.

Gonna stick with just grepping the selector for :local(.something) and doing that until PostCSS gets its proper CSS selector parser.

npm package missing licence file

The ISC license explicitly requires to attach the full license text to the code or any distribution. Without this the license isn't fulfilled by the project itself and thus invalid.

The npm package as it’s published and distributed, do not comply with this, as it doesn’t contain the license file. Effectively, without the full license text they are proprietary code and cannot be used by anyone who needs to comply with the licenses.

Can you please publish a patch with it?

generateScopedName should export the node

If you define both a class and keyframes with the same name, it is impossible to distinguish them. This is problematic for my use case, as I am able to remove unused classes but not keyframes.

Support PostCSS 5.x API

This will require a major version bump, as it will affect users on the 4.x path using any 4.x plugins.

Add `result.messages.dependency` support

Adds composition files to webpack via this.addDependency() (postcss-loader) enabling watch mode for them

.compose {
   composes: x from './path/to/file.css';
}
postcss([ compose() ]).process(css, options)
  .then((result) => {
      result.messages // [ { type: 'dependency', file: 'path/to/file' } , ...]
  })

Don't set Container#nodes directly

You should set children by append() or any other inset methods (of course, except push()).

Here we have same problem as with push(): PostCSS will not fix issues for you as result it is easy to broke AST.

In result we have issue in other PostCSS plugins like this: cssnano/cssnano#163 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.