7.1.8 • Published 16 days ago

postcss-custom-selectors v7.1.8

Weekly downloads
3,926,544
License
MIT
Repository
github
Last release
16 days ago

PostCSS Custom Selectors

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 */);

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

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 */);
postcss-preset-envce-webpack-temptuum@infinitebrahmanuniverse/nolb-postcss-csklif-ui-kitsklif-api@everything-registry/sub-chunk-2460sklif-ui@contagt/metismenu@davidwells/config-postcss@bpanchenko/uikit@carhoo/widget-dealerspostcss-preset-ccbreact-lightbox-pack-18supportreact-solid-gradient-pickervirtual-tour-guideycsswildplatesourdough-preprocessorstories-fsstories-react-bdspike-css-standardsstyle-guide-mainresponsis-gantt-task-reacttest-iki-mini-appreacteekreactofy-css-libraryrelient-clireact-ang-notifications-honey-comb-setupreact-ark-toolsreact-app-tools-telesohoreact_gantt@clark/ember-css-modules-config@csstools/csstools-cli@dgrammatiko/joomla-tools@digitalnative/postcss-preset-env@digitalnativeinc/postcss-preset-envcustome-package-amincssbagcssnextde.css.configdbz-flame-scripts@anonybit-modules/videoreconstruction@ericmcornelius/ease@enirisdev/angular-google-charts@fusionary/postcss-base@helpfulhuman/postcss-preset@kkt/postcss-preset-env@kanopi/pack@knooks/use-title@leiyulf/gantt-task-react@max-norin/postcss-project-init@namtoonix/editorjs-custom-multiple-selected@mayuriachewad/pickupbiz-npm-packagemy-library-button@zalastax/nolb-postcss-cmavectrajulien-easy-modal@sveltevietnam/ui@synocate/build-toolseditor.js-custom-multiple-selected@vasosolo/multiselectcomboboxeditorjs_forkedelectron-react-app-scriptsmicroend-componentaltiore-reactnka-gantt-task-reactomni-common-uibabel-plugin-prejss@vituum/tailwind@oat-sa/postcss-preset-env@pangolinjs/postcss-preset-envlearning_lockerlevel4@sadcitizen/postcss-configkirei-cssgenerator-react-staparis-nord-estpm-galleryhelp-widgethiqgulp-config-devpickupbiz-npm-packagece-webpackportal_kitcase-gg-editorpostcss-mixpostcss-cssnextpostcss-cssplusqpack
7.1.8

16 days ago

7.1.7

1 month ago

7.1.6

6 months ago

7.1.5

6 months ago

7.1.4

9 months ago

7.1.3

12 months ago

7.1.2

1 year ago

7.1.1

1 year ago

7.1.0

1 year ago

7.0.0

1 year ago

6.0.1

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.0

3 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

7 years ago

4.0.0

7 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

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago