-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Button Block]: Add padding block support #31774
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
Changes from all commits
1136357
4d93ddd
0fa1556
0c298fc
1286e6b
ef6fb3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getInlineStyles } from './style'; | ||
|
|
||
| // This utility is intended to assist where the serialization of the spacing | ||
| // block support is being skipped for a block but the spacing related CSS | ||
| // styles still need to be generated so they can be applied to inner elements. | ||
|
|
||
| /** | ||
| * Provides the CSS class names and inline styles for a block's spacing support | ||
| * attributes. | ||
| * | ||
| * @param {Object} attributes Block attributes. | ||
| * | ||
| * @return {Object} Spacing block support derived CSS classes & styles. | ||
| */ | ||
| export function getSpacingClassesAndStyles( attributes ) { | ||
| const { style } = attributes; | ||
|
|
||
| // Collect inline styles for spacing. | ||
| const spacingStyles = style?.spacing || {}; | ||
| const styleProp = getInlineStyles( { spacing: spacingStyles } ); | ||
|
|
||
| return { | ||
| style: styleProp, | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import { | |
| useBlockProps, | ||
| __experimentalUseBorderProps as useBorderProps, | ||
| __experimentalUseColorProps as useColorProps, | ||
| __experimentalGetSpacingClassesAndStyles as useSpacingProps, | ||
| __experimentalLinkControl as LinkControl, | ||
| } from '@wordpress/block-editor'; | ||
| import { rawShortcut, displayShortcut } from '@wordpress/keycodes'; | ||
|
|
@@ -199,6 +200,7 @@ function ButtonEdit( props ) { | |
|
|
||
| const borderProps = useBorderProps( attributes ); | ||
| const colorProps = useColorProps( attributes ); | ||
| const spacingProps = useSpacingProps( attributes ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify why this is needed here? Ideally padding support is enabled for blocks by just adding a block support flag without touching the block itself at all.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is because of the extra wrapper of the button block? That wrapper is hurting us a lot, ideally we should find ways to remove it without breaking changes. We tried this in the past but reverted. I wonder if we could make it opt-in somehow. It seems for now we're just accepting the less than ideal button markup. cc @mtias
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely worth considering and exploring. I'm not too sure of what was the case with the extra wrapper. |
||
| const ref = useRef(); | ||
| const blockProps = useBlockProps( { ref } ); | ||
|
|
||
|
|
@@ -231,6 +233,7 @@ function ButtonEdit( props ) { | |
| style={ { | ||
| ...borderProps.style, | ||
| ...colorProps.style, | ||
| ...spacingProps.style, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be ported to edit.native.js as well? Asking because I don't know :) and I can't yet get the native mobile test env running locally.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } } | ||
| onSplit={ ( value ) => | ||
| createBlock( 'core/button', { | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.