| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\FormTextarea; |
| 3 |
|
| 4 |
use ABlocks\Controls\Range; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
use ABlocks\Classes\BlockBaseAbstract; |
| 11 |
use ABlocks\Classes\CssGenerator; |
| 12 |
|
| 13 |
class Block extends BlockBaseAbstract { |
| 14 |
protected $parent_block_name = 'form-builder'; |
| 15 |
protected $block_name = 'form-textarea'; |
| 16 |
|
| 17 |
public function build_css( $attributes ) { |
| 18 |
$css_generator = new CssGenerator( $attributes ); |
| 19 |
$css_generator->add_class_styles( |
| 20 |
'{{WRAPPER}}', |
| 21 |
$this->get_wrapper_css( $attributes ), |
| 22 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 23 |
$this->get_wrapper_css( $attributes, 'Mobile' ) |
| 24 |
); |
| 25 |
$css_generator->add_class_styles( |
| 26 |
'{{WRAPPER}}.ablocks-block--form-textarea', |
| 27 |
$this->get_input_block_main_wrapper( $attributes ), |
| 28 |
$this->get_input_block_main_wrapper( $attributes, 'Tablet' ), |
| 29 |
$this->get_input_block_main_wrapper( $attributes, 'Mobile' ), |
| 30 |
); |
| 31 |
return $css_generator->generate_css(); |
| 32 |
} |
| 33 |
public function get_wrapper_css() { |
| 34 |
return []; |
| 35 |
} |
| 36 |
public function get_input_block_main_wrapper( $attributes, $device = '' ) { |
| 37 |
$css = []; |
| 38 |
$css['box-sizing'] = 'border-box'; |
| 39 |
|
| 40 |
$valueKey = $device === 'Tablet' ? 'valueTablet' : ( $device === 'Mobile' ? 'valueMobile' : 'value' ); |
| 41 |
$unitKey = $device === 'Tablet' ? 'valueUnitTablet' : ( $device === 'Mobile' ? 'valueUnitMobile' : 'valueUnit' ); |
| 42 |
|
| 43 |
$widthValue = isset( $attributes['inputWidth'][ $valueKey ] ) && $attributes['inputWidth'][ $valueKey ] !== '' |
| 44 |
? $attributes['inputWidth'][ $valueKey ] |
| 45 |
: ( isset( $attributes['inputWidth']['value'] ) ? $attributes['inputWidth']['value'] : 100 ); |
| 46 |
|
| 47 |
$widthUnit = isset( $attributes['inputWidth'][ $unitKey ] ) && $attributes['inputWidth'][ $unitKey ] !== '' |
| 48 |
? $attributes['inputWidth'][ $unitKey ] |
| 49 |
: '%'; |
| 50 |
|
| 51 |
if ( is_numeric( $widthValue ) ) { |
| 52 |
$widthValue = max( 0, floatval( $widthValue ) - 1 ); |
| 53 |
} |
| 54 |
|
| 55 |
$css['width'] = $widthValue . $widthUnit; |
| 56 |
|
| 57 |
return $css; |
| 58 |
} |
| 59 |
} |
| 60 |
|