-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract the Global Styles Typography Panel into block-editor package #47356
Extract the Global Styles Typography Panel into block-editor package #47356
Conversation
Size Change: -22 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
packages/block-editor/src/components/global-styles/typography-panel.js
Outdated
Show resolved
Hide resolved
packages/edit-site/src/components/global-styles/typography-panel.js
Outdated
Show resolved
Hide resolved
You beat me to it @youknowriad! 😀 Nice work.
Yeah think we need to unify these. Worth noting is that there's already some duplication as I have been thinking that maybe it makes sense to move the theme styles and settings into So:
Makes sense. I don't see this mapping in this PR though?
Agreed. There's a lot of assumptions here that are difficult to validate (e.g. my comment about heading levels) until we try to use the same |
What's a good way to provide some design feedback on this one? As far as I can tell, the approach makes sense, and the typography panel looks right. The main disconnect I see between global styles and blocks, is that there's an almost but not quite connection between inspector panels and GS > Blocks sections. I.e. the mapping is right between typography and color, but layout has become a kitchen sink for any panel that doesn't have a GS section counterpart. |
@jasmussen yes, so far this is more technical so it allows to actually use the same code. So As far as nothing breaks (same typography settings, we can edit the typography styles properly...) we're on a good path. So far I'm only updating the "global styles UI" code, but I'll also touch the block inspector a biter later. |
Flaky tests detected in 143dc47. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4132145710
|
It looks like a reasonable direction to take 👍 the test failures seem genuine though. |
letterSpacing: true, | ||
textTransform: true, | ||
textDecoration: true, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is interesting to note here that the "default controls" are sourced from the block.json for the block inspector but they are actually "static" for the global styles. In other words, it's an inconsistency between say "button" panel in global styles and "button" panel in the block inspector.
I've considered removing the "defaultControls" prop and just "always" sourcing from the block.json but I thought maybe we should not change any behavior in the current PR and just leave this unification for its own PR.
settings, | ||
panelId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"panelId" and "as" prop go hand in hand. I believe there's so magic in the "InspectorControls" panel that "forces" us to do this. There might be a simpler way to do this but this is fine enough I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some explanatory docs here:
gutenberg/packages/components/src/tools-panel/types.ts
Lines 24 to 28 in 7cfbdfd
/** | |
* If a `panelId` is set, it is passed through the `ToolsPanelContext` and | |
* used to restrict panel items. Only items with a matching `panelId` will | |
* be able to register themselves with this panel. | |
*/ |
I don't really understand why it's necessary. Surely each block would have a different ToolsPanelContext
by virtue of the key={ clientId }
in BlockSupportToolsPanel
. If not then that seems like a bug in ToolsPanel
.
If it truly turns out to be necessary then could make this "more correct" by having an as
prop for the ToolsPanelItem
s.
🤷♂️ agree it's fine for now.
packages/block-editor/src/components/global-styles/typography-panel.js
Outdated
Show resolved
Hide resolved
I'm actually really satisfied about how this PR is going, I think it's in a state where we can consider moving forward. Just need to address the small details/tests... Would love more reviews here :) |
19e0eee
to
453e4a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code changes look good, and things seem to work well on my tests. But there is an end to test failure that seems relevant "Global styles variations › should apply custom colors and font sizes in a variation".
@jorgefilipecosta The e2e test failure should be fixed in the last commit 4a1508f The problem was that we were using This is what the commit is about, it touches a number of files, so I'm going to extract it to its own PR. |
841804c
to
143dc47
Compare
Related to #37064 and #47348
What?
A year ago now, I've opened a discussion in #37064 that proposes unifying the components that are used in the block inspector and global styles. The idea is that we'd have components that look like this:
That component would render a panel used to edit a given style (say "typography" or "colors"), the
value
has a well specified prop (that is mapped over the "style" object of a block or a global style "node" ). The idea is that we could use that exact same panel in both places, the only difference is a wrapper that map the "value" to the right place:This PR is a first step towards that.
How?
Right now this PR basically extracts the "TypographyPanel" from the global styles panel into a reusable component with the API as described above. I've reused that extracted component and mapped it into the global styles UI in edit-site but I haven't replaced the block inspector one (meaning at the moment, we still have two similar components within block-editor). There are some notes that would have to be answered to move forward with the block inspector integration and PR:
The component at the moment need to be rendered with aI've extracted a settings prop.GlobalStylesContext
meaning it's still a bit hard to reuse within the block inspector unless we addGlobalStylesContext
withBlockEditorProvider
somehow or that we remove that dependency by requiring another prop asettings
prop maybe.We need to implement "mapping" between the style object and the block attributes, it's basically the same format except for the "presets" where for some properties we don't store theI've implemented this for the typography styles.var|preset|value
format but instead "extract" that value to a separate dedicated block attribute (like color or background). I've long wanted to remove that exception from blocks but It would require a number of block deprecations. So it's probably safer here to start with a mapping function.Block inspector controls often have slots within them to allow third-party blocks to inject "extra" elements within these panels. It should be solvable but I haven't looked at it yet.Managed to solve this with some extra props (as, panelId props)Testing Instructions
This PR can also be considered a first step towards this issue #47348 as it will become easier to share the exact same components between these two contexts (local vs global)