137748cd8SNickeau<?php 237748cd8SNickeau 337748cd8SNickeau 437748cd8SNickeaunamespace ComboStrap; 537748cd8SNickeau 637748cd8SNickeau/** 737748cd8SNickeau * Class Skin 837748cd8SNickeau * @package ComboStrap 937748cd8SNickeau * Processing the skin attribute 1037748cd8SNickeau */ 1137748cd8SNickeauclass Skin 1237748cd8SNickeau{ 1337748cd8SNickeau 1437748cd8SNickeau const CANONICAL = "skin"; 1537748cd8SNickeau 1637748cd8SNickeau 1737748cd8SNickeau static $colors = array( 1837748cd8SNickeau "info" => array( 1937748cd8SNickeau ColorUtility::COLOR => "#0c5460", 2037748cd8SNickeau Background::BACKGROUND_COLOR => "#d1ecf1", 2137748cd8SNickeau ColorUtility::BORDER_COLOR => "#bee5eb" 2237748cd8SNickeau ), 2337748cd8SNickeau "tip" => array( 2437748cd8SNickeau ColorUtility::COLOR => "#6c6400", 2537748cd8SNickeau Background::BACKGROUND_COLOR => "#fff79f", 2637748cd8SNickeau ColorUtility::BORDER_COLOR => "#FFF78c" 2737748cd8SNickeau ), 2837748cd8SNickeau "warning" => array( 2937748cd8SNickeau ColorUtility::COLOR => "#856404", 3037748cd8SNickeau Background::BACKGROUND_COLOR => "#fff3cd", 3137748cd8SNickeau ColorUtility::BORDER_COLOR => "#ffeeba" 3237748cd8SNickeau ), 3337748cd8SNickeau "primary" => array( 3437748cd8SNickeau ColorUtility::COLOR => "#fff", 3537748cd8SNickeau Background::BACKGROUND_COLOR => "#007bff", 3637748cd8SNickeau ColorUtility::BORDER_COLOR => "#007bff" 3737748cd8SNickeau ), 3837748cd8SNickeau "secondary" => array( 3937748cd8SNickeau ColorUtility::COLOR => "#fff", 4037748cd8SNickeau Background::BACKGROUND_COLOR => "#6c757d", 4137748cd8SNickeau ColorUtility::BORDER_COLOR => "#6c757d" 4237748cd8SNickeau ), 4337748cd8SNickeau "success" => array( 4437748cd8SNickeau ColorUtility::COLOR => "#fff", 4537748cd8SNickeau Background::BACKGROUND_COLOR => "#28a745", 4637748cd8SNickeau ColorUtility::BORDER_COLOR => "#28a745" 4737748cd8SNickeau ), 4837748cd8SNickeau "danger" => array( 4937748cd8SNickeau ColorUtility::COLOR => "#fff", 5037748cd8SNickeau Background::BACKGROUND_COLOR => "#dc3545", 5137748cd8SNickeau ColorUtility::BORDER_COLOR => "#dc3545" 5237748cd8SNickeau ), 5337748cd8SNickeau "dark" => array( 5437748cd8SNickeau ColorUtility::COLOR => "#fff", 5537748cd8SNickeau Background::BACKGROUND_COLOR => "#343a40", 5637748cd8SNickeau ColorUtility::BORDER_COLOR => "#343a40" 5737748cd8SNickeau ), 5837748cd8SNickeau "light" => array( 5937748cd8SNickeau ColorUtility::COLOR => "#fff", 6037748cd8SNickeau Background::BACKGROUND_COLOR => "#f8f9fa", 6137748cd8SNickeau ColorUtility::BORDER_COLOR => "#f8f9fa" 6237748cd8SNickeau ) 6337748cd8SNickeau ); 6437748cd8SNickeau 6537748cd8SNickeau public static function processSkinAttribute(TagAttributes &$attributes) 6637748cd8SNickeau { 6737748cd8SNickeau // Skin 6837748cd8SNickeau $skinAttributes = "skin"; 6937748cd8SNickeau if ($attributes->hasComponentAttribute($skinAttributes)) { 7037748cd8SNickeau $skinValue = $attributes->getValueAndRemove($skinAttributes); 7137748cd8SNickeau if (!$attributes->hasComponentAttribute(TagAttributes::TYPE_KEY)) { 7237748cd8SNickeau LogUtility::msg("A component type is mandatory when using the skin attribute", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 7337748cd8SNickeau 7437748cd8SNickeau } else { 7537748cd8SNickeau $type = $attributes->getValue(TagAttributes::TYPE_KEY); 7637748cd8SNickeau if (!isset(self::$colors[$type])) { 7737748cd8SNickeau $types = implode(", ", array_keys(self::$colors)); 7837748cd8SNickeau LogUtility::msg("The type value ($type) is not supported. Only the following types value may be used: $types", LogUtility::LVL_MSG_WARNING, self::CANONICAL); 7937748cd8SNickeau } else { 8037748cd8SNickeau $color = self::$colors[$type]; 8137748cd8SNickeau switch ($skinValue) { 8237748cd8SNickeau case "contained": 83*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(ColorUtility::COLOR, $color[ColorUtility::COLOR]); 84*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, $color[Background::BACKGROUND_COLOR]); 85*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(ColorUtility::BORDER_COLOR, $color[ColorUtility::BORDER_COLOR]); 8637748cd8SNickeau Shadow::addMediumElevation($attributes); 8737748cd8SNickeau break; 8837748cd8SNickeau case "filled": 8937748cd8SNickeau case "solid": 90*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(ColorUtility::COLOR, $color[ColorUtility::COLOR]); 91*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, $color[Background::BACKGROUND_COLOR]); 92*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(ColorUtility::BORDER_COLOR, $color[ColorUtility::BORDER_COLOR]); 9337748cd8SNickeau break; 9437748cd8SNickeau case "outline": 9537748cd8SNickeau $primaryColor = $color[ColorUtility::COLOR]; 9637748cd8SNickeau if ($primaryColor === "#fff") { 9737748cd8SNickeau $primaryColor = $color[Background::BACKGROUND_COLOR]; 9837748cd8SNickeau } 99*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(ColorUtility::COLOR, $primaryColor); 100*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, "transparent"); 10137748cd8SNickeau $borderColor = $color[Background::BACKGROUND_COLOR]; 10237748cd8SNickeau if ($attributes->hasStyleDeclaration(ColorUtility::BORDER_COLOR)) { 10337748cd8SNickeau // Color in the `border` attribute 10437748cd8SNickeau // takes precedence in the `border-color` if located afterwards 10537748cd8SNickeau // We don't take the risk 10637748cd8SNickeau $borderColor = $attributes->getAndRemoveStyleDeclaration(ColorUtility::BORDER_COLOR); 10737748cd8SNickeau } 108*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet("border", "1px solid " . $borderColor); 10937748cd8SNickeau 11037748cd8SNickeau break; 11137748cd8SNickeau case "text": 11237748cd8SNickeau $primaryColor = $color[ColorUtility::COLOR]; 11337748cd8SNickeau if ($primaryColor === "#fff") { 11437748cd8SNickeau $primaryColor = $color[Background::BACKGROUND_COLOR]; 11537748cd8SNickeau } 116*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(ColorUtility::COLOR, $primaryColor); 117*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(Background::BACKGROUND_COLOR, "transparent"); 118*82a60d03SNickeau $attributes->addStyleDeclarationIfNotSet(ColorUtility::BORDER_COLOR, "transparent"); 11937748cd8SNickeau break; 12037748cd8SNickeau } 12137748cd8SNickeau } 12237748cd8SNickeau } 12337748cd8SNickeau } 12437748cd8SNickeau } 12537748cd8SNickeau 12637748cd8SNickeau} 127