Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-mixins] Allow mixins/functions to be called via custom properties #10006

Open
sorvell opened this issue Feb 27, 2024 · 0 comments
Open

[css-mixins] Allow mixins/functions to be called via custom properties #10006

sorvell opened this issue Feb 27, 2024 · 0 comments

Comments

@sorvell
Copy link

sorvell commented Feb 27, 2024

Allow functions and mixins to be called via custom properties to support some additional interesting use cases. The syntax in the current proposal seems like it might need a little tweaking to support this. Here's a rough sketch that needs a lot more fleshing out if this idea doesn't have some obvious fatal flaw.

The suggestion in the current proposal is that functions/mixins are global, and while this allows some composition, it's limited since it must be determined at thte point of consumption, and it's cumbersome (requiring some companion variable) for the caller to do so.

Basic Idea

Introduce a way to "call" mixins/functions, say, using a built-in function called call that accepts var:

@mixin --hover-focus(--hover; --focus;) {
  &:hover {
    @apply call(var(--hover), 2);
  }
  &:focus {
    @apply call(var(--focus), 4;
  }
}

@function --shadow(--x: 0; --y: 0; --color: black; --calc-blur;) {
  @return var(--x) var(--y) call(var(--calc-blur, --x, --y)) var(--color);
}

Use Cases

  • more robust composition of effects (the contrived examples above hint at this).
  • passing nested content to mixins as noted in the explainer.
  • as custom properties, mixins and functions could inherit down the tree to be applied elsewhere in the DOM, even cross-scope in Shadow DOM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants