From 0acbb9c873340a8c0c5bc53d865763fdcda27d37 Mon Sep 17 00:00:00 2001 From: Pierre <pierredureau@yahoo.fr> Date: Thu, 23 Jan 2025 10:04:47 +0100 Subject: [PATCH] Issue #3497594 by pdureau: Clean variant logic in templates --- components/alert/alert.twig | 4 ++-- components/badge/badge.twig | 4 ++-- components/button/button.preview.story.yml | 2 +- components/button/button.twig | 4 ++-- components/button_group/button_group.preview.story.yml | 2 +- components/button_group/button_group.twig | 4 ++-- components/callout/callout.preview.story.yml | 2 +- components/card/card.preview.story.yml | 4 ++-- components/card/card.twig | 4 ++-- components/content_media/content_media.twig | 4 ++-- components/download_block/download_block.preview.story.yml | 2 +- components/france_connect/france_connect.twig | 4 ++-- components/header/header.preview.story.yml | 6 +++--- components/highlight/highlight.twig | 4 ++-- components/link/link.preview.story.yml | 2 +- components/link/link.twig | 4 ++-- components/modal/modal.preview.story.yml | 4 ++-- components/modal/modal.twig | 6 +++--- components/side_menu/side_menu.twig | 4 ++-- components/tab/tab.preview.story.yml | 2 +- components/tab/tab.twig | 2 +- components/tab_panel/tab_panel.twig | 2 +- components/tag/tag.preview.story.yml | 2 +- components/tag/tag.twig | 4 ++-- components/tile/tile.twig | 4 ++-- components/translate/translate.twig | 2 +- 26 files changed, 44 insertions(+), 44 deletions(-) diff --git a/components/alert/alert.twig b/components/alert/alert.twig index 296fe66a..97687f05 100644 --- a/components/alert/alert.twig +++ b/components/alert/alert.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set variants = variant|split('__')|map(v => v|lower|replace({(v): 'fr-alert--' ~ v})|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set variants = variant|split('__')|map(v => v|replace({(v): 'fr-alert--' ~ v})) %} {% set attributes = attributes.addClass(variants) %} {% endif %} diff --git a/components/badge/badge.twig b/components/badge/badge.twig index fc1353ba..f5bbf37c 100644 --- a/components/badge/badge.twig +++ b/components/badge/badge.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set attributes = attributes.addClass('fr-badge--' ~ variant|lower|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set attributes = attributes.addClass('fr-badge--' ~ variant) %} {% endif %} {% if system_type %} diff --git a/components/button/button.preview.story.yml b/components/button/button.preview.story.yml index f7e10c12..07330e9e 100644 --- a/components/button/button.preview.story.yml +++ b/components/button/button.preview.story.yml @@ -8,5 +8,5 @@ props: icon_position: left icon: pack_id: dsfr - settings: { } + settings: {} icon_id: checkbox-circle-line diff --git a/components/button/button.twig b/components/button/button.twig index 4f0f5ff7..b1d7c18f 100644 --- a/components/button/button.twig +++ b/components/button/button.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set variants = variant|split('__')|map(v => v|lower|replace({(v): 'fr-btn--' ~ v})|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set variants = variant|split('__')|map(v => v|replace({(v): 'fr-btn--' ~ v})|replace({_: '-'})) %} {% set attributes = attributes.addClass(variants) %} {% endif %} diff --git a/components/button_group/button_group.preview.story.yml b/components/button_group/button_group.preview.story.yml index e9ba14f9..cad3bfaf 100644 --- a/components/button_group/button_group.preview.story.yml +++ b/components/button_group/button_group.preview.story.yml @@ -9,7 +9,7 @@ slots: props: icon: pack_id: dsfr - settings: { } + settings: {} icon_id: arrow-right-line icon_position: right - type: component diff --git a/components/button_group/button_group.twig b/components/button_group/button_group.twig index 3f69da26..d37f6305 100644 --- a/components/button_group/button_group.twig +++ b/components/button_group/button_group.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set variants = variant|split('__')|map(v => v|lower|replace({(v): 'fr-btns-group--' ~ v})|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set variants = variant|split('__')|map(v => v|replace({(v): 'fr-btns-group--' ~ v})) %} {% set attributes = attributes.addClass(variants) %} {% endif %} diff --git a/components/callout/callout.preview.story.yml b/components/callout/callout.preview.story.yml index 94a2a2ee..49e8fbbe 100644 --- a/components/callout/callout.preview.story.yml +++ b/components/callout/callout.preview.story.yml @@ -12,5 +12,5 @@ props: color_schema: green-tilleul-verveine icon: pack_id: dsfr - settings: { } + settings: {} icon_id: alert-line diff --git a/components/card/card.preview.story.yml b/components/card/card.preview.story.yml index 40dea2a5..ba9d1dd8 100644 --- a/components/card/card.preview.story.yml +++ b/components/card/card.preview.story.yml @@ -62,9 +62,9 @@ props: bg_boxes: shadow detail_icon: pack_id: dsfr - settings: { } + settings: {} icon_id: checkbox-circle-line detail_end_icon: pack_id: dsfr - settings: { } + settings: {} icon_id: alert-fill diff --git a/components/card/card.twig b/components/card/card.twig index 0001fd31..9192fd08 100644 --- a/components/card/card.twig +++ b/components/card/card.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set variants = variant|split('__')|map(v => v|lower|replace({(v): 'fr-card--' ~ v})|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set variants = variant|split('__')|map(v => v|replace({(v): 'fr-card--' ~ v})) %} {% set attributes = attributes.addClass(variants) %} {% if 'fr-card--horizontal' in variants and horizontal_ratio %} {% set attributes = attributes.addClass('fr-card--horizontal-' ~ horizontal_ratio) %} diff --git a/components/content_media/content_media.twig b/components/content_media/content_media.twig index 614c3b65..ad417154 100644 --- a/components/content_media/content_media.twig +++ b/components/content_media/content_media.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set attributes = attributes.addClass('fr-content-media--' ~ variant|lower|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set attributes = attributes.addClass('fr-content-media--' ~ variant) %} {% endif %} {% if caption or transcription %} diff --git a/components/download_block/download_block.preview.story.yml b/components/download_block/download_block.preview.story.yml index 65965dc9..1c6ea0a1 100644 --- a/components/download_block/download_block.preview.story.yml +++ b/components/download_block/download_block.preview.story.yml @@ -8,5 +8,5 @@ props: new_window: true detail_icon: pack_id: dsfr - settings: { } + settings: {} icon_id: file-pdf-line diff --git a/components/france_connect/france_connect.twig b/components/france_connect/france_connect.twig index 7289c103..b60b9ecc 100644 --- a/components/france_connect/france_connect.twig +++ b/components/france_connect/france_connect.twig @@ -1,8 +1,8 @@ {% set brand = 'FranceConnect'|t %} {% set url = 'https://franceconnect.gouv.fr/' %} -{% if variant and variant|lower != 'default' %} - {% set attributes = attributes.addClass('fr-connect--' ~ variant|lower|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set attributes = attributes.addClass('fr-connect--' ~ variant) %} {% set brand = 'FranceConnect'|t %} {% set url = 'https://franceconnect.gouv.fr/france-connect-plus' %} {% endif %} diff --git a/components/header/header.preview.story.yml b/components/header/header.preview.story.yml index f47c66fe..c75e3a30 100644 --- a/components/header/header.preview.story.yml +++ b/components/header/header.preview.story.yml @@ -18,7 +18,7 @@ slots: props: icon: pack_id: dsfr - settings: { } + settings: {} icon_id: add-circle-line - type: component component: "ui_suite_dsfr:link" @@ -28,7 +28,7 @@ slots: props: icon: pack_id: dsfr - settings: { } + settings: {} icon_id: lock-line - type: component component: "ui_suite_dsfr:link" @@ -38,7 +38,7 @@ slots: props: icon: pack_id: dsfr - settings: { } + settings: {} icon_id: account-line navbar: type: component diff --git a/components/highlight/highlight.twig b/components/highlight/highlight.twig index f52e84f9..9b34f02a 100644 --- a/components/highlight/highlight.twig +++ b/components/highlight/highlight.twig @@ -1,6 +1,6 @@ {% set text_attributes = create_attribute() %} -{% if variant and variant|lower != 'default' %} - {% set text_attributes = text_attributes.addClass('fr-text--' ~ variant|lower) %} +{% if variant and variant != 'default' %} + {% set text_attributes = text_attributes.addClass('fr-text--' ~ variant) %} {% endif %} {% if color_schema %} diff --git a/components/link/link.preview.story.yml b/components/link/link.preview.story.yml index 1f1cb7ea..f026372e 100644 --- a/components/link/link.preview.story.yml +++ b/components/link/link.preview.story.yml @@ -10,5 +10,5 @@ props: icon_position: left icon: pack_id: dsfr - settings: { } + settings: {} icon_id: arrow-right-line diff --git a/components/link/link.twig b/components/link/link.twig index d7f821ad..4b5ada84 100644 --- a/components/link/link.twig +++ b/components/link/link.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' and not external %} - {% set attributes = attributes.addClass('fr-link--' ~ variant|lower|replace({_: '-'})) %} +{% if variant and variant != 'default' and not external %} + {% set attributes = attributes.addClass('fr-link--' ~ variant) %} {% endif %} {% set attributes = attributes.addClass('fr-link') %} diff --git a/components/modal/modal.preview.story.yml b/components/modal/modal.preview.story.yml index 32bd33d2..d68e34fa 100644 --- a/components/modal/modal.preview.story.yml +++ b/components/modal/modal.preview.story.yml @@ -17,7 +17,7 @@ slots: props: icon: pack_id: dsfr - settings: { } + settings: {} icon_id: check-line icon_position: left - type: component @@ -32,5 +32,5 @@ slots: props: icon: pack_id: dsfr - settings: { } + settings: {} icon_id: question-line diff --git a/components/modal/modal.twig b/components/modal/modal.twig index 454cf58c..5f7308b1 100644 --- a/components/modal/modal.twig +++ b/components/modal/modal.twig @@ -1,10 +1,10 @@ -{% if not variant or variant|lower == 'default' %} +{% if not variant or variant == 'default' %} {% set attributes = attributes.addClass('fr-col-md-6') %} {% endif %} -{% if variant|lower == 'sm' %} +{% if variant == 'sm' %} {% set attributes = attributes.addClass('fr-col-md-4') %} {% endif %} -{% if variant|lower == 'lg' %} +{% if variant == 'lg' %} {% set attributes = attributes.addClass('fr-col-md-8') %} {% endif %} {% set modal_id = id|default('modal-' ~ random()) %} diff --git a/components/side_menu/side_menu.twig b/components/side_menu/side_menu.twig index d038f9ff..59e649ad 100644 --- a/components/side_menu/side_menu.twig +++ b/components/side_menu/side_menu.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set attributes = attributes.addClass('fr-sidemenu--' ~ variant|lower|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set attributes = attributes.addClass('fr-sidemenu--' ~ variant|replace({_: '-'})) %} {% endif %} {% if position and position|lower != 'default' %} diff --git a/components/tab/tab.preview.story.yml b/components/tab/tab.preview.story.yml index 846e3131..1e8386e8 100644 --- a/components/tab/tab.preview.story.yml +++ b/components/tab/tab.preview.story.yml @@ -4,5 +4,5 @@ slots: props: icon: pack_id: dsfr - settings: { } + settings: {} icon_id: checkbox-circle-line diff --git a/components/tab/tab.twig b/components/tab/tab.twig index 1f8559a6..b53badef 100644 --- a/components/tab/tab.twig +++ b/components/tab/tab.twig @@ -6,7 +6,7 @@ {% if id %} {% set attributes = attributes.setAttribute('id', 'tab-' ~ id).setAttribute('aria-controls', 'panel-' ~ id) %} {% endif %} -{% if variant|lower == 'selected' %} +{% if variant == 'selected' %} {% set attributes = attributes.setAttribute('tabindex', '0').setAttribute('aria-selected', 'true').addClass('fr-tabs__tab--selected') %} {% endif %} diff --git a/components/tab_panel/tab_panel.twig b/components/tab_panel/tab_panel.twig index a9de2151..9bcdd6e3 100644 --- a/components/tab_panel/tab_panel.twig +++ b/components/tab_panel/tab_panel.twig @@ -2,7 +2,7 @@ {% if id %} {% set attributes = attributes.setAttribute('id', 'panel-' ~ id).setAttribute('aria-labelledby', 'tab-' ~ id) %} {% endif %} -{% if variant|lower == 'selected' %} +{% if variant == 'selected' %} {% set attributes = attributes.setAttribute('tabindex', '0').addClass('fr-tabs__panel--selected') %} {% endif %} diff --git a/components/tag/tag.preview.story.yml b/components/tag/tag.preview.story.yml index 3d113285..d7f00344 100644 --- a/components/tag/tag.preview.story.yml +++ b/components/tag/tag.preview.story.yml @@ -7,5 +7,5 @@ props: color_schema: brown-caramel icon: pack_id: dsfr - settings: { } + settings: {} icon_id: checkbox-circle-line diff --git a/components/tag/tag.twig b/components/tag/tag.twig index 21fcd080..23b71fbd 100644 --- a/components/tag/tag.twig +++ b/components/tag/tag.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set attributes = attributes.addClass('fr-tag--' ~ variant|lower|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set attributes = attributes.addClass('fr-tag--' ~ variant) %} {% endif %} {% if not dismissible and icon.icon_id %} diff --git a/components/tile/tile.twig b/components/tile/tile.twig index 706ddf4c..24b986ef 100644 --- a/components/tile/tile.twig +++ b/components/tile/tile.twig @@ -1,5 +1,5 @@ -{% if variant and variant|lower != 'default' %} - {% set variants = variant|split('__')|map(v => v|lower|replace({(v): 'fr-tile--' ~ v})|replace({_: '-'})) %} +{% if variant and variant != 'default' %} + {% set variants = variant|split('__')|map(v => v|replace({(v): 'fr-tile--' ~ v})) %} {% set attributes = attributes.addClass(variants) %} {% endif %} diff --git a/components/translate/translate.twig b/components/translate/translate.twig index e5a82ea8..cb29b72d 100644 --- a/components/translate/translate.twig +++ b/components/translate/translate.twig @@ -3,7 +3,7 @@ {% if links -%} <nav{{ attributes.addClass(['fr-translate', 'fr-nav']) }} role="navigation"> <div class="fr-nav__item"> - <button class="fr-translate__btn fr-btn fr-btn--tertiary{% if variant|lower == 'no-outline' %}-no-outline{% endif %}" aria-controls="{{ translate_id }}" aria-expanded="false" title="{{ 'Select a language'|t }}" type="button"> + <button class="fr-translate__btn fr-btn fr-btn--tertiary{% if variant == 'no-outline' %}-no-outline{% endif %}" aria-controls="{{ translate_id }}" aria-expanded="false" title="{{ 'Select a language'|t }}" type="button"> {{ title }} </button> <div class="fr-collapse fr-translate__menu fr-menu" id="{{ translate_id }}"> -- GitLab