Class: DsfrComponent::TagComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/dsfr_component/tag_component.rb

Constant Summary collapse

SIZES =
%i[sm md].freeze

Constants inherited from Base

Base::HEADING_LEVELS

Instance Attribute Summary

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(title:, icon: nil, size: nil, url: nil, selected: nil, dismissable: nil, classes: [], html_attributes: {}) ⇒ TagComponent

Returns a new instance of TagComponent.

Parameters:

  • title (String)

    tag title

  • icon (String) (defaults to: nil)

    icon name (optional)

  • size (Symbol) (defaults to: nil)

    tag size : ‘:md` (default) or `:sm` (optional)

  • url (String) (defaults to: nil)

    for clickable tags only (optional)

  • selected (Boolean) (defaults to: nil)

    adds a check, useful for filters list, cannot be used with ‘url` (optional)

  • dismissable (Boolean) (defaults to: nil)

    adds a close icon on the right, cannot be used with ‘url` or `icon` (optional)



11
12
13
14
15
16
17
18
19
20
# File 'app/components/dsfr_component/tag_component.rb', line 11

def initialize(title:, icon: nil, size: nil, url: nil, selected: nil, dismissable: nil, classes: [], html_attributes: {})
  @title = title
  @icon = icon
  @size = size
  @url = url
  @selected = selected
  @dismissable = dismissable

  super(classes: classes, html_attributes: html_attributes)
end

Instance Method Details

#callObject



22
23
24
25
# File 'app/components/dsfr_component/tag_component.rb', line 22

def call
  validate_size && validate_selected && validate_dismissable
  tag.send(tag_name, **html_attributes) { title }
end