PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.4.0
GenerateBlocks v1.4.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / components / range-control / index.js
generateblocks / src / components / range-control Last commit date
editor.scss 4 years ago index.js 4 years ago
index.js
89 lines
1 import hasNumericValue from '../../utils/has-numeric-value';
2
3 // Import CSS
4 import './editor.scss';
5
6 import {
7 Component,
8 } from '@wordpress/element';
9
10 import {
11 RangeControl,
12 TextControl,
13 } from '@wordpress/components';
14
15 export default class RangeControlInput extends Component {
16 render() {
17 const {
18 label,
19 value,
20 onChange,
21 rangeMin = 0,
22 rangeMax = 100,
23 inputMin = '',
24 inputMax = '',
25 step = 1,
26 help = '',
27 beforeIcon = '',
28 initialPosition = '',
29 placeholder = '',
30 disabled = false,
31 } = this.props;
32
33 return (
34 <div className="components-gblocks-range-control">
35 { label &&
36 <div className="components-gblocks-range-control--label">
37 { label }
38 </div>
39 }
40
41 <div className="components-gblocks-range-control--wrapper">
42 <div className="components-gblocks-range-control--range">
43 <RangeControl
44 className={ 'gblocks-range-control-range' }
45 beforeIcon={ beforeIcon }
46 value={ hasNumericValue( value ) ? parseFloat( value ) : '' }
47 onChange={ ( newVal ) => onChange( newVal ) }
48 min={ rangeMin }
49 max={ rangeMax }
50 step={ step }
51 withInputField={ false }
52 initialPosition={ initialPosition }
53 disabled={ disabled }
54 />
55 </div>
56
57 <div className="components-gblocks-range-control-input">
58 <TextControl
59 type="number"
60 placeholder={ '' !== placeholder ? placeholder : '' }
61 min={ inputMin }
62 max={ inputMax }
63 step={ step }
64 value={ hasNumericValue( value ) ? value : '' }
65 disabled={ disabled }
66 onChange={ ( newVal ) => onChange( newVal ) }
67 onBlur={ () => {
68 if ( hasNumericValue( value ) ) {
69 onChange( parseFloat( value ) );
70 }
71 } }
72 onClick={ ( e ) => {
73 // Make sure onBlur fires in Firefox.
74 e.currentTarget.focus();
75 } }
76 />
77 </div>
78 </div>
79
80 { help &&
81 <p className="components-base-control__help">
82 { help }
83 </p>
84 }
85 </div>
86 );
87 }
88 }
89