bootstrap_italia-8.x-0.x-dev/components/components-2/badge/badge.html.twig
components/components-2/badge/badge.html.twig
{#
/**
* @file
* Template for badge component.
* Docs: https://italia.github.io/bootstrap-italia/docs/componenti/badge/
* Latest revision: v2.8.7
*
* Parameters:
* - label (string) (default: '')
* - Badge text
* - background (string) (default: '')
* - options ["primary", "secondary", "success", "danger", "warning", "white", "dark" ]
* - text_color (string) (default: '')
* - options ["primary", "secondary", "success", "danger", "warning", "muted",
* "white", "dark"]
* - assistive_text (string) (default: '')
* - Optional assistive text for badge label
* - rounded_pill (boolean) (default: false)
* - Rounded effect
* - outline (boolean) (default: false)
* - Enable outiline background color
* - badge_classes (array) (default: '')
* - options ["position-absolute top-0 start-100 translate-middle", "neutral-2-bg"]
* - badge_attributes (obj attribute) (default: '')
* - Object with extra attributes
*
* Note: https://italia.github.io/bootstrap-italia/docs/componenti/badge/#link
* is implemented in link component
*
* Examples:
{% include "@bi-bcl/badge/badge.html.twig"
with {
label: field_label,
assistive_text: 'Unreaded emails'|trans
}
%}
*
*/
#}
{% apply spaceless %}
{# Set defaults #}
{% set _label = label|default('') %}
{% set _background = background|default('') %}
{% set _text_color = text_color|default('') %}
{% set _assistive_text = assistive_text|default('') %}
{% set _rounded_pill = rounded_pill ?? false %}
{% set _outline = outline ?? false %}
{% set _badge_classes = badge_classes|default('') %}
{% set _badge_attributes = badge_attributes|default('') %}
{# Set options #}
{% set _classes = [
_label is not empty ? 'badge',
_outline and _background is not empty ? 'badge-outline-' ~ _background,
not _outline and _background is not empty ? 'bg-' ~ _background,
_text_color ? 'text-' ~ _text_color,
_rounded_pill ? 'rounded-pill',
_background in ['light', 'white'] and _text_color is empty ? 'text-dark'
] %}
{% if _badge_classes is not empty %}
{% set _classes = _classes|merge(badge_classes) %}
{% endif %}
{% if _badge_attributes is empty %}
{% set badge_attributes = create_attribute() %}
{% endif %}
{% set badge_attributes = badge_attributes.addClass(_classes) %}
{# Component #}
<span {{ badge_attributes }}>
{%- if _label is not empty -%}
{{- _label -}}
{%- endif -%}
</span>
{%- if _assistive_text is not empty -%}
<span class="visually-hidden">
{{- _assistive_text -}}
</span>
{%- endif -%}
{% endapply %}
