register_block_from_metadata( 'number' );
}
public function render( $atts ) {
if ( ! $this->allow_render_now( $atts ) ) {
return '';
}
$label = isset( $atts['label'] ) ? $atts['label'] : 'Number';
$name = isset( $atts['name'] ) ? $atts['name'] : 'number_field';
$name = sanitize_key( $name );
$ph = isset( $atts['placeholder'] ) ? esc_attr( $atts['placeholder'] ) : '';
$required = ! empty( $atts['required'] );
$reqAttr = $this->get_field_boolean_attr( $atts, 'required', 'required' );
$defVal = isset( $atts['defaultValue'] ) ? esc_attr( $atts['defaultValue'] ) : '';
$acomp = isset( $atts['autocomplete'] ) && $atts['autocomplete'] !== '' ? 'autocomplete="'. esc_attr( $atts['autocomplete'] ) .'"' : '';
$inputMode = isset( $atts['inputMode'] ) && $atts['inputMode'] !== '' ? 'inputmode="'. esc_attr( $atts['inputMode'] ) .'"' : 'inputmode="numeric"';
$min = isset( $atts['min'] ) && $atts['min'] !== '' ? 'min="'. esc_attr( $atts['min'] ) .'"' : '';
$max = isset( $atts['max'] ) && $atts['max'] !== '' ? 'max="'. esc_attr( $atts['max'] ) .'"' : '';
$step = isset( $atts['step'] ) && $atts['step'] !== '' ? 'step="'. esc_attr( $atts['step'] ) .'"' : '';
$disabled= $this->get_field_boolean_attr( $atts, 'disabled', 'disabled' );
$readonly= $this->get_field_boolean_attr( $atts, 'readOnly', 'readonly' );
$labelPos= $this->get_field_label_position( $atts );
$class = $this->build_field_wrapper_class( 'number', $atts );
$style_rules = $this->get_field_wrapper_style_rules( $atts );
$prefix = isset( $atts['prefix'] ) ? esc_html( $atts['prefix'] ) : '';
$suffix = isset( $atts['suffix'] ) ? esc_html( $atts['suffix'] ) : '';
$help_context = $this->get_field_help_context( $atts, $name );
$ariaLabel = $this->get_field_aria_label_attr( $atts );
$ariaDesc = $help_context['aria_describedby'];
$id = 'stacklar-number-' . $name . '-' . wp_generate_password( 6, false, false );
$input_rules = $this->get_input_style_rules( $atts );
$inputStyle = $this->build_style_attribute( $input_rules );
$labelHtml = $this->render_field_label( $id, $label, $required, $labelPos, $atts );
$inputHtml = $this->render_input_wrap(
( $prefix !== '' ? ''. $prefix .'' : '' ) .
'' .
( $suffix !== '' ? ''. $suffix .'' : '' )
);
$contentHtml = $this->render_field_content( $labelHtml, $inputHtml, $labelPos, $help_context['help_html'] );
$html = $this->render_wrapper_open(
$atts,
$class,
$style_rules,
array(
'label' => '> label, .stacklar__inline > label',
'input' => 'input[type="number"]',
)
);
$html .= $contentHtml;
$html .= $this->render_wrapper_close();
return $html;
}
}