-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
80 lines (74 loc) · 1.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* External dependencies
*/
import classnames from 'classnames';
const { isFinite } = lodash;
/**
* WordPress dependencies
*/
const { __ } = wp.i18n;
const { withInstanceId } = wp.compose;
/**
* Internal dependencies
*/
const { BaseControl, Button, Dashicon } = wp.components;
function RangeControl( {
className,
label,
value,
instanceId,
onChange,
beforeIcon,
afterIcon,
help,
allowReset,
initialPosition,
...props
} ) {
const id = `inspector-range-control-${ instanceId }`;
const resetValue = () => onChange();
const onChangeValue = ( event ) => {
const newValue = event.target.value;
if ( newValue === '' ) {
resetValue();
return;
}
onChange( Number( newValue ) );
};
const initialSliderValue = isFinite( value ) ? value : initialPosition || '';
return (
<BaseControl
label={ label }
id={ id }
help={ help }
className={ classnames( 'components-range-control', className ) }
>
{ beforeIcon && <Dashicon icon={ beforeIcon } /> }
<input
className="components-range-control__slider"
id={ id }
type="range"
value={ initialSliderValue }
onChange={ onChangeValue }
aria-describedby={ !! help ? id + '__help' : undefined }
{ ...props } />
{ afterIcon && <Dashicon icon={ afterIcon } /> }
<input
className="components-range-control__number"
type="number"
onChange={ onChangeValue }
aria-label={ label }
value={ initialSliderValue }
{ ...props }
/>
{ allowReset &&
<Button onClick={ resetValue } disabled={ value === undefined }>
{ __( 'Reset' ) }
</Button>
}
</BaseControl>
);
}
// const asInstance = withInstanceId( RangeControl );
// export { asInstance as RangeControl };
export default withInstanceId( RangeControl );