/* globals _, wp, React */ import InputRange from 'react-input-range'; import reactCSS from 'reactcss'; import NumberFormat from 'react-number-format'; const KirkiRangeForm = ( props ) => { const decimalPoints = () => { if ( props.choices.step.toString().split( '.' )[1] ) { return props.choices.step.toString().split( '.' )[1].length; } return 0; }; const formatNumber = ( val ) => { const pow = Math.pow( 10, decimalPoints() ); return Math.round( val * pow ) / pow; } const formatValue = ( val ) => { return Math.min( props.choices.max, Math.max( props.choices.min, formatNumber( val ) ) ); }; props.choices.min = formatNumber( props.choices.min ); props.choices.max = formatNumber( props.choices.max ); props.choices.step = formatNumber( props.choices.step ); props.choices.prefix = props.choices.prefix || ''; props.choices.suffix = props.choices.suffix || ''; const handleChangeComplete = ( val ) => { wp.customize.control( props.customizerSetting.id ).setting.set( formatValue( val ) ); }; const handleChangeCompleteTextInput = ( values ) => { const {formattedValue, value} = values; wp.customize.control( props.customizerSetting.id ).setting.set( formatValue( value ) ); }; // Styles. const styles = reactCSS( { default: { labelsWrapper: { display: 'flex', justifyContent: 'space-between', color: '#aaaaaa', fontSize: '10px', }, valueLabel: { color: '#555d66', fontWeight: '700', fontSize: '13px' } } } ); return (