1<?php 2 3 4namespace ComboStrap; 5 6 7class TextColor 8{ 9 10 const TEXT_COLOR_ATTRIBUTE = "text-color"; 11 const CSS_ATTRIBUTE = "color"; 12 const CANONICAL = self::TEXT_COLOR_ATTRIBUTE; 13 const TEXT_TAGS = [ 14 \syntax_plugin_combo_text::TAG, 15 \syntax_plugin_combo_itext::TAG 16 ]; 17 const TEXT_COLORS = array( 18 'primary', 19 'secondary', 20 'success', 21 'danger', 22 'warning', 23 'info', 24 'light', 25 'dark', 26 'body', 27 'muted', 28 'white', 29 'black-50', 30 'white-50' 31 ); 32 33 /** 34 * @param TagAttributes $attributes 35 */ 36 public static function processTextColorAttribute(TagAttributes &$attributes) 37 { 38 39 $colorAttributes = [TextColor::CSS_ATTRIBUTE, TextColor::TEXT_COLOR_ATTRIBUTE]; 40 foreach ($colorAttributes as $colorAttribute) { 41 if ($attributes->hasComponentAttribute($colorAttribute)) { 42 $colorValue = $attributes->getValueAndRemove($colorAttribute); 43 $lowerCase = strtolower($colorValue); 44 if (in_array($lowerCase, self::TEXT_COLORS)) { 45 /** 46 * The bootstrap text class 47 * https://getbootstrap.com/docs/5.0/utilities/colors/#colors 48 */ 49 $attributes->addClassName("text-$lowerCase"); 50 } else { 51 /** 52 * Other Text Colors 53 */ 54 $colorValue = ColorUtility::getColorValue($colorValue); 55 if (!empty($colorValue)) { 56 $attributes->addStyleDeclaration(TextColor::CSS_ATTRIBUTE, $colorValue); 57 } 58 } 59 break; 60 } 61 } 62 63 64 } 65 66 67 68} 69