-
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 all input inspector controls #1202
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7d84507
Do not add bottom margin for controls which aren’t the last item.
paulwilde bf6333a
Added ToggleControl.
paulwilde 33b1a2f
Increase bottom margin.
paulwilde 7b2355a
Improve range control alignment.
paulwilde ceb4b91
Further style improvements to range control.
paulwilde 765739d
Added TextareaControl. Reduce input side padding for consistency.
paulwilde d06f290
Added SelectControl.
paulwilde acfa21e
Change value key to selected.
paulwilde cf5ff38
Added CheckboxControl.
paulwilde 0bece73
Set textarea rows default to 4.
paulwilde e103a28
Added RadioControl.
paulwilde 82268f7
Add BaseControl.
paulwilde b5cc807
Do not force a ‘type’ prop for BaseControl, instead allow a custom cl…
paulwilde ec3b9dd
Fixed a bunch of lint issues.
paulwilde 13a22a0
Addressed feedback.
paulwilde 51764cf
Remove ...props.
paulwilde f849e9d
Use string for className.
paulwilde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }> | ||
<input | ||
id={ id } | ||
className="blocks-checkbox-control__input" | ||
type="checkbox" | ||
value="1" | ||
onChange={ onChangeValue } | ||
checked={ checked } | ||
{ ...props } | ||
/> | ||
{ label } | ||
</label> | ||
</BaseControl> | ||
); | ||
} | ||
|
||
export default withInstanceId( CheckboxControl ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.blocks-checkbox-control__input[type=checkbox] { | ||
margin-right: 6px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.blocks-select-control__input { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.blocks-textarea-control__input { | ||
width: 100%; | ||
padding: 6px 8px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.blocks-toggle-control { | ||
display: flex; | ||
justify-content: space-between; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 drop the label here? It's already added by BaseControl?
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 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.
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 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.
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.
So remove the
heading
label prop, and then change the prop for the checkbox to something else. How aboutoptionLabel
orcheckboxLabel
?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.
Well! According to the HTML Documentation, we can have two labels for the same input. So, let's leave it as is