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