Class: Yattho::Alpha::ActionList::Item

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/alpha/action_list/item.rb

Overview

An individual ‘ActionList` item. Items can optionally include leading and/or trailing visuals, such as icons, avatars, and counters.

Direct Known Subclasses

NavList::Item

Constant Summary collapse

DEFAULT_SIZE =
:medium
SIZE_MAPPINGS =
{
  DEFAULT_SIZE => nil,
  :large => "ActionListContent--sizeLarge",
  :xlarge => "ActionListContent--sizeXLarge"
}.freeze
SIZE_OPTIONS =
SIZE_MAPPINGS.keys.freeze
DEFAULT_DESCRIPTION_SCHEME =
:block
DESCRIPTION_SCHEME_MAPPINGS =
{
  :inline => "ActionListItem-descriptionWrap--inline",
  DEFAULT_DESCRIPTION_SCHEME => "ActionListItem-descriptionWrap"
}.freeze
DESCRIPTION_SCHEME_OPTIONS =
DESCRIPTION_SCHEME_MAPPINGS.keys.freeze
DEFAULT_SCHEME =
:default
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => nil,
  :danger => "ActionListItem--danger"
}.freeze
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys.freeze

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(list:, label:, label_classes: nil, content_arguments: {}, parent: nil, truncate_label: false, href: nil, role: :listitem, size: DEFAULT_SIZE, scheme: DEFAULT_SCHEME, disabled: false, description_scheme: DEFAULT_DESCRIPTION_SCHEME, active: false, on_click: nil, id: self.class.generate_id, **system_arguments) ⇒ Item

Returns a new instance of Item.

Parameters:

  • list (Yattho::Alpha::ActionList)

    The list that contains this item. Used internally.

  • parent (Yattho::Alpha::ActionList::Item) (defaults to: nil)

    This item’s parent item. ‘nil` if this item is at the root. Used internally.

  • label (String)

    Item label.

  • label_classes (String) (defaults to: nil)

    CSS classes that will be added to the label.

  • content_arguments (Hash) (defaults to: {})

    <%= link_to_system_arguments_docs %> used to construct the item’s anchor or button tag.

  • truncate_label (Boolean) (defaults to: false)

    Truncate label with ellipsis.

  • href (String) (defaults to: nil)

    Link URL.

  • role (String) (defaults to: :listitem)

    ARIA role describing the function of the item.

  • size (Symbol) (defaults to: DEFAULT_SIZE)

    Controls block sizing of the item.

  • scheme (Symbol) (defaults to: DEFAULT_SCHEME)

    Controls color/style based on behavior.

  • disabled (Boolean) (defaults to: false)

    Disabled items are not clickable and visually dim.

  • description_scheme (Symbol) (defaults to: DEFAULT_DESCRIPTION_SCHEME)

    Display description inline with label, or block on the next line.

  • active (Boolean) (defaults to: false)

    Sets an active state on navigational items.

  • on_click (String) (defaults to: nil)

    JavaScript to execute when the item is clicked.

  • id (String) (defaults to: self.class.generate_id)

    Used internally.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'app/components/yattho/alpha/action_list/item.rb', line 143

def initialize(
  list:,
  label:,
  label_classes: nil,
  content_arguments: {},
  parent: nil,
  truncate_label: false,
  href: nil,
  role: :listitem,
  size: DEFAULT_SIZE,
  scheme: DEFAULT_SCHEME,
  disabled: false,
  description_scheme: DEFAULT_DESCRIPTION_SCHEME,
  active: false,
  on_click: nil,
  id: self.class.generate_id,
  **system_arguments
)
  @list = list
  @parent = parent
  @label = label
  @href = href
  @truncate_label = truncate_label
  @disabled = disabled
  @active = active
  @trailing_action_on_hover = false
  @id = id
  @system_arguments = system_arguments
  @content_arguments = content_arguments

  @size = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)
  @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)
  @description_scheme = fetch_or_fallback(
    DESCRIPTION_SCHEME_OPTIONS, description_scheme, DEFAULT_DESCRIPTION_SCHEME
  )

  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    SCHEME_MAPPINGS[@scheme],
    "ActionListItem"
  )

  @system_arguments[:role] = role

  @system_arguments[:aria] ||= {}
  @system_arguments[:aria][:disabled] = "true" if @disabled

  @label_arguments = {
    classes: class_names(
      label_classes,
      "ActionListItem-label",
      "ActionListItem-label--truncate" => @truncate_label
    )
  }

  @content_arguments[:id] = @id
  @content_arguments[:classes] = class_names(
    @content_arguments[:classes],
    "ActionListContent",
    SIZE_MAPPINGS[@size]
  )

  if @href && !@disabled
    @content_arguments[:tag] = :a
    @content_arguments[:href] = @href
  else
    @content_arguments[:tag] = :button
    @content_arguments[:onclick] = on_click if on_click
  end

  @description_wrapper_arguments = {
    classes: class_names(
      "ActionListItem-descriptionWrap",
      DESCRIPTION_SCHEME_MAPPINGS[@description_scheme]
    )
  }
end

Instance Attribute Details

#activeObject (readonly) Also known as: active?

Returns the value of attribute active.



115
116
117
# File 'app/components/yattho/alpha/action_list/item.rb', line 115

def active
  @active
end

#disabledObject (readonly) Also known as: disabled?

Returns the value of attribute disabled.



115
116
117
# File 'app/components/yattho/alpha/action_list/item.rb', line 115

def disabled
  @disabled
end

#hrefObject (readonly)

Returns the value of attribute href.



115
116
117
# File 'app/components/yattho/alpha/action_list/item.rb', line 115

def href
  @href
end

#listObject (readonly)

Returns the value of attribute list.



115
116
117
# File 'app/components/yattho/alpha/action_list/item.rb', line 115

def list
  @list
end

#parentObject (readonly)

Returns the value of attribute parent.



115
116
117
# File 'app/components/yattho/alpha/action_list/item.rb', line 115

def parent
  @parent
end