| 1 |
/** |
| 2 |
* External dependencies |
| 3 |
*/ |
| 4 |
import classnames from 'classnames/dedupe'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Internal dependencies |
| 8 |
*/ |
| 9 |
import FieldLabel from '../../field-label'; |
| 10 |
import FieldDescription from '../../field-description'; |
| 11 |
import { getFieldAttributes, FieldDefaultSettings } from '../../field-attributes'; |
| 12 |
|
| 13 |
/** |
| 14 |
* WordPress dependencies |
| 15 |
*/ |
| 16 |
const { __ } = wp.i18n; |
| 17 |
|
| 18 |
const { applyFilters } = wp.hooks; |
| 19 |
|
| 20 |
const { Component, Fragment } = wp.element; |
| 21 |
|
| 22 |
const { PanelBody, TextControl } = wp.components; |
| 23 |
|
| 24 |
const { InspectorControls } = wp.blockEditor; |
| 25 |
|
| 26 |
/** |
| 27 |
* Block Edit Class. |
| 28 |
*/ |
| 29 |
class BlockEdit extends Component { |
| 30 |
render() { |
| 31 |
const { attributes, setAttributes } = this.props; |
| 32 |
|
| 33 |
const { min, max, step, default: defaultVal } = attributes; |
| 34 |
|
| 35 |
let { className = '' } = this.props; |
| 36 |
|
| 37 |
className = classnames('ghostkit-form-field ghostkit-form-field-number', className); |
| 38 |
|
| 39 |
className = applyFilters('ghostkit.editor.className', className, this.props); |
| 40 |
|
| 41 |
const defaultCustom = ( |
| 42 |
<TextControl |
| 43 |
type="number" |
| 44 |
label={__('Default', 'ghostkit')} |
| 45 |
value={defaultVal} |
| 46 |
onChange={(val) => setAttributes({ default: val })} |
| 47 |
step={step} |
| 48 |
max={max} |
| 49 |
min={min} |
| 50 |
/> |
| 51 |
); |
| 52 |
|
| 53 |
return ( |
| 54 |
<Fragment> |
| 55 |
<InspectorControls> |
| 56 |
<PanelBody> |
| 57 |
<FieldDefaultSettings {...this.props} defaultCustom={defaultCustom} /> |
| 58 |
</PanelBody> |
| 59 |
<PanelBody title={__('Number Settings', 'ghostkit')}> |
| 60 |
<TextControl |
| 61 |
type="number" |
| 62 |
label={__('Min', 'ghostkit')} |
| 63 |
value={min} |
| 64 |
onChange={(val) => setAttributes({ min: val })} |
| 65 |
step={step} |
| 66 |
max={max} |
| 67 |
/> |
| 68 |
<TextControl |
| 69 |
type="number" |
| 70 |
label={__('Max', 'ghostkit')} |
| 71 |
value={max} |
| 72 |
onChange={(val) => setAttributes({ max: val })} |
| 73 |
step={step} |
| 74 |
min={min} |
| 75 |
/> |
| 76 |
<TextControl |
| 77 |
type="number" |
| 78 |
label={__('Step', 'ghostkit')} |
| 79 |
value={step} |
| 80 |
onChange={(val) => setAttributes({ step: val })} |
| 81 |
/> |
| 82 |
</PanelBody> |
| 83 |
</InspectorControls> |
| 84 |
<div className={className}> |
| 85 |
<FieldLabel {...this.props} /> |
| 86 |
<TextControl type="number" {...getFieldAttributes(attributes)} /> |
| 87 |
<FieldDescription {...this.props} /> |
| 88 |
</div> |
| 89 |
</Fragment> |
| 90 |
); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
export default BlockEdit; |
| 95 |
|