137748cd8SNickeau<?php 237748cd8SNickeau 337748cd8SNickeau 437748cd8SNickeaunamespace ComboStrap; 537748cd8SNickeau 6*4cadd4f8SNickeauuse splitbrain\phpcli\Colors; 7*4cadd4f8SNickeau 837748cd8SNickeau/** 937748cd8SNickeau * Class Skin 1037748cd8SNickeau * @package ComboStrap 1137748cd8SNickeau * Processing the skin attribute 1237748cd8SNickeau */ 1337748cd8SNickeauclass Skin 1437748cd8SNickeau{ 1537748cd8SNickeau 16*4cadd4f8SNickeau const CANONICAL = self::SKIN_ATTRIBUTE; 17*4cadd4f8SNickeau const SKIN_ATTRIBUTE = "skin"; 18*4cadd4f8SNickeau const FILLED_VALUE = "filled"; 1937748cd8SNickeau 2037748cd8SNickeau 21*4cadd4f8SNickeau static $colorsWithoutPrimaryAndSecondary = array( 2237748cd8SNickeau "info" => array( 23*4cadd4f8SNickeau ColorRgb::COLOR => "#0c5460", 2437748cd8SNickeau Background::BACKGROUND_COLOR => "#d1ecf1", 25*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#bee5eb" 2637748cd8SNickeau ), 2737748cd8SNickeau "tip" => array( 28*4cadd4f8SNickeau ColorRgb::COLOR => "#6c6400", 2937748cd8SNickeau Background::BACKGROUND_COLOR => "#fff79f", 30*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#FFF78c" 3137748cd8SNickeau ), 3237748cd8SNickeau "warning" => array( 33*4cadd4f8SNickeau ColorRgb::COLOR => "#856404", 3437748cd8SNickeau Background::BACKGROUND_COLOR => "#fff3cd", 35*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#ffeeba" 3637748cd8SNickeau ), 3737748cd8SNickeau "success" => array( 38*4cadd4f8SNickeau ColorRgb::COLOR => "#fff", 3937748cd8SNickeau Background::BACKGROUND_COLOR => "#28a745", 40*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#28a745" 4137748cd8SNickeau ), 4237748cd8SNickeau "danger" => array( 43*4cadd4f8SNickeau ColorRgb::COLOR => "#fff", 4437748cd8SNickeau Background::BACKGROUND_COLOR => "#dc3545", 45*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#dc3545" 4637748cd8SNickeau ), 4737748cd8SNickeau "dark" => array( 48*4cadd4f8SNickeau ColorRgb::COLOR => "#fff", 4937748cd8SNickeau Background::BACKGROUND_COLOR => "#343a40", 50*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#343a40" 5137748cd8SNickeau ), 5237748cd8SNickeau "light" => array( 53*4cadd4f8SNickeau ColorRgb::COLOR => "#fff", 5437748cd8SNickeau Background::BACKGROUND_COLOR => "#f8f9fa", 55*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#f8f9fa" 5637748cd8SNickeau ) 5737748cd8SNickeau ); 5837748cd8SNickeau 59*4cadd4f8SNickeau public static function getSkinColors(): array 60*4cadd4f8SNickeau { 61*4cadd4f8SNickeau $primaryColorRgbHex = Site::getPrimaryColor("#007bff")->toRgbHex(); 62*4cadd4f8SNickeau $secondaryColorRgbHex = Site::getSecondaryColor("#6c757d")->toRgbHex(); 63*4cadd4f8SNickeau $brandingColors = array(ColorRgb::PRIMARY_VALUE => array( 64*4cadd4f8SNickeau ColorRgb::COLOR => "#fff", 65*4cadd4f8SNickeau Background::BACKGROUND_COLOR => $primaryColorRgbHex, 66*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => $primaryColorRgbHex 67*4cadd4f8SNickeau ), 68*4cadd4f8SNickeau ColorRgb::SECONDARY_VALUE => array( 69*4cadd4f8SNickeau ColorRgb::COLOR => "#fff", 70*4cadd4f8SNickeau Background::BACKGROUND_COLOR => $secondaryColorRgbHex, 71*4cadd4f8SNickeau ColorRgb::BORDER_COLOR => $secondaryColorRgbHex 72*4cadd4f8SNickeau )); 73*4cadd4f8SNickeau return array_merge($brandingColors, self::$colorsWithoutPrimaryAndSecondary); 74*4cadd4f8SNickeau } 75*4cadd4f8SNickeau 76*4cadd4f8SNickeau /** 77*4cadd4f8SNickeau * Used with button 78*4cadd4f8SNickeau * @param TagAttributes $attributes 79*4cadd4f8SNickeau */ 8037748cd8SNickeau public static function processSkinAttribute(TagAttributes &$attributes) 8137748cd8SNickeau { 8237748cd8SNickeau // Skin 83*4cadd4f8SNickeau if (!$attributes->hasComponentAttribute(self::SKIN_ATTRIBUTE)) { 84*4cadd4f8SNickeau return; 85*4cadd4f8SNickeau } 86*4cadd4f8SNickeau $skinValue = $attributes->getValue(self::SKIN_ATTRIBUTE); 8737748cd8SNickeau if (!$attributes->hasComponentAttribute(TagAttributes::TYPE_KEY)) { 88*4cadd4f8SNickeau 8937748cd8SNickeau LogUtility::msg("A component type is mandatory when using the skin attribute", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 9037748cd8SNickeau 9137748cd8SNickeau } else { 9237748cd8SNickeau $type = $attributes->getValue(TagAttributes::TYPE_KEY); 93*4cadd4f8SNickeau if ( 94*4cadd4f8SNickeau $skinValue === self::FILLED_VALUE 95*4cadd4f8SNickeau && ($attributes->hasClass("btn-$type")||$attributes->hasClass("alert-$type")) 96*4cadd4f8SNickeau ) { 97*4cadd4f8SNickeau $isBrandingColor = in_array($type, [ColorRgb::PRIMARY_VALUE, ColorRgb::SECONDARY_VALUE]); 98*4cadd4f8SNickeau if (!$isBrandingColor) { 99*4cadd4f8SNickeau // example: light 100*4cadd4f8SNickeau return; 101*4cadd4f8SNickeau } 102*4cadd4f8SNickeau if (!Site::isBrandingColorInheritanceFunctional()) { 103*4cadd4f8SNickeau // example: primary, secondary 104*4cadd4f8SNickeau return; 105*4cadd4f8SNickeau } 106*4cadd4f8SNickeau } 107*4cadd4f8SNickeau 108*4cadd4f8SNickeau $skinColors = self::getSkinColors(); 109*4cadd4f8SNickeau if (!isset($skinColors[$type])) { 110*4cadd4f8SNickeau $types = implode(", ", array_keys($skinColors)); 11137748cd8SNickeau LogUtility::msg("The type value ($type) is not supported. Only the following types value may be used: $types", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 11237748cd8SNickeau } else { 113*4cadd4f8SNickeau $color = $skinColors[$type]; 11437748cd8SNickeau switch ($skinValue) { 11537748cd8SNickeau case "contained": 116*4cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, $color[ColorRgb::COLOR]); 11782a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, $color[Background::BACKGROUND_COLOR]); 118*4cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::BORDER_COLOR, $color[ColorRgb::BORDER_COLOR]); 11937748cd8SNickeau Shadow::addMediumElevation($attributes); 12037748cd8SNickeau break; 121*4cadd4f8SNickeau case self::FILLED_VALUE: 12237748cd8SNickeau case "solid": 123*4cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, $color[ColorRgb::COLOR]); 12482a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, $color[Background::BACKGROUND_COLOR]); 125*4cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::BORDER_COLOR, $color[ColorRgb::BORDER_COLOR]); 12637748cd8SNickeau break; 12737748cd8SNickeau case "outline": 128*4cadd4f8SNickeau $primaryColor = $color[ColorRgb::COLOR]; 12937748cd8SNickeau if ($primaryColor === "#fff") { 13037748cd8SNickeau $primaryColor = $color[Background::BACKGROUND_COLOR]; 13137748cd8SNickeau } 132*4cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, $primaryColor); 13382a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, "transparent"); 13437748cd8SNickeau $borderColor = $color[Background::BACKGROUND_COLOR]; 135*4cadd4f8SNickeau if ($attributes->hasStyleDeclaration(ColorRgb::BORDER_COLOR)) { 13637748cd8SNickeau // Color in the `border` attribute 13737748cd8SNickeau // takes precedence in the `border-color` if located afterwards 13837748cd8SNickeau // We don't take the risk 139*4cadd4f8SNickeau $borderColor = $attributes->getAndRemoveStyleDeclaration(ColorRgb::BORDER_COLOR); 14037748cd8SNickeau } 14182a60d03SNickeau $attributes->addStyleDeclarationIfNotSet("border", "1px solid " . $borderColor); 14237748cd8SNickeau 14337748cd8SNickeau break; 14437748cd8SNickeau case "text": 145*4cadd4f8SNickeau $primaryColor = $color[ColorRgb::COLOR]; 14637748cd8SNickeau if ($primaryColor === "#fff") { 14737748cd8SNickeau $primaryColor = $color[Background::BACKGROUND_COLOR]; 14837748cd8SNickeau } 149*4cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, "$primaryColor!important"); 15082a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, "transparent"); 151*4cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::BORDER_COLOR, "transparent"); 15237748cd8SNickeau break; 15337748cd8SNickeau } 15437748cd8SNickeau } 15537748cd8SNickeau } 15637748cd8SNickeau } 15737748cd8SNickeau 15837748cd8SNickeau} 159