Class: PandaCms::Admin::HeadingComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- PandaCms::Admin::HeadingComponent
- Defined in:
- app/components/panda_cms/admin/heading_component.rb
Instance Attribute Summary collapse
-
#additional_styles ⇒ Object
readonly
Returns the value of attribute additional_styles.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(text:, level: 2, icon: "", additional_styles: "") ⇒ HeadingComponent
constructor
A new instance of HeadingComponent.
Constructor Details
#initialize(text:, level: 2, icon: "", additional_styles: "") ⇒ HeadingComponent
Returns a new instance of HeadingComponent.
10 11 12 13 14 15 16 |
# File 'app/components/panda_cms/admin/heading_component.rb', line 10 def initialize(text:, level: 2, icon: "", additional_styles: "") @text = text @level = level @icon = icon @additional_styles = additional_styles @additional_styles = @additional_styles.split(" ") if @additional_styles.is_a?(String) end |
Instance Attribute Details
#additional_styles ⇒ Object (readonly)
Returns the value of attribute additional_styles.
8 9 10 |
# File 'app/components/panda_cms/admin/heading_component.rb', line 8 def additional_styles @additional_styles end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
8 9 10 |
# File 'app/components/panda_cms/admin/heading_component.rb', line 8 def icon @icon end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
8 9 10 |
# File 'app/components/panda_cms/admin/heading_component.rb', line 8 def level @level end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
8 9 10 |
# File 'app/components/panda_cms/admin/heading_component.rb', line 8 def text @text end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/components/panda_cms/admin/heading_component.rb', line 18 def call output = "" output += content_tag(:div, @text, class: "grow") if output += content_tag(:span, class: "actions flex gap-x-2 -mt-1") do safe_join(, "") end end output = output.html_safe base_heading_styles = "flex pt-1 text-black mb-5 -mt-1" if level == 1 content_tag(:h1, output, class: [base_heading_styles, "text-2xl font-medium", @additional_styles]) elsif level == 2 content_tag(:h2, output, class: [base_heading_styles, "text-xl font-medium", @additional_styles]) elsif level == 3 content_tag(:h3, output, class: [base_heading_styles, "text-xl", "font-light", @additional_styles]) elsif level == :panel content_tag(:h3, output, class: ["text-base font-medium p-4 text-white"]) end end |