137748cd8SNickeau<?php 237748cd8SNickeau 337748cd8SNickeau 437748cd8SNickeaunamespace ComboStrap; 537748cd8SNickeau 6*04fd306cSNickeauuse ComboStrap\TagAttribute\BackgroundAttribute; 7*04fd306cSNickeauuse ComboStrap\TagAttribute\Shadow; 84cadd4f8SNickeau 937748cd8SNickeau/** 1037748cd8SNickeau * Class Skin 1137748cd8SNickeau * @package ComboStrap 1237748cd8SNickeau * Processing the skin attribute 1337748cd8SNickeau */ 1437748cd8SNickeauclass Skin 1537748cd8SNickeau{ 1637748cd8SNickeau 174cadd4f8SNickeau const CANONICAL = self::SKIN_ATTRIBUTE; 184cadd4f8SNickeau const SKIN_ATTRIBUTE = "skin"; 194cadd4f8SNickeau const FILLED_VALUE = "filled"; 2037748cd8SNickeau 2137748cd8SNickeau 224cadd4f8SNickeau static $colorsWithoutPrimaryAndSecondary = array( 2337748cd8SNickeau "info" => array( 244cadd4f8SNickeau ColorRgb::COLOR => "#0c5460", 25*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => "#d1ecf1", 264cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#bee5eb" 2737748cd8SNickeau ), 2837748cd8SNickeau "tip" => array( 294cadd4f8SNickeau ColorRgb::COLOR => "#6c6400", 30*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => "#fff79f", 314cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#FFF78c" 3237748cd8SNickeau ), 3337748cd8SNickeau "warning" => array( 344cadd4f8SNickeau ColorRgb::COLOR => "#856404", 35*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => "#fff3cd", 364cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#ffeeba" 3737748cd8SNickeau ), 3837748cd8SNickeau "success" => array( 394cadd4f8SNickeau ColorRgb::COLOR => "#fff", 40*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => "#28a745", 414cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#28a745" 4237748cd8SNickeau ), 4337748cd8SNickeau "danger" => array( 444cadd4f8SNickeau ColorRgb::COLOR => "#fff", 45*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => "#dc3545", 464cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#dc3545" 4737748cd8SNickeau ), 4837748cd8SNickeau "dark" => array( 494cadd4f8SNickeau ColorRgb::COLOR => "#fff", 50*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => "#343a40", 514cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#343a40" 5237748cd8SNickeau ), 5337748cd8SNickeau "light" => array( 544cadd4f8SNickeau ColorRgb::COLOR => "#fff", 55*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => "#f8f9fa", 564cadd4f8SNickeau ColorRgb::BORDER_COLOR => "#f8f9fa" 5737748cd8SNickeau ) 5837748cd8SNickeau ); 5937748cd8SNickeau 604cadd4f8SNickeau public static function getSkinColors(): array 614cadd4f8SNickeau { 624cadd4f8SNickeau $primaryColorRgbHex = Site::getPrimaryColor("#007bff")->toRgbHex(); 634cadd4f8SNickeau $secondaryColorRgbHex = Site::getSecondaryColor("#6c757d")->toRgbHex(); 644cadd4f8SNickeau $brandingColors = array(ColorRgb::PRIMARY_VALUE => array( 654cadd4f8SNickeau ColorRgb::COLOR => "#fff", 66*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => $primaryColorRgbHex, 674cadd4f8SNickeau ColorRgb::BORDER_COLOR => $primaryColorRgbHex 684cadd4f8SNickeau ), 694cadd4f8SNickeau ColorRgb::SECONDARY_VALUE => array( 704cadd4f8SNickeau ColorRgb::COLOR => "#fff", 71*04fd306cSNickeau BackgroundAttribute::BACKGROUND_COLOR => $secondaryColorRgbHex, 724cadd4f8SNickeau ColorRgb::BORDER_COLOR => $secondaryColorRgbHex 734cadd4f8SNickeau )); 744cadd4f8SNickeau return array_merge($brandingColors, self::$colorsWithoutPrimaryAndSecondary); 754cadd4f8SNickeau } 764cadd4f8SNickeau 774cadd4f8SNickeau /** 784cadd4f8SNickeau * Used with button 794cadd4f8SNickeau * @param TagAttributes $attributes 804cadd4f8SNickeau */ 8137748cd8SNickeau public static function processSkinAttribute(TagAttributes &$attributes) 8237748cd8SNickeau { 8337748cd8SNickeau // Skin 844cadd4f8SNickeau if (!$attributes->hasComponentAttribute(self::SKIN_ATTRIBUTE)) { 854cadd4f8SNickeau return; 864cadd4f8SNickeau } 87*04fd306cSNickeau $skinValue = $attributes->getValueAndRemove(self::SKIN_ATTRIBUTE); 8837748cd8SNickeau if (!$attributes->hasComponentAttribute(TagAttributes::TYPE_KEY)) { 894cadd4f8SNickeau 9037748cd8SNickeau LogUtility::msg("A component type is mandatory when using the skin attribute", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 9137748cd8SNickeau 9237748cd8SNickeau } else { 9337748cd8SNickeau $type = $attributes->getValue(TagAttributes::TYPE_KEY); 944cadd4f8SNickeau if ( 954cadd4f8SNickeau $skinValue === self::FILLED_VALUE 964cadd4f8SNickeau && ($attributes->hasClass("btn-$type")||$attributes->hasClass("alert-$type")) 974cadd4f8SNickeau ) { 984cadd4f8SNickeau $isBrandingColor = in_array($type, [ColorRgb::PRIMARY_VALUE, ColorRgb::SECONDARY_VALUE]); 994cadd4f8SNickeau if (!$isBrandingColor) { 1004cadd4f8SNickeau // example: light 1014cadd4f8SNickeau return; 1024cadd4f8SNickeau } 1034cadd4f8SNickeau if (!Site::isBrandingColorInheritanceFunctional()) { 1044cadd4f8SNickeau // example: primary, secondary 1054cadd4f8SNickeau return; 1064cadd4f8SNickeau } 1074cadd4f8SNickeau } 1084cadd4f8SNickeau 1094cadd4f8SNickeau $skinColors = self::getSkinColors(); 1104cadd4f8SNickeau if (!isset($skinColors[$type])) { 1114cadd4f8SNickeau $types = implode(", ", array_keys($skinColors)); 11237748cd8SNickeau LogUtility::msg("The type value ($type) is not supported. Only the following types value may be used: $types", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 11337748cd8SNickeau } else { 1144cadd4f8SNickeau $color = $skinColors[$type]; 11537748cd8SNickeau switch ($skinValue) { 11637748cd8SNickeau case "contained": 1174cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, $color[ColorRgb::COLOR]); 118*04fd306cSNickeau $attributes->addStyleDeclarationIfNotSet(BackgroundAttribute::BACKGROUND_COLOR, $color[BackgroundAttribute::BACKGROUND_COLOR]); 1194cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::BORDER_COLOR, $color[ColorRgb::BORDER_COLOR]); 12037748cd8SNickeau Shadow::addMediumElevation($attributes); 12137748cd8SNickeau break; 1224cadd4f8SNickeau case self::FILLED_VALUE: 12337748cd8SNickeau case "solid": 1244cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, $color[ColorRgb::COLOR]); 125*04fd306cSNickeau $attributes->addStyleDeclarationIfNotSet(BackgroundAttribute::BACKGROUND_COLOR, $color[BackgroundAttribute::BACKGROUND_COLOR]); 1264cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::BORDER_COLOR, $color[ColorRgb::BORDER_COLOR]); 12737748cd8SNickeau break; 12837748cd8SNickeau case "outline": 1294cadd4f8SNickeau $primaryColor = $color[ColorRgb::COLOR]; 13037748cd8SNickeau if ($primaryColor === "#fff") { 131*04fd306cSNickeau $primaryColor = $color[BackgroundAttribute::BACKGROUND_COLOR]; 13237748cd8SNickeau } 1334cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, $primaryColor); 134*04fd306cSNickeau $attributes->addStyleDeclarationIfNotSet(BackgroundAttribute::BACKGROUND_COLOR, "transparent"); 135*04fd306cSNickeau $borderColor = $color[BackgroundAttribute::BACKGROUND_COLOR]; 1364cadd4f8SNickeau if ($attributes->hasStyleDeclaration(ColorRgb::BORDER_COLOR)) { 13737748cd8SNickeau // Color in the `border` attribute 13837748cd8SNickeau // takes precedence in the `border-color` if located afterwards 13937748cd8SNickeau // We don't take the risk 1404cadd4f8SNickeau $borderColor = $attributes->getAndRemoveStyleDeclaration(ColorRgb::BORDER_COLOR); 14137748cd8SNickeau } 14282a60d03SNickeau $attributes->addStyleDeclarationIfNotSet("border", "1px solid " . $borderColor); 14337748cd8SNickeau 14437748cd8SNickeau break; 14537748cd8SNickeau case "text": 1464cadd4f8SNickeau $primaryColor = $color[ColorRgb::COLOR]; 14737748cd8SNickeau if ($primaryColor === "#fff") { 148*04fd306cSNickeau $primaryColor = $color[BackgroundAttribute::BACKGROUND_COLOR]; 14937748cd8SNickeau } 1504cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::COLOR, "$primaryColor!important"); 151*04fd306cSNickeau $attributes->addStyleDeclarationIfNotSet(BackgroundAttribute::BACKGROUND_COLOR, "transparent"); 1524cadd4f8SNickeau $attributes->addStyleDeclarationIfNotSet(ColorRgb::BORDER_COLOR, "transparent"); 15337748cd8SNickeau break; 15437748cd8SNickeau } 15537748cd8SNickeau } 15637748cd8SNickeau } 15737748cd8SNickeau } 15837748cd8SNickeau 15937748cd8SNickeau} 160