-
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
Changes from 15 commits
7d84507
bf6333a
33b1a2f
7b2355a
ceb4b91
765739d
d06f290
acfa21e
cf5ff38
0bece73
e103a28
82268f7
b5cc807
ec3b9dd
13a22a0
51764cf
f849e9d
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
function BaseControl( { id, label, className, children, ...props } ) { | ||
return ( | ||
<div className={ classnames( 'blocks-base-control', className ) } { ...props }> | ||
{ label && <label className="blocks-base-control__label" htmlFor={ id }>{ label }</label> } | ||
{ children } | ||
</div> | ||
); | ||
} | ||
|
||
export default BaseControl; |
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; | ||
} |
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 }> | ||
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. 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. So remove the 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. Well! According to the HTML Documentation, we can have two labels for the same input. So, let's leave it as is
|
||
<input | ||
id={ id } | ||
className="blocks-checkbox-control__input" | ||
type="checkbox" | ||
value="1" | ||
onChange={ onChangeValue } | ||
checked={ checked } | ||
{ ...props } | ||
/> | ||
{ label } | ||
</label> | ||
</BaseControl> | ||
); | ||
} | ||
|
||
export default withInstanceId( CheckboxControl ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.blocks-checkbox-control__input[type=checkbox] { | ||
margin-right: 6px; | ||
} |
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' ] }> | ||
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. Might be a tad simpler to pass |
||
{ 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 ); |
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; | ||
} |
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; | ||
} |
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 ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.blocks-select-control__input { | ||
width: 100%; | ||
} |
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; | ||
} | ||
|
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 ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.blocks-textarea-control__input { | ||
width: 100%; | ||
padding: 6px 8px; | ||
} |
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 ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.blocks-toggle-control { | ||
display: flex; | ||
justify-content: space-between; | ||
} |
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'm thinking we should drop the
...props
here until we explicitly need it.