CSS Custom Functions and Mixins
feature request
### What would you want to propose?
Spec: https://drafts.csswg.org/css-mixins/
The time has come. SCSS mixins are coming to CSS. Currently, this is hidden behind a feature flag in Chrome. We need a PostCSS preprocessor for it.
### Suggested solution
Similar to https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-media, I would recommend to create a `postcss-custom-functions` package that adds the functionality. In the future, the (polyfil at build time) could be removed. However, that will certainly take several years.
```css
@function --shadow(--shadow-color <color> : inherit) {
/* If --shadow-color argument isn't passed,
or doesn't successfully parse as a <color>,
try to use the --shadow-color *property*
from the element instead */
/* var(--shadow-color) refers to the --shadow-color parameter,
rather than a custom property,
but can still use a fallback value as normal */
result: 2px 2px var(--shadow-color, black);
}
.foo {
--shadow-color: blue;
box-shadow: --shadow(); /* produces a blue shadow */
/* or just */
box-shadow: --shadow(blue);
}
```
### Additional context
_No response_
### Validations
- [x] Follow our [Code of Conduct](https://github.com/csstools/postcss-plugins/blob/master/CODE_OF_CONDUCT.md)
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
### Would you like to open a PR for this feature?
- [ ] I'm willing to open a PR
关闭于 2025-12-30 0 条评论