PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.13.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.13.0
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / blocks / form-password / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.13.0, at includes/blocks/form-password/block.php

115 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 );
29 $css_generator->add_class_styles(
30 '{{WRAPPER}}.ablocks-block--form-password',
31 $this->get_input_block_main_wrapper( $attributes ),
32 $this->get_input_block_main_wrapper( $attributes, 'Tablet' ),
33 $this->get_input_block_main_wrapper( $attributes, 'Mobile' ),
34 );
35
36 // Generate button icon CSS start
37 $css_generator->add_class_styles(
38 '{{WRAPPER}} .ablocks-form-builder__input-icon .ablocks-icon-wrap',
39 $this->get_icon_wrapper_css( $attributes ),
40 $this->get_icon_wrapper_css( $attributes, 'Tablet' ),
41 $this->get_icon_wrapper_css( $attributes, 'Mobile' )
42 );
43
44 $css_generator->add_class_styles(
45 '{{WRAPPER}} .ablocks-form-builder__input-show-icon',
46 $this->get_icon_space_css( $attributes ),
47 $this->get_icon_space_css( $attributes, 'Tablet' ),
48 $this->get_icon_space_css( $attributes, 'Mobile' )
49 );
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .ablocks-form-builder__input-toggle-password .ablocks-icon-wrap ',
52 $this->get_password_show_hide_icon_wrapper_css( $attributes )
53 );
54 return $css_generator->generate_css();
55 }
56
57 public function get_wrapper_css() {
58 // phpcs:ignore Squiz.PHP.NonExecutableCode.ReturnNotRequired
59 return;
60 }
61 public function get_input_block_main_wrapper( $attributes, $device = '' ) {
62 $css = [];
63 $css['box-sizing'] = 'border-box';
64
65 $valueKey = $device === 'Tablet' ? 'valueTablet' : ( $device === 'Mobile' ? 'valueMobile' : 'value' );
66 $unitKey = $device === 'Tablet' ? 'valueUnitTablet' : ( $device === 'Mobile' ? 'valueUnitMobile' : 'valueUnit' );
67
68 $widthValue = isset( $attributes['inputWidth'][ $valueKey ] ) && $attributes['inputWidth'][ $valueKey ] !== ''
69 ? $attributes['inputWidth'][ $valueKey ]
70 : ( isset( $attributes['inputWidth']['value'] ) ? $attributes['inputWidth']['value'] : 100 );
71
72 $widthUnit = isset( $attributes['inputWidth'][ $unitKey ] ) && $attributes['inputWidth'][ $unitKey ] !== ''
73 ? $attributes['inputWidth'][ $unitKey ]
74 : '%';
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 }
115