Class: PandaCms::Admin::HeadingComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/panda_cms/admin/heading_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_stylesObject (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

#iconObject (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

#levelObject (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

#textObject (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

#callObject



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 += (:div, @text, class: "grow")

  if buttons?
    output += (:span, class: "actions flex gap-x-2 -mt-1") do
      safe_join(buttons, "")
    end
  end

  output = output.html_safe
  base_heading_styles = "flex pt-1 text-black mb-5 -mt-1"

  if level == 1
    (:h1, output, class: [base_heading_styles, "text-2xl font-medium", @additional_styles])
  elsif level == 2
    (:h2, output, class: [base_heading_styles, "text-xl font-medium", @additional_styles])
  elsif level == 3
    (:h3, output, class: [base_heading_styles, "text-xl", "font-light", @additional_styles])
  elsif level == :panel
    (:h3, output, class: ["text-base font-medium p-4 text-white"])
  end
end