| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Common\Styles; |
| 3 |
|
| 4 |
use Depicter\Document\CSS\Breakpoints; |
| 5 |
use Depicter\Document\Helper\Helper; |
| 6 |
use Depicter\Document\Models\Traits\HoverAbleStyleTrait; |
| 7 |
|
| 8 |
class Transition extends States |
| 9 |
{ |
| 10 |
use HoverAbleStyleTrait; |
| 11 |
|
| 12 |
/** |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public $timingFunction; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var float |
| 19 |
*/ |
| 20 |
public $duration; |
| 21 |
|
| 22 |
/** |
| 23 |
* style name |
| 24 |
*/ |
| 25 |
const NAME = 'transition'; |
| 26 |
|
| 27 |
public function set( $css ) { |
| 28 |
$devices = Breakpoints::names(); |
| 29 |
|
| 30 |
foreach ( $devices as $device ) { |
| 31 |
// Turn off transition for a breakpoint if it is disabled in hover options |
| 32 |
if( $this->isHoverDisabled( $device ) ){ |
| 33 |
$css[ $device ][ self::NAME . '-property' ] = "none"; |
| 34 |
// Check if properties for this breakpoint are available, and generate appropriate styles |
| 35 |
} elseif ( $this->isBreakpointEnabled( $device ) ) { |
| 36 |
$timingFunction = $this->{$device}->timingFunction ?? 'ease'; |
| 37 |
$duration = $this->{$device}->duration ?? 1; |
| 38 |
$css[ $device ][ self::NAME ] = "all {$timingFunction} {$duration}s"; |
| 39 |
// If no property is set and hover is enabled for this breakpoint, set a default transition |
| 40 |
} elseif( $this->isHoverEnabled( $device ) ){ |
| 41 |
$css[ $device ][ self::NAME ] = "all ease 1s"; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
return $css; |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|