2023-03-24 11:08:31 +01:00
|
|
|
class EditableChamp::HeaderSectionComponent < ApplicationComponent
|
2023-04-28 10:33:01 +02:00
|
|
|
def initialize(form: nil, champ:, seen_at: nil, html_class: {})
|
2023-03-24 11:08:31 +01:00
|
|
|
@champ = champ
|
2023-04-28 10:33:01 +02:00
|
|
|
@html_class = html_class
|
2023-04-12 17:55:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def level
|
2023-04-24 11:42:55 +02:00
|
|
|
@champ.level + 1 # skip one heading level
|
2023-03-24 11:08:31 +01:00
|
|
|
end
|
|
|
|
|
2023-04-28 10:33:01 +02:00
|
|
|
def collapsible?
|
|
|
|
@champ.level == 1
|
|
|
|
end
|
|
|
|
|
2023-03-24 11:08:31 +01:00
|
|
|
def libelle
|
|
|
|
@champ.libelle
|
|
|
|
end
|
|
|
|
|
|
|
|
def header_section_classnames
|
2023-04-24 10:38:17 +02:00
|
|
|
class_names(
|
2023-04-28 10:33:01 +02:00
|
|
|
{
|
|
|
|
"section-#{level}": true,
|
|
|
|
'header-section': @champ.dossier.auto_numbering_section_headers_for?(@champ),
|
|
|
|
'hidden': !@champ.visible?
|
|
|
|
}.merge(@html_class)
|
2023-04-24 10:38:17 +02:00
|
|
|
)
|
2023-03-24 11:08:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag_for_depth
|
2023-04-24 11:42:55 +02:00
|
|
|
if level <= 6
|
|
|
|
"h#{level}"
|
|
|
|
else
|
|
|
|
"p"
|
|
|
|
end
|
2023-03-24 11:08:31 +01:00
|
|
|
end
|
2022-08-12 10:45:04 +02:00
|
|
|
end
|