'33.3333', '66' => '66.6667', ); $percent = isset( $percent_map[ $field_width ] ) ? $percent_map[ $field_width ] : $field_width; // Share of one gap each field gives up, rounded to 4 decimals with // trailing zeros trimmed (50 -> 0.5, 33.3333 -> 0.6667). $gap_factor = rtrim( rtrim( number_format( ( 100 - (float) $percent ) / 100, 4, '.', '' ), '0' ), '.' ); $calc = 'calc(' . $percent . '% - var(--airo-wp-form-field-spacing, 1.5rem) * ' . $gap_factor . ')'; return 'flex-basis:' . $calc . ';max-width:' . $calc; } } if ( ! function_exists( 'airowp_form_field_wrapper_attributes' ) ) { /** * Build a form field's wrapper attributes. * * Adds `data-airo-wp-field` (the field name) to every field and, when the * field has conditional logic, the `airo-wp-form-field--conditional` class and * its sanitized rules as `data-airo-wp-conditions` for the view script. * get_block_wrapper_attributes() escapes every value. * * @param array $attributes Block attributes. * @param string $type Field type slug for the BEM modifier (e.g. 'text'). * @param string $style Inline style ('' for none). * @return string Wrapper attributes. */ function airowp_form_field_wrapper_attributes( array $attributes, $type, $style = '' ) { $extra = array( 'class' => 'airo-wp-form-field airo-wp-form-field--' . $type ); if ( '' !== $style ) { $extra['style'] = $style; } $field_name = isset( $attributes['fieldName'] ) ? (string) $attributes['fieldName'] : ''; if ( '' !== $field_name ) { $extra['data-airo-wp-field'] = $field_name; } $rules = \airo - wp\Blocks\Form_Conditions::normalize_rules( isset( $attributes['dsgoConditions'] ) ? $attributes['dsgoConditions'] : null ); if ( null !== $rules ) { $extra['class'] .= ' airo-wp-form-field--conditional'; $extra['data-airo-wp-conditions'] = wp_json_encode( $rules ); } return get_block_wrapper_attributes( $extra ); } } if ( ! function_exists( 'airowp_form_field_label_html' ) ) { /** * Build a field