styletron / styletron

:zap: Toolkit for component-oriented styling
https://www.styletron.org
MIT License
3.32k stars 100 forks source link

More robust value fallback support #6

Open rtsao opened 8 years ago

rtsao commented 8 years ago

Value fallbacks (i.e. multiple values for a single property) are useful.

Because order is not currently guaranteed, using value fallbacks with styletron will not be robust.

menelike commented 7 years ago

@rtsao Not sure if I understand "value fallbacks" right, if it means deterministic resolution, then https://github.com/rofrischmann/fela/issues/165 might be interesting. A atomic CSS cache (like styletron's) could solve that issue particially.

joeshub commented 7 years ago

@menelike here's an example of a value fallback in CSS for fonts:

font-family: 'Roboto', arial, sans-serif; I imagine in Styletron use case would be:

{
    fontFamily: ['Roboto', 'arial', 'sans-serif'],
}

although you end up with the last array element being used instead letting the browser fall back gracefully.

skellyb commented 7 years ago

It looks like injectStyle already supports an array of values, but instead of creating fallbacks, multiple classes are being created. It's not clear to me what the use case for this functionality would be, since order is unreliable.

Here's a real use-case I'm trying to support:

// set font-size to 8vw, falling back to 32px if browser doesn't support that unit type
{ fontSize: ['32px', '8vw']  }

Currently, that would create two classes. I'd like it create one, with two rules in the order declared, like so:

.a { font-size: 32px; font-size: 8vw; }

Would it be reasonable to change how arrays of values are being handled? If so, I'd be happy to help.

frenic commented 7 years ago

I could give this a shot.

TxHawks commented 7 years ago

I'm trying to understand if the use case requested by @skellyb ({ fontSize: ['32px', '8vw'] } --> .a { font-size: 32px; font-size: 8vw; }) is supported by #145, into which #133 was merged to.

If it is, it'd be nice to add this to the documentation in some way (Happy to do it myself, once I actually undersand how deterministic fallbacks work).

grundmanise commented 6 years ago

Did anyone succeed in providing fallback values? for example for a background css prop.

tajo commented 5 years ago

This API/approach can be used? https://github.com/rofrischmann/fela/tree/master/packages/fela-plugin-fallback-value