1*37748cd8SNickeau<?php 2*37748cd8SNickeau 3*37748cd8SNickeau 4*37748cd8SNickeaunamespace ComboStrap; 5*37748cd8SNickeau 6*37748cd8SNickeau/** 7*37748cd8SNickeau * Class Skin 8*37748cd8SNickeau * @package ComboStrap 9*37748cd8SNickeau * Processing the skin attribute 10*37748cd8SNickeau */ 11*37748cd8SNickeauclass Skin 12*37748cd8SNickeau{ 13*37748cd8SNickeau 14*37748cd8SNickeau const CANONICAL = "skin"; 15*37748cd8SNickeau 16*37748cd8SNickeau 17*37748cd8SNickeau static $colors = array( 18*37748cd8SNickeau "info" => array( 19*37748cd8SNickeau ColorUtility::COLOR => "#0c5460", 20*37748cd8SNickeau Background::BACKGROUND_COLOR => "#d1ecf1", 21*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#bee5eb" 22*37748cd8SNickeau ), 23*37748cd8SNickeau "tip" => array( 24*37748cd8SNickeau ColorUtility::COLOR => "#6c6400", 25*37748cd8SNickeau Background::BACKGROUND_COLOR => "#fff79f", 26*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#FFF78c" 27*37748cd8SNickeau ), 28*37748cd8SNickeau "warning" => array( 29*37748cd8SNickeau ColorUtility::COLOR => "#856404", 30*37748cd8SNickeau Background::BACKGROUND_COLOR => "#fff3cd", 31*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#ffeeba" 32*37748cd8SNickeau ), 33*37748cd8SNickeau "primary" => array( 34*37748cd8SNickeau ColorUtility::COLOR => "#fff", 35*37748cd8SNickeau Background::BACKGROUND_COLOR => "#007bff", 36*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#007bff" 37*37748cd8SNickeau ), 38*37748cd8SNickeau "secondary" => array( 39*37748cd8SNickeau ColorUtility::COLOR => "#fff", 40*37748cd8SNickeau Background::BACKGROUND_COLOR => "#6c757d", 41*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#6c757d" 42*37748cd8SNickeau ), 43*37748cd8SNickeau "success" => array( 44*37748cd8SNickeau ColorUtility::COLOR => "#fff", 45*37748cd8SNickeau Background::BACKGROUND_COLOR => "#28a745", 46*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#28a745" 47*37748cd8SNickeau ), 48*37748cd8SNickeau "danger" => array( 49*37748cd8SNickeau ColorUtility::COLOR => "#fff", 50*37748cd8SNickeau Background::BACKGROUND_COLOR => "#dc3545", 51*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#dc3545" 52*37748cd8SNickeau ), 53*37748cd8SNickeau "dark" => array( 54*37748cd8SNickeau ColorUtility::COLOR => "#fff", 55*37748cd8SNickeau Background::BACKGROUND_COLOR => "#343a40", 56*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#343a40" 57*37748cd8SNickeau ), 58*37748cd8SNickeau "light" => array( 59*37748cd8SNickeau ColorUtility::COLOR => "#fff", 60*37748cd8SNickeau Background::BACKGROUND_COLOR => "#f8f9fa", 61*37748cd8SNickeau ColorUtility::BORDER_COLOR => "#f8f9fa" 62*37748cd8SNickeau ) 63*37748cd8SNickeau ); 64*37748cd8SNickeau 65*37748cd8SNickeau public static function processSkinAttribute(TagAttributes &$attributes) 66*37748cd8SNickeau { 67*37748cd8SNickeau // Skin 68*37748cd8SNickeau $skinAttributes = "skin"; 69*37748cd8SNickeau if ($attributes->hasComponentAttribute($skinAttributes)) { 70*37748cd8SNickeau $skinValue = $attributes->getValueAndRemove($skinAttributes); 71*37748cd8SNickeau if (!$attributes->hasComponentAttribute(TagAttributes::TYPE_KEY)) { 72*37748cd8SNickeau LogUtility::msg("A component type is mandatory when using the skin attribute", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 73*37748cd8SNickeau 74*37748cd8SNickeau } else { 75*37748cd8SNickeau $type = $attributes->getValue(TagAttributes::TYPE_KEY); 76*37748cd8SNickeau if (!isset(self::$colors[$type])) { 77*37748cd8SNickeau $types = implode(", ", array_keys(self::$colors)); 78*37748cd8SNickeau LogUtility::msg("The type value ($type) is not supported. Only the following types value may be used: $types", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 79*37748cd8SNickeau } else { 80*37748cd8SNickeau $color = self::$colors[$type]; 81*37748cd8SNickeau switch ($skinValue) { 82*37748cd8SNickeau case "contained": 83*37748cd8SNickeau $attributes->addStyleDeclaration(ColorUtility::COLOR, $color[ColorUtility::COLOR]); 84*37748cd8SNickeau $attributes->addStyleDeclaration(Background::BACKGROUND_COLOR, $color[Background::BACKGROUND_COLOR]); 85*37748cd8SNickeau $attributes->addStyleDeclaration(ColorUtility::BORDER_COLOR, $color[ColorUtility::BORDER_COLOR]); 86*37748cd8SNickeau Shadow::addMediumElevation($attributes); 87*37748cd8SNickeau break; 88*37748cd8SNickeau case "filled": 89*37748cd8SNickeau case "solid": 90*37748cd8SNickeau $attributes->addStyleDeclaration(ColorUtility::COLOR, $color[ColorUtility::COLOR]); 91*37748cd8SNickeau $attributes->addStyleDeclaration(Background::BACKGROUND_COLOR, $color[Background::BACKGROUND_COLOR]); 92*37748cd8SNickeau $attributes->addStyleDeclaration(ColorUtility::BORDER_COLOR, $color[ColorUtility::BORDER_COLOR]); 93*37748cd8SNickeau break; 94*37748cd8SNickeau case "outline": 95*37748cd8SNickeau $primaryColor = $color[ColorUtility::COLOR]; 96*37748cd8SNickeau if ($primaryColor === "#fff") { 97*37748cd8SNickeau $primaryColor = $color[Background::BACKGROUND_COLOR]; 98*37748cd8SNickeau } 99*37748cd8SNickeau $attributes->addStyleDeclaration(ColorUtility::COLOR, $primaryColor); 100*37748cd8SNickeau $attributes->addStyleDeclaration(Background::BACKGROUND_COLOR, "transparent"); 101*37748cd8SNickeau $borderColor = $color[Background::BACKGROUND_COLOR]; 102*37748cd8SNickeau if ($attributes->hasStyleDeclaration(ColorUtility::BORDER_COLOR)) { 103*37748cd8SNickeau // Color in the `border` attribute 104*37748cd8SNickeau // takes precedence in the `border-color` if located afterwards 105*37748cd8SNickeau // We don't take the risk 106*37748cd8SNickeau $borderColor = $attributes->getAndRemoveStyleDeclaration(ColorUtility::BORDER_COLOR); 107*37748cd8SNickeau } 108*37748cd8SNickeau $attributes->addStyleDeclaration("border", "1px solid " . $borderColor); 109*37748cd8SNickeau 110*37748cd8SNickeau break; 111*37748cd8SNickeau case "text": 112*37748cd8SNickeau $primaryColor = $color[ColorUtility::COLOR]; 113*37748cd8SNickeau if ($primaryColor === "#fff") { 114*37748cd8SNickeau $primaryColor = $color[Background::BACKGROUND_COLOR]; 115*37748cd8SNickeau } 116*37748cd8SNickeau $attributes->addStyleDeclaration(ColorUtility::COLOR, $primaryColor); 117*37748cd8SNickeau $attributes->addStyleDeclaration(Background::BACKGROUND_COLOR, "transparent"); 118*37748cd8SNickeau $attributes->addStyleDeclaration(ColorUtility::BORDER_COLOR, "transparent"); 119*37748cd8SNickeau break; 120*37748cd8SNickeau } 121*37748cd8SNickeau } 122*37748cd8SNickeau } 123*37748cd8SNickeau } 124*37748cd8SNickeau } 125*37748cd8SNickeau 126*37748cd8SNickeau} 127