Class: Primer::OpenProject::CollapsibleSection

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/collapsible_section.rb

Overview

A component consisting of a title and collapsible content. Clicking the title will hide the collapsible content

Constant Summary collapse

TITLE_TAG_FALLBACK =
:h2
TITLE_TAG_OPTIONS =
[:h1, TITLE_TAG_FALLBACK, :h3, :h4, :h5, :h6, :span].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

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

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

Methods included from AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(id: self.class.generate_id, collapsed: false, **system_arguments) ⇒ CollapsibleSection

Returns a new instance of CollapsibleSection.

Parameters:

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

    The unique ID of the collapsible section.

  • collapsed (Boolean) (defaults to: false)

    Whether the section is collapsed on initial render.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/components/primer/open_project/collapsible_section.rb', line 53

def initialize(id: self.class.generate_id, collapsed: false, **system_arguments)
  @title_id = "#{id}-title"
  @content_id = "#{id}-content"
  @collapsed = collapsed

  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = "collapsible-section"
  @system_arguments[:id] = id
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "CollapsibleSection",
    "CollapsibleSection--collapsed" => @collapsed
  )

  @system_arguments[:data] ||= {}
  @system_arguments[:data][:collapsed] = true if @collapsed
end