Render a currency-prefixed input for advanced number filters of type “currency”.

This commit is contained in:
Jeff Stieler 2018-12-12 14:04:39 -07:00
parent e620f8ef92
commit cb09c195c8
2 changed files with 17 additions and 4 deletions

View File

@ -4,11 +4,16 @@
*/
import { Component, Fragment } from '@wordpress/element';
import { SelectControl, TextControl } from '@wordpress/components';
import { find, partial } from 'lodash';
import { get, find, partial } from 'lodash';
import interpolateComponents from 'interpolate-components';
import classnames from 'classnames';
import { _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import TextControlWithAffixes from '../../text-control-with-affixes';
class NumberFilter extends Component {
getBetweenString() {
return _x(
@ -42,15 +47,24 @@ class NumberFilter extends Component {
}
getFilterInput() {
const { filter, onFilterChange } = this.props;
const { config, filter, onFilterChange } = this.props;
const { rule, value } = filter;
const inputType = get( config, [ 'input', 'type' ], 'number' );
if ( 'between' === rule ) {
return this.getRangeInput();
}
return (
<TextControl
'currency' === inputType
? <TextControlWithAffixes
prefix="$"
className="woocommerce-filters-advanced__input-numeric-range"
type="number"
value={ value }
onChange={ partial( onFilterChange, filter.key, 'value' ) }
/>
: <TextControl
className="woocommerce-filters-advanced__input-numeric-range"
type="number"
value={ value }

View File

@ -177,6 +177,5 @@
input {
height: 38px;
border-radius: 4px;
}
}