Class: Pulse::ActionList::Item
- Defined in:
- app/components/pulse/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 =
:large => "ActionListContent--sizeLarge", :xlarge => "ActionListContent--sizeXLarge"
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
Constants included from Pulse::AttributesHelper
Pulse::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Pulse::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
generate_id, #merge_attributes, #merge_classes
Methods included from SvgHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean
Methods included from Pulse::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.
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'app/components/pulse/action_list/item.rb', line 167 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] = merge_classes( @system_arguments[:classes], SCHEME_MAPPINGS[@scheme], 'pulse-relative pulse-rounded selected:pulse-font-normal', 'ActionListItem--disabled' => @disabled ) @system_arguments[:data] ||= {} @system_arguments[:data][:targets] = "#{list_class.custom_element_name}.items" @label_arguments = { **label_arguments, classes: merge_classes( label_classes, label_arguments[:classes], 'pulse-font-semibold', 'ActionListItem-label--truncate' => @truncate_label ) } @content_arguments[:id] = @id @content_arguments[:classes] = merge_classes( @content_arguments[:classes], 'pulse-relative pulse-grid pulse-w-full pulse-text-start', 'pulse-select-none pulse-bg-transparent pulse-rounded', 'pulse-grid-rows-[min-content]', 'pulse-grid-cols-[min-content_min-content_minmax(0,auto)_min-content_min-content]', # rubocop:disable Layout/LineLength 'pulse-border-none hover:pulse-no-underline pulse-py-2', 'pulse-items-start pulse-gap-2 pulse-items-center', 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: merge_classes( 'ActionListItem-descriptionWrap', DESCRIPTION_SCHEME_MAPPINGS[@description_scheme] ) } end |
Instance Attribute Details
#active ⇒ Object (readonly) Also known as: active?
Returns the value of attribute active.
137 138 139 |
# File 'app/components/pulse/action_list/item.rb', line 137 def active @active end |
#disabled ⇒ Object (readonly) Also known as: disabled?
Returns the value of attribute disabled.
137 138 139 |
# File 'app/components/pulse/action_list/item.rb', line 137 def disabled @disabled end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
137 138 139 |
# File 'app/components/pulse/action_list/item.rb', line 137 def href @href end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
137 138 139 |
# File 'app/components/pulse/action_list/item.rb', line 137 def id @id end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
137 138 139 |
# File 'app/components/pulse/action_list/item.rb', line 137 def list @list end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
137 138 139 |
# File 'app/components/pulse/action_list/item.rb', line 137 def parent @parent end |