side_menu_component: add icon

This commit is contained in:
simon lehericey 2023-04-24 15:13:51 +02:00 committed by LeSim
parent 62662c99c0
commit 2fb33336d1
2 changed files with 8 additions and 3 deletions

View file

@ -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

View file

@ -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