| @@ -1,7 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace ABlocks\Blocks\FormCheckbox; |
| 3 | 3 | |
| 4 | +use ABlocks\Controls\Range; | |
| 5 | + | |
| 6 | + | |
| 4 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | 8 | exit; |
| 6 | 9 | } |
| 7 | 10 | |
| @@ -17,9 +20,10 @@ | ||
| 17 | 20 | $css_generator->add_class_styles( |
| 18 | 21 | '{{WRAPPER}}', |
| 19 | 22 | $this->get_wrapper_css( $attributes ), |
| 20 | 23 | $this->get_wrapper_css( $attributes, 'Tablet' ), |
| 21 | - $this->get_wrapper_css( $attributes, 'Mobile' ) | |
| 24 | + $this->get_wrapper_css( $attributes, 'Mobile' ), | |
| 25 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_wrapper_css( $attributes, $device ); } ) | |
| 22 | 26 | ); |
| 23 | 27 | $css_generator->add_class_styles( |
| 24 | 28 | '{{WRAPPER}}.ablocks-block--form-checkbox', |
| 25 | 29 | $this->get_input_block_main_wrapper( $attributes ), |
| @@ -30,16 +34,26 @@ | ||
| 30 | 34 | } |
| 31 | 35 | public function get_wrapper_css() { |
| 32 | 36 | return []; |
| 33 | 37 | } |
| 38 | + | |
| 34 | 39 | public function get_input_block_main_wrapper( $attributes, $device = '' ) { |
| 35 | 40 | $css = []; |
| 36 | - $css['display'] = 'inline-block'; | |
| 37 | 41 | $css['box-sizing'] = 'border-box'; |
| 38 | - $css['padding'] = '0px 2px'; | |
| 39 | - if ( isset( $attributes['inputWidth'] ) ) { | |
| 40 | - $css['width'] = ( $attributes['inputWidth'] - 1 ) . '%'; | |
| 42 | + | |
| 43 | + // The device's own width, else the nearest containing wider device's | |
| 44 | + // (custom breakpoints included), else Desktop's. | |
| 45 | + $input_width = isset( $attributes['inputWidth'] ) ? (array) $attributes['inputWidth'] : []; | |
| 46 | + $widthValue = \ABlocks\Helper::get_responsive_value( $input_width, 'value', $device ); | |
| 47 | + $widthValue = false === $widthValue ? 100 : $widthValue; | |
| 48 | + $widthUnit = \ABlocks\Helper::get_responsive_value( $input_width, 'valueUnit', $device ); | |
| 49 | + $widthUnit = false === $widthUnit ? '%' : $widthUnit; | |
| 50 | + | |
| 51 | + if ( is_numeric( $widthValue ) ) { | |
| 52 | + $widthValue = max( 0, floatval( $widthValue ) - 1 ); | |
| 41 | 53 | } |
| 54 | + | |
| 55 | + $css['width'] = $widthValue . $widthUnit; | |
| 42 | 56 | |
| 43 | 57 | return $css; |
| 44 | 58 | } |
| 45 | 59 | } |