Animation.php
1 year ago
Background.php
1 year ago
BackgroundImage.php
1 year ago
Border.php
2 years ago
BoxShadow.php
1 year ago
ColumnWidth.php
1 year ago
CustomHeight.php
1 year ago
CustomSize.php
4 years ago
Gap.php
1 year ago
Height.php
1 year ago
JustifyContent.php
1 year ago
MaxWidth.php
1 year ago
MultipleImage.php
1 year ago
ObjectCss.php
1 year ago
Opacity.php
1 year ago
Property.php
1 year ago
PropertyBase.php
1 year ago
Size.php
1 year ago
Stroke.php
1 year ago
TBLR.php
1 year ago
TextShadow.php
1 year ago
Transform.php
2 years ago
Transition.php
1 year ago
Typography.php
1 month ago
UnitValuePercentage.php
1 year ago
UnitValuePx.php
1 year ago
ValueProxy.php
4 years ago
Width.php
1 year ago
Background.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core\StyleManager\Props; |
| 4 | |
| 5 | use Kubio\Core\Background\BackgroundDefaults; |
| 6 | use Kubio\Core\LodashBasic; |
| 7 | |
| 8 | class Background extends PropertyBase { |
| 9 | public $types; |
| 10 | |
| 11 | public function parse( $value, $options ) { |
| 12 | |
| 13 | $this->types = $this->config( 'enums.types' ); |
| 14 | |
| 15 | $unsetColorOnEmpty = true; |
| 16 | $defaultValue = BackgroundDefaults::getDefaultBackground(); |
| 17 | $background = new ValueProxy( $value, $defaultValue ); |
| 18 | |
| 19 | $style = array(); |
| 20 | $colorIsSet = false; |
| 21 | |
| 22 | if ( |
| 23 | $background->color |
| 24 | //&& $background->type !== $this->types['GRADIENT'] |
| 25 | ) { |
| 26 | $style['backgroundColor'] = $background->color; |
| 27 | $colorIsSet = true; |
| 28 | } |
| 29 | |
| 30 | if ( |
| 31 | ! $unsetColorOnEmpty && |
| 32 | ! $colorIsSet && |
| 33 | $background->type !== $this->types['GRADIENT'] |
| 34 | ) { |
| 35 | $colorIsSet = true; |
| 36 | } |
| 37 | |
| 38 | switch ( $background->type ) { |
| 39 | case $this->types['IMAGE']: |
| 40 | case $this->types['GRADIENT']: |
| 41 | // add source to image object directly, to be compatible with multiple backgrounds in the feature// |
| 42 | $image = LodashBasic::merge( |
| 43 | array( 'source' => array( 'type' => $background->type ) ), |
| 44 | $background->image[0] |
| 45 | ); |
| 46 | $bgImage = new BackgroundImage( $image, $this->config( 'default' ) ); |
| 47 | |
| 48 | $style = LodashBasic::merge( $style, $bgImage->toStyle() ); |
| 49 | break; |
| 50 | case $this->types['NONE']: |
| 51 | $style = LodashBasic::merge( $style, $this->getBackgroundNoneCss( $colorIsSet ) ); |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | return $style; |
| 56 | } |
| 57 | |
| 58 | public function getBackgroundNoneCss( $colorIsSet ) { |
| 59 | $computedStyle = array(); |
| 60 | if ( ! $colorIsSet ) { |
| 61 | $computedStyle['backgroundColor'] = 'unset'; |
| 62 | } |
| 63 | $computedStyle['backgroundImage'] = 'none'; |
| 64 | |
| 65 | return $computedStyle; |
| 66 | } |
| 67 | } |
| 68 |