Skip to content
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

Merged
merged 6 commits into from
Jun 13, 2017

Conversation

paulwilde
Copy link
Contributor

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:

  • Separate CSS into more generic reusable .blocks-inspector-control-* classes.
  • Allow custom attributes on the TextControl component.
  • Default the type attribute to text so it inherits the WordPress CSS styles.
  • Added RangeControl component and tweaked the style to improve the grid.

const id = 'inspector-range-control-' + instanceId;

return (
<div className="blocks-inspector-control">
Copy link
Contributor

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.

@@ -120,8 +121,7 @@ registerBlockType( 'core/gallery', {

edit( { attributes, setAttributes, focus, id } ) {
Copy link
Contributor

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 } ) {
Copy link
Contributor

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

Copy link
Contributor

@youknowriad youknowriad left a 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.
@paulwilde
Copy link
Contributor Author

Gone ahead and addressed all the notes.

const id = 'inspector-text-control-' + instanceId;
const type = props.type || 'text';
Copy link
Contributor

@youknowriad youknowriad Jun 13, 2017

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 } ) {

@youknowriad
Copy link
Contributor

I'm seeing some spaces/tabs mixed usages in different files, npm run lint could help here I guess?

@paulwilde
Copy link
Contributor Author

Done and done.

@youknowriad
Copy link
Contributor

I'm seeing a small style issue (The number is not correctly aligned and maybe the control should be 100% width) but we have the same issue on master. I'll merge when the tests completes.

screen shot 2017-06-13 at 15 16 24

@youknowriad
Copy link
Contributor

Thanks a lot for working on this

@youknowriad youknowriad merged commit f486884 into WordPress:master Jun 13, 2017
@paulwilde paulwilde deleted the add/inspector-range-control branch June 13, 2017 14:22
<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 ) } />
Copy link
Member

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).

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants