Skip to content

Commit

Permalink
fix(banner): apply custom classes when type is provided (#887)
Browse files Browse the repository at this point in the history
* fix(banner): Fix issue with classes not working if banner type not provided

* fix(banner): Reformat file

* add removed carriage return

* fix(banner): fix nunjucks formatting

* fix(banner): update to review comments

* fix(banner): fix issue with join

* fix(banner): fix issue with array handling
  • Loading branch information
AlexBramhill authored Nov 5, 2024
1 parent 9e6d87d commit fa418d4
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/moj/components/banner/template.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
<div class="moj-banner{% if params.type == 'success' %} moj-banner--success{% elif params.type == 'warning' %} moj-banner--warning{% else %} {{- ' ' + params.classes if params.classes}}{% endif %}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %} role="region" aria-label="{{ params.iconFallbackText | default(params.type) | default("banner") }}">
{#- Set classes for this component #}
{%- set classNames = ["moj-banner"] -%}

{%- if params.type == 'success' %}
{%- set classNames = classNames.concat("moj-banner--success") %}
{%- elif params.type == 'warning' %}
{%- set classNames = classNames.concat("moj-banner--warning") %}
{%- elif params.type == 'information' %}
{%- set classNames = classNames.concat("moj-banner--information") %}
{%- endif %}

{%- if params.classes %}
{%- set classNames = classNames.concat(params.classes) %}
{%- endif %}

{%- set classNames = classNames | join(' ') -%}

<div
class="{{ classNames }}"
{%- for attribute, value in params.attributes %}
{{ attribute }}="{{ value }}"
{% endfor %}
role="region"
aria-label="{{ params.iconFallbackText | default(params.type) | default("banner") }}"
>

{% if params.type == 'success' %}
<svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"/></svg>
Expand All @@ -13,4 +37,4 @@
{{- params.html | safe if params.html else params.text -}}
</div>

</div>
</div>

0 comments on commit fa418d4

Please sign in to comment.