W3C home > Mailing lists > Public > www-style@w3.org > May 2012

Re: [css-variables] Maintain link between var declaration and use

From: Chris Eppstein <chris@eppsteins.net>
Date: Mon, 21 May 2012 17:10:14 +0100
Message-ID: <CANyEp6V8e_V-Z6KeDCcnU9zSVnJGgsdTKeYMdvBKHqiUb4GgVg@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: Christoph Päper <christoph.paeper@crissov.de>, www-style list <www-style@w3.org>
Your edge cases needn't affect the syntax of the common case.

If you need a read-time variable default you can simply define a function
for that case:

var-default($some-color, blue)

Similarly for the inheritance issues.

But we need to make the common use case of a globally set value and a basic
read drop-dead simple for authors to read and write; the function notation
does not accomplish this.

Chris

On Mon, May 21, 2012 at 3:46 PM, Tab Atkins Jr. <jackalmage@gmail.com>wrote:

> On Mon, May 21, 2012 at 5:43 AM, Chris Eppstein <chris@eppsteins.net>
> wrote:
> >> That gains us nothing, though.  I see no good reason to switch away
> >> from dashes unless we're going full-on to something that looks like a
> >> function.
> >
> > Just use $ as a sigil. Function notation is such a bad idea. We don't
> need the ability to prefix variables, we don't need the extra keystrokes,
> we don't need the faux parser compatibility.
> >
> > Follow Sass's lead on this, we got it right.
>
> We *do* need the ability to specify a default value for when the
> variable you're referencing isn't defined, though.  Unfortunately,
> after some research I've decided that the !default idea (opposite of
> !important, puts it at a new, lower, specificity level) doesn't work
> very well.
>
> In one of the major use-cases for default values (accumulating a value
> in a variable repeatedly, or cycling through variables) having a
> default argument gives smaller, easier-to-understand code.  Without
> it, you have to write two selectors, and make sure the second only
> selects descendants of the first, so you can first provide a value and
> then start interacting with it.
>
> In the other major use-case for default values (using variables as a
> hook for styling Web Components, allowing author-declared vars to
> inherit into the shadow tree), !default unfortunately doesn't work at
> all, because *any* specified value, no matter the specificity, wins
> over inherited values.  The default argument, on the other hand, only
> has effect when inheritance doesn't produce anything.
>
> Both of those cases, and several more, also want the ability to refer
> to the inherited value of a variable, rather than the current value.
> This requires some sort of extra syntax - right now I'm leaning toward
> another function.  You can't overload the $ to do anything new.
>
> I think SASS made the right choice for the specific type of variable
> it uses - global vars with no structure beyond the dependency graph
> you set up yourself just don't have much complexity, so using a simple
> non-extensible syntax for it is okay.  But I think it's *too* simple
> for what CSS variables needs.
>
> ~TJ
>
Received on Monday, 21 May 2012 16:11:05 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:54 GMT