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