Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Mini Cart: Add font size and font family controls (#6396)
Browse files Browse the repository at this point in the history
* Mini Cart: Add font size and family controls

* Remove redundant property from the path

* Add conditional check for isFeaturePluginBuild
  • Loading branch information
danieldudzic authored May 30, 2022
1 parent a184946 commit e3e1868
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions assets/js/blocks/mini-cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { cart } from '@woocommerce/icons';
import { Icon } from '@wordpress/icons';
import { registerBlockType } from '@wordpress/blocks';
import type { BlockConfiguration } from '@wordpress/blocks';
import { isFeaturePluginBuild } from '@woocommerce/block-settings';

/**
* Internal dependencies
Expand Down Expand Up @@ -33,6 +34,12 @@ const settings: BlockConfiguration = {
html: false,
multiple: false,
color: true,
typography: {
fontSize: true,
...( isFeaturePluginBuild() && {
__experimentalFontFamily: true,
} ),
},
},
example: {
attributes: {
Expand Down
2 changes: 2 additions & 0 deletions assets/js/blocks/mini-cart/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
border: none;
color: inherit;
display: flex;
font-size: inherit;
font-family: inherit;
font-weight: 400;
padding: em($gap-small) em($gap-smaller);

Expand Down
2 changes: 1 addition & 1 deletion src/BlockTypes/MiniCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ protected function get_markup( $attributes ) {
$cart_contents_total += $cart->get_subtotal_tax();
}

$classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color' ) );
$classes_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'text_color', 'background_color', 'font_size', 'font_family' ) );
$wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] );
$wrapper_styles = $classes_styles['styles'];

Expand Down
21 changes: 21 additions & 0 deletions src/Utils/StyleAttributesUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public static function get_font_size_class_and_style( $attributes ) {
return null;
}

/**
* Get class and style for font-family from attributes.
*
* @param array $attributes Block attributes.
*
* @return (array | null)
*/
public static function get_font_family_class_and_style( $attributes ) {

$font_family = $attributes['fontFamily'] ?? '';

if ( $font_family ) {
return array(
'class' => sprintf( 'has-%s-font-family', $font_family ),
'style' => null,
);
}
return null;
}

/**
* Get class and style for text-color from attributes.
*
Expand Down Expand Up @@ -319,6 +339,7 @@ public static function get_classes_and_styles_by_attributes( $attributes, $prope
'line_height' => self::get_line_height_class_and_style( $attributes ),
'text_color' => self::get_text_color_class_and_style( $attributes ),
'font_size' => self::get_font_size_class_and_style( $attributes ),
'font_family' => self::get_font_family_class_and_style( $attributes ),
'link_color' => self::get_link_color_class_and_style( $attributes ),
'background_color' => self::get_background_color_class_and_style( $attributes ),
'border_color' => self::get_border_color_class_and_style( $attributes ),
Expand Down

0 comments on commit e3e1868

Please sign in to comment.