1<?php 2 3 4namespace ComboStrap; 5 6 7use ComboStrap\TagAttribute\Vertical; 8 9class Horizontal 10{ 11 12 13 public const HORIZONTAL_ATTRIBUTE = "horizontal"; 14 const CANONICAL = self::HORIZONTAL_ATTRIBUTE; 15 16 const VALUES = [ 17 "start-items", 18 "end", 19 "center-children", 20 "between", 21 "around", 22 "evenly" 23 ]; 24 25 public static function processHorizontal(TagAttributes &$tagAttributes) 26 { 27 28 self::processFlexAttribute(self::HORIZONTAL_ATTRIBUTE, $tagAttributes); 29 30 } 31 32 static function processFlexAttribute(string $attributeName, $tagAttributes) 33 { 34 35 $value = $tagAttributes->getValueAndRemove($attributeName); 36 if ($value === null) { 37 return; 38 } 39 40 $logicalTag = $tagAttributes->getLogicalTag(); 41 42 if (!in_array($logicalTag, Vertical::COMPONENTS)) { 43 LogUtility::warning("The $attributeName attribute is only meant to be used on the following component " . implode(", ", Vertical::COMPONENTS), self::CANONICAL); 44 } 45 try { 46 $conditionalValue = ConditionalValue::createFrom($value); 47 } catch (ExceptionBadSyntax $e) { 48 LogUtility::error("The $attributeName attribute value is not valid. Error: {$e->getMessage()}", self::CANONICAL); 49 return; 50 } 51 $valueWithoutBreakpoint = $conditionalValue->getValue(); 52 if ($attributeName === self::HORIZONTAL_ATTRIBUTE) { 53 $possibleValues = self::VALUES; 54 } else { 55 $possibleValues = Horizontal::VALUES; 56 } 57 if (!in_array($valueWithoutBreakpoint, $possibleValues)) { 58 LogUtility::error("The $attributeName attribute value ($valueWithoutBreakpoint) is not good. It should be one of: " . implode(", ", $possibleValues), self::CANONICAL); 59 return; 60 } 61 $breakpoint = $conditionalValue->getBreakpoint(); 62 if ($attributeName === self::HORIZONTAL_ATTRIBUTE) { 63 $classPrefix = "justify-content"; 64 } else { 65 $classPrefix = "align-items"; 66 } 67 if ($breakpoint !== null) { 68 $class = "$classPrefix-$breakpoint-$valueWithoutBreakpoint"; 69 } else { 70 $class = "$classPrefix-$valueWithoutBreakpoint"; 71 } 72 $tagAttributes->addClassName($class); 73 74 // works only on flex items 75 // row is a flex item 76 if ($logicalTag !== GridTag::TAG) { 77 $tagAttributes->addClassName(\syntax_plugin_combo_cell::FLEX_CLASS); 78 } 79 80 } 81 82} 83