| @@ -1,7 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace ABlocks\Blocks\FormRadio; |
| 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-radio', |
| 25 | 28 | $this->get_input_block_main_wrapper( $attributes ), |
| @@ -29,9 +32,10 @@ | ||
| 29 | 32 | $css_generator->add_class_styles( |
| 30 | 33 | '{{WRAPPER}} .ablocks-form-builder__radio-option', |
| 31 | 34 | $this->get_radio_dynamic_width_css( $attributes ), |
| 32 | 35 | $this->get_radio_dynamic_width_css( $attributes, 'Tablet' ), |
| 33 | - $this->get_radio_dynamic_width_css( $attributes, 'Mobile' ) | |
| 36 | + $this->get_radio_dynamic_width_css( $attributes, 'Mobile' ), | |
| 37 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_radio_dynamic_width_css( $attributes, $device ); } ) | |
| 34 | 38 | ); |
| 35 | 39 | return $css_generator->generate_css(); |
| 36 | 40 | } |
| 37 | 41 | public function get_radio_dynamic_width_css( $attributes, $device = '' ) { |
| @@ -45,14 +49,23 @@ | ||
| 45 | 49 | return []; |
| 46 | 50 | } |
| 47 | 51 | public function get_input_block_main_wrapper( $attributes, $device = '' ) { |
| 48 | 52 | $css = []; |
| 49 | - $css['display'] = 'inline-block'; | |
| 50 | 53 | $css['box-sizing'] = 'border-box'; |
| 51 | - $css['padding'] = '0px 2px'; | |
| 52 | - if ( isset( $attributes['inputWidth'] ) ) { | |
| 53 | - $css['width'] = ( $attributes['inputWidth'] - 1 ) . '%'; | |
| 54 | + | |
| 55 | + // The device's own width, else the nearest containing wider device's | |
| 56 | + // (custom breakpoints included), else Desktop's. | |
| 57 | + $input_width = isset( $attributes['inputWidth'] ) ? (array) $attributes['inputWidth'] : []; | |
| 58 | + $widthValue = \ABlocks\Helper::get_responsive_value( $input_width, 'value', $device ); | |
| 59 | + $widthValue = false === $widthValue ? 100 : $widthValue; | |
| 60 | + $widthUnit = \ABlocks\Helper::get_responsive_value( $input_width, 'valueUnit', $device ); | |
| 61 | + $widthUnit = false === $widthUnit ? '%' : $widthUnit; | |
| 62 | + | |
| 63 | + if ( is_numeric( $widthValue ) ) { | |
| 64 | + $widthValue = max( 0, floatval( $widthValue ) - 1 ); | |
| 54 | 65 | } |
| 66 | + | |
| 67 | + $css['width'] = $widthValue . $widthUnit; | |
| 55 | 68 | |
| 56 | 69 | return $css; |
| 57 | 70 | } |
| 58 | 71 | } |