-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 inspector range control #1144
Add inspector range control #1144
Conversation
…ype attribute to ‘text’ to inherit the WordPress CSS styles.
const id = 'inspector-range-control-' + instanceId; | ||
|
||
return ( | ||
<div className="blocks-inspector-control"> |
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.
this breaks our css guidelines https://github.com/WordPress/gutenberg/blob/master/docs/coding-guidelines.md#css
The className here should be "blocks-range-control" and the subclassNames "blocks-range-control__label". This forces us to think in shared components instead of shared classNames. We could probably create a generic BaseControl
responsible of showing the label and the surroundings.
blocks/library/gallery/index.js
Outdated
@@ -120,8 +121,7 @@ registerBlockType( 'core/gallery', { | |||
|
|||
edit( { attributes, setAttributes, focus, id } ) { |
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 remove id
here since it's no longer used?
import './style.scss'; | ||
|
||
function TextControl( { label, value, instanceId, onChange } ) { | ||
function TextControl( { label, value, instanceId, onChange, ...attributes } ) { |
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.
Maybe props instead of attributes just to respect React's wording
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.
Left some minor notes, but this is looking good overall
* Remove unused id. * Conform to CSS guideline naming conventions.
Gone ahead and addressed all the notes. |
const id = 'inspector-text-control-' + instanceId; | ||
const type = props.type || 'text'; |
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.
Could we use default values + destructuring instead?
TextControl( { label, value, instanceId, onChange, type = 'text', ...props } ) {
I'm seeing some spaces/tabs mixed usages in different files, |
Done and done. |
Thanks a lot for working on this |
<label className="blocks-text-control__label" htmlFor={ rangeId }>{ __( 'Columns' ) }</label> | ||
<input id={ rangeId } type="range" min="1" max={ Math.min( MAX_COLUMNS, images.length ) } value={ columns } onChange={ setColumnsNumber } /> | ||
<span>{columns}</span> | ||
<RangeControl label={ __( 'Columns' ) } value={ columns } onChange={ setColumnsNumber } min="1" max={ Math.min( MAX_COLUMNS, images.length ) } /> |
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.
Might have helped readability to split these props across multiple lines (very long line).
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.
👍 I missed it. We should probably add an eslint rule for this.
As suggested on #1135 (comment), this separates the range control into its own component.
I'm more fluent in Vue.js and have never touched React, so let me know if there's anything that looks wrong.
This pull request does the following:
.blocks-inspector-control-*
classes.TextControl
component.text
so it inherits the WordPress CSS styles.RangeControl
component and tweaked the style to improve the grid.