-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
add width control to separator block #16925
Changes from all commits
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 |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
}, | ||
"customColor": { | ||
"type": "string" | ||
}, | ||
"width": { | ||
"type": "number" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,15 @@ import classnames from 'classnames'; | |
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { HorizontalRule } from '@wordpress/components'; | ||
import { HorizontalRule, RangeControl, PanelBody } from '@wordpress/components'; | ||
import { | ||
InspectorControls, | ||
withColors, | ||
PanelColorSettings, | ||
} from '@wordpress/block-editor'; | ||
|
||
function SeparatorEdit( { color, setColor, className } ) { | ||
function SeparatorEdit( { color, setColor, className, attributes, setAttributes } ) { | ||
const { width = 25 } = attributes; | ||
return ( | ||
<> | ||
<HorizontalRule | ||
|
@@ -27,9 +28,23 @@ function SeparatorEdit( { color, setColor, className } ) { | |
style={ { | ||
backgroundColor: color.color, | ||
color: color.color, | ||
width: width + '%', | ||
} } | ||
/> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Separator Settings' ) }> | ||
<RangeControl | ||
label={ __( 'Percentage width' ) } | ||
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. Range control has a initialPosition property https://github.com/WordPress/gutenberg//blob/1e40b281d1db725e512e383b5e00f3b59e333d5a/packages/components/src/range-control/README.md. when the value is unset the property allows the range to be in a give position e.g: 25, but the input is empty to allow the user to differentiate between the state the user set the width to 25 (inline style added) the user did not set any width but currently the default is 25 (no inline style is added). |
||
value={ width || '' } | ||
onChange={ ( nextWidth ) => { | ||
setAttributes( { width: nextWidth } ); | ||
} } | ||
min={ 1 } | ||
max={ 100 } | ||
required | ||
allowReset | ||
/> | ||
</PanelBody> | ||
<PanelColorSettings | ||
title={ __( 'Color Settings' ) } | ||
colorSettings={ [ | ||
|
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.
Should we create a constant at the top of the file for the default width (25)?