-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add width block supports under dimensions. #71905
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
769bb54
89ed419
55402fe
36a526d
105a250
ab2591f
257c2fe
e9ace72
2aaaea4
5ba8dde
a609173
63a31d3
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,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/10470 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/71905 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ export function useHasDimensionsPanel( settings ) { | |
| const hasMargin = useHasMargin( settings ); | ||
| const hasGap = useHasGap( settings ); | ||
| const hasMinHeight = useHasMinHeight( settings ); | ||
| const hasWidth = useHasWidth( settings ); | ||
| const hasAspectRatio = useHasAspectRatio( settings ); | ||
| const hasChildLayout = useHasChildLayout( settings ); | ||
|
|
||
|
|
@@ -50,6 +51,7 @@ export function useHasDimensionsPanel( settings ) { | |
| hasMargin || | ||
| hasGap || | ||
| hasMinHeight || | ||
| hasWidth || | ||
| hasAspectRatio || | ||
| hasChildLayout ) | ||
| ); | ||
|
|
@@ -79,6 +81,10 @@ function useHasMinHeight( settings ) { | |
| return settings?.dimensions?.minHeight; | ||
| } | ||
|
|
||
| function useHasWidth( settings ) { | ||
| return settings?.dimensions?.width; | ||
| } | ||
|
|
||
| function useHasAspectRatio( settings ) { | ||
| return settings?.dimensions?.aspectRatio; | ||
| } | ||
|
|
@@ -206,6 +212,7 @@ const DEFAULT_CONTROLS = { | |
| margin: true, | ||
| blockGap: true, | ||
| minHeight: true, | ||
| width: true, | ||
| aspectRatio: true, | ||
| childLayout: true, | ||
| }; | ||
|
|
@@ -384,6 +391,17 @@ export default function DimensionsPanel( { | |
| }; | ||
| const hasMinHeightValue = () => !! value?.dimensions?.minHeight; | ||
|
|
||
| // Width | ||
| const showWidthControl = useHasWidth( settings ); | ||
| const widthValue = decodeValue( inheritedValue?.dimensions?.width ); | ||
| const setWidthValue = ( newValue ) => { | ||
| onChange( setImmutably( value, [ 'dimensions', 'width' ], newValue ) ); | ||
| }; | ||
| const resetWidthValue = () => { | ||
| setWidthValue( undefined ); | ||
| }; | ||
| const hasWidthValue = () => !! value?.dimensions?.width; | ||
|
|
||
| // Aspect Ratio | ||
| const showAspectRatioControl = useHasAspectRatio( settings ); | ||
| const aspectRatioValue = decodeValue( | ||
|
|
@@ -439,6 +457,7 @@ export default function DimensionsPanel( { | |
| ...previousValue?.dimensions, | ||
| minHeight: undefined, | ||
| aspectRatio: undefined, | ||
| width: undefined, | ||
| }, | ||
| }; | ||
| }, [] ); | ||
|
|
@@ -688,6 +707,23 @@ export default function DimensionsPanel( { | |
| /> | ||
| </ToolsPanelItem> | ||
| ) } | ||
| { showWidthControl && ( | ||
| <ToolsPanelItem | ||
| hasValue={ hasWidthValue } | ||
| label={ __( 'Width' ) } | ||
| onDeselect={ resetWidthValue } | ||
| isShownByDefault={ | ||
| defaultControls.width ?? DEFAULT_CONTROLS.width | ||
| } | ||
| panelId={ panelId } | ||
| > | ||
| <HeightControl | ||
|
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. The naming here is a little unfortunate, using a
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. Yes, we should change this. If width and height are going to share a control, then WidthHeightControl?
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. We had a similar discussion in the past when we implemented the font size preset UI. At that time, we discussed exposing a generic In a follow-up, we might be able to reconsider creating a more abstract component for sizing. |
||
| label={ __( 'Width' ) } | ||
| value={ widthValue } | ||
| onChange={ setWidthValue } | ||
| /> | ||
| </ToolsPanelItem> | ||
| ) } | ||
| { showAspectRatioControl && ( | ||
| <AspectRatioTool | ||
| hasValue={ hasAspectRatioValue } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.