question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

First-class plain CSS functions

See original GitHub issue

Similar 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:open
  • Created 2 years ago
  • Reactions:4
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nex3commented, Oct 5, 2021

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() and meta.fn-args() which work analogously to meta.calc-name() and meta.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.

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);
}

It’s worth noting that this already works as written today.

0reactions
asyncLizcommented, Nov 15, 2022

I have started work on a proposal for this: #3446

That’s awesome! We’ll be following closely 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found