← All changes
|
modules/atomic-widgets/props-resolver/transformers/styles/flex-transformer.php
+8
-36
4.2.2
→
4.3.1
View file →
| @@ -9,8 +9,12 @@ | ||
| 9 | 9 | exit; // Exit if accessed directly. |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | class Flex_Transformer extends Transformer_Base { |
| 13 | + const DEFAULT_FLEX_GROW = 0; | |
| 14 | + const DEFAULT_FLEX_SHRINK = 1; | |
| 15 | + const DEFAULT_FLEX_BASIS = 'auto'; | |
| 16 | + | |
| 13 | 17 | public function transform( $value, Props_Resolver_Context $context ) { |
| 14 | 18 | $grow = $value['flexGrow'] ?? null; |
| 15 | 19 | $shrink = $value['flexShrink'] ?? null; |
| 16 | 20 | $basis = $value['flexBasis'] ?? null; |
| @@ -22,47 +26,15 @@ | ||
| 22 | 26 | if ( ! $has_grow && ! $has_shrink && ! $has_basis ) { |
| 23 | 27 | return null; |
| 24 | 28 | } |
| 25 | 29 | |
| 26 | - $basis_value = $this->transform_basis_value( $basis ); | |
| 30 | + $grow_out = $has_grow ? $grow : self::DEFAULT_FLEX_GROW; | |
| 31 | + $shrink_out = $has_shrink ? $shrink : self::DEFAULT_FLEX_SHRINK; | |
| 32 | + $basis_out = $has_basis ? $this->transform_basis_value( $basis ) : self::DEFAULT_FLEX_BASIS; | |
| 27 | 33 | |
| 28 | - if ( $has_grow && $has_shrink && $has_basis ) { | |
| 29 | - return "{$grow} {$shrink} {$basis_value}"; | |
| 30 | - } | |
| 31 | - | |
| 32 | - if ( $has_grow && $has_shrink && ! $has_basis ) { | |
| 33 | - return "{$grow} {$shrink}"; | |
| 34 | - } | |
| 35 | - | |
| 36 | - if ( $has_grow && ! $has_shrink && $has_basis ) { | |
| 37 | - return "{$grow} 1 {$basis_value}"; | |
| 38 | - } | |
| 39 | - | |
| 40 | - if ( ! $has_grow && $has_shrink && $has_basis ) { | |
| 41 | - return "0 {$shrink} {$basis_value}"; | |
| 42 | - } | |
| 43 | - | |
| 44 | - if ( $has_grow && ! $has_shrink && ! $has_basis ) { | |
| 45 | - return "{$grow}"; | |
| 46 | - } | |
| 47 | - | |
| 48 | - if ( ! $has_grow && $has_shrink && ! $has_basis ) { | |
| 49 | - return "0 {$shrink}"; | |
| 50 | - } | |
| 51 | - | |
| 52 | - if ( ! $has_grow && ! $has_shrink && $has_basis ) { | |
| 53 | - return "0 1 {$basis_value}"; | |
| 54 | - } | |
| 55 | - | |
| 56 | - return null; | |
| 34 | + return "{$grow_out} {$shrink_out} {$basis_out}"; | |
| 57 | 35 | } |
| 58 | 36 | |
| 59 | - /** | |
| 60 | - * Transform basis value to string format | |
| 61 | - * | |
| 62 | - * @param mixed $basis The basis value | |
| 63 | - * @return string | |
| 64 | - */ | |
| 65 | 37 | private function transform_basis_value( $basis ) { |
| 66 | 38 | if ( is_array( $basis ) && isset( $basis['size'] ) ) { |
| 67 | 39 | $unit = $basis['unit'] ?? ''; |
| 68 | 40 | return $basis['size'] . $unit; |