[MOOSE-356] FE: Extend Create WP Controls Script#332
Open
GeoffDusome wants to merge 4 commits intomainfrom
Open
[MOOSE-356] FE: Extend Create WP Controls Script#332GeoffDusome wants to merge 4 commits intomainfrom
GeoffDusome wants to merge 4 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this do/fix?
Important
Please note the "Visibility in Style subgroups" portion of the "Inspector group and panel" heading in the docs. While we have the ability to add controls to whatever Group we want, the actual outcome as to whether or not the control shows is completely up to WP and the state of that group (https://p.tri.be/i/vbaVGY, https://p.tri.be/i/6QYvh8). Here I put the Balanced Text control of the Heading block into the Typography group to test it out and the visibility of the control is completely dependent on whether or not the Typography group has an active control already. There doesn't seem to be a way around this.
Note
I mostly used AI for this change, guiding it and fixing some formatting where it made sense to me. In my opinion, the code is still readable and editable but it is starting to get pretty complex with features so I don't think we'd want to go much further than this. Please let me know if you have any concerns about it though.
Updates to the Create WP Controls utility and its docs: class handling for all control types, optional Inspector group/panel placement, conditional visibility, InputControl for number fields, and layout/visibility behavior in Style subgroups.
Create WP Controls utility (
create-wp-controls.js)Class application
applyClass-{value}(value slugified). Only the current value’s class is applied; others are removed.Conditional visibility
showWhen(attributes): Optional function on a control. When it returnsfalse, the control is hidden in the sidebar; saved attribute values still apply (e.g. classes/styles on output).Inspector group and panel
group(optional): Chooses which InspectorControls group the control goes in. Supports:default/settings,styles, and Style subgroups (color,typography,dimensions,border,background,position,effects,filter,content,list,advanced,bindings). Unset = default group.panel(optional): Panel title used only whengroupisdefaultorstyles. Default:"Custom Block Settings". Samepanelon multiple controls = same PanelBody; differentpanel= separate panel.stylesgroups render controls inside aPanelBody. All other groups render controls directly (no PanelBody). Controls in direct groups are wrapped in a full-width container (grid-column: 1 / -1, classcreate-wp-controls__group-control) so they don’t get a cramped layout in the Styles subgroup grids.Number control
__experimentalInputControlwithtype="number"from@wordpress/componentsinstead of__experimentalNumberControl, to align with the intended replacement and avoid a future migration.Code quality
determineControlToRender: Refactored from anifchain to aswitch (control.type)for consistency with the rest of the file.Documentation (
docs/create-wp-controls-script.md)applyClass-{value}).showWhenwith an example.groupandpanel, list of groups, rendering behavior, full-width wrapper for direct groups, and recommendation to usegroup: 'styles'with apanelwhen controls must always be visible in the Styles tab (since subgroups liketypography/colormay be hidden when the group has no active content).type="number") instead of NumberControl.Backward compatibility
group,panel, orshowWhenbehave as before: a single “Custom Block Settings” panel in the Settings tab.number-type controls keep the same config; only the underlying component (InputControl) changed.QA
Links to relevant issues
Pull request checklist
I've captured a screenshot or screencast of the changes and linked it above.No change, not necessary.