source: frontend/node_modules/postcss-env-function/README.md

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

Fix frontend appearance

  • Property mode set to 100644
File size: 4.4 KB
Line 
1# PostCSS Environment Variables [<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-env-function.svg" height="20">][npm-url]
4[<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/environment-variables.svg" height="20">][css-url]
5[<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/actions/workflows/test.yml/badge.svg" height="20">][cli-url]
6[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
7
8[PostCSS Environment Variables] lets you use `env()` variables in CSS, following the [CSS Environment Variables] specification.
9
10```pcss
11@media (max-width: env(--branding-small)) {
12 body {
13 padding: env(--branding-padding);
14 }
15}
16
17/* becomes */
18
19@media (min-width: 600px) {
20 body {
21 padding: 20px;
22 }
23}
24
25/* when the `importFrom` option is: {
26 "environmentVariables": {
27 "--branding-small": "600px",
28 "--branding-padding": "20px"
29 }
30} */
31```
32
33## Usage
34
35Add [PostCSS Environment Variables] to your project:
36
37```bash
38npm install postcss postcss-env-function --save-dev
39```
40
41Use it as a [PostCSS] plugin:
42
43```js
44const postcss = require('postcss')
45const postcssEnvFunction = require('postcss-env-function')
46
47postcss([
48 postcssEnvFunction(/* pluginOptions */)
49]).process(YOUR_CSS /*, processOptions */)
50```
51
52[PostCSS Environment Variables] runs in all Node environments, with special instructions for:
53
54| [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) |
55| --- | --- | --- | --- | --- | --- |
56
57## Options
58
59### importFrom
60
61The `importFrom` option specifies sources where Environment Variables can be imported from, which might be JS and JSON files, functions, and directly passed objects.
62
63```js
64postcssEnvFunction({
65 importFrom: 'path/to/file.js' /* module.exports = {
66 environmentVariables: {
67 '--branding-padding': '20px',
68 '--branding-small': '600px'
69 }
70 } */
71})
72```
73
74```pcss
75@media (max-width: env(--branding-small)) {
76 body {
77 padding: env(--branding-padding);
78 }
79}
80
81/* becomes */
82
83@media (min-width: 600px) {
84 body {
85 padding: 20px;
86 }
87}
88```
89
90Multiple 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 Properties using the `environmentVariables` or `environment-variables` key.
91
92```js
93postcssEnvFunction({
94 importFrom: [
95 /* Import from a CommonJS file:
96
97 module.exports = {
98 environmentVariables: {
99 '--branding-padding': '20px'
100 }
101 } */
102 'path/to/file.js',
103
104 /* Import from a JSON file:
105
106 {
107 "environment-variables": {
108 "--branding-padding": "20px"
109 }
110 } */
111 'and/then/this.json',
112
113 /* Import from an JavaScript Object: */
114 {
115 environmentVariables: { '--branding-padding': '20px' }
116 },
117
118 /* Import from a JavaScript Function: */
119 () => {
120 const environmentVariables = { '--branding-padding': '20px' }
121
122 return { environmentVariables }
123 }
124 ]
125})
126```
127
128See example imports written in [JS](test/import-variables.js) and [JSON](test/import-variables.json).
129Currently only valid [custom property names] (beginning with `--`) are accepted.
130Not all valid [declaration value names] are accepted.
131
132### disableDeprecationNotice
133
134Silence the deprecation notice that is printed to the console when using `importFrom``.
135
136> postcss-env-function is deprecated and will be removed.
137> Check the discussion on github for more details. https://github.com/csstools/postcss-plugins/discussions/192
138
139[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
140[css-url]: https://cssdb.org/#environment-variables
141[discord]: https://discord.gg/bUadyRwkJS
142[npm-url]: https://www.npmjs.com/package/postcss-env-function
143
144[CSS Environment Variables]: https://drafts.csswg.org/css-env-1/
145[PostCSS]: https://github.com/postcss/postcss
146[PostCSS Environment Variables]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-env-function
147
148[custom property names]: https://drafts.csswg.org/css-variables-1/#typedef-custom-property-name
149[declaration value names]: https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value
Note: See TracBrowser for help on using the repository browser.