| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Elements; |
| 3 |
|
| 4 |
use Depicter\Document\Models; |
| 5 |
use Depicter\Html\Html; |
| 6 |
|
| 7 |
class Button extends Models\Element |
| 8 |
{ |
| 9 |
|
| 10 |
public function render() { |
| 11 |
|
| 12 |
$args = $this->getDefaultAttributes(); |
| 13 |
|
| 14 |
if ( $this->componentType && |
| 15 |
in_array( $this->componentType, ['form:submit', 'survey:submit', 'survey:next', 'survey:prev'] ) |
| 16 |
) { |
| 17 |
$args['data-type'] = $this->componentType; |
| 18 |
} |
| 19 |
|
| 20 |
if ( $this->componentType && $this->componentType == 'survey:next' ) { |
| 21 |
if ( ! empty( $this->options->toggleToSubmit ) ) { |
| 22 |
$args['data-toggle-to-submit'] = 'true'; |
| 23 |
} |
| 24 |
|
| 25 |
if ( ! empty( $this->options->removeIconOnSubmit ) ) { |
| 26 |
$args['data-remove-icon-on-submit'] = 'true'; |
| 27 |
} |
| 28 |
|
| 29 |
if ( ! empty( $this->options->submitContent ) ) { |
| 30 |
$args['data-submit-text'] = $this->options->submitContent; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
if ( ! empty( $this->options->iconAlign ) && $this->options->iconAlign == 'right' ) { |
| 35 |
$args['class'] .= ' dp-icon-right'; |
| 36 |
} |
| 37 |
|
| 38 |
if ( ! empty( $this->options->disableOnFirst ) ) { |
| 39 |
$args['data-disable-on-first'] = 'true'; |
| 40 |
} |
| 41 |
|
| 42 |
if ( ! empty( $this->options->disableOnLast ) ) { |
| 43 |
$args['data-disable-on-last'] = 'true'; |
| 44 |
} |
| 45 |
|
| 46 |
$iconTag = ""; |
| 47 |
if ( ! empty( $this->options->iconContent) ) { |
| 48 |
$iconTag = Html::span([ |
| 49 |
'class' => 'dp-icon-container' |
| 50 |
], $this->options->iconContent ); |
| 51 |
} |
| 52 |
|
| 53 |
$content = ! empty ( $this->options->iconOnly ) && $this->options->iconOnly ? "" : $this->maybeReplaceDataSheetTags( $this->options->content ); |
| 54 |
|
| 55 |
$buttonContent = Html::span( [ |
| 56 |
'class' => 'dp-inner-content' |
| 57 |
], $iconTag . $content); |
| 58 |
|
| 59 |
$button = Html::button( $args, $buttonContent ); |
| 60 |
|
| 61 |
if ( false !== $a = $this->getLinkTag() ) { |
| 62 |
return $a->nest( $button ); |
| 63 |
} |
| 64 |
|
| 65 |
return $button; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Get list of selector and CSS for element |
| 70 |
* |
| 71 |
* @return array |
| 72 |
* @throws \JsonMapper_Exception |
| 73 |
*/ |
| 74 |
public function getSelectorAndCssList(){ |
| 75 |
$this->selectorCssList = parent::getSelectorAndCssList(); |
| 76 |
|
| 77 |
// Add SVG selector and css |
| 78 |
$this->selectorCssList[ $this->getSvgSelector() ] = $this->getSvgCss(); |
| 79 |
if ( ! empty( $this->selectorCssList[ $this->getSvgSelector() ]['hover'] ) ) { |
| 80 |
$this->selectorCssList[ $this->getHoverSvgSelector() ] = $this->selectorCssList[ $this->getSvgSelector() ]['hover']; |
| 81 |
unset( $this->selectorCssList[ $this->getSvgSelector() ]['hover'] ); |
| 82 |
} |
| 83 |
|
| 84 |
return $this->selectorCssList; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Get svg selector |
| 89 |
* |
| 90 |
* @return string |
| 91 |
*/ |
| 92 |
protected function getSvgSelector() { |
| 93 |
return '.' . $this->getSelector() . ' svg, .' . $this->getSelector() . ' path'; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Get svg selector |
| 98 |
* |
| 99 |
* @return string |
| 100 |
*/ |
| 101 |
protected function getHoverSvgSelector() { |
| 102 |
return '.' . $this->getSelector() . ':hover svg, .' . $this->getSelector() . ':hover path'; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Get styles of svg |
| 107 |
* |
| 108 |
* @return array|array[] |
| 109 |
* @throws \JsonMapper_Exception |
| 110 |
*/ |
| 111 |
protected function getSvgCss() { |
| 112 |
// Get styles list from styles property |
| 113 |
return ! empty( $this->styles ) ? $this->styles->getSvgCss() : []; |
| 114 |
} |
| 115 |
} |
| 116 |
|