{# Reusable UI macros for Tutortool templates. Usage: {% from "macros/ui.html" import flash_messages, styled_field, text_input %} #} {# Renders all flashed messages with colour-coded styling. #} {% macro flash_messages() %} {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %}
{% for category, message in messages %} {% if category == 'error' %} {% set alert_class = 'bg-red-900 border-red-400 text-red-100' %} {% elif category == 'expired' %} {% set alert_class = 'bg-orange-900 border-orange-400 text-orange-100' %} {% else %} {% set alert_class = 'bg-green-900 border-green-400 text-green-100' %} {% endif %} {% endfor %}
{% endif %} {% endwith %} {% endmacro %} {# Renders a WTForms field with a label and standard Tailwind styling. Pass extra_kwargs as a dict for additional HTML attributes (e.g. type, multiple). #} {% macro styled_field(field, extra_kwargs={}) %}
{{ field( class="w-full rounded-lg p-3 bg-background border border-border text-text placeholder-muted focus:outline-none focus:ring-2 focus:ring-primary", **extra_kwargs ) }} {% for error in field.errors %}

{{ error }}

{% endfor %}
{% endmacro %} {# Renders a plain (not WTForms) with standard styling. `type` defaults to 'text'. #} {% macro text_input(name, label, placeholder='', type='text', required=true, autofocus=false) %}
{% endmacro %} {# Renders a delete button wrapped in a form. #} {% macro delete_button(action_url, label='Delete') %}
{% endmacro %} {# Course-switcher dropdown (used in admin and index pages). #} {% macro course_switcher(courses, active_course_name, switch_url_prefix) %}
{% endmacro %}