Consistency and coherence for the high level UI components to edit styles (global styles and block styles) #37064
Replies: 5 comments 4 replies
-
Thanks for getting this discussion going @youknowriad 🙇
Overall, I really like the approach. Including the addition of the The benefits from the increase in consistency across components reach beyond easing maintenance burdens to reducing barriers for people to use the components with confidence. It should also provide solid examples to follow when creating new components. In terms of covering all our use-cases, others probably have broader experience here and can better evaluate this. For me though, it appears like it will cover global styles, block supports and ad hoc uses that I've seen, so looks promising. My gut feel around the potential performance hit is that it could be a reasonable trade-off but it would be nice to quantify it.
If we can make these components generic enough, I think the
Another possible advantage of including the components within the Wherever the documentation ends up, I think it would be good to define some best practices. In particular, how to use them in an ad hoc manner. For example, ensuring that an ad hoc solution's style object pulled from a block's attributes doesn't interfere with block supports or similar. If we proceed with this proposal, let me know how I can help out, I'd like to get involved 🙂 |
Beta Was this translation helpful? Give feedback.
-
Just a +1 I like the sound of this proposal, too! Having a clean and consistent API for these controls will be really beneficial, particularly in reducing some of the edge cases between the block editor and global styles.
That sounds good to me, too. At first glance, these components don't appear to rely on block editor state, since they're passed the style objects and callbacks that they need. So that package (or nesting them in a directory within that package) sounds like a good candidate to me! |
Beta Was this translation helpful? Give feedback.
-
I believe that The proposed components deal with settings and style objects which are quite specific to how gutenberg and the block editor work, and therefore I'm not sure that Otherwise, I definitely agree that, in order to maintain a good components library, tools like Storybook and a good documentation (including best practices) are a requirement. Even in terms of how to "signal" that these are quite a high-level components, currently we don't have any particular agreement on how to classify components in |
Beta Was this translation helpful? Give feedback.
-
I agree with this. These components receive a style shape and mutate it; I don't think they fit the component package. We already have lower-level counterparts in the components package e.g.: something that receives value onChange (as a raw value, not a style shape) and for future components, we should continue to do so. The UI should be on the components package with a very generic API, and then we have higher-level versions; now, they usually are on the block editor. I'm not sure about where they should be in the future. Regarding a component like:
The colors are implemented using PanelColorGradientSettings, a component that allows changing multiple colors at the same time and deals with things like color indications.
I'm not sure if we gain much in having each color in a component. Maybe we can have a component that includes all the colors and uses PanelColorGradientSettings inside? I guess we can start exploring this approach on the other controls besides colors and see where it goes, and then if it is a good fit for the other places, we can see how to make it work for the colors. We have an issue that we can not share code between block-editor and global styles without making that code part of our public API. That causes us to fear creating reusable artifacts between the two packages. We end up duplicating code or following different logics. I think if we could share code between these two packages without it being public from the begging, we would have much more reusability, and we would see natural API's patterns to emerge. |
Beta Was this translation helpful? Give feedback.
-
One thing that cross my mind that is not addressed in the proposal above is the fact that some blocks add additional controls to "ToolPanels" (dimensions, ...) using Slots. The questions that arise here for me is:
Any thoughts here? |
Beta Was this translation helpful? Give feedback.
-
The UI components we have right now to edit styles (colors, typography, dimensions...) grew organically based on use-cases over time but overall we lack consistency and organisation in our code base:
It is becoming very hard to maintain as we keep iterating and introducing new props, special cases, duplicate components...
Is there a way we can improve the situation and clarify:
Solution
Here's a potential (maybe naive) solution.
Examples
Base Principles:
value
prop corresponds to the actual style object for the current context (context could block instance, root global styles, block context in global styles, or element context in global styles). The format of the object can be close to the one used in Global Styles.onChange
is just a callback triggered upon change of thevalue
prop.settings
corresponds to the whole settings object of the current context, it would contain things like "enable/disable things", presets... The format of that object can be close the one used in Global Styles as well.inherit
prop is also a "style object" similar to thevalue
prop but it contains the style that is inherited from parent contexts (it can be optional for a start but it's useful in some situtations)Flexible usage
getStyleFromAttributes
,getAttributesFromStyle
,getSettingsForCurrentBlock
,getStyleFromGlobalStylesContext
,getGlobalStyleObjectFromValue
andgetSettingsForCurrentGlobalStylesContext
are all functions that we build once and use everywhere.Potential downside
Open Questions
cc @jorgefilipecosta @oandregal @mcsf @mtias @ciampo @gziolo @aaronrobertshaw @andrewserong
Beta Was this translation helpful? Give feedback.
All reactions