Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit e2ae3b3

Browse files
dmarchenaMoOx
authored andcommitted
Added: new rgb() & hsl() functional notation (via postcss-color-rgb & postcss-color-hsl) (#330)
* Added: postcss-color-rgb & postcss-color-hsl for transpiling functional notation * Fix: CI error: Cannot find module postcss-value-parse Closes #300
1 parent d2095d2 commit e2ae3b3

File tree

10 files changed

+84
-0
lines changed

10 files changed

+84
-0
lines changed

docs/content/features.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,47 @@ Allows you to use case insensitive attributes.
442442
|
443443
[Plugin documentation](https://github.com/Semigradsky/postcss-attribute-case-insensitive)
444444

445+
## `rgb()` function (functional-notation)
446+
447+
Allows you to use its new syntax consisting of space-separated arguments and
448+
an optional slash-separated opacity.
449+
450+
You can also use number for color channels.
451+
452+
The alpha value accepts percentage as well as number and has been added to
453+
`rgb()` as optional argument. As a result, `rgb()` and `rgba()` are now
454+
aliases of each other.
455+
456+
```css
457+
div {
458+
background-color: rgb(100 222.2 100.9 / 30%);
459+
}
460+
```
461+
462+
[Specification](https://drafts.csswg.org/css-color/#rgb-functions)
463+
|
464+
[Plugin documentation](https://github.com/dmarchena/postcss-color-rgb)
465+
466+
## `hsl()` function (functional-notation)
467+
468+
Allows you to use its new syntax consisting of space-separated arguments and
469+
an optional slash-separated opacity.
470+
471+
`hsl()` now accepts angles (`deg`, `grad`, `rad`, `turn`) as well as numbers for
472+
hues and an optional percentage or number for alpha value. So, `hsl()` and
473+
`hsla()` are now aliases of each other too.
474+
475+
```css
476+
div {
477+
color: hsl(90deg 90% 70%);
478+
background-color: hsl(300grad 25% 15% / 70%);
479+
}
480+
```
481+
482+
[Specification](https://drafts.csswg.org/css-color/#the-hsl-notation)
483+
|
484+
[Plugin documentation](https://github.com/dmarchena/postcss-color-hsl)
485+
445486
## @todo
446487

447488
Any omissions of the CSS specifications (even in draft) that are subject to be

docs/content/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ title: cssnext - Use tomorrow’s CSS syntax, today.
139139
<li class="r-Grid-cell r-minS--1of2">
140140
<a href="/features/#attribute-case-insensitive">attribute case insensitive</a>
141141
</li>
142+
<li class="r-Grid-cell r-minS--1of2">
143+
<a href="/features/#rgb-function-functional-notation"><code>rgb()</code> function</a>
144+
<small class="cssnext-FeaturesList-small">
145+
(functional-notation)
146+
</small>
147+
</li>
148+
<li class="r-Grid-cell r-minS--1of2">
149+
<a href="/features/#hsl-function-functional-notation"><code>hsl()</code> function</a>
150+
<small class="cssnext-FeaturesList-small">
151+
(functional-notation)
152+
</small>
153+
</li>
142154
</ul>
143155
<small
144156
class="cssnext-FeaturesList-small"

docs/content/playground.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
}
5858
a:hover { color: gray(255, 50%) }
5959
a:active { color: rebeccapurple }
60+
a:focus { background-color: rgb(255 153 0 / 33%); outline: 3px solid hsl(1turn 60% 50%); }
6061
a:any-link { color: color(var(--highlightColor) blackness(+20%)) }
6162

6263
/* font stuff */

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
"postcss-color-function": "^2.0.0",
3434
"postcss-color-gray": "^3.0.0",
3535
"postcss-color-hex-alpha": "^2.0.0",
36+
"postcss-color-hsl": "^1.0.5",
3637
"postcss-color-hwb": "^2.0.0",
3738
"postcss-color-rebeccapurple": "^2.0.0",
39+
"postcss-color-rgb": "^1.1.4",
3840
"postcss-color-rgba-fallback": "^2.0.0",
3941
"postcss-custom-media": "^5.0.0",
4042
"postcss-custom-properties": "^5.0.0",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.foo {
2+
color: hsl(.25turn 90% 70%);
3+
background-color: hsl(300grad 25% 15% / 70%);
4+
border: 1px solid hsl(0 5% 10% / .6);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.foo {
2+
color: hsl(90, 90%, 70%);
3+
background-color: hsla(270, 25%, 15%, .7);
4+
border: 1px solid hsla(0, 5%, 10%, .6);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.foo {
2+
color: rgb(255 200 205);
3+
background-color: rgb(100 222.2 100.9 / 30%);
4+
border: 1px solid rgb(0% 5% 10% / .7);
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.foo {
2+
color: rgb(255, 200, 205);
3+
background-color: rgba(100, 222, 101, .3);
4+
border: 1px solid rgba(0%, 5%, 10%, .7);
5+
}

src/features-activation-map.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export default {
1212
// mediaQueriesRange: [ null ],
1313
// customSelectors: [ null ],
1414
// colorRebeccapurple: [ null ], // @todo can be done easily
15+
// colorHsl: [ null ],
1516
// colorHwb: [ null ],
17+
// colorRgb: [ null ],
1618
// colorGray: [ null ],
1719
// colorHexAlpha: [ null ],
1820
// colorFunction:[ null],

src/features.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export default {
3636
// https://npmjs.com/package/postcss-color-hwb
3737
colorHwb: (options) => require("postcss-color-hwb")(options),
3838

39+
// https://npmjs.com/package/postcss-color-hsl
40+
colorHsl: (options) => require("postcss-color-hsl")(options),
41+
42+
// https://npmjs.com/package/postcss-color-rgb
43+
colorRgb: (options) => require("postcss-color-rgb")(options),
44+
3945
// https://npmjs.com/package/postcss-color-gray
4046
colorGray: (options) => require("postcss-color-gray")(options),
4147

0 commit comments

Comments
 (0)