Default props/classes per element. #1683
Replies: 5 comments 2 replies
-
We found that inheritance and method wrapping are enough. But it's good to challenge base assumptions. Do you already have a syntax in mind? |
Beta Was this translation helpful? Give feedback.
-
I would need to think about it. I wanted to see if anyone thought it was worth spending any time on first. I only got as far as getting tired of copying and pasting so far. 🤣 Both of the strategies you listed are definitely legitimate but having something baked in feels better. |
Beta Was this translation helpful? Give feedback.
-
I could imagine something like ui.button.default_props = 'outline rounded'
ui.label.default_classes = 'border'
ui.card.default_style = 'background-color: #eee' Or maybe it's better to go with class methods (similar to the existing methods ui.button.default_props('outline rounded')
ui.label.default_classes('border')
ui.card.default_style('background-color: #eee') If we're lucky we only need to change the implementation of |
Beta Was this translation helpful? Give feedback.
-
Both look good but the method is probably best for consistency. I think the single 'element' only change might be possible. It sounds like this idea might have some legs. I can try to submit a draft PR this week so the mechanics could be looked at more closely. Another idea I had that could be implemented in parallel if you guys thought it was worth looking into would be an 'on_render' callback. This would fire on instantiation of an element and could be registered via decorators I think. |
Beta Was this translation helpful? Give feedback.
-
PR #1689 is merged. ✔️ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In my projects I am constantly applying identical props/classes to all elements. It seems like it would be nice to be able to apply a default for some of these attributes that would be reused on every element you create. I know I could probably override the element classes or do something else but I thought there might be something to the idea which might warrant a change. I am not sure if this was asked before, I couldn't find something similar in a search.
Beta Was this translation helpful? Give feedback.
All reactions