First-class plain CSS functions
See original GitHub issueSimilar to the new calculation type, it would be fantastic to add first-class support for the var()
function as a new variable
type.
Desired Features
Meta type recognition
$custom-prop: var(--foo);
@debug meta.type-of($custom-prop); // "variable"
Inspection of name and values
$custom-prop: var(--foo, 8px);
@debug meta.var-name($custom-prop); // "--foo"
@debug meta.var-value($custom-prop); // 8px
Interpolation
$length: 8px;
$custom-prop: var(--bar, red);
.foo {
color: var(--foo, $custom-prop);
padding: var(--baz, $length);
}
.foo {
color: var(--foo, var(--bar, red));
padding: var(--baz, 8px);
}
Motivation
This would be of particular use to the Material Web team, which uses a custom Map data structure to manage CSS variables. This is necessary since a var()
is a string and the type of the value is lost when attempting to parse/inspect it.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:8 (3 by maintainers)
Top Results From Across the Web
first - CSS: Cascading Style Sheets - MDN Web Docs
The :first CSS pseudo-class, used with the @page at-rule, represents the first page of a printed document. (See :first-child for general ...
Read more >What is the first class function in JavaScript ? - GeeksforGeeks
JavaScript treat function as a first-class-citizens. This means that functions are simply a value and are just another type of object. Example: ...
Read more >What are first-class vs higher-order functions in JavaScript?
First-class functions are functions that are treated as variables. They can also be parsed into other functions as arguments. In JavaScript, functions are ......
Read more >Request for Comments: First-Class Calc - Sass
To be more specific: a calc() expression will be parsed according to the CSS syntax, with additional support for Sass variables, functions, ...
Read more >First-Class Functions in JavaScript | by Ian Grubb - Medium
It does this by supporting the use of first-class functions — functions that can be stored in variables and treated like data.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A more general way to do this would be to treat all plain-CSS functions as first-class values whose names and arguments could be directly inspected, rather than eagerly converting them to strings. So we’d something like
meta.fn-name()
andmeta.fn-args()
which work analogously tometa.calc-name()
andmeta.calc-args()
. We could potentially even subsume the latter into the former by saying that calculations count as plain CSS functions for the purposes of built-in functions.It’s worth noting that this already works as written today.
That’s awesome! We’ll be following closely 😄