source: frontend/node_modules/postcss-custom-selectors/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 4.7 KB
Line 
1# PostCSS Custom Selectors [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
2
3[<img alt="npm version" src="https://img.shields.io/npm/v/postcss-custom-selectors.svg" height="20">][npm-url] [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/custom-selectors.svg" height="20">][css-url] [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url] [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
4
5[PostCSS Custom Selectors] lets you define `@custom-selector` in CSS following the [Custom Selectors Specification].
6
7```pcss
8@custom-selector :--heading h1, h2, h3;
9
10article :--heading + p {
11 margin-top: 0;
12}
13
14/* becomes */
15
16article h1 + p,article h2 + p,article h3 + p {
17 margin-top: 0;
18}
19```
20
21## Usage
22
23Add [PostCSS Custom Selectors] to your project:
24
25```bash
26npm install postcss postcss-custom-selectors --save-dev
27```
28
29Use it as a [PostCSS] plugin:
30
31```js
32const postcss = require('postcss');
33const postcssCustomSelectors = require('postcss-custom-selectors');
34
35postcss([
36 postcssCustomSelectors(/* pluginOptions */)
37]).process(YOUR_CSS /*, processOptions */);
38```
39
40[PostCSS Custom Selectors] runs in all Node environments, with special
41instructions for:
42
43| [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
44| --- | --- | --- | --- | --- | --- |
45
46## Options
47
48### preserve
49
50The `preserve` option determines whether the original notation
51is preserved. By default, it is not preserved.
52
53```js
54postcssCustomSelectors({ preserve: true })
55```
56
57```pcss
58@custom-selector :--heading h1, h2, h3;
59
60article :--heading + p {
61 margin-top: 0;
62}
63
64/* becomes */
65
66@custom-selector :--heading h1, h2, h3;
67
68article h1 + p,article h2 + p,article h3 + p {
69 margin-top: 0;
70}
71
72article :--heading + p {
73 margin-top: 0;
74}
75```
76
77### importFrom
78
79The `importFrom` option specifies sources where custom selectors can be
80imported from, which might be CSS, JS, and JSON files, functions, and directly
81passed objects.
82
83```js
84postcssCustomSelectors({
85 importFrom: 'path/to/file.css' // => @custom-selector :--heading h1, h2, h3;
86});
87```
88
89```pcss
90article :--heading + p {
91 margin-top: 0;
92}
93
94/* becomes */
95
96article h1 + p, article h2 + p, article h3 + p {}
97```
98
99Multiple sources can be passed into this option, and they will be parsed in the
100order they are received. JavaScript files, JSON files, functions, and objects
101will need to namespace custom selectors using the `customProperties` or
102`custom-properties` key.
103
104```js
105postcssCustomSelectors({
106 importFrom: [
107 'path/to/file.css',
108 'and/then/this.js',
109 'and/then/that.json',
110 {
111 customSelectors: { ':--heading': 'h1, h2, h3' }
112 },
113 () => {
114 const customProperties = { ':--heading': 'h1, h2, h3' };
115
116 return { customProperties };
117 }
118 ]
119});
120```
121
122### exportTo
123
124The `exportTo` option specifies destinations where custom selectors can be
125exported to, which might be CSS, JS, and JSON files, functions, and directly
126passed objects.
127
128```js
129postcssCustomSelectors({
130 exportTo: 'path/to/file.css' // @custom-selector :--heading h1, h2, h3;
131});
132```
133
134Multiple destinations can be passed into this option, and they will be parsed
135in the order they are received. JavaScript files, JSON files, and objects will
136need to namespace custom selectors using the `customProperties` or
137`custom-properties` key.
138
139```js
140const cachedObject = { customSelectors: {} };
141
142postcssCustomSelectors({
143 exportTo: [
144 'path/to/file.css', // @custom-selector :--heading h1, h2, h3;
145 'and/then/this.js', // module.exports = { customSelectors: { ':--heading': 'h1, h2, h3' } }
146 'and/then/this.mjs', // export const customSelectors = { ':--heading': 'h1, h2, h3' } }
147 'and/then/that.json', // { "custom-selectors": { ":--heading": "h1, h2, h3" } }
148 cachedObject,
149 customProperties => {
150 customProperties // { ':--heading': 'h1, h2, h3' }
151 }
152 ]
153});
154```
155
156[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
157[css-url]: https://cssdb.org/#custom-selectors
158[discord]: https://discord.gg/bUadyRwkJS
159[npm-url]: https://www.npmjs.com/package/postcss-custom-selectors
160
161[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
162[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
163[PostCSS]: https://github.com/postcss/postcss
164[PostCSS Loader]: https://github.com/postcss/postcss-loader
165[PostCSS Custom Selectors]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-selectors
166[Custom Selectors Specification]: https://drafts.csswg.org/css-extensions/#custom-selectors
Note: See TracBrowser for help on using the repository browser.