| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Elements; |
| 3 |
|
| 4 |
use Depicter\Document\Models; |
| 5 |
use Depicter\Html\Html; |
| 6 |
|
| 7 |
class Bullet extends Models\Element |
| 8 |
{ |
| 9 |
|
| 10 |
public function render() { |
| 11 |
|
| 12 |
$args = $this->getDefaultAttributes(); |
| 13 |
|
| 14 |
if ( isset( $this->options->direction ) ) { |
| 15 |
$args['data-direction'] = $this->options->direction; |
| 16 |
} |
| 17 |
|
| 18 |
return Html::div( $args ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Get bullet item selector |
| 23 |
* |
| 24 |
* @return string |
| 25 |
*/ |
| 26 |
protected function getBulletItemSelector() { |
| 27 |
return '.' . $this->getSelector() . ' .depicter-bullet-item'; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Get bullet item selector |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
protected function getBulletsWrapperSelector() { |
| 36 |
return '.' . $this->getSelector() . ' .depicter-bullets-wrapper'; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* get active bullet item selector |
| 41 |
* @return string |
| 42 |
*/ |
| 43 |
protected function getActiveBulletItemSelector() { |
| 44 |
return '.' . $this->getSelector() . ' .depicter-bullet-item.depicter-bullet-active'; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* get bullet items css |
| 49 |
* @return array |
| 50 |
*/ |
| 51 |
protected function getBulletItemCss() { |
| 52 |
$styles = []; |
| 53 |
|
| 54 |
foreach ( $this->devices as $device ) { |
| 55 |
|
| 56 |
if ( isset( $this->options->bullet->styles->color->{$device} ) ) { |
| 57 |
$styles[ $device ]['background-color'] = $this->options->bullet->styles->color->{$device}; |
| 58 |
} |
| 59 |
|
| 60 |
if ( isset( $this->options->bullet->hover->color->{$device} ) ) { |
| 61 |
$styles['hover'][ $device ]['background-color'] = $this->options->bullet->hover->color->{$device}; |
| 62 |
} |
| 63 |
|
| 64 |
if ( isset( $this->options->bullet->styles->corner->{$device} ) ) { |
| 65 |
$styles[ $device ]['border-radius'] = $this->getBulletItemBorderRadius( $this->options->bullet->styles->corner->{$device} ); |
| 66 |
} |
| 67 |
|
| 68 |
if ( isset( $this->options->bullet->styles->size->{$device} ) && isset( $this->options->bullet->styles->size->{$device}->width ) ) { |
| 69 |
$styles[ $device ]['width'] = $this->options->bullet->styles->size->{$device}->width->value . $this->options->bullet->styles->size->{$device}->width->unit; |
| 70 |
} |
| 71 |
|
| 72 |
if ( isset( $this->options->bullet->styles->size->{$device} ) && isset( $this->options->bullet->styles->size->{$device}->height ) ) { |
| 73 |
$styles[ $device ]['height'] = $this->options->bullet->styles->size->{$device}->height->value . $this->options->bullet->styles->size->{$device}->height->unit; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
return $styles; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* get bullet item border radius |
| 82 |
* @param $deviceObject |
| 83 |
* |
| 84 |
* @return string |
| 85 |
*/ |
| 86 |
protected function getBulletItemBorderRadius( $deviceObject ) { |
| 87 |
return $deviceObject->topRight->value . $deviceObject->topRight->unit . ' ' . $deviceObject->bottomRight->value . $deviceObject->bottomRight->unit . ' ' . $deviceObject->bottomLeft->value . $deviceObject->bottomLeft->unit . ' ' . $deviceObject->topLeft->value . $deviceObject->topLeft->unit . ' '; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Get active bullets item css |
| 92 |
* |
| 93 |
* @return array |
| 94 |
*/ |
| 95 |
protected function getActiveBulletItemCss() { |
| 96 |
$styles = []; |
| 97 |
foreach ( $this->devices as $device ) { |
| 98 |
if ( isset( $this->options->bullet->styles->activeColor->{$device} ) ) { |
| 99 |
$styles[ $device ]['background-color'] = $this->options->bullet->styles->activeColor->{$device}; |
| 100 |
} |
| 101 |
|
| 102 |
if ( isset( $this->options->bullet->hover->color->{$device} ) ) { |
| 103 |
$styles['hover'][ $device ]['background-color'] = $this->options->bullet->hover->color->{$device}; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
return $styles; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Get styles for bullets wrapper |
| 112 |
* |
| 113 |
* @return array |
| 114 |
*/ |
| 115 |
protected function getBulletsWrapperCss() { |
| 116 |
$styles = []; |
| 117 |
foreach ( $this->devices as $device ) { |
| 118 |
if ( isset( $this->options->bullet->styles->space->{$device}->right ) ) { |
| 119 |
$styles[ $device ]['gap'] = $this->options->bullet->styles->space->{$device}->right->value . $this->options->bullet->styles->space->{$device}->right->unit; |
| 120 |
} |
| 121 |
} |
| 122 |
$styles['default']['flex-direction'] = ($this->options->direction ?? 'h') === 'h' ? 'row' : 'column'; |
| 123 |
|
| 124 |
return $styles; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Get list of selector and CSS for element |
| 129 |
* |
| 130 |
* @return array |
| 131 |
* @throws \JsonMapper_Exception |
| 132 |
*/ |
| 133 |
public function getSelectorAndCssList(){ |
| 134 |
parent::getSelectorAndCssList(); |
| 135 |
|
| 136 |
$this->selectorCssList[ $this->getBulletItemSelector() ] = $this->getBulletItemCss(); |
| 137 |
$this->selectorCssList[ $this->getActiveBulletItemSelector() ] = $this->getActiveBulletItemCss(); |
| 138 |
$this->selectorCssList[ $this->getBulletsWrapperSelector() ] = $this->getBulletsWrapperCss(); |
| 139 |
|
| 140 |
return $this->selectorCssList; |
| 141 |
} |
| 142 |
} |
| 143 |
|