Bläddra i källkod

Update icon template to allow `classname`

- Preserve the existing `class_name` behaviour in most other cases
- Update only docs reference to use `classname`
- Relates to #6107 & #6028
LB Johnston 2 år sedan
förälder
incheckning
3d484e133d

+ 1 - 1
docs/advanced_topics/customisation/streamfield_blocks.md

@@ -71,7 +71,7 @@ A form template for a StructBlock must include the output of `render_form` for e
     {% if help_text %}
         <span>
             <div class="help">
-                {% icon name="help" class_name="default" %}
+                {% icon name="help" classname="default" %}
                 {{ help_text }}
             </div>
         </span>

+ 1 - 1
wagtail/admin/templates/wagtailadmin/shared/icon.html

@@ -1,7 +1,7 @@
 {% spaceless %}
     {# Reference implementation: components/Icon.tsx #}
     {% if wrapped %}<span class="icon-wrapper">{% endif %}
-    <svg class="icon icon-{{ name }} {{ class_name }}" aria-hidden="true">
+    <svg class="icon icon-{{ name }} {{ classname }}" aria-hidden="true">
         <use href="#icon-{{ name }}"></use>
     </svg>
     {% if title %}

+ 10 - 4
wagtail/admin/templatetags/wagtailadmin_tags.py

@@ -669,24 +669,30 @@ def versioned_static(path):
 
 
 @register.inclusion_tag("wagtailadmin/shared/icon.html", takes_context=False)
-def icon(name=None, class_name="icon", title=None, wrapped=False):
+def icon(name=None, classname=None, title=None, wrapped=False, class_name=None):
     """
     Abstracts away the actual icon implementation.
 
     Usage:
         {% load wagtailadmin_tags %}
         ...
-        {% icon name="cogs" class_name="icon--red" title="Settings" %}
+        {% icon name="cogs" classname="icon--red" title="Settings" %}
 
     :param name: the icon name/id, required (string)
-    :param class_name: default 'icon' (string)
+    :param classname: defaults to 'icon' if not provided (string)
     :param title: accessible label intended for screen readers (string)
     :return: Rendered template snippet (string)
     """
     if not name:
         raise ValueError("You must supply an icon name")
 
-    return {"name": name, "class_name": class_name, "title": title, "wrapped": wrapped}
+    return {
+        "name": name,
+        # supporting class_name for backwards compatibility
+        "classname": classname or class_name or "icon",
+        "title": title,
+        "wrapped": wrapped,
+    }
 
 
 @register.filter()

+ 1 - 1
wagtail/blocks/base.py

@@ -604,7 +604,7 @@ class BlockField(forms.Field):
 @lru_cache(maxsize=1)
 def get_help_icon():
     return render_to_string(
-        "wagtailadmin/shared/icon.html", {"name": "help", "class_name": "default"}
+        "wagtailadmin/shared/icon.html", {"name": "help", "classname": "default"}
     )
 
 

+ 2 - 2
wagtail/contrib/modeladmin/templatetags/modeladmin_tags.py

@@ -118,7 +118,7 @@ def pagination_link_previous(current_page, view):
     if current_page.has_previous():
         previous_page_number0 = current_page.previous_page_number() - 1
         tpl = get_template("wagtailadmin/shared/icon.html")
-        icon_svg = tpl.render({"name": "arrow-left", "class_name": "default"})
+        icon_svg = tpl.render({"name": "arrow-left", "classname": "default"})
         return format_html(
             '<li class="prev"><a href="{}">{} {}</a></li>',
             view.get_query_string({view.PAGE_VAR: previous_page_number0}),
@@ -133,7 +133,7 @@ def pagination_link_next(current_page, view):
     if current_page.has_next():
         next_page_number0 = current_page.next_page_number() - 1
         tpl = get_template("wagtailadmin/shared/icon.html")
-        icon_svg = tpl.render({"name": "arrow-right", "class_name": "default"})
+        icon_svg = tpl.render({"name": "arrow-right", "classname": "default"})
         return format_html(
             '<li class="next"><a href="{}">{} {}</a></li>',
             view.get_query_string({view.PAGE_VAR: next_page_number0}),