| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\FormInput; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\BlockBaseAbstract; |
| 9 |
use ABlocks\Classes\CssGenerator; |
| 10 |
|
| 11 |
class Block extends BlockBaseAbstract { |
| 12 |
protected $parent_block_name = 'form-builder'; |
| 13 |
protected $block_name = 'form-input'; |
| 14 |
|
| 15 |
public function build_css( $attributes ) { |
| 16 |
$css_generator = new CssGenerator( $attributes ); |
| 17 |
$css_generator->add_class_styles( |
| 18 |
'{{WRAPPER}}', |
| 19 |
$this->get_wrapper_css( $attributes ), |
| 20 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 21 |
$this->get_wrapper_css( $attributes, 'Mobile' ) |
| 22 |
); |
| 23 |
$css_generator->add_class_styles( |
| 24 |
'{{WRAPPER}}.ablocks-block--form-input', |
| 25 |
$this->get_input_block_main_wrapper( $attributes ), |
| 26 |
$this->get_input_block_main_wrapper( $attributes, 'Tablet' ), |
| 27 |
$this->get_input_block_main_wrapper( $attributes, 'Mobile' ) |
| 28 |
); |
| 29 |
|
| 30 |
// Generate button icon CSS start |
| 31 |
$css_generator->add_class_styles( |
| 32 |
'{{WRAPPER}} .ablocks-icon-wrap', |
| 33 |
$this->get_icon_wrapper_css( $attributes ), |
| 34 |
$this->get_icon_wrapper_css( $attributes, 'Tablet' ), |
| 35 |
$this->get_icon_wrapper_css( $attributes, 'Mobile' ) |
| 36 |
); |
| 37 |
$css_generator->add_class_styles( |
| 38 |
'{{WRAPPER}} .ablocks-form-builder__input-show-icon', |
| 39 |
$this->get_icon_space_css( $attributes ), |
| 40 |
$this->get_icon_space_css( $attributes, 'Tablet' ), |
| 41 |
$this->get_icon_space_css( $attributes, 'Mobile' ) |
| 42 |
); |
| 43 |
|
| 44 |
$css_generator->add_class_styles( |
| 45 |
'{{WRAPPER}} .ablocks-form-builder__input-toggle-password .ablocks-icon-wrap ', |
| 46 |
$this->get_password_show_hide_icon_wrapper_css( $attributes ) |
| 47 |
); |
| 48 |
return $css_generator->generate_css(); |
| 49 |
} |
| 50 |
|
| 51 |
public function get_wrapper_css() { |
| 52 |
|
| 53 |
return []; |
| 54 |
|
| 55 |
} |
| 56 |
public function get_icon_wrapper_css( $attributes, $device = '' ) { |
| 57 |
$css = []; |
| 58 |
|
| 59 |
// Check for 'inputIconSize' in the attributes and set font-size |
| 60 |
if ( isset( $attributes['inputIconSize'] ) ) { |
| 61 |
$css['font-size'] = $attributes['inputIconSize'] . 'px'; |
| 62 |
} |
| 63 |
|
| 64 |
// Check for 'iconColor' in the attributes and set fill color |
| 65 |
if ( isset( $attributes['iconColor'] ) ) { |
| 66 |
$css['fill'] = $attributes['iconColor']; |
| 67 |
} |
| 68 |
|
| 69 |
return $css; |
| 70 |
} |
| 71 |
public function get_icon_space_css( $attributes, $device = '' ) { |
| 72 |
$css = []; |
| 73 |
|
| 74 |
// Check for 'inputIconSpace' in the attributes and set padding-left |
| 75 |
if ( isset( $attributes['inputIconSpace'] ) ) { |
| 76 |
$css['padding-left'] = $attributes['inputIconSpace'] . 'px'; |
| 77 |
} |
| 78 |
|
| 79 |
return $css; |
| 80 |
} |
| 81 |
|
| 82 |
public function get_input_block_main_wrapper( $attributes, $device = '' ) { |
| 83 |
$css = []; |
| 84 |
$css['display'] = 'inline-block'; |
| 85 |
$css['box-sizing'] = 'border-box'; |
| 86 |
$css['padding'] = '0px 2px'; |
| 87 |
|
| 88 |
if ( isset( $attributes['inputWidth'] ) && is_numeric( $attributes['inputWidth'] ) ) { |
| 89 |
$css['width'] = ( $attributes['inputWidth'] - 1 ) . '%'; |
| 90 |
} else { |
| 91 |
// Handle case where inputWidth is not set or not a number |
| 92 |
$css['width'] = '100%'; // or some default value |
| 93 |
} |
| 94 |
|
| 95 |
return $css; |
| 96 |
} |
| 97 |
|
| 98 |
public function get_password_show_hide_icon_wrapper_css( $attributes ) { |
| 99 |
$password_show_hide_icon_wrapper_css = []; |
| 100 |
|
| 101 |
if ( isset( $attributes['passwordShowHideIconSize'] ) ) { |
| 102 |
$password_show_hide_icon_wrapper_css['font-size'] = $attributes['passwordShowHideIconSize'] . 'px'; |
| 103 |
} |
| 104 |
|
| 105 |
return $password_show_hide_icon_wrapper_css; |
| 106 |
} |
| 107 |
} |
| 108 |
|