Strategy for styling components with custom properties #164
Replies: 3 comments 1 reply
-
Actually, it sounds good but I have some concerns. While we define the CSS variable, we usually add a component name in front of it (such as
Actually, my main concern, while creating the academy button, I changed the theme according to the academy button colors. But if we let customize the CSS variable in the parent scope, every component using
If the developer customizes in the parent scope, any component can be changed with the new colors. And this situation may not be noticed. |
Beta Was this translation helpful? Give feedback.
-
We concluded this discussing as moving private css variables to an wrapping element inside the component. Here is a change for As a further action, I think we can add a document to about this decision in our contribution guideline. I mentioned this in #73 |
Beta Was this translation helpful? Give feedback.
-
We have a document that covers the guidance mentioned here. https://baklava.design/?path=/docs/documentation-customizing-components-style--page |
Beta Was this translation helpful? Give feedback.
-
We set default values of custom properties for components like below:
In this way we are not able to customise
--bl-badge-color
in a scope of parent element likeYou can see the demonstration of the issue here: https://jsfiddle.net/wa0bdxmz/1/
It's a bit controversy to define expected behaviour here. It would be helpful to be able to set a custom property of all of the components in a scope. Also while we develop
tab
component, we needed to set custom property ofbl-badge
insidebl-tab
. Currently we can not do this outside ifbl-tab
component doesn't pass this variable from it's parent to thebl-badge
inside.On the other hand, some finds this a safer approach that will prevent developers to style many components unintentionally. Ionic, for example, uses this approach for some of its components: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/picker/picker.scss
But since our custom property names are prefixed with the name of component (like
--bl-badge-...
) I also find it already gives the feeling that you will set this property for all of the badges inside the context you are setting. So if developer writes:they will already be aware that this will effect all of the badge components inside
.container
element.I want to hear your opinions about this. @leventozen @DamlaDemir
Beta Was this translation helpful? Give feedback.
All reactions