@@ -4,30 +4,30 @@ class Matestack::Ui::Bootstrap::Components::Accordion < Matestack::Ui::Component
44 optional :items # array with 2 Hashes: header and body
55 optional :open
66 optional :variant
7- optional attributes : { as : :bs_attrs } , class : { as : :bs_class } , id : { as : :bs_id }
7+ optional :attributes , :class , :id
88
9- def setup
10- @accordion_id = ( bs_id . present? ? bs_id : "matestack-accordion-#{ SecureRandom . hex ( 3 ) } " )
9+ def prepare
10+ @accordion_id = ( context . id . present? ? context . id : "matestack-accordion-#{ SecureRandom . hex ( 3 ) } " )
1111 end
1212
1313 def response
1414 div accordion_attributes do
15- accordion_content_partial if items . present?
16- yield_components
15+ accordion_content_partial if context . items . present?
16+ yield
1717 end
1818 end
1919
2020 protected
2121
2222 def accordion_content_partial
23- items . each_with_index do | item , index |
23+ context . items . each_with_index do | item , index |
2424 div class : "accordion-item" do
2525 heading class : "accordion-header #{ item [ :header ] [ :class ] } " , id : ( item [ :header ] [ :id ] || "header-#{ index } " ) , size : ( item [ :header ] [ :size ] || 2 ) do
2626 button class : "accordion-button" , text :item [ :header ] [ :text ] ,
2727 data : { "bs-toggle" : "collapse" , "bs-target" : "#collapse-#{ ( item [ :header ] [ :id ] || "header-#{ index } " ) } " } ,
2828 attributes : { "aria-expanded" : "false" , "aria-controls" : "collapse-#{ ( item [ :header ] [ :id ] || "header-#{ index } " ) } " , type : "button" }
2929 end
30- bs_collapse class : "accordion-collapse #{ 'show' if open || item [ :open ] } " , id : "collapse-#{ ( item [ :header ] [ :id ] || "header-#{ index } " ) } " , labelledby : ( item [ :header ] [ :id ] || "header-#{ index } " ) ,
30+ bs_collapse class : "accordion-collapse #{ 'show' if context . open || item [ :open ] } " , id : "collapse-#{ ( item [ :header ] [ :id ] || "header-#{ index } " ) } " , labelledby : ( item [ :header ] [ :id ] || "header-#{ index } " ) ,
3131 parent : @accordion_id , multi : ( item [ :body ] [ :multi ] || false ) do
3232 div class : "accordion-body #{ item [ :body ] [ :class ] } " do
3333 plain item [ :body ] [ :text ]
@@ -38,19 +38,18 @@ def accordion_content_partial
3838 end
3939
4040 def accordion_attributes
41- html_attributes . merge (
41+ options . merge (
4242 id : @accordion_id ,
43- class : accordion_classes ,
44- attributes : bs_attrs
45- )
43+ class : accordion_classes
44+ ) . merge ( context . attributes )
4645 end
4746
4847 def accordion_classes
4948 [ ] . tap do |classes |
5049 classes << 'accordion'
51- classes << 'open' if open
52- classes << 'accordion-flush' if variant == :flush
53- classes << bs_class
50+ classes << 'open' if context . open
51+ classes << 'accordion-flush' if context . variant == :flush
52+ classes << context . class
5453 end . join ( ' ' ) . strip
5554 end
5655end
0 commit comments