Open Prinzhorn opened 6 years ago
TODO: the observedAttributes getter needs to be aware of all possible conditions to add them to the list. To allow custom conditions in userland we face the same issue as with custom behaviors. They need to be specified before the custom element is registered or otherwise the observedAttributes getter won't know about them.
done.
Also note: it should be possible to not define the default at all. So using fluidtext_m
will only add the fluidtext behavior for m and up. It will be completely removed otherwise.
Also note: it should be possible to not define the default at all. So using fluidtext_m will only add the fluidtext behavior for m and up. It will be completely removed otherwise.
Note that this might break stuff like querySelectoAll('[layout]')
. The element at least needs to be tagged with an empty layout
attribute then ;)
In theory this can be done in userland. A
responsive
behavior could simply overwrite other attributes (behaviors) depending on different conditions. E.g.But nesting attributes as strings inside attributes looks hell and no. Just no.
Instead we can make this part of the very core, since it is an essential feature anyway. A-frame allows the same component (we call it behavior) to be added multiple times by specifying an id using two underscores. E.g.
<a-entitiy thing__foo="" thing__bar="">
. Inspired by this idea I think we could use a similar naming convention to make behaviors' properties responsive.The following example defines an element which uses the
left
andright
guides (basically full width) as a default. It also defines a spacing of10vh
. Now if thedesktop
condition is met, thelayout.guides
property is overwritten withleft center
, making the element span the left half. Spacing is untouched.These type of conditions could be anything, not just the browser width. A condition is basically a named function, in this case
desktop
. But you might as well define atouch
condition or aie9
condition. And of course they don't just apply to thelayout
behavior, but literally every behavior. And since many behaviors add functionality and not just styling, this allows to declaratively change the functionality without writing any code. For the behavior itself this is completely transparent. It doesn't know about conditions. It just receives new props.In the above example the
layout
attribute is actually just a shorthand forlayout_default
. Thedefault
condition is always true.TODO: the conditions need to have an order/specifity. E.g. the
default
condition has the lowest specifity and will be overwritten be any other matching condition.TODO: the
observedAttributes
getter needs to be aware of all possible conditions to add them to the list. To allow custom conditions in userland we face the same issue as with custom behaviors. They need to be specified before the custom element is registered or otherwise theobservedAttributes
getter won't know about them.