| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Common\Styles; |
| 3 |
|
| 4 |
use Depicter\Document\CSS\Breakpoints; |
| 5 |
use Depicter\Document\Models\Traits\HoverAbleStyleTrait; |
| 6 |
|
| 7 |
class Border extends States |
| 8 |
{ |
| 9 |
use HoverAbleStyleTrait; |
| 10 |
|
| 11 |
/** |
| 12 |
* style name |
| 13 |
*/ |
| 14 |
const NAME = 'border'; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
public $borderWidth = '1px'; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
public $borderStyle = 'solid'; |
| 25 |
|
| 26 |
/** |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public $borderColor = '#000'; |
| 30 |
|
| 31 |
public function set( $css ) { |
| 32 |
$devices = Breakpoints::names(); |
| 33 |
|
| 34 |
foreach ( $devices as $device ) { |
| 35 |
|
| 36 |
// If in Hover state and Hover is enabled for a breakpoint, just set the border color and skip the other properties |
| 37 |
if( $this->isHoverEnabled( $device ) ){ |
| 38 |
if ( !empty( $this->{$device}->color ) ) { |
| 39 |
$css[ $device ]['border-color'] = $this->{$device}->color; |
| 40 |
} |
| 41 |
|
| 42 |
// If in "Normal" state and properties for a breakpoint are available, generate appropriate styles |
| 43 |
} elseif ( $this->isBreakpointEnabled( $device ) ) { |
| 44 |
if( isset( $this->{$device}->top->value ) ){ |
| 45 |
if ( !empty( $this->{$device}->link ) ) { |
| 46 |
$css[$device]['border-width'] = $this->{$device}->top->value . $this->{$device}->top->unit; |
| 47 |
} else { |
| 48 |
$css[$device]['border-width'] = $this->{$device}->top->value . $this->{$device}->top->unit . " " . $this->{$device}->right->value . $this->{$device}->right->unit . " " . $this->{$device}->bottom->value . $this->{$device}->bottom->unit . " " . $this->{$device}->left->value . $this->{$device}->left->unit; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
// make sure to set default border styles if not defined |
| 53 |
$css[ $device ]['border-width'] = $css[ $device ]['border-width'] ?? "1px"; |
| 54 |
$css[ $device ]['border-style'] = $this->{$device}->style ?? "solid"; |
| 55 |
$css[ $device ]['border-color'] = $this->{$device}->color ?? "#000"; |
| 56 |
|
| 57 |
// If breakpoint is disabled in normal state, reset the border style |
| 58 |
} elseif( $this->isBreakpointDisabled( $device ) ){ |
| 59 |
$css[ $device ][ self::NAME ] = "none"; |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
return $css; |
| 65 |
} |
| 66 |
} |
| 67 |
|