Merge pull request #181 from woocommerce/PCP-158-mini-cart-button-size

Add button height setting for mini cart
This commit is contained in:
Emili Castells 2021-07-01 09:45:53 +02:00 committed by GitHub
commit 1711628cf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View file

@ -650,6 +650,7 @@ class SmartButton implements SmartButtonInterface {
'shape' => $this->style_for_context( 'shape', 'mini-cart' ),
'label' => $this->style_for_context( 'label', 'mini-cart' ),
'tagline' => $this->style_for_context( 'tagline', 'mini-cart' ),
'height' => $this->settings->has( 'button_mini-cart_height' ) && $this->settings->get( 'button_mini-cart_height' ) ? $this->normalize_height( (int) $this->settings->get( 'button_mini-cart_height' ) ) : 35,
),
'style' => array(
'layout' => $this->style_for_context( 'layout', $this->context() ),
@ -943,4 +944,21 @@ class SmartButton implements SmartButtonInterface {
}
return (string) $value;
}
/**
* Returns a value between 25 and 55.
*
* @param int $height The input value.
* @return int The normalized output value.
*/
private function normalize_height( int $height ): int {
if ( $height < 25 ) {
return 25;
}
if ( $height > 55 ) {
return 55;
}
return $height;
}
}

View file

@ -1734,6 +1734,19 @@ return array(
'requirements' => array(),
'gateway' => 'paypal',
),
'button_mini-cart_height' => array(
'title' => __( 'Button Height', 'woocommerce-paypal-payments' ),
'type' => 'number',
'default' => '35',
'desc_tip' => true,
'description' => __( 'Add a value from 25 to 55.', 'woocommerce-paypal-payments' ),
'screens' => array(
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
),
'requirements' => array(),
'gateway' => 'paypal',
),
'disable_cards' => array(
'title' => __( 'Disable specific credit cards', 'woocommerce-paypal-payments' ),

View file

@ -315,6 +315,7 @@ class SettingsListener {
$settings[ $key ] = isset( $raw_data[ $key ] );
break;
case 'text':
case 'number':
case 'ppcp-text-input':
case 'ppcp-password':
$settings[ $key ] = isset( $raw_data[ $key ] ) ? sanitize_text_field( $raw_data[ $key ] ) : '';