Automattic\WooCommerce\Blocks\Utils

StyleAttributesUtils::get_text_color_class_and_style()public staticWC 1.0

Get class and style for text-color from attributes.

Method of the class: StyleAttributesUtils{}

No Hooks.

Return

Array.

Usage

$result = StyleAttributesUtils::get_text_color_class_and_style( $attributes );
$attributes(array) (required)
Block attributes.

StyleAttributesUtils::get_text_color_class_and_style() code WC 9.4.2

public static function get_text_color_class_and_style( $attributes ) {

	$text_color = $attributes['textColor'] ?? '';

	$custom_text_color = $attributes['style']['color']['text'] ?? '';

	if ( ! $text_color && ! $custom_text_color ) {
		return self::EMPTY_STYLE;
	}

	if ( $text_color ) {
		return array(
			'class' => sprintf( 'has-text-color has-%s-color', $text_color ),
			'style' => null,
			'value' => self::get_preset_value( $text_color ),
		);
	} elseif ( $custom_text_color ) {
		return array(
			'class' => null,
			'style' => sprintf( 'color: %s;', $custom_text_color ),
			'value' => $custom_text_color,
		);
	}

	return self::EMPTY_STYLE;
}