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