feat: render tooltips

This commit is contained in:
Björn Fromme
2025-09-24 10:44:01 +02:00
parent cf66b85993
commit 1a1e120cf6
+51 -22
View File
@@ -46,6 +46,11 @@
{%- block form_widget_simple -%}
{%- set type = type|default('text') -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- if type != 'hidden' -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-field')|trim }) -%}
{%- if errors|length -%}
@@ -55,13 +60,20 @@
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%}
{%- endif -%}
{%- endif -%}
{{ parent() }}
{%- if disabled is defined and disabled == true -%}
<input type="hidden" name="{{ form.vars.full_name }}" value="{{ form.vars.value }}">
{%- endif -%}
<div{% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
{{ parent() }}
{%- if disabled is defined and disabled == true -%}
<input type="hidden" name="{{ form.vars.full_name }}" value="{{ form.vars.value }}">
{%- endif -%}
</div>
{%- endblock form_widget_simple -%}
{%- block textarea_widget -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-field')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-field--has-error' }) -%}
@@ -69,20 +81,27 @@
{%- if disabled is defined and disabled == true -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%}
{%- endif -%}
{{ parent() }}
{%- if disabled is defined and disabled == true -%}
<input type="hidden" name="{{ form.vars.full_name }}" value="{{ form.vars.value }}">
{%- endif -%}
<div{% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
{{ parent() }}
{%- if disabled is defined and disabled == true -%}
<input type="hidden" name="{{ form.vars.full_name }}" value="{{ form.vars.value }}">
{%- endif -%}
</div>
{%- endblock textarea_widget -%}
{%- block checkbox_widget -%}
{%- set attr = attr|filter((v, k) => k != 'tooltip') -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-checkbox')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-checkbox--has-error' }) -%}
{%- endif -%}
{%- set tooltip = null -%}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
<div{% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
</div>
{%- endblock checkbox_widget -%}
{%- block radio_widget -%}
@@ -91,9 +110,9 @@
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-radio--has-error' }) -%}
{%- endif -%}
{%- set tooltip = null -%}
{%- if attr.tooltip is defined -%}
{%- set tooltip = attr.tooltip -%}
{%- set attr = attr|filter((v, k) => k != 'tooltip') -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
<div{% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
@@ -102,8 +121,8 @@
{% block checkbox_row %}
{%- set tooltip = null -%}
{%- if form.vars.attr.tooltip is defined -%}
{%- set tooltip = form.vars.attr.tooltip -%}
{%- if form.vars.attr['data-tooltip'] is defined -%}
{%- set tooltip = form.vars.attr['data-tooltip'] -%}
{%- endif -%}
<div class="{{ html_classes({ 'cursor-not-allowed': form.vars.attr.readonly is defined }) }}" {% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
<label for="{{ form.vars.id }}" class="{{ html_classes('relative flex items-start', { 'pointer-events-none': form.vars.attr.readonly is defined }) }}">
@@ -119,6 +138,11 @@
{% endblock %}
{%- block choice_widget_collapsed -%}
{%- set tooltip = null -%}
{%- if attr['data-tooltip'] is defined -%}
{%- set tooltip = attr['data-tooltip'] -%}
{%- set attr = attr|filter((v, k) => k != 'data-tooltip') -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-field')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-field--has-error' }) -%}
@@ -126,13 +150,15 @@
{%- if disabled is defined and disabled == true -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' cursor-not-allowed' }) -%}
{%- endif -%}
{%- if attr.readonly is defined %}
<div class="cursor-not-allowed">
<div{% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
{%- if attr.readonly is defined %}
<div class="cursor-not-allowed">
{{ parent() }}
</div>
{% else %}
{{ parent() }}
</div>
{% else %}
{{ parent() }}
{% endif %}
{% endif %}
</div>
{%- endblock choice_widget_collapsed -%}
{%- block choice_widget_expanded -%}
@@ -145,6 +171,9 @@
'hx-swap': attr['hx-swap']
}) -%}
{%- endif -%}
{%- if child.vars.attr['data-tooltip'] is defined -%}
{%- set child_attr = child_attr|merge({'data-tooltip': child.vars.attr['data-tooltip']}) -%}
{%- endif -%}
{{- form_row(child, { 'attr': child_attr }) -}}
{% endfor -%}
{%- endblock choice_widget_expanded -%}