Class: Primer::Alpha::ActionList::Item
- Defined in:
- app/components/primer/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
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
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Constants included from Primer::AttributesHelper
Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#active ⇒ Object
(also: #active?)
readonly
Returns the value of attribute active.
-
#disabled ⇒ Object
(also: #disabled?)
readonly
Returns the value of attribute disabled.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from Primer::AttributesHelper
#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Constructor Details
#initialize(list:, label: nil, label_classes: nil, label_arguments: {}, content_arguments: {}, form_arguments: {}, parent: nil, truncate_label: false, href: nil, role: nil, 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.
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'app/components/primer/alpha/action_list/item.rb', line 161 def initialize( list:, label: nil, label_classes: nil, label_arguments: {}, content_arguments: {}, form_arguments: {}, parent: nil, truncate_label: false, href: nil, role: nil, 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 || content_arguments[:href] @truncate_label = truncate_label @disabled = disabled @active = active @id = id @system_arguments = system_arguments @content_arguments = content_arguments @form_wrapper = FormWrapper.new(list: @list, action: @href, **form_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", "ActionListItem--disabled" => @disabled ) @system_arguments[:data] ||= {} @system_arguments[:data][:targets] = "#{list_class.custom_element_name}.items" @label_arguments = { **label_arguments, classes: class_names( label_classes, label_arguments[:classes], "ActionListItem-label", "ActionListItem-label--truncate" => @truncate_label ) } @content_arguments[:id] = @id @content_arguments[:classes] = class_names( @content_arguments[:classes], "ActionListContent", SIZE_MAPPINGS[@size] ) unless @content_arguments[:tag] if @href && @form_wrapper.get? && !@disabled @content_arguments[:tag] = :a @content_arguments[:href] = @href else @content_arguments[:tag] = :button @content_arguments[:type] = @form_wrapper.form_required? ? :submit : :button @content_arguments[:onclick] = on_click if on_click end end if @content_arguments[:tag] != :button && @form_wrapper.form_required? raise ArgumentError, "items that submit forms must use a \"button\" tag instead of \"#{@content_arguments[:tag]}\"" end if @content_arguments[:tag] != :button && @list.acts_as_form_input? raise ArgumentError, "items within lists/menus that act as form inputs must use \"button\" tags instead of \"#{@content_arguments[:tag]}\"" end if @disabled @content_arguments[:aria] ||= merge_aria( @content_arguments, { aria: { disabled: "true" } } ) end @content_arguments[:role] = role || if @list.allows_selection? ActionList::SELECT_VARIANT_ROLE_MAP[@list.select_variant] elsif @list. ActionList::DEFAULT_MENU_ITEM_ROLE end @system_arguments[:role] = @list. ? :none : nil @description_wrapper_arguments = { classes: class_names( "ActionListItem-descriptionWrap", DESCRIPTION_SCHEME_MAPPINGS[@description_scheme] ) } end |
Instance Attribute Details
#active ⇒ Object (readonly) Also known as: active?
Returns the value of attribute active.
131 132 133 |
# File 'app/components/primer/alpha/action_list/item.rb', line 131 def active @active end |
#disabled ⇒ Object (readonly) Also known as: disabled?
Returns the value of attribute disabled.
131 132 133 |
# File 'app/components/primer/alpha/action_list/item.rb', line 131 def disabled @disabled end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
131 132 133 |
# File 'app/components/primer/alpha/action_list/item.rb', line 131 def href @href end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
131 132 133 |
# File 'app/components/primer/alpha/action_list/item.rb', line 131 def id @id end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
131 132 133 |
# File 'app/components/primer/alpha/action_list/item.rb', line 131 def list @list end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
131 132 133 |
# File 'app/components/primer/alpha/action_list/item.rb', line 131 def parent @parent end |