Repository navigation
Global Styles: List elements alongside blocks #81645
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
Open
MaggieCabrera
wants to merge
27
commits into
trunk
Choose a base branch
from
codex/global-styles-forms-section
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+847
−501
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ac28493
Global Styles: Add Forms section
MaggieCabrera 2787163
Global Styles: Add Elements section
MaggieCabrera b362992
Global Styles: Give elements their own home and the full control set
MaggieCabrera e5ccb54
Global Styles: Preview elements with the site's own styles
MaggieCabrera 568979a
Global Styles: List elements in one flat list with blocks
MaggieCabrera f1a3a1b
Global Styles: Resolve an element's styles once per screen
MaggieCabrera f895665
Global Styles: Share border handling and the CSS capability check
MaggieCabrera e42c081
Global Styles: Restore the Text and All headings entries and fix CI
MaggieCabrera 4b31bf3
Global Styles: Reformat for the wp-prettier upgrade on trunk
MaggieCabrera c8632a5
Icons: Move the formInput changelog entry to Unreleased
MaggieCabrera aac3306
Global Styles: Mention elements in the Blocks & Elements description
MaggieCabrera 2a92d72
Blocks: Keep text alignment for elements in Global Styles
MaggieCabrera 72cd2f8
Global Styles: Offer states on the link and button element screens
MaggieCabrera 984ba05
Global Styles: Show the default background size on element screens
MaggieCabrera a330047
Global Styles: Use one route for the element screens
MaggieCabrera c129bee
Global Styles: Share element titles between the list and their screens
MaggieCabrera c706df8
Global Styles: Restore trunk's formatting of a media query
MaggieCabrera 5410a24
Global Styles: Drop the deprecated spacer from the element screen
MaggieCabrera a19876a
Global Styles: Keep trunk's Text row under Typography
MaggieCabrera 4703e54
Move this PR's changelog entries back under Unreleased
MaggieCabrera 1680f55
Global Styles: Drop the custom styles dot from element rows
MaggieCabrera f5c7771
Global Styles: Keep the border helper in the block screen
MaggieCabrera 57d9d27
Global Styles: Inline the customized check for elements
MaggieCabrera e3cca76
Global Styles: Check that searching lists matching elements
MaggieCabrera 5ba39ae
Style Book: Show the Text category on element screens
MaggieCabrera cdb44e0
Global Styles: Match element names and group titles in search
MaggieCabrera f2115f4
Fix the formatting of the heading styles end-to-end test
MaggieCabrera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { useMemo } from '@wordpress/element'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { getBlockType } from '@wordpress/blocks'; | ||
| import { | ||
| __unstableIframe as Iframe, | ||
| __unstableEditorStyles as EditorStyles, | ||
| store as blockEditorStore, | ||
| // @ts-expect-error: Not typed yet. | ||
| } from '@wordpress/block-editor'; | ||
|
|
||
| interface ElementPreviewProps { | ||
| element: string; | ||
| } | ||
|
|
||
| /* | ||
| * Centres the sample and strips the canvas chrome. Everything the sample | ||
| * actually looks like comes from the site's own stylesheet. | ||
| */ | ||
| const PREVIEW_CSS = ` | ||
| body { | ||
| margin: 0; | ||
| padding: 16px; | ||
| min-height: 100px; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| text-align: center; | ||
| overflow: hidden; | ||
| } | ||
| figure.wp-block-image img.global-styles-ui-element-preview__media { | ||
| display: block; | ||
| width: 100%; | ||
| height: 44px; | ||
| max-height: 44px; | ||
| border-radius: 2px; | ||
| object-fit: cover; | ||
| aspect-ratio: auto; | ||
| } | ||
| figure { | ||
| margin: 0; | ||
| max-width: 160px; | ||
| } | ||
| blockquote { | ||
| margin: 0; | ||
| max-width: 220px; | ||
| } | ||
| blockquote p { | ||
| margin: 0 0 4px; | ||
| } | ||
| `; | ||
|
|
||
| /** | ||
| * Renders a sample of an element using the site's own styles. | ||
| * | ||
| * The sample is real markup carrying the classes the element's selector | ||
| * targets, rendered in the editor's iframe with the generated stylesheet, so it | ||
| * picks up every panel, the theme's fonts and the cascade, rather than a list of | ||
| * properties copied across by hand. | ||
| * | ||
| * @param props | ||
| * @param props.element The element being previewed. | ||
| */ | ||
| export default function ElementPreview( { element }: ElementPreviewProps ) { | ||
| const styles = useSelect( | ||
| ( select ) => select( blockEditorStore ).getSettings().styles, | ||
| [] | ||
| ); | ||
|
|
||
| const editorStyles = useMemo( | ||
| () => [ ...( styles ?? [] ), { css: PREVIEW_CSS } ], | ||
| [ styles ] | ||
| ); | ||
|
|
||
| // Show a caption on the image the Image block uses for its own example, | ||
| // rather than keeping a second copy of that URL here. | ||
| const imageUrl = getBlockType( 'core/image' )?.example?.attributes?.url as | ||
| string | undefined; | ||
|
|
||
| let sample; | ||
| switch ( element ) { | ||
| case 'button': | ||
| // The class is half of the element's selector, so a button only | ||
| // picks up the element's styles when it carries it. | ||
| sample = ( | ||
| <button className="wp-element-button" type="button"> | ||
| { __( 'Call to action' ) } | ||
| </button> | ||
| ); | ||
| break; | ||
| case 'textInput': | ||
| sample = ( | ||
| <input type="text" defaultValue={ __( 'Text' ) } readOnly /> | ||
| ); | ||
| break; | ||
| case 'select': | ||
| sample = ( | ||
| <select> | ||
| <option>{ __( 'Select an option' ) }</option> | ||
| </select> | ||
| ); | ||
| break; | ||
| case 'caption': | ||
| sample = ( | ||
| <figure className="wp-block-image"> | ||
| { imageUrl && ( | ||
| <img | ||
| className="global-styles-ui-element-preview__media" | ||
| src={ imageUrl } | ||
| alt="" | ||
| /> | ||
| ) } | ||
| <figcaption className="wp-element-caption"> | ||
| { __( 'A caption for the image above' ) } | ||
| </figcaption> | ||
| </figure> | ||
| ); | ||
| break; | ||
| case 'cite': | ||
| sample = ( | ||
| <blockquote> | ||
| <p>{ __( 'In quoting others, we cite ourselves.' ) }</p> | ||
| <cite>{ __( 'Julio Cortázar' ) }</cite> | ||
| </blockquote> | ||
| ); | ||
| break; | ||
| case 'link': | ||
| sample = <a href="#anchor">{ __( 'A link' ) }</a>; | ||
| break; | ||
| case 'heading': | ||
| // The shared heading entry has no tag of its own; any level shows | ||
| // what it sets, and h2 is the most common in content. | ||
| sample = <h2>{ __( 'Aa' ) }</h2>; | ||
| break; | ||
| default: { | ||
| // The heading level elements are named after their tag. | ||
| const Tag = ( /^h[1-6]$/.test( element ) ? element : 'p' ) as | ||
| 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p'; | ||
| sample = <Tag>{ __( 'Aa' ) }</Tag>; | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div className="global-styles-ui-element-preview"> | ||
| <Iframe | ||
| tabIndex={ -1 } | ||
| readonly | ||
| title={ __( 'Element preview' ) } | ||
| aria-hidden="true" | ||
| > | ||
| <EditorStyles styles={ editorStyles } /> | ||
| { sample } | ||
| </Iframe> | ||
| </div> | ||
| ); | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Since
ELEMENT_BLOCK_SUPPORTSstarts fromROOT_BLOCK_SUPPORTS, elements keepcontentSizeandwideSize. The width controls never render becauseScreenElementdoesn't passincludeLayoutControls, butuseHasDimensionsPanelstill counts them. So on a theme that sets layout widths without enabling padding or margin (noappearanceTools), every element screen shows an empty "Dimensions" panel. FilteringcontentSizeandwideSizehere alongsideblockGapwould fix it. The expected lists intest/private-selectors.jswould need updating too.