1<?php 2 3 4namespace ComboStrap; 5 6/** 7 * Class Float 8 * @package ComboStrap 9 * 10 * 11 * Don't use float: 12 * PHP Fatal error: Cannot use 'Float' as class name as it is reserved 13 */ 14class FloatAttribute 15{ 16 const CANONICAL = "float"; 17 const CONF_FLOAT_DEFAULT_BREAKPOINT = "floatDefaultBreakpoint"; 18 const FLOAT_KEY = "float"; 19 20 /** 21 * @param TagAttributes $attributes 22 */ 23 public static function processFloat(&$attributes) 24 { 25 // The class shortcut 26 $float = self::FLOAT_KEY; 27 if ($attributes->hasComponentAttribute($float)) { 28 $floatValue = $attributes->getValueAndRemove($float); 29 $floatedValues = StringUtility::explodeAndTrim($floatValue, " "); 30 foreach ($floatedValues as $floatedValue) { 31 32 /** 33 * Bootstrap 5 has switch from left, right to start, end 34 */ 35 if (Bootstrap::getBootStrapMajorVersion() == Bootstrap::BootStrapFiveMajorVersion) { 36 switch ($floatedValue) { 37 case "left": 38 $floatedValue = "start"; 39 break; 40 case "right": 41 $floatValue = "end"; 42 break; 43 } 44 } 45 46 /** 47 * If there is no break point in the value 48 */ 49 switch ($floatedValue) { 50 case "left": 51 case "right": 52 case "start": 53 case "end": 54 case "none": 55 $defaultBreakpoint = SiteConfig::getConfValue(self::CONF_FLOAT_DEFAULT_BREAKPOINT, "sm"); 56 $floatValue = "{$defaultBreakpoint}-$floatValue"; 57 break; 58 } 59 60 /** 61 * Automatic spacing when on the right 62 * To not touch the text 63 */ 64 switch ($floatedValue) { 65 case "right": 66 case "end": 67 if (!$attributes->hasComponentAttribute("spacing")){ 68 $attributes->addComponentAttributeValue("spacing","ms-3"); 69 } 70 break; 71 } 72 73 $attributes->addClassName("float-{$floatValue}"); 74 } 75 /** 76 * By default, we don't float on extra small screen 77 */ 78 if (!StringUtility::contain("xs", $floatValue)) { 79 $attributes->addClassName("float-xs-none"); 80 } 81 82 // position relative and z-index are needed to put the float above 83 $attributes->addStyleDeclarationIfNotSet("position", "relative!important"); 84 $attributes->addStyleDeclarationIfNotSet("z-index", 1); 85 } 86 } 87} 88