Skip to content

Commit

Permalink
Add default template for Button component
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage authored and thibaudcolas committed Jan 2, 2024
1 parent 4554dbd commit 2274a44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
7 changes: 7 additions & 0 deletions wagtail/admin/templates/wagtailadmin/shared/button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% load wagtailadmin_tags %}
<a href="{{ button.url }}" class="{{ button.classname }}" {{ button.base_attrs_string }}>
{% if button.icon_name %}
{% icon name=button.icon_name %}
{% endif %}
{{ button.label }}
</a>
14 changes: 3 additions & 11 deletions wagtail/admin/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.forms.utils import flatatt
from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.html import format_html
from django.utils.http import urlencode

from wagtail import hooks
Expand All @@ -13,6 +12,7 @@


class Button(Component):
template_name = "wagtailadmin/shared/button.html"
show = True
label = ""
icon_name = None
Expand Down Expand Up @@ -43,16 +43,8 @@ def __init__(
self.attrs["aria-label"] = self.attrs.pop("title")
self.priority = priority

def render_html(self, parent_context=None):
if hasattr(self, "template_name"):
return super().render_html(parent_context)
else:
attrs = {
"href": self.url,
"class": self.classname,
}
attrs.update(self.attrs)
return format_html("<a{}>{}</a>", flatatt(attrs), self.label)
def get_context_data(self, parent_context):
return {"button": self}

@property
def base_attrs_string(self):
Expand Down

0 comments on commit 2274a44

Please sign in to comment.