postcss-custom-selectors
Use Custom Selectors in CSS
Last updated 13 days ago by romainmenke .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install postcss-custom-selectors 
SYNC missed versions from official npm registry.

PostCSS Custom Selectors PostCSS Logo

npm install postcss-custom-selectors --save-dev

PostCSS Custom Selectors lets you define @custom-selector in CSS following the Custom Selectors Specification.

@custom-selector :--heading h1, h2, h3;

article :--heading + p {
	margin-top: 0;
}

/* becomes */

article :is(h1, h2, h3) + p {
	margin-top: 0;
}

Usage

Add PostCSS Custom Selectors to your project:

npm install postcss postcss-custom-selectors --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssCustomSelectors = require('postcss-custom-selectors');

postcss([
	postcssCustomSelectors(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

Options

preserve

The preserve option determines whether the original notation is preserved. By default, it is not preserved.

postcssCustomSelectors({ preserve: true })
@custom-selector :--heading h1, h2, h3;

article :--heading + p {
	margin-top: 0;
}

/* becomes */

@custom-selector :--heading h1, h2, h3;

article :is(h1, h2, h3) + p {
	margin-top: 0;
}

article :--heading + p {
	margin-top: 0;
}

Modular CSS Processing

If you're using Modular CSS such as, CSS Modules, postcss-loader or vanilla-extract to name a few, you'll probably notice that custom selectors are not being resolved. This happens because each file is processed separately so unless you import the custom selector definitions in each file, they won't be resolved.

To overcome this, we recommend using the PostCSS Global Data plugin which allows you to pass a list of files that will be globally available. The plugin won't inject any extra code in the output but will provide the context needed to resolve custom selectors.

For it to run it needs to be placed before the PostCSS Custom Selectors plugin.

const postcss = require('postcss');
const postcssCustomSelectors = require('postcss-custom-selectors');
const postcssGlobalData = require('@csstools/postcss-global-data');

postcss([
	postcssGlobalData({
		files: [
			'path/to/your/custom-selectors.css'
		]
	}),
	postcssCustomSelectors(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

Current Tags

  • 8.0.4                                ...           latest (13 days ago)

39 Versions

  • 8.0.4                                ...           13 days ago
  • 8.0.3                                ...           22 days ago
  • 8.0.2                                ...           a month ago
  • 8.0.1                                ...           3 months ago
  • 8.0.0                                ...           3 months ago
  • 7.1.12                                ...           4 months ago
  • 7.1.11                                ...           5 months ago
  • 7.1.10                                ...           6 months ago
  • 7.1.9                                ...           6 months ago
  • 7.1.8                                ...           8 months ago
  • 7.1.7                                ...           9 months ago
  • 7.1.6                                ...           a year ago
  • 7.1.5                                ...           a year ago
  • 7.1.4                                ...           a year ago
  • 7.1.3                                ...           2 years ago
  • 7.1.2                                ...           2 years ago
  • 7.1.1                                ...           2 years ago
  • 7.1.0                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 6.0.3                                ...           2 years ago
  • 6.0.2                                ...           2 years ago
  • 6.0.1                                ...           2 years ago
  • 6.0.0                                ...           4 years ago
  • 5.1.2                                ...           6 years ago
  • 5.1.1                                ...           6 years ago
  • 5.1.0                                ...           6 years ago
  • 5.0.0                                ...           6 years ago
  • 4.0.1                                ...           8 years ago
  • 4.0.0                                ...           8 years ago
  • 3.0.0                                ...           9 years ago
  • 2.3.0                                ...           9 years ago
  • 2.2.0                                ...           9 years ago
  • 2.1.1                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE