From 2fb33336d1e2cb2fb0c71c1838e05fba96734b00 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 24 Apr 2023 15:13:51 +0200 Subject: [PATCH] side_menu_component: add icon --- app/components/dsfr/sidemenu_component.rb | 5 +++-- .../dsfr/sidemenu_component/sidemenu_component.html.haml | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/components/dsfr/sidemenu_component.rb b/app/components/dsfr/sidemenu_component.rb index d448f7852..31c2730e4 100644 --- a/app/components/dsfr/sidemenu_component.rb +++ b/app/components/dsfr/sidemenu_component.rb @@ -2,10 +2,11 @@ class Dsfr::SidemenuComponent < ApplicationComponent renders_many :links, "LinkComponent" class LinkComponent < ApplicationComponent - attr_reader :name, :url - def initialize(name:, url:) + attr_reader :name, :url, :icon + def initialize(name:, url:, icon: nil) @name = name @url = url + @icon = icon end end diff --git a/app/components/dsfr/sidemenu_component/sidemenu_component.html.haml b/app/components/dsfr/sidemenu_component/sidemenu_component.html.haml index 2e2a70014..2c6c96e26 100644 --- a/app/components/dsfr/sidemenu_component/sidemenu_component.html.haml +++ b/app/components/dsfr/sidemenu_component/sidemenu_component.html.haml @@ -6,4 +6,8 @@ %ul.fr-sidemenu__list - links.each do |link| %li{ class: "fr-sidemenu__item fr-sidemenu__item#{active?(link.url) ? '--active' : ''}" } - = link_to link.name, link.url, class: 'fr-sidemenu__link', 'aria-current': active?(link.url) ? 'page' : nil, target: "_self" + = link_to link.url, class: 'fr-sidemenu__link ', 'aria-current': active?(link.url) ? 'page' : nil, target: "_self" do + - capture do + - if link.icon.present? + %span{ class: link.icon }  + = link.name