Flexible `style` property for every component

I would like to propose adding a style property to the design panel of every component, such that we can modify any css attribute in-line, not only a select few present in the designer.

While we can modify any css attribute via Roles, I often find myself wanting to tweak just one specific button, image, etc., and it gets a tad annoying having to create a whole new Role that you would only use for one instance of a component. Moreover, the role dropdown list gets quite cluttered with this approach.

Would it be an idea to have a generic style property for each component where you could just write the raw in-line style string and specify the values for an arbitrary selection of attributes? E.g. like in the example below:

If there are any conflicts between the values of attributes specified in this style property and those specified in the standalone properties (e.g, if background-color is specified both in the style property and the standalone background_color property), then whatever’s in the style property could take priority as it would likely be used by more advanced users.

It would allow developers much greater flexibility in applying style changes to individual instances of components, rather than having to create a new Role that may only be used once.

1 Like

I like the idea, as long as somebody includes pointers to syntax and semantics of the entries.

Many folks come to Anvil because they don’t know HTML, CSS, Javascript (and its myriad frameworks), etc.; don’t want to know; and have no idea what search terms to use when looking for those things.

Take the existing border entry, for example. You can type almost anything in there, with no guidance whatsoever. Get anything even slightly wrong, and it will be ignored. Silently. Nothing to tell you what went wrong. Nothing to learn from. Anvil’s documentation assumes that you already know what belongs in these fields, what works, what doesn’t, what’s safe, what isn’t.

To be effective, this style field will have to be different. It doesn’t have to repeat existing documentation, but it will have to point to current, accurate documentation of its allowable contents, preferably aimed not at CSS experts, but at Anvil’s most common developers.

1 Like

Hey Phil, I’m not sure I completely understood your argument.

I feel like even now if someone wants to do more specific styling modifications they have to delve at least somewhat into CSS. For example I wouldn’t know what to write in the border property unless I google it. Anvil’s docs just say “The border of this component. Can take any valid CSS border value.” If you use Roles you also need to dive into CSS.

Yes, this property would be somewhat different in the sense that it doesn’t take a single value, but the whole declaration block. But I think that this could be properly explained, and fairly straightforward to understand with some examples.

It could also be hidden behind an “advanced” dropdown / button click so as to not intimidate new users. There are solutions.

In the end, nobody would have to to use it any more so than they have to use Roles or Anvil’s other more ‘advanced’ features. But it would give a lot more optionality when it comes to styling to those who need it.

I agree. Moreover, Anvil doesn’t have to provide them, as long as it points to the proper documentation that has such examples.

It’s the current lack of such pointers, in the current documentation, that rubs me the wrong way.

Absolutely. And I would love to have the chance to use a generalized style field, even in place of the current, piecemeal fields.

I simply note that if most current Anvil developers are to use style successfully, then such documentation pointers will be more necessary than they already are for border, due to style’s much broader scope.

This would actually be an opportunity, for a clever CSS expert: design and build an Anvil App that can

  1. translate a widget’s CSS into terms a typical Anvil user can reasonably interpret, and
  2. translate the other way, back into CSS, for filling into your style field.

That would actually be a great IDE feature, come to think of it. After all, the IDE has all the CSS context, the values that “cascade” on down to the widget, from its environment, and are not stated explicitly in the widget’s (style’s) CSS itself.

With practical help like that, I think that your style idea could really take off.

2 Likes