postcss-custom-selectors

WebJar for postcss-custom-selectors

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

postcss-custom-selectors
Last Version

Last Version

4.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

postcss-custom-selectors
WebJar for postcss-custom-selectors
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/postcss/postcss-custom-selectors

Download postcss-custom-selectors

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/postcss-custom-selectors/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>postcss-custom-selectors</artifactId>
    <version>4.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/postcss-custom-selectors/
implementation 'org.webjars.npm:postcss-custom-selectors:4.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/postcss-custom-selectors/
implementation ("org.webjars.npm:postcss-custom-selectors:4.0.1")
'org.webjars.npm:postcss-custom-selectors:jar:4.0.1'
<dependency org="org.webjars.npm" name="postcss-custom-selectors" rev="4.0.1">
  <artifact name="postcss-custom-selectors" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='postcss-custom-selectors', version='4.0.1')
)
libraryDependencies += "org.webjars.npm" % "postcss-custom-selectors" % "4.0.1"
[org.webjars.npm/postcss-custom-selectors "4.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : postcss jar [6.0.1,7)
org.webjars.npm » postcss-selector-matches jar [3.0.0,4)

Project Modules

There are no modules declared in this project.

PostCSS Custom Selectors PostCSS

NPM Version CSS Standard Status Build Status Support Chat

PostCSS Custom Selectors lets you use Custom Selectors in CSS, following the CSS Extensions specification.

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

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

/* becomes */

article h1 + p, article h2 + p, article h3 + p {}

Usage

Add PostCSS Custom Selectors to your project:

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

Use PostCSS Custom Selectors to process your CSS:

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

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

Or use it as a PostCSS plugin:

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

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

PostCSS Custom Selectors runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

Options

preserve

The preserve option determines whether custom selectors and rules using custom selectors should be preserved in their original form.

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

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

/* becomes */

article h1 + p, article h2 + p, article h3 + p {}

article :--heading + p {}

importFrom

The importFrom option specifies sources where custom selectors can be imported from, which might be CSS, JS, and JSON files, functions, and directly passed objects.

postcssCustomSelectors({
  importFrom: 'path/to/file.css' // => @custom-selector :--heading h1, h2, h3;
});
article :--heading + p {
  margin-top: 0;
}

/* becomes */

article h1 + p, article h2 + p, article h3 + p {}

Multiple sources can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, functions, and objects will need to namespace custom selectors using the customProperties or custom-properties key.

postcssCustomSelectors({
  importFrom: [
    'path/to/file.css',
    'and/then/this.js',
    'and/then/that.json',
    {
      customSelectors: { ':--heading': 'h1, h2, h3' }
    },
    () => {
      const customProperties = { ':--heading': 'h1, h2, h3' };

      return { customProperties };
    }
  ]
});

exportTo

The exportTo option specifies destinations where custom selectors can be exported to, which might be CSS, JS, and JSON files, functions, and directly passed objects.

postcssCustomSelectors({
  exportTo: 'path/to/file.css' // @custom-selector :--heading h1, h2, h3;
});

Multiple destinations can be passed into this option, and they will be parsed in the order they are received. JavaScript files, JSON files, and objects will need to namespace custom selectors using the customProperties or custom-properties key.

const cachedObject = { customSelectors: {} };

postcssCustomSelectors({
  exportTo: [
    'path/to/file.css',   // @custom-selector :--heading h1, h2, h3;
    'and/then/this.js',   // module.exports = { customSelectors: { ':--heading': 'h1, h2, h3' } }
    'and/then/this.mjs',  // export const customSelectors = { ':--heading': 'h1, h2, h3' } }
    'and/then/that.json', // { "custom-selectors": { ":--heading": "h1, h2, h3" } }
    cachedObject,
    customProperties => {
      customProperties    // { ':--heading': 'h1, h2, h3' }
    }
  ]
});
org.webjars.npm

PostCSS

PostCSS and plugins based on it

Versions

Version
4.0.1