From 0627dd38460cc13ed4a4b8daeecb1de06073bfaf Mon Sep 17 00:00:00 2001 From: xaralis <filip.varecha@fragaria.cz> Date: Tue, 28 Jun 2022 10:11:25 +0200 Subject: [PATCH] fix(shared): button block icon field description doesn't match actual block behavior --- shared/blocks.py | 14 ++++++++++++++ .../styleguide/2.3.x/blocks/button_block.html | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/shared/blocks.py b/shared/blocks.py index 287d53cb..de51ed4a 100644 --- a/shared/blocks.py +++ b/shared/blocks.py @@ -331,6 +331,20 @@ class ButtonBlock(blocks.StructBlock): return super().clean(value) + def get_context(self, value, parent_context=None): + context = super().get_context(value, parent_context) + + if value["icon"]: + context["icon_class"] = ( + value["icon"] + if value["icon"].startswith("ico--") + else f"ico--{value['icon']}" + ) + else: + context["icon_class"] = None + + return context + class ButtonGroupBlock(blocks.StructBlock): buttons = blocks.ListBlock(ButtonBlock(), label="Tlačítka") diff --git a/shared/templates/styleguide/2.3.x/blocks/button_block.html b/shared/templates/styleguide/2.3.x/blocks/button_block.html index 7a8fe5f4..9279ac84 100644 --- a/shared/templates/styleguide/2.3.x/blocks/button_block.html +++ b/shared/templates/styleguide/2.3.x/blocks/button_block.html @@ -3,10 +3,10 @@ {% if self.align == 'center' %}<div class="text-center">{% endif %} <a href="{{ target }}" class="btn btn--{{ self.color }} {% if self.hoveractive %}btn--hoveractive{% endif %} {% if self.icon %}btn--icon{% endif %} text-{{ self.size }} {% if self.mobile_fullwidth %}btn--fullwidth md:btn--autowidth{% else %}btn--autowidth{% endif %}" > - {% if self.icon %} + {% if icon_class %} <div class="btn__body-wrap"> <div class="btn__body ">{{ self.title }}</div> - <div class="btn__icon "><i class="ico--{{ self.icon }}"></i></div> + <div class="btn__icon "><i class="{{ icon_class }}"></i></div> </div> {% else %} <div class="btn__body ">{{ self.title }}</div> -- GitLab