Handle custom currency formats (https://github.com/woocommerce/woocommerce-admin/pull/3349)
* add custom currency render * tooltip * remove filters * remove custom component * revert tooltip changes' * update package-lock * revert package-lock * revert package-lock again
This commit is contained in:
parent
0396740c49
commit
c0fc8a5be1
|
@ -29,21 +29,31 @@ export default class Currency {
|
|||
this.symbol = config.symbol.toString();
|
||||
this.symbolPosition = config.symbolPosition.toString();
|
||||
this.decimalSeparator = config.decimalSeparator.toString();
|
||||
this.priceFormat = config.priceFormat ? config.priceFormat.toString() : this.getPriceFormat( config );
|
||||
this.priceFormat = this.getPriceFormat( config );
|
||||
this.thousandSeparator = config.thousandSeparator.toString();
|
||||
|
||||
const precisionNumber = parseInt( config.precision, 10 );
|
||||
this.precision = precisionNumber;
|
||||
}
|
||||
|
||||
stripTags( str ) {
|
||||
const tmp = document.createElement( 'DIV' );
|
||||
tmp.innerHTML = str;
|
||||
return tmp.textContent || tmp.innerText || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default price format from a currency.
|
||||
*
|
||||
* @param {Object} currency Currency configuration.
|
||||
* @param {Object} config Currency configuration.
|
||||
* @return {String} Price format.
|
||||
*/
|
||||
getPriceFormat( currency ) {
|
||||
switch ( currency.symbolPosition ) {
|
||||
getPriceFormat( config ) {
|
||||
if ( config.priceFormat ) {
|
||||
return this.stripTags( config.priceFormat.toString() );
|
||||
}
|
||||
|
||||
switch ( config.symbolPosition ) {
|
||||
case 'left':
|
||||
return '%1$s%2$s';
|
||||
case 'right':
|
||||
|
|
Loading…
Reference in New Issue