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 all input inspector controls #1202

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions blocks/inspector-controls/base-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* Internal dependencies
*/
import './style.scss';

function BaseControl( { id, label, className, children } ) {
return (
<div className={ classnames( 'blocks-base-control', className ) }>
{ label && <label className="blocks-base-control__label" htmlFor={ id }>{ label }</label> }
{ children }
</div>
);
}

export default BaseControl;
9 changes: 9 additions & 0 deletions blocks/inspector-controls/base-control/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.blocks-base-control:not(:last-child) {
margin-bottom: 15px;
}

.blocks-base-control__label {
display: block;
font-weight: 500;
margin-bottom: 5px;
}
34 changes: 34 additions & 0 deletions blocks/inspector-controls/checkbox-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* WordPress dependencies
*/
import { withInstanceId } from 'components';

/**
* Internal dependencies
*/
import BaseControl from './../base-control';
import './style.scss';

function CheckboxControl( { label, heading, checked, instanceId, onChange, ...props } ) {
const id = 'inspector-checkbox-control-' + instanceId;
const onChangeValue = ( event ) => onChange( event.target.value );

return (
<BaseControl label={ heading } id={ id }>
<label className="blocks-checkbox-control__label" htmlFor={ 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 drop the label here? It's already added by BaseControl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one in particular is for the label beside the checkbox. So in my screenshot it is the "Option" text. There is an optional label (Coming from the BaseControl) with the prop 'heading' which is "Checkbox Control" in my screenshot.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! I'm wondering if it's ok for an input to have two labels? Maybe we should avoid the label prop for this control and add it explicitly here using another tag.

Copy link
Contributor Author

@paulwilde paulwilde Jun 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So remove the heading label prop, and then change the prop for the checkbox to something else. How about optionLabel or checkboxLabel?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well! According to the HTML Documentation, we can have two labels for the same input. So, let's leave it as is

More than one LABEL may be associated with the same control by creating multiple references via the for attribute.

<input
id={ id }
className="blocks-checkbox-control__input"
type="checkbox"
value="1"
onChange={ onChangeValue }
checked={ checked }
{ ...props }
/>
{ label }
</label>
</BaseControl>
);
}

export default withInstanceId( CheckboxControl );
3 changes: 3 additions & 0 deletions blocks/inspector-controls/checkbox-control/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.blocks-checkbox-control__input[type=checkbox] {
margin-right: 6px;
}
39 changes: 39 additions & 0 deletions blocks/inspector-controls/radio-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import { withInstanceId } from 'components';
import { isEmpty } from 'lodash';

/**
* Internal dependencies
*/
import BaseControl from './../base-control';
import './style.scss';

function RadioControl( { label, selected, instanceId, onChange, options = [] } ) {
const id = 'inspector-radio-control-' + instanceId;
const onChangeValue = ( event ) => onChange( event.target.value );

return ! isEmpty( options ) && (
<BaseControl label={ label } id={ id } className="blocks-radio-control">
{ options.map( ( option, index ) =>
<div className="blocks-radio-control__option">
<input
id={ ( id + '-' + index ) }
className="blocks-radio-control__input"
type="radio"
name={ id }
value={ option.value }
onChange={ onChangeValue }
selected={ option.value === selected }
/>
<label key={ option.value } htmlFor={ ( id + '-' + index ) }>
{ option.label }
</label>
</div>
) }
</BaseControl>
);
}

export default withInstanceId( RadioControl );
13 changes: 13 additions & 0 deletions blocks/inspector-controls/radio-control/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.blocks-radio-control {
display: flex;
flex-direction: column;
}

.blocks-radio-control__option:not(:last-child) {
margin-bottom: 4px;
}

.blocks-radio-control__input[type=radio] {
margin-top: 0;
margin-right: 6px;
}
12 changes: 7 additions & 5 deletions blocks/inspector-controls/range-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import { withInstanceId } from 'components';
/**
* Internal dependencies
*/
import BaseControl from './../base-control';
import './style.scss';

function RangeControl( { label, value, instanceId, onChange, ...props } ) {
const id = 'inspector-range-control-' + instanceId;

return (
<div className="blocks-range-control">
<label className="blocks-range-control__label" htmlFor={ id }>{ label }</label>
<input className="blocks-range-control__input" id={ id } type="range" value={ value } onChange={ onChange } { ...props } />
<span>{ value }</span>
</div>
<BaseControl label={ label } id={ id }>
<div className="blocks-range-control">
<input className="blocks-range-control__input" id={ id } type="range" value={ value } onChange={ onChange } { ...props } />
<span className="blocks-range-control__hint">{ value }</span>
</div>
</BaseControl>
);
}

Expand Down
15 changes: 10 additions & 5 deletions blocks/inspector-controls/range-control/style.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
.blocks-range-control {
margin-bottom: 10px;
display: flex;
justify-content: center;
}

.blocks-range-control__label {
display: block;
font-weight: 500;
margin-bottom: 5px;
.blocks-range-control__input {
width: 100%;
}

.blocks-range-control__hint {
display: inline-block;
margin-left: 10px;
font-weight: 500;
}
39 changes: 39 additions & 0 deletions blocks/inspector-controls/select-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import { withInstanceId } from 'components';
import { isEmpty } from 'lodash';

/**
* Internal dependencies
*/
import BaseControl from './../base-control';
import './style.scss';

function SelectControl( { label, selected, instanceId, onBlur, options = [], ...props } ) {
const id = 'inspector-select-control-' + instanceId;
const onBlurValue = ( event ) => onBlur( event.target.value );

return ! isEmpty( options ) && (
<BaseControl label={ label } id={ id }>
<select
id={ id }
className="blocks-select-control__input"
onBlur={ onBlurValue }
{ ...props }
>
{ options.map( ( option ) =>
<option
key={ option.value }
value={ option.value }
selected={ option.value === selected }
>
{ label }
</option>
) }
</select>
</BaseControl>
);
}

export default withInstanceId( SelectControl );
3 changes: 3 additions & 0 deletions blocks/inspector-controls/select-control/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.blocks-select-control__input {
width: 100%;
}
6 changes: 3 additions & 3 deletions blocks/inspector-controls/text-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { withInstanceId } from 'components';
/**
* Internal dependencies
*/
import BaseControl from './../base-control';
import './style.scss';

function TextControl( { label, value, instanceId, onChange, type = 'text', ...props } ) {
const id = 'inspector-text-control-' + instanceId;
const onChangeValue = ( event ) => onChange( event.target.value );

return (
<div className="blocks-text-control">
<label className="blocks-text-control__label" htmlFor={ id }>{ label }</label>
<BaseControl label={ label } id={ id }>
<input className="blocks-text-control__input" type={ type } id={ id } value={ value } onChange={ onChangeValue } { ...props } />
</div>
</BaseControl>
);
}

Expand Down
13 changes: 1 addition & 12 deletions blocks/inspector-controls/text-control/style.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
.blocks-text-control {
margin-bottom: 10px;
}

.blocks-text-control__label {
display: block;
font-weight: 500;
margin-bottom: 5px;
}

.blocks-text-control__input {
width: 100%;
padding: 6px 10px;
padding: 6px 8px;
}

25 changes: 25 additions & 0 deletions blocks/inspector-controls/textarea-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* WordPress dependencies
*/
import { withInstanceId } from 'components';

/**
* Internal dependencies
*/
import BaseControl from './../base-control';
import './style.scss';

function TextareaControl( { label, value, instanceId, onChange, rows = 4, ...props } ) {
const id = 'inspector-textarea-control-' + instanceId;
const onChangeValue = ( event ) => onChange( event.target.value );

return (
<BaseControl label={ label } id={ id }>
<textarea className="blocks-textarea-control__input" id={ id } rows={ rows } onChange={ onChangeValue } { ...props }>
{ value }
</textarea>
</BaseControl>
);
}

export default withInstanceId( TextareaControl );
4 changes: 4 additions & 0 deletions blocks/inspector-controls/textarea-control/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.blocks-textarea-control__input {
width: 100%;
padding: 6px 8px;
}
23 changes: 23 additions & 0 deletions blocks/inspector-controls/toggle-control/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* WordPress dependencies
*/
import { withInstanceId } from 'components';
import Toggle from 'components/form-toggle';

/**
* Internal dependencies
*/
import BaseControl from './../base-control';
import './style.scss';

function ToggleControl( { label, checked, instanceId, onChange } ) {
const id = 'inspector-toggle-control-' + instanceId;

return (
<BaseControl label={ label } id={ id } className="blocks-toggle-control">
<Toggle id={ id } checked={ checked } onChange={ onChange } />
</BaseControl>
);
}

export default withInstanceId( ToggleControl );
4 changes: 4 additions & 0 deletions blocks/inspector-controls/toggle-control/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.blocks-toggle-control {
display: flex;
justify-content: space-between;
}
15 changes: 6 additions & 9 deletions blocks/library/text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { __ } from 'i18n';
import { Children, cloneElement } from 'element';
import Toggle from 'components/form-toggle';

/**
* Internal dependencies
Expand All @@ -13,6 +12,7 @@ import AlignmentToolbar from '../../alignment-toolbar';
import BlockControls from '../../block-controls';
import Editable from '../../editable';
import InspectorControls from '../../inspector-controls';
import ToggleControl from '../../inspector-controls/toggle-control';

const { children } = query;

Expand Down Expand Up @@ -49,14 +49,11 @@ registerBlockType( 'core/text', {
),
focus && (
<InspectorControls key="inspector">
<div className="blocks-text__drop-cap" style={ { display: 'flex', justifyContent: 'space-between' } }>
<label htmlFor="blocks-text__drop-cap">{ __( 'Drop Cap' ) }</label>
<Toggle
checked={ !! dropCap }
onChange={ toggleDropCap }
id="blocks-text__drop-cap-toggle"
/>
</div>
<ToggleControl
label={ __( 'Drop Cap' ) }
checked={ !! dropCap }
onChange={ toggleDropCap }
/>
</InspectorControls>
),
<Editable
Expand Down